⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 symbol.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 2 页
字号:
                    return nssym1;
                }
            }
            else
                nssym1 = temp;
        }
        list = list->link;
        if (!list)
        {
            list = list2;
            list2 = 0;
        }
    }
    return 0;
}

//-------------------------------------------------------------------------

int isaccessible(SYM *sp)
{
        //   if (!currentfunc)
        //      return TRUE ;
        //   if (!isstructured(sp->tp))
        //      return TRUE ;
        if (declclass && sp->mainsym == declclass->mainsym)
            return TRUE;
        if ((sp->value.classdata.cppflags &PF_MEMBER) && sp->parentclass)
        {
            if (sp->value.classdata.cppflags &PF_UNREACHABLE)
                return FALSE;
            if (sp->parentclass != declclass)
            {
                if (sp->parentclass && declclass && sp->parentclass->mainsym ==
                    declclass->mainsym)
                    return TRUE;
                if (declclass)
                {
                    if (!(sp->value.classdata.cppflags &(PF_PUBLIC |
                        PF_PROTECTED)))
                        return FALSE;
                }
                else if (!(sp->value.classdata.cppflags &PF_PUBLIC))
                    return FALSE;
            }
        }
    return TRUE;
}

/*
 * Some tables use hash tables and some use linked lists
 * This is the global symbol search routine
 */
SYM *basesearch(char *na, TABLE *table, int checkaccess)
{
    SYM *thead = table->head;
    SYM **p,  *sp;
    if (table == gsyms)
    {
        p = ((SYM **)LookupHash(na, table, HASHTABLESIZE));
        if (p)
        {
            p =  *p;
            //         if (checkaccess)
            //            if (!isaccessible(p) && !isfriend(p,table)) 
            //               genclasserror(ERR_NOTACCESSIBLE,sp->name);
        }
        return (SYM*)p;
    }
    else if (table == tagtable)
    {
        if (funcnesting)
        {
            SYM *rv = basesearch(na, &ltags, checkaccess);
            if (rv)
                return rv;
        }
        p = ((SYM **)LookupHash(na, table, HASHTABLESIZE));
        if (p)
        {
            p =  *p;
            //         if (checkaccess)
            //            if (!isaccessible(p) && !isfriend(p,table)) 
            //               genclasserror(ERR_NOTACCESSIBLE,sp->name);
        }
        return (SYM*)p;
    }
    else if (table ==  &defsyms)
    {
        p = ((SYM **)LookupHash(na, defhash, HASHTABLESIZE));
        if (p)
        {
            p =  *p;
            //         if (checkaccess)
            //            if (!isaccessible(p) && !isfriend(p,table)) 
            //               genclasserror(ERR_NOTACCESSIBLE,sp->name);
        }
        return (SYM*)p;
    }
    else if (table == templateFuncs)
    {
        p = ((SYM **)LookupHash(na, templateFuncs, HASHTABLESIZE));
        if (p)
            p =  *p;
        return (SYM*)p;
    }
    else
    {
        finish: 
        while (thead != 0)
        {
            if (strcmp(thead->name, na) == 0)
            {
                if (checkaccess)
                    if (!isaccessible(thead) && (!declclass || !isfriend(thead,
                        &declclass->tp->lst.head)) && !isfriend(thead, table))
                        genclasserror(ERR_NOTACCESSIBLE, fullcppmangle(thead
                            ->tp->sp->parentclass, thead->name, 0));
                return thead;
            }
            thead = thead->next;
        }
    }
    return 0;
}

//-------------------------------------------------------------------------

