Annotation of OpenXM_contrib2/asir2000/parse/pvar.c, Revision 1.1.1.1
1.1 noro 1: /* $OpenXM: OpenXM/src/asir99/parse/pvar.c,v 1.1.1.1 1999/11/10 08:12:34 noro Exp $ */
2: #include "ca.h"
3: #include "parse.h"
4:
5: NODE PVSS;
6:
7: void mkpvs()
8: {
9: VS pvs;
10:
11: pvs = (VS)MALLOC(sizeof(struct oVS));
12: pvs->va = (struct oPV *)MALLOC(DEFSIZE*sizeof(struct oPV));
13: pvs->n = 0;
14: pvs->asize=DEFSIZE;
15: CPVS = pvs;
16: }
17:
18: void pushpvs(f)
19: FUNC f;
20: {
21: VS pvs;
22: NODE node;
23: int level;
24: extern int evalstatline;
25:
26: pvs = f->f.usrf->pvs;
27: if ( PVSS ) {
28: ((VS)BDY(PVSS))->at = evalstatline;
29: level = ((VS)BDY(PVSS))->level+1;
30: } else
31: level = 1;
32: MKNODE(node,pvs,PVSS);
33: PVSS = node;
34: CPVS = (VS)MALLOC(sizeof(struct oVS)); BDY(PVSS) = (pointer)CPVS;
35: CPVS->usrf = f;
36: CPVS->n = CPVS->asize = pvs->n;
37: CPVS->level = level;
38: if ( CPVS->n ) {
39: CPVS->va = (struct oPV *)MALLOC(CPVS->n*sizeof(struct oPV));
40: bcopy((char *)pvs->va,(char *)CPVS->va,(int)(pvs->n*sizeof(struct oPV)));
41: }
42: if ( nextbp )
43: nextbplevel++;
44: }
45:
46: void poppvs() {
47: PVSS = NEXT(PVSS);
48: if ( PVSS )
49: CPVS = (VS)BDY(PVSS);
50: else
51: CPVS = GPVS;
52: if ( nextbp )
53: nextbplevel--;
54: }
55:
56: int gdef;
57:
58: int makepvar(str)
59: char *str;
60: {
61: int c;
62:
63: c = getpvar(CPVS,str,0);
64: if ( gdef ) {
65: getpvar(EPVS,str,0);
66: if ( CPVS != GPVS ) {
67: getpvar(GPVS,str,0);
68: CPVS->va[c].attr = 1;
69: }
70: } else if ( (CPVS != GPVS) &&
71: (CPVS->va[c].attr || (getpvar(EPVS,str,1) >= 0)) ) {
72: CPVS->va[c].attr = 1;
73: c = (getpvar(GPVS,str,1)|MSB);
74: }
75: return c;
76: }
77:
78: extern FUNC parse_targetf;
79:
80: int searchpvar(str)
81: char *str;
82: {
83: VS pvs;
84: int i;
85:
86: if ( parse_targetf && parse_targetf->id != A_USR )
87: return -1;
88: pvs = parse_targetf ? parse_targetf->f.usrf->pvs : GPVS;
89: i = getpvar(pvs,str,1);
90: if ( ((i>=0)&&pvs->va[i].attr) || (i<0) )
91: return getpvar(GPVS,str,1)|MSB;
92: else
93: return i;
94: }
95:
96: int getpvar(pvs,str,searchonly)
97: VS pvs;
98: char *str;
99: int searchonly;
100: {
101: struct oPV *va;
102: PV v;
103: int i;
104:
105: for ( va = pvs->va, i = 0; i < (int)pvs->n; i++ )
106: if ( va[i].name && !strcmp(va[i].name,str) )
107: return i;
108: if ( searchonly )
109: return -1;
110: if ( pvs->asize == pvs->n )
111: reallocarray((char **)&pvs->va,(int *)&pvs->asize,(int *)&pvs->n,(int)sizeof(struct oPV));
112: v = &pvs->va[pvs->n];
113: NAME(v) = (char *)CALLOC(strlen(str)+1,sizeof(char));
114: strcpy(NAME(v),str); v->priv = 0;
115: v->attr= 0; v->type = -1; i = pvs->n; pvs->n++;
116: return i;
117: }
118:
119: #if defined(VISUAL)
120: #define PCLOSE _pclose
121: #else
122: #define PCLOSE pclose
123: #endif
124:
125: void closecurrentinput()
126: {
127: if ( asir_infile && !asir_infile->fp )
128: return;
129:
130: #if defined(THINK_C) || defined(VISUAL)
131: #if defined(THINK_C)
132: void setDir(short);
133:
134: fclose(asir_infile->fp);
135: setDir(asir_infile->vol);
136: unlink(asir_infile->tname);
137: resetDir();
138: #else
139: fclose(asir_infile->fp);
140: unlink(asir_infile->tname);
141: #endif
142: #else
143: PCLOSE(asir_infile->fp);
144: #endif
145: asir_infile = NEXT(asir_infile);
146: resetpvs();
147: }
148:
149: void resetpvs()
150: {
151: if ( !NEXT(asir_infile) ) {
152: PVSS = 0; CPVS = GPVS; nextbp = 0;
153: if ( EPVS->va ) {
154: bzero((char *)EPVS->va,(int)(EPVS->asize*sizeof(struct oPV))); EPVS->n = 0;
155: }
156: }
157: }
158:
159: static NODE saved_PVSS;
160: static VS saved_CPVS;
161: static int saved_nextbp, saved_nextbplevel;
162:
163: void savepvs()
164: {
165: saved_PVSS = PVSS;
166: saved_CPVS = CPVS;
167: saved_nextbp = nextbp;
168: saved_nextbplevel = nextbplevel;
169: }
170:
171: void restorepvs()
172: {
173: PVSS = saved_PVSS;
174: CPVS = saved_CPVS;
175: nextbp = saved_nextbp;
176: nextbplevel = saved_nextbplevel;
177: }
178:
179: void storeans(p)
180: pointer p;
181: {
182: if ( APVS->asize == APVS->n )
183: reallocarray((char **)&APVS->va,(int *)&APVS->asize,(int *)&APVS->n,(int)sizeof(struct oPV));
184: APVS->va[APVS->n++].priv = p;
185: }
186:
187: #if 1
188: pointer evalpv(id,expr,f)
189: int id;
190: FNODE expr;
191: pointer f;
192: {
193: pointer a,val = 0;
194: pointer *addr;
195:
196: if ( expr->id != I_PVAR && expr->id != I_CAST )
197: error("evalpv : invalid assignment");
198: switch ( id ) {
199: case I_PRESELF:
200: getmemberp((FNODE)expr,(Obj **)&addr);
201: (*((ARF)f)->fp)(CO,*addr,ONE,&val); *addr = val; break;
202: case I_POSTSELF:
203: getmemberp((FNODE)expr,(Obj **)&addr);
204: val = *addr; (*((ARF)f)->fp)(CO,*addr,ONE,&a); *addr = a; break;
205: case I_PVAR:
206: getmember((FNODE)expr,(Obj *)&val); break;
207: case I_ASSPVAR:
208: getmemberp((FNODE)expr,(Obj **)&addr); *addr = val = eval((FNODE)f); break;
209: }
210: return val;
211: }
212: #endif
213:
214: #if 0
215: pointer evalpv(id,tree,f)
216: int id;
217: NODE2 tree;
218: pointer f;
219: {
220: pointer a,val = 0;
221: pointer *addr;
222: int pv;
223: NODE ind,tn;
224:
225: switch ( id ) {
226: case I_PRESELF:
227: getmemberp((FNODE)tree,(Obj **)&addr);
228: (*((ARF)f)->fp)(CO,*addr,ONE,&val); *addr = val; break;
229: case I_POSTSELF:
230: getmemberp((FNODE)tree,(Obj **)&addr);
231: val = *addr; (*((ARF)f)->fp)(CO,*addr,ONE,&a); *addr = a; break;
232: case I_PVAR:
233: pv = (int)BDY1(tree); ind = (NODE)BDY2(tree); GETPV(pv,a);
234: if ( !ind )
235: val = a;
236: else {
237: evalnodebody(ind,&tn); getarray(a,tn,&val);
238: }
239: break;
240: case I_ASSPVAR:
241: pv = (int)BDY1(tree); ind = (NODE)BDY2(tree);
242: if ( !ind ) {
243: val = eval(f); ASSPV(pv,val);
244: } else {
245: GETPV(pv,a);
246: if ( a ) {
247: evalnodebody(ind,&tn); putarray(a,tn,val = eval(f));
248: }
249: }
250: break;
251: }
252: return val;
253: }
254: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>