Annotation of OpenXM_contrib2/asir2000/parse/pvar.c, Revision 1.9
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.9 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/pvar.c,v 1.8 2003/05/14 07:08:48 noro Exp $
1.2 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
52:
53: NODE PVSS;
54:
55: void mkpvs()
1.6 noro 56: {
1.1 noro 57: VS pvs;
58:
59: pvs = (VS)MALLOC(sizeof(struct oVS));
60: pvs->va = (struct oPV *)MALLOC(DEFSIZE*sizeof(struct oPV));
61: pvs->n = 0;
62: pvs->asize=DEFSIZE;
63: CPVS = pvs;
64: }
65:
1.6 noro 66: void pushpvs(FUNC f)
1.1 noro 67: {
68: VS pvs;
69: NODE node;
70: int level;
71: extern int evalstatline;
72:
73: pvs = f->f.usrf->pvs;
74: if ( PVSS ) {
75: ((VS)BDY(PVSS))->at = evalstatline;
76: level = ((VS)BDY(PVSS))->level+1;
77: } else
78: level = 1;
79: MKNODE(node,pvs,PVSS);
80: PVSS = node;
81: CPVS = (VS)MALLOC(sizeof(struct oVS)); BDY(PVSS) = (pointer)CPVS;
82: CPVS->usrf = f;
83: CPVS->n = CPVS->asize = pvs->n;
84: CPVS->level = level;
85: if ( CPVS->n ) {
86: CPVS->va = (struct oPV *)MALLOC(CPVS->n*sizeof(struct oPV));
87: bcopy((char *)pvs->va,(char *)CPVS->va,(int)(pvs->n*sizeof(struct oPV)));
88: }
89: if ( nextbp )
90: nextbplevel++;
91: }
92:
93: void poppvs() {
94: PVSS = NEXT(PVSS);
95: if ( PVSS )
96: CPVS = (VS)BDY(PVSS);
97: else
98: CPVS = GPVS;
99: if ( nextbp )
100: nextbplevel--;
101: }
102:
1.7 noro 103: int gdef,mgdef;
1.1 noro 104:
1.7 noro 105: #define IS_LOCAL 0
106: #define IS_GLOBAL 1
107: #define IS_MGLOBAL 2
108:
109: unsigned int makepvar(char *str)
1.1 noro 110: {
1.7 noro 111: int c,c1;
1.1 noro 112:
1.7 noro 113: /* EPVS : global list of the current file */
114: /* add to the local variable list */
1.1 noro 115: if ( gdef ) {
1.7 noro 116: /* add to the external variable list */
1.9 ! noro 117: c = getpvar(CPVS,str,0);
1.1 noro 118: getpvar(EPVS,str,0);
119: if ( CPVS != GPVS ) {
1.7 noro 120: /* inside function : we add the name to the global list */
1.1 noro 121: getpvar(GPVS,str,0);
1.7 noro 122: CPVS->va[c].attr = IS_GLOBAL;
123: }
124: } else if ( mgdef ) {
1.9 ! noro 125: c = getpvar(CPVS,str,0);
1.7 noro 126: getpvar(CUR_MODULE->pvs,str,0);
127: if ( CPVS != GPVS ) {
128: /* inside function */
129: CPVS->va[c].attr = IS_MGLOBAL;
130: }
131: } else if ( CPVS != GPVS ) {
132: /* inside function */
1.9 ! noro 133: c = getpvar(CPVS,str,0);
1.7 noro 134: switch ( CPVS->va[c].attr ) {
135: case IS_GLOBAL:
136: c1 = getpvar(GPVS,str,1); c = PVGLOBAL((unsigned int)c1);
137: break;
138: case IS_MGLOBAL:
139: c1 = getpvar(CUR_MODULE->pvs,str,1); c = PVMGLOBAL((unsigned int)c1);
140: break;
141: case IS_LOCAL:
142: default:
143: if ( CUR_MODULE &&
144: ((c1 = getpvar(CUR_MODULE->pvs,str,1)) >= 0) ) {
145: CPVS->va[c].attr = IS_MGLOBAL;
146: c = PVMGLOBAL((unsigned int)c1);
147: } else if ( getpvar(EPVS,str,1) >= 0 ) {
148: CPVS->va[c].attr = IS_GLOBAL;
149: c1 = getpvar(GPVS,str,1); c = PVGLOBAL((unsigned int)c1);
150: }
151: break;
1.1 noro 152: }
1.9 ! noro 153: } else if ( CUR_MODULE ) {
! 154: /* outside function, inside module */
! 155: if ( (c = getpvar(CUR_MODULE->pvs,str,1)) >= 0 )
! 156: c = PVMGLOBAL((unsigned int)c);
! 157: else if ( getpvar(EPVS,str,1) >= 0 ) {
! 158: c = getpvar(GPVS,str,1);
! 159: c = PVGLOBAL((unsigned int)c);
! 160: } else {
! 161: /* not declared as static or extern */
! 162: error("Undeclared variable in a module.");
! 163: }
! 164: } else {
! 165: /* outside function, outside module */
! 166: c = getpvar(GPVS,str,0);
1.1 noro 167: }
168: return c;
169: }
170:
171: extern FUNC parse_targetf;
172:
1.6 noro 173: int searchpvar(char *str)
1.1 noro 174: {
175: VS pvs;
1.7 noro 176: MODULE mod;
177: int c;
1.1 noro 178:
179: if ( parse_targetf && parse_targetf->id != A_USR )
1.7 noro 180: c = -1;
181: else if ( parse_targetf ) {
182: pvs = parse_targetf->f.usrf->pvs;
183: mod = parse_targetf->f.usrf->module;
184: if ( (c = getpvar(pvs,str,1)) >= 0 ) {
185: switch ( pvs->va[c].attr ) {
186: case IS_GLOBAL:
187: c = getpvar(GPVS,str,1);
188: c = PVGLOBAL((unsigned int)c);
189: break;
190: case IS_MGLOBAL:
191: c = getpvar(mod->pvs,str,1);
192: c = PVMGLOBAL((unsigned int)c);
193: break;
194: default:
195: break;
196: }
197: } else if ( mod && (c = getpvar(mod->pvs,str,1)) >= 0 )
198: c = PVMGLOBAL((unsigned int)c);
199: else if ( (c = getpvar(GPVS,str,1)) >= 0 )
200: c = PVGLOBAL((unsigned int)c);
201: else
202: c = -1;
203: }
204: return c;
1.1 noro 205: }
206:
1.6 noro 207: int getpvar(VS pvs,char *str,int searchonly)
1.1 noro 208: {
209: struct oPV *va;
210: PV v;
211: int i;
212:
213: for ( va = pvs->va, i = 0; i < (int)pvs->n; i++ )
214: if ( va[i].name && !strcmp(va[i].name,str) )
215: return i;
216: if ( searchonly )
217: return -1;
218: if ( pvs->asize == pvs->n )
219: reallocarray((char **)&pvs->va,(int *)&pvs->asize,(int *)&pvs->n,(int)sizeof(struct oPV));
220: v = &pvs->va[pvs->n];
221: NAME(v) = (char *)CALLOC(strlen(str)+1,sizeof(char));
222: strcpy(NAME(v),str); v->priv = 0;
1.7 noro 223: v->attr= IS_LOCAL; v->type = -1; i = pvs->n; pvs->n++;
1.1 noro 224: return i;
225: }
226:
227: #if defined(VISUAL)
228: #define PCLOSE _pclose
229: #else
230: #define PCLOSE pclose
231: #endif
232:
233: void closecurrentinput()
234: {
235: if ( asir_infile && !asir_infile->fp )
236: return;
237:
1.5 noro 238: #if defined(VISUAL)
1.1 noro 239: fclose(asir_infile->fp);
240: unlink(asir_infile->tname);
241: #else
242: PCLOSE(asir_infile->fp);
243: #endif
244: asir_infile = NEXT(asir_infile);
245: resetpvs();
246: }
247:
248: void resetpvs()
249: {
250: if ( !NEXT(asir_infile) ) {
1.8 noro 251: PVSS = 0; CPVS = GPVS; MPVS = 0; CUR_MODULE = 0; nextbp = 0;
1.1 noro 252: if ( EPVS->va ) {
253: bzero((char *)EPVS->va,(int)(EPVS->asize*sizeof(struct oPV))); EPVS->n = 0;
254: }
255: }
256: }
257:
258: static NODE saved_PVSS;
259: static VS saved_CPVS;
260: static int saved_nextbp, saved_nextbplevel;
261:
262: void savepvs()
263: {
264: saved_PVSS = PVSS;
265: saved_CPVS = CPVS;
266: saved_nextbp = nextbp;
267: saved_nextbplevel = nextbplevel;
268: }
269:
270: void restorepvs()
271: {
272: PVSS = saved_PVSS;
273: CPVS = saved_CPVS;
274: nextbp = saved_nextbp;
275: nextbplevel = saved_nextbplevel;
276: }
277:
1.6 noro 278: void storeans(pointer p)
1.1 noro 279: {
280: if ( APVS->asize == APVS->n )
281: reallocarray((char **)&APVS->va,(int *)&APVS->asize,(int *)&APVS->n,(int)sizeof(struct oPV));
282: APVS->va[APVS->n++].priv = p;
283: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>