This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: RFC: PATCH for multiple-file functions and the treerepresentation
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 15 Jan 2002 22:27:08 +0000
- Subject: Re: RFC: PATCH for multiple-file functions and the treerepresentation
- References: <wvl4rlsdgp1.fsf@prospero.cambridge.redhat.com>
OK, there were several problems with the last patch. One, there's already
a last_filename. Two, reusing EXPR_WITH_FILE_LOCATION like this doesn't
mesh well with the statement/expression code distinction. So I gave up and
introduced a new statement code. I'm not entirely happy with this
solution, but it works well. I'm still open to comments, but I'm checking
it in now.
Tested i686-pc-linux-gnu.
2002-01-15 Jason Merrill <jason@redhat.com>
* c-common.def (FILE_STMT): New code.
* c-common.c (statement_code_p): It's a statement.
* c-common.h (stmt_tree_s): Add x_last_filename.
(FILE_STMT_FILENAME_NODE, FILE_STMT_FILENAME): New macros.
(last_expr_filename): New macro.
* c-semantics.c (begin_stmt_tree): Initialize it.
(add_stmt): If the filename changed, also insert a
FILE_STMT.
(expand_stmt): Handle seeing one.
*** c-common.c.~1~ Mon Jan 7 19:06:42 2002
--- c-common.c Mon Jan 14 21:26:48 2002
*************** statement_code_p (code)
*** 3111,3116 ****
--- 3111,3117 ----
case GOTO_STMT:
case LABEL_STMT:
case ASM_STMT:
+ case FILE_STMT:
case CASE_LABEL:
return 1;
*** c-common.h.~1~ Mon Jan 7 19:06:42 2002
--- c-common.h Mon Jan 14 21:27:46 2002
*************** struct stmt_tree_s {
*** 257,262 ****
--- 257,264 ----
/* The type of the last expression statement. (This information is
needed to implement the statement-expression extension.) */
tree x_last_expr_type;
+ /* The last filename we recorded. */
+ const char *x_last_expr_filename;
/* In C++, Non-zero if we should treat statements as full
expressions. In particular, this variable is no-zero if at the
end of a statement we should destroy any temporaries created
*************** struct language_function {
*** 296,301 ****
--- 298,307 ----
#define last_expr_type (current_stmt_tree ()->x_last_expr_type)
+ /* The name of the last file we have seen. */
+
+ #define last_expr_filename (current_stmt_tree ()->x_last_expr_filename)
+
/* LAST_TREE contains the last statement parsed. These are chained
together through the TREE_CHAIN field, but often need to be
re-organized since the parse is performed bottom-up. This macro
*************** extern tree strip_array_types
*** 688,693 ****
--- 694,705 ----
#define ASM_VOLATILE_P(NODE) \
(ASM_CV_QUAL (ASM_STMT_CHECK (NODE)) != NULL_TREE)
+ /* The filename we are changing to as of this FILE_STMT. */
+ #define FILE_STMT_FILENAME_NODE(NODE) \
+ (TREE_OPERAND (FILE_STMT_CHECK (NODE), 0))
+ #define FILE_STMT_FILENAME(NODE) \
+ (IDENTIFIER_POINTER (FILE_STMT_FILENAME_NODE (NODE)))
+
/* The line-number at which a statement began. But if
STMT_LINENO_FOR_FN_P does holds, then this macro gives the
line number for the end of the current function instead. */
*** c-common.def.~1~ Fri Dec 28 22:38:38 2001
--- c-common.def Mon Jan 14 21:18:15 2002
*************** DEFTREECODE (ASM_STMT, "asm_stmt", 'e',
*** 92,97 ****
--- 92,101 ----
variables declared in this scope. */
DEFTREECODE (SCOPE_STMT, "scope_stmt", 'e', 1)
+ /* A FILE_STMT marks the spot where a function changes files. It has no
+ other semantics. FILE_STMT_FILENAME gives the name. */
+ DEFTREECODE (FILE_STMT, "file_stmt", 'e', 1)
+
/* Used to represent a CASE_LABEL. The operands are CASE_LOW and
CASE_HIGH, respectively. If CASE_LOW is NULL_TREE, the label is a
'default' label. If CASE_HIGH is NULL_TREE, the label is a normal case
*************** DEFTREECODE (STMT_EXPR, "stmt_expr", 'e'
*** 108,110 ****
--- 112,120 ----
the DECL_INITIAL of that decl is the CONSTRUCTOR that initializes
the compound literal. */
DEFTREECODE (COMPOUND_LITERAL_EXPR, "compound_literal_expr", 'e', 1)
+
+ /*
+ Local variables:
+ mode:c
+ End:
+ */
*** c-semantics.c.~1~ Mon Jan 7 19:06:43 2002
--- c-semantics.c Mon Jan 14 21:34:42 2002
*************** begin_stmt_tree (t)
*** 60,65 ****
--- 60,66 ----
*t = build_nt (EXPR_STMT, void_zero_node);
last_tree = *t;
last_expr_type = NULL_TREE;
+ last_expr_filename = input_filename;
}
/* T is a statement. Add it to the statement-tree. */
*************** tree
*** 68,73 ****
--- 69,87 ----
add_stmt (t)
tree t;
{
+ if (input_filename != last_expr_filename)
+ {
+ /* If the filename has changed, also add in a FILE_STMT. Do a string
+ compare first, though, as it might be an equivalent string. */
+ int add = (strcmp (input_filename, last_expr_filename) != 0);
+ last_expr_filename = input_filename;
+ if (add)
+ {
+ tree pos = build_nt (FILE_STMT, get_identifier (input_filename));
+ add_stmt (pos);
+ }
+ }
+
/* Add T to the statement-tree. */
TREE_CHAIN (last_tree) = t;
last_tree = t;
*************** expand_stmt (t)
*** 760,765 ****
--- 774,783 ----
switch (TREE_CODE (t))
{
+ case FILE_STMT:
+ input_filename = FILE_STMT_FILENAME (t);
+ break;
+
case RETURN_STMT:
genrtl_return_stmt (t);
break;