-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathwrite.cc
More file actions
205 lines (187 loc) · 7.29 KB
/
Copy pathwrite.cc
File metadata and controls
205 lines (187 loc) · 7.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*****************************************************************************
* write.cc *
* *
* Description: Contains the write() functions through which the complex *
* structures can write themselves to file. More specifically, *
* the structures generate code in an output file which can be *
* used to recreate the same structures. *
* *
* Created by: David Rosenfeld *
* Date: 01/09/97 *
*****************************************************************************/
#include "complexSupport.h"
// Local function prototypes:
static void writeheader( ostream &, int );
void print_complex( ComplexCollect & collect, const char * filename )
/*
* Standalone function called from exp2cxx. Takes a ComplexCollect
* and writes its contents to a file (filename) which can be used to
* recreate this CCollect.
*/
{
#ifdef COMPLEX_INFO
ComplexList * cl;
if( collect.clists ) {
// If there's something in this collect, print it out:
cout << "\nHere's everything:\n";
for( cl = collect.clists; cl != NULL; cl = cl->next ) {
cout << *cl << endl;
}
}
#endif
collect.write( filename );
}
void ComplexCollect::write( const char * fname )
/*
* Generates C++ code in os which may be compiled and run to create a
* ComplexCollect structure. Functions are called to write out the
* ComplexList structures contained in this.
*/
{
ofstream complex;
ComplexList * clist;
int maxlevel, listmax;
// Open the stream:
complex.open( fname );
if( !complex ) {
cerr << "ERROR: Could not create output file " << fname << endl;
// yikes this is pretty drastic, Sun C++ doesn't like this anyway DAS
// exit(-1);
return;
}
writeheader( complex, clists == NULL );
// If there's nothing in this, make function a stub (very little was
// printed in writeheader() also):
if( clists == NULL ) {
complex << " return 0;" << endl;
complex << "}" << endl;
complex.close();
return;
}
// First write to os the variables it will need:
complex << " ComplexCollect *cc;\n";
complex << " ComplexList *cl;\n";
complex << " EntList *node, *child;\n";
// Determine maximum EntList level among all lists so we know how large
// of an array to create.
maxlevel = 0;
clist = clists;
while( clist ) {
listmax = clist->getEntListMaxLevel();
if( listmax > maxlevel ) {
maxlevel = listmax;
}
clist = clist->next;
}
complex << " EntList *next[" << maxlevel + 1 << "];\n\n";
// Next create the CCollect and CLists:
complex << " cc = new ComplexCollect;\n";
clist = clists;
while( clist ) {
complex << endl;
complex << " // ComplexList with supertype \"" << clist->supertype()
<< "\":\n";
clist->write( complex );
complex << " cc->insert( cl );\n";
clist = clist->next;
}
// Close up:
complex << "\n return cc;\n";
complex << "}" << endl;
complex.close();
}
static void writeheader( ostream & os, int noLists )
/*
* Writes the header for the complex file.
*/
{
// If there are no ComplexLists in the ComplexCollect, make this function
// a stub:
if( noLists ) {
os << "/*" << endl
<< " * This file normally contains instantiation statements to\n"
<< " * create complex support structures. For the current EXPRESS\n"
<< " * file, however, there are no complex entities, so this\n"
<< " * function is a stub.\n"
<< " */" << endl << endl;
os << "#include \"complexSupport.h\"\n\n";
os << "ComplexCollect *gencomplex()" << endl;
os << "{" << endl;
return;
}
// Otherwise, write file and function comments:
os << "/*" << endl
<< " * This file contains instantiation statements to create complex\n"
<< " * support structures. The structures will be used in the SCL to\n"
<< " * validate user requests to instantiate complex entities.\n"
<< " */" << endl << endl;
os << "#include \"complexSupport.h\"\n\n";
os << "ComplexCollect *gencomplex()" << endl;
os << " /*" << endl
<< " * This function contains instantiation statements for all the\n"
<< " * ComplexLists and EntLists in a ComplexCollect. The instan-\n"
<< " * stiation statements were generated in order of lower to\n"
<< " * higher, and last to first to simplify creating some of the\n"
<< " * links between structures. Because of this, the code is not\n"
<< " * very readable, but does the trick.\n"
<< " */" << endl;
os << "{" << endl;
}
void ComplexList::write( ostream & os )
/*
* Generates C++ code in os which will create an instantiation of a CList
* which will recreate this.
*/
{
head->write( os );
os << " cl = new ComplexList((AndList *)node);\n";
os << " cl->buildList();\n";
os << " cl->head->setLevel( 0 );\n";
}
void MultList::write( ostream & os )
/*
* Writes to os code to instantiate a replica of this. Does so by first
* recursing to replicate this's children, and then instantiating this.
* When write() is finished, the "node" variable in os will point to this.
*/
{
EntList * child = getLast();
// First write our children, from last to first. (We go in backwards order
// so that "node" (a variable name in the os) will = our first child when
// this loop is done. See below.)
child->write( os );
while( child->prev ) {
// Whenever an EntList::write() function is called, it writes to os
// an instantiation statement basically of the form "node = new XXX-
// List;". So we know that in the output file (os) the newly-created
// EntList is pointed to by variable node.
os << " next[" << level + 1 << "] = node;\n";
child = child->prev;
child->write( os );
os << " next[" << level + 1 << "]->prev = node;\n";
os << " node->next = next[" << level + 1 << "];\n";
}
// Now write out this:
os << " child = node;\n";
// "node" was set to the last child list we just added (which is the first
// of our children). Now we set the variable "child" to it so we can reset
// node. We do this so that node will = this when we're done and return
// to the calling function (so the calling fn can make the same assumption
// we just did).
if( join == AND ) {
os << " node = new AndList;\n";
} else if( join == ANDOR ) {
os << " node = new AndOrList;\n";
} else {
os << " node = new OrList;\n";
}
os << " ((MultList *)node)->appendList( child );\n";
// The above line will set node's childList and numchidren count.
}
void SimpleList::write( ostream & os )
/*
* Writes to os a statement to instantiate this.
*/
{
os << " node = new SimpleList( \"" << name << "\" );\n";
}