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