On Thu, 27 Oct 2016, Trevor Saunders wrote: > On Tue, Oct 25, 2016 at 03:33:36PM +0200, Richard Biener wrote: > > > > Hi, > > > > so I did the massaging to split out the GIMPLE parsing routines out > > to a separate file (quite tricky to get the gengtype issues correctly > > so I thought to help out here and get things started). > > actually it looks like you didn't get the gengtype issues quiet right :( > stage 1 is fine, but when doing a bootstrap stage 2 dies trying to build > cc1obj. That's because objc pulls in c-parser.o, but not c-lang.o which > means that the gengtype routines for c_parser which are in > gt-c-c-parser.h (included by c-parser.c) are included in cc1obj, but the > routines for vec<c_token_, va_gc> are not because they get put in > gengtype-c.h which is included in c-lang.c. Unfortunately I'm not sure > how to fix that off hand.
Hohumm. I've only bootstrapped with --enable-languages=c but indeed I can reproduce this... Indeed this was also the reason I had to add c-parser.h as #include to c-lang.c ... > Killing pch and moving c_parser out of gc memory would of course be one > answer, but that's a rather massive hammer to use. Yeah... So the only thing I came up with was to privatize c_parser again and provide some extra abstraction for accessing ->error and ->tokens_buf. Bootstrap built stage1 cc1objc with --enable-stage1-languages=objc sofar, will push soon. Richard. 2016-10-27 Richard Biener <rguent...@suse.de> c/ * c-lang.c: Revert changes. * c-parser.c (struct c_parser): Put declaration back here. (c_parser_tokens_buf): New function. (c_parser_error): Likewise. (c_parser_set_error): Likewise. * c-parser.h (struct c_parser): Only declare forward. (c_parser_tokens_buf): Declare. (c_parser_error): Likewise. (c_parser_set_error): Likewise. * gimple-parser.c (c_parser_gimple_compound_statement): Use c_parser_error. (c_parser_gimple_binary_expression): Likewise. (c_parser_gimple_postfix_expression_after_primary): Use c_parser_tokens_buf. (c_parser_gimple_declaration): Use c_parser_set_error. diff --git a/gcc/c/c-lang.c b/gcc/c/c-lang.c index a2dd768..b4096d0 100644 --- a/gcc/c/c-lang.c +++ b/gcc/c/c-lang.c @@ -25,8 +25,6 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" #include "langhooks-def.h" #include "c-objc-common.h" -#include "c-family/c-pragma.h" -#include "c-parser.h" enum c_language_kind c_language = clk_c; diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index ad80b16..f69121b 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -152,6 +152,83 @@ c_parse_init (void) } } +/* A parser structure recording information about the state and + context of parsing. Includes lexer information with up to two + tokens of look-ahead; more are not needed for C. */ +struct GTY(()) c_parser { + /* The look-ahead tokens. */ + c_token * GTY((skip)) tokens; + /* Buffer for look-ahead tokens. */ + c_token GTY(()) tokens_buf[4]; + /* How many look-ahead tokens are available (0 - 4, or + more if parsing from pre-lexed tokens). */ + unsigned int tokens_avail; + /* True if a syntax error is being recovered from; false otherwise. + c_parser_error sets this flag. It should clear this flag when + enough tokens have been consumed to recover from the error. */ + BOOL_BITFIELD error : 1; + /* True if we're processing a pragma, and shouldn't automatically + consume CPP_PRAGMA_EOL. */ + BOOL_BITFIELD in_pragma : 1; + /* True if we're parsing the outermost block of an if statement. */ + BOOL_BITFIELD in_if_block : 1; + /* True if we want to lex an untranslated string. */ + BOOL_BITFIELD lex_untranslated_string : 1; + + /* Objective-C specific parser/lexer information. */ + + /* True if we are in a context where the Objective-C "PQ" keywords + are considered keywords. */ + BOOL_BITFIELD objc_pq_context : 1; + /* True if we are parsing a (potential) Objective-C foreach + statement. This is set to true after we parsed 'for (' and while + we wait for 'in' or ';' to decide if it's a standard C for loop or an + Objective-C foreach loop. */ + BOOL_BITFIELD objc_could_be_foreach_context : 1; + /* The following flag is needed to contextualize Objective-C lexical + analysis. In some cases (e.g., 'int NSObject;'), it is + undesirable to bind an identifier to an Objective-C class, even + if a class with that name exists. */ + BOOL_BITFIELD objc_need_raw_identifier : 1; + /* Nonzero if we're processing a __transaction statement. The value + is 1 | TM_STMT_ATTR_*. */ + unsigned int in_transaction : 4; + /* True if we are in a context where the Objective-C "Property attribute" + keywords are valid. */ + BOOL_BITFIELD objc_property_attr_context : 1; + + /* Cilk Plus specific parser/lexer information. */ + + /* Buffer to hold all the tokens from parsing the vector attribute for the + SIMD-enabled functions (formerly known as elemental functions). */ + vec <c_token, va_gc> *cilk_simd_fn_tokens; +}; + +/* Return a pointer to the Nth token in PARERs tokens_buf. */ + +c_token * +c_parser_tokens_buf (c_parser *parser, unsigned n) +{ + return &parser->tokens_buf[n]; +} + +/* Return the error state of PARSER. */ + +bool +c_parser_error (c_parser *parser) +{ + return parser->error; +} + +/* Set the error state of PARSER to ERR. */ + +void +c_parser_set_error (c_parser *parser, bool err) +{ + parser->error = err; +} + + /* The actual parser and external interface. ??? Does this need to be garbage-collected? */ diff --git a/gcc/c/c-parser.h b/gcc/c/c-parser.h index d178254..f36e738 100644 --- a/gcc/c/c-parser.h +++ b/gcc/c/c-parser.h @@ -50,7 +50,7 @@ enum c_id_kind { /* A single C token after string literal concatenation and conversion of preprocessing tokens to tokens. */ -typedef struct GTY (()) c_token { +struct GTY (()) c_token { /* The kind of token. */ ENUM_BITFIELD (cpp_ttype) type : 8; /* If this token is a CPP_NAME, this value indicates whether also @@ -78,60 +78,11 @@ typedef struct GTY (()) c_token { { return get_range ().m_finish; } -} c_token_; - -/* A parser structure recording information about the state and - context of parsing. Includes lexer information with up to two - tokens of look-ahead; more are not needed for C. */ -struct GTY(()) c_parser { - /* The look-ahead tokens. */ - struct c_token * GTY((skip)) tokens; - /* Buffer for look-ahead tokens. */ - struct c_token GTY(()) tokens_buf[4]; - /* How many look-ahead tokens are available (0 - 4, or - more if parsing from pre-lexed tokens). */ - unsigned int tokens_avail; - /* True if a syntax error is being recovered from; false otherwise. - c_parser_error sets this flag. It should clear this flag when - enough tokens have been consumed to recover from the error. */ - BOOL_BITFIELD error : 1; - /* True if we're processing a pragma, and shouldn't automatically - consume CPP_PRAGMA_EOL. */ - BOOL_BITFIELD in_pragma : 1; - /* True if we're parsing the outermost block of an if statement. */ - BOOL_BITFIELD in_if_block : 1; - /* True if we want to lex an untranslated string. */ - BOOL_BITFIELD lex_untranslated_string : 1; - - /* Objective-C specific parser/lexer information. */ - - /* True if we are in a context where the Objective-C "PQ" keywords - are considered keywords. */ - BOOL_BITFIELD objc_pq_context : 1; - /* True if we are parsing a (potential) Objective-C foreach - statement. This is set to true after we parsed 'for (' and while - we wait for 'in' or ';' to decide if it's a standard C for loop or an - Objective-C foreach loop. */ - BOOL_BITFIELD objc_could_be_foreach_context : 1; - /* The following flag is needed to contextualize Objective-C lexical - analysis. In some cases (e.g., 'int NSObject;'), it is - undesirable to bind an identifier to an Objective-C class, even - if a class with that name exists. */ - BOOL_BITFIELD objc_need_raw_identifier : 1; - /* Nonzero if we're processing a __transaction statement. The value - is 1 | TM_STMT_ATTR_*. */ - unsigned int in_transaction : 4; - /* True if we are in a context where the Objective-C "Property attribute" - keywords are valid. */ - BOOL_BITFIELD objc_property_attr_context : 1; - - /* Cilk Plus specific parser/lexer information. */ - - /* Buffer to hold all the tokens from parsing the vector attribute for the - SIMD-enabled functions (formerly known as elemental functions). */ - vec <c_token_, va_gc> *cilk_simd_fn_tokens; }; +/* The parser. */ +struct c_parser; + /* Possibly kinds of declarator to parse. */ enum c_dtr_syn { /* A normal declarator with an identifier. */ @@ -193,6 +144,13 @@ extern c_token * c_parser_peek_2nd_token (c_parser *parser); bool c_parser_next_tokens_start_declaration (c_parser *parser); bool c_token_starts_typename (c_token *token); +/* Abstraction to avoid defining c_parser here which messes up gengtype + output wrt ObjC due to vec<c_token> routines being put in gtype-c.h + but not gtype-objc.h. */ +extern c_token * c_parser_tokens_buf (c_parser *parser, unsigned n); +extern bool c_parser_error (c_parser *parser); +extern void c_parser_set_error (c_parser *parser, bool); + /* Return true if the next token from PARSER has the indicated TYPE. */ diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c index 8db425f..f109745 100644 --- a/gcc/c/gimple-parser.c +++ b/gcc/c/gimple-parser.c @@ -158,7 +158,7 @@ c_parser_gimple_compound_statement (c_parser *parser, gimple_seq *seq) while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE)) { - if (parser->error) + if (c_parser_error (parser)) { c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); return return_p; @@ -484,7 +484,7 @@ c_parser_gimple_binary_expression (c_parser *parser, enum tree_code *subcode) stack[0].expr = c_parser_gimple_unary_expression (parser); sp = 0; source_range src_range; - if (parser->error) + if (c_parser_error (parser)) goto out; switch (c_parser_peek_token (parser)->type) { @@ -813,7 +813,7 @@ c_parser_gimple_postfix_expression_after_primary (c_parser *parser, break; start = expr.get_start (); - finish = parser->tokens_buf[0].location; + finish = c_parser_tokens_buf (parser, 0)->location; expr.value = build_array_ref (op_loc, expr.value, idx); set_c_expr_source_range (&expr, start, finish); @@ -834,7 +834,7 @@ c_parser_gimple_postfix_expression_after_primary (c_parser *parser, "expected %<)%>"); orig_expr = expr; start = expr.get_start (); - finish = parser->tokens_buf[0].get_finish (); + finish = c_parser_tokens_buf (parser, 0)->get_finish (); expr.value = c_build_function_call_vec (expr_loc, arg_loc, expr.value, exprlist, origtypes); set_c_expr_source_range (&expr, start, finish); @@ -1032,7 +1032,7 @@ c_parser_gimple_declaration (c_parser *parser) && ! c_parser_next_token_is (parser, CPP_NAME)) { c_parser_error (parser, "expected %<;%>"); - parser->error = false; + c_parser_set_error (parser, false); return; }