Esempio n. 1
0
def create_body(stripped_file_content):
    escape_newlines = lambda line: replace(line, [
        (r'\n', '\\\n'),
    ])
    for prefix, body, suffix in create_body_variants(stripped_file_content):
        yield [
            prefix,
        ], True
        declarations = map(parsing.parse_declaration,
                           parsing.declaration_blocks(body))
        updated_declarations = zip(
            *list(update_all_declarations(declarations)))
        macro_define = create_c_macro_def(zip(*declarations)[1])
        interface = ((macro_define % impl.INTERFACE, ) +
                     updated_declarations[1])
        yield map(escape_newlines, interface), updated_declarations[0]

        new_implementations = filter(
            None, map(create_implementation,
                      *zip(*declarations)[:3]))
        imp_block = [
            macro_define % impl.IMPLEMENTATION,
        ] + impl.ignore(new_implementations, impl.w_incomplete)
        yield map(escape_newlines, imp_block), False
        yield [
            suffix,
        ], True
Esempio n. 2
0
def update_all_declarations(parsed_declarations):
	"""Apply regexes to an @interface ... @end declaration block to replace class names of objects, keys, ..."""
	updated_bodies = {}
	for decl_type, cls, category, superclass, protocols, body in parsed_declarations:
		decl_header = ''.join(create_declaration_header(decl_type, cls, category, superclass, protocols))
		updated_body = replace(body, subs.substitutions_for([cls, superclass]))
		if superclass in updated_bodies:
			wrapped = impl.ignore([updated_bodies[superclass], ], impl.w_duplicate)
			updated_body += impl.super_declaration_start % superclass + '\n'.join(wrapped)
		updated_bodies[cls] = updated_bodies.get(cls, '') + updated_body
		
		yield decl_header, decl_header + '\n' + updated_body + '@end;\n'
Esempio n. 3
0
def create_body(stripped_file_content):
	escape_newlines = lambda line: replace(line, [(r'\n', '\\\n'), ])
	for prefix, body, suffix in create_body_variants(stripped_file_content):
		yield [prefix, ], True
		declarations = map(parsing.parse_declaration, parsing.declaration_blocks(body))
		updated_declarations = zip(*list(update_all_declarations(declarations)))
		macro_define = create_c_macro_def(zip(*declarations)[1])
		interface = ((macro_define % impl.INTERFACE, ) + updated_declarations[1])
		yield map(escape_newlines, interface), updated_declarations[0]

		new_implementations = filter(None, map(create_implementation, *zip(*declarations)[:3]))
		imp_block = [macro_define % impl.IMPLEMENTATION, ] + impl.ignore(new_implementations, impl.w_incomplete)
		yield map(escape_newlines, imp_block), False
		yield [suffix, ], True
Esempio n. 4
0
def update_all_declarations(parsed_declarations):
    """Apply regexes to an @interface ... @end declaration block to replace class names of objects, keys, ..."""
    updated_bodies = {}
    for decl_type, cls, category, superclass, protocols, body in parsed_declarations:
        decl_header = ''.join(
            create_declaration_header(decl_type, cls, category, superclass,
                                      protocols))
        updated_body = replace(body, subs.substitutions_for([cls, superclass]))
        if superclass in updated_bodies:
            wrapped = impl.ignore([
                updated_bodies[superclass],
            ], impl.w_duplicate)
            updated_body += impl.super_declaration_start % superclass + '\n'.join(
                wrapped)
        updated_bodies[cls] = updated_bodies.get(cls, '') + updated_body

        yield decl_header, decl_header + '\n' + updated_body + '@end;\n'