[BACK]Return to pvar.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / parse

Annotation of OpenXM_contrib2/asir2000/parse/pvar.c, Revision 1.10

1.2       noro        1: /*
                      2:  * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
                      3:  * All rights reserved.
                      4:  *
                      5:  * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
                      6:  * non-exclusive and royalty-free license to use, copy, modify and
                      7:  * redistribute, solely for non-commercial and non-profit purposes, the
                      8:  * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
                      9:  * conditions of this Agreement. For the avoidance of doubt, you acquire
                     10:  * only a limited right to use the SOFTWARE hereunder, and FLL or any
                     11:  * third party developer retains all rights, including but not limited to
                     12:  * copyrights, in and to the SOFTWARE.
                     13:  *
                     14:  * (1) FLL does not grant you a license in any way for commercial
                     15:  * purposes. You may use the SOFTWARE only for non-commercial and
                     16:  * non-profit purposes only, such as academic, research and internal
                     17:  * business use.
                     18:  * (2) The SOFTWARE is protected by the Copyright Law of Japan and
                     19:  * international copyright treaties. If you make copies of the SOFTWARE,
                     20:  * with or without modification, as permitted hereunder, you shall affix
                     21:  * to all such copies of the SOFTWARE the above copyright notice.
                     22:  * (3) An explicit reference to this SOFTWARE and its copyright owner
                     23:  * shall be made on your publication or presentation in any form of the
                     24:  * results obtained by use of the SOFTWARE.
                     25:  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.3       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2       noro       27:  * for such modification or the source code of the modified part of the
                     28:  * SOFTWARE.
                     29:  *
                     30:  * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
                     31:  * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
                     32:  * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
                     33:  * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
                     34:  * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
                     35:  * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
                     36:  * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
                     37:  * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
                     38:  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
                     39:  * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
                     40:  * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
                     41:  * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
                     42:  * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
                     43:  * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
                     44:  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
                     45:  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
                     46:  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
                     47:  *
1.10    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/pvar.c,v 1.9 2003/05/14 09:18:38 noro Exp $
1.2       noro       49: */
1.1       noro       50: #include "ca.h"
                     51: #include "parse.h"
                     52:
                     53: NODE PVSS;
1.10    ! noro       54: extern char *CUR_FUNC;
1.1       noro       55:
1.10    ! noro       56: void mkpvs(char *fname)
1.6       noro       57: {
1.1       noro       58:        VS pvs;
                     59:
                     60:        pvs = (VS)MALLOC(sizeof(struct oVS));
                     61:        pvs->va = (struct oPV *)MALLOC(DEFSIZE*sizeof(struct oPV));
                     62:        pvs->n = 0;
                     63:        pvs->asize=DEFSIZE;
                     64:        CPVS = pvs;
1.10    ! noro       65:
        !            66:        /* XXX */
        !            67:        CUR_FUNC = fname;
1.1       noro       68: }
                     69:
1.6       noro       70: void pushpvs(FUNC f)
1.1       noro       71: {
                     72:        VS pvs;
                     73:        NODE node;
                     74:        int level;
                     75:        extern int evalstatline;
                     76:
                     77:        pvs = f->f.usrf->pvs;
                     78:        if ( PVSS ) {
                     79:                ((VS)BDY(PVSS))->at = evalstatline;
                     80:                level = ((VS)BDY(PVSS))->level+1;
                     81:        } else
                     82:                level = 1;
                     83:        MKNODE(node,pvs,PVSS);
                     84:        PVSS = node;
                     85:        CPVS = (VS)MALLOC(sizeof(struct oVS)); BDY(PVSS) = (pointer)CPVS;
                     86:        CPVS->usrf = f;
                     87:        CPVS->n = CPVS->asize = pvs->n;
                     88:        CPVS->level = level;
                     89:        if ( CPVS->n ) {
                     90:                CPVS->va = (struct oPV *)MALLOC(CPVS->n*sizeof(struct oPV));
                     91:                bcopy((char *)pvs->va,(char *)CPVS->va,(int)(pvs->n*sizeof(struct oPV)));
                     92:        }
                     93:        if ( nextbp )
                     94:                nextbplevel++;
                     95: }
                     96:
                     97: void poppvs() {
                     98:        PVSS = NEXT(PVSS);
                     99:        if ( PVSS )
                    100:                CPVS = (VS)BDY(PVSS);
                    101:        else
                    102:                CPVS = GPVS;
                    103:        if ( nextbp )
                    104:                nextbplevel--;
                    105: }
                    106:
1.7       noro      107: int gdef,mgdef;
1.1       noro      108:
1.7       noro      109: #define IS_LOCAL 0
                    110: #define IS_GLOBAL 1
                    111: #define IS_MGLOBAL 2
                    112:
1.10    ! noro      113:
1.7       noro      114: unsigned int makepvar(char *str)
1.1       noro      115: {
1.7       noro      116:        int c,c1;
1.1       noro      117:
1.7       noro      118:        /* EPVS : global list of the current file */
                    119:        /* add to the local variable list */
1.1       noro      120:        if ( gdef ) {
1.7       noro      121:                /* add to the external variable list */
1.9       noro      122:                c = getpvar(CPVS,str,0);
1.1       noro      123:                getpvar(EPVS,str,0);
1.10    ! noro      124:                if ( CUR_MODULE ) {
        !           125:                        c1 = getpvar(CUR_MODULE->pvs,str,1);
        !           126:                        if ( c1 >= 0 ) {
        !           127:                                fprintf(stderr,"\"%s\", near line %d: conflicting declarations for `%s'",
        !           128:                                        asir_infile->name,asir_infile->ln,str);
        !           129:                                error("");
        !           130:                        }
        !           131:                }
1.1       noro      132:                if ( CPVS != GPVS ) {
1.7       noro      133:                        /* inside function : we add the name to the global list */
1.1       noro      134:                        getpvar(GPVS,str,0);
1.7       noro      135:                        CPVS->va[c].attr = IS_GLOBAL;
                    136:                }
                    137:        } else if ( mgdef ) {
1.9       noro      138:                c = getpvar(CPVS,str,0);
1.7       noro      139:                getpvar(CUR_MODULE->pvs,str,0);
1.10    ! noro      140:                c1 = getpvar(EPVS,str,1);
        !           141:                if ( c1 >= 0 ) {
        !           142:                        fprintf(stderr,"\"%s\", near line %d: conflicting declarations for `%s'",
        !           143:                                asir_infile->name,asir_infile->ln,str);
        !           144:                        error("");
        !           145:                }
1.7       noro      146:                if ( CPVS != GPVS ) {
                    147:                        /* inside function */
                    148:                        CPVS->va[c].attr = IS_MGLOBAL;
                    149:                }
                    150:        } else if ( CPVS != GPVS ) {
                    151:                /* inside function */
1.9       noro      152:                c = getpvar(CPVS,str,0);
1.7       noro      153:                switch ( CPVS->va[c].attr ) {
                    154:                        case IS_GLOBAL:
                    155:                                c1 = getpvar(GPVS,str,1); c = PVGLOBAL((unsigned int)c1);
                    156:                                break;
                    157:                        case IS_MGLOBAL:
                    158:                                c1 = getpvar(CUR_MODULE->pvs,str,1); c = PVMGLOBAL((unsigned int)c1);
                    159:                                break;
                    160:                        case IS_LOCAL:
                    161:                        default:
                    162:                                if ( CUR_MODULE &&
                    163:                                        ((c1 = getpvar(CUR_MODULE->pvs,str,1)) >= 0) ) {
                    164:                                        CPVS->va[c].attr = IS_MGLOBAL;
                    165:                                        c = PVMGLOBAL((unsigned int)c1);
                    166:                                } else if ( getpvar(EPVS,str,1) >= 0 ) {
                    167:                                        CPVS->va[c].attr = IS_GLOBAL;
                    168:                                        c1 = getpvar(GPVS,str,1); c = PVGLOBAL((unsigned int)c1);
                    169:                                }
                    170:                                break;
1.1       noro      171:                }
1.9       noro      172:        } else if ( CUR_MODULE ) {
                    173:                /* outside function, inside module */
                    174:                if ( (c = getpvar(CUR_MODULE->pvs,str,1)) >= 0 )
                    175:                        c = PVMGLOBAL((unsigned int)c);
                    176:                else if ( getpvar(EPVS,str,1) >= 0 ) {
                    177:                        c = getpvar(GPVS,str,1);
                    178:                        c = PVGLOBAL((unsigned int)c);
                    179:                } else {
                    180:                        /* not declared as static or extern */
1.10    ! noro      181:                        fprintf(stderr,"\"%s\", near line %d: undeclared variable `%s'",
        !           182:                                asir_infile->name,asir_infile->ln,str);
        !           183:                        error("");
1.9       noro      184:                }
                    185:        } else {
                    186:                /* outside function, outside module */
                    187:                c = getpvar(GPVS,str,0);
1.1       noro      188:        }
                    189:        return c;
                    190: }
                    191:
                    192: extern FUNC parse_targetf;
                    193:
