Esempio n. 1
0
 def __init__(self, condition: ExpressionStatement,
              if_expression: ExpressionStatement,
              else_expression: ExpressionStatement) -> None:
     super().__init__()
     self.condition: ExpressionStatement = condition
     self.if_expression: ExpressionStatement = if_expression
     self.else_expression: ExpressionStatement = else_expression
     self.anchors.extend(condition.get_anchors())
     self.anchors.extend(if_expression.get_anchors())
     self.anchors.extend(else_expression.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, condition: ExpressionStatement, if_branch: BasicBlock,
              else_branch: BasicBlock) -> None:
     super().__init__()
     self.condition: ExpressionStatement = condition
     self.if_branch: BasicBlock = if_branch
     self.else_branch: BasicBlock = else_branch
     self.anchors.extend(condition.get_anchors())
     self.anchors.extend(if_branch.get_anchors())
     self.anchors.extend(else_branch.get_anchors())
Esempio n. 4
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. 5
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. 6
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))
Esempio n. 7
0
    def set_expression(self, expression: ExpressionStatement) -> None:
        """
        Set the expression that constrains the basetype. This expression
        should reference the value that will be assign to a variable of this
        type. This variable has the same name as the type.
        """
        contains_var = False

        if hasattr(expression, "arguments"):
            # some sort of function call
            expression = Equals(expression, Literal(True))

        for var in expression.requires():
            if var == self.name or var == "self":
                contains_var = True

        if not contains_var:
            raise TypingException(self, "typedef expressions should reference the self variable")

        self.__expression = expression
Esempio n. 8
0
 def __init__(self, name: LocatableString) -> None:
     ExpressionStatement.__init__(self)
     self.name = str(name)
     self.full_name = str(name)
Esempio n. 9
0
 def __init__(self, themap: ExpressionStatement, key: ExpressionStatement):
     super(MapLookup, self).__init__([themap, key])
     self.themap = themap
     self.key = key
     self.location = themap.get_location().merge(key.location)