diff options
author | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-09-24 17:37:16 +0000 |
---|---|---|
committer | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-09-24 17:37:16 +0000 |
commit | 01c8b828d8905a7565b1cc7803f0ef960a0b4f95 (patch) | |
tree | b69215f34e3bb2c29a5ec4bfc4727dfce15fafb1 /gcc/gengtype-parse.c | |
parent | 93b796431bc4cfdb4f27ca12bef3df917a0e09e1 (diff) | |
download | gcc-01c8b828d8905a7565b1cc7803f0ef960a0b4f95.tar.gz |
2010-09-24 Basile Starynkevitch <basile@starynkevitch.net>
* gcc/gengtype.c: Reindented.
* gcc/gengtype.h: Reindented.
* gcc/gengtype-parse.c: Reindented.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@164604 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/gengtype-parse.c')
-rw-r--r-- | gcc/gengtype-parse.c | 222 |
1 files changed, 126 insertions, 96 deletions
diff --git a/gcc/gengtype-parse.c b/gcc/gengtype-parse.c index c6b6e933cc5..3092a43eca0 100644 --- a/gcc/gengtype-parse.c +++ b/gcc/gengtype-parse.c @@ -1,21 +1,21 @@ /* Process source files and output type information. Copyright (C) 2006, 2007 Free Software Foundation, Inc. -This file is part of GCC. + 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 3, or (at your option) any later -version. + 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 3, or (at your option) any later + version. -GCC is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. + GCC is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of 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 COPYING3. If not see -<http://www.gnu.org/licenses/>. */ + You should have received a copy of the GNU General Public License + along with GCC; see the file COPYING3. If not see + <http://www.gnu.org/licenses/>. */ #include "bconfig.h" #include "system.h" @@ -113,7 +113,7 @@ print_token (int code, const char *value) else if (code < FIRST_TOKEN_WITH_VALUE) return xasprintf ("'%s'", token_names[code - CHAR_TOKEN_OFFSET]); else if (!value) - return token_names[code - CHAR_TOKEN_OFFSET]; /* don't quote these */ + return token_names[code - CHAR_TOKEN_OFFSET]; /* don't quote these */ else return xasprintf (token_value_format[code - FIRST_TOKEN_WITH_VALUE], value); @@ -199,7 +199,7 @@ string_seq (void) l1 = strlen (s1); l2 = strlen (s2); - buf = XRESIZEVEC (char, CONST_CAST(char *, s1), l1 + l2 + 1); + buf = XRESIZEVEC (char, CONST_CAST (char *, s1), l1 + l2 + 1); memcpy (buf + l1, s2, l2 + 1); XDELETE (CONST_CAST (char *, s2)); s1 = buf; @@ -222,7 +222,7 @@ typedef_name (void) require (','); c2 = require (ID); require (')'); - r = concat ("VEC_", c1, "_", c2, (char *)0); + r = concat ("VEC_", c1, "_", c2, (char *) 0); free (CONST_CAST (char *, c1)); free (CONST_CAST (char *, c2)); return r; @@ -239,10 +239,18 @@ consume_balanced (int opener, int closer) for (;;) switch (token ()) { - default: advance (); break; - case '(': consume_balanced ('(',')'); break; - case '[': consume_balanced ('[',']'); break; - case '{': consume_balanced ('{','}'); break; + default: + advance (); + break; + case '(': + consume_balanced ('(', ')'); + break; + case '[': + consume_balanced ('[', ']'); + break; + case '{': + consume_balanced ('{', '}'); + break; case '}': case ']': @@ -250,8 +258,8 @@ consume_balanced (int opener, int closer) if (token () != closer) parse_error ("unbalanced delimiters - expected '%c', have '%c'", closer, token ()); - advance (); - return; + advance (); + return; case EOF_TOKEN: parse_error ("unexpected end of file within %c%c-delimited construct", @@ -272,18 +280,28 @@ consume_until_semi (bool immediate) for (;;) switch (token ()) { - case ';': advance (); return; - default: advance (); break; + case ';': + advance (); + return; + default: + advance (); + break; - case '(': consume_balanced ('(',')'); break; - case '[': consume_balanced ('[',']'); break; - case '{': consume_balanced ('{','}'); break; + case '(': + consume_balanced ('(', ')'); + break; + case '[': + consume_balanced ('[', ']'); + break; + case '{': + consume_balanced ('{', '}'); + break; case '}': case ']': case ')': parse_error ("unmatched '%c' while scanning for ';'", token ()); - return; + return; case EOF_TOKEN: parse_error ("unexpected end of file while scanning for ';'"); @@ -304,28 +322,40 @@ consume_until_comma_or_semi (bool immediate) for (;;) switch (token ()) { - case ',': advance (); return true; - case ';': advance (); return false; - default: advance (); break; + case ',': + advance (); + return true; + case ';': + advance (); + return false; + default: + advance (); + break; - case '(': consume_balanced ('(',')'); break; - case '[': consume_balanced ('[',']'); break; - case '{': consume_balanced ('{','}'); break; + case '(': + consume_balanced ('(', ')'); + break; + case '[': + consume_balanced ('[', ']'); + break; + case '{': + consume_balanced ('{', '}'); + break; case '}': case ']': case ')': parse_error ("unmatched '%s' while scanning for ',' or ';'", print_cur_token ()); - return false; + return false; case EOF_TOKEN: parse_error ("unexpected end of file while scanning for ',' or ';'"); return false; } } - + /* GTY(()) option handling. */ static type_p type (options_p *optsp, bool nested); @@ -401,11 +431,11 @@ nestedptr_optvalue (options_p prev) } /* One GTY(()) option: - ID str_optvalue_opt - | PTR_ALIAS type_optvalue - | PARAM_IS type_optvalue - | NESTED_PTR nestedptr_optvalue - */ + ID str_optvalue_opt + | PTR_ALIAS type_optvalue + | PARAM_IS type_optvalue + | NESTED_PTR nestedptr_optvalue +*/ static options_p option (options_p prev) { @@ -426,8 +456,7 @@ option (options_p prev) return nestedptr_optvalue (prev); default: - parse_error ("expected an option keyword, have %s", - print_cur_token ()); + parse_error ("expected an option keyword, have %s", print_cur_token ()); advance (); return create_option (prev, "", ""); } @@ -479,9 +508,9 @@ gtymarker_opt (void) we don't have to do it. */ /* array_and_function_declarators_opt: - \epsilon - array_and_function_declarators_opt ARRAY - array_and_function_declarators_opt '(' ... ')' + \epsilon + array_and_function_declarators_opt ARRAY + array_and_function_declarators_opt '(' ... ')' where '...' indicates stuff we ignore except insofar as grouping symbols ()[]{} must balance. @@ -510,8 +539,8 @@ array_and_function_declarators_opt (type_p ty) static type_p inner_declarator (type_p, const char **, options_p *); /* direct_declarator: - '(' inner_declarator ')' - gtymarker_opt ID array_and_function_declarators_opt + '(' inner_declarator ')' + gtymarker_opt ID array_and_function_declarators_opt Subroutine of declarator, mutually recursive with inner_declarator; do not use elsewhere. */ @@ -550,7 +579,7 @@ direct_declarator (type_p ty, const char **namep, options_p *optsp) /* The difference between inner_declarator and declarator is in the handling of stars. Consider this declaration: - char * (*pfc) (void) + char * (*pfc) (void) It declares a pointer to a function that takes no arguments and returns a char*. To construct the correct type for this @@ -562,8 +591,8 @@ direct_declarator (type_p ty, const char **namep, options_p *optsp) creating pointers. */ /* inner_declarator: - '*' inner_declarator - direct_declarator + '*' inner_declarator + direct_declarator Mutually recursive subroutine of direct_declarator; do not use elsewhere. */ @@ -609,13 +638,13 @@ declarator (type_p ty, const char **namep, options_p *optsp) /* Structure field(s) declaration: ( - type bitfield ';' - | type declarator bitfield? ( ',' declarator bitfield? )+ ';' + type bitfield ';' + | type declarator bitfield? ( ',' declarator bitfield? )+ ';' )+ Knows that such declarations must end with a close brace (or, erroneously, at EOF). - */ +*/ static pair_p struct_field_seq (void) { @@ -666,7 +695,7 @@ struct_field_seq (void) /* This is called type(), but what it parses (sort of) is what C calls declaration-specifiers and specifier-qualifier-list: - SCALAR + SCALAR | ID // typedef | (STRUCT|UNION) ID? gtymarker? ( '{' gtymarker? struct_field_seq '}' )? | ENUM ID ( '{' ... '}' )? @@ -674,7 +703,7 @@ struct_field_seq (void) Returns a partial type; under some conditions (notably "struct foo GTY((...)) thing;") it may write an options structure to *OPTSP. - */ +*/ static type_p type (options_p *optsp, bool nested) { @@ -695,15 +724,16 @@ type (options_p *optsp, bool nested) case UNION: { options_p opts = 0; - /* GTY annotations follow attribute syntax - GTY_BEFORE_ID is for union/struct declarations - GTY_AFTER_ID is for variable declarations. */ - enum { - NO_GTY, - GTY_BEFORE_ID, - GTY_AFTER_ID - } is_gty = NO_GTY; - bool is_union = (token () == UNION); + /* GTY annotations follow attribute syntax + GTY_BEFORE_ID is for union/struct declarations + GTY_AFTER_ID is for variable declarations. */ + enum + { + NO_GTY, + GTY_BEFORE_ID, + GTY_AFTER_ID + } is_gty = NO_GTY; + bool is_union = (token () == UNION); advance (); /* Top-level structures that are not explicitly tagged GTY(()) @@ -713,8 +743,8 @@ type (options_p *optsp, bool nested) that we can't handle. */ if (nested || token () == GTY_TOKEN) { - is_gty = GTY_BEFORE_ID; - opts = gtymarker_opt (); + is_gty = GTY_BEFORE_ID; + opts = gtymarker_opt (); } if (token () == ID) @@ -722,31 +752,31 @@ type (options_p *optsp, bool nested) else s = xasprintf ("anonymous:%s:%d", lexer_line.file, lexer_line.line); - /* Unfortunately above GTY_TOKEN check does not capture the - typedef struct_type GTY case. */ + /* Unfortunately above GTY_TOKEN check does not capture the + typedef struct_type GTY case. */ if (token () == GTY_TOKEN) { - is_gty = GTY_AFTER_ID; - opts = gtymarker_opt (); + is_gty = GTY_AFTER_ID; + opts = gtymarker_opt (); } - if (is_gty) - { - if (token () == '{') - { - pair_p fields; - - if (is_gty == GTY_AFTER_ID) - parse_error ("GTY must be specified before identifier"); - - advance (); - fields = struct_field_seq (); - require ('}'); - return new_structure (s, is_union, &lexer_line, fields, opts); - } - } - else if (token () == '{') - consume_balanced ('{', '}'); + if (is_gty) + { + if (token () == '{') + { + pair_p fields; + + if (is_gty == GTY_AFTER_ID) + parse_error ("GTY must be specified before identifier"); + + advance (); + fields = struct_field_seq (); + require ('}'); + return new_structure (s, is_union, &lexer_line, fields, opts); + } + } + else if (token () == '{') + consume_balanced ('{', '}'); if (opts) *optsp = opts; return find_structure (s, is_union); @@ -754,13 +784,13 @@ type (options_p *optsp, bool nested) case ENUM: advance (); - if (token () == ID) - s = advance (); - else - s = xasprintf ("anonymous:%s:%d", lexer_line.file, lexer_line.line); + if (token () == ID) + s = advance (); + else + s = xasprintf ("anonymous:%s:%d", lexer_line.file, lexer_line.line); if (token () == '{') - consume_balanced ('{','}'); + consume_balanced ('{', '}'); return create_scalar_type (s); default: @@ -821,7 +851,7 @@ struct_or_union (void) } /* GC root declaration: - (extern|static) gtymarker? type ID array_declarators_opt (';'|'=') + (extern|static) gtymarker? type ID array_declarators_opt (';'|'=') If the gtymarker is not present, we ignore the rest of the declaration. */ static void extern_or_static (void) @@ -838,8 +868,8 @@ extern_or_static (void) } opts = gtymarker (); - ty = type (&opts2, true); /* if we get here, it's got a GTY(()) */ - dty = declarator (ty, &name, &dopts); + ty = type (&opts2, true); /* if we get here, it's got a GTY(()) */ + dty = declarator (ty, &name, &dopts); if ((opts && dopts) || (opts && opts2) || (opts2 && dopts)) parse_error ("GTY((...)) specified more than once for %s", name); @@ -864,7 +894,7 @@ extern_or_static (void) static void def_vec (void) { - bool is_scalar = (token() == DEFVEC_I); + bool is_scalar = (token () == DEFVEC_I); const char *type; require2 (DEFVEC_OP, DEFVEC_I); |