Release coccinelle-0.2.4rc5
[bpt/coccinelle.git] / parsing_c / type_annoter_c.ml
index a55753a..5779ee0 100644 (file)
@@ -611,8 +611,8 @@ let annotater_expr_visitor_subpart = (fun (k,bigf) expr ->
 
     (* -------------------------------------------------- *)
     (* todo: should analyse the 's' for int to know if unsigned or not *)
-    | Constant (String (s,kind)) -> make_info_def (type_of_s "char *")
-    | Constant MultiString _  -> make_info_def (type_of_s "char *")
+    | Constant (String (s,kind)) -> make_info_def (type_of_s "char []")
+    | Constant MultiString _  -> make_info_def (type_of_s "char []")
     | Constant (Char   (s,kind)) -> make_info_def (type_of_s "char")
     | Constant (Int (s,kind)) ->
        (* this seems really unpleasant, but perhaps the type needs to be set
@@ -860,8 +860,12 @@ let annotater_expr_visitor_subpart = (fun (k,bigf) expr ->
     (* todo? lub, hmm maybe not, cos type must be e1 *)
     | Assignment (e1, op, e2) ->
         k expr;
-        (* value of an assignment is the value of the RHS expression *)
-        Ast_c.get_type_expr e2
+        (* value of an assignment is the value of the RHS expression, but its
+           type is the type of the lhs expression.  Use the rhs exp if no
+          information is available *)
+        (match Ast_c.get_type_expr e1 with
+         (None,_) -> Ast_c.get_type_expr e2
+       | (Some ty,t) -> (Some ty,t))
     | Sequence (e1, e2) ->
         k expr;
         Ast_c.get_type_expr e2
@@ -907,7 +911,8 @@ let annotater_expr_visitor_subpart = (fun (k,bigf) expr ->
 
     | Unary (e, Not) ->
         k expr; (* recurse to set the types-ref of sub expressions *)
-        Ast_c.get_type_expr e
+       (* the result of ! is always 0 or 1, not the argument type *)
+        make_info_def (type_of_s "int")
     | Unary (e, Tilde) ->
         k expr; (* recurse to set the types-ref of sub expressions *)
         Ast_c.get_type_expr e