parse.y (function_invocation, [...]): Pass location to tree_code_get_expression.
authorJames A. Morrison <phython@gcc.gnu.org>
Sat, 26 Feb 2005 16:07:49 +0000 (16:07 +0000)
committerJames A. Morrison <phython@gcc.gnu.org>
Sat, 26 Feb 2005 16:07:49 +0000 (16:07 +0000)
2005-02-26  James A. Morrison  <phython@gcc.gnu.org>

        * parse.y (function_invocation, variable-ref, make_plus_expression):
        Pass location to tree_code_get_expression.
        * treetree.c (tree_code_generate_return): Set EXPR_LOCUS on retval.
        (tree_code_get_expression): Wrap variable references in NOP_EXPRs and
        set EXPR_LOCATION on ret1.
        * treetree.h (tree_code_get_expression): Take the location of the
        expression as an argument.

From-SVN: r95584

gcc/treelang/ChangeLog
gcc/treelang/parse.y
gcc/treelang/treetree.c
gcc/treelang/treetree.h

index d428afdabe403958f45c923dc01db130c3528553..eb5c55da45182e628b8398c7e012b270fdde8846 100644 (file)
@@ -1,3 +1,13 @@
+2005-02-26  James A. Morrison  <phython@gcc.gnu.org>
+
+       * parse.y (function_invocation, variable-ref, make_plus_expression):
+       Pass location to tree_code_get_expression.
+       * treetree.c (tree_code_generate_return): Set EXPR_LOCUS on retval.
+       (tree_code_get_expression): Wrap variable references in NOP_EXPRs and
+       set EXPR_LOCATION on ret1.
+       * treetree.h (tree_code_get_expression): Take the location of the
+       expression as an argument.
+
 2005-02-26  James A. Morrison  <phython@gcc.gnu.org>
 
        * treelang.texi: Treelang does have warnings.
index abf2bcbf795fb1f89b6e2fa23d427ce46bfc35ca..be4436252218785fda25dba0b6c85ec0a4a66924 100644 (file)
@@ -675,7 +675,7 @@ NAME LEFT_PARENTHESIS expressions_with_commas_opt RIGHT_PARENTHESIS {
   type = tree_code_get_type (NUMERIC_TYPE (prod));
   prod->tp.pro.code = tree_code_get_expression (EXP_FUNCTION_INVOCATION, type,
                                                 proto->tp.pro.code, parms,
-                                                NULL);
+                                                NULL, tok->tp.tok.location);
   $$ = prod;
 }
 ;
@@ -730,8 +730,9 @@ NAME {
   OP1 (prod) = $1;
   
   prod->tp.pro.code =
-    tree_code_get_expression (EXP_REFERENCE, type, 
-                             symbol_table_entry->tp.pro.code, NULL, NULL);
+    tree_code_get_expression (EXP_REFERENCE, type,
+                             symbol_table_entry->tp.pro.code, NULL, NULL,
+                             tok->tp.tok.location);
   $$ = prod;
 }
 ;
@@ -920,7 +921,8 @@ make_plus_expression (struct prod_token_parm_item* tok,
       
   prod->tp.pro.code = tree_code_get_expression (prod_code, type,
                                                op1->tp.pro.code,
-                                               op2->tp.pro.code, NULL);
+                                               op2->tp.pro.code, NULL,
+                                               tok->tp.tok.location);
 
   return prod;
 }
index ac8c7a39494eb3e256f9650534b00a5940e6c53e..aea6e0ba5cbc6838671c3d02a63d8bca4ed0a685 100644 (file)
@@ -589,6 +589,9 @@ tree_code_generate_return (tree type, tree exp)
       TREE_SIDE_EFFECTS (setret) = 1;
       TREE_USED (setret) = 1;
       setret = build1 (RETURN_EXPR, type, setret);
+      /* Use EXPR_LOCUS so we don't lose any information about the file we
+        are compiling.  */
+      SET_EXPR_LOCUS (setret, EXPR_LOCUS (exp));
     }
    else
      setret = build1 (RETURN_EXPR, type, NULL_TREE);
@@ -647,7 +650,8 @@ tree_code_get_integer_value (unsigned char* chars, unsigned int length)
 tree
 tree_code_get_expression (unsigned int exp_type,
                           tree type, tree op1, tree op2,
-                         tree op3 ATTRIBUTE_UNUSED)
+                         tree op3 ATTRIBUTE_UNUSED,
+                         location_t loc)
 {
   tree ret1;
   int operator;
@@ -685,12 +689,13 @@ tree_code_get_expression (unsigned int exp_type,
 
       /* Reference to a variable.  This is dead easy, just return the
          decl for the variable.  If the TYPE is different than the
-         variable type, convert it.  */
+         variable type, convert it.  However, to keep accurate location
+        information we wrap it in a NOP_EXPR is is easily stripped.  */
     case EXP_REFERENCE:
       gcc_assert (op1);
       TREE_USED (op1) = 1;
       if (type == TREE_TYPE (op1))
-        ret1 = op1;
+        ret1 = build1 (NOP_EXPR, type, op1);
       else
         ret1 = fold (build1 (CONVERT_EXPR, type, op1));
       break;
@@ -710,6 +715,10 @@ tree_code_get_expression (unsigned int exp_type,
       gcc_unreachable ();
     }
 
+  /* Declarations already have a location and constants can be shared so they
+     shouldn't a location set on them.  */
+  if (! DECL_P (ret1) && ! TREE_CONSTANT (ret1))
+    SET_EXPR_LOCATION (ret1, loc);
   return ret1;
 }
 
index 323509cf669a0719ae1bc7e5fc774f11bbc4387a..cb6891ebfddc914e9c221403eb60e0b45c15f0e6 100644 (file)
@@ -33,7 +33,8 @@ tree tree_code_add_parameter (tree list, tree proto_exp, tree exp);
 tree tree_code_get_integer_value (unsigned char *chars, unsigned int length);
 void tree_code_generate_return (tree type, tree exp);
 void tree_ggc_storage_always_used  (void *m);
-tree tree_code_get_expression (unsigned int exp_type, tree type, tree op1, tree op2, tree op3);
+tree tree_code_get_expression (unsigned int exp_type, tree type, tree op1,
+                              tree op2, tree op3, location_t loc);
 tree tree_code_get_numeric_type (unsigned int size1, unsigned int sign1);
 void tree_code_create_function_initial (tree prev_saved,
                                        location_t loc);