本文整理汇总了C++中document::Ptr::check方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::check方法的具体用法?C++ Ptr::check怎么用?C++ Ptr::check使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类document::Ptr
的用法示例。
在下文中一共展示了Ptr::check方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_codegen_definition_empty_class
void CppToolsPlugin::test_codegen_definition_empty_class()
{
const QByteArray srcText = "\n"
"class Foo\n" // line 1
"{\n"
"void foo();\n" // line 3
"};\n"
"\n";
const QByteArray dstText = "\n"
"int x;\n" // line 1
"\n";
Document::Ptr src = Document::create(QDir::tempPath() + QLatin1String("/file.h"));
Utils::FileSaver srcSaver(src->fileName());
srcSaver.write(srcText);
srcSaver.finalize();
src->setUtf8Source(srcText);
src->parse();
src->check();
QCOMPARE(src->diagnosticMessages().size(), 0);
QCOMPARE(src->globalSymbolCount(), 1U);
Document::Ptr dst = Document::create(QDir::tempPath() + QLatin1String("/file.cpp"));
Utils::FileSaver dstSaver(dst->fileName());
dstSaver.write(dstText);
dstSaver.finalize();
dst->setUtf8Source(dstText);
dst->parse();
dst->check();
QCOMPARE(dst->diagnosticMessages().size(), 0);
QCOMPARE(dst->globalSymbolCount(), 1U);
Snapshot snapshot;
snapshot.insert(src);
snapshot.insert(dst);
Class *foo = src->globalSymbolAt(0)->asClass();
QVERIFY(foo);
QCOMPARE(foo->line(), 1U);
QCOMPARE(foo->column(), 7U);
QCOMPARE(foo->memberCount(), 1U);
Declaration *decl = foo->memberAt(0)->asDeclaration();
QVERIFY(decl);
QCOMPARE(decl->line(), 3U);
QCOMPARE(decl->column(), 6U);
CppRefactoringChanges changes(snapshot);
InsertionPointLocator find(changes);
QList<InsertionLocation> locList = find.methodDefinition(decl);
QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first();
QCOMPARE(loc.fileName(), dst->fileName());
QCOMPARE(loc.prefix(), QLatin1String("\n\n"));
QCOMPARE(loc.suffix(), QString());
QCOMPARE(loc.line(), 3U);
QCOMPARE(loc.column(), 1U);
}
示例2: get
void tst_Lookup::templates_5()
{
const QByteArray source = "\n"
"struct Point {\n"
" int x,y;\n"
"};\n"
"\n"
"template <typename _Tp>\n"
"struct Allocator {\n"
" typedef const _Tp &const_reference;\n"
"\n"
" const_reference get();\n"
"};\n"
"\n"
"int main()\n"
"{\n"
" Allocator<Point>::const_reference r = pt;\n"
" //r.; // const Point &\n"
"\n"
" Allocator<Point> a;\n"
" a.get(); // const Point &\n"
"}\n";
Document::Ptr doc = Document::create("templates_5");
doc->setUtf8Source(source);
doc->parse();
doc->check();
QVERIFY(doc->diagnosticMessages().isEmpty());
}
示例3: deduceAuto
// Resolves auto and decltype initializer string
QList<LookupItem> TypeResolver::resolveDeclInitializer(
CreateBindings &factory, const Declaration *decl,
const QSet<const Declaration* > &declarationsBeingResolved,
const Identifier *id)
{
const StringLiteral *initializationString = decl->getInitializer();
if (initializationString == 0)
return QList<LookupItem>();
const QByteArray &initializer =
QByteArray::fromRawData(initializationString->chars(),
initializationString->size()).trimmed();
// Skip lambda-function initializers
if (initializer.length() > 0 && initializer[0] == '[')
return QList<LookupItem>();
TypeOfExpression exprTyper;
exprTyper.setExpandTemplates(true);
Document::Ptr doc = factory.snapshot().document(QString::fromLocal8Bit(decl->fileName()));
exprTyper.init(doc, factory.snapshot(), factory.sharedFromThis(), declarationsBeingResolved);
Document::Ptr exprDoc =
documentForExpression(exprTyper.preprocessedExpression(initializer));
factory.addExpressionDocument(exprDoc);
exprDoc->check();
if (id) {
DeduceAutoCheck deduceAuto(id, exprDoc->translationUnit());
if (deduceAuto._block)
return QList<LookupItem>();
}
return exprTyper(extractExpressionAST(exprDoc), exprDoc, decl->enclosingScope());
}
示例4: findUsages
void tst_FindUsages::shadowedNames_2()
{
const QByteArray src = "\n"
"int a();\n"
"struct X{ int a(); };\n"
"int X::a() {}\n"
"void f(X x) { x.a(); }\n"
"void g() { a(); }\n";
Document::Ptr doc = Document::create("shadowedNames_2");
doc->setUtf8Source(src);
doc->parse();
doc->check();
QVERIFY(doc->diagnosticMessages().isEmpty());
QCOMPARE(doc->globalSymbolCount(), 5U);
Snapshot snapshot;
snapshot.insert(doc);
Class *c = doc->globalSymbolAt(1)->asClass();
QVERIFY(c);
QCOMPARE(c->name()->identifier()->chars(), "X");
QCOMPARE(c->memberCount(), 1U);
Declaration *d = c->memberAt(0)->asDeclaration();
QVERIFY(d);
QCOMPARE(d->name()->identifier()->chars(), "a");
FindUsages findUsages(src, doc, snapshot);
findUsages(d);
QCOMPARE(findUsages.usages().size(), 3);
}
示例5: begin
void tst_Lookup::templates_1()
{
const QByteArray source = "\n"
"namespace std {\n"
" template <typename T>\n"
" struct _List_iterator {\n"
" T data;\n"
" };\n"
"\n"
" template <typename T>\n"
" struct list {\n"
" typedef _List_iterator<T> iterator;\n"
"\n"
" iterator begin();\n"
" _List_iterator<T> end();\n"
" };\n"
"}\n"
"\n"
"struct Point {\n"
" int x, y;\n"
"};\n"
"\n"
"int main()\n"
"{\n"
" std::list<Point> l;\n"
" l.begin(); // std::_List_iterator<Point> .. and not only _List_iterator<Point>\n"
" l.end(); // std::_List_iterator<Point>\n"
"}\n";
Document::Ptr doc = Document::create("templates_1");
doc->setUtf8Source(source);
doc->parse();
doc->check();
QVERIFY(doc->diagnosticMessages().isEmpty());
}
示例6: inlineMethod
void tst_FindUsages::inlineMethod()
{
const QByteArray src = "\n"
"class Tst {\n"
" int method(int arg) {\n"
" return arg;\n"
" }\n"
"};\n";
Document::Ptr doc = Document::create("inlineMethod");
doc->setUtf8Source(src);
doc->parse();
doc->check();
QVERIFY(doc->diagnosticMessages().isEmpty());
QCOMPARE(doc->globalSymbolCount(), 1U);
Snapshot snapshot;
snapshot.insert(doc);
Class *tst = doc->globalSymbolAt(0)->asClass();
QVERIFY(tst);
QCOMPARE(tst->memberCount(), 1U);
Function *method = tst->memberAt(0)->asFunction();
QVERIFY(method);
QCOMPARE(method->argumentCount(), 1U);
Argument *arg = method->argumentAt(0)->asArgument();
QVERIFY(arg);
QCOMPARE(arg->identifier()->chars(), "arg");
FindUsages findUsages(src, doc, snapshot);
findUsages(arg);
QCOMPARE(findUsages.usages().size(), 2);
QCOMPARE(findUsages.references().size(), 2);
}
示例7: lambdaCaptureByReference
void tst_FindUsages::lambdaCaptureByReference()
{
const QByteArray src = "\n"
"void f() {\n"
" int test;\n"
" [&test] { ++test; };\n"
"}\n";
Document::Ptr doc = Document::create("lambdaCaptureByReference");
doc->setUtf8Source(src);
doc->parse();
doc->check();
QVERIFY(doc->diagnosticMessages().isEmpty());
QCOMPARE(doc->globalSymbolCount(), 1U);
Snapshot snapshot;
snapshot.insert(doc);
Function *f = doc->globalSymbolAt(0)->asFunction();
QVERIFY(f);
QCOMPARE(f->memberCount(), 1U);
Block *b = f->memberAt(0)->asBlock();
QCOMPARE(b->memberCount(), 2U);
Declaration *d = b->memberAt(0)->asDeclaration();
QVERIFY(d);
QCOMPARE(d->name()->identifier()->chars(), "test");
FindUsages findUsages(src, doc, snapshot);
findUsages(d);
QCOMPARE(findUsages.usages().size(), 3);
}
示例8: main
void tst_Lookup::templates_2()
{
const QByteArray source = "\n"
"template <typename T1>\n"
"struct Node {\n"
" T1 value;\n"
" Node *next;\n"
" Node<T1> *other_next;\n"
"};\n"
"\n"
"template <typename T2>\n"
"struct List {\n"
" Node<T2> *elements;\n"
"};\n"
"\n"
"int main()\n"
"{\n"
" List<int> *e;\n"
" e->elements; // Node<int> *\n"
" e->elements->next; // Node<int> *\n"
" e->elements->other_next; // Node<int> *\n"
"}\n"
;
Document::Ptr doc = Document::create("templates_2");
doc->setUtf8Source(source);
doc->parse();
doc->check();
QVERIFY(doc->diagnosticMessages().isEmpty());
}
示例9: test_codegen_public_in_empty_class
/*!
Should insert at line 3, column 1, with "public:\n" as prefix and without suffix.
*/
void CppToolsPlugin::test_codegen_public_in_empty_class()
{
const QByteArray src = "\n"
"class Foo\n" // line 1
"{\n"
"};\n"
"\n";
Document::Ptr doc = Document::create(QLatin1String("public_in_empty_class"));
doc->setUtf8Source(src);
doc->parse();
doc->check();
QCOMPARE(doc->diagnosticMessages().size(), 0);
QCOMPARE(doc->globalSymbolCount(), 1U);
Class *foo = doc->globalSymbolAt(0)->asClass();
QVERIFY(foo);
QCOMPARE(foo->line(), 1U);
QCOMPARE(foo->column(), 7U);
Snapshot snapshot;
snapshot.insert(doc);
CppRefactoringChanges changes(snapshot);
InsertionPointLocator find(changes);
InsertionLocation loc = find.methodDeclarationInClass(
doc->fileName(),
foo,
InsertionPointLocator::Public);
QVERIFY(loc.isValid());
QCOMPARE(loc.prefix(), QLatin1String("public:\n"));
QVERIFY(loc.suffix().isEmpty());
QCOMPARE(loc.line(), 3U);
QCOMPARE(loc.column(), 1U);
}
示例10: class_with_baseclass
void tst_Lookup::class_with_baseclass()
{
const QByteArray source = "\n"
"@implementation BaseZoo {} -(void)baseDecl; -(void)baseMethod{} @end\n"
"@interface Zoo: BaseZoo {} +(id)alloc; -(id)init; @end\n"
"@implementation Zoo +(id)alloc{} -(id)init{} -(void)dealloc{} @end\n";
Document::Ptr doc = Document::create("class_with_baseclass");
doc->setUtf8Source(source);
doc->parse();
doc->check();
QVERIFY(doc->diagnosticMessages().isEmpty());
QCOMPARE(doc->globalSymbolCount(), 3U);
Snapshot snapshot;
snapshot.insert(doc);
Document::Ptr emptyDoc = Document::create("<empty>");
ObjCClass *baseZoo = doc->globalSymbolAt(0)->asObjCClass();
QVERIFY(baseZoo);
QVERIFY(!baseZoo->isInterface());
QCOMPARE(baseZoo->memberCount(), 2U);
ObjCClass *zooIface = doc->globalSymbolAt(1)->asObjCClass();
QVERIFY(zooIface);
QVERIFY(zooIface->isInterface());
QVERIFY(zooIface->baseClass()->name() == baseZoo->name());
ObjCClass *zooImpl = doc->globalSymbolAt(2)->asObjCClass();
QVERIFY(zooImpl);
QVERIFY(!zooImpl->isInterface());
QCOMPARE(zooImpl->memberCount(), 3U);
Declaration *baseDecl = baseZoo->memberAt(0)->asDeclaration();
QVERIFY(baseDecl);
QVERIFY(baseDecl->name() && baseDecl->name()->identifier());
QCOMPARE(QLatin1String(baseDecl->name()->identifier()->chars()), QLatin1String("baseDecl"));
ObjCMethod *baseMethod = baseZoo->memberAt(1)->asObjCMethod();
QVERIFY(baseMethod);
QVERIFY(baseMethod->name() && baseMethod->name()->identifier());
QCOMPARE(QLatin1String(baseMethod->name()->identifier()->chars()), QLatin1String("baseMethod"));
const LookupContext context(doc, snapshot);
LookupScope *objClass = context.lookupType(baseZoo->name(), zooImpl->enclosingScope());
QVERIFY(objClass != 0);
QVERIFY(objClass->symbols().contains(baseZoo));
QList<LookupItem> results = context.lookup(baseDecl->name(), zooImpl);
QCOMPARE(results.size(), 1);
QCOMPARE(results.at(0).declaration(), baseDecl);
results = context.lookup(baseMethod->name(), zooImpl);
QCOMPARE(results.size(), 1);
QCOMPARE(results.at(0).declaration(), baseMethod);
}
示例11: class_with_protocol_with_protocol
void tst_Lookup::class_with_protocol_with_protocol()
{
const QByteArray source = "\n"
"@protocol P1 -(void)p1method; @end\n"
"@protocol P2 <P1> -(void)p2method; @end\n"
"@interface Zoo <P2> {} +(id)alloc; -(id)init; @end\n"
"@implementation Zoo +(id)alloc{} -(id)init{} -(void)dealloc{} @end\n";
Document::Ptr doc = Document::create("class_with_protocol_with_protocol");
doc->setUtf8Source(source);
doc->parse();
doc->check();
QVERIFY(doc->diagnosticMessages().isEmpty());
QCOMPARE(doc->globalSymbolCount(), 4U);
Snapshot snapshot;
snapshot.insert(doc);
ObjCProtocol *P1 = doc->globalSymbolAt(0)->asObjCProtocol();
QVERIFY(P1);
QCOMPARE(P1->memberCount(), 1U);
QCOMPARE(P1->protocolCount(), 0U);
Declaration *p1method = P1->memberAt(0)->asDeclaration();
QVERIFY(p1method);
QCOMPARE(QLatin1String(p1method->name()->identifier()->chars()), QLatin1String("p1method"));
ObjCProtocol *P2 = doc->globalSymbolAt(1)->asObjCProtocol();
QVERIFY(P2);
QCOMPARE(P2->memberCount(), 1U);
QCOMPARE(P2->protocolCount(), 1U);
QCOMPARE(QLatin1String(P2->protocolAt(0)->name()->identifier()->chars()), QLatin1String("P1"));
ObjCClass *zooImpl = doc->globalSymbolAt(3)->asObjCClass();
QVERIFY(zooImpl);
const LookupContext context(doc, snapshot);
{
const QList<LookupItem> candidates = context.lookup(P1->name(), zooImpl->enclosingScope());
QCOMPARE(candidates.size(), 1);
QVERIFY(candidates.at(0).declaration() == P1);
}
{
const QList<LookupItem> candidates = context.lookup(P2->protocolAt(0)->name(), zooImpl->enclosingScope());
QCOMPARE(candidates.size(), 1);
QVERIFY(candidates.first().declaration() == P1);
}
QList<LookupItem> results = context.lookup(p1method->name(), zooImpl);
QCOMPARE(results.size(), 1);
QCOMPARE(results.at(0).declaration(), p1method);
}
示例12: test_codegen_qtdesigner_integration
/*!
Should insert at line 18, column 1, with "private slots:\n" as prefix and "\n"
as suffix.
This is the typical Qt Designer case, with test-input like what the integration
generates.
*/
void CppToolsPlugin::test_codegen_qtdesigner_integration()
{
const QByteArray src = "/**** Some long (C)opyright notice ****/\n"
"#ifndef MAINWINDOW_H\n"
"#define MAINWINDOW_H\n"
"\n"
"#include <QMainWindow>\n"
"\n"
"namespace Ui {\n"
" class MainWindow;\n"
"}\n"
"\n"
"class MainWindow : public QMainWindow\n" // line 10
"{\n"
" Q_OBJECT\n"
"\n"
"public:\n" // line 14
" explicit MainWindow(QWidget *parent = 0);\n"
" ~MainWindow();\n"
"\n"
"private:\n" // line 18
" Ui::MainWindow *ui;\n"
"};\n"
"\n"
"#endif // MAINWINDOW_H\n";
Document::Ptr doc = Document::create(QLatin1String("qtdesigner_integration"));
doc->setUtf8Source(src);
doc->parse();
doc->check();
QCOMPARE(doc->diagnosticMessages().size(), 0);
QCOMPARE(doc->globalSymbolCount(), 2U);
Class *foo = doc->globalSymbolAt(1)->asClass();
QVERIFY(foo);
QCOMPARE(foo->line(), 10U);
QCOMPARE(foo->column(), 7U);
Snapshot snapshot;
snapshot.insert(doc);
CppRefactoringChanges changes(snapshot);
InsertionPointLocator find(changes);
InsertionLocation loc = find.methodDeclarationInClass(
doc->fileName(),
foo,
InsertionPointLocator::PrivateSlot);
QVERIFY(loc.isValid());
QCOMPARE(loc.prefix(), QLatin1String("private slots:\n"));
QCOMPARE(loc.suffix(), QLatin1String("\n"));
QCOMPARE(loc.line(), 18U);
QCOMPARE(loc.column(), 1U);
}
示例13: reference
QList<LookupItem> TypeOfExpression::reference(const QByteArray &utf8code,
Scope *scope,
PreprocessMode mode)
{
Document::Ptr expressionDoc;
if (mode == Preprocess)
expressionDoc = documentForExpression(preprocessedExpression(utf8code));
else
expressionDoc = documentForExpression(utf8code);
expressionDoc->check();
return reference(extractExpressionAST(expressionDoc), expressionDoc, scope);
}
示例14: 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);
}
示例15: 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);
}