Exemplo n.º 1
0
bool LoadTokenIdxSetFromFile(std::istream& f,TokenIdxSet* data)
{
    if(!data)
        return false;
    bool result = true;
    data->clear();
    int size = 0;
    do
    {
        if (!LoadIntFromFile(f, &size))
        {
            result = false;
            break;
        }
        int i,num = 0;
        for (i = 0; i < size; i++)
        {
            if(!LoadIntFromFile(f,&num))
            {
                result = false;
                break;
            }
            data->insert(num);
        }
    }while(false);
    return result;
}
Exemplo n.º 2
0
bool Parser::ReadFromCache(wxInputStream* f)
{
    bool result = false;

    TRACK_THREAD_LOCKER(s_TokensTreeCritical);
    wxCriticalSectionLocker locker(s_TokensTreeCritical);
    THREAD_LOCKER_SUCCESS(s_TokensTreeCritical);

    char CACHE_MAGIC_READ[] = "           ";
    m_TokensTree->clear(); // Clear data

    // File format is like this:
    //
    // CACHE_MAGIC
    // Number of parsed files
    // Number of tokens
    // Parsed files
    // Tokens
    // EOF

//  Begin loading process
    do
    {

        // keep a backup of include dirs
        if (f->Read(CACHE_MAGIC_READ, sizeof(CACHE_MAGIC_READ)).LastRead() != sizeof(CACHE_MAGIC_READ) ||
            strncmp(CACHE_MAGIC, CACHE_MAGIC_READ, sizeof(CACHE_MAGIC_READ) != 0))
            break;
        int fcount = 0, actual_fcount = 0;
        int tcount = 0, actual_tcount = 0;
        int idx;
        if (!LoadIntFromFile(f, &fcount))
            break;
        if (!LoadIntFromFile(f, &tcount))
            break;
        if (fcount < 0)
            break;
        if (tcount < 0)
            break;

        wxString file;
        int nonempty_token = 0;
        Token* token = 0;
        do // do while-false block
        {
            // Filenames
            int i;
            for (i = 0; i < fcount && !f->Eof(); ++i)
            {
                if (!LoadIntFromFile(f,&idx)) // Filename index
                    break;
                if (idx != i)
                    break;
                if (!LoadStringFromFile(f,file)) // Filename data
                    break;
                if (!idx)
                    file.Clear();
                if (file.IsEmpty())
                    idx = 0;
                m_TokensTree->m_FilenamesMap.insert(file);
                actual_fcount++;
            }
            result = (actual_fcount == fcount);
            if (!result)
                break;
            if (tcount)
                m_TokensTree->m_Tokens.resize(tcount,0);
            // Tokens
            for (i = 0; i < tcount && !f->Eof(); ++i)
            {
                token = 0;
                if (!LoadIntFromFile(f, &nonempty_token))
                break;
                if (nonempty_token != 0)
                {
                    token = new Token(wxEmptyString, 0, 0, ++m_TokensTree->m_TokenTicketCount);
                    if (!token->SerializeIn(f))
                    {
                        delete token;
                        --m_TokensTree->m_TokenTicketCount;
                        token = 0;
                        break;
                    }
                    m_TokensTree->insert(i,token);
                }
                ++actual_tcount;
            }
            if (actual_tcount != tcount)
                break;
            m_TokensTree->RecalcFreeList();
            result = true;
        } while(false);

    } while(false);

//  End loading process

    if (result)
        m_UsingCache = true;
    else
        m_TokensTree->clear();

    m_TokensTree->m_Modified = false;

    return result;
}
Exemplo n.º 3
0
bool Token::SerializeIn(std::istream& f)
{
    bool result = true;
    do
    {
        if (!LoadIntFromFile(f, (int*)&m_Self))
        {
            result = false;
            break;
        }
        if (!LoadIntFromFile(f, (int*)&m_ParentIndex))
        {
            result = false;
            break;
        }
        if(m_ParentIndex < 0)
            m_ParentIndex = -1;

        if (!LoadStringFromFile(f, m_Type))
        {
            result = false;
            break;
        }
        if (!LoadStringFromFile(f, m_ActualType))
        {
            result = false;
            break;
        }
        if (!LoadStringFromFile(f, m_Name))
        {
            result = false;
            break;
        }
        if (!LoadStringFromFile(f, m_Args))
        {
            result = false;
            break;
        }
        if (!LoadStringFromFile(f, m_AncestorsString))
        {
            result = false;
            break;
        }
        if (!LoadIntFromFile(f, (int*)&m_FileIdx))
        {
            result = false;
            break;
        }
        if (!LoadIntFromFile(f, (int*)&m_Line))
        {
            result = false;
            break;
        }
        if (!LoadIntFromFile(f, (int*)&m_ImplFile))
        {
            result = false;
            break;
        }
        if (!LoadIntFromFile(f, (int*)&m_ImplLine))
        {
            result = false;
            break;
        }
        if (!LoadIntFromFile(f, (int*)&m_Scope))
        {
            result = false;
            break;
        }
        if (!LoadIntFromFile(f, (int*)&m_TokenKind))
        {
            result = false;
            break;
        }
        if (!LoadIntFromFile(f, (int*)&m_IsOperator))
        {
            result = false;
            break;
        }
        if (!LoadIntFromFile(f, (int*)&m_IsLocal))
        {
            result = false;
            break;
        }
        if(!LoadTokenIdxSetFromFile(f, &m_Ancestors))
        {
            result = false;
            break;
        }
        if(!LoadTokenIdxSetFromFile(f, &m_Children))
        {
            result = false;
            break;
        }
        if(!LoadTokenIdxSetFromFile(f, &m_Descendants))
        {
            result = false;
            break;
        }
    } while(false);
    return result;
}
Exemplo n.º 4
0
bool Token::SerializeIn(wxFile* f)
{
    if (!LoadIntFromFile(f, (int*)&m_ParentIndex)) return false;
    if (!LoadStringFromFile(f, m_Type)) return false;
    if (!LoadStringFromFile(f, m_ActualType)) return false;
    if (!LoadStringFromFile(f, m_Name)) return false;
    if (!LoadStringFromFile(f, m_DisplayName)) return false;
    if (!LoadStringFromFile(f, m_Args)) return false;
    if (!LoadStringFromFile(f, m_AncestorsString)) return false;
    if (!LoadStringFromFile(f, m_Filename)) return false;
    if (!LoadIntFromFile(f, (int*)&m_Line)) return false;
    if (!LoadStringFromFile(f, m_ImplFilename)) return false;
    if (!LoadIntFromFile(f, (int*)&m_ImplLine)) return false;
    if (!LoadIntFromFile(f, (int*)&m_Scope)) return false;
    if (!LoadIntFromFile(f, (int*)&m_TokenKind)) return false;
    if (!LoadIntFromFile(f, (int*)&m_IsOperator)) return false;
    if (!LoadIntFromFile(f, (int*)&m_IsLocal)) return false;

    m_AncestorsIndices.Clear();
    int count = 0;
    LoadIntFromFile(f, &count);
    for (int i = 0; i < count; ++i)
    {
        int idx = 0;
        LoadIntFromFile(f, &idx);
        m_AncestorsIndices.Add(idx);
    }

    m_ChildrenIndices.Clear();
    count = 0;
    LoadIntFromFile(f, &count);
    for (int i = 0; i < count; ++i)
    {
        int idx = 0;
        LoadIntFromFile(f, &idx);
        m_ChildrenIndices.Add(idx);
    }
    // parent-child relationship is set in a post-processing step
    return true;
}