Save header file when option --header-file is specified
| 3356 | |
| 3357 | /// Save header file when option --header-file is specified |
| 3358 | void Reflex::write_header_file() |
| 3359 | { |
| 3360 | if (!options["header_file"].empty()) |
| 3361 | { |
| 3362 | std::string prefix = options["prefix"]; |
| 3363 | std::string token_type = options["token_type"].empty() ? "int" : options["token_type"]; |
| 3364 | std::string yyltype = options["YYLTYPE"].empty() ? "YYLTYPE" : options["YYLTYPE"]; |
| 3365 | std::string yystype = options["YYSTYPE"].empty() ? "YYSTYPE" : options["YYSTYPE"]; |
| 3366 | std::string params = options["params"].empty() ? "void" : options["params"]; |
| 3367 | std::string comma_params = options["params"].empty() ? "" : ", " + params; |
| 3368 | std::ofstream ofs(options["header_file"].c_str(), std::ofstream::out); |
| 3369 | if (!ofs.is_open()) |
| 3370 | abort("cannot open file ", options["header_file"].c_str()); |
| 3371 | out = &ofs; |
| 3372 | *out << |
| 3373 | "// " << options["header_file"] << " generated by reflex " REFLEX_VERSION " from " << infile << "\n\n" << |
| 3374 | "#ifndef " << (prefix == "yy" ? "" : prefix.c_str()) << "REFLEX_" << upper_name(options["header_file"]) << '\n' << |
| 3375 | "#define " << (prefix == "yy" ? "" : prefix.c_str()) << "REFLEX_" << upper_name(options["header_file"]) << '\n' << |
| 3376 | "#define " << prefix << "IN_HEADER 1\n"; |
| 3377 | write_prelude(); |
| 3378 | write_section_top(); |
| 3379 | if (options["bison_cc"].empty() && (!options["bison"].empty() || !options["reentrant"].empty() || !options["bison_bridge"].empty() || !options["bison_locations"].empty())) |
| 3380 | *out << "\n#ifdef __cplusplus\n"; |
| 3381 | write_class(); |
| 3382 | if (!options["bison_cc"].empty()) |
| 3383 | { |
| 3384 | write_banner("BISON C++"); |
| 3385 | } |
| 3386 | else if (!options["reentrant"].empty() || !options["bison_bridge"].empty()) |
| 3387 | { |
| 3388 | if (!options["bison_locations"].empty()) |
| 3389 | write_banner("BISON BRIDGE LOCATIONS"); |
| 3390 | else if (!options["bison_bridge"].empty()) |
| 3391 | write_banner("BISON BRIDGE"); |
| 3392 | else |
| 3393 | write_banner("REENTRANT"); |
| 3394 | *out << |
| 3395 | "typedef void *yyscan_t;\n" |
| 3396 | "typedef "; |
| 3397 | if (!options["namespace"].empty()) |
| 3398 | write_namespace_scope(); |
| 3399 | if (!options["yyclass"].empty()) |
| 3400 | *out << options["yyclass"]; |
| 3401 | else if (!options["class"].empty()) |
| 3402 | *out << options["class"]; |
| 3403 | else |
| 3404 | *out << options["lexer"]; |
| 3405 | *out << |
| 3406 | " yyscanner_t;\n" |
| 3407 | "\n" |
| 3408 | "#ifndef YY_EXTERN_C\n" |
| 3409 | "#define YY_EXTERN_C\n" |
| 3410 | "#endif\n" |
| 3411 | "\n" |
| 3412 | "#else // !__cplusplus\n" |
| 3413 | "\n" |
| 3414 | "typedef void *yyscan_t;\n" |
| 3415 | "\n" |