当前位置: 首页>>代码示例>>C++>>正文


C++ TranslationUnit类代码示例

本文整理汇总了C++中TranslationUnit的典型用法代码示例。如果您正苦于以下问题:C++ TranslationUnit类的具体用法?C++ TranslationUnit怎么用?C++ TranslationUnit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TranslationUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: PrintTo

void PrintTo(const TranslationUnit &translationUnit, ::std::ostream *os)
{
    *os << "TranslationUnit("
        << translationUnit.filePath().constData() << ", "
        << translationUnit.projectPartId().constData() << ", "
        << translationUnit.documentRevision() << ")";
}
开发者ID:raphaelcotty,项目名称:qt-creator,代码行数:7,代码来源:translationunit.cpp

示例2: test_main

int test_main(int argc, char * argv[])
{
   try
   { 
      // setup log
      initializeStderrLog("coredev", ::core::system::kLogLevelWarning);

      // ignore sigpipe
      Error error = ::core::system::ignoreSignal(::core::system::SigPipe);
      if (error)
         LOG_ERROR(error);

      // write a C++ file
      std::string cpp =
        "#include <string>\n"
        "class X { public:\n"
        "   void test(int y, int x = 10);\n"
        "}\n"
        "void X::test(int y, int x) {}\n"
        "void foobar() {\n"
        "   X x;\n"
        "   x."
        "}";
      std::ofstream ostr("foo.cpp");
      ostr << cpp;
      ostr.close();

      // load libclang
      using namespace libclang;
      std::string diagnostics;
      clang().load(EmbeddedLibrary(), LibraryVersion(3,4,0), &diagnostics);
      if (!clang().isLoaded())
      {
         std::cerr << "Failed to load libclang: " << diagnostics << std::endl;
         return EXIT_FAILURE;
      }

      // create a source index and get a translation unit for it
      SourceIndex sourceIndex;
      TranslationUnit tu = sourceIndex.getTranslationUnit("foo.cpp");
      if (tu.empty())
      {
         std::cerr << "No translation unit foo.cpp" << std::endl;
         return EXIT_FAILURE;
      }

      // code complete
      CodeCompleteResults results = tu.codeCompleteAt("foo.cpp", 8, 6);
      for (unsigned i = 0; i<results.getNumResults(); i++) {
        std::cout << results.getResult(i).getTypedText() << std::endl;
        std::cout << "   " << results.getResult(i).getText() << std::endl;
      }

      return EXIT_SUCCESS;
   }
   CATCH_UNEXPECTED_EXCEPTION
   
   // if we got this far we had an unexpected exception
   return EXIT_FAILURE ;
}
开发者ID:howarthjw,项目名称:rstudio,代码行数:60,代码来源:Main.cpp

示例3: context

IAsyncJob::AsyncPrepareResult UpdateAnnotationsJob::prepareAsyncRun()
{
    const JobRequest jobRequest = context().jobRequest;
    QTC_ASSERT(isExpectedJobRequestType(jobRequest), return AsyncPrepareResult());
    QTC_ASSERT(acquireDocument(), return AsyncPrepareResult());

    const TranslationUnit translationUnit = *m_translationUnit;
    const TranslationUnitUpdateInput updateInput = createUpdateInput(m_pinnedDocument);
    setRunner([translationUnit, updateInput]() {
        TIME_SCOPE_DURATION("UpdateAnnotationsJobRunner");

        // Update
        UpdateAnnotationsJob::AsyncResult asyncResult;
        asyncResult.updateResult = translationUnit.update(updateInput);

        // Collect
        translationUnit.extractAnnotations(asyncResult.firstHeaderErrorDiagnostic,
                                           asyncResult.diagnostics,
                                           asyncResult.tokenInfos,
                                           asyncResult.skippedSourceRanges);
        asyncResult.unresolvedFilePaths.unite(
            unresolvedFilePaths({asyncResult.firstHeaderErrorDiagnostic}));
        asyncResult.unresolvedFilePaths.unite(unresolvedFilePaths(asyncResult.diagnostics));

        return asyncResult;
    });

    return AsyncPrepareResult{translationUnit.id()};
}
开发者ID:kai66673,项目名称:qt-creator,代码行数:29,代码来源:clangupdateannotationsjob.cpp

示例4: qCDebug

