Commit 40725cfd authored by Christian Kamm's avatar Christian Kamm

C++: Bind Q_ENUMS in the code model.

Reviewed-by: Roberto Raggi
parent 0edd253b
......@@ -1931,8 +1931,13 @@ bool Bind::visit(QtEnumDeclarationAST *ast)
// unsigned enum_specifier_token = ast->enum_specifier_token;
// unsigned lparen_token = ast->lparen_token;
for (NameListAST *it = ast->enumerator_list; it; it = it->next) {
/*const Name *value =*/ this->name(it->value);
const Name *value = this->name(it->value);
if (!value)
continue;
QtEnum *qtEnum = control()->newQtEnum(it->value->firstToken(), value);
_scope->addMember(qtEnum);
}
// unsigned rparen_token = ast->rparen_token;
return false;
}
......@@ -2833,6 +2838,7 @@ bool Bind::visit(EnumSpecifierAST *ast)
{
unsigned sourceLocation = location(ast->name, ast->firstToken());
const Name *enumName = this->name(ast->name);
Enum *e = control()->newEnum(sourceLocation, enumName);
e->setStartOffset(tokenAt(sourceLocation).end()); // at the end of the enum or identifier token.
e->setEndOffset(tokenAt(ast->lastToken() - 1).end());
......
......@@ -133,6 +133,7 @@ class Token;
// Qt symbols
class QtPropertyDeclaration;
class QtEnum;
// Objective-C symbols
class ObjCBaseClass;
......
......@@ -410,6 +410,13 @@ public:
return d;
}
QtEnum *newQtEnum(unsigned sourceLocation, const Name *name)
{
QtEnum *d = new QtEnum(translationUnit, sourceLocation, name);
symbols.push_back(d);
return d;
}
ObjCBaseClass *newObjCBaseClass(unsigned sourceLocation, const Name *name)
{
ObjCBaseClass *c = new ObjCBaseClass(translationUnit, sourceLocation, name);
......@@ -720,6 +727,9 @@ QtPropertyDeclaration *Control::newQtPropertyDeclaration(unsigned sourceLocation
const Name *name)
{ return d->newQtPropertyDeclaration(sourceLocation, name); }
QtEnum *Control::newQtEnum(unsigned sourceLocation, const Name *name)
{ return d->newQtEnum(sourceLocation, name); }
ObjCBaseClass *Control::newObjCBaseClass(unsigned sourceLocation, const Name *name)
{ return d->newObjCBaseClass(sourceLocation, name); }
......
......@@ -161,6 +161,9 @@ public:
/// Creates a new QtPropertyDeclaration symbol.
QtPropertyDeclaration *newQtPropertyDeclaration(unsigned sourceLocation, const Name *name = 0);
/// Creates a new QtEnum symbol.
QtEnum *newQtEnum(unsigned sourceLocation, const Name *name = 0);
ObjCBaseClass *newObjCBaseClass(unsigned sourceLocation, const Name *name);
ObjCBaseProtocol *newObjCBaseProtocol(unsigned sourceLocation, const Name *name);
......
......@@ -205,6 +205,9 @@ public:
/// Returns true if this Symbol is a QtPropertyDeclaration.
bool isQtPropertyDeclaration() const;
/// Returns true if this Symbol is a QtEnum.
bool isQtEnum() const;
bool isObjCBaseClass() const;
bool isObjCBaseProtocol() const;
......@@ -242,6 +245,7 @@ public:
virtual const BaseClass *asBaseClass() const { return 0; }
virtual const ForwardClassDeclaration *asForwardClassDeclaration() const { return 0; }
virtual const QtPropertyDeclaration *asQtPropertyDeclaration() const { return 0; }
virtual const QtEnum *asQtEnum() const { return 0; }
virtual const ObjCBaseClass *asObjCBaseClass() const { return 0; }
virtual const ObjCBaseProtocol *asObjCBaseProtocol() const { return 0; }
virtual const ObjCClass *asObjCClass() const { return 0; }
......@@ -267,6 +271,7 @@ public:
virtual BaseClass *asBaseClass() { return 0; }
virtual ForwardClassDeclaration *asForwardClassDeclaration() { return 0; }
virtual QtPropertyDeclaration *asQtPropertyDeclaration() { return 0; }
virtual QtEnum *asQtEnum() { return 0; }
virtual ObjCBaseClass *asObjCBaseClass() { return 0; }
virtual ObjCBaseProtocol *asObjCBaseProtocol() { return 0; }
virtual ObjCClass *asObjCClass() { return 0; }
......
......@@ -89,6 +89,7 @@ public:
// Qt
virtual bool visit(QtPropertyDeclaration *) { return true; }
virtual bool visit(QtEnum *) { return true; }
// Objective-C
virtual bool visit(ObjCBaseClass *) { return true; }
......
......@@ -687,6 +687,7 @@ void Class::visitSymbol0(SymbolVisitor *visitor)
QtPropertyDeclaration::QtPropertyDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
: Symbol(translationUnit, sourceLocation, name)
, _flags(NoFlags)
{ }
QtPropertyDeclaration::~QtPropertyDeclaration()
......@@ -708,6 +709,20 @@ void QtPropertyDeclaration::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }
QtEnum::QtEnum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
: Symbol(translationUnit, sourceLocation, name)
{ }
QtEnum::~QtEnum()
{ }
FullySpecifiedType QtEnum::type() const
{ return FullySpecifiedType(); }
void QtEnum::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }
ObjCBaseClass::ObjCBaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name)
: Symbol(translationUnit, sourceLocation, name)
{ }
......
......@@ -524,6 +524,7 @@ class CPLUSPLUS_EXPORT QtPropertyDeclaration: public Symbol
{
public:
enum Flag {
NoFlags = 0,
ReadFunction = 1 << 0,
WriteFunction = 1 << 1,
ResetFunction = 1 << 2,
......@@ -566,6 +567,25 @@ private:
int _flags;
};
class CPLUSPLUS_EXPORT QtEnum: public Symbol
{
public:
QtEnum(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
virtual ~QtEnum();
// Symbol's interface
virtual FullySpecifiedType type() const;
virtual const QtEnum *asQtEnum() const
{ return this; }
virtual QtEnum *asQtEnum()
{ return this; }
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
};
class CPLUSPLUS_EXPORT ObjCBaseClass: public Symbol
{
public:
......
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