[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.15

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.15    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/pvar.c,v 1.14 2003/11/12 07:01: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.12      noro       55: int gdef,mgdef,ldef;
                     56:
1.1       noro       57:
1.10      noro       58: void mkpvs(char *fname)
1.6       noro       59: {
1.1       noro       60:        VS pvs;
1.11      noro       61:        char *fullname;
1.12      noro       62:        FUNC f;
1.1       noro       63:
1.12      noro       64:        if ( CUR_MODULE ) {
                     65:                /* function must be declared in advance */
                     66:                searchf(CUR_MODULE->usrf_list,fname,&f);
                     67:                if ( !f ) {
                     68:                        fprintf(stderr,"\"%s\", near line %d: undeclared function `%s'",
                     69:                                asir_infile->name,asir_infile->ln,fname);
                     70:                        error("");
                     71:                }
                     72:        }
1.1       noro       73:        pvs = (VS)MALLOC(sizeof(struct oVS));
                     74:        pvs->va = (struct oPV *)MALLOC(DEFSIZE*sizeof(struct oPV));
                     75:        pvs->n = 0;
                     76:        pvs->asize=DEFSIZE;
                     77:        CPVS = pvs;
1.10      noro       78:
                     79:        /* XXX */
1.11      noro       80:        if ( CUR_MODULE ) {
                     81:                fullname =
                     82:                        (char *)MALLOC_ATOMIC(strlen(CUR_MODULE->name)+strlen(fname)+1);
                     83:                sprintf(fullname,"%s.%s",CUR_MODULE->name,fname);
                     84:                CUR_FUNC = fullname;
                     85:        } else
                     86:                CUR_FUNC = fname;
1.1       noro       87: }
                     88:
1.6       noro       89: void pushpvs(FUNC f)
1.1       noro       90: {
                     91:        VS pvs;
                     92:        NODE node;
                     93:        int level;
                     94:        extern int evalstatline;
                     95:
                     96:        pvs = f->f.usrf->pvs;
                     97:        if ( PVSS ) {
                     98:                ((VS)BDY(PVSS))->at = evalstatline;
                     99:                level = ((VS)BDY(PVSS))->level+1;
                    100:        } else
                    101:                level = 1;
                    102:        MKNODE(node,pvs,PVSS);
                    103:        PVSS = node;
                    104:        CPVS = (VS)MALLOC(sizeof(struct oVS)); BDY(PVSS) = (pointer)CPVS;
                    105:        CPVS->usrf = f;
                    106:        CPVS->n = CPVS->asize = pvs->n;
                    107:        CPVS->level = level;
                    108:        if ( CPVS->n ) {
                    109:                CPVS->va = (struct oPV *)MALLOC(CPVS->n*sizeof(struct oPV));
                    110:                bcopy((char *)pvs->va,(char *)CPVS->va,(int)(pvs->n*sizeof(struct oPV)));
                    111:        }
                    112:        if ( nextbp )
                    113:                nextbplevel++;
                    114: }
                    115:
                    116: void poppvs() {
                    117:        PVSS = NEXT(PVSS);
                    118:        if ( PVSS )
                    119:                CPVS = (VS)BDY(PVSS);
                    120:        else
                    121:                CPVS = GPVS;
                    122:        if ( nextbp )
                    123:                nextbplevel--;
                    124: }
                    125:
1.7       noro      126: #define IS_LOCAL 0
                    127: #define IS_GLOBAL 1
                    128: #define IS_MGLOBAL 2
1.15    ! noro      129: #define IS_PATTERN 3
1.7       noro      130:
1.10      noro      131:
1.7       noro      132: unsigned int makepvar(char *str)
1.1       noro      133: {
1.12      noro      134:        int c,c1,created;
1.1       noro      135:
1.15    ! noro      136:        if ( str[0] == '_' ) {
        !           137:                /* pattern variable */
        !           138:                c1 = getpvar(PPVS,str,0);
        !           139:                c = PVPATTERN((unsigned int)c1);
        !           140:                PPVS->va[c1].attr = IS_PATTERN;
        !           141:        } else if ( gdef ) {
        !           142:                /* EPVS : global list of the current file */
        !           143:                /* add to the local variable list */
        !           144:                /* also add to the external variable list */
1.9       noro      145:                c = getpvar(CPVS,str,0);
1.1       noro      146:                getpvar(EPVS,str,0);
1.10      noro      147:                if ( CUR_MODULE ) {
                    148:                        c1 = getpvar(CUR_MODULE->pvs,str,1);
1.13      noro      149:                        if ( c1 >= 0 ) goto CONFLICTION;
1.10      noro      150:                }
1.1       noro      151:                if ( CPVS != GPVS ) {
1.7       noro      152:                        /* inside function : we add the name to the global list */
1.1       noro      153:                        getpvar(GPVS,str,0);
1.7       noro      154:                        CPVS->va[c].attr = IS_GLOBAL;
                    155:                }
                    156:        } else if ( mgdef ) {
1.9       noro      157:                c = getpvar(CPVS,str,0);
1.7       noro      158:                getpvar(CUR_MODULE->pvs,str,0);
1.10      noro      159:                c1 = getpvar(EPVS,str,1);
1.13      noro      160:                if ( c1 >= 0 ) goto CONFLICTION;
1.7       noro      161:                if ( CPVS != GPVS ) {
                    162:                        /* inside function */
                    163:                        CPVS->va[c].attr = IS_MGLOBAL;
                    164:                }
1.12      noro      165:        } else if ( ldef > 0 ) {
                    166:                /* if ldef > 0, then local variables are being declared */
                    167:                c = getpvar(CPVS,str,0);
1.13      noro      168:                c1 = getpvar(EPVS,str,1);
1.14      noro      169:                if ( c1 >= 0 ) {
                    170:                        if ( CUR_MODULE )
                    171:                                goto CONFLICTION;
                    172:                        else {
                    173:                                fprintf(stderr,"Warning: \"%s\", near line %d: conflicting declarations for `%s'\n",
                    174:                                        asir_infile->name,asir_infile->ln,str);
                    175:                                fprintf(stderr,"         `%s' is bound to the global variable\n",str);
                    176:                                CPVS->va[c].attr = IS_GLOBAL;
                    177:                                c1 = getpvar(GPVS,str,1); c = PVGLOBAL((unsigned int)c1);
                    178:                        }
                    179:                } else {
                    180:                        if ( CUR_MODULE ) {
                    181:                                c1 = getpvar(CUR_MODULE->pvs,str,1);
                    182:                        }
                    183:                        if ( c1 >= 0 ) goto CONFLICTION;
                    184:                        CPVS->va[c].attr = IS_LOCAL;
1.13      noro      185:                }
1.7       noro      186:        } else if ( CPVS != GPVS ) {
                    187:                /* inside function */
1.12      noro      188:                if ( CUR_MODULE ) {
                    189:                        /* search only */
                    190:                        c = getpvar(CPVS,str,1);
                    191:                        if ( c < 0 ) {
                    192:                                c = getpvar(CPVS,str,0);
                    193:                                created = 1;
                    194:                        } else
                    195:                                created = 0;
                    196:                } else {
                    197:                        /* may be created */
                    198:                        c = getpvar(CPVS,str,0);
                    199:                }
1.7       noro      200:                switch ( CPVS->va[c].attr ) {
                    201:                        case IS_GLOBAL:
                    202:                                c1 = getpvar(GPVS,str,1); c = PVGLOBAL((unsigned int)c1);
                    203:                                break;
                    204:                        case IS_MGLOBAL:
                    205:                                c1 = getpvar(CUR_MODULE->pvs,str,1); c = PVMGLOBAL((unsigned int)c1);
                    206:                                break;
                    207:                        case IS_LOCAL:
                    208:                        default:
                    209:                                if ( CUR_MODULE &&
                    210:                                        ((c1 = getpvar(CUR_MODULE->pvs,str,1)) >= 0) ) {
                    211:                                        CPVS->va[c].attr = IS_MGLOBAL;
                    212:                                        c = PVMGLOBAL((unsigned int)c1);
                    213:                                } else if ( getpvar(EPVS,str,1) >= 0 ) {
                    214:                                        CPVS->va[c].attr = IS_GLOBAL;
                    215:                                        c1 = getpvar(GPVS,str,1); c = PVGLOBAL((unsigned int)c1);
1.12      noro      216:                                } else if ( CUR_MODULE && created && (ldef == 0) ) {
                    217:                                        /* not declared */
                    218:                                        /* if ldef == 0, at least one local variables has been
                    219:                                           declared */
                    220:                                        fprintf(stderr,
                    221:                                                "Warning: \"%s\", near line %d: undeclared local variable `%s'\n",
                    222:                                                asir_infile->name,asir_infile->ln,str);
1.7       noro      223:                                }
                    224:                                break;
1.1       noro      225:                }
1.9       noro      226:        } else if ( CUR_MODULE ) {
                    227:                /* outside function, inside module */
                    228:                if ( (c = getpvar(CUR_MODULE->pvs,str,1)) >= 0 )
                    229:                        c = PVMGLOBAL((unsigned int)c);
                    230:                else if ( getpvar(EPVS,str,1) >= 0 ) {
                    231:                        c = getpvar(GPVS,str,1);
                    232:                        c = PVGLOBAL((unsigned int)c);
                    233:                } else {
                    234:                        /* not declared as static or extern */
1.10      noro      235:                        fprintf(stderr,"\"%s\", near line %d: undeclared variable `%s'",
                    236:                                asir_infile->name,asir_infile->ln,str);
                    237:                        error("");
1.9       noro      238:                }
                    239:        } else {
                    240:                /* outside function, outside module */
                    241:                c = getpvar(GPVS,str,0);
1.1       noro      242:        }
                    243:        return c;
1.13      noro      244:
                    245: CONFLICTION:
                    246:        fprintf(stderr,"\"%s\", near line %d: conflicting declarations for `%s'",
                    247:                asir_infile->name,asir_infile->ln,str);
                    248:        error("");
1.1       noro      249: }
                    250:
                    251: extern FUNC parse_targetf;
                    252:
1.6       noro      253: int searchpvar(char *str)
1.1       noro      254: {
                    255:        VS pvs;
1.7       noro      256:        MODULE mod;
                    257:        int c;
1.1       noro      258:
                    259:        if ( parse_targetf && parse_targetf->id != A_USR )
1.7       noro      260:                c = -1;
                    261:        else if ( parse_targetf ) {
                    262:                pvs = parse_targetf->f.usrf->pvs;
                    263:                mod = parse_targetf->f.usrf->module;
                    264:                if ( (c = getpvar(pvs,str,1)) >= 0 ) {
                    265:                        switch ( pvs->va[c].attr ) {
                    266:                                case IS_GLOBAL:
                    267:                                        c = getpvar(GPVS,str,1);
                    268:                                        c = PVGLOBAL((unsigned int)c);
                    269:                                        break;
                    270:                                case IS_MGLOBAL:
                    271:                                        c = getpvar(mod->pvs,str,1);
                    272:                                        c = PVMGLOBAL((unsigned int)c);
                    273:                                        break;
                    274:                                default:
                    275:                                        break;
                    276:                        }
                    277:                } else if ( mod && (c = getpvar(mod->pvs,str,1)) >= 0 )
                    278:                        c = PVMGLOBAL((unsigned int)c);
                    279:                else if ( (c = getpvar(GPVS,str,1)) >= 0 )
                    280:                        c = PVGLOBAL((unsigned int)c);
                    281:                else
                    282:                        c = -1;
                    283:        }
                    284:        return c;
1.1       noro      285: }
                    286:
1.6       noro      287: int getpvar(VS pvs,char *str,int searchonly)
1.1       noro      288: {
                    289:        struct oPV *va;
                    290:        PV v;
                    291:        int i;
                    292:
                    293:        for ( va = pvs->va, i = 0; i < (int)pvs->n; i++ )
                    294:                if ( va[i].name && !strcmp(va[i].name,str) )
                    295:                        return i;
                    296:        if ( searchonly )
                    297:                return -1;
                    298:        if ( pvs->asize == pvs->n )
                    299:                reallocarray((char **)&pvs->va,(int *)&pvs->asize,(int *)&pvs->n,(int)sizeof(struct oPV));
                    300:        v = &pvs->va[pvs->n];
                    301:        NAME(v) = (char *)CALLOC(strlen(str)+1,sizeof(char));
                    302:        strcpy(NAME(v),str); v->priv = 0;
1.7       noro      303:        v->attr= IS_LOCAL; v->type = -1; i = pvs->n; pvs->n++;
1.1       noro      304:        return i;
                    305: }
                    306:
                    307: #if defined(VISUAL)
                    308: #define PCLOSE _pclose
                    309: #else
                    310: #define PCLOSE pclose
                    311: #endif
                    312:
                    313: void closecurrentinput()
                    314: {
                    315:        if ( asir_infile && !asir_infile->fp )
                    316:                return;
                    317:
1.5       noro      318: #if defined(VISUAL)
1.1       noro      319:        fclose(asir_infile->fp);
                    320:        unlink(asir_infile->tname);
                    321: #else
                    322:        PCLOSE(asir_infile->fp);
                    323: #endif
                    324:        asir_infile = NEXT(asir_infile);
                    325:        resetpvs();
                    326: }
                    327:
                    328: void resetpvs()
                    329: {
                    330:        if ( !NEXT(asir_infile) ) {
1.8       noro      331:                PVSS = 0; CPVS = GPVS; MPVS = 0; CUR_MODULE = 0; nextbp = 0;
1.12      noro      332:                gdef = mgdef = ldef = 0;
1.1       noro      333:                if ( EPVS->va ) {
                    334:                        bzero((char *)EPVS->va,(int)(EPVS->asize*sizeof(struct oPV))); EPVS->n = 0;
                    335:                }
                    336:        }
                    337: }
                    338:
                    339: static NODE saved_PVSS;
                    340: static VS saved_CPVS;
                    341: static int saved_nextbp, saved_nextbplevel;
                    342:
                    343: void savepvs()
                    344: {
                    345:        saved_PVSS = PVSS;
                    346:        saved_CPVS = CPVS;
                    347:        saved_nextbp = nextbp;
                    348:        saved_nextbplevel = nextbplevel;
                    349: }
                    350:
                    351: void restorepvs()
                    352: {
                    353:        PVSS = saved_PVSS;
                    354:        CPVS = saved_CPVS;
                    355:        nextbp = saved_nextbp;
                    356:        nextbplevel = saved_nextbplevel;
                    357: }
                    358:
1.6       noro      359: void storeans(pointer p)
1.1       noro      360: {
                    361:        if ( APVS->asize == APVS->n )
                    362:                reallocarray((char **)&APVS->va,(int *)&APVS->asize,(int *)&APVS->n,(int)sizeof(struct oPV));
                    363:        APVS->va[APVS->n++].priv = p;
                    364: }

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