示例#1
0
    def __init__(self, method: MethodDefinition, thing: ThingDefinition):
        super(IndexerContext, self).__init__()

        self.current_method = method
        self.locals = OrderedDict({Identifier.self(): LocalMember(thing.name, 0, 'self', not method.static)})

        # Note: this keeps the first slot reserved for self, even in a static method

        for arg in method.arguments:
            self.locals[arg] = LocalMember(arg.type, len(self.locals), 'argument', True)
示例#2
0
    def finalize(self):
        if not self.is_constructor():
            return super().finalize()

        for descendant in self.descendants:
            if isinstance(
                    descendant,
                    MethodCall) and descendant.target[0] == Identifier.super():
                descendant.replace(
                    AssignmentOperation(
                        AssignmentOperation.REASSIGNMENT,
                        NamedAccess([Identifier.self(),
                                     Identifier.super()]),
                        MethodCall(NamedAccess(
                            [self.parent.extends,
                             Identifier.constructor()]),
                                   descendant.arguments,
                                   is_captured=True).deriving_from(
                                       self)).deriving_from(descendant))

        super().finalize()