Parse a thrift program for testing
| 117 | |
| 118 | // Parse a thrift program for testing |
| 119 | inline void parse_thrift_for_test(t_program* program) { |
| 120 | REQUIRE(program != nullptr); |
| 121 | |
| 122 | // These globals are used by the parser; see thrift/globals.h. |
| 123 | g_program = program; |
| 124 | g_scope = program->scope(); |
| 125 | g_parent_scope = nullptr; |
| 126 | g_parent_prefix = program->get_name() + "."; |
| 127 | |
| 128 | g_curpath = program->get_path(); |
| 129 | g_curdir = directory_name(g_curpath); |
| 130 | |
| 131 | // Pass 1: scan includes (even if none) to match the compiler behavior. |
| 132 | g_parse_mode = INCLUDES; |
| 133 | yylineno = 1; |
| 134 | yyin = std::fopen(g_curpath.c_str(), "r"); |
| 135 | REQUIRE(yyin != nullptr); |
| 136 | REQUIRE(yyparse() == 0); |
| 137 | std::fclose(yyin); |
| 138 | yyin = nullptr; |
| 139 | |
| 140 | // Pass 2: parse program. |
| 141 | g_parse_mode = PROGRAM; |
| 142 | yylineno = 1; |
| 143 | yyin = std::fopen(g_curpath.c_str(), "r"); |
| 144 | REQUIRE(yyin != nullptr); |
| 145 | REQUIRE(yyparse() == 0); |
| 146 | std::fclose(yyin); |
| 147 | yyin = nullptr; |
| 148 | } |
| 149 | |
| 150 | } // namespace cpp_generator_test_utils |
| 151 |
no test coverage detected