Commit d0f794b6 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Reduced the number of ambiguous ExpressionOrDeclarationStatementAST nodes.

parent c8bb37d2
This diff is collapsed.
......@@ -78,8 +78,8 @@ public:
public:
bool parseAccessSpecifier(SpecifierAST *&node);
bool parseExpressionList(ExpressionListAST *&node);
bool parseAbstractCoreDeclarator(DeclaratorAST *&node);
bool parseAbstractDeclarator(DeclaratorAST *&node);
bool parseAbstractCoreDeclarator(DeclaratorAST *&node, SpecifierListAST *decl_specifier_list);
bool parseAbstractDeclarator(DeclaratorAST *&node, SpecifierListAST *decl_specifier_list);
bool parseEmptyDeclaration(DeclarationAST *&node);
bool parseAccessDeclaration(DeclarationAST *&node);
bool parseQtPropertyDeclaration(DeclarationAST *&node);
......@@ -110,12 +110,12 @@ public:
bool parseConstantExpression(ExpressionAST *&node);
bool parseCtorInitializer(CtorInitializerAST *&node);
bool parseCvQualifiers(SpecifierListAST *&node);
bool parseDeclaratorOrAbstractDeclarator(DeclaratorAST *&node);
bool parseDeclaratorOrAbstractDeclarator(DeclaratorAST *&node, SpecifierListAST *decl_specifier_list);
bool parseDeclaration(DeclarationAST *&node);
bool parseSimpleDeclaration(DeclarationAST *&node, bool acceptStructDeclarator = false);
bool parseSimpleDeclaration(DeclarationAST *&node, ClassSpecifierAST *declaringClass = 0);
bool parseDeclarationStatement(StatementAST *&node);
bool parseCoreDeclarator(DeclaratorAST *&node);
bool parseDeclarator(DeclaratorAST *&node, bool stopAtCppInitializer = false);
bool parseCoreDeclarator(DeclaratorAST *&node, SpecifierListAST *decl_specifier_list, bool declaringClass);
bool parseDeclarator(DeclaratorAST *&node, SpecifierListAST *decl_specifier_list, bool declaringClass = false);
bool parseDeleteExpression(ExpressionAST *&node);
bool parseDoStatement(StatementAST *&node);
bool parseElaboratedTypeSpecifier(SpecifierListAST *&node);
......@@ -134,7 +134,7 @@ public:
bool parseFunctionBody(StatementAST *&node);
bool parseIfStatement(StatementAST *&node);
bool parseInclusiveOrExpression(ExpressionAST *&node);
bool parseInitDeclarator(DeclaratorAST *&node, bool acceptStructDeclarator);
bool parseInitDeclarator(DeclaratorAST *&node, SpecifierListAST *decl_specifier_list, bool declaringClass);
bool parseInitializerList(ExpressionListAST *&node);
bool parseInitializer(ExpressionAST *&node, unsigned *equals_token);
bool parseInitializerClause(ExpressionAST *&node);
......@@ -145,7 +145,7 @@ public:
bool parseLogicalOrExpression(ExpressionAST *&node);
bool parseMemInitializer(MemInitializerListAST *&node);
bool parseMemInitializerList(MemInitializerListAST *&node);
bool parseMemberSpecification(DeclarationAST *&node);
bool parseMemberSpecification(DeclarationAST *&node, ClassSpecifierAST *declaringClass);
bool parseMultiplicativeExpression(ExpressionAST *&node);
bool parseTemplateId(NameAST *&node, unsigned template_token = 0);
bool parseClassOrNamespaceName(NameAST *&node);
......@@ -287,11 +287,13 @@ public:
bool lookAtBuiltinTypeSpecifier() const;
bool lookAtClassKey() const;
const Identifier *className(ClassSpecifierAST *ast) const;
const Identifier *identifier(NameAST *name) const;
void match(int kind, unsigned *token);
bool maybeAmbiguousStatement(DeclarationStatementAST *ast) const;
bool maybeAmbiguousStatement(DeclarationStatementAST *ast, StatementAST *&node);
bool maybeForwardOrClassDeclaration(SpecifierListAST *decl_specifier_seq) const;
bool isPointerDeclaration(DeclarationStatementAST *ast) const;
int peekAtQtContextKeyword() const;
......
......@@ -295,7 +295,7 @@ bool TranslationUnit::parse(ParseMode mode)
case ParseDeclarator: {
DeclaratorAST *node = 0;
parsed = parser.parseDeclarator(node);
parsed = parser.parseDeclarator(node, /*decl_specifier_list =*/ 0);
_ast = node;
} break;
......
......@@ -94,6 +94,7 @@ public:
MemoryPool *memoryPool() const;
AST *ast() const;
bool blockErrors() const { return f._blockErrors; }
bool blockErrors(bool block);
bool qtMocRunEnabled() const;
......
......@@ -42,6 +42,33 @@ void parse(const char *fileName, const char *source, unsigned size);
int runWithSystemPreprocessor(int argc, char *argv[]);
int runWithNewPreprocessor(int argc, char *argv[]);
struct V: public ASTVisitor
{
V(TranslationUnit *unit)
: ASTVisitor(unit) {}
virtual bool visit(FunctionDeclaratorAST *ast)
{
if (ast->as_cpp_initializer) {
if (! (ast->symbol && ast->symbol->scope()))
; //translationUnit()->warning(ast->firstToken(), "resolved as function declaration");
else if (ast->symbol->scope()->isNamespace() || ast->symbol->scope()->isTemplate())
; //translationUnit()->warning(ast->firstToken(), "resolved as function declaration");
else if (ast->symbol->scope()->isBlock())
; //translationUnit()->warning(ast->firstToken(), "resolved as C++ initializer");
else
translationUnit()->warning(ast->firstToken(), "ambiguous function declarator or C++ intializer");
}
return true;
}
virtual bool visit(ExpressionOrDeclarationStatementAST *ast)
{
translationUnit()->warning(ast->firstToken(), "ambiguous expression or declaration statement");
return true;
}
};
int main(int argc, char *argv[])
{
if (getenv("CPLUSPLUS_WITH_NEW_PREPROCESSOR"))
......@@ -53,7 +80,7 @@ int main(int argc, char *argv[])
int runWithSystemPreprocessor(int argc, char *argv[])
{
std::string cmdline;
cmdline += "gcc -E -xc++ -U__BLOCKS__ -D__restrict= -D__extension__=";
cmdline += "gcc -E -xc++ -U__BLOCKS__ -D__restrict= -D__restrict__= -D__extension__= -D__imag__= -D__real__= -D__complex__= -D_Complex= -D__signed=signed";
for (int i = 1; i < argc; ++i) {
cmdline += ' ';
......@@ -117,7 +144,12 @@ void parse(const char *fileName, const char *source, unsigned size)
unit.setSource(source, size);
unit.parse();
#if 1
Namespace *globalNamespace = control.newNamespace(0);
Bind bind(&unit);
bind(unit.ast()->asTranslationUnit(), globalNamespace);
V v(&unit);
v.accept(unit.ast());
#endif
}
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