Exemple #1
0
def lower_var_stmts(stmts):
    for idx, stmt in enumerate(stmts):
        if isinstance(stmt, VarAction):
            lhs = stmt.args[0]
            rhs = stmt.args[1] if len(stmt.args) > 1 else None
            lsym = lhs.prefix('loc:')
            subst = {lhs.rep: lsym.rep}
            lines = lower_var_stmts(stmts[idx + 1:])
            lines = [
                subst_prefix_atoms_ast(s, subst, None, None) for s in lines
            ]
            if rhs is not None:
                asgn = AssignAction(lsym, rhs)
                asgn.lineno = stmt.lineno
            else:
                asgn = lsym
            body = Sequence(*lines)
            body.lineno = stmt.lineno
            res = LocalAction(*[asgn, body])
            res.lineno = body.lineno
            return stmts[:idx] + [res]
    return stmts
Exemple #2
0
def p_action_term_assign_fmla(p):
    "action : term ASSIGN fmla"
    p[0] = AssignAction(p[1], p[3])
    p[0].lineno = get_lineno(p, 2)
Exemple #3
0
def p_action_term_assign_fmla(p):
    'action : term ASSIGN fmla'
    p[0] = AssignAction(p[1], p[3])
    p[0].lineno = get_lineno(p, 2)
Exemple #4
0
def p_action_term_assign_fmla(p):
    'action : term ASSIGN fmla'
    p[0] = AssignAction(p[1],p[3])
    p[0].lineno = p.lineno(2)
Exemple #5
0
 def scenario(self, scen):
     init_tokens = set(p.rep for p in scen.args[0].args)
     transs_by_action = defaultdict(list)
     for tr in scen.args[1:]:
         transs_by_action[tr.args[2].args[1].args[0].rep].append(tr)
     for (place_name, lineno) in scen.places():
         sym = find_symbol(place_name)
         iname = place_name + '[init]'
         iact = AssignAction(
             sym,
             ivy_logic.And() if
             (place_name in init_tokens) else ivy_logic.Or())
         iact.formal_params = []
         iact.formal_returns = []
         iact.lineno = scen.lineno
         self.mod.actions[iname] = iact
         self.mixin(
             ivy_ast.MixinAfterDef(ivy_ast.Atom(iname),
                                   ivy_ast.Atom('init')))
     for actname, trs in transs_by_action.iteritems():
         choices = []
         params = None
         afters = []
         for tr in trs:
             scmix = tr.args[2]
             is_after = isinstance(scmix, ivy_ast.ScenarioAfterMixin)
             df = scmix.args[1]
             body = compile_action_def(df, self.mod.sig)
             seq = []
             if not is_after:
                 for p in tr.args[0].args:
                     seq.append(AssumeAction(find_symbol(p.rep)))
                 for p in tr.args[0].args:
                     seq.append(
                         AssignAction(find_symbol(p.rep), ivy_logic.Or()))
                 for p in tr.args[1].args:
                     seq.append(
                         AssignAction(find_symbol(p.rep), ivy_logic.And()))
                 seq.append(body)
                 seq = Sequence(*seq)
             else:
                 for p in tr.args[0].args:
                     seq.append(
                         AssignAction(find_symbol(p.rep), ivy_logic.Or()))
                 for p in tr.args[1].args:
                     seq.append(
                         AssignAction(find_symbol(p.rep), ivy_logic.And()))
                 seq.append(body)
                 seq = Sequence(*seq)
                 seq = IfAction(
                     And(*[find_symbol(p.rep) for p in tr.args[0].args]),
                     seq)
             if params is None:
                 params = body.formal_params
                 returns = body.formal_returns
                 mixer = scmix.args[0]
                 mixee = scmix.args[1].args[0]
             else:
                 aparams = df.formal_params + df.formal_returns
                 subst = dict(zip(aparams, params + returns))
                 seq = substitute_constants_ast(seq, subst)
             seq.lineno = tr.lineno
             if not is_after:
                 choices.append(seq)
             else:
                 afters.append(seq)
         if choices:
             choice = BalancedChoice(choices)
             choice.lineno = choices[0].lineno
             choice.formal_params = params
             choice.formal_returns = returns
             self.mod.actions[mixer.rep] = choice
             self.mixin(ivy_ast.MixinBeforeDef(mixer, mixee))
         if afters:
             choice = Sequence(*afters)
             choice.lineno = afters[0].lineno
             choice.formal_params = params
             choice.formal_returns = returns
             self.mod.actions[mixer.rep] = choice
             self.mixin(ivy_ast.MixinAfterDef(mixer, mixee))