OSDN Git Service

* lex.c (handle_pragma_interface): Don't copy the filename.
[pf3gnuchains/gcc-fork.git] / gcc / cp / lex.c
index f47aa93..4552305 100644 (file)
@@ -1,13 +1,14 @@
 /* Separate lexical analyzer for GNU C++.
    Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
+   Free Software Foundation, Inc.
    Hacked by Michael Tiemann (tiemann@cygnus.com)
 
 This file is part of GCC.
 
 GCC is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GCC is distributed in the hope that it will be useful,
@@ -16,9 +17,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING.  If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
 
 
 /* This file is the lexical analyzer for GNU C++.  */
@@ -82,12 +82,6 @@ struct impl_files
 static struct impl_files *impl_file_chain;
 
 \f
-int interface_only;            /* whether or not current file is only for
-                                  interface definitions.  */
-int interface_unknown;         /* whether or not we know this class
-                                  to behave according to #pragma interface.  */
-
-\f
 void
 cxx_finish (void)
 {
@@ -123,7 +117,7 @@ init_operators (void)
         : &operator_name_info[(int) CODE]);                                \
   oni->identifier = identifier;                                                    \
   oni->name = NAME;                                                        \
-  oni->mangled_name = MANGLING;                                             \
+  oni->mangled_name = MANGLING;                                                    \
   oni->arity = ARITY;
 
 #include "operators.def"
@@ -150,9 +144,8 @@ init_operators (void)
   operator_name_info [(int) ABS_EXPR].name = "abs";
   operator_name_info [(int) TRUTH_AND_EXPR].name = "strict &&";
   operator_name_info [(int) TRUTH_OR_EXPR].name = "strict ||";
-  operator_name_info [(int) IN_EXPR].name = "in";
   operator_name_info [(int) RANGE_EXPR].name = "...";
-  operator_name_info [(int) CONVERT_EXPR].name = "+";
+  operator_name_info [(int) UNARY_PLUS_EXPR].name = "+";
 
   assignment_operator_name_info [(int) EXACT_DIV_EXPR].name
     = "(exact /=)";
@@ -182,6 +175,8 @@ struct resword
    _true_.  */
 #define D_EXT          0x01    /* GCC extension */
 #define D_ASM          0x02    /* in C99, but has a switch to turn it off */
+#define D_OBJC         0x04    /* Objective C++ only */
+#define D_CXX0X         0x08    /* C++0x only */
 
 CONSTRAINT(ridbits_fit, RID_LAST_MODIFIER < sizeof(unsigned long) * CHAR_BIT);
 
@@ -190,7 +185,7 @@ static const struct resword reswords[] =
   { "_Complex",                RID_COMPLEX,    0 },
   { "__FUNCTION__",    RID_FUNCTION_NAME, 0 },
   { "__PRETTY_FUNCTION__", RID_PRETTY_FUNCTION_NAME, 0 },
-  { "__alignof",       RID_ALIGNOF,    0 },
+  { "__alignof",       RID_ALIGNOF,    0 },
   { "__alignof__",     RID_ALIGNOF,    0 },
   { "__asm",           RID_ASM,        0 },
   { "__asm__",         RID_ASM,        0 },
@@ -202,8 +197,26 @@ static const struct resword reswords[] =
   { "__complex__",     RID_COMPLEX,    0 },
   { "__const",         RID_CONST,      0 },
   { "__const__",       RID_CONST,      0 },
+  { "__decltype",       RID_DECLTYPE,   0 },
   { "__extension__",   RID_EXTENSION,  0 },
   { "__func__",                RID_C99_FUNCTION_NAME,  0 },
+  { "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN, 0 },
+  { "__has_nothrow_constructor", RID_HAS_NOTHROW_CONSTRUCTOR, 0 },
+  { "__has_nothrow_copy", RID_HAS_NOTHROW_COPY, 0 },
+  { "__has_trivial_assign", RID_HAS_TRIVIAL_ASSIGN, 0 },
+  { "__has_trivial_constructor", RID_HAS_TRIVIAL_CONSTRUCTOR, 0 },
+  { "__has_trivial_copy", RID_HAS_TRIVIAL_COPY, 0 },
+  { "__has_trivial_destructor", RID_HAS_TRIVIAL_DESTRUCTOR, 0 },
+  { "__has_virtual_destructor", RID_HAS_VIRTUAL_DESTRUCTOR, 0 },
+  { "__is_abstract",   RID_IS_ABSTRACT, 0 },
+  { "__is_base_of",    RID_IS_BASE_OF, 0 },
+  { "__is_class",      RID_IS_CLASS,   0 },
+  { "__is_convertible_to", RID_IS_CONVERTIBLE_TO, 0 },
+  { "__is_empty",      RID_IS_EMPTY,   0 },
+  { "__is_enum",       RID_IS_ENUM,    0 },
+  { "__is_pod",                RID_IS_POD,     0 },
+  { "__is_polymorphic",        RID_IS_POLYMORPHIC, 0 },
+  { "__is_union",      RID_IS_UNION,   0 },
   { "__imag",          RID_IMAGPART,   0 },
   { "__imag__",                RID_IMAGPART,   0 },
   { "__inline",                RID_INLINE,     0 },
@@ -232,6 +245,7 @@ static const struct resword reswords[] =
   { "const",           RID_CONST,      0 },
   { "const_cast",      RID_CONSTCAST,  0 },
   { "continue",                RID_CONTINUE,   0 },
+  { "decltype",         RID_DECLTYPE,   D_CXX0X },
   { "default",         RID_DEFAULT,    0 },
   { "delete",          RID_DELETE,     0 },
   { "do",              RID_DO,         0 },
@@ -265,6 +279,7 @@ static const struct resword reswords[] =
   { "signed",          RID_SIGNED,     0 },
   { "sizeof",          RID_SIZEOF,     0 },
   { "static",          RID_STATIC,     0 },
+  { "static_assert",    RID_STATIC_ASSERT, D_CXX0X },
   { "static_cast",     RID_STATCAST,   0 },
   { "struct",          RID_STRUCT,     0 },
   { "switch",          RID_SWITCH,     0 },
@@ -283,9 +298,34 @@ static const struct resword reswords[] =
   { "virtual",         RID_VIRTUAL,    0 },
   { "void",            RID_VOID,       0 },
   { "volatile",                RID_VOLATILE,   0 },
-  { "wchar_t",          RID_WCHAR,     0 },
+  { "wchar_t",         RID_WCHAR,      0 },
   { "while",           RID_WHILE,      0 },
 
+  /* The remaining keywords are specific to Objective-C++.  NB:
+     All of them will remain _disabled_, since they are context-
+     sensitive.  */
+
+  /* These ObjC keywords are recognized only immediately after
+     an '@'.  NB: The following C++ keywords double as
+     ObjC keywords in this context: RID_CLASS, RID_PRIVATE,
+     RID_PROTECTED, RID_PUBLIC, RID_THROW, RID_TRY and RID_CATCH.  */
+  { "compatibility_alias", RID_AT_ALIAS,       D_OBJC },
+  { "defs",            RID_AT_DEFS,            D_OBJC },
+  { "encode",          RID_AT_ENCODE,          D_OBJC },
+  { "end",             RID_AT_END,             D_OBJC },
+  { "implementation",  RID_AT_IMPLEMENTATION,  D_OBJC },
+  { "interface",       RID_AT_INTERFACE,       D_OBJC },
+  { "protocol",                RID_AT_PROTOCOL,        D_OBJC },
+  { "selector",                RID_AT_SELECTOR,        D_OBJC },
+  { "finally",         RID_AT_FINALLY,         D_OBJC },
+  { "synchronized",    RID_AT_SYNCHRONIZED,    D_OBJC },
+  /* These are recognized only in protocol-qualifier context.  */
+  { "bycopy",          RID_BYCOPY,             D_OBJC },
+  { "byref",           RID_BYREF,              D_OBJC },
+  { "in",              RID_IN,                 D_OBJC },
+  { "inout",           RID_INOUT,              D_OBJC },
+  { "oneway",          RID_ONEWAY,             D_OBJC },
+  { "out",             RID_OUT,                D_OBJC },
 };
 
 void
