Added semantic checks for Q_ENUMS.

This commit is contained in:
Erik Verbruggen
2010-02-06 14:32:25 +01:00
parent ac6aba5ec3
commit 21488e8898
15 changed files with 184 additions and 77 deletions

View File

@@ -570,7 +570,7 @@ public:
unsigned property_specifier_token;
unsigned lparen_token;
ExpressionAST *type_id;
SimpleNameAST *type_name;
SimpleNameAST *property_name;
unsigned read_token;
SimpleNameAST *read_function;
unsigned write_token;

View File

@@ -145,8 +145,8 @@ QtPropertyDeclarationAST *QtPropertyDeclarationAST::clone(MemoryPool *pool) cons
ast->lparen_token = lparen_token;
if (type_id)
ast->type_id = type_id->clone(pool);
if (type_name)
ast->type_name = type_name->clone(pool);
if (property_name)
ast->property_name = property_name->clone(pool);
ast->read_token = read_token;
if (read_function)
ast->read_function = read_function->clone(pool);

View File

@@ -220,9 +220,9 @@ bool ASTMatcher::match(QtPropertyDeclarationAST *node, QtPropertyDeclarationAST
else if (! AST::match(node->type_id, pattern->type_id, this))
return false;
if (! pattern->type_name)
pattern->type_name = node->type_name;
else if (! AST::match(node->type_name, pattern->type_name, this))
if (! pattern->property_name)
pattern->property_name = node->property_name;
else if (! AST::match(node->property_name, pattern->property_name, this))
return false;
pattern->read_token = node->read_token;

View File

@@ -112,7 +112,7 @@ void QtPropertyDeclarationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
accept(type_id, visitor);
accept(type_name, visitor);
accept(property_name, visitor);
accept(read_function, visitor);
accept(write_function, visitor);
accept(reset_function, visitor);

View File

@@ -60,11 +60,7 @@
# elif defined(CPLUSPLUS_BUILD_STATIC_LIB)
# define CPLUSPLUS_EXPORT
# else
# ifdef ICHECK_BUILD
# define CPLUSPLUS_EXPORT
# else
# define CPLUSPLUS_EXPORT Q_DECL_IMPORT
# endif
# define CPLUSPLUS_EXPORT Q_DECL_IMPORT
# endif
#else
# define CPLUSPLUS_EXPORT

View File

@@ -170,9 +170,7 @@ bool CheckDeclaration::visit(SimpleDeclarationAST *ast)
const bool isQ_SLOT = ast->qt_invokable_token && tokenKind(ast->qt_invokable_token) == T_Q_SLOT;
const bool isQ_SIGNAL = ast->qt_invokable_token && tokenKind(ast->qt_invokable_token) == T_Q_SIGNAL;
#ifdef ICHECK_BUILD
const bool isQ_INVOKABLE = ast->qt_invokable_token && tokenKind(ast->qt_invokable_token) == T_Q_INVOKABLE;
#endif
List<Declaration *> **decl_it = &ast->symbols;
for (DeclaratorListAST *it = ast->declarator_list; it; it = it->next) {
@@ -199,10 +197,8 @@ bool CheckDeclaration::visit(SimpleDeclarationAST *ast)
fun->setMethodKey(Function::SignalMethod);
else if (isQ_SLOT)
fun->setMethodKey(Function::SlotMethod);
#ifdef ICHECK_BUILD
else if (isQ_INVOKABLE)
fun->setInvokable(true);
#endif
fun->setMethodKey(Function::InvokableMethod);
fun->setVisibility(semantic()->currentVisibility());
} else if (semantic()->currentMethodKey() != Function::NormalMethod) {
translationUnit()->warning(ast->firstToken(),
@@ -266,28 +262,6 @@ bool CheckDeclaration::visit(AccessDeclarationAST *ast)
return false;
}
#ifdef ICHECK_BUILD
bool CheckDeclaration::visit(QPropertyDeclarationAST *)
{
return false;
}
bool CheckDeclaration::visit(QEnumDeclarationAST *)
{
return false;
}
bool CheckDeclaration::visit(QFlagsDeclarationAST *)
{
return false;
}
bool CheckDeclaration::visit(QDeclareFlagsDeclarationAST *)
{
return false;
}
#endif
bool CheckDeclaration::visit(AsmDefinitionAST *)
{
return false;
@@ -827,3 +801,43 @@ bool CheckDeclaration::visit(ObjCPropertyDeclarationAST *ast)
return false;
}
bool CheckDeclaration::visit(QtDeclareFlagsDeclarationAST *ast)
{
if (ast->flags_name)
semantic()->check(ast->flags_name, _scope);
if (ast->enum_name)
semantic()->check(ast->enum_name, _scope);
return false;
}
bool CheckDeclaration::visit(QtEnumDeclarationAST *ast)
{
for (NameListAST *iter = ast->enumerator_list; iter; iter = iter->next)
semantic()->check(iter->value, _scope);
return false;
}
bool CheckDeclaration::visit(QtFlagsDeclarationAST *ast)
{
for (NameListAST *iter = ast->flag_enums_list; iter; iter = iter->next)
semantic()->check(iter->value, _scope);
return false;
}
bool CheckDeclaration::visit(QtPropertyDeclarationAST *ast)
{
if (ast->type_id)
semantic()->check(ast->type_id, _scope);
if (ast->property_name)
semantic()->check(ast->property_name, _scope);
if (ast->read_function)
semantic()->check(ast->read_function, _scope);
if (ast->write_function)
semantic()->check(ast->write_function, _scope);
if (ast->reset_function)
semantic()->check(ast->reset_function, _scope);
if (ast->notify_function)
semantic()->check(ast->notify_function, _scope);
return false;
}

View File

@@ -77,12 +77,10 @@ protected:
virtual bool visit(SimpleDeclarationAST *ast);
virtual bool visit(EmptyDeclarationAST *ast);
virtual bool visit(AccessDeclarationAST *ast);
#ifdef ICHECK_BUILD
virtual bool visit(QPropertyDeclarationAST *ast);
virtual bool visit(QEnumDeclarationAST *ast);
virtual bool visit(QFlagsDeclarationAST *ast);
virtual bool visit(QDeclareFlagsDeclarationAST *ast);
#endif
virtual bool visit(QtPropertyDeclarationAST *ast);
virtual bool visit(QtEnumDeclarationAST *ast);
virtual bool visit(QtFlagsDeclarationAST *ast);
virtual bool visit(QtDeclareFlagsDeclarationAST *ast);
virtual bool visit(AsmDefinitionAST *ast);
virtual bool visit(ExceptionDeclarationAST *ast);
virtual bool visit(FunctionDefinitionAST *ast);

View File

@@ -1792,8 +1792,8 @@ bool Parser::parseQtPropertyDeclaration(DeclarationAST *&node)
if (LA() == T_LPAREN) {
ast->lparen_token = consumeToken();
parseTypeId(ast->type_id);
ast->type_name = new (_pool) SimpleNameAST;
match(T_IDENTIFIER, &ast->type_name->identifier_token);
ast->property_name = new (_pool) SimpleNameAST;
match(T_IDENTIFIER, &ast->property_name->identifier_token);
while (true) {
if (LA() == T_RPAREN) {
@@ -1963,6 +1963,7 @@ bool Parser::parseQtDeclareFlags(DeclarationAST *&node)
ast->flags_name = new (_pool) SimpleNameAST;
match(T_IDENTIFIER, &ast->flags_name->identifier_token);
match(T_COMMA, &ast->comma_token);
ast->enum_name = new (_pool) SimpleNameAST;
match(T_IDENTIFIER, &ast->enum_name->identifier_token);
match(T_RPAREN, &ast->rparen_token);
node = ast;
@@ -1995,13 +1996,11 @@ bool Parser::parseMemberSpecification(DeclarationAST *&node)
case T_Q_ENUMS:
return parseQtEnumDeclaration(node);
#ifdef ICHECK_BUILD
case T_Q_FLAGS:
return parseQFlags(node);
return parseQtFlags(node);
case T_Q_DECLARE_FLAGS:
return parseQDeclareFlags(node);
#endif
return parseQtDeclareFlags(node);
default:
return parseSimpleDeclaration(node, /*acceptStructDeclarator=*/true);

View File

@@ -353,16 +353,6 @@ bool Function::isPureVirtual() const
void Function::setPureVirtual(bool isPureVirtual)
{ f._isPureVirtual = isPureVirtual; }
#ifdef ICHECK_BUILD
bool Function::isInvokable() const
{ return f._isInvokable == 1; }
void Function::setInvokable(bool isInvokable)
{ f._isInvokable = isInvokable; }
#endif
bool Function::isAmbiguous() const
{ return f._isAmbiguous; }

View File

@@ -303,7 +303,8 @@ public:
enum MethodKey {
NormalMethod,
SlotMethod,
SignalMethod
SignalMethod,
InvokableMethod
};
public:
@@ -351,11 +352,7 @@ public:
void setPureVirtual(bool isPureVirtual);
#ifdef ICHECK_BUILD
bool isInvokable() const;
void setInvokable(bool isInvokable);
bool isEqualTo(const Function* fct, bool ignoreName = false) const;
#endif
// Symbol's interface
@@ -395,9 +392,6 @@ private:
unsigned _isVolatile: 1;
unsigned _isAmbiguous: 1;
unsigned _methodKey: 3;
#ifdef ICHECK_BUILD
unsigned _isInvokable: 1;
#endif
};
union {
unsigned _flags;

View File

@@ -93,9 +93,7 @@ static const char *token_names[] = {
("SIGNAL"), ("SLOT"), ("Q_SIGNAL"), ("Q_SLOT"), ("signals"), ("slots"),
("Q_FOREACH"), ("Q_D"), ("Q_Q"),
#ifdef ICHECK_BUILD
("Q_INVOKABLE"), ("Q_PROPERTY"), ("Q_ENUMS"), ("Q_FLAGS"), ("Q_DECLARE_FLAGS")
#endif
};
Token::Token() :