def process(nodes): def warn(things): print(things) nodes, _ = model.evaluate_model(nodes, warn) CppGenerator().check_nodes(nodes) return nodes
def main(): opts = options.parse_options() if opts.version: print "prophyc {}".format(__version__) sys.exit(0) if not opts.input_files: sys.exit("prophyc: error: missing input file") if opts.isar: from prophyc.parsers.isar import IsarParser parser = IsarParser() parse_error = None elif opts.sack: if not module_exists("clang"): sys.exit("Sack input requires clang and it's not installed") from prophyc.parsers.sack import SackParser parser = SackParser(opts.include_dirs) parse_error = None else: from prophyc.parsers.prophy import ProphyParser, ParseError parser = ProphyParser() parse_error = ParseError serializers = [] if opts.python_out: from prophyc.generators.python import PythonGenerator serializers.append(PythonGenerator(opts.python_out)) if opts.cpp_out: from prophyc.generators.cpp import CppGenerator serializers.append(CppGenerator(opts.cpp_out)) if not serializers: sys.exit("Missing output directives") for input_file in opts.input_files: try: nodes = parser.parse(input_file) except parse_error as e: sys.exit('\n'.join(e.errors)) if opts.patch: from prophyc import patch patches = patch.parse(opts.patch) patch.patch(nodes, patches) model.topological_sort(nodes) model.cross_reference(nodes) model.evaluate_kinds(nodes) for serializer in serializers: basename = get_basename(input_file) serializer.serialize(nodes, basename)
def get_serializers(opts): serializers = [] if opts.python_out: from prophyc.generators.python import PythonGenerator serializers.append(PythonGenerator(opts.python_out)) if opts.cpp_out: from prophyc.generators.cpp import CppGenerator serializers.append(CppGenerator(opts.cpp_out)) if opts.cpp_full_out: from prophyc.generators.cpp_full import CppFullGenerator serializers.append(CppFullGenerator(opts.cpp_full_out)) return serializers
def generate_definitions(nodes): process_nodes(nodes) return CppGenerator().generate_definitions(nodes)
def generate_cpp(nodes, basename): process_nodes(nodes) return CppGenerator().serialize_string_cpp(nodes, basename)
def generate_swap(nodes): process_nodes(nodes) return CppGenerator().generate_swap(nodes)
def generate_cpp(nodes, basename): return CppGenerator().serialize_string_cpp(nodes, basename)
def generate_swap(nodes): return CppGenerator().generate_swap(nodes)
def generate_swap_declarations(nodes): return CppGenerator().generate_swap_declarations(nodes)
def generate_definitions(nodes): return CppGenerator().generate_definitions(nodes)
def test_struct_size_error(): nodes = [model.Struct('X', [model.StructMember('x', 'Unknown')])] with pytest.raises(GenerateError) as e: CppGenerator().check_nodes(nodes) assert "X byte size unknown" == str(e.value)