@@ -294,9 +334,11 @@ init_reswords (void)
   unsigned int i;
   tree id;
   int mask = ((flag_no_asm ? D_ASM : 0)
-             | (flag_no_gnu_keywords ? D_EXT : 0));
+             | D_OBJC
+             | (flag_no_gnu_keywords ? D_EXT : 0)
+              | ((cxx_dialect == cxx0x) ? 0 : D_CXX0X));
 
-  ridpointers = ggc_calloc ((int) RID_MAX, sizeof (tree));
+  ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX);
   for (i = 0; i < ARRAY_SIZE (reswords); i++)
     {
       id = get_identifier (reswords[i].word);
@@ -319,6 +361,10 @@ init_cp_pragma (void)
   c_register_pragma ("GCC", "java_exceptions", handle_pragma_java_exceptions);
 }
 \f
+/* TRUE if a code represents a statement.  */
+
+bool statement_code_p[MAX_TREE_CODES];
+
 /* Initialize the C++ front end.  This function is very sensitive to
    the exact order that things are done here.  It would be nice if the
    initialization done by this routine were moved to its subroutines,
@@ -326,21 +372,22 @@ init_cp_pragma (void)
 bool
 cxx_init (void)
 {
+  location_t saved_loc;
+  unsigned int i;
   static const enum tree_code stmt_codes[] = {
-    c_common_stmt_codes,
-    cp_stmt_codes
+   CTOR_INITIALIZER,   TRY_BLOCK,      HANDLER,
+   EH_SPEC_BLOCK,      USING_STMT,     TAG_DEFN,
+   IF_STMT,            CLEANUP_STMT,   FOR_STMT,
+   WHILE_STMT,         DO_STMT,        BREAK_STMT,
+   CONTINUE_STMT,      SWITCH_STMT,    EXPR_STMT
   };
 
-  INIT_STATEMENT_CODES (stmt_codes);
+  memset (&statement_code_p, 0, sizeof (statement_code_p));
+  for (i = 0; i < ARRAY_SIZE (stmt_codes); i++)
+    statement_code_p[stmt_codes[i]] = true;
 
-  /* We cannot just assign to input_filename because it has already
-     been initialized and will be used later as an N_BINCL for stabs+
-     debugging.  */
-#ifdef USE_MAPPED_LOCATION
-  push_srcloc (BUILTINS_LOCATION);
-#else
-  push_srcloc ("<built-in>", 0);
-#endif
+  saved_loc = input_location;
+  input_location = BUILTINS_LOCATION;
 
   init_reswords ();
   init_tree ();
@@ -355,40 +402,31 @@ cxx_init (void)
 
   cxx_init_decl_processing ();
 
-  /* Create the built-in __null node.  */
-  null_node = build_int_2 (0, 0);
-  TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0);
-  ridpointers[RID_NULL] = null_node;
-
-  interface_unknown = 1;
+  /* The fact that G++ uses COMDAT for many entities (inline
+     functions, template instantiations, virtual tables, etc.) mean
+     that it is fundamentally unreliable to try to make decisions
+     about whether or not to output a particular entity until the end
+     of the compilation.  However, the inliner requires that functions
+     be provided to the back end if they are to be inlined.
+     Therefore, we always use unit-at-a-time mode; in that mode, we
+     can provide entities to the back end and it will decide what to
+     emit based on what is actually needed.  */
+  flag_unit_at_a_time = 1;
 
   if (c_common_init () == false)
     {
-      pop_srcloc();
+      input_location = saved_loc;
       return false;
     }
 
   init_cp_pragma ();
 
-  init_repo (main_input_filename);
+  init_repo ();
 
-  pop_srcloc();
+  input_location = saved_loc;
   return true;
 }
 \f
-/* Helper function to load global variables with interface
-   information.  */
-
-void
-extract_interface_info (void)
-{
-  struct c_fileinfo *finfo;
-
-  finfo = get_fileinfo (input_filename);
-  interface_only = finfo->interface_only;
-  interface_unknown = finfo->interface_unknown;
-}
-
 /* Return nonzero if S is not considered part of an
    INTERFACE/IMPLEMENTATION pair.  Otherwise, return 0.  */
 
@@ -439,20 +477,19 @@ parse_strconst_pragma (const char* name, int opt)
   tree result, x;
   enum cpp_ttype t;
 
-  t = c_lex (&x);
+  t = pragma_lex (&result);
   if (t == CPP_STRING)
     {
-      result = x;
-      if (c_lex (&x) != CPP_EOF)
-       warning ("junk at end of #pragma %s", name);
+      if (pragma_lex (&x) != CPP_EOF)
+       warning (0, "junk at end of #pragma %s", name);
       return result;
     }
 
   if (t == CPP_EOF && opt)
-    return 0;
+    return NULL_TREE;
 
   error ("invalid #pragma %s", name);
-  return (tree)-1;
+  return error_mark_node;
 }
 
 static void
@@ -474,14 +511,14 @@ handle_pragma_interface (cpp_reader* dfile ATTRIBUTE_UNUSED )
 {
   tree fname = parse_strconst_pragma ("interface", 1);
   struct c_fileinfo *finfo;
-  const char *main_filename;
+  const char *filename;
 
-  if (fname == (tree)-1)
+  if (fname == error_mark_node)
     return;
   else if (fname == 0)
-    main_filename = lbasename (input_filename);
+    filename = lbasename (input_filename);
   else
-    main_filename = TREE_STRING_POINTER (fname);
+    filename = TREE_STRING_POINTER (fname);
 
   finfo = get_fileinfo (input_filename);
 
@@ -493,14 +530,11 @@ handle_pragma_interface (cpp_reader* dfile ATTRIBUTE_UNUSED )
        main_input_filename = input_filename;
     }
 
-  interface_only = interface_strcmp (main_filename);
-#ifdef MULTIPLE_SYMBOL_SPACES
-  if (! interface_only)
-#endif
-    interface_unknown = 0;
-
-  finfo->interface_only = interface_only;
-  finfo->interface_unknown = interface_unknown;
+  finfo->interface_only = interface_strcmp (filename);
+  /* If MULTIPLE_SYMBOL_SPACES is set, we cannot assume that we can see
+     a definition in another file.  */
+  if (!MULTIPLE_SYMBOL_SPACES || !finfo->interface_only)
+    finfo->interface_unknown = 0;
 }
 
 /* Note that we have seen a #pragma implementation for the key MAIN_FILENAME.
@@ -508,44 +542,45 @@ handle_pragma_interface (cpp_reader* dfile ATTRIBUTE_UNUSED )
    in older compilers and it seems reasonable to allow it in the headers
    themselves, too.  It only needs to precede the matching #p interface.
 
-   We don't touch interface_only or interface_unknown; the user must specify
-   a matching #p interface for this to have any effect.  */
+   We don't touch finfo->interface_only or finfo->interface_unknown;
+   the user must specify a matching #p interface for this to have
+   any effect.  */
 
 static void
 handle_pragma_implementation (cpp_reader* dfile ATTRIBUTE_UNUSED )
 {
   tree fname = parse_strconst_pragma ("implementation", 1);
-  const char *main_filename;
+  const char *filename;
   struct impl_files *ifiles = impl_file_chain;
 
-  if (fname == (tree)-1)
+  if (fname == error_mark_node)
     return;
 
   if (fname == 0)
     {
       if (main_input_filename)
-       main_filename = main_input_filename;
+       filename = main_input_filename;
       else
-       main_filename = input_filename;
-      main_filename = lbasename (main_filename);
+       filename = input_filename;
+      filename = lbasename (filename);
     }
   else
     {
-      main_filename = TREE_STRING_POINTER (fname);
-      if (cpp_included (parse_in, main_filename))
-       warning ("#pragma implementation for %s appears after file is included",
-                main_filename);
+      filename = TREE_STRING_POINTER (fname);
+      if (cpp_included_before (parse_in, filename, input_location))
+       warning (0, "#pragma implementation for %qs appears after "
+                "file is included", filename);
     }
 
   for (; ifiles; ifiles = ifiles->next)
     {
-      if (! strcmp (ifiles->filename, main_filename))
+      if (! strcmp (ifiles->filename, filename))
        break;
     }
   if (ifiles == 0)
     {
-      ifiles = xmalloc (sizeof (struct impl_files));
-      ifiles->filename = main_filename;
+      ifiles = XNEW (struct impl_files);
+      ifiles->filename = xstrdup (filename);
       ifiles->next = impl_file_chain;
       impl_file_chain = ifiles;
     }
@@ -553,11 +588,11 @@ handle_pragma_implementation (cpp_reader* dfile ATTRIBUTE_UNUSED )
 
 /* Indicate that this file uses Java-personality exception handling.  */
 static void
-handle_pragma_java_exceptions (cpp_reader* dfile ATTRIBUTE_UNUSED )
+handle_pragma_java_exceptions (cpp_reader* dfile ATTRIBUTE_UNUSED)
 {
   tree x;
-  if (c_lex (&x) != CPP_EOF)
-    warning ("junk at end of #pragma GCC java_exceptions");
+  if (pragma_lex (&x) != CPP_EOF)
+    warning (0, "junk at end of #pragma GCC java_exceptions");
 
   choose_personality_routine (lang_java);
 }
@@ -571,11 +606,11 @@ unqualified_name_lookup_error (tree name)
   if (IDENTIFIER_OPNAME_P (name))
     {
       if (name != ansi_opname (ERROR_MARK))
-       error ("`%D' not defined", name);
+       error ("%qD not defined", name);
     }
   else
     {
-      error ("`%D' was not declared in this scope", name);
+      error ("%qD was not declared in this scope", name);
       /* Prevent repeated error messages by creating a VAR_DECL with
         this NAME in the innermost block scope.  */
       if (current_function_decl)
@@ -584,6 +619,9 @@ unqualified_name_lookup_error (tree name)
          decl = build_decl (VAR_DECL, name, error_mark_node);
          DECL_CONTEXT (decl) = current_function_decl;
          push_local_binding (name, decl, 0);
+         /* Mark the variable as used so that we do not get warnings
+            about it being unused later.  */
+         TREE_USED (decl) = 1;
        }
     }
 
