MCPcopy Create free account
hub / github.com/OpenSteam001/OpenSteamTool / generate

Function generate

tools/ipc_codegen/ipc_codegen.cpp:1115–1150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1113}
1114
1115bool generate(const std::string& inputPath, const std::string& cppOut) {
1116 std::ifstream input(inputPath, std::ios::binary);
1117 if (!input) {
1118 std::fprintf(stderr, "ipc_codegen: cannot open %s\n", inputPath.c_str());
1119 return false;
1120 }
1121 std::ostringstream buffer;
1122 buffer << input.rdbuf();
1123 const std::string source = buffer.str();
1124
1125 Lexer lexer(source, inputPath);
1126 Parser parser(lexer);
1127 File file = parser.parse();
1128
1129 const std::string header = stem(inputPath) + ".gen.h";
1130 const std::string outputPath = cppOut.empty() ? header : cppOut + "/" + header;
1131
1132 std::ostringstream generated;
1133 Emitter emitter(generated, file);
1134 emitter.emit(inputPath, header);
1135
1136 std::ofstream output(outputPath, std::ios::binary | std::ios::trunc);
1137 if (!output) {
1138 std::fprintf(stderr, "ipc_codegen: cannot write %s\n", outputPath.c_str());
1139 return false;
1140 }
1141 output << generated.str();
1142 if (!output) {
1143 std::fprintf(stderr, "ipc_codegen: failed to write %s\n", outputPath.c_str());
1144 return false;
1145 }
1146
1147 std::fprintf(stderr, "ipc_codegen: wrote %s (%zu interfaces)\n",
1148 outputPath.c_str(), file.interfaces.size());
1149 return true;
1150}
1151
1152} // namespace
1153

Callers 1

mainFunction · 0.85

Calls 5

stemFunction · 0.85
parseMethod · 0.80
emptyMethod · 0.80
emitMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected