c-common.def (FILE_STMT): New code.
authorJason Merrill <jason@redhat.com>
Tue, 15 Jan 2002 22:27:07 +0000 (17:27 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 15 Jan 2002 22:27:07 +0000 (17:27 -0500)
        * 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.

From-SVN: r48881

gcc/ChangeLog
gcc/c-common.c
gcc/c-common.def
gcc/c-common.h
gcc/c-semantics.c

index 26570444123bedb3d8772a72cc2454b0d651d30a..2ae5a60871d853a8a10c384db86a690ef6152b5f 100644 (file)
@@ -1,3 +1,15 @@
+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.
+
 2002-01-15  Eric Christopher  <echristo@redhat.com>
 
        * flow.c (propagate_one_insn): Add error message and print out
index b08ef5b77a3c9a74364cb0ad9cff176f000b7938..bbccf4a5092da7ee00b1995046a1b1ba74e476b3 100644 (file)
@@ -3111,6 +3111,7 @@ statement_code_p (code)
     case GOTO_STMT:
     case LABEL_STMT:
     case ASM_STMT:
+    case FILE_STMT:
     case CASE_LABEL:
       return 1;
 
index 2f14cf2ceaf6d747e892bc56aca1abcd92d757e3..d59a151680ea7add3890a0598ab645eff667c9dc 100644 (file)
@@ -92,6 +92,10 @@ DEFTREECODE (ASM_STMT, "asm_stmt", 'e', 5)
    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
@@ -108,3 +112,9 @@ DEFTREECODE (STMT_EXPR, "stmt_expr", 'e', 1)
    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:
+*/
index 873021bc2db21d15bf255a8b52fc657e8a7cb028..3aaa513ed66d2fee2939c6795cde8c26ae1565b0 100644 (file)
@@ -257,6 +257,8 @@ struct stmt_tree_s {
   /* 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
@@ -296,6 +298,10 @@ struct language_function {
 
 #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
@@ -688,6 +694,12 @@ extern tree strip_array_types                   PARAMS ((tree));
 #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.  */
index 4bab4d3aaa6043fb9bac29a95ba44b9d89ae09f0..682943f17c29f957e2f65b9dd912b4d2b21e3923 100644 (file)
@@ -60,6 +60,7 @@ begin_stmt_tree (t)
   *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.  */
@@ -68,6 +69,19 @@ tree
 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;
@@ -760,6 +774,10 @@ expand_stmt (t)
 
       switch (TREE_CODE (t))
        {
+       case FILE_STMT:
+         input_filename = FILE_STMT_FILENAME (t);
+         break;
+
        case RETURN_STMT:
          genrtl_return_stmt (t);
          break;
@@ -845,4 +863,3 @@ expand_stmt (t)
       t = TREE_CHAIN (t);
     }
 }
-