@@ -603,23 +641,23 @@ unqualified_fn_lookup_error (tree name)
         declaration of "f" is available.  Historically, G++ and most
         other compilers accepted that usage since they deferred all name
         lookup until instantiation time rather than doing unqualified
-        name lookup at template definition time; explain to the user what 
+        name lookup at template definition time; explain to the user what
         is going wrong.
 
         Note that we have the exact wording of the following message in
         the manual (trouble.texi, node "Name lookup"), so they need to
         be kept in synch.  */
-      pedwarn ("there are no arguments to `%D' that depend on a template "
-              "parameter, so a declaration of `%D' must be available", 
-              name, name);
-      
+      permerror ("there are no arguments to %qD that depend on a template "
+                "parameter, so a declaration of %qD must be available",
+                name, name);
+
       if (!flag_permissive)
        {
          static bool hint;
          if (!hint)
            {
-             error ("(if you use `-fpermissive', G++ will accept your code, "
-                    "but allowing the use of an undeclared name is "
+             inform ("(if you use %<-fpermissive%>, G++ will accept your "
+                    "code, but allowing the use of an undeclared name is "
                     "deprecated)");
              hint = true;
            }
@@ -638,11 +676,16 @@ build_lang_decl (enum tree_code code, tree name, tree type)
   t = build_decl (code, name, type);
   retrofit_lang_decl (t);
 
+  /* All nesting of C++ functions is lexical; there is never a "static
+     chain" in the sense of GNU C nested functions.  */
+  if (code == FUNCTION_DECL)
+    DECL_NO_STATIC_CHAIN (t) = 1;
+
   return t;
 }
 
 /* Add DECL_LANG_SPECIFIC info to T.  Called from build_lang_decl
-   and pushdecl (for functions generated by the backend).  */
+   and pushdecl (for functions generated by the back end).  */
 
 void
 retrofit_lang_decl (tree t)
@@ -655,7 +698,7 @@ retrofit_lang_decl (tree t)
   else
     size = sizeof (struct lang_decl_flags);
 
-  ld = ggc_alloc_cleared (size);
+  ld = GGC_CNEWVAR (struct lang_decl, size);
 
   ld->decl_flags.can_be_full = CAN_HAVE_FULL_LANG_DECL_P (t) ? 1 : 0;
   ld->decl_flags.u1sel = TREE_CODE (t) == NAMESPACE_DECL ? 1 : 0;
@@ -671,7 +714,8 @@ retrofit_lang_decl (tree t)
     SET_DECL_LANGUAGE (t, lang_c);
   else if (current_lang_name == lang_name_java)
     SET_DECL_LANGUAGE (t, lang_java);
-  else abort ();
+  else
+    gcc_unreachable ();
 
 #ifdef GATHER_STATISTICS
   tree_node_counts[(int)lang_decl] += 1;
@@ -692,7 +736,7 @@ cxx_dup_lang_specific_decl (tree node)
     size = sizeof (struct lang_decl_flags);
   else
     size = sizeof (struct lang_decl);
-  ld = ggc_alloc (size);
+  ld = GGC_NEWVAR (struct lang_decl, size);
   memcpy (ld, DECL_LANG_SPECIFIC (node), size);
   DECL_LANG_SPECIFIC (node) = ld;
 
@@ -729,7 +773,7 @@ copy_lang_type (tree node)
     size = sizeof (struct lang_type);
   else
     size = sizeof (struct lang_type_ptrmem);
-  lt = ggc_alloc (size);
+  lt = GGC_NEWVAR (struct lang_type, size);
   memcpy (lt, TYPE_LANG_SPECIFIC (node), size);
   TYPE_LANG_SPECIFIC (node) = lt;
 
@@ -757,12 +801,10 @@ cxx_make_type (enum tree_code code)
   tree t = make_node (code);
 
   /* Create lang_type structure.  */
-  if (IS_AGGR_TYPE_CODE (code)
+  if (RECORD_OR_UNION_CODE_P (code)
       || code == BOUND_TEMPLATE_TEMPLATE_PARM)
     {
-      struct lang_type *pi;
-
-      pi = ggc_alloc_cleared (sizeof (struct lang_type));
+      struct lang_type *pi = GGC_CNEW (struct lang_type);
 
       TYPE_LANG_SPECIFIC (t) = pi;
       pi->u.c.h.is_lang_type_class = 1;
@@ -774,51 +816,35 @@ cxx_make_type (enum tree_code code)
     }
 
   /* Set up some flags that give proper default behavior.  */
-  if (IS_AGGR_TYPE_CODE (code))
+  if (RECORD_OR_UNION_CODE_P (code))
     {
-      SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
-      CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
-
-      /* Make sure this is laid out, for ease of use later.  In the
-        presence of parse errors, the normal was of assuring this
-        might not ever get executed, so we lay it out *immediately*.  */
-      build_pointer_type (t);
-
-      TYPE_BINFO (t) = make_binfo (size_zero_node, t, NULL_TREE, NULL_TREE);
+      struct c_fileinfo *finfo = get_fileinfo (input_filename);
+      SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, finfo->interface_unknown);
+      CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
     }
-  else
-    /* We use TYPE_ALIAS_SET for the CLASSTYPE_MARKED bits.  But,
-       TYPE_ALIAS_SET is initialized to -1 by default, so we must
-       clear it here.  */
-    TYPE_ALIAS_SET (t) = 0;
 
   return t;
 }
 
 tree
