diff libcpp/directives.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
line wrap: on
line diff
--- a/libcpp/directives.c	Thu Oct 25 07:37:49 2018 +0900
+++ b/libcpp/directives.c	Thu Feb 13 11:34:05 2020 +0900
@@ -1,5 +1,5 @@
 /* CPP Library. (Directive handling.)
-   Copyright (C) 1986-2018 Free Software Foundation, Inc.
+   Copyright (C) 1986-2020 Free Software Foundation, Inc.
    Contributed by Per Bothner, 1994-95.
    Based on CCCP program by Paul Rubin, June 1986
    Adapted to ANSI C, Richard Stallman, Jan 1987
@@ -30,7 +30,7 @@
 struct if_stack
 {
   struct if_stack *next;
-  source_location line;		/* Line where condition started.  */
+  location_t line;		/* Line where condition started.  */
   const cpp_hashnode *mi_cmacro;/* macro name for #ifndef around entire file */
   bool skip_elses;		/* Can future #else / #elif be skipped?  */
   bool was_skipping;		/* If were skipping on entry.  */
@@ -98,7 +98,7 @@
 static void run_directive (cpp_reader *, int, const char *, size_t);
 static char *glue_header_name (cpp_reader *);
 static const char *parse_include (cpp_reader *, int *, const cpp_token ***,
-				  source_location *);
+				  location_t *);
 static void push_conditional (cpp_reader *, int, int, const cpp_hashnode *);
 static unsigned int read_flag (cpp_reader *, unsigned int);
 static bool strtolinenum (const uchar *, size_t, linenum_type *, bool *);
@@ -124,8 +124,8 @@
 static const cpp_token *get_token_no_padding (cpp_reader *);
 static const cpp_token *get__Pragma_string (cpp_reader *);
 static void destringize_and_run (cpp_reader *, const cpp_string *,
-				 source_location);
-static bool parse_answer (cpp_reader *, int, source_location, cpp_macro **);
+				 location_t);
+static bool parse_answer (cpp_reader *, int, location_t, cpp_macro **);
 static cpp_hashnode *parse_assertion (cpp_reader *, int, cpp_macro **);
 static cpp_macro **find_answer (cpp_hashnode *, const cpp_macro *);
 static void handle_assertion (cpp_reader *, const char *, int);
@@ -133,35 +133,30 @@
 static void do_pragma_pop_macro (cpp_reader *);
 static void cpp_pop_definition (cpp_reader *, struct def_pragma_macro *);
 
-/* This is the table of directive handlers.  It is ordered by
-   frequency of occurrence; the numbers at the end are directive
-   counts from all the source code I have lying around (egcs and libc
-   CVS as of 1999-05-18, plus grub-0.5.91, linux-2.2.9, and
-   pcmcia-cs-3.0.9).  This is no longer important as directive lookup
-   is now O(1).  All extensions other than #warning, #include_next,
-   and #import are deprecated.  The name is where the extension
-   appears to have come from.  */
+/* This is the table of directive handlers.  All extensions other than
+   #warning, #include_next, and #import are deprecated.  The name is
+   where the extension appears to have come from.  */
 
 #define DIRECTIVE_TABLE							\
