Skip to content

Commit

Permalink
Tidbit: unary operator, was missing previously
Browse files Browse the repository at this point in the history
  • Loading branch information
msprotz committed Jul 24, 2023
1 parent 3e0e6c7 commit 422685c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/Constant.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ let bytes_of_width (w: width) =
type op =
(* Arithmetic operations *)
| Add | AddW | Sub | SubW | Div | DivW | Mult | MultW | Mod
| Neg
(* Bitwise operations *)
| BOr | BAnd | BXor | BShiftL | BShiftR | BNot
(* Arithmetic comparisons / boolean comparisons *)
Expand Down
2 changes: 1 addition & 1 deletion lib/Helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let type_of_op op w =
TArrow (TBool, TArrow (TBool, TBool))
| Not ->
TArrow (TBool, TBool)
| BNot ->
| BNot | Neg ->
TArrow (TInt w, TInt w)
| Assign | PreIncr | PreDecr | PostIncr | PostDecr | Comma ->
invalid_arg "type_of_op"
Expand Down
6 changes: 3 additions & 3 deletions lib/PrintC.ml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ and p_type_name (qs, spec, decl) =
| _ ->
p_qualifiers_break qs ^^ p_type_spec spec ^^ space ^^ p_type_declarator decl

(* http:/ /en.cppreference.com/w/c/language/operator_precedence *)
(* http://en.cppreference.com/w/c/language/operator_precedence *)
and prec_of_op2 op =
let open Constant in
match op with
Expand All @@ -151,12 +151,12 @@ and prec_of_op2 op =
| Or -> 12, 12, 12
| Assign -> 14, 13, 14
| Comma -> 15, 15, 14
| PreIncr | PostIncr | PreDecr | PostDecr | Not | BNot -> raise (Invalid_argument "prec_of_op2")
| PreIncr | PostIncr | PreDecr | PostDecr | Not | BNot | Neg -> raise (Invalid_argument "prec_of_op2")

and prec_of_op1 op =
let open Constant in
match op with
| PreDecr | PreIncr | Not | BNot -> 2
| PreDecr | PreIncr | Not | BNot | Neg -> 2
| PostDecr | PostIncr -> 1
| _ -> raise (Invalid_argument "prec_of_op1")

Expand Down
1 change: 1 addition & 0 deletions lib/PrintCommon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ let print_op = function
| PostDecr | PreDecr -> string "--"
| Assign -> string "="
| Comma -> string ","
| Neg -> string "-"

let print_cc = function
| CDecl -> string "__cdecl"
Expand Down

0 comments on commit 422685c

Please sign in to comment.