-make_aggr_type (enum tree_code code)
+make_class_type (enum tree_code code)
 {
   tree t = cxx_make_type (code);
-
-  if (IS_AGGR_TYPE_CODE (code))
-    SET_IS_AGGR_TYPE (t, 1);
-
+  SET_CLASS_TYPE_P (t, 1);
   return t;
 }
 
-/* Return the type-qualifier corresponding to the identifier given by
-   RID.  */
+/* Returns true if we are currently in the main source file, or in a
+   template instantiation started from the main source file.  */
 
-int
-cp_type_qual_from_rid (tree rid)
+bool
+in_main_input_context (void)
 {
-  if (rid == ridpointers[(int) RID_CONST])
-    return TYPE_QUAL_CONST;
-  else if (rid == ridpointers[(int) RID_VOLATILE])
-    return TYPE_QUAL_VOLATILE;
-  else if (rid == ridpointers[(int) RID_RESTRICT])
-    return TYPE_QUAL_RESTRICT;
-
-  abort ();
-  return TYPE_UNQUALIFIED;
+  struct tinst_level *tl = outermost_tinst_level();
+
+  if (tl)
+    return strcmp (main_input_filename,
+                  LOCATION_FILE (tl->locus)) == 0;
+  else
+    return strcmp (main_input_filename, input_filename) == 0;
 }