Exemple #1
0
def run_forall(rhandler, request, exec_module):
    domain_map = request[1].resolve(rhandler.C)
    sub_request = request[2]
    variables = []
    choices = []
    for var_choice in domain_map:
        variables.append(var_choice.get_key())
        domain = rhandler.eval.apply(var_choice.get_value())
        domain_list = []
        for v in domain:
            domain_list.append(v)
        # domain.add_all_to(domain_list)
        choices.append(domain_list)
    if rhandler.verbose:
        Logger.msg(rhandler.name, "forall choices: " + str(choices))
    combos = ComboIterator(choices)
    s = Substitution()
    for combo in combos:
        for i in range(len(combo)):
            s.add(variables[i], combo[i])

        sub_req_inst = sub_request.substitute(s)
        if rhandler.verbose:
            Logger.msg(rhandler.name, "calling: " + str(sub_req_inst))
            Logger.inc_depth()
        rhandler.satisfy_request(sub_req_inst, exec_module)
        if rhandler.verbose:
            Logger.dec_depth()
Exemple #2
0
    def get_matching_entries(self, modulePattern, typePattern, namePattern):
        r = []
        for m in self.moduleList:
            s_base = None
            if modulePattern is not None:
                s_base = modulePattern.match(m.get_name())
            else:
                s_base = Substitution()
            if s_base is not None:
                for e in m.get_entries():
                    s = s_base.copy()

                    if typePattern is not None:
                        s_tmp = typePattern.match(e.get_type())
                        if s_tmp is None or not s.add_substitution(s_tmp):
                            continue
                    if namePattern is not None:
                        s_tmp = namePattern.match(e.get_name())
                        if s_tmp is None or not s.add_substitution(s_tmp):
                            continue
                        else:
                            r.append(e)
                    elif s is not None:
                        r.append(e)
        return r
Exemple #3
0
 def match(self, other):
     if isinstance(other, List):
         sCombined = Substitution()
         if len(self._internal_list) != len(other._internal_list):
             return None
         for i in range(len(self._internal_list)):
             subArg = self._internal_list[i].match(other._internal_list[i])
             if subArg is None:
                 return None
             if not sCombined.add_substitution(subArg):
                 return None
         return sCombined
     return None
Exemple #4
0
 def apply(self, arg):
     if self.args is None:
         s = Substitution()
         s.add(SELF, arg)
         s.add(SELF_ALT, arg)
     else:
         s = self.args.match(arg)
     return self.e.apply(self.f.substitute(s))
Exemple #5
0
    def toggle_namespaces(self, flag):
        sub_map = {}
        for m in self.moduleList:
            ns_sub = m.get_namespace_substitution()
            if not flag:
                ns_sub = ns_sub.inverse()
            sub_map[m.get_name()] = ns_sub

        for m in self.moduleList:
            namespaces = self.get_matching_entries(m.get_name(),
                                                   Symbolic("#namespace"),
                                                   None)
            namespaces += self.get_matching_entries(m.get_name(),
                                                    Symbolic("#nms"), None)
            s = Substitution()
            for ns in namespaces:
                ns_term = ns.get_value()

                if isinstance(ns_term, Symbolic):
                    ns_mod_name = self.resolve_module_alias(
                        m.get_name(), ns.get_name())

                    if ns_mod_name is None:
                        raise ValueError("Could not find alias: %s %s" %
                                         (m.get_name(), ns.get_name()))
                    if not s.add_substitution(sub_map.get(ns_mod_name)):
                        raise ValueError("Namespace conflict in module " +
                                         str(m.get_name()) +
                                         ". Change namespace or use " +
                                         "#req and references.")

                elif isinstance(ns_term, Tuple):
                    ns_name = ns_term[0]
                    ns_table = self.resolve_reference(ns_term[1])
                    ns_sub = Substitution()
                    for entry in ns_table:
                        ns_sub.add(entry[ns_name], entry[0])
                    if not s.add_substitution(ns_sub):
                        print("Namespace term:", ns_term)
                        print("Substitution before:", s)
                        print("Failed to add:", ns_sub)
                        raise ValueError("Namespace conflict in module " +
                                         str(m.get_name()) +
                                         ". Change namespace or use " +
                                         "#req and references.")

            if len(s) > 0:
                m.substitute(s)
Exemple #6
0
 def check_type(self, type_def, x):
     tCheck = None
     if isinstance(type_def, Symbolic):
         tCheck = self.fReg.get_function(type_def)
         print("[W] Symbolic function reference:", type_def, "for", x, "it's a", type(type_def))
     elif isinstance(type_def, FunctionReference):
         tCheck = type_def.get_function()
         if tCheck is not None:
             return tCheck.apply(x)
         else:
             print("Function not found:", type_def)
     print("[W] Not a function reference:", type_def, "for", x, "it's a", type(type_def))
     selfSub = Substitution()
     selfSub.add(SELF, x)
     selfSub.add(SELF_ALT, x)
     return self.evaluator.apply(type_def.substitute(selfSub))
Exemple #7
0
 def match(self, other):
     s = Substitution()
     s.add(self, other)
     return s
Exemple #8
0
 def get_namespace_substitution(self):
     name_sub = Substitution()
     for e in self.data.values():
         if not e.get_type() == MOD:
             name_sub.add(e.get_name(), e.get_value())
     return name_sub
Exemple #9
0
 def apply(self, x):
     s = Substitution.from_term(x[1])
     return x[0].substitute(s)
Exemple #10
0
 def apply(self, x):
     s = Substitution()
     for kvp in x.get(0):
         s.add(kvp.get_key(), self.evaluator.apply(kvp.get_value()))
     return self.evaluator.apply(x.get(1).substitute(s))