Annotation of OpenXM_contrib2/asir2000/parse/pvar.c, Revision 1.8
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.8 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/pvar.c,v 1.7 2003/05/14 06:20:12 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: c = getpvar(CPVS,str,0);
116: if ( gdef ) {
1.7 noro 117: /* add to the external variable list */
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 ) {
125: getpvar(CUR_MODULE->pvs,str,0);
126: if ( CPVS != GPVS ) {
127: /* inside function */
128: CPVS->va[c].attr = IS_MGLOBAL;
129: }
130: } else if ( CPVS != GPVS ) {
131: /* inside function */
132: switch ( CPVS->va[c].attr ) {
133: case IS_GLOBAL:
134: c1 = getpvar(GPVS,str,1); c = PVGLOBAL((unsigned int)c1);
135: break;
136: case IS_MGLOBAL:
137: c1 = getpvar(CUR_MODULE->pvs,str,1); c = PVMGLOBAL((unsigned int)c1);
138: break;
139: case IS_LOCAL:
140: default:
141: if ( CUR_MODULE &&
142: ((c1 = getpvar(CUR_MODULE->pvs,str,1)) >= 0) ) {
143: CPVS->va[c].attr = IS_MGLOBAL;
144: c = PVMGLOBAL((unsigned int)c1);
145: } else if ( getpvar(EPVS,str,1) >= 0 ) {
146: CPVS->va[c].attr = IS_GLOBAL;
147: c1 = getpvar(GPVS,str,1); c = PVGLOBAL((unsigned int)c1);
148: }
149: break;
1.1 noro 150: }
151: }
152: return c;
153: }
154:
155: extern FUNC parse_targetf;
156:
1.6 noro 157: int searchpvar(char *str)
1.1 noro 158: {
159: VS pvs;
1.7 noro 160: MODULE mod;
161: int c;
1.1 noro 162:
163: if ( parse_targetf && parse_targetf->id != A_USR )
1.7 noro 164: c = -1;
165: else if ( parse_targetf ) {
166: pvs = parse_targetf->f.usrf->pvs;
167: mod = parse_targetf->f.usrf->module;
168: if ( (c = getpvar(pvs,str,1)) >= 0 ) {
169: switch ( pvs->va[c].attr ) {
170: case IS_GLOBAL:
171: c = getpvar(GPVS,str,1);
172: c = PVGLOBAL((unsigned int)c);
173: break;
174: case IS_MGLOBAL:
175: c = getpvar(mod->pvs,str,1);
176: c = PVMGLOBAL((unsigned int)c);
177: break;
178: default:
179: break;
180: }
181: } else if ( mod && (c = getpvar(mod->pvs,str,1)) >= 0 )
182: c = PVMGLOBAL((unsigned int)c);
183: else if ( (c = getpvar(GPVS,str,1)) >= 0 )
184: c = PVGLOBAL((unsigned int)c);
185: else
186: c = -1;
187: }
188: return c;
1.1 noro 189: }
190:
1.6 noro 191: int getpvar(VS pvs,char *str,int searchonly)
1.1 noro 192: {
193: struct oPV *va;
194: PV v;
195: int i;
196:
197: for ( va = pvs->va, i = 0; i < (int)pvs->n; i++ )
198: if ( va[i].name && !strcmp(va[i].name,str) )
199: return i;
200: if ( searchonly )
201: return -1;
202: if ( pvs->asize == pvs->n )
203: reallocarray((char **)&pvs->va,(int *)&pvs->asize,(int *)&pvs->n,(int)sizeof(struct oPV));
204: v = &pvs->va[pvs->n];
205: NAME(v) = (char *)CALLOC(strlen(str)+1,sizeof(char));
206: strcpy(NAME(v),str); v->priv = 0;
1.7 noro 207: v->attr= IS_LOCAL; v->type = -1; i = pvs->n; pvs->n++;
1.1 noro 208: return i;
209: }
210:
211: #if defined(VISUAL)
212: #define PCLOSE _pclose
213: #else
214: #define PCLOSE pclose
215: #endif
216:
217: void closecurrentinput()
218: {
219: if ( asir_infile && !asir_infile->fp )
220: return;
221:
1.5 noro 222: #if defined(VISUAL)
1.1 noro 223: fclose(asir_infile->fp);
224: unlink(asir_infile->tname);
225: #else
226: PCLOSE(asir_infile->fp);
227: #endif
228: asir_infile = NEXT(asir_infile);
229: resetpvs();
230: }
231:
232: void resetpvs()
233: {
234: if ( !NEXT(asir_infile) ) {
1.8 ! noro 235: PVSS = 0; CPVS = GPVS; MPVS = 0; CUR_MODULE = 0; nextbp = 0;
1.1 noro 236: if ( EPVS->va ) {
237: bzero((char *)EPVS->va,(int)(EPVS->asize*sizeof(struct oPV))); EPVS->n = 0;
238: }
239: }
240: }
241:
242: static NODE saved_PVSS;
243: static VS saved_CPVS;
244: static int saved_nextbp, saved_nextbplevel;
245:
246: void savepvs()
247: {
248: saved_PVSS = PVSS;
249: saved_CPVS = CPVS;
250: saved_nextbp = nextbp;
251: saved_nextbplevel = nextbplevel;
252: }
253:
254: void restorepvs()
255: {
256: PVSS = saved_PVSS;
257: CPVS = saved_CPVS;
258: nextbp = saved_nextbp;
259: nextbplevel = saved_nextbplevel;
260: }
261:
1.6 noro 262: void storeans(pointer p)
1.1 noro 263: {
264: if ( APVS->asize == APVS->n )
265: reallocarray((char **)&APVS->va,(int *)&APVS->asize,(int *)&APVS->n,(int)sizeof(struct oPV));
266: APVS->va[APVS->n++].priv = p;
267: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>