Exemplo n.º 1
0
bool ParserBase::Reparse(const wxString& file, cb_unused bool isLocal)
{
    FileLoader* loader = new FileLoader(file);
    (*loader)();

    ParserThreadOptions opts;

    opts.useBuffer             = false; // default
    opts.parentIdxOfBuffer     = -1;    // default
    opts.initLineOfBuffer      = -1;    // default
    opts.bufferSkipBlocks      = false; // default
    opts.bufferSkipOuterBlocks = false; // default
    opts.isTemp                = false; // default

    opts.followLocalIncludes   = true;  // default
    opts.followGlobalIncludes  = true;  // default
    opts.wantPreprocessor      = true;  // default
    opts.parseComplexMacros    = true;  // default

    opts.handleFunctions       = true;  // default
    opts.handleVars            = true;  // default
    opts.handleClasses         = true;  // default
    opts.handleEnums           = true;  // default
    opts.handleTypedefs        = true;  // default

    opts.loader                = loader;

    ParserThread* pt = new ParserThread(this, file, true, opts, m_TokenTree);
    bool success = pt->Parse();
    delete pt;

    return success;
}
Exemplo n.º 2
0
bool ParserTest::Start(const wxString& file)
{
    ParserBase client;
    FileLoader* loader = new FileLoader(file);
    (*loader)();

    ParserThreadOptions opts;
    opts.wantPreprocessor      = true;
    opts.useBuffer             = false;
    opts.bufferSkipBlocks      = false;
    opts.bufferSkipOuterBlocks = false;
    opts.followLocalIncludes   = true;
    opts.followGlobalIncludes  = true;
    opts.loader                = loader;

    ParserThread* ph = new ParserThread(&client, file, true, opts, m_tokensTree);
    bool b = ph->Parse();
    delete ph;

    return b;
}
Exemplo n.º 3
0
bool Parser::Parse(const wxString& filename, bool isLocal, bool locked, LoaderBase* loader)
{
    ParserThreadOptions opts;
    opts.wantPreprocessor      = m_Options.wantPreprocessor;
    opts.useBuffer             = false;
    opts.bufferSkipBlocks      = false;
    opts.bufferSkipOuterBlocks = false;
    opts.followLocalIncludes   = m_Options.followLocalIncludes;
    opts.followGlobalIncludes  = m_Options.followGlobalIncludes;
    opts.parseComplexMacros    = m_Options.parseComplexMacros;
    opts.loader                = loader; // maybe 0 at this point

    const wxString unixFilename = UnixFilename(filename);
    bool result = false;
    do
    {
        bool canparse = false;
        {
            if (!locked)
            {
                TRACK_THREAD_LOCKER(s_TokensTreeCritical);
                s_TokensTreeCritical.Enter();
                THREAD_LOCKER_SUCCESS(s_TokensTreeCritical);
            }

            canparse = !m_TokensTree->IsFileParsed(unixFilename);
            if (canparse)
                canparse = m_TokensTree->ReserveFileForParsing(unixFilename, true) != 0;

            if (!locked)
                s_TokensTreeCritical.Leave();
        }

        if (!canparse)
        {
           if (opts.loader) // if a loader is already open at this point, the caller must clean it up
               CCLogger::Get()->DebugLog(_T("Parse() : CodeCompletion Plugin: FileLoader memory leak ")
                                         _T("likely while loading file ") + unixFilename);
           break;
        }

        // this should always be true
        // memory will leak if a loader has already been initialized before this point
        if (!opts.loader)
            opts.loader = Manager::Get()->GetFileManager()->Load(unixFilename, m_NeedsReparse);

        ParserThread* thread = new ParserThread(this, unixFilename, isLocal, opts, m_TokensTree);
        TRACE(_T("Parse() : Parsing %s"), unixFilename.wx_str());

        if (m_IsPriority)
        {
            if (isLocal) // Parsing priority files
            {
                TRACE(_T("Parse() : Parsing priority header, %s"), unixFilename.wx_str());

                if (!locked)
                {
                    TRACK_THREAD_LOCKER(s_TokensTreeCritical);
                    s_TokensTreeCritical.Enter();
                    THREAD_LOCKER_SUCCESS(s_TokensTreeCritical);
                }

                result = thread->Parse();
                delete thread;

                if (!locked)
                    s_TokensTreeCritical.Leave();
                return true;
            }
            else // Add task when parsing priority files
            {
                TRACK_THREAD_LOCKER(s_ParserCritical);
                wxCriticalSectionLocker locker(s_ParserCritical);
                THREAD_LOCKER_SUCCESS(s_ParserCritical);

                TRACE(_T("Parse() : Add task for priority header, %s"), unixFilename.wx_str());
                m_PoolTask.push(PTVector());
                m_PoolTask.back().push_back(thread);
            }
        }
        else
        {
            TRACK_THREAD_LOCKER(s_ParserCritical);
            wxCriticalSectionLocker locker(s_ParserCritical);
            THREAD_LOCKER_SUCCESS(s_ParserCritical);

            TRACE(_T("Parse() : Parallel Parsing %s"), unixFilename.wx_str());

            // Add a task for all project files
            if (m_IsFirstBatch)
            {
                m_IsFirstBatch = false;
                m_PoolTask.push(PTVector());
            }

            if (m_IsParsing)
                m_Pool.AddTask(thread, true);
            else
            {
                if (!m_PoolTask.empty())
                    m_PoolTask.back().push_back(thread);
                else
                {
                    Manager::Get()->GetLogManager()->DebugLog(_T("Why m_PoolTask is empty?"));
                    return false;
                }
            }
        }

        result = true;
    }
    while (false);

    return result;
}