本文整理汇总了C++中TranslationUnit::ast方法的典型用法代码示例。如果您正苦于以下问题:C++ TranslationUnit::ast方法的具体用法?C++ TranslationUnit::ast怎么用?C++ TranslationUnit::ast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TranslationUnit
的用法示例。
在下文中一共展示了TranslationUnit::ast方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ctx
void tst_Lookup::base_class_defined_1()
{
Overview overview;
const QByteArray source = "\n"
"class base {};\n"
"class derived: public base {};\n";
Document::Ptr doc = Document::create("base_class_defined_1");
doc->setSource(source);
doc->parse();
doc->check();
QVERIFY(doc->diagnosticMessages().isEmpty());
QCOMPARE(doc->globalSymbolCount(), 2U);
Snapshot snapshot;
snapshot.insert(doc->fileName(), doc);
Document::Ptr emptyDoc = Document::create("<empty>");
Class *baseClass = doc->globalSymbolAt(0)->asClass();
QVERIFY(baseClass);
Class *derivedClass = doc->globalSymbolAt(1)->asClass();
QVERIFY(derivedClass);
LookupContext ctx(derivedClass, emptyDoc, doc, snapshot);
const QList<Symbol *> candidates =
ctx.resolveClass(derivedClass->baseClassAt(0)->name());
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);
const QMap<Class *, ClassSpecifierAST *> classToAST =
invert(classSymbols.asMap());
QVERIFY(classToAST.value(baseClass) != 0);
QVERIFY(classToAST.value(derivedClass) != 0);
}
示例2: ctx
void tst_Lookup::base_class_defined_1()
{
Overview overview;
const QByteArray source = "\n"
"class base {};\n"
"class derived: public base {};\n";
Document::Ptr doc = Document::create("base_class_defined_1");
doc->setUtf8Source(source);
doc->parse();
doc->check();
QVERIFY(doc->diagnosticMessages().isEmpty());
QCOMPARE(doc->globalSymbolCount(), 2U);
Snapshot snapshot;
snapshot.insert(doc);
Class *baseClass = doc->globalSymbolAt(0)->asClass();
QVERIFY(baseClass);
Class *derivedClass = doc->globalSymbolAt(1)->asClass();
QVERIFY(derivedClass);
const LookupContext ctx(doc, snapshot);
LookupScope *klass = ctx.lookupType(derivedClass->baseClassAt(0)->name(), derivedClass->enclosingScope());
QVERIFY(klass != 0);
QCOMPARE(klass->symbols().size(), 1);
QCOMPARE(klass->symbols().first(), baseClass);
TranslationUnit *unit = doc->translationUnit();
QVERIFY(unit != 0);
TranslationUnitAST *ast = unit->ast()->asTranslationUnit();
QVERIFY(ast != 0);
ClassSymbols classSymbols(unit);
classSymbols(ast);
QCOMPARE(classSymbols.size(), 2);
const QMap<Class *, ClassSpecifierAST *> classToAST =
invert(classSymbols.asMap());
QVERIFY(classToAST.value(baseClass) != 0);
QVERIFY(classToAST.value(derivedClass) != 0);
}