bool JobQueue::isJobRequestOutDated(const JobRequest &jobRequest) const
{
    const JobRequest::Requirements requirements = jobRequest.requirements;
    const UnsavedFiles unsavedFiles = m_translationUnits.unsavedFiles();

    if (requirements.testFlag(JobRequest::CurrentUnsavedFiles)) {
        if (jobRequest.unsavedFilesChangeTimePoint != unsavedFiles.lastChangeTimePoint()) {
            qCDebug(jobsLog) << "Removing due to outdated unsaved files:" << jobRequest;
            return true;
        }
    }

    bool projectCheckedAndItExists = false;

    if (requirements.testFlag(JobRequest::DocumentValid)) {
        if (!m_translationUnits.hasTranslationUnit(jobRequest.filePath, jobRequest.projectPartId)) {
            qCDebug(jobsLog) << "Removing due to already closed document:" << jobRequest;
            return true;
        }

        if (!m_projectParts.hasProjectPart(jobRequest.projectPartId)) {
            qCDebug(jobsLog) << "Removing due to already closed project:" << jobRequest;
            return true;
        }
        projectCheckedAndItExists = true;

        const TranslationUnit translationUnit
                = m_translationUnits.translationUnit(jobRequest.filePath, jobRequest.projectPartId);
        if (!translationUnit.isIntact()) {
            qCDebug(jobsLog) << "Removing due to not intact translation unit:" << jobRequest;
            return true;
        }

        if (requirements.testFlag(JobRequest::CurrentDocumentRevision)) {
            if (translationUnit.documentRevision() != jobRequest.documentRevision) {
                qCDebug(jobsLog) << "Removing due to changed document revision:" << jobRequest;
                return true;
            }
        }
    }

    if (requirements.testFlag(JobRequest::CurrentProject)) {
        if (!projectCheckedAndItExists && !m_projectParts.hasProjectPart(jobRequest.projectPartId)) {
            qCDebug(jobsLog) << "Removing due to already closed project:" << jobRequest;
            return true;
        }

        const ProjectPart &project = m_projectParts.project(jobRequest.projectPartId);
        if (project.lastChangeTimePoint() != jobRequest.projectChangeTimePoint) {
            qCDebug(jobsLog) << "Removing due to outdated project:" << jobRequest;
            return true;
        }
    }

    return false;
}
开发者ID:qrsrjm,项目名称:qt-creator,代码行数:56,代码来源:clangjobqueue.cpp

示例5: sendDocumentAnnotations

void TranslationUnits::sendDocumentAnnotations(const TranslationUnit &translationUnit)
{
    if (sendDocumentAnnotationsCallback) {
        DocumentAnnotationsChangedMessage message(translationUnit.fileContainer(),
                                                  translationUnit.mainFileDiagnostics(),
                                                  translationUnit.highlightingMarks().toHighlightingMarksContainers(),
                                                  translationUnit.skippedSourceRanges().toSourceRangeContainers());

        sendDocumentAnnotationsCallback(std::move(message));
    }
}
开发者ID:,项目名称:,代码行数:11,代码来源:

示例6: TranslationUnit

 TranslationUnit *parse(const QByteArray &source,
                        TranslationUnit::ParseMode mode,
                        LanguageFeatures features)
 {
     const StringLiteral *fileId = control->stringLiteral("<stdin>");
     TranslationUnit *unit = new TranslationUnit(control.data(), fileId);
     unit->setSource(source.constData(), source.length());
     unit->setLanguageFeatures(features);
     unit->parse(mode);
     return unit;
 }
开发者ID:DuinoDu,项目名称:qt-creator,代码行数:11,代码来源:tst_semantic.cpp

示例7: translationUnit

TranslationUnitUpdater Document::createUpdater() const
{
    TranslationUnit unit = translationUnit();

    const TranslationUnitUpdateInput updateInput = createUpdateInput();
    TranslationUnitUpdater updater(unit.id(),
                                   unit.cxIndex(),
                                   unit.cxTranslationUnit(),
                                   updateInput);

    return updater;
}
开发者ID:choenig,项目名称:qt-creator,代码行数:12,代码来源:clangdocument.cpp

示例8: priority

static int priority(const TranslationUnit &translationUnit)
{
    int thePriority = 0;

    if (translationUnit.isUsedByCurrentEditor())
        thePriority += 1000;

    if (translationUnit.isVisibleInEditor())
        thePriority += 100;

    return thePriority;
}
开发者ID:qrsrjm,项目名称:qt-creator,代码行数:12,代码来源:clangjobqueue.cpp

示例9: TranslationUnit

 TranslationUnit *parse(const QByteArray &source,
                        TranslationUnit::ParseMode mode,
                        bool blockErrors = false)
 {
     StringLiteral *fileId = control.findOrInsertStringLiteral("<stdin>");
     TranslationUnit *unit = new TranslationUnit(&control, fileId);
     unit->setObjCEnabled(true);
     unit->setSource(source.constData(), source.length());
     unit->blockErrors(blockErrors);
     unit->parse(mode);
     return unit;
 }
开发者ID:halsten,项目名称:beaverdbg,代码行数:12,代码来源:tst_ast.cpp

示例10: QVERIFY

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);
}
开发者ID:halsten,项目名称:beaverdbg,代码行数:52,代码来源:tst_lookup.cpp

示例11: context

IAsyncJob::AsyncPrepareResult UpdateExtraDocumentAnnotationsJob::prepareAsyncRun()
{
    const JobRequest jobRequest = context().jobRequest;
    QTC_ASSERT(acquireDocument(), return AsyncPrepareResult());

    const TranslationUnit translationUnit = *m_translationUnit;
    setRunner([translationUnit]() {
        TIME_SCOPE_DURATION("UpdateExtraDocumentAnnotationsJobRunner");
        return translationUnit.fullTokenInfos().toTokenInfoContainers();
    });

    return AsyncPrepareResult{translationUnit.id()};
}
开发者ID:choenig,项目名称:qt-creator,代码行数:13,代码来源:clangupdateextradocumentannotationsjob.cpp

示例12: TranslationUnit

 TranslationUnit *parse(const QByteArray &source,
                        TranslationUnit::ParseMode mode,
                        bool enableObjc,
                        bool qtMocRun)
 {
     const StringLiteral *fileId = control->stringLiteral("<stdin>");
     TranslationUnit *unit = new TranslationUnit(control.data(), fileId);
     unit->setSource(source.constData(), source.length());
     unit->setObjCEnabled(enableObjc);
     unit->setQtMocRunEnabled(qtMocRun);
     unit->parse(mode);
     return unit;
 }
开发者ID:,项目名称:,代码行数:13,代码来源:

示例13: TEST

TEST(visit, declTest)
{
    const char* path = "loadsrcs/decl.c";
    CyFlowVisitor* visitor = new CyFlowVisitor();

    EXPECT_EQ( 0 ,cflowSrcParse(path));

    TranslationUnit* unit = TranslationUnit::getInstance();
    unit->accept(visitor);
    visitor->save("dots/decl");
    unit->deleteInstance();
    delete visitor;
}
开发者ID:yubako,项目名称:cflowmake,代码行数:13,代码来源:decl.cpp

示例14: QVERIFY

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);
}
开发者ID:AgnosticPope,项目名称:qt-creator,代码行数:50,代码来源:tst_lookup.cpp

示例15: TEST_F

TEST_F( TranslationUnitTest, InvalidTranslationUnit ) {

  TranslationUnit unit;

  EXPECT_TRUE( unit.IsCurrentlyUpdating() );

  EXPECT_EQ( std::vector< CompletionData >(),
             unit.CandidatesForLocation( 1, 1, std::vector< UnsavedFile >() ) );

  EXPECT_EQ( Location(),
             unit.GetDeclarationLocation( 1,
                                          1,
                                          std::vector< UnsavedFile >() ) );

  EXPECT_EQ( Location(),
             unit.GetDefinitionLocation( 1,
                                         1,
                                         std::vector< UnsavedFile >() ) );

  EXPECT_EQ( std::string( "Internal error: no translation unit" ),
             unit.GetTypeAtLocation( 1, 1, std::vector< UnsavedFile >() ) );

  EXPECT_EQ( std::string( "Internal error: no translation unit" ),
             unit.GetEnclosingFunctionAtLocation( 1,
                                                  1,
                                                  std::vector< UnsavedFile >()
                                                ) );

  EXPECT_EQ( DocumentationData(),
             unit.GetDocsForLocationInFile( 1,
                                            1,
                                            std::vector< UnsavedFile >(), false
                                          ) );
}
开发者ID:CoderPad,项目名称:ycmd,代码行数:34,代码来源:TranslationUnit_test.cpp


注:本文中的TranslationUnit类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。