This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[committed] Give treelang expressions locations
- From: ja2morri at csclub dot uwaterloo dot ca (James A. Morrison)
- To: gcc-patches at gcc dot gnu dot org
- Date: 26 Feb 2005 11:13:20 -0500
- Subject: [committed] Give treelang expressions locations
Hi,
This patch gives each expression in treelang a location.
Bubblestrapped and tested treelang on sparc-linux.
--
Thanks,
Jim
http://www.student.cs.uwaterloo.ca/~ja2morri/
http://phython.blogspot.com
http://open.nit.ca/wiki/?page=jim
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.
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/parse.y,v
retrieving revision 1.21
diff -u -p -r1.21 parse.y
--- parse.y 26 Feb 2005 14:01:03 -0000 1.21
+++ parse.y 26 Feb 2005 15:34:17 -0000
@@ -675,7 +674,7 @@ NAME LEFT_PARENTHESIS expressions_with_c
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 +729,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_
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: treetree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/treetree.c,v
retrieving revision 1.57
diff -u -p -r1.57 treetree.c
--- treetree.c 26 Feb 2005 14:10:11 -0000 1.57
+++ treetree.c 26 Feb 2005 15:34:18 -0000
@@ -589,6 +589,9 @@ tree_code_generate_return (tree type, tr
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 ch
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 e
/* 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 e
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: treetree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/treelang/treetree.h,v
retrieving revision 1.11
diff -u -p -r1.11 treetree.h
--- treetree.h 24 Feb 2005 16:12:39 -0000 1.11
+++ treetree.h 26 Feb 2005 15:34:18 -0000
@@ -33,7 +33,8 @@ tree tree_code_add_parameter (tree list,
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);
Index: var_defs.tree
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/treelang/compile/var_defs.tree,v
retrieving revision 1.2
diff -u -p -r1.2 var_defs.tree
--- var_defs.tree 2 Oct 2004 18:38:29 -0000 1.2
+++ var_defs.tree 26 Feb 2005 16:10:52 -0000
@@ -1,4 +1,5 @@
// { dg-do compile }
+// { dg-options "-Wuninitialized -O" }
external_definition void boring (int arg0);
external_definition char condition (char arg1, char arg2);
external_definition int first_nonzero (int arg5, int arg6);
@@ -14,11 +15,12 @@ condition
if (arg1)
{
automatic int i;
- return arg1;
+ return i + 1; // { dg-warning "uninitialized" }
}
else
{
- return 0;
+ automatic int j;
+ return j; // { dg-warning "uninitialized" }
}
}