Beispiel #1
0
    def get_instance(self, attributes: Dict[str, object], resolver: Resolver,
                     queue: QueueScheduler, location: Location) -> "Instance":
        """
            Return an instance of the class defined in this entity
        """
        out = Instance(self, resolver, queue)
        out.location = location
        for k, v in attributes.items():
            out.set_attribute(k, v, location)

        self.add_instance(out)
        return out
Beispiel #2
0
def test_slots_rt():
    ns = Namespace("root", None)
    rs = Resolver(ns)
    e = Entity("xx", ns)
    qs = QueueScheduler(None, [], [], None, set())
    r = RelationAttribute(e, None, "xx", Location("", 1))
    i = Instance(e, rs, qs)

    assert_slotted(ResultVariable())
    assert_slotted(AttributeVariable(None, None))
    assert_slotted(Promise(None, None))
    assert_slotted(ListVariable(r, i, qs))
    assert_slotted(OptionVariable(r, i, qs))

    assert_slotted(qs)
    assert_slotted(DelegateQueueScheduler(qs, None))

    assert_slotted(Waiter(qs))

    assert_slotted(
        ExecutionUnit(qs, r, ResultVariable(), {}, Literal(""), None))
    assert_slotted(HangUnit(qs, r, {}, None, Resumer()))
    assert_slotted(RawUnit(qs, r, {}, Resumer()))

    assert_slotted(FunctionUnit(qs, rs, ResultVariable(), {}, None))

    assert_slotted(i)
Beispiel #3
0
    def execute(self, requires: Dict[object, object], instance: Instance,
                queue: QueueScheduler) -> object:
        """
        Evaluate this statement
        """
        LOGGER.log(LOG_LEVEL_TRACE,
                   "executing subconstructor for %s implement %s", self.type,
                   self.implements.location)
        # this assertion is because the typing of this method is not correct
        # it should logically always hold, but we can't express this as types yet
        assert isinstance(instance, Instance)
        condition = self.implements.constraint.execute(requires, instance,
                                                       queue)
        try:
            inmanta_type.Bool().validate(condition)
        except RuntimeException as e:
            e.set_statement(self.implements)
            e.msg = (
                "Invalid value `%s`: the condition for a conditional implementation can only be a boolean expression"
                % condition)
            raise e
        if not condition:
            return None

        myqueue = queue.for_tracker(ImplementsTracker(self, instance))

        implementations = self.implements.implementations

        for impl in implementations:
            if instance.add_implementation(impl):
                # generate a subscope/namespace for each loop
                xc = ExecutionContext(
                    impl.statements,
                    instance.for_namespace(impl.statements.namespace))
                xc.emit(myqueue)

        return None
Beispiel #4
0
    def get_instance(
        self,
        attributes: Dict[str, object],
        resolver: Resolver,
        queue: QueueScheduler,
        location: Location,
        node: Optional[dataflow.InstanceNodeReference] = None,
    ) -> "Instance":
        """
        Return an instance of the class defined in this entity.
        If the corresponding node is not None, passes it on the instance.
        """
        out = Instance(self, resolver, queue, node)
        out.set_location(location)
        for k, v in attributes.items():
            out.set_attribute(k, v, location)

        self.add_instance(out)
        return out