1.6       noro      194: int searchpvar(char *str)
1.1       noro      195: {
                    196:        VS pvs;
1.7       noro      197:        MODULE mod;
                    198:        int c;
1.1       noro      199:
                    200:        if ( parse_targetf && parse_targetf->id != A_USR )
1.7       noro      201:                c = -1;
                    202:        else if ( parse_targetf ) {
                    203:                pvs = parse_targetf->f.usrf->pvs;
                    204:                mod = parse_targetf->f.usrf->module;
                    205:                if ( (c = getpvar(pvs,str,1)) >= 0 ) {
                    206:                        switch ( pvs->va[c].attr ) {
                    207:                                case IS_GLOBAL:
                    208:                                        c = getpvar(GPVS,str,1);
                    209:                                        c = PVGLOBAL((unsigned int)c);
                    210:                                        break;
                    211:                                case IS_MGLOBAL:
                    212:                                        c = getpvar(mod->pvs,str,1);
                    213:                                        c = PVMGLOBAL((unsigned int)c);
                    214:                                        break;
                    215:                                default:
                    216:                                        break;
                    217:                        }
                    218:                } else if ( mod && (c = getpvar(mod->pvs,str,1)) >= 0 )
                    219:                        c = PVMGLOBAL((unsigned int)c);
                    220:                else if ( (c = getpvar(GPVS,str,1)) >= 0 )
                    221:                        c = PVGLOBAL((unsigned int)c);
                    222:                else
                    223:                        c = -1;
                    224:        }
                    225:        return c;
1.1       noro      226: }
                    227:
1.6       noro      228: int getpvar(VS pvs,char *str,int searchonly)
1.1       noro      229: {
                    230:        struct oPV *va;
                    231:        PV v;
                    232:        int i;
                    233:
                    234:        for ( va = pvs->va, i = 0; i < (int)pvs->n; i++ )
                    235:                if ( va[i].name && !strcmp(va[i].name,str) )
                    236:                        return i;
                    237:        if ( searchonly )
                    238:                return -1;
                    239:        if ( pvs->asize == pvs->n )
                    240:                reallocarray((char **)&pvs->va,(int *)&pvs->asize,(int *)&pvs->n,(int)sizeof(struct oPV));
                    241:        v = &pvs->va[pvs->n];
                    242:        NAME(v) = (char *)CALLOC(strlen(str)+1,sizeof(char));
                    243:        strcpy(NAME(v),str); v->priv = 0;
1.7       noro      244:        v->attr= IS_LOCAL; v->type = -1; i = pvs->n; pvs->n++;
1.1       noro      245:        return i;
                    246: }
                    247:
                    248: #if defined(VISUAL)
                    249: #define PCLOSE _pclose
                    250: #else
                    251: #define PCLOSE pclose
                    252: #endif
                    253:
                    254: void closecurrentinput()
                    255: {
                    256:        if ( asir_infile && !asir_infile->fp )
                    257:                return;
                    258:
1.5       noro      259: #if defined(VISUAL)
1.1       noro      260:        fclose(asir_infile->fp);
                    261:        unlink(asir_infile->tname);
                    262: #else
                    263:        PCLOSE(asir_infile->fp);
                    264: #endif
                    265:        asir_infile = NEXT(asir_infile);
                    266:        resetpvs();
                    267: }
                    268:
                    269: void resetpvs()
                    270: {
                    271:        if ( !NEXT(asir_infile) ) {
1.8       noro      272:                PVSS = 0; CPVS = GPVS; MPVS = 0; CUR_MODULE = 0; nextbp = 0;
1.1       noro      273:                if ( EPVS->va ) {
                    274:                        bzero((char *)EPVS->va,(int)(EPVS->asize*sizeof(struct oPV))); EPVS->n = 0;
                    275:                }
                    276:        }
                    277: }
                    278:
                    279: static NODE saved_PVSS;
                    280: static VS saved_CPVS;
                    281: static int saved_nextbp, saved_nextbplevel;
                    282:
                    283: void savepvs()
                    284: {
                    285:        saved_PVSS = PVSS;
                    286:        saved_CPVS = CPVS;
                    287:        saved_nextbp = nextbp;
                    288:        saved_nextbplevel = nextbplevel;
                    289: }
                    290:
                    291: void restorepvs()
                    292: {
                    293:        PVSS = saved_PVSS;
                    294:        CPVS = saved_CPVS;
                    295:        nextbp = saved_nextbp;
                    296:        nextbplevel = saved_nextbplevel;
                    297: }
                    298:
1.6       noro      299: void storeans(pointer p)
1.1       noro      300: {
                    301:        if ( APVS->asize == APVS->n )
                    302:                reallocarray((char **)&APVS->va,(int *)&APVS->asize,(int *)&APVS->n,(int)sizeof(struct oPV));
                    303:        APVS->va[APVS->n++].priv = p;
                    304: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>