• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ TranslationUnit类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: translationUnit

void Symbol::setSourceLocation(unsigned sourceLocation)
{
    _sourceLocation = sourceLocation;

    if (! _sourceLocation) {
        _isGenerated = false;
        _sourceOffset = 0;
    } else {
        TranslationUnit *unit = translationUnit();

        const Token &tk = unit->tokenAt(sourceLocation);

        _isGenerated = tk.f.generated;
        _sourceOffset = tk.offset;
    }
}
开发者ID:kuailexs,项目名称:symbiandump-mw3,代码行数:16,代码来源:Symbol.cpp


示例17: prefix

/// Currently, we return the end of fileName.cpp
/// \todo take the definitions of the surrounding declarations into account
QList<InsertionLocation> InsertionPointLocator::methodDefinition(
    Declaration *declaration) const
{
    QList<InsertionLocation> result;
    if (!declaration)
        return result;

    const QString declFileName = QString::fromUtf8(declaration->fileName(),
                                                   declaration->fileNameLength());
    QString target = declFileName;
    if (!isSourceFile(declFileName)) {
        Internal::CppToolsPlugin *cpptools = Internal::CppToolsPlugin::instance();
        QString candidate = cpptools->correspondingHeaderOrSource(declFileName);
        if (!candidate.isEmpty())
            target = candidate;
    }

    Document::Ptr doc = m_refactoringChanges->file(target).cppDocument();
    if (doc.isNull())
        return result;

    Snapshot simplified = m_refactoringChanges->snapshot().simplified(doc);
    if (Symbol *s = simplified.findMatchingDefinition(declaration)) {
        if (Function *f = s->asFunction()) {
            if (f->isConst() == declaration->type().isConst()
                    && f->isVolatile() == declaration->type().isVolatile())
                return result;
        }
    }

    TranslationUnit *xUnit = doc->translationUnit();
    unsigned tokenCount = xUnit->tokenCount();
    if (tokenCount < 2) // no tokens available
        return result;

    unsigned line = 0, column = 0;
    xUnit->getTokenEndPosition(xUnit->tokenCount() - 2, &line, &column);

    const QLatin1String prefix("\n\n");
    result.append(InsertionLocation(target, prefix, QString(), line, column));

    return result;
}
开发者ID:NoobSaibot,项目名称:qtcreator-minimap,代码行数:45,代码来源:insertionpointlocator.cpp


示例18: context

IAsyncJob::AsyncPrepareResult UpdateDocumentAnnotationsJob::prepareAsyncRun()
{
    const JobRequest jobRequest = context().jobRequest;
    QTC_ASSERT(jobRequest.type == JobRequest::Type::UpdateDocumentAnnotations,
               return AsyncPrepareResult());

    try {
        m_pinnedDocument = context().documentForJobRequest();
        m_pinnedFileContainer = m_pinnedDocument.fileContainer();

        const TranslationUnit translationUnit
                = m_pinnedDocument.translationUnit(jobRequest.preferredTranslationUnit);
        const TranslationUnitUpdateInput updateInput = m_pinnedDocument.createUpdateInput();
        setRunner([translationUnit, updateInput]() {
            return runAsyncHelper(translationUnit, updateInput);
        });
        return AsyncPrepareResult{translationUnit.id()};

    } catch (const std::exception &exception) {
        qWarning() << "Error in UpdateDocumentAnnotationsJob::prepareAsyncRun:" << exception.what();
        return AsyncPrepareResult();
    }
}
开发者ID:qtproject,项目名称:qt-creator,代码行数:23,代码来源:clangupdatedocumentannotationsjob.cpp


示例19:

bool operator==(const TranslationUnit &first, const TranslationUnit &second)
{
    return first.filePath() == second.filePath() && first.projectPartId() == second.projectPartId();
}
开发者ID:raphaelcotty,项目名称:qt-creator,代码行数:4,代码来源:translationunit.cpp


示例20: createAttributes

/*
     Walk the codemodel.
*/
void CodeModelAttributes::createAttributes(TranslationUnit translationUnit)
{
    m_translationUnit = translationUnit;
    parseScope(const_cast<CodeModel::NamespaceScope *>(translationUnit.codeModel()));
}
开发者ID:husninazer,项目名称:qt,代码行数:8,代码来源:codemodelattributes.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ TranslationUnitDecl类代码示例发布时间:2022-05-31
下一篇:
C++ Transition类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap