summaryrefslogtreecommitdiff
path: root/gcc/gengtype-lex.l
diff options
context:
space:
mode:
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2007-03-26 21:18:43 +0000
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2007-03-26 21:18:43 +0000
commit1e8375615ba6d4322a5c6c637c799f27695eedcb (patch)
tree92672610b9effb039afa4b4273d36d385aff54d8 /gcc/gengtype-lex.l
parent570af75a16610c2ff3fe4591de6498eb24d52112 (diff)
downloadgcc-1e8375615ba6d4322a5c6c637c799f27695eedcb.tar.gz
* gengtype-parse.c: New file.
* gengtype-yacc.y: Delete. * gengtype-lex.l: Don't include gengtype-yacc.h. Define YY_DECL and yyterminate appropriately for recursive descent parser. yylval is now a string out-parameter to yylex. (HWS, EOID): New shorthand. (IWORD): Add a couple more types. (yylex): Add a setup stanza. Remove the complex rules for detecting GTY'ed types and typedefs; replace with simple keyword detectors. Adjust everything for the changed definition of yylval. Ignore all pp-directives, not just #define. (yyerror): Delete. (parse_file): Rename yybegin; do not call yyparse. (yyend): New. * gengtype.c (xasprintf): Export again. (this_file): New. Use everywhere __FILE__ was being used. (get_lang_bitmap): Special case types defined in gengtype.c. (do_typedef, new_structure): Suppress definition of certain types. (new_structure): Improve diagnostics of duplicate definitions. Make sure location_s is associated with input.h. (nreverse_pairs, define_location_structures): New functions. (main): Improve tagging of kludge types. Remove old kludges for input.h types; use define_location_structures. * gengtype.h: Update prototypes. Define token codes here. * Makefile.in: Remove all references to gengtype-yacc. Add rules for gengtype-parse.o. Adjust rules for gengtype-lex.o and gengtype. * bitmap.h (struct bitmap_head_def): Coalesce definitions, add GTY((skip)) to the field that's only conditionally there. * doc/install.texi: Document that Bison is no longer required unless building treelang. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@123235 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/gengtype-lex.l')
-rw-r--r--gcc/gengtype-lex.l284
1 files changed, 68 insertions, 216 deletions
diff --git a/gcc/gengtype-lex.l b/gcc/gengtype-lex.l
index baf09bcd5fe..2d003e0c5fa 100644
--- a/gcc/gengtype-lex.l
+++ b/gcc/gengtype-lex.l
@@ -27,7 +27,9 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
#define realloc xrealloc
#include "gengtype.h"
-#include "gengtype-yacc.h"
+
+#define YY_DECL int yylex (const char **yylval)
+#define yyterminate() return EOF_TOKEN
struct fileloc lexer_line;
int lexer_toplevel_done;
@@ -44,199 +46,58 @@ update_lineno (const char *l, size_t len)
ID [[:alpha:]_][[:alnum:]_]*
WS [[:space:]]+
-IWORD short|long|(un)?signed|char|int|HOST_WIDE_INT|HOST_WIDEST_INT|bool|size_t|BOOL_BITFIELD
+HWS [ \t\r\v\f]*
+IWORD short|long|(un)?signed|char|int|HOST_WIDE_INT|HOST_WIDEST_INT|bool|size_t|BOOL_BITFIELD|CPPCHAR_SIGNED_T|ino_t|dev_t
ITYPE {IWORD}({WS}{IWORD})*
+EOID [^[:alnum:]_]
%x in_struct in_struct_comment in_comment
%option warn noyywrap nounput nodefault perf-report
%option 8bit never-interactive
%%
+ /* Do this on entry to yylex(): */
+ *yylval = 0;
+ if (lexer_toplevel_done)
+ {
+ BEGIN(INITIAL);
+ lexer_toplevel_done = 0;
+ }
-[^[:alnum:]_]typedef{WS}(struct|union){WS}{ID}{WS}?[*[:space:]]{WS}?{ID}{WS}?";" {
- char *tagstart;
- size_t taglen;
- char *namestart;
- size_t namelen;
- int is_pointer = 0;
- struct type *t;
- int union_p;
-
- tagstart = yytext + strlen (" typedef ");
- while (ISSPACE (*tagstart))
- tagstart++;
- union_p = tagstart[0] == 'u';
- tagstart += strlen ("union ");
- while (ISSPACE (*tagstart))
- tagstart++;
- for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
- ;
- for (namestart = tagstart + taglen;
- ! ISIDNUM (*namestart);
- namestart++)
- if (*namestart == '*')
- is_pointer = 1;
- for (namelen = 1; ISIDNUM (namestart[namelen]); namelen++)
- ;
- t = find_structure ((const char *) xmemdup (tagstart, taglen, taglen+1),
- union_p);
- if (is_pointer)
- t = create_pointer (t);
- namestart = (char *) xmemdup (namestart, namelen, namelen+1);
-#ifdef USE_MAPPED_LOCATION
- /* temporary kludge - gentype doesn't handle cpp conditionals */
- if (strcmp (namestart, "location_t") != 0
- && strcmp (namestart, "expanded_location") != 0)
-#endif
- do_typedef (namestart, t, &lexer_line);
- update_lineno (yytext, yyleng);
+ /* Things we look for in skipping mode: */
+<INITIAL>{
+^typedef/{EOID} {
+ BEGIN(in_struct);
+ return TYPEDEF;
}
-
-[^[:alnum:]_]typedef{WS}{ITYPE}{WS}{ID}{WS}?";" {
-
- char *namestart;
- size_t namelen;
- char *typestart;
- size_t typelen;
-
- for (namestart = yytext + yyleng - 2; ISSPACE (*namestart); namestart--)
- ;
- for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
- ;
- namestart -= namelen - 1;
- for (typestart = yytext + strlen (" typedef ");
- ISSPACE(*typestart);
- typestart++)
- ;
- for (typelen = namestart - typestart;
- ISSPACE (typestart[typelen-1]);
- typelen--)
- ;
- typestart[typelen] = '\0';
-
- do_typedef ((const char *) xmemdup (namestart, namelen, namelen+1),
- create_scalar_type (typestart),
- &lexer_line);
- update_lineno (yytext, yyleng);
+^struct/{EOID} {
+ BEGIN(in_struct);
+ return STRUCT;
}
-
-[^[:alnum:]_]typedef{WS}{ID}{WS}{ID}{WS}"(" {
- char *namestart;
- size_t namelen;
-
- for (namestart = yytext + yyleng - 2; ISSPACE (*namestart); namestart--)
- ;
- for (namelen = 1; !ISSPACE (namestart[-namelen]); namelen++)
- ;
- namestart -= namelen - 1;
-
- do_scalar_typedef ((const char *) xmemdup (namestart, namelen, namelen+1),
- &lexer_line);
- update_lineno (yytext, yyleng);
+^union/{EOID} {
+ BEGIN(in_struct);
+ return UNION;
}
-
-[^[:alnum:]_]typedef{WS}{ID}{WS}?"*"?{WS}?"("{WS}?"*"{WS}?{ID}{WS}?")"{WS}?"(" {
- char *namestart;
- size_t namelen;
-
- for (namestart = yytext + yyleng - 2; !ISIDNUM (*namestart); namestart--)
- ;
- for (namelen = 1; ISIDNUM (namestart[-namelen]); namelen++)
- ;
- namestart -= namelen - 1;
-
- do_scalar_typedef ((const char *) xmemdup (namestart, namelen, namelen+1),
- &lexer_line);
- update_lineno (yytext, yyleng);
+^extern/{EOID} {
+ BEGIN(in_struct);
+ return EXTERN;
}
-
-[^[:alnum:]_](typedef{WS})?(struct|union){WS}{ID}{WS}/"GTY" {
- char *tagstart;
- size_t taglen;
- int typedef_p;
- int union_p;
-
- typedef_p = yytext[1] == 't';
- if (typedef_p)
- for (tagstart = yytext + strlen (" typedef ");
- ISSPACE(*tagstart);
- tagstart++)
- ;
- else
- tagstart = yytext + 1;
-
- union_p = tagstart[0] == 'u';
- tagstart += strlen ("union ");
- while (ISSPACE (*tagstart))
- tagstart++;
- for (taglen = 1; ISIDNUM (tagstart[taglen]); taglen++)
- ;
-
- yylval.s = (const char *) xmemdup (tagstart, taglen, taglen + 1);
-
+^static/{EOID} {
BEGIN(in_struct);
- update_lineno (yytext, yyleng);
- return union_p ? (typedef_p ? ENT_TYPEDEF_UNION : ENT_UNION)
- : (typedef_p ? ENT_TYPEDEF_STRUCT : ENT_STRUCT);
+ return STATIC;
}
-[^[:alnum:]_](extern|static){WS}/"GTY" {
+^DEF_VEC_[OP]/{EOID} {
BEGIN(in_struct);
- update_lineno (yytext, yyleng);
- return ENT_EXTERNSTATIC;
+ return DEFVEC_OP;
}
-
-^"DEF_VEC_"[IPO]{WS}?"("{WS}?{ID}{WS}?")" {
- /* Definition of a generic VEC structure. If the letter after
- DEF_VEC_ is "I", the structure definition is slightly different
- than if it is "P" or "O". */
-
- char *p = yytext + sizeof("DEF_VEC_") - 1;
- char *q;
- const char *type;
- bool is_I = (*p == 'I');
-
- /* Extract the argument to the macro. */
- p++;
- while (!ISALNUM(*p) && *p != '_')
- p++;
- q = p;
- while (ISALNUM(*q) || *q == '_')
- ++;
- type = xmemdup (p, q - p, q - p + 1);
-
- note_def_vec (type, is_I, &lexer_line);
- note_def_vec_alloc (type, "none", &lexer_line);
+^DEF_VEC_I/{EOID} {
+ BEGIN(in_struct);
+ return DEFVEC_I;
+}
+^DEF_VEC_ALLOC_[IOP]/{EOID} {
+ BEGIN(in_struct);
+ return DEFVEC_ALLOC;
}
-
-^"DEF_VEC_ALLOC_"[IPO]{WS}?"("{WS}?{ID}{WS}?","{WS}?{ID}{WS}?")" {
- /* Definition of an allocation strategy for a VEC structure. For
- purposes of gengtype, this just declares a wrapper structure. */
-
- char *p = yytext + sizeof("DEF_VEC_ALLOC_I") - 1;
- char *q;
- char *type, *astrat;
-
- /* Extract the two arguments to the macro. */
- while (!ISALNUM(*p) && *p != '_')
- p++;
- q = p;
- while (ISALNUM(*q) || *q == '_')
- q++;
- type = alloca (q - p + 1);
- memcpy (type, p, q - p);
- type[q - p] = '\0';
- p = q;
-
- while (!ISALNUM(*p) && *p != '_')
- p++;
- q = p;
- while (ISALNUM(*q) || *q == '_')
- q++;
- astrat = alloca (q - p + 1);
- memcpy (astrat, p, q - p);
- astrat[q - p] = '\0';
-
- note_def_vec_alloc (type, astrat, &lexer_line);
}
<in_struct>{
@@ -245,63 +106,57 @@ ITYPE {IWORD}({WS}{IWORD})*
{WS} { update_lineno (yytext, yyleng); }
-"const"/[^[:alnum:]_] /* don't care */
-"GTY"/[^[:alnum:]_] { return GTY_TOKEN; }
-"VEC"/[^[:alnum:]_] { return VEC_TOKEN; }
-"union"/[^[:alnum:]_] { return UNION; }
-"struct"/[^[:alnum:]_] { return STRUCT; }
-"enum"/[^[:alnum:]_] { return ENUM; }
-"ptr_alias"/[^[:alnum:]_] { return ALIAS; }
-"nested_ptr"/[^[:alnum:]_] { return NESTED_PTR; }
+"const"/{EOID} /* don't care */
+"GTY"/{EOID} { return GTY_TOKEN; }
+"VEC"/{EOID} { return VEC_TOKEN; }
+"union"/{EOID} { return UNION; }
+"struct"/{EOID} { return STRUCT; }
+"enum"/{EOID} { return ENUM; }
+"ptr_alias"/{EOID} { return PTR_ALIAS; }
+"nested_ptr"/{EOID} { return NESTED_PTR; }
[0-9]+ { return NUM; }
-"param"[0-9]*"_is"/[^[:alnum:]_] {
- yylval.s = (const char *) xmemdup (yytext, yyleng, yyleng+1);
+"param"[0-9]*"_is"/{EOID} {
+ *yylval = xmemdup (yytext, yyleng, yyleng+1);
return PARAM_IS;
}
-{IWORD}({WS}{IWORD})*/[^[:alnum:]_] |
+{IWORD}({WS}{IWORD})*/{EOID} |
"ENUM_BITFIELD"{WS}?"("{WS}?{ID}{WS}?")" {
size_t len;
for (len = yyleng; ISSPACE (yytext[len-1]); len--)
;
- yylval.s = (const char *) xmemdup (yytext, len, len+1);
+ *yylval = xmemdup (yytext, len, len+1);
update_lineno (yytext, yyleng);
return SCALAR;
}
-{ID}/[^[:alnum:]_] {
- yylval.s = (const char *) xmemdup (yytext, yyleng, yyleng+1);
+{ID}/{EOID} {
+ *yylval = xmemdup (yytext, yyleng, yyleng+1);
return ID;
}
\"([^"\\]|\\.)*\" {
- yylval.s = (const char *) xmemdup (yytext+1, yyleng-2, yyleng-1);
+ *yylval = xmemdup (yytext+1, yyleng-2, yyleng-1);
return STRING;
}
+ /* This "terminal" avoids having to parse integer constant expressions. */
"["[^\[\]]*"]" {
- yylval.s = (const char *) xmemdup (yytext+1, yyleng-2, yyleng-1);
+ *yylval = xmemdup (yytext+1, yyleng-2, yyleng-1);
return ARRAY;
}
"'"("\\".|[^\\])"'" {
- yylval.s = (const char *) xmemdup (yytext+1, yyleng-2, yyleng);
+ *yylval = xmemdup (yytext+1, yyleng-2, yyleng);
return CHAR;
}
-[(){},*:<>] { return yytext[0]; }
-
-[;=] {
- if (lexer_toplevel_done)
- {
- BEGIN(INITIAL);
- lexer_toplevel_done = 0;
- }
- return yytext[0];
-}
+"..." { return ELLIPSIS; }
+[(){},*:<>;=%|-] { return yytext[0]; }
-"#define"[^\n]*\n {lexer_line.line++;}
+ /* ignore pp-directives */
+^{HWS}"#"{HWS}[a-z_]+[^\n]*\n {lexer_line.line++;}
. {
error_at_line (&lexer_line, "unexpected character `%s'", yytext);
@@ -339,23 +194,20 @@ ITYPE {IWORD}({WS}{IWORD})*
%%
void
-yyerror (const char *s)
-{
- error_at_line (&lexer_line, s);
-}
-
-void
-parse_file (const char *fname)
+yybegin (const char *fname)
{
yyin = fopen (fname, "r");
- lexer_line.file = fname;
- lexer_line.line = 1;
if (yyin == NULL)
{
perror (fname);
exit (1);
}
- if (yyparse() != 0)
- exit (1);
+ lexer_line.file = fname;
+ lexer_line.line = 1;
+}
+
+void
+yyend (void)
+{
fclose (yyin);
}