Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 1 | /** |
| 2 | * thrift - a lightweight cross-language rpc/serialization tool |
| 3 | * |
| 4 | * This file contains the main compiler engine for Thrift, which invokes the |
| 5 | * scanner/parser to build the thrift object tree. The interface generation |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 6 | * code for each language lives in a file by the language name under the |
| 7 | * generate/ folder, and all parse structures live in parse/ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 8 | * |
| 9 | * @author Mark Slee <mcslee@facebook.com> |
| 10 | */ |
| 11 | |
| 12 | #include <stdlib.h> |
| 13 | #include <stdio.h> |
| 14 | #include <stdarg.h> |
| 15 | #include <string> |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 16 | #include <sys/types.h> |
| 17 | #include <sys/stat.h> |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 18 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 19 | // Careful: must include globals first for extern definitions |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 20 | #include "globals.h" |
| 21 | |
| 22 | #include "main.h" |
| 23 | #include "parse/t_program.h" |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 24 | #include "parse/t_scope.h" |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 25 | #include "generate/t_cpp_generator.h" |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 26 | #include "generate/t_java_generator.h" |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 27 | #include "generate/t_php_generator.h" |
Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 28 | #include "generate/t_py_generator.h" |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 29 | |
| 30 | using namespace std; |
| 31 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 32 | /** |
| 33 | * Global program tree |
| 34 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 35 | t_program* g_program; |
| 36 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 37 | /** |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 38 | * Global types |
| 39 | */ |
| 40 | |
| 41 | t_type* g_type_void; |
| 42 | t_type* g_type_string; |
| 43 | t_type* g_type_bool; |
| 44 | t_type* g_type_byte; |
| 45 | t_type* g_type_i16; |
| 46 | t_type* g_type_i32; |
| 47 | t_type* g_type_i64; |
| 48 | t_type* g_type_double; |
| 49 | |
| 50 | /** |
| 51 | * Global scope |
| 52 | */ |
| 53 | t_scope* g_scope; |
| 54 | |
| 55 | /** |
| 56 | * Parent scope to also parse types |
| 57 | */ |
| 58 | t_scope* g_parent_scope; |
| 59 | |
| 60 | /** |
| 61 | * Prefix for putting types in parent scope |
| 62 | */ |
| 63 | string g_parent_prefix; |
| 64 | |
| 65 | /** |
| 66 | * Parsing pass |
| 67 | */ |
| 68 | PARSE_MODE g_parse_mode; |
| 69 | |
| 70 | /** |
| 71 | * Current directory of file being parsed |
| 72 | */ |
| 73 | string g_curdir; |
| 74 | |
| 75 | /** |
| 76 | * Current file being parsed |
| 77 | */ |
| 78 | string g_curpath; |
| 79 | |
| 80 | /** |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 81 | * Global debug state |
| 82 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 83 | int g_debug = 0; |
| 84 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 85 | /** |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 86 | * Warning level |
| 87 | */ |
| 88 | int g_warn = 1; |
| 89 | |
| 90 | /** |
| 91 | * Verbose output |
| 92 | */ |
| 93 | int g_verbose = 0; |
| 94 | |
| 95 | /** |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 96 | * Global time string |
| 97 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 98 | char* g_time_str; |
| 99 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 100 | /** |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 101 | * Flags to control code generation |
| 102 | */ |
| 103 | bool gen_cpp = false; |
| 104 | bool gen_java = false; |
| 105 | bool gen_py = false; |
| 106 | bool gen_php = false; |
| 107 | bool gen_phpi = false; |
| 108 | bool gen_recurse = false; |
| 109 | |
| 110 | /** |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 111 | * Report an error to the user. This is called yyerror for historical |
| 112 | * reasons (lex and yacc expect the error reporting routine to be called |
| 113 | * this). Call this function to report any errors to the user. |
| 114 | * yyerror takes printf style arguments. |
| 115 | * |
| 116 | * @param fmt C format string followed by additional arguments |
| 117 | */ |
| 118 | void yyerror(char* fmt, ...) { |
| 119 | va_list args; |
| 120 | fprintf(stderr, |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 121 | "[ERROR:%s:%d] (last token was '%s')\n", |
| 122 | g_curpath.c_str(), |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 123 | yylineno, |
| 124 | yytext); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 125 | |
| 126 | va_start(args, fmt); |
| 127 | vfprintf(stderr, fmt, args); |
| 128 | va_end(args); |
| 129 | |
| 130 | fprintf(stderr, "\n"); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Prints a debug message from the parser. |
| 135 | * |
| 136 | * @param fmt C format string followed by additional arguments |
| 137 | */ |
| 138 | void pdebug(char* fmt, ...) { |
| 139 | if (g_debug == 0) { |
| 140 | return; |
| 141 | } |
| 142 | va_list args; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 143 | printf("[PARSE] "); |
| 144 | va_start(args, fmt); |
| 145 | vprintf(fmt, args); |
| 146 | va_end(args); |
| 147 | printf("\n"); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Prints a verbose output mode message |
| 152 | * |
| 153 | * @param fmt C format string followed by additional arguments |
| 154 | */ |
| 155 | void pverbose(char* fmt, ...) { |
| 156 | if (g_verbose == 0) { |
| 157 | return; |
| 158 | } |
| 159 | va_list args; |
| 160 | va_start(args, fmt); |
| 161 | vprintf(fmt, args); |
| 162 | va_end(args); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Prints a warning message |
| 167 | * |
| 168 | * @param fmt C format string followed by additional arguments |
| 169 | */ |
| 170 | void pwarning(int level, char* fmt, ...) { |
| 171 | if (g_warn < level) { |
| 172 | return; |
| 173 | } |
| 174 | va_list args; |
| 175 | printf("[WARNING:%s:%d] ", g_curpath.c_str(), yylineno); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 176 | va_start(args, fmt); |
| 177 | vprintf(fmt, args); |
| 178 | va_end(args); |
| 179 | printf("\n"); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Prints a failure message and exits |
| 184 | * |
| 185 | * @param fmt C format string followed by additional arguments |
| 186 | */ |
| 187 | void failure(char* fmt, ...) { |
| 188 | va_list args; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 189 | fprintf(stderr, "[FAILURE:%s:%d] ", g_curpath.c_str(), yylineno); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 190 | va_start(args, fmt); |
| 191 | vfprintf(stderr, fmt, args); |
| 192 | va_end(args); |
| 193 | printf("\n"); |
| 194 | exit(1); |
| 195 | } |
| 196 | |
| 197 | /** |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 198 | * Converts a string filename into a thrift program name |
| 199 | */ |
| 200 | string program_name(string filename) { |
| 201 | string::size_type slash = filename.rfind("/"); |
| 202 | if (slash != string::npos) { |
| 203 | filename = filename.substr(slash+1); |
| 204 | } |
| 205 | string::size_type dot = filename.rfind("."); |
| 206 | if (dot != string::npos) { |
| 207 | filename = filename.substr(0, dot); |
| 208 | } |
| 209 | return filename; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Gets the directory path of a filename |
| 214 | */ |
| 215 | string directory_name(string filename) { |
| 216 | string::size_type slash = filename.rfind("/"); |
| 217 | // No slash, just use the current directory |
| 218 | if (slash == string::npos) { |
| 219 | return "."; |
| 220 | } |
| 221 | return filename.substr(0, slash); |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Finds the appropriate file path for the given filename |
| 226 | */ |
| 227 | string include_file(string filename) { |
| 228 | // Absolute path? Just try that |
| 229 | if (filename[0] != '/') { |
| 230 | filename = g_curdir + "/" + filename; |
| 231 | } |
| 232 | |
| 233 | // Realpath! |
| 234 | char rp[PATH_MAX]; |
| 235 | if (realpath(filename.c_str(), rp) == NULL) { |
| 236 | pwarning(0, "Cannot open include file %s\n", filename.c_str()); |
| 237 | return std::string(); |
| 238 | } |
| 239 | |
| 240 | // Stat this files |
| 241 | struct stat finfo; |
| 242 | if (stat(rp, &finfo) == 0) { |
| 243 | return rp; |
| 244 | } |
| 245 | |
| 246 | // Uh oh |
| 247 | pwarning(0, "Could not find include file %s\n", filename.c_str()); |
| 248 | return std::string(); |
| 249 | } |
| 250 | |
| 251 | /** |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 252 | * Diplays the usage message and then exits with an error code. |
| 253 | */ |
| 254 | void usage() { |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 255 | fprintf(stderr, "Usage: thrift [options] file\n"); |
| 256 | fprintf(stderr, "Options:\n"); |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 257 | fprintf(stderr, " --cpp Generate C++ output files\n"); |
| 258 | fprintf(stderr, " --java Generate Java output files\n"); |
| 259 | fprintf(stderr, " --php Generate PHP output files\n"); |
| 260 | fprintf(stderr, " --phpi Generate PHP inlined files\n"); |
| 261 | fprintf(stderr, " --py Generate Python output files\n"); |
| 262 | fprintf(stderr, " --nowarn Suppress all compiler warnings (BAD!)\n"); |
| 263 | fprintf(stderr, " --strict Strict compiler warnings on\n"); |
| 264 | fprintf(stderr, " --v[erbose] Verbose mode\n"); |
| 265 | fprintf(stderr, " --r[ecurse] Also generate included files\n"); |
| 266 | fprintf(stderr, " --debug Parse debug trace to stdout\n"); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 267 | exit(1); |
| 268 | } |
| 269 | |
| 270 | /** |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 271 | * Parses a program |
| 272 | */ |
| 273 | void parse(t_program* program, t_program* parent_program) { |
| 274 | // Get scope file path |
| 275 | string path = program->get_path(); |
| 276 | |
| 277 | // Set current dir global, which is used in the include_file function |
| 278 | g_curdir = directory_name(path); |
| 279 | g_curpath = path; |
| 280 | |
| 281 | // Open the file |
| 282 | yyin = fopen(path.c_str(), "r"); |
| 283 | if (yyin == 0) { |
| 284 | failure("Could not open input file: \"%s\"", path.c_str()); |
| 285 | } |
| 286 | |
| 287 | // Create new scope and scan for includes |
| 288 | pverbose("Scanning %s for includes\n", path.c_str()); |
| 289 | g_parse_mode = INCLUDES; |
| 290 | g_program = program; |
| 291 | g_scope = program->scope(); |
| 292 | if (yyparse() != 0) { |
| 293 | failure("Parser error during include pass."); |
| 294 | } |
| 295 | fclose(yyin); |
| 296 | |
| 297 | // Recursively parse all the include programs |
| 298 | vector<t_program*>& includes = program->get_includes(); |
| 299 | vector<t_program*>::iterator iter; |
| 300 | for (iter = includes.begin(); iter != includes.end(); ++iter) { |
| 301 | parse(*iter, program); |
| 302 | } |
| 303 | |
| 304 | // Parse the program the file |
| 305 | g_parse_mode = PROGRAM; |
| 306 | g_program = program; |
| 307 | g_scope = program->scope(); |
| 308 | g_parent_scope = (parent_program != NULL) ? parent_program->scope() : NULL; |
| 309 | g_parent_prefix = program->get_name() + "."; |
| 310 | g_curpath = path; |
| 311 | yyin = fopen(path.c_str(), "r"); |
| 312 | if (yyin == 0) { |
| 313 | failure("Could not open input file: \"%s\"", path.c_str()); |
| 314 | } |
| 315 | pverbose("Parsing %s for types\n", path.c_str()); |
| 316 | if (yyparse() != 0) { |
| 317 | failure("Parser error during types pass."); |
| 318 | } |
| 319 | fclose(yyin); |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Generate code |
| 324 | */ |
| 325 | void generate(t_program* program) { |
| 326 | // Oooohh, recursive code generation, hot!! |
| 327 | if (gen_recurse) { |
| 328 | const vector<t_program*>& includes = program->get_includes(); |
| 329 | for (size_t i = 0; i < includes.size(); ++i) { |
| 330 | generate(includes[i]); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | // Generate code! |
| 335 | try { |
| 336 | pverbose("Program: %s\n", program->get_path().c_str()); |
| 337 | |
| 338 | if (gen_cpp) { |
| 339 | pverbose("Generating C++\n"); |
| 340 | t_cpp_generator* cpp = new t_cpp_generator(program); |
| 341 | cpp->generate_program(); |
| 342 | delete cpp; |
| 343 | } |
| 344 | |
| 345 | if (gen_java) { |
| 346 | pverbose("Generating Java\n"); |
| 347 | t_java_generator* java = new t_java_generator(program); |
| 348 | java->generate_program(); |
| 349 | delete java; |
| 350 | } |
| 351 | |
| 352 | if (gen_php) { |
| 353 | pverbose("Generating PHP\n"); |
| 354 | t_php_generator* php = new t_php_generator(program, false); |
| 355 | php->generate_program(); |
| 356 | delete php; |
| 357 | } |
| 358 | |
| 359 | if (gen_phpi) { |
| 360 | pverbose("Generating PHP-inline\n"); |
| 361 | t_php_generator* phpi = new t_php_generator(program, true); |
| 362 | phpi->generate_program(); |
| 363 | delete phpi; |
| 364 | } |
| 365 | |
| 366 | if (gen_py) { |
| 367 | pverbose("Generating Python\n"); |
| 368 | t_py_generator* py = new t_py_generator(program); |
| 369 | py->generate_program(); |
| 370 | delete py; |
| 371 | } |
| 372 | } catch (string s) { |
| 373 | printf("Error: %s\n", s.c_str()); |
| 374 | } catch (const char* exc) { |
| 375 | printf("Error: %s\n", exc); |
| 376 | } |
| 377 | |
| 378 | } |
| 379 | |
| 380 | /** |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 381 | * Parse it up.. then spit it back out, in pretty much every language. Alright |
| 382 | * not that many languages, but the cool ones that we care about. |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 383 | */ |
| 384 | int main(int argc, char** argv) { |
| 385 | int i; |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 386 | |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 387 | // Setup time string |
| 388 | time_t now = time(NULL); |
| 389 | g_time_str = ctime(&now); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 390 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 391 | // Check for necessary arguments, you gotta have at least a filename and |
| 392 | // an output language flag |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 393 | if (argc < 2) { |
| 394 | usage(); |
| 395 | } |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 396 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 397 | // Hacky parameter handling... I didn't feel like using a library sorry! |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 398 | for (i = 1; i < argc-1; i++) { |
Mark Slee | fdbee81 | 2006-09-27 18:50:48 +0000 | [diff] [blame] | 399 | char* arg; |
| 400 | arg = strtok(argv[i], " "); |
| 401 | while (arg != NULL) { |
| 402 | if (strcmp(arg, "--debug") == 0) { |
| 403 | g_debug = 1; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 404 | } else if (strcmp(arg, "--nowarn") == 0) { |
| 405 | g_warn = 0; |
| 406 | } else if (strcmp(arg, "--strict") == 0) { |
| 407 | g_warn = 2; |
| 408 | } else if (strcmp(arg, "--v") == 0 || strcmp(arg, "--verbose") == 0 ) { |
| 409 | g_verbose = 1; |
| 410 | } else if (strcmp(arg, "--r") == 0 || strcmp(arg, "--recurse") == 0 ) { |
| 411 | gen_recurse = true; |
Mark Slee | fdbee81 | 2006-09-27 18:50:48 +0000 | [diff] [blame] | 412 | } else if (strcmp(arg, "--cpp") == 0) { |
| 413 | gen_cpp = true; |
| 414 | } else if (strcmp(arg, "--java") == 0) { |
| 415 | gen_java = true; |
| 416 | } else if (strcmp(arg, "--php") == 0) { |
| 417 | gen_php = true; |
Mark Slee | fdbee81 | 2006-09-27 18:50:48 +0000 | [diff] [blame] | 418 | } else if (strcmp(arg, "--phpi") == 0) { |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 419 | gen_phpi = true; |
Mark Slee | fdbee81 | 2006-09-27 18:50:48 +0000 | [diff] [blame] | 420 | } else if (strcmp(arg, "--py") == 0) { |
| 421 | gen_py = true; |
| 422 | } else { |
| 423 | fprintf(stderr, "!!! Unrecognized option: %s\n", arg); |
| 424 | usage(); |
| 425 | } |
| 426 | |
| 427 | // Tokenize more |
| 428 | arg = strtok(NULL, " "); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 432 | // You gotta generate something! |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 433 | if (!gen_cpp && !gen_java && !gen_php && !gen_phpi && !gen_py) { |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 434 | fprintf(stderr, "!!! No output language(s) specified\n\n"); |
| 435 | usage(); |
| 436 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 437 | |
| 438 | // Real-pathify it |
| 439 | char rp[PATH_MAX]; |
| 440 | if (realpath(argv[i], rp) == NULL) { |
| 441 | failure("Could not open input file: %s", argv[i]); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 442 | } |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 443 | string input_file(rp); |
| 444 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 445 | // Instance of the global parse tree |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 446 | t_program* program = new t_program(input_file); |
| 447 | |
| 448 | // Initialize global types |
| 449 | g_type_void = new t_base_type("void", t_base_type::TYPE_VOID); |
| 450 | g_type_string = new t_base_type("string", t_base_type::TYPE_STRING); |
| 451 | g_type_bool = new t_base_type("bool", t_base_type::TYPE_BOOL); |
| 452 | g_type_byte = new t_base_type("byte", t_base_type::TYPE_BYTE); |
| 453 | g_type_i16 = new t_base_type("i16", t_base_type::TYPE_I16); |
| 454 | g_type_i32 = new t_base_type("i32", t_base_type::TYPE_I32); |
| 455 | g_type_i64 = new t_base_type("i64", t_base_type::TYPE_I64); |
| 456 | g_type_double = new t_base_type("double", t_base_type::TYPE_DOUBLE); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 457 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 458 | // Parse it! |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 459 | parse(program, NULL); |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 460 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 461 | // Generate it! |
| 462 | generate(program); |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 463 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 464 | // Clean up. Who am I kidding... this program probably orphans heap memory |
| 465 | // all over the place, but who cares because it is about to exit and it is |
| 466 | // all referenced and used by this wacky parse tree up until now anyways. |
Mark Slee | b15a68b | 2006-06-07 06:46:24 +0000 | [diff] [blame] | 467 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame^] | 468 | delete program; |
| 469 | delete g_type_void; |
| 470 | delete g_type_string; |
| 471 | delete g_type_bool; |
| 472 | delete g_type_byte; |
| 473 | delete g_type_i16; |
| 474 | delete g_type_i32; |
| 475 | delete g_type_i64; |
| 476 | delete g_type_double; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 477 | |
| 478 | // Finished |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 479 | return 0; |
| 480 | } |