diff mbox

wide-int, gengtype

Message ID 9995BD70-E5F5-4B1F-8B48-90A238D740ED@comcast.net
State New
Headers show

Commit Message

Mike Stump Jan. 2, 2014, 3:58 a.m. UTC
On Nov 23, 2013, at 11:21 AM, Mike Stump <mikestump@comcast.net> wrote:
> Richi has asked the we break the wide-int patch so that the individual port and front end maintainers can review their parts without have to go through the entire patch.    This patch covers the gengtype code.
> 
> Ok?

Ping?

We'll need a global reviewer to step forward if the gty maintainer doesn't have the time.  If no one is at one with the code, then I'd ask the SC to solicit such an additional person to become maintainer.
* gengtype.c: Remove include of double-int.h.
	(do_typedef): Use wide-int interfaces.
	(open_base_files): Add wide-int.h.
	(main): Add offset_int and widest_int typedefs.
	* gengtype-lex.l: Handle "^".
	(CXX_KEYWORD): Add "static".
	* gengtype-parse.c
	(require3): New.
	(require_template_declaration): Handle constant template arguments
	and nested templates.
	* gengtype-state.c: Don't include "double-int.h".
diff mbox

Patch

diff --git a/gcc/gengtype.c b/gcc/gengtype.c
index 86e9ca2..0c0195c 100644
--- a/gcc/gengtype.c
+++ b/gcc/gengtype.c
@@ -25,7 +25,6 @@ 
 #include "system.h"
 #include "errors.h"		/* for fatal */
 #include "getopt.h"
-#include "double-int.h"
 #include "version.h"		/* for version_string & pkgversion_string.  */
 #include "hashtab.h"
 #include "xregex.h"
@@ -535,7 +534,7 @@  do_typedef (const char *s, type_p t, struct fileloc *pos)
   for (p = typedefs; p != NULL; p = p->next)
     if (strcmp (p->name, s) == 0)
       {
-	if (p->type != t)
+	if (p->type != t && strcmp (s, "result_type") != 0)
 	  {
 	    error_at_line (pos, "type `%s' previously defined", s);
 	    error_at_line (&p->line, "previously defined here");
@@ -1766,7 +1765,7 @@  open_base_files (void)
     static const char *const ifiles[] = {
       "config.h", "system.h", "coretypes.h", "tm.h",
       "hashtab.h", "splay-tree.h", "obstack.h", "bitmap.h", "input.h",
-      "tree.h", "rtl.h", "function.h", "insn-config.h", "expr.h",
+      "tree.h", "rtl.h", "wide-int.h", "function.h", "insn-config.h", "expr.h",
       "hard-reg-set.h", "basic-block.h", "cselib.h", "insn-addr.h",
       "optabs.h", "libfuncs.h", "debug.h", "ggc.h", "cgraph.h",
       "gimple.h", "gimple-iterator.h", "gimple-ssa.h", "tree-cfg.h",
@@ -5633,6 +5632,8 @@  main (int argc, char **argv)
       POS_HERE (do_scalar_typedef ("REAL_VALUE_TYPE", &pos));
       POS_HERE (do_scalar_typedef ("FIXED_VALUE_TYPE", &pos));
       POS_HERE (do_scalar_typedef ("double_int", &pos));
+      POS_HERE (do_scalar_typedef ("offset_int", &pos));
+      POS_HERE (do_scalar_typedef ("widest_int", &pos));
       POS_HERE (do_scalar_typedef ("uint64_t", &pos));
       POS_HERE (do_scalar_typedef ("uint8", &pos));
       POS_HERE (do_scalar_typedef ("uintptr_t", &pos));
diff --git a/gcc/gengtype-lex.l b/gcc/gengtype-lex.l
index f46cd17..7ece2ab 100644
--- a/gcc/gengtype-lex.l
+++ b/gcc/gengtype-lex.l
@@ -57,7 +57,7 @@  ITYPE	{IWORD}({WS}{IWORD})*
     /* Include '::' in identifiers to capture C++ scope qualifiers.  */
 ID	{CID}({HWS}::{HWS}{CID})*
 EOID	[^[:alnum:]_]
-CXX_KEYWORD inline|public:|private:|protected:|template|operator|friend
+CXX_KEYWORD inline|public:|private:|protected:|template|operator|friend|static
 
 %x in_struct in_struct_comment in_comment
 %option warn noyywrap nounput nodefault perf-report
@@ -110,6 +110,7 @@  CXX_KEYWORD inline|public:|private:|protected:|template|operator|friend
 "const"/{EOID}			/* don't care */
 {CXX_KEYWORD}/{EOID}			|
 "~"					|
+"^"					|
 "&"					{
     *yylval = XDUPVAR (const char, yytext, yyleng, yyleng + 1);
     return IGNORABLE_CXX_KEYWORD;
diff --git a/gcc/gengtype-parse.c b/gcc/gengtype-parse.c
index 8328e3a..0a58822 100644
--- a/gcc/gengtype-parse.c
+++ b/gcc/gengtype-parse.c
@@ -197,6 +197,23 @@  require2 (int t1, int t2)
   return v;
 }
 
+/* If the next token does not have one of the codes T1, T2 or T3, report a
+   parse error; otherwise return the token's value.  */
+static const char *
+require3 (int t1, int t2, int t3)
+{
+  int u = token ();
+  const char *v = advance ();
+  if (u != t1 && u != t2 && u != t3)
+    {
+      parse_error ("expected %s, %s or %s, have %s",
+		   print_token (t1, 0), print_token (t2, 0),
+		   print_token (t3, 0), print_token (u, v));
+      return 0;
+    }
+  return v;
+}
+
 /* Near-terminals.  */
 
 /* C-style string constant concatenation: STRING+
@@ -243,18 +260,45 @@  require_template_declaration (const char *tmpl_name)
   str = concat (tmpl_name, "<", (char *) 0);
 
   /* Read the comma-separated list of identifiers.  */
-  while (token () != '>')
+  int depth = 1;
+  while (depth > 0)
     {
-      const char *id = require2 (ID, ',');
+      if (token () == ENUM)
+	{
+	  advance ();
+	  str = concat (str, "enum ", (char *) 0);
+	  continue;
+	}
+      if (token () == NUM)
+	{
+	  str = concat (str, advance (), (char *) 0);
+	  continue;
+	}
+      if (token () == ':')
+	{
+	  advance ();
+	  str = concat (str, ":", (char *) 0);
+	  continue;
+	}
+      if (token () == '<')
+	{
+	  advance ();
+	  str = concat (str, "<", (char *) 0);
+	  depth += 1;
+	  continue;
+	}
+      if (token () == '>')
+	{
+	  advance ();
+	  str = concat (str, ">", (char *) 0);
+	  depth -= 1;
+	  continue;
+	}
+      const char *id = require3 (SCALAR, ID, ',');
       if (id == NULL)
 	id = ",";
       str = concat (str, id, (char *) 0);
     }
-
-  /* Recognize the closing '>'.  */
-  require ('>');
-  str = concat (str, ">", (char *) 0);
-
   return str;
 }
 
diff --git a/gcc/gengtype-state.c b/gcc/gengtype-state.c
index fda473a..ed61375 100644
--- a/gcc/gengtype-state.c
+++ b/gcc/gengtype-state.c
@@ -30,7 +30,6 @@ 
 #endif
 #include "system.h"
 #include "errors.h"	/* For fatal.  */
-#include "double-int.h"
 #include "hashtab.h"
 #include "version.h"	/* For version_string & pkgversion_string.  */
 #include "obstack.h"