-D(define,	T_DEFINE = 0,	KANDR,     IN_I)	   /* 270554 */ \
-D(include,	T_INCLUDE,	KANDR,     INCL | EXPAND)  /*  52262 */ \
-D(endif,	T_ENDIF,	KANDR,     COND)	   /*  45855 */ \
-D(ifdef,	T_IFDEF,	KANDR,     COND | IF_COND) /*  22000 */ \
-D(if,		T_IF,		KANDR, COND | IF_COND | EXPAND) /*  18162 */ \
-D(else,		T_ELSE,		KANDR,     COND)	   /*   9863 */ \
-D(ifndef,	T_IFNDEF,	KANDR,     COND | IF_COND) /*   9675 */ \
-D(undef,	T_UNDEF,	KANDR,     IN_I)	   /*   4837 */ \
-D(line,		T_LINE,		KANDR,     EXPAND)	   /*   2465 */ \
-D(elif,		T_ELIF,		STDC89,    COND | EXPAND)  /*    610 */ \
-D(error,	T_ERROR,	STDC89,    0)		   /*    475 */ \
-D(pragma,	T_PRAGMA,	STDC89,    IN_I)	   /*    195 */ \
-D(warning,	T_WARNING,	EXTENSION, 0)		   /*     22 */ \
-D(include_next,	T_INCLUDE_NEXT,	EXTENSION, INCL | EXPAND)  /*     19 */ \
-D(ident,	T_IDENT,	EXTENSION, IN_I)           /*     11 */ \
-D(import,	T_IMPORT,	EXTENSION, INCL | EXPAND)  /* 0 ObjC */	\
-D(assert,	T_ASSERT,	EXTENSION, DEPRECATED)	   /* 0 SVR4 */	\
-D(unassert,	T_UNASSERT,	EXTENSION, DEPRECATED)	   /* 0 SVR4 */	\
-D(sccs,		T_SCCS,		EXTENSION, IN_I)           /* 0 SVR4? */
+  D(define,	T_DEFINE = 0,	KANDR,     IN_I)			\
+  D(include,	T_INCLUDE,	KANDR,     INCL | EXPAND)		\
+  D(endif,	T_ENDIF,	KANDR,     COND)			\
+  D(ifdef,	T_IFDEF,	KANDR,     COND | IF_COND)		\
+  D(if,		T_IF,		KANDR, 	   COND | IF_COND | EXPAND) 	\
+  D(else,	T_ELSE,		KANDR,     COND)	   		\
+  D(ifndef,	T_IFNDEF,	KANDR,     COND | IF_COND)		\
+  D(undef,	T_UNDEF,	KANDR,     IN_I)			\
+  D(line,	T_LINE,		KANDR,     EXPAND)			\
+  D(elif,	T_ELIF,		STDC89,    COND | EXPAND)		\
+  D(error,	T_ERROR,	STDC89,    0)				\
+  D(pragma,	T_PRAGMA,	STDC89,    IN_I)			\
+  D(warning,	T_WARNING,	EXTENSION, 0)				\
+  D(include_next, T_INCLUDE_NEXT, EXTENSION, INCL | EXPAND)		\
+  D(ident,	T_IDENT,	EXTENSION, IN_I)			\
+  D(import,	T_IMPORT,	EXTENSION, INCL | EXPAND)  /* ObjC */	\
+  D(assert,	T_ASSERT,	EXTENSION, DEPRECATED)	   /* SVR4 */	\
+  D(unassert,	T_UNASSERT,	EXTENSION, DEPRECATED)	   /* SVR4 */	\
+  D(sccs,	T_SCCS,		EXTENSION, IN_I)   	   /*  SVR4? */
 
 /* #sccs is synonymous with #ident.  */
 #define do_sccs do_ident
@@ -209,8 +204,6 @@
   do_linemarker, UC"#", 1, KANDR, IN_I
 };
 
-#define SEEN_EOL() (pfile->cur_token[-1].type == CPP_EOF)
-
 /* Skip any remaining tokens in a directive.  */
 static void
 skip_rest_of_line (cpp_reader *pfile)
@@ -413,13 +406,13 @@
     }
 }
 
-/* Check if we have a known directive.  INDENTED is nonzero if the
+/* Check if we have a known directive.  INDENTED is true if the
    '#' of the directive was indented.  This function is in this file
    to save unnecessarily exporting dtable etc. to lex.c.  Returns
    nonzero if the line of tokens has been handled, zero if we should
    continue processing the line.  */
 int
-_cpp_handle_directive (cpp_reader *pfile, int indented)
+_cpp_handle_directive (cpp_reader *pfile, bool indented)
 {
   const directive *dir = 0;
   const cpp_token *dname;
@@ -602,14 +595,11 @@
     {
       cpp_hashnode *node = token->val.node.node;
 
-      if (is_def_or_undef && node == pfile->spec_nodes.n_defined)
+      if (is_def_or_undef
+	  && node == pfile->spec_nodes.n_defined)
 	cpp_error (pfile, CPP_DL_ERROR,
-		   "\"defined\" cannot be used as a macro name");
-      else if (is_def_or_undef
-	    && (node == pfile->spec_nodes.n__has_include__
-	     || node == pfile->spec_nodes.n__has_include_next__))
-	cpp_error (pfile, CPP_DL_ERROR,
-		   "\"__has_include__\" cannot be used as a macro name");
+		   "\"%s\" cannot be used as a macro name",
+		   NODE_NAME (node));
       else if (! (node->flags & NODE_POISONED))
 	return node;
     }