SYM *search2(char *na, TABLE *table, int checkaccess, int definition)
{

    SYM *sp1 = 0,  *sp2 = 0,  *sp3 = 0;
    nssym1 = nssym2 = 0;
    if (typequal)
        return tcsearch(na, checkaccess);
    if (!definition || !openns_list || table != gsyms && table != tagtable)
        sp1 = basesearch(na, table, checkaccess);
    if (sp1)
        nssym1 = sp1;
    if (!sp1 && openns_list && (table == gsyms || table == tagtable))
    {
        sp1 = openns_list->data;
        sp1 = namespace_search(na, sp1->value.classdata.parentns, table ==
            tagtable);
        if (sp1)
            return sp1;
        if (definition)
            return 0;
    }
    if (!nonslookup)
    if (table == gsyms || table == tagtable)
    {
        if (table == tagtable && (funcnesting || structlevel))
            namespace_search_full(na, &local_tag_using_list, table);
        namespace_search_full(na, table == tagtable ? global_tag_using_list :
            global_using_list, table);
        if (openns_list && openns_list->link) {
            SYM *sp = openns_list->link->data;
            namespace_search_full(na, table == tagtable ? sp
                    ->value.classdata.parentns->tag_using_list: sp
                    ->value.classdata.parentns->using_list,table);
        }
    }
    else if (table ==  &lsyms)
        namespace_search_full(na, &local_using_list, table);
    nonslookup = FALSE;
    if (nssym1 && nssym2)
        genfunc2error(ERR_AMBIGFUNC, fullcppmangle(nssym1, nssym1->name, nssym1
            ->tp), fullcppmangle(nssym2, nssym2->name, nssym2->tp));
    if (nssym1)
        return nssym1;
    else
        return nssym2;
}

//-------------------------------------------------------------------------

SYM *search(char *na, TABLE *table)
{
    SYM *sp;
    int lastl;
    if (table == lastsearchtable && lastsearchsym)
    {
        if (!strcmp(na, lastsearchname))
            return lastsearchsym;
    }
    searchname[0] = 0;
    sp = search2(na, table, TRUE, FALSE);
    if (table == gsyms || table == tagtable)
    {
        lastsearchtable = table;
        strcpy(lastsearchname, na);
        lastsearchsym = sp;
    }
    return sp;
}

//-------------------------------------------------------------------------

SYM *losearch(char *na)
{
    SYM *sp = 0;
    if (templateLookup)
        sp = search(na, &currentTemplate->classes);
    if (!sp && baseasnsymtbl)
        sp = search(na, baseasnsymtbl);
    if (!sp && inarrayindexparsing && funcparmtable)
        sp = search(na, funcparmtable);
    if (!sp)
        sp = search(na, &lsyms);
    if (!sp && declclass)
        sp = search(na, &declclass->tp->lst);
    return sp;
}

//-------------------------------------------------------------------------

SYM *tcsearch(char *na, int checkaccess)
{
    SYM *rv;
    if (!typequal)
        return 0;
    if (typequal->storage_class == sc_type)
        return basesearch(na, &typequal->tp->lst, checkaccess);
    else if (typequal->storage_class == sc_namespace)
    {
        if (parsing_params)
        {
            parm_namespaces[parm_ns_level][parm_ns_counts[parm_ns_level]++] =
                typequal;
        }
        if (rv = namespace_search(na, typequal->value.classdata.parentns, 0))
            return rv;
        else
            return namespace_search(na, typequal->value.classdata.parentns, 1);
    }
    return 0;
}

//-------------------------------------------------------------------------

SYM *gsearch(char *na)
{
    SYM *sp;
    if ((sp = losearch(na)) == 0)
        sp = search(na, gsyms);
    return sp;
}

//-------------------------------------------------------------------------

SYM *typesearch(char *na)
{
    SYM *sp;
    sp = gsearch(na);
    if (sp || !prm_cplusplus)
    {
        return sp;
    }
    return search(na, tagtable);
}

/* The global symbol insert routine */
void insert(SYM *sp, TABLE *table)

{
    SYM *sp1;
    lastsearchname[0] = 0;
    lastsearchtable = 0;
    lastsearchsym = 0;
    if (table == NULL)
        return ;
    // Assume some error led to this
    if (table == gsyms || table == tagtable)
    {
        if (table == tagtable && !global_flag)
        {
            SYM *thead = ltags.head,  *qhead = 0,  **oldhead = &ltags.head;
            table = &ltags;
            /* Only check the current local block... */
            while (thead != oldltag.head)
            {
                if (strcmp(thead->name, sp->name) == 0)
                {
                    qhead = thead;
                    break;
                }
                oldhead = &thead->next;
                thead = thead->next;
            }
            if (qhead && !(qhead->value.classdata.cppflags &PF_INHERITED))
                gensymerror(ERR_DUPSYM, sp->name);
            else
            {
                if (qhead)
                    *oldhead = qhead->next;
                /* Putting local symbols in backwards */
                if (table->head == 0)
                {
                    table->head = table->tail = sp;
                    sp->next = 0;
                }
                else
                {
                    sp->next = table->head;
                    table->head = sp;
                }
            }
        }
        else if (openns_list)
        {
            NAMESPACE *s = ((SYM*)openns_list->data)->value.classdata.parentns;
            if (AddHash(sp, table == gsyms ? s->table: s->tagtable,
                HASHTABLESIZE))
                gensymerror(ERR_DUPSYM, fullcppmangle(sp, sp->name, sp->tp));
        }
        else if (AddHash(sp, table, HASHTABLESIZE))
            gensymerror(ERR_DUPSYM, sp->name);
    }
    else if (table ==  &defsyms)
    {
        AddHash(sp, defhash, HASHTABLESIZE);
    }
    else
    {
        if (table ==  &lsyms)
        {
            SYM *thead = table->head,  *qhead = 0,  **oldhead = &table->head;
            /* Only check the current local block... */
            while (thead != oldlsym.head)
            {
                if (strcmp(thead->name, sp->name) == 0)
                {
                    qhead = thead;
                    break;
                }
                oldhead = &thead->next;
                thead = thead->next;
            }
            if (qhead && !(qhead->value.classdata.cppflags &PF_INHERITED))
                gensymerror(ERR_DUPSYM, sp->name);
            else
            {
                if (qhead)
                    *oldhead = qhead->next;
                /* Putting local symbols in backwards */
                if (table->head == 0)
                {
                    table->head = table->tail = sp;
                    sp->next = 0;
                }
                else
                {
                    sp->next = table->head;
                    table->head = sp;
                }
            }
        }
        else if (table == templateFuncs)
        {
            if (AddHash(sp, templateFuncs, HASHTABLESIZE))
                gensymerror(ERR_DUPSYM, sp->name);
        }
        else if ((sp1 = search2(sp->name, table, FALSE, FALSE)) == 0 || (sp1
            ->value.classdata.cppflags &PF_INHERITED))
        {
            if (table->head == 0)
                table->head = table->tail = sp;
            else
            {
                table->tail->next = sp;
                table->tail = sp;
            }
            sp->next = 0;
            if (sp1)
            {
                SYM *sp2 = table->head,  **spo = &table->head;
                while (sp2)
                {
                    if (sp2 == sp1)
                    {
                        *spo = sp2->next;
                        break;
                    }
                    spo = &sp2->next;
                    sp2 = sp2->next;
                }
            }
        }
        else
            gensymerror(ERR_DUPSYM, sp->name);
    }
}

//-------------------------------------------------------------------------

int unlinkTag(SYM *sp)

{
    int rv = FALSE;
    LIST **ul = 0;
    SYM *sp1;
    if (!global_flag)
    {
        SYM *thead = ltags.head,  *qhead = 0,  **oldhead = &ltags.head;
        /* Only check the current local block... */
        while (thead != oldltag.head)
        {
            if (strcmp(thead->name, sp->name) == 0)
            {
                qhead = thead;
                break;
            }
            oldhead = &thead->next;
            thead = thead->next;
        }
        if (qhead)
        {
            *oldhead = qhead->next;
            rv = TRUE;
        }
        else
        {
            ul = &local_using_list;
        }
    }
    else if (openns_list)
    {
        NAMESPACE *s = ((SYM*)openns_list->data)->value.classdata.parentns;
        SYM **p = LookupHash(sp->name, s->tagtable, HASHTABLESIZE);
        if (p)
        {
            *p = (*p)->next;
            rv = TRUE;
        }
        else
        {
            ul = &s->tag_using_list;
        }
    }
    else
    {
        SYM **p = LookupHash(sp->name, tagtable, HASHTABLESIZE);
        if (p)
        {
            *p = (*p)->next;
            rv = TRUE;
        }
        else
        {
            ul = &global_tag_using_list;
        }
    }
    if (!rv && ul)
    {
        if (ul !=  &local_tag_using_list)
            ul = LookupHash(sp->name,  *ul, HASHTABLESIZE);
        if (ul)
        {
            while (*ul)
            {
                if (((SYM*)(*ul)->data)->mainsym == sp->mainsym)
                {
                    *ul = (*ul)->link;
                    rv = TRUE;
                    break;
                }
                ul = &(*ul)->link;
            }
        }
    }
    return rv;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -