Debian Codegraph @

terps/tads/tads3/test/test_tok.cpp

raw symbols SCIP
1 #ifdef RCSID
2 static char RCSid[] =
3 "$Header: d:/cvsroot/tads/tads3/test/TEST_TOK.CPP,v 1.4 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_tok.cpp - tokenizer test
15 Function
16
17 Notes
18
19 Modified
20 04/16/99 MJRoberts - Creation
21 */
22
23 #include <stdlib.h>
24 #include <stdio.h>
25
26 #include "os.h"
27 #include "t3std.h"
28 #include "tctok.h"
29 #include "resload.h"
30 #include "tcmain.h"
31 #include "tchostsi.h"
32 #include "tcglob.h"
33 #include "tcprs.h"
34 #include "vmimage.h"
35 #include "vmrunsym.h"
36 #include "vmmeta.h"
37 #include "t3test.h"
38 #include "tct3drv.h"
39
40
41 static void errexit(const char *msg)
42 {
43 printf("%s\n", msg);
44 exit(1);
45 }
46
47 int main(int argc, char **argv)
48 {
49 CResLoader *res_loader;
50 CTcHostIfc *hostifc;
51 int curarg;
52 CTcTokFileDesc *desc;
53 long linenum;
54 int pp_mode = FALSE;
55 char pathbuf[OSFNMAX];
56
57 /* initialize for testing */
58 test_init();
59
60 /* create the host interface object */
61 hostifc = new CTcHostIfcStdio();
62
63 /* create a resource loader */
64 os_get_special_path(pathbuf, sizeof(pathbuf), argv[0], OS_GSP_T3_RES);
65 res_loader = new CResLoader(pathbuf);
66
67 /* initialize the compiler */
68 CTcMain::init(hostifc, res_loader, "us-ascii");
69
70 /* set test reporting mode */
71 G_tok->set_test_report_mode(TRUE);
72 G_tcmain->set_test_report_mode(TRUE);
73
74 err_try
75 {
76 /* add some pre-defined symbols for testing */
77 G_tok->add_define("_MSC_VER", "1100");
78 G_tok->add_define("_WIN32", "1");
79 G_tok->add_define("_M_IX86", "500");
80 G_tok->add_define("__STDC__", "0");
81 G_tok->add_define("_INTEGRAL_MAX_BITS", "64");
82 G_tok->add_define("__cplusplus", "1");
83
84 /* scan -I arguments */
85 for (curarg = 1 ; curarg < argc ; ++curarg)
86 {
87 char *p;
88
89 /* get the argument string for easy reference */
90 p = argv[curarg];
91
92 /* if it's not an option, we're done */
93 if (*p != '-')
94 break;
95
96 /* if it's a -I argument, use it */
97 if (*(p + 1) == 'I')
98 {
99 char *path;
100
101 /*
102 * if it's with this argument, read it, otherwise move
103 * on to the next argument
104 */
105 if (*(p + 2) == '\0')
106 path = argv[++curarg];
107 else
108 path = p + 2;
109
110 /* add the directory to the include path list */
111 G_tok->add_inc_path(path);
112 }
113 else if (*(p + 1) == 'P')
114 {
115 /* set preprocess-only mode */
116 G_tok->set_mode_pp_only(TRUE);
117 pp_mode = TRUE;
118 }
119 else if (*(p + 1) == 'v')
120 {
121 /* set verbose mode */
122 G_tcmain->set_verbosity(TRUE);
123 }
124 else
125 {
126 /*
127 * invalid usage - consume all the arguments and fall
128 * through to the usage checker
129 */
130 curarg = argc;
131 break;
132 }
133 }
134
135 /* check arguments */
136 if (curarg + 1 != argc)
137 {
138 /* terminate the compiler */
139 CTcMain::terminate();
140
141 /* delete our objects */
142 delete res_loader;
143
144 /* exit with an error */
145 errexit("usage: test_tok [options] <source-file>\n"
146 "options:\n"
147 " -Idir - add dir to include path\n"
148 " -P - preprocess to standard output\n"
149 " -v - verbose error messages");
150 }
151
152 /* set up the tokenizer with the main input file */
153 if (G_tok->set_source(argv[curarg], argv[curarg]))
154 errexit("unable to open source file");
155
156 /* start out with no stream */
157 desc = 0;
158 linenum = 0;
159
160 /* read lines of input */
161 for (;;)
162 {
163 /* read the next line, and stop if we've reached end of file */
164 if (G_tok->read_line_pp())
165 break;
166
167 /*
168 * If we're in a different stream than for the last line, or
169 * the new line number is more than the last line number plus
170 * 1, add a #line directive to the output stream.
171 *
172 * In order to make test log output independent of local path
173 * naming conventions and the local directory structure, use
174 * only the root filename in the #line directive.
175 */
176 if (pp_mode
177 && (G_tok->get_last_desc() != desc
178 || G_tok->get_last_linenum() != linenum + 1))
179 printf("#line %ld %s\n", G_tok->get_last_linenum(),
180 G_tok->get_last_desc()->get_dquoted_rootname());
181
182 /* remember the last line we read */
183 desc = G_tok->get_last_desc();
184 linenum = G_tok->get_last_linenum();
185
186 /* show this line */
187 printf("%s\n", G_tok->get_cur_line());
188 }
189
190 /* dump the hash table, to see what it looks like */
191 G_tok->get_defines_table()->debug_dump();
192 }
193 err_catch(exc)
194 {
195 /*
196 * if it's not the general internal error, log it; don't log
197 * general internal errors, since these will have been logged as
198 * specific internal errors before being thrown
199 */
200 if (exc->get_error_code() != TCERR_INTERNAL_ERROR)
201 printf("exception caught: %d\n", exc->get_error_code());
202 }
203 err_end;
204
205 /* shut down the compiler */
206 CTcMain::terminate();
207
208 /* done with the res loader */
209 delete res_loader;
210
211 /* delete host interface */
212 delete hostifc;
213
214 /* show any unfreed memory */
215 t3_list_memory_blocks(0);
216
217 /* success */
218 return 0;
219 }
220
221 /* ------------------------------------------------------------------------ */
222 /*
223 * dummy implementation of runtime symbol table
224 */
225 void CVmRuntimeSymbols::add_sym(const char *, size_t,
226 const vm_val_t *)
227 {
228 }
229
230 /* dummy implementation of runtime metaclass table */
231 vm_meta_entry_t *CVmMetaTable::get_entry_by_id(const char *id) const
232 {
233 return 0;
234 }
235
236 CTcSymObj *CTcParser::add_gen_obj_stat(CTcSymObj *)
237 {
238 return 0;
239 }
240
241 void CTcParser::add_gen_obj_prop_stat(
242 CTcSymObj *, CTcSymProp *, const CTcConstVal *)
243 {
244 }
245
246 void CTcParser::set_source_text_group_mode(int)
247 {
248 }
249
250 class CTPNInlineObject *CTcPrsOpUnary::parse_inline_object(int)
251 {
252 return 0;
253 }
254
255 CTPNAnonFunc *CTcPrsOpUnary::parse_anon_func(int, int)
256 {
257 return 0;
258 }
259
260 void CTcPrsSymtab::add_to_global_symtab(CTcPrsSymtab *, CTcSymbol *)
261 {
262 }
263
264 int CTcParser::alloc_ctx_arr_idx()
265 {
266 return 0;
267 }
268
269 void CTcParser::init_local_ctx()
270 {
271 }
272
273 void CTPNStmObjectBase::add_implicit_constructor()
274 {
275 }
276
277 void CTPNObjDef::fold_proplist(CTcPrsSymtab *)
278 {
279 }
280
281 void CTPNStmObjectBase::add_prop_entry(CTPNObjProp *prop, int replace)
282 {
283 }
284
285 void CTPNStmObjectBase::delete_property(CTcSymProp *)
286 {
287 }
288
289 int CTPNStmObjectBase::parse_nested_obj_prop(
290 CTPNObjProp* &, int *, tcprs_term_info *, CTcToken const *, int)
291 {
292 return FALSE;
293 }
294
295 void CTPNStmBase::add_debug_line_rec()
296 {
297 }
298
299 void CTPNStmBase::add_debug_line_rec(CTcTokFileDesc *, long)
300 {
301 }