|
|
1.1 root 1: /*******************************************************************
2: * *
3: * File: CIFPLOT/symbol.c *
4: * Written by Dan Fitzpatrick *
5: * copyright 1980 -- Regents of the University of California *
6: * *
7: ********************************************************************/
8:
9: #include <stdio.h>
10: #include "defs.h"
11: #include "globals.h"
12: #include "parser_defs.h"
13: #include "structs.h"
14:
15: extern Command *FindSymbol(); /* Forward reference FindSymbol */
16: IMPORT Command *MakeSymbol();
17: IMPORT Command *MakePoly();
18: IMPORT Command *MakeWire();
19: IMPORT Command *MakeBox();
20: IMPORT Command *MakeFlash();
21: IMPORT Command *MakeText();
22: IMPORT Command *MakeCall();
23: IMPORT Command *MakeArray();
24: IMPORT Command *MakePointName();
25: IMPORT struct PathHeader *MakePath();
26: IMPORT Error();
27: IMPORT AddCmd();
28:
29: CopyDelete(sym)
30: Command *sym;
31: /* Make a copy of the symbol 'sym' and mark the original deleted.
32: * Go down 'sym' backtrace list and CopyDelete all the symbols on that */
33: {
34: struct CCell *p;
35: int b;
36:
37: b = 0;
38: if (sym->Ctype.Symbl.status != DELETED) {
39: sym->Ctype.Symbl.status = DELETED;
40: b = 1;
41: CopySymbol(sym);
42: for(p=sym->Ctype.Symbl.backTrace; p!=NIL; p=p->CCLink)
43: CopyDelete(p->CCCom);
44: }
45: return(b);
46: }
47:
48: CopySymbol(sym)
49: Command *sym;
50: /* Make a new symbol header and copy all the Commands contained in 'sym'. */
51: {
52: Command *newsym,*q,*p;
53: PointList *ptr;
54: struct PathHeader *path;
55: point *pt;
56:
57: newsym = MakeSymbol(sym->Ctype.Symbl.SymNo,sym->Ctype.Symbl.a,
58: sym->Ctype.Symbl.b);
59: newsym->Ctype.Symbl.status = UNUSED;
60: newsym->Ctype.Symbl.SName = sym->Ctype.Symbl.SName;
61: for(p=sym->Ctype.Symbl.CStart; p!=NIL; p=p->CLink) {
62: switch(p->type) {
63: case POLYGON:
64: pt = &(p->Ctype.Path->pt);
65: path = MakePath(pt);
66: for(ptr=p->Ctype.Path->PLink; ptr!=NIL; ptr= ptr->PLink)
67: AddPath(path,&(ptr->pt));
68: q = MakePoly(path);
69: q->level = p->level;
70: AddCmd(newsym,q);
71: break;
72: case WIRE:
73: pt = &(p->Ctype.Wire.WPath->pt);
74: path = MakePath(pt);
75: for(ptr=p->Ctype.Wire.WPath->PLink; ptr!=NIL; ptr= ptr->PLink)
76: AddPath(path,&(ptr->pt));
77: q = MakeWire(p->Ctype.Wire.WWidth,path);
78: q->level = p->level;
79: AddCmd(newsym,q);
80: break;
81: case BOX:
82: q = MakeBox(p->Ctype.Box.blength,p->Ctype.Box.bwidth,
83: &(p->Ctype.Box.bcenter),&(p->Ctype.Box.bdirect));
84: AddCmd(newsym,q);
85: break;
86: case FLASH:
87: q = MakeFlash(p->Ctype.Flash.fdia,&(p->Ctype.Flash.fcenter));
88: AddCmd(newsym,q);
89: break;
90: case TEXT:
91: q = MakeText(p->Ctype.Text.TString,p->Ctype.Text.TTrans);
92: AddCmd(newsym,q);
93: break;
94: case POINTNAME:
95: q = MakePointName(p->Ctype.PointName.Name,
96: p->Ctype.PointName.loc.x,
97: p->Ctype.PointName.loc.y,
98: p->Ctype.PointName.Label);
99: AddCmd(newsym,q);
100: break;
101: /*
102: case POLYGON:
103: case BOX:
104: case WIRE:
105: case FLASH:
106: case TEXT:
107: AddCmd(newsym,q);
108: break;
109: */
110: case ARRAY:
111: q = MakeArray(p->Ctype.Array.As,
112: p->Ctype.Array.Am,p->Ctype.Array.An,
113: p->Ctype.Array.Adx,p->Ctype.Array.Ady);
114: AddCmd(newsym,q);
115: break;
116: case CALL:
117: q = MakeCall(p->Ctype.Call.CallNo,p->Ctype.Call.trans);
118: AddCmd(newsym,q);
119: break;
120: default:
121: { char s[128];
122: sprintf(s,"Illegal command found in symbol %d\n",
123: sym->Ctype.Symbl.SymNo);
124: Error(s,INTERNAL);
125: }
126: }
127: }
128: StoreSymbol(newsym);
129: }
130:
131: Command *SymbolTable[TableSize];
132:
133: #define hash(x) ABS(x % TableSize)
134:
135: StoreSymbol(sym)
136: Command *sym;
137: /* Put 'sym' in to the Symbol hash table */
138: {
139: int n,status;
140:
141: n = sym->Ctype.Symbl.SymNo;
142: /* Check to see there is no other copy of n */
143: status = State(n);
144: if( (status != NONEXIST) && (status != DELETED) ) {
145: char s[128];
146: sprintf(s,"Two Living Copies of Symbol %d",n);
147: Error(s,INTERNAL);
148: }
149:
150: sym->CLink = SymbolTable[hash(n)];
151: SymbolTable[hash(n)] = sym;
152: }
153:
154: Command *
155: FindSymbol(n)
156: int n;
157: /* Return a pointer to symbol n */
158: {
159: Command *p;
160:
161: for(p = SymbolTable[hash(n)]; p != NIL; p= p->CLink)
162: if (p->Ctype.Symbl.SymNo == n) {
163: return(p);
164: }
165: DEBUG("FindSymbol failed to return symbol\n");
166: return(NIL);
167: }
168:
169: DeleteDefintion(i)
170: int i;
171: {
172: int j,p;
173: Command *temp,*store,*RemovedSymbols;
174: struct CCell *bptr;
175:
176: RemovedSymbols = NIL;
177: /* Go through every symbol in the symbol table
178: * If the symbol is greater or equal to 'i' delete
179: * the symbol and put it in the RemovedSymbol list.
180: * If the symbol is less than 'i' put in a store list.
181: * This reverses the order so put back in SymbolTable again
182: * reversing the order
183: */
184: for(j=0; j<TableSize; j++) {
185: store = NIL;
186: for(temp=SymbolTable[j]; temp!= NIL; temp=SymbolTable[j]){
187: SymbolTable[j] = temp->CLink;
188: if(temp->Ctype.Symbl.SymNo < i) {
189: temp->CLink = store;
190: store = temp;
191: }
192: else {
193: temp->Ctype.Symbl.status = DELETED;
194: temp->CLink = RemovedSymbols;
195: RemovedSymbols = temp;
196: }
197: }
198: for(temp=store; temp != NIL; temp=store) {
199: store = temp->CLink;
200: temp->CLink = SymbolTable[j];
201: SymbolTable[j] = temp;
202: }
203: }
204: /* Now CopyDelete all the non-deleted backtrace symbols */
205: p = 0;
206: for(temp = RemovedSymbols; temp!=NIL; temp=temp->CLink)
207: for(bptr=temp->Ctype.Symbl.backTrace;bptr!=NIL;bptr=bptr->CCLink)
208: p |= CopyDelete(bptr->CCCom);
209: if(p) Error("Dangling References After Delete Defintion",WARNING);
210: }
211:
212: State(n)
213: int n;
214: /* Return the state of symbol n */
215: {
216: Command *p;
217:
218: for(p = SymbolTable[hash(n)]; p != NIL; p = p-> CLink)
219: if (p->Ctype.Symbl.SymNo == n)
220: return(p->Ctype.Symbl.status);
221: return(NONEXIST);
222: }
223:
224:
225: InitSymbol(){
226: int i;
227:
228: for(i=0;i<TableSize;i++)
229: SymbolTable[i] = NIL;
230: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.