def test_big_example(): mm = metamodel_for_language("item") assert mm is not None inpath = join(this_folder, "model") model = mm.model_from_file(join(inpath, "big_example.item")) assert model is not None outpath = join(this_folder, "src-gen") gen = generator_for_language_target("item", "cpp_v2") if exists(outpath): rmtree(outpath) mkdir(outpath) gen(mm, model, output_path=outpath, overwrite=True, debug=False) refpath = join(inpath, "ref") structs = get_children_of_type("Struct", model) enums = get_children_of_type("Enum", model) constants = get_children_of_type("Constants", model) for s in structs + enums + constants: outputfile = output_filename(refpath, s, "regex_ref") if exists(outputfile): check_file( filename=output_filename(outpath, s), regex_reference_filename=outputfile, )
def generate_cpp_for_struct(struct_obj, output_file, overwrite): if not exists(output_file) or (overwrite and obj_is_newer_than_file( struct_obj, output_file)): with open(output_file, "w") as f: f.write("#ifndef __{}_{}_H_V2\n".format( "_".join(get_package_names_of_obj(struct_obj)), struct_obj.name.upper(), )) f.write("#define __{}_{}_H_V2\n".format( "_".join(get_package_names_of_obj(struct_obj)), struct_obj.name.upper(), )) f.write("// ACTIVATE FOR SWIG\n") f.write("#include <cstdint>\n") f.write("#include <vector>\n") f.write("#include <array>\n") f.write("#include <variant>\n") f.write("#include <memory>\n") f.write("#include <stdexcept>\n") f.write("#include <type_traits>\n") f.write("\n") for r in get_referenced_elements_of_struct(struct_obj): f.write('#include "{}"\n'.format(output_filename(None, r))) f.write("\n") generate_cpp_struct(f, struct_obj) f.write("#endif // __{}_{}_H_V2\n".format( "_".join(get_package_names_of_obj(struct_obj)), struct_obj.name.upper(), ))
def generate_cpp_for_enum(enum_obj, output_file, overwrite): if not exists(output_file) or ( overwrite and obj_is_newer_than_file(enum_obj, output_file) ): with open(output_file, "w") as f: f.write( "#ifndef __{}_{}_H\n".format( "_".join(get_package_names_of_obj(enum_obj)), enum_obj.name.upper() ) ) f.write( "#define __{}_{}_H\n".format( "_".join(get_package_names_of_obj(enum_obj)), enum_obj.name.upper() ) ) f.write("// ACTIVATE FOR SWIG\n") f.write("#include <cstdint>\n") f.write("#include <iostream>\n") f.write("\n") for r in get_referenced_elements_of_enum(enum_obj): f.write('#include "{}"\n'.format(output_filename(None, r))) f.write("\n") generate_cpp_enum(f, enum_obj) f.write( "#endif // __{}_{}_H\n".format( "_".join(get_package_names_of_obj(enum_obj)), enum_obj.name.upper() ) )