Debian Codegraph @

terps/tads/tads3/test/test_sym.cpp

raw symbols SCIP
1 #ifdef RCSID
2 static char RCSid[] =
3 "$Header: d:/cvsroot/tads/tads3/test/TEST_SYM.CPP,v 1.1 1999/07/11 00:47:03 MJRoberts Exp $";
4 #endif
5
6 /*
7 * Copyright (c) 1999, 2002 Michael J. Roberts. All Rights Reserved.
8 *
9 * Please see the accompanying license file, LICENSE.TXT, for information
10 * on using and copying this software.
11 */
12 /*
13 Name
14 test_sym.cpp - parser test: parse a source file and create a
15 symbol export file
16 Function
17
18 Notes
19
20 Modified
21 05/01/99 MJRoberts - Creation
22 */
23
24 #include <stdlib.h>
25 #include <stdio.h>
26
27 #include "os.h"
28 #include "t3std.h"
29 #include "tctok.h"
30 #include "resload.h"
31 #include "tcmain.h"
32 #include "tchostsi.h"
33 #include "tcglob.h"
34 #include "tcprs.h"
35 #include "vmfile.h"
36 #include "tct3.h"
37 #include "vmimage.h"
38 #include "vmrunsym.h"
39 #include "vmmeta.h"
40 #include "t3test.h"
41 #include "tcmake.h"
42
43
44 static void errexit(const char *msg)
45 {
46 printf("%s\n", msg);
47 exit(1);
48 }
49
50 int main(int argc, char **argv)
51 {
52 CResLoader *res_loader;
53 CTcHostIfc *hostifc;
54 int curarg;
55 int fatal_error_count = 0;
56 osfildef *fpout = 0;
57 CTPNStmProg *node;
58 const char *sym_fname;
59 CVmFile *sym_file = 0;
60 int success;
61 char pathbuf[OSFNMAX];
62
63 /* initialize for testing */
64 test_init();
65
66 /* create the host interface object */
67 hostifc = new CTcHostIfcStdio();
68
69 /* create a resource loader */
70 os_get_special_path(pathbuf, sizeof(pathbuf), argv[0], OS_GSP_T3_RES);
71 res_loader = new CResLoader(pathbuf);
72
73 /* initialize the compiler */
74 CTcMain::init(hostifc, res_loader, 0);
75
76 err_try
77 {
78 /* scan -I arguments */
79 for (curarg = 1 ; curarg < argc ; ++curarg)
80 {
81 char *p;
82
83 /* get the argument string for easy reference */
84 p = argv[curarg];
85
86 /* if it's not an option, we're done */
87 if (*p != '-')
88 break;
89
90 /* if it's a -I argument, use it */
91 if (*(p + 1) == 'I')
92 {
93 char *path;
94
95 /*
96 * if it's with this argument, read it, otherwise move
97 * on to the next argument
98 */
99 if (*(p + 2) == '\0')
100 path = argv[++curarg];
101 else
102 path = p + 2;
103
104 /* add the directory to the include path list */
105 G_tok->add_inc_path(path);
106 }
107 else if (*(p + 1) == 'v')
108 {
109 /* set verbose mode */
110 G_tcmain->set_verbosity(TRUE);
111 }
112 else
113 {
114 /*
115 * invalid usage - consume all the arguments and fall
116 * through to the usage checker
117 */
118 curarg = argc;
119 break;
120 }
121 }
122
123 /* check arguments */
124 if (curarg + 2 != argc)
125 {
126 /* terminate the compiler */
127 CTcMain::terminate();
128
129 /* delete our objects */
130 delete res_loader;
131
132 /* exit with an error */
133 errexit("usage: test_sym [options] <source-file> <symbol-file>\n"
134 "options:\n"
135 " -Idir - add dir to include path\n"
136 " -v - verbose error messages");
137 }
138
139 /* set up the tokenizer with the main input file */
140 if (G_tok->set_source(argv[curarg], argv[curarg]))
141 errexit("unable to open source file");
142
143 /* set up the output symbol file */
144 sym_fname = argv[curarg+1];
145 fpout = osfopwb(sym_fname, OSFTT3SYM);
146 if (fpout == 0)
147 errexit("unable to open image file");
148 sym_file = new CVmFile();
149 sym_file->set_file(fpout, 0);
150
151 /* parse in syntax-only mode */
152 G_prs->set_syntax_only(TRUE);
153
154 /* read the first token */
155 G_tok->next();
156
157 /* parse at the top level */
158 node = G_prs->parse_top();
159
160 /* if errors occurred during parsing, stop here */
161 if (G_tcmain->get_error_count() != 0 || node == 0)
162 goto done;
163
164 /* write the symbol file */
165 G_prs->write_symbol_file(sym_file, 0);
166
167 done: ;
168 }
169 err_catch(exc)
170 {
171 /*
172 * if it's not a general internal or fatal error, log it; don't
173 * log general errors, since these will have been logged as
174 * specific internal errors before being thrown
175 */
176 if (exc->get_error_code() != TCERR_INTERNAL_ERROR
177 && exc->get_error_code() != TCERR_FATAL_ERROR)
178 G_tok->log_error(TC_SEV_FATAL, exc->get_error_code());
179
180 /* count the fatal error */
181 ++fatal_error_count;
182 }
183 err_end;
184
185 /* report errors */
186 fprintf(stderr,
187 "Warnings: %d\n"
188 "Errors: %d\n"
189 "Longest string: %lu, longest list: %lu\n",
190 G_tcmain->get_warning_count(),
191 G_tcmain->get_error_count() + fatal_error_count,
192 (unsigned long)G_cg->get_max_str_len(),
193 (unsigned long)G_cg->get_max_list_cnt());
194
195 /*
196 * note whether or not the compilation was successful - it succeeded
197 * if we had no errors or fatal errors
198 */
199 success = (G_tcmain->get_error_count() + fatal_error_count == 0);
200
201 /* delete the image file object (this closes the file) */
202 delete sym_file;
203
204 /*
205 * if any errors occurred, delete the image file in the external
206 * file system - this prevents us from leaving around an incomplete
207 * or corrupted image file when compilation fails, and helps
208 * 'make'-type tools realize that they must generate the image file
209 * target again on the next build, even if source files didn't
210 * change
211 */
212 if (!success)
213 osfdel(sym_fname);
214
215 /* shut down the compiler */
216 CTcMain::terminate();
217
218 /* done with the res loader */
219 delete res_loader;
220
221 /* delete the host interface */
222 delete hostifc;
223
224 /* show any unfreed memory */
225 t3_list_memory_blocks(0);
226
227 /*
228 * terminate - exit with a success indication if we had no errors
229 * (other than warnings); exit with an error indication otherwise
230 */
231 return (success ? OSEXSUCC : OSEXFAIL);
232 }
233
234 /* ------------------------------------------------------------------------ */
235 /*
236 * dummy implementation of runtime symbol table
237 */
238 void CVmRuntimeSymbols::add_sym(const char *, size_t,
239 const vm_val_t *)
240 {
241 }
242
243 void CTcGenTarg::add_debug_line_table(ulong)
244 {
245 }
246
247 void CTPNObjProp::check_locals()
248 {
249 }
250
251 /* dummy implementation of runtime metaclass table */
252 vm_meta_entry_t *CVmMetaTable::get_entry_by_id(const char *id) const
253 {
254 return 0;
255 }