Esempio n. 1
0
    def __init__(
        self,
        namespace: Namespace,
        name: LocatableString,
        target_type: LocatableString,
        statements: BasicBlock,
        comment: LocatableString,
    ):
        TypeDefinitionStatement.__init__(self, namespace, str(name))
        self.name = str(name)
        if "-" in self.name:
            inmanta_warnings.warn(HyphenDeprecationWarning(name))

        self.block = statements
        self.entity = target_type

        self.comment = None
        if comment is not None:
            self.comment = str(comment)

        self.location = name.get_location()

        self.type = Implementation(str(self.name), self.block, self.namespace, str(target_type), self.comment)
        self.type.location = name.get_location()
        self.anchors = [TypeReferenceAnchor(namespace, target_type)]
        self.anchors.extend(statements.get_anchors())
Esempio n. 2
0
 def __init__(
     self,
     entity_name: LocatableString,
     implementations: List[LocatableString],
     select: ExpressionStatement,
     inherit: bool = False,
     comment: LocatableString = None,
 ) -> None:
     DefinitionStatement.__init__(self)
     self.entity = entity_name
     self.entity_location = entity_name.get_location()
     self.implementations = implementations
     self.anchors = [
         TypeReferenceAnchor(x.namespace, x) for x in implementations
     ]
     self.anchors.append(
         TypeReferenceAnchor(entity_name.namespace, entity_name))
     self.anchors.extend(select.get_anchors())
     self.location = entity_name.get_location()
     if inherit and (not isinstance(select, Literal)
                     or select.value is not True):
         raise RuntimeException(
             self, "Conditional implementation with parents not allowed")
     self.select = select
     self.inherit: bool = inherit
     if comment is not None:
         self.comment = str(comment)
     else:
         self.comment = None
Esempio n. 3
0
 def __init__(
     self, namespace: Namespace, name: LocatableString, basetype: LocatableString, expression: ExpressionStatement
 ) -> None:
     TypeDefinitionStatement.__init__(self, namespace, str(name))
     self.set_location(name.get_location())
     self.basetype = basetype
     self.anchors.append(TypeReferenceAnchor(namespace, basetype))
     self.anchors.extend(expression.get_anchors())
     self.set_expression(expression)
     self.type = ConstraintType(self.namespace, str(name))
     self.type.location = name.get_location()
     self.comment = None
     if self.name in TYPES:
         inmanta_warnings.warn(CompilerRuntimeWarning(self, "Trying to override a built-in type: %s" % self.name))
     if "-" in self.name:
         inmanta_warnings.warn(HyphenDeprecationWarning(name))
Esempio n. 4
0
 def __init__(self, namespace: Namespace, name: LocatableString,
              class_ctor: Constructor):
     TypeDefinitionStatement.__init__(self, namespace, str(name))
     self.type = Default(namespace, self.name)
     self.ctor = class_ctor
     self.comment = None
     self.type.location = name.get_location()
     self.anchors.extend(class_ctor.get_anchors())
Esempio n. 5
0
 def __init__(self, namespace: Namespace, name: LocatableString, class_ctor: Constructor):
     TypeDefinitionStatement.__init__(self, namespace, str(name))
     self.type = Default(namespace, self.name)
     self.ctor = class_ctor
     self.comment = None
     self.type.location = name.get_location()
     self.anchors.extend(class_ctor.get_anchors())
     if "-" in self.name:
         inmanta_warnings.warn(HyphenDeprecationWarning(name))
Esempio n. 6
0
 def __init__(self, variable: ExpressionStatement,
              loop_var: LocatableString, module: BasicBlock) -> None:
     super().__init__()
     self.base = variable
     self.loop_var = str(loop_var)
     self.loop_var_loc = loop_var.get_location()
     self.module = module
     self.anchors.extend(module.get_anchors())
     self.anchors.extend(variable.get_anchors())
Esempio n. 7
0
 def add_attribute(self, lname: LocatableString,
                   value: ExpressionStatement) -> None:
     """
     Add an attribute to this constructor call
     """
     name = str(lname)
     if name not in self.__attributes:
         self.__attributes[name] = value
         self.anchors.append(
             AttributeReferenceAnchor(lname.get_location(), lname.namespace,
                                      self.class_type, name))
         self.anchors.extend(value.get_anchors())
     else:
         raise RuntimeException(
             self,
             "The attribute %s in the constructor call of %s is already set."
             % (name, self.class_type))