def work(filename):
    schema = ExpressReader.read(filename,silent=True)
    entities, stub_decls, schema_table, converters, typedefs, predefs = '','',[],'','',''

    
    whitelist = []
    with open('entitylist.txt', 'rt') as inp:
        whitelist = [n.strip() for n in inp.read().split('\n') if n[:1]!='#' and n.strip()]

    schema.whitelist = set()
    schema.blacklist_partial = set()
    for ename in whitelist:
        try:
            e = schema.entities[ename]
        except KeyError:
            # type, not entity
            continue
        for base in [e.name]+get_base_classes(e,schema):
            schema.whitelist.add(base)
        for base in get_derived(e,schema):
            schema.blacklist_partial.add(base)

    schema.blacklist_partial -= schema.whitelist
    schema.whitelist |= schema.blacklist_partial

    # uncomment this to disable automatic code reduction based on whitelisting all used entities
    # (blacklisted entities are those who are in the whitelist and may be instanced, but will
    # only be accessed through a pointer to a base-class.
    #schema.whitelist = set(schema.entities.keys())
    #schema.blacklist_partial = set()

    for ntype in schema.types.values():
        typedefs += gen_type_struct(ntype,schema)
        schema_table.append(template_schema_type.format(normalized_name=ntype.name.lower()))

    sorted_entities = sort_entity_list(schema)
    for entity in sorted_entities:
        parent = entity.parent+',' if entity.parent else ''

        if entity.name in schema.whitelist:
            converters += template_converter.format(type=entity.name,contents=gen_converter(entity,schema))
            schema_table.append(template_schema.format(type=entity.name,normalized_name=entity.name.lower(),argcnt=len(entity.members)))
            entities += template_entity.format(entity=entity.name,argcnt=len(entity.members),parent=parent,fields=generate_fields(entity,schema))
            predefs += template_entity_predef.format(entity=entity.name)
            stub_decls += template_stub_decl.format(type=entity.name)
        else:
            entities += template_entity_ni.format(entity=entity.name)
            predefs += template_entity_predef_ni.format(entity=entity.name)
            schema_table.append(template_schema.format(type="NotImplemented",normalized_name=entity.name.lower(),argcnt=0))

    schema_table = ','.join(schema_table)

    with open(input_template_h,'rt') as inp:
        with open(output_file_h,'wt') as outp:
            # can't use format() here since the C++ code templates contain single, unescaped curly brackets
            outp.write(inp.read().replace('{predefs}',predefs).replace('{types}',typedefs).replace('{entities}',entities).replace('{converter-decl}',stub_decls))
    
    with open(input_template_cpp,'rt') as inp:
        with open(output_file_cpp,'wt') as outp:
            outp.write(inp.read().replace('{schema-static-table}',schema_table).replace('{converter-impl}',converters))
Exemplo n.º 2
0
def work(filename):
    schema = ExpressReader.read(filename,silent=True)
    entities, stub_decls, schema_table, converters, typedefs, predefs = '','',[],'','',''

    
    whitelist = []
    with open('entitylist.txt', 'rt') as inp:
        whitelist = [n.strip() for n in inp.read().split('\n') if n[:1]!='#' and n.strip()]

    schema.whitelist = set()
    schema.blacklist_partial = set()
    for ename in whitelist:
        try:
            e = schema.entities[ename]
        except KeyError:
            # type, not entity
            continue
        for base in [e.name]+get_base_classes(e,schema):
            schema.whitelist.add(base)
        for base in get_derived(e,schema):
            schema.blacklist_partial.add(base)

    schema.blacklist_partial -= schema.whitelist
    schema.whitelist |= schema.blacklist_partial

    # uncomment this to disable automatic code reduction based on whitelisting all used entities
    # (blacklisted entities are those who are in the whitelist and may be instanced, but will
    # only be accessed through a pointer to a base-class.
    #schema.whitelist = set(schema.entities.keys())
    #schema.blacklist_partial = set()

    for ntype in schema.types.values():
        typedefs += gen_type_struct(ntype,schema)
        schema_table.append(template_schema_type.format(normalized_name=ntype.name.lower()))

    sorted_entities = sort_entity_list(schema)
    for entity in sorted_entities:
        parent = entity.parent+',' if entity.parent else ''

        if entity.name in schema.whitelist:
            converters += template_converter.format(type=entity.name,contents=gen_converter(entity,schema))
            schema_table.append(template_schema.format(type=entity.name,normalized_name=entity.name.lower(),argcnt=len(entity.members)))
            entities += template_entity.format(entity=entity.name,argcnt=len(entity.members),parent=parent,fields=generate_fields(entity,schema))
            predefs += template_entity_predef.format(entity=entity.name)
            stub_decls += template_stub_decl.format(type=entity.name)
        else:
            entities += template_entity_ni.format(entity=entity.name)
            predefs += template_entity_predef_ni.format(entity=entity.name)
            schema_table.append(template_schema.format(type="NotImplemented",normalized_name=entity.name.lower(),argcnt=0))

    schema_table = ','.join(schema_table)

    with open(input_template_h,'rt') as inp:
        with open(output_file_h,'wt') as outp:
            # can't use format() here since the C++ code templates contain single, unescaped curly brackets
            outp.write(inp.read().replace('{predefs}',predefs).replace('{types}',typedefs).replace('{entities}',entities).replace('{converter-decl}',stub_decls))
    
    with open(input_template_cpp,'rt') as inp:
        with open(output_file_cpp,'wt') as outp:
            outp.write(inp.read().replace('{schema-static-table}',schema_table).replace('{converter-impl}',converters))
Exemplo n.º 3
0
def work(filename):
    schema = ExpressReader.read(filename, silent=True)
    entities, converters, header = '', '', ''

    whitelist = []
    with open('metalist.txt', 'rt') as inp:
        whitelist = [
            n.strip() for n in inp.read().split('\n')
            if n[:1] != '#' and n.strip()
        ]

    schema.whitelist = set()
    schema.blacklist_partial = set()
    for ename in whitelist:
        try:
            e = schema.entities[ename]
        except KeyError:
            # type, not entity
            continue
        for base in [e.name]:
            schema.whitelist.add(base)

    schema.blacklist_partial -= schema.whitelist
    schema.whitelist |= schema.blacklist_partial

    # uncomment this to disable automatic code reduction based on whitelisting all used entities
    # (blacklisted entities are those who are in the whitelist and may be instanced, but will
    # only be accessed through a pointer to a base-class.
    #schema.whitelist = set(schema.entities.keys())
    #schema.blacklist_partial = set()
    sorted_entities = sort_entity_list(schema)

    for entity in sorted_entities:
        parent = entity.parent + ',' if entity.parent else ''

        if entity.name in schema.whitelist:
            converters += template_converter.format(type=entity.name,
                                                    contents=gen_converter(
                                                        entity, schema))
            header += template_header.format(type=entity.name)

    with open(input_template_h, 'rt') as inp:
        with open(output_file_h, 'wt') as outp:
            # can't use format() here since the C++ code templates contain single, unescaped curly brackets
            outp.write(inp.read().replace('{converter-decl}', header))

    with open(input_template_cpp, 'rt') as inp:
        with open(output_file_cpp, 'wt') as outp:
            outp.write(inp.read().replace('{converter-impl}', converters))
Exemplo n.º 4
0
def work(filename):
    schema = ExpressReader.read(filename,silent=True)
    entities, converters, header = '','',''

    whitelist = []
    with open('metalist.txt', 'rt') as inp:
        whitelist = [n.strip() for n in inp.read().split('\n') if n[:1]!='#' and n.strip()]

    schema.whitelist = set()
    schema.blacklist_partial = set()
    for ename in whitelist:
        try:
            e = schema.entities[ename]
        except KeyError:
            # type, not entity
            continue
        for base in [e.name]:
            schema.whitelist.add(base)

    schema.blacklist_partial -= schema.whitelist
    schema.whitelist |= schema.blacklist_partial

    # uncomment this to disable automatic code reduction based on whitelisting all used entities
    # (blacklisted entities are those who are in the whitelist and may be instanced, but will
    # only be accessed through a pointer to a base-class.
    #schema.whitelist = set(schema.entities.keys())
    #schema.blacklist_partial = set()
    sorted_entities = sort_entity_list(schema)

    for entity in sorted_entities:
        parent = entity.parent+',' if entity.parent else ''

        if entity.name in schema.whitelist:
            converters += template_converter.format(type=entity.name,contents=gen_converter(entity,schema))
            header += template_header.format(type=entity.name)

    with open(input_template_h,'rt') as inp:
        with open(output_file_h,'wt') as outp:
            # can't use format() here since the C++ code templates contain single, unescaped curly brackets
            outp.write(inp.read().replace('{converter-decl}', header))

    with open(input_template_cpp,'rt') as inp:
        with open(output_file_cpp,'wt') as outp:
            outp.write(inp.read().replace('{converter-impl}',converters))