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())
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())
def graph() -> Iterator[DataflowGraph]: namespace: Namespace = Namespace("dummy_namespace") resolver: Resolver = Resolver(namespace, enable_dataflow_graph=True) block: BasicBlock = BasicBlock(namespace, []) xc: ExecutionContext = ExecutionContext(block, resolver) block.namespace.scope = xc yield DataflowGraph(resolver)
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())
def p_implementation_def(p: YaccProduction) -> None: "implementation_def : IMPLEMENTATION ID FOR class_ref implementation" assert namespace docstr, stmts = p[5] p[0] = DefineImplementation(namespace, p[2], p[4], BasicBlock(namespace, stmts), docstr)
def p_if_elif(p: YaccProduction) -> None: "if_next : ELIF if_body" assert namespace p[0] = BasicBlock(namespace, [p[2]]) attach_lnr(p, 1)
def p_if_else(p: YaccProduction) -> None: "if_next : ELSE ':' stmt_list" assert namespace p[0] = BasicBlock(namespace, p[3])
def p_if_end(p: YaccProduction) -> None: "if_next : empty" assert namespace p[0] = BasicBlock(namespace, [])
def p_if_body(p: YaccProduction) -> None: "if_body : expression ':' stmt_list if_next" assert namespace p[0] = If(p[1], BasicBlock(namespace, p[3]), p[4]) attach_lnr(p, 2)
def p_for(p: YaccProduction) -> None: "for : FOR ID IN operand ':' block" assert namespace p[0] = For(p[4], p[2], BasicBlock(namespace, p[6])) attach_lnr(p, 1)
def p_implementation_def(p): "implementation_def : IMPLEMENTATION ID FOR class_ref implementation" docstr, stmts = p[5] p[0] = DefineImplementation(namespace, p[2], p[4], BasicBlock(namespace, stmts), docstr) attach_lnr(p)
def p_for(p): "for : FOR ID IN operand ':' block" p[0] = For(p[4], p[2], BasicBlock(namespace, p[6])) attach_lnr(p, 1)
def p_if_else(p: YaccProduction) -> None: "if : IF expression ':' stmt_list ELSE ':' block" p[0] = If(p[2], BasicBlock(namespace, p[4]), BasicBlock(namespace, p[7])) attach_lnr(p, 1)
def p_if(p: YaccProduction) -> None: "if : IF expression ':' block" p[0] = If(p[2], BasicBlock(namespace, p[4]), BasicBlock(namespace, [])) attach_lnr(p, 1)