Commit 9c038180 authored by Roberto Raggi's avatar Roberto Raggi

Improved compatibility with the gcc extensions.

parent c3c98cca
......@@ -150,6 +150,8 @@ static const char pp_configuration[] =
"#define __imag__\n"
"#define __real__\n"
"#define __builtin_va_arg(a,b) ((b)0)\n"
// ### add macros for win32
"#define __cdecl\n"
"#define QT_WA(x) x\n"
......
......@@ -570,6 +570,8 @@ unsigned DeclarationListAST::lastToken() const
unsigned DeclaratorAST::firstToken() const
{
if (attributes)
return attributes->firstToken();
if (ptr_operators)
return ptr_operators->firstToken();
else if (core_declarator)
......@@ -589,7 +591,7 @@ unsigned DeclaratorAST::lastToken() const
if (initializer)
return initializer->lastToken();
for (SpecifierAST *it = attributes; it; it = it->next) {
for (SpecifierAST *it = post_attributes; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
......@@ -607,6 +609,11 @@ unsigned DeclaratorAST::lastToken() const
return it->lastToken();
}
for (SpecifierAST *it = attributes; it; it = it->next) {
if (! it->next)
return it->lastToken();
}
// ### assert?
return 0;
}
......
......@@ -371,10 +371,11 @@ public:
class CPLUSPLUS_EXPORT DeclaratorAST: public AST
{
public:
SpecifierAST *attributes;
PtrOperatorAST *ptr_operators;
CoreDeclaratorAST *core_declarator;
PostfixDeclaratorAST *postfix_declarators;
SpecifierAST *attributes;
SpecifierAST *post_attributes;
unsigned equals_token;
ExpressionAST *initializer;
......
......@@ -97,10 +97,11 @@ DeclaratorAST *DeclaratorAST::clone(MemoryPool *pool) const
{
DeclaratorAST *ast = new (pool) DeclaratorAST;
// copy DeclaratorAST
if (attributes) ast->attributes = attributes->clone(pool);
if (ptr_operators) ast->ptr_operators = ptr_operators->clone(pool);
if (core_declarator) ast->core_declarator = core_declarator->clone(pool);
if (postfix_declarators) ast->postfix_declarators = postfix_declarators->clone(pool);
if (attributes) ast->attributes = attributes->clone(pool);
if (post_attributes) ast->post_attributes = post_attributes->clone(pool);
ast->equals_token = equals_token;
if (initializer) ast->initializer = initializer->clone(pool);
return ast;
......
......@@ -85,12 +85,14 @@ void DeclaratorAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
// visit DeclaratorAST
for (SpecifierAST *it = attributes; it; it = it->next)
accept(it, visitor);
for (PtrOperatorAST *it = ptr_operators; it; it = it->next)
accept(it, visitor);
accept(core_declarator, visitor);
for (PostfixDeclaratorAST *it = postfix_declarators; it; it = it->next)
accept(it, visitor);
for (SpecifierAST *it = attributes; it; it = it->next)
for (SpecifierAST *it = post_attributes; it; it = it->next)
accept(it, visitor);
accept(initializer, visitor);
}
......
......@@ -671,6 +671,9 @@ bool Parser::parseAsmDefinition(DeclarationAST *&node)
bool Parser::parseAsmOperandList()
{
if (LA() != T_STRING_LITERAL)
return true;
if (parseAsmOperand()) {
while (LA() == T_COMMA) {
consumeToken();
......@@ -678,6 +681,7 @@ bool Parser::parseAsmOperandList()
}
return true;
}
return false;
}
......@@ -949,6 +953,14 @@ bool Parser::parseDeclaratorOrAbstractDeclarator(DeclaratorAST *&node)
bool Parser::parseCoreDeclarator(DeclaratorAST *&node)
{
unsigned start = cursor();
SpecifierAST *attributes = 0;
SpecifierAST **attribute_ptr = &attributes;
while (LA() == T___ATTRIBUTE__) {
parseAttributeSpecifier(*attribute_ptr);
attribute_ptr = &(*attribute_ptr)->next;
}
PtrOperatorAST *ptr_operators = 0, **ptr_operators_tail = &ptr_operators;
while (parsePtrOperator(*ptr_operators_tail))
ptr_operators_tail = &(*ptr_operators_tail)->next;
......@@ -960,12 +972,16 @@ bool Parser::parseCoreDeclarator(DeclaratorAST *&node)
DeclaratorIdAST *declarator_id = new (_pool) DeclaratorIdAST;
declarator_id->name = name;
DeclaratorAST *ast = new (_pool) DeclaratorAST;
ast->attributes = attributes;
ast->ptr_operators = ptr_operators;
ast->core_declarator = declarator_id;
node = ast;
return true;
}
} else if (LA() == T_LPAREN) {
if (attributes)
_translationUnit->warning(attributes->firstToken(), "unexpected attribtues");
unsigned lparen_token = consumeToken();
DeclaratorAST *declarator = 0;
if (parseDeclarator(declarator) && LA() == T_RPAREN) {
......@@ -980,6 +996,7 @@ bool Parser::parseCoreDeclarator(DeclaratorAST *&node)
return true;
}
}
rewind(start);
return false;
}
......@@ -1060,7 +1077,7 @@ bool Parser::parseDeclarator(DeclaratorAST *&node, bool stopAtCppInitializer)
break;
}
SpecifierAST **spec_ptr = &node->attributes;
SpecifierAST **spec_ptr = &node->post_attributes;
while (LA() == T___ATTRIBUTE__) {
parseAttributeSpecifier(*spec_ptr);
spec_ptr = &(*spec_ptr)->next;
......
......@@ -6,3 +6,6 @@
#define restrict
#define __restrict
#define __weak
#define __builtin_va_arg(a,b) ((b)0)
#define __stdcall
#define __fastcall
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment