Commit 6672f89f authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Annotate the ClassSpecifierAST node with the class symbol.

parent 1dcabe5a
......@@ -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);
......
#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)
......
Supports Markdown
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