@@ -761,7 +751,7 @@
 
 static const char *
 parse_include (cpp_reader *pfile, int *pangle_brackets,
-	       const cpp_token ***buf, source_location *location)
+	       const cpp_token ***buf, location_t *location)
 {
   char *fname;
   const cpp_token *header;
@@ -819,34 +809,36 @@
   const char *fname;
   int angle_brackets;
   const cpp_token **buf = NULL;
-  source_location location;
+  location_t location;
 
   /* Re-enable saving of comments if requested, so that the include
      callback can dump comments which follow #include.  */
   pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
 
+  /* Tell the lexer this is an include directive -- we want it to
+     increment the line number even if this is the last line of a file.  */
+  pfile->state.in_directive = 2;
+
   fname = parse_include (pfile, &angle_brackets, &buf, &location);
   if (!fname)
-    {
-      if (buf)
-	XDELETEVEC (buf);
-      return;
-    }
+    goto done;
 
   if (!*fname)
-  {
-    cpp_error_with_line (pfile, CPP_DL_ERROR, location, 0,
-			 "empty filename in #%s",
-			 pfile->directive->name);
-    XDELETEVEC (fname);
-    if (buf)
-      XDELETEVEC (buf);
-    return;
-  }
+    {
+      cpp_error_with_line (pfile, CPP_DL_ERROR, location, 0,
+			   "empty filename in #%s",
+			   pfile->directive->name);
+      goto done;
+    }
 
   /* Prevent #include recursion.  */
-  if (pfile->line_table->depth >= CPP_STACK_MAX)
-    cpp_error (pfile, CPP_DL_ERROR, "#include nested too deeply");
+  if (pfile->line_table->depth >= CPP_OPTION (pfile, max_include_depth))
+    cpp_error (pfile, 
+	       CPP_DL_ERROR, 
+	       "#include nested depth %u exceeds maximum of %u"
+	       " (use -fmax-include-depth=DEPTH to increase the maximum)",
+	       pfile->line_table->depth,
+	       CPP_OPTION (pfile, max_include_depth));
   else
     {
       /* Get out of macro context, if we are.  */
@@ -860,6 +852,7 @@
       _cpp_stack_include (pfile, fname, angle_brackets, type, location);
     }
 
+ done:
   XDELETEVEC (fname);
   if (buf)
     XDELETEVEC (buf);
@@ -951,7 +944,7 @@
 static void
 do_line (cpp_reader *pfile)
 {
-  struct line_maps *line_table = pfile->line_table;
+  class line_maps *line_table = pfile->line_table;
   const line_map_ordinary *map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
 
   /* skip_rest_of_line() may cause line table to be realloc()ed so note down
@@ -1014,7 +1007,7 @@
 static void
 do_linemarker (cpp_reader *pfile)
 {
-  struct line_maps *line_table = pfile->line_table;
+  class line_maps *line_table = pfile->line_table;
   const line_map_ordinary *map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
   const cpp_token *token;
   const char *new_file = ORDINARY_MAP_FILE_NAME (map);
@@ -1092,9 +1085,17 @@
       map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
       const line_map_ordinary *from
 	= linemap_included_from_linemap (line_table, map);
-      if (MAIN_FILE_P (map)
-	  || (from
-	      && filename_cmp (ORDINARY_MAP_FILE_NAME (from), new_file) != 0))
+
+      if (!from)
+	/* Not nested.  */;
+      else if (!new_file[0])
+	/* Leaving to "" means fill in the popped-to name.  */
+	new_file = ORDINARY_MAP_FILE_NAME (from);
+      else if (filename_cmp (ORDINARY_MAP_FILE_NAME (from), new_file) != 0)
+	/* It's the wrong name, Grommit!  */
+	from = NULL;
+
+      if (!from)
 	{
 	  cpp_warning (pfile, CPP_W_NONE,
 		       "file \"%s\" linemarker ignored due to "
@@ -1102,9 +1103,10 @@
 	  return;
 	}
     }
+
   /* Compensate for the increment in linemap_add that occurs in
      _cpp_do_file_change.  We're currently at the start of the line
-     *following* the #line directive.  A separate source_location for this
+     *following* the #line directive.  A separate location_t for this
      location makes no sense (until we do the LC_LEAVE), and
      complicates LAST_SOURCE_LINE_LOCATION.  */
   pfile->line_table->highest_location--;
@@ -1146,7 +1148,7 @@
 {
   const unsigned char *dir_name;
   unsigned char *line;
-  source_location src_loc = pfile->cur_token[-1].src_loc;
+  location_t src_loc = pfile->cur_token[-1].src_loc;
 
   if (print_dir)
     dir_name = pfile->directive->name;
@@ -1443,7 +1445,7 @@
 {
   const struct pragma_entry *p = NULL;
   const cpp_token *token, *pragma_token;
-  source_location pragma_token_virt_loc = 0;
+  location_t pragma_token_virt_loc = 0;
   cpp_token ns_token;
   unsigned int count = 1;
 
@@ -1549,7 +1551,7 @@
   txt = get__Pragma_string (pfile);
   if (!txt)
     {
-      source_location src_loc = pfile->cur_token[-1].src_loc;
+      location_t src_loc = pfile->cur_token[-1].src_loc;
       cpp_error_with_line (pfile, CPP_DL_ERROR, src_loc, 0,
 		 "invalid #pragma push_macro directive");
       check_eol (pfile, false);
@@ -1577,6 +1579,8 @@
   node = _cpp_lex_identifier (pfile, c->name);
   if (node->type == NT_VOID)
     c->is_undef = 1;
+  else if (node->type == NT_BUILTIN_MACRO)
+    c->is_builtin = 1;
   else
     {
       defn = cpp_macro_definition (pfile, node);
@@ -1604,7 +1608,7 @@
   txt = get__Pragma_string (pfile);
   if (!txt)
     {
-      source_location src_loc = pfile->cur_token[-1].src_loc;
+      location_t src_loc = pfile->cur_token[-1].src_loc;
       cpp_error_with_line (pfile, CPP_DL_ERROR, src_loc, 0,
 		 "invalid #pragma pop_macro directive");
       check_eol (pfile, false);
@@ -1706,7 +1710,7 @@
 {
   const char *fname;
   int angle_brackets, ordering;
-  source_location location;
+  location_t location;
 
   fname = parse_include (pfile, &angle_brackets, NULL, &location);
   if (!fname)
@@ -1812,7 +1816,7 @@
    \" and \\ sequences, and process the result as a #pragma directive.  */
 static void
 destringize_and_run (cpp_reader *pfile, const cpp_string *in,
-		     source_location expansion_loc)
+		     location_t expansion_loc)
 {
   const unsigned char *src, *limit;
   char *dest, *result;
@@ -1932,7 +1936,7 @@
 
 /* Handle the _Pragma operator.  Return 0 on error, 1 if ok.  */
 int
-_cpp_do__Pragma (cpp_reader *pfile, source_location expansion_loc)
+_cpp_do__Pragma (cpp_reader *pfile, location_t expansion_loc)
 {
   const cpp_token *string = get__Pragma_string (pfile);
   pfile->directive_result.type = CPP_PADDING;
@@ -1959,11 +1963,7 @@
 
       if (node)
 	{
-	  /* Do not treat conditional macros as being defined.  This is due to
-	     the powerpc and spu ports using conditional macros for 'vector',
-	     'bool', and 'pixel' to act as conditional keywords.  This messes
-	     up tests like #ifndef bool.  */
-	  skip = !cpp_macro_p (node) || (node->flags & NODE_CONDITIONAL);
+	  skip = !_cpp_defined_macro_p (node);
 	  _cpp_mark_macro_used (node);
 	  _cpp_maybe_notify_macro_use (pfile, node);
 	  if (pfile->cb.used)
@@ -1989,11 +1989,10 @@
       if (node)
 	{
 	  /* Do not treat conditional macros as being defined.  This is due to
-	     the powerpc and spu ports using conditional macros for 'vector',
-	     'bool', and 'pixel' to act as conditional keywords.  This messes
-	     up tests like #ifndef bool.  */
-	  skip = (cpp_macro_p (node)
-		  && !(node->flags & NODE_CONDITIONAL));
+	     the powerpc port using conditional macros for 'vector', 'bool',
+	     and 'pixel' to act as conditional keywords.  This messes up tests
+	     like #ifndef bool.  */
+	  skip = _cpp_defined_macro_p (node);
 	  _cpp_mark_macro_used (node);
 	  _cpp_maybe_notify_macro_use (pfile, node);
 	  if (pfile->cb.used)
@@ -2153,7 +2152,7 @@
    ANSWERP to point to the answer.  PRED_LOC is the location of the
    predicate.  */
 static bool
-parse_answer (cpp_reader *pfile, int type, source_location pred_loc,
+parse_answer (cpp_reader *pfile, int type, location_t pred_loc,
 	      cpp_macro **answer_ptr)
 {
   /* In a conditional, it is legal to not have an open paren.  We
@@ -2465,6 +2464,11 @@
 
   if (c->is_undef)
     return;
+  if (c->is_builtin)
+    {
+      _cpp_restore_special_builtin (pfile, c);
+      return;
+    }
 
   {
     size_t namelen;
@@ -2552,7 +2556,7 @@
 }
 
 /* The dependencies structure.  (Creates one if it hasn't already been.)  */
-struct deps *
+class mkdeps *
 cpp_get_deps (cpp_reader *pfile)
 {
   if (!pfile->deps)
@@ -2618,18 +2622,17 @@
 
       _cpp_do_file_change (pfile, LC_LEAVE, 0, 0, 0);
     }
+  else if (to_free)
+    free ((void *)to_free);
 }
 
 /* Enter all recognized directives in the hash table.  */
 void
 _cpp_init_directives (cpp_reader *pfile)
 {
-  unsigned int i;
-  cpp_hashnode *node;
-
-  for (i = 0; i < (unsigned int) N_DIRECTIVES; i++)
+  for (int i = 0; i < N_DIRECTIVES; i++)
     {
-      node = cpp_lookup (pfile, dtable[i].name, dtable[i].length);
+      cpp_hashnode *node = cpp_lookup (pfile, dtable[i].name, dtable[i].length);
       node->is_directive = 1;
       node->directive_index = i;
     }