forked from qt-creator/qt-creator
Annotate the ClassSpecifierAST node with the class symbol.
This commit is contained in:
@@ -515,6 +515,9 @@ public:
|
||||
DeclarationAST *member_specifiers;
|
||||
unsigned rbrace_token;
|
||||
|
||||
public: // annotations
|
||||
Class *class_symbol;
|
||||
|
||||
public:
|
||||
virtual unsigned firstToken() const;
|
||||
virtual unsigned lastToken() const;
|
||||
|
@@ -300,6 +300,7 @@ bool CheckSpecifier::visit(ClassSpecifierAST *ast)
|
||||
{
|
||||
Name *className = semantic()->check(ast->name, _scope);
|
||||
Class *klass = control()->newClass(ast->firstToken(), className);
|
||||
ast->class_symbol = klass;
|
||||
unsigned classKey = tokenKind(ast->classkey_token);
|
||||
if (classKey == T_CLASS)
|
||||
klass->setClassKey(Class::ClassKey);
|
||||
|
@@ -1,6 +1,10 @@
|
||||
|
||||
#include <QtTest>
|
||||
#include <QObject>
|
||||
|
||||
#include <AST.h>
|
||||
#include <ASTVisitor.h>
|
||||
#include <TranslationUnit.h>
|
||||
#include <CppDocument.h>
|
||||
#include <LookupContext.h>
|
||||
#include <Symbols.h>
|
||||
@@ -8,6 +12,29 @@
|
||||
|
||||
CPLUSPLUS_USE_NAMESPACE
|
||||
|
||||
class ClassSymbols: protected ASTVisitor,
|
||||
public QMap<ClassSpecifierAST *, Class *>
|
||||
{
|
||||
public:
|
||||
ClassSymbols(Control *control)
|
||||
: ASTVisitor(control)
|
||||
{ }
|
||||
|
||||
void operator()(AST *ast)
|
||||
{ accept(ast); }
|
||||
|
||||
protected:
|
||||
virtual bool visit(ClassSpecifierAST *ast)
|
||||
{
|
||||
Class *classSymbol = ast->class_symbol;
|
||||
Q_ASSERT(classSymbol != 0);
|
||||
|
||||
insert(ast, classSymbol);
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class tst_Lookup: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -50,6 +77,17 @@ void tst_Lookup::base_class_defined_1()
|
||||
|
||||
QCOMPARE(candidates.size(), 1);
|
||||
QCOMPARE(candidates.at(0), baseClass);
|
||||
|
||||
TranslationUnit *unit = doc->translationUnit();
|
||||
QVERIFY(unit != 0);
|
||||
|
||||
TranslationUnitAST *ast = unit->ast()->asTranslationUnit();
|
||||
QVERIFY(ast != 0);
|
||||
|
||||
ClassSymbols classSymbols(doc->control());
|
||||
classSymbols(ast);
|
||||
|
||||
QCOMPARE(classSymbols.size(), 2);
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_Lookup)
|
||||
|
Reference in New Issue
Block a user