Пример #1
0
    def __init__(self,
                 entity: "Entity",
                 value_type: "Type",
                 name: str,
                 location: Location,
                 multi: bool = False,
                 nullable: bool = False) -> None:
        Locatable.__init__(self)
        self.location = location
        self.__name: str = name
        entity.add_attribute(self)
        self.__entity = entity
        self.__multi = multi
        self.__nullable = nullable

        self.__type: Type = value_type
        if multi:
            self.__type = TypedList(self.__type)
        if nullable:
            self.__type = NullableType(self.__type)

        self.low: int = 0 if nullable else 1
        # This attribute is only used for the DeprecatedOptionVariable
        self.high: Optional[int] = None
        self.comment = None  # type: Optional[str]
        self.end: Optional[RelationAttribute] = None
Пример #2
0
    def __init__(
        self,
        mytype: "Entity",
        resolver: Resolver,
        queue: QueueScheduler,
        node: Optional["dataflow.InstanceNodeReference"] = None,
    ) -> None:
        Locatable.__init__(self)
        # ExecutionContext, Resolver -> this class only uses it as an "interface", so no constructor call!
        self.resolver = resolver.get_root_resolver()
        self.type = mytype
        self.slots: Dict[str, ResultVariable] = {}
        for attr_name in mytype.get_all_attribute_names():
            if attr_name in self.slots:
                # prune duplicates because get_new_result_variable() has side effects
                # don't use set for pruning because side effects drive control flow and set iteration is nondeterministic
                continue
            attribute = mytype.get_attribute(attr_name)
            assert attribute is not None  # Make mypy happy
            self.slots[attr_name] = attribute.get_new_result_variable(
                self, queue)
        # TODO: this is somewhat ugly. Is there a cleaner way to enforce this constraint
        assert (resolver.dataflow_graph is None) == (node is None)
        self.dataflow_graph: Optional[DataflowGraph] = None
        self.instance_node: Optional[dataflow.InstanceNodeReference] = node
        if self.instance_node is not None:
            self.dataflow_graph = DataflowGraph(self, resolver.dataflow_graph)
            for name, var in self.slots.items():
                var.set_dataflow_node(
                    dataflow.InstanceAttributeNodeReference(
                        self.instance_node.top_node(), name))

        self.slots["self"] = ResultVariable()
        self.slots["self"].set_value(self, None)
        if self.instance_node is not None:
            self_var_node: dataflow.AssignableNodeReference = dataflow.AssignableNode(
                "__self__").reference()
            self_var_node.assign(self.instance_node, self,
                                 cast(DataflowGraph, self.dataflow_graph))
            self.slots["self"].set_dataflow_node(self_var_node)

        self.sid = id(self)
        self.implementations: "Set[Implementation]" = set()

        # see inmanta.ast.execute.scheduler.QueueScheduler
        self.trackers: List[Tracker] = []

        self.locations: List[Location] = []
Пример #3
0
 def get_location(self) -> Location:
     return Locatable.get_location(self)
Пример #4
0
 def set_location(self, location: Location) -> None:
     Locatable.set_location(self, location)
     self.locations.append(location)
Пример #5
0
def location(obj: Locatable) -> model.Location:
    loc = obj.get_location()
    return model.Location(loc.file, loc.lnr)
Пример #6
0
 def copy_location(self, statement: Locatable) -> None:
     """
         Copy the location of this statement in the given statement
     """
     statement.location = self.location
Пример #7
0
 def __init__(self) -> None:
     Locatable.__init__(self)
     self.constraint = None  # type: ExpressionStatement
     self.implementations = []  # type: List[Implementation]
     self.comment = None  # type: str
     self.normalized = False