MCPcopy Create free account
hub / github.com/coi/coi / generate_cpp_code

Function generate_cpp_code

src/codegen/codegen.cc:8–432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6#include <iostream>
7
8void generate_cpp_code(
9 std::ostream &out,
10 std::vector<Component> &all_components,
11 const std::vector<std::unique_ptr<DataDef>> &all_global_data,
12 const std::vector<std::unique_ptr<EnumDef>> &all_global_enums,
13 const AppConfig &final_app_config,
14 const std::set<std::string> &required_headers,
15 const FeatureFlags &features)
16{
17 // Include required headers
18 for (const auto &header : required_headers)
19 {
20 out << "#include \"webcc/" << header << ".h\"\n";
21 }
22 out << "#include \"webcc/core/function.h\"\n";
23 out << "#include \"webcc/core/allocator.h\"\n";
24 out << "#include \"webcc/core/new.h\"\n";
25 out << "#include \"webcc/core/string.h\"\n";
26 out << "#include \"webcc/core/array.h\"\n";
27 out << "#include \"webcc/core/vector.h\"\n";
28 out << "#include \"webcc/core/unordered_map.h\"\n";
29 out << "#include \"webcc/core/random.h\"\n";
30 out << "#include \"webcc/core/math.h\"\n";
31 out << "\n";
32 out << "namespace coi {\n";
33 out << "using string = webcc::string;\n";
34 out << "using string_view = webcc::string_view;\n";
35 out << "template<typename T> using vector = webcc::vector<T>;\n";
36 out << "template<typename T, size_t N> using array = webcc::array<T, N>;\n";
37 out << "template<typename K, typename V> using map = webcc::unordered_map<K, V>;\n";
38 out << "template<typename Signature> using function = webcc::function<Signature>;\n";
39 out << "using webcc::move;\n";
40 out << "using webcc::malloc;\n";
41 out << "namespace math {\n";
42 out << "inline constexpr float PI = webcc::PI;\n";
43 out << "inline constexpr float HALF_PI = webcc::HALF_PI;\n";
44 out << "inline constexpr float TAU = webcc::TAU;\n";
45 out << "inline constexpr float DEG2RAD = webcc::DEG2RAD;\n";
46 out << "inline constexpr float RAD2DEG = webcc::RAD2DEG;\n";
47 out << "inline float abs(float x) { return webcc::abs(x); }\n";
48 out << "inline float sqrt(float x) { return webcc::sqrt(x); }\n";
49 out << "inline float sin(float x) { return webcc::sin(x); }\n";
50 out << "inline float cos(float x) { return webcc::cos(x); }\n";
51 out << "inline float tan(float x) { return webcc::tan(x); }\n";
52 out << "}\n";
53 out << "// Cast helpers backing the builtin toInt/toFloat/toString methods.\n";
54 out << "// Overloaded so one inline template stays valid for any receiver type.\n";
55 out << "inline int to_int(const string& s) { return s.to_int(); }\n";
56 out << "inline int to_int(double v) { return (int)v; }\n";
57 out << "inline int to_int(float v) { return (int)v; }\n";
58 out << "inline int to_int(int v) { return v; }\n";
59 out << "inline int to_int(unsigned int v) { return (int)v; }\n";
60 out << "inline int to_int(long v) { return (int)v; }\n";
61 out << "inline int to_int(unsigned long v) { return (int)v; }\n";
62 out << "inline int to_int(long long v) { return (int)v; }\n";
63 out << "inline int to_int(unsigned long long v) { return (int)v; }\n";
64 out << "inline double to_float(const string& s) { return s.to_float(); }\n";
65 out << "inline double to_float(double v) { return v; }\n";

Callers 1

mainFunction · 0.85

Calls 14

emit_json_runtimeFunction · 0.85
qualified_nameFunction · 0.85
needs_dispatcherFunction · 0.85
emit_feature_globalsFunction · 0.85
convert_typeFunction · 0.85
generate_meta_structFunction · 0.85
emit_feature_initFunction · 0.85
register_typeMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected