void CppIncludeHierarchyModel::buildHierarchyIncludes_helper(const QString &filePath,
                                                             CppIncludeHierarchyItem *parent,
                                                             QSet<QString> *cyclic, bool recursive)
{
    if (!m_editor)
        return;

    CppModelManagerInterface *cppMM = CppModelManagerInterface::instance();
    const Snapshot &snapshot = cppMM->cppEditorSupport(m_editor)->snapshotUpdater()->snapshot();
    Document::Ptr doc = snapshot.document(filePath);
    if (!doc)
        return;

    parent->setHasChildren(doc->resolvedIncludes().size() > 0);
    if (!recursive)
        return;

    cyclic->insert(filePath);

    foreach (const Document::Include &includeFile, doc->resolvedIncludes()) {
        const QString includedFilePath = includeFile.resolvedFileName();
        CppIncludeHierarchyItem *item = 0;

        if (cyclic->contains(includedFilePath)) {
            item = new CppIncludeHierarchyItem(includedFilePath, parent, true);
            parent->appendChild(item);
            continue;
        }
        item = new CppIncludeHierarchyItem(includedFilePath, parent);
        parent->appendChild(item);
        buildHierarchyIncludes_helper(includedFilePath, item, cyclic, false);

    }
    cyclic->remove(filePath);
}
bool CppElementEvaluator::matchIncludeFile(const Document::Ptr &document, unsigned line)
{
    foreach (const Document::Include &includeFile, document->resolvedIncludes()) {
        if (includeFile.line() == line) {
            m_element = QSharedPointer<CppElement>(new CppInclude(includeFile));
            return true;
        }
    }
    return false;
}
Exemplo n.º 3
0
void TypeOfExpression::processEnvironment(Document::Ptr doc, Environment *env,
                                          QSet<QString> *processed) const
{
    if (doc && ! processed->contains(doc->fileName())) {
        processed->insert(doc->fileName());

        foreach (const Document::Include &incl, doc->resolvedIncludes())
            processEnvironment(m_snapshot.document(incl.resolvedFileName()), env, processed);

        foreach (const Macro &macro, doc->definedMacros())
            env->bind(macro);
    }
Exemplo n.º 4
0
QList<Snapshot::IncludeLocation> Snapshot::includeLocationsOfDocument(const QString &fileName) const
{
    QList<IncludeLocation> result;
    for (const_iterator cit = begin(), citEnd = end(); cit != citEnd; ++cit) {
        const Document::Ptr doc = cit.value();
        foreach (const Document::Include &includeFile, doc->resolvedIncludes()) {
            if (includeFile.resolvedFileName() == fileName)
                result.append(qMakePair(doc, includeFile.line()));
        }
    }
    return result;
}
Exemplo n.º 5
0
    void process(Document::Ptr doc, QSet<Namespace *> *processed)
    {
        if (!doc)
            return;
        if (!processed->contains(doc->globalNamespace())) {
            processed->insert(doc->globalNamespace());

            foreach (const Document::Include &i, doc->resolvedIncludes())
                process(_snapshot.document(i.resolvedFileName()), processed);

            _mainDocument = (doc == _doc); // ### improve
            accept(doc->globalNamespace());
        }
Exemplo n.º 6
0
void SnapshotSymbolVisitor::accept(Document::Ptr doc, QSet<QString> *processed)
{
    if (doc && doc->globalNamespace() && ! processed->contains(doc->fileName())) {
        processed->insert(doc->fileName());

        foreach (const Document::Include &i, doc->resolvedIncludes()) {
            if (Document::Ptr incl = _snapshot.document(i.resolvedFileName()))
                accept(incl, processed);
        }

        std::swap(_document, doc);
        accept(_document->globalNamespace());
        std::swap(_document, doc);
    }
Exemplo n.º 7
0
LineForNewIncludeDirective::LineForNewIncludeDirective(const QTextDocument *textDocument,
                                                       const Document::Ptr cppDocument,
                                                       MocIncludeMode mocIncludeMode,
                                                       IncludeStyle includeStyle)
    : m_textDocument(textDocument)
    , m_cppDocument(cppDocument)
    , m_includeStyle(includeStyle)
{
    QList<Document::Include> includes
        = cppDocument->resolvedIncludes() + cppDocument->unresolvedIncludes();
    Utils::sort(includes, &Include::line);

    // Ignore *.moc includes if requested
    if (mocIncludeMode == IgnoreMocIncludes) {
        foreach (const Document::Include &include, includes) {
            if (!include.unresolvedFileName().endsWith(QLatin1String(".moc")))
                m_includes << include;
        }
    } else {
Exemplo n.º 8
0
void CppPreprocessor::mergeEnvironment(Document::Ptr doc)
{
    if (!doc)
        return;

    const QString fn = doc->fileName();

    if (m_processed.contains(fn))
        return;

    m_processed.insert(fn);

    foreach (const Document::Include &incl, doc->resolvedIncludes()) {
        const QString includedFile = incl.resolvedFileName();

        if (Document::Ptr includedDoc = m_snapshot.document(includedFile))
            mergeEnvironment(includedDoc);
        else if (!m_included.contains(includedFile))
            run(includedFile);
    }

    m_env.addMacros(doc->definedMacros());
}
void CppIncludeHierarchyModel::buildHierarchyIncludedBy_helper(const QString &filePath,
                                                               CppIncludeHierarchyItem *parent,
                                                               QSet<QString> *cyclic,
                                                               bool recursive)
{
    cyclic->insert(filePath);
    const Snapshot &snapshot = CppTools::CppModelManagerInterface::instance()->snapshot();
    Snapshot::const_iterator citEnd = snapshot.end();
    for (Snapshot::const_iterator cit = snapshot.begin(); cit != citEnd; ++cit) {
        const QString filePathFromSnapshot = cit.key();
        Document::Ptr doc = cit.value();
        foreach (const Document::Include &includeFile, doc->resolvedIncludes()) {
            const QString includedFilePath = includeFile.resolvedFileName();

            if (includedFilePath == filePath) {
                parent->setHasChildren(true);
                if (!recursive) {
                    cyclic->remove(filePath);
                    return;
                }

                const bool isCyclic = cyclic->contains(filePathFromSnapshot);
                CppIncludeHierarchyItem *item = new CppIncludeHierarchyItem(filePathFromSnapshot,
                                                                            parent,
                                                                            isCyclic);
                item->setLine(includeFile.line());
                parent->appendChild(item);

                if (isCyclic)
                    continue;
                else
                    buildHierarchyIncludedBy_helper(filePathFromSnapshot, item, cyclic, false);
            }
        }
    }
    cyclic->remove(filePath);
}