Exemplo n.º 1
0
void TranslationUnit::createTranslationUnitIfNeeded() const
{
    if (!d->translationUnit) {
        d->translationUnit = CXTranslationUnit();

        const auto args = commandLineArguments();
        if (isVerboseModeEnabled())
            args.print();

        CXErrorCode errorCode = clang_parseTranslationUnit2(index(),
                                                            NULL,
                                                            args.data(),
                                                            args.count(),
                                                            unsavedFiles().cxUnsavedFiles(),
                                                            unsavedFiles().count(),
                                                            defaultOptions(),
                                                            &d->translationUnit);

        checkTranslationUnitErrorCode(errorCode);

        updateIncludeFilePaths();

        updateLastProjectPartChangeTimePoint();
    }
}
Exemplo n.º 2
0
void TranslationUnit::reparseTranslationUnit() const
{
    clang_reparseTranslationUnit(d->translationUnit,
                                 unsavedFiles().count(),
                                 unsavedFiles().cxUnsavedFiles(),
                                 clang_defaultReparseOptions(d->translationUnit));

    d->needsToBeReparsed = false;
}
Exemplo n.º 3
0
void TranslationUnit::createTranslationUnitIfNeeded() const
{
    if (!d->translationUnit) {
        d->translationUnit = CXTranslationUnit();
        CXErrorCode errorCode = clang_parseTranslationUnit2(index(),
                                                            d->filePath.constData(),
                                                            d->projectPart.cxArguments(),
                                                            d->projectPart.argumentCount(),
                                                            unsavedFiles().cxUnsavedFiles(),
                                                            unsavedFiles().count(),
                                                            defaultOptions(),
                                                            &d->translationUnit);

        checkTranslationUnitErrorCode(errorCode);

        updateIncludeFilePaths();


        updateLastProjectPartChangeTimePoint();
    }
}
Exemplo n.º 4
0
bool ClangIndexer::parse()
{
    StopWatch sw;
    assert(!mClangUnit);
    assert(!mIndex);
    mIndex = clang_createIndex(0, 1);
    assert(mIndex);
    const unsigned int commandLineFlags = Source::FilterBlacklist|Source::IncludeDefines|Source::IncludeIncludepaths;
    const unsigned int flags = CXTranslationUnit_DetailedPreprocessingRecord;
    List<CXUnsavedFile> unsavedFiles(mUnsavedFiles.size() + 1);
    int unsavedIndex = 0;
    for (const auto &it : mUnsavedFiles) {
        unsavedFiles[unsavedIndex++] = {
            it.first.constData(),
            it.second.constData(),
            static_cast<unsigned long>(it.second.size())
        };
    }

    debug() << "CI::parse: " << mSource.toCommandLine(commandLineFlags) << "\n";

    // for (const auto it : mSource.toCommandLine(commandLineFlags)) {
    //     error("[%s]", it.constData());
    // }
    RTags::parseTranslationUnit(mSourceFile, mSource.toCommandLine(commandLineFlags), mClangUnit,
                                mIndex, &unsavedFiles[0], unsavedIndex, flags, &mClangLine);

    warning() << "CI::parse loading unit " << mClangLine << " " << (mClangUnit != 0);
    if (mClangUnit) {
        clang_getInclusions(mClangUnit, ClangIndexer::inclusionVisitor, this);
        mParseDuration = sw.elapsed();
        return true;
    }
    error() << "got failure" << mClangLine;
    for (Hash<uint32_t, bool>::const_iterator it = mData->visited.begin(); it != mData->visited.end(); ++it) {
        mData->dependencies[it->first].insert(mSource.fileId);
        addFileSymbol(it->first);
    }

    return false;
}
Exemplo n.º 5
0
CXUnsavedFile *TranslationUnit::cxUnsavedFiles() const
{
    return unsavedFiles().cxUnsavedFiles();
}
Exemplo n.º 6
0
uint TranslationUnit::unsavedFilesCount() const
{
    return unsavedFiles().count();
}
Exemplo n.º 7
0
UnsavedFile &TranslationUnit::unsavedFile() const
{
    return unsavedFiles().unsavedFile(filePath());
}