Exemplo n.º 1
0
 def declare_global(self,
                    type_spaced: str,
                    name: str,
                    static: bool = True,
                    initializer: Optional[str] = None) -> None:
     initializer_body = '' if not initializer else ' = {}'.format(
         initializer)
     static_str = 'static ' if static else ''
     if name not in self.context.declarations:
         self.context.declarations[name] = HeaderDeclaration(
             set(),
             [
                 '{}{}{}{};'.format(static_str, type_spaced, name,
                                    initializer_body)
             ],
         )
Exemplo n.º 2
0
def generate_object_struct(cl: ClassIR, emitter: Emitter) -> None:
    seen_attrs = set()  # type: Set[Tuple[str, RType]]
    lines = []  # type: List[str]
    lines += ['typedef struct {', 'PyObject_HEAD', 'CPyVTableItem *vtable;']
    for base in reversed(cl.base_mro):
        if not base.is_trait:
            for attr, rtype in base.attributes.items():
                if (attr, rtype) not in seen_attrs:
                    lines.append('{}{};'.format(emitter.ctype_spaced(rtype),
                                                emitter.attr(attr)))
                    seen_attrs.add((attr, rtype))

                    if isinstance(rtype, RTuple):
                        emitter.declare_tuple_struct(rtype)

    lines.append('}} {};'.format(cl.struct_name(emitter.names)))
    lines.append('')
    emitter.context.declarations[cl.struct_name(
        emitter.names)] = HeaderDeclaration(lines, is_type=True)
Exemplo n.º 3
0
def generate_function_declaration(fn: FuncIR, emitter: Emitter) -> None:
    emitter.context.declarations[emitter.native_function_name(fn.decl)] = HeaderDeclaration(
        '{};'.format(native_function_header(fn.decl, emitter)))
    if fn.name != TOP_LEVEL_NAME:
        emitter.context.declarations[PREFIX + fn.cname(emitter.names)] = HeaderDeclaration(
            '{};'.format(wrapper_function_header(fn, emitter.names)))