typedef declaration_t* (*parsed_declaration_func) (declaration_t *declaration, bool is_definition);
+/** The current token. */
static token_t token;
+/** The lookahead ring-buffer. */
static token_t lookahead_buffer[MAX_LOOKAHEAD];
+/** Position of the next token in the lookahead buffer. */
static int lookahead_bufpos;
static stack_entry_t *environment_stack = NULL;
static stack_entry_t *label_stack = NULL;
static goto_statement_t *goto_last = NULL;
static label_statement_t *label_first = NULL;
static label_statement_t *label_last = NULL;
+/** current translation unit. */
static translation_unit_t *unit = NULL;
+/** true if we are in a type property context (evaluation only for type. */
+static bool in_type_prop = false;
+/** true in we are in a __extension__ context. */
+static bool in_gcc_extension = false;
static struct obstack temp_obst;
+
#define PUSH_PARENT(stmt) \
statement_t *const prev_parent = current_parent; \
current_parent = (stmt);
/** The current source position. */
#define HERE (&token.source_position)
+/** true if we are in GCC mode. */
+#define GNU_MODE ((c_mode & _GNUC) || in_gcc_extension)
+
static type_t *type_valist;
static statement_t *parse_compound_statement(bool inside_expression_statement);
expression_t *expression = NULL;
-restart:
- switch(token.type) {
- case T___extension__:
- /* This can be a prefix to a typename or an expression. We simply eat
- * it now. */
- do {
- next_token();
- } while (token.type == T___extension__);
- goto restart;
+ bool old_type_prop = in_type_prop;
+ bool old_gcc_extension = in_gcc_extension;
+ in_type_prop = true;
+ while (token.type == T___extension__) {
+ /* This can be a prefix to a typename or an expression. */
+ next_token();
+ in_gcc_extension = true;
+ }
+ switch (token.type) {
case T_IDENTIFIER:
if (is_typedef_symbol(token.v.symbol)) {
type = parse_typename();
type = expression->base.type;
break;
}
+ in_type_prop = old_type_prop;
+ in_gcc_extension = old_gcc_extension;
rem_anchor_token(')');
expect(')');
return false;
}
unsigned v = (unsigned)intvalue;
- for(unsigned i = 1; i <= 8192; i += i) {
+ for (unsigned i = 1; i <= 8192; i += i) {
if (i == v)
return true;
}
} else if (symbol == sym_property) {
next_token();
expect('(');
- for(;;) {
+ for (;;) {
bool is_get = false;
if (token.type != T_IDENTIFIER)
goto end_error;
static void parse_declaration_specifiers(declaration_specifiers_t *specifiers)
{
- type_t *type = NULL;
- type_qualifiers_t qualifiers = TYPE_QUALIFIER_NONE;
- type_modifiers_t modifiers = TYPE_MODIFIER_NONE;
- unsigned type_specifiers = 0;
- bool newtype = false;
- bool saw_error = false;
+ type_t *type = NULL;
+ type_qualifiers_t qualifiers = TYPE_QUALIFIER_NONE;
+ type_modifiers_t modifiers = TYPE_MODIFIER_NONE;
+ unsigned type_specifiers = 0;
+ bool newtype = false;
+ bool saw_error = false;
+ bool old_gcc_extension = in_gcc_extension;
specifiers->source_position = token.source_position;
if (specifiers->modifiers & DM_TRANSPARENT_UNION)
modifiers |= TYPE_MODIFIER_TRANSPARENT_UNION;
- switch(token.type) {
+ switch (token.type) {
/* storage class */
#define MATCH_STORAGE_CLASS(token, class) \
MATCH_TYPE_QUALIFIER(T___sptr, TYPE_QUALIFIER_SPTR);
case T___extension__:
- /* TODO */
next_token();
+ in_gcc_extension = true;
break;
/* type specifiers */
}
finish_specifiers:
+ in_gcc_extension = old_gcc_extension;
+
if (type == NULL || (saw_error && type_specifiers != 0)) {
atomic_type_kind_t atomic_type;
static bool is_declaration_specifier(const token_t *token,
bool only_specifiers_qualifiers)
{
- switch(token->type) {
+ switch (token->type) {
TYPE_SPECIFIERS
TYPE_QUALIFIERS
return true;
parsed_declaration_func finished_declaration)
{
add_anchor_token(';');
- add_anchor_token('=');
add_anchor_token(',');
while(true) {
declaration_t *declaration =
break;
eat(',');
+ add_anchor_token('=');
ndeclaration = parse_declarator(specifiers, /*may_be_abstract=*/false);
+ rem_anchor_token('=');
}
expect(';');
end_error:
rem_anchor_token(';');
- rem_anchor_token('=');
rem_anchor_token(',');
}
cnst->conste.v.character = token.v.string;
if (cnst->conste.v.character.size != 1) {
- if (warning.multichar && (c_mode & _GNUC)) {
- /* TODO */
+ if (warning.multichar && GNU_MODE) {
warningf(HERE, "multi-character character constant");
} else {
errorf(HERE, "more than 1 characters in character constant");
cnst->conste.v.wide_character = token.v.wide_string;
if (cnst->conste.v.wide_character.size != 1) {
- if (warning.multichar && (c_mode & _GNUC)) {
- /* TODO */
+ if (warning.multichar && GNU_MODE) {
warningf(HERE, "multi-character character constant");
} else {
errorf(HERE, "more than 1 characters in character constant");
declaration->symbol, &declaration->source_position);
}
}
- if (warning.init_self && declaration == current_init_decl) {
+ if (warning.init_self && declaration == current_init_decl && !in_type_prop) {
current_init_decl = NULL;
warningf(HERE, "variable '%#T' is initialized by itself",
declaration->type, declaration->symbol);
case T___builtin_prefetch: return parse_builtin_prefetch();
case T__assume: return parse_assume();
case T_ANDAND:
- if (c_mode & _GNUC)
+ if (GNU_MODE)
return parse_label_address();
break;
char const* const what = kind == EXPR_SIZEOF ? "sizeof" : "alignof";
- /* we only refer to a type property, not the value, so do not warn
- * when using current_init_decl */
- declaration_t *old = current_init_decl;
- current_init_decl = NULL;
+ /* we only refer to a type property, mark this case */
+ bool old = in_type_prop;
+ in_type_prop = true;
if (token.type == '(' && is_declaration_specifier(look_ahead(1), true)) {
next_token();
add_anchor_token(')');
}
end_error:
- current_init_decl = old;
+ in_type_prop = old;
return tp_expression;
}
expression_t *true_expression = expression;
bool gnu_cond = false;
- if ((c_mode & _GNUC) && token.type == ':') {
+ if (GNU_MODE && token.type == ':') {
gnu_cond = true;
} else
true_expression = parse_expression();
{
eat(T___extension__);
- /* TODO enable extensions */
+ bool old_gcc_extension = in_gcc_extension;
+ in_gcc_extension = true;
expression_t *expression = parse_sub_expression(precedence);
- /* TODO disable extensions */
+ in_gcc_extension = old_gcc_extension;
return expression;
}
points_to = skip_typeref(points_to);
if (is_type_incomplete(points_to)) {
- if (!(c_mode & _GNUC) || !is_type_atomic(points_to, ATOMIC_TYPE_VOID)) {
+ if (!GNU_MODE || !is_type_atomic(points_to, ATOMIC_TYPE_VOID)) {
errorf(source_position,
"arithmetic with pointer to incomplete type '%T' not allowed",
orig_pointer_type);
orig_pointer_type);
}
} else if (is_type_function(points_to)) {
- if (!(c_mode && _GNUC)) {
+ if (!GNU_MODE) {
errorf(source_position,
"arithmetic with pointer to function type '%T' not allowed",
orig_pointer_type);
statement->case_label.last_case = val;
}
- if (c_mode & _GNUC) {
+ if (GNU_MODE) {
if (token.type == T_DOTDOTDOT) {
next_token();
expression_t *const end_range = parse_expression();
eat(T_goto);
statement_t *statement;
- if (c_mode & _GNUC && token.type == '*') {
+ if (GNU_MODE && token.type == '*') {
next_token();
expression_t *expression = parse_expression();
statement->gotos.expression = expression;
} else {
if (token.type != T_IDENTIFIER) {
- if (c_mode & _GNUC)
+ if (GNU_MODE)
parse_error_expected("while parsing goto", T_IDENTIFIER, '*', NULL);
else
parse_error_expected("while parsing goto", T_IDENTIFIER, NULL);
statement->base.source_position = token.source_position;
declaration_t *before = last_declaration;
- if (c_mode & _GNUC)
+ if (GNU_MODE)
parse_external_declaration();
else
parse_declaration(record_declaration);
do {
next_token();
} while (token.type == T___extension__);
+ bool old_gcc_extension = in_gcc_extension;
+ in_gcc_extension = true;
statement = parse_statement();
+ in_gcc_extension = false;
break;
DECLARATION_START
for (;;) {
#ifndef NDEBUG
bool anchor_leak = false;
- for (token_type_t i = 0; i != T_LAST_TOKEN; ++i) {
+ for (int i = 0; i != T_LAST_TOKEN; ++i) {
unsigned char count = token_anchor_set[i];
if (count != 0) {
errorf(HERE, "Leaked anchor token %k %d times", i, count);
anchor_leak = true;
}
}
+ if (in_gcc_extension) {
+ errorf(HERE, "Leaked __extension__");
+ anchor_leak = true;
+ }
+
if (anchor_leak)
abort();
#endif