Example #1
0
def str_subst(s, subst):
    names = split_name(s)
    it = subst.get(names[0], names[0])
    if isinstance(it, This):
        if len(names) > 1:
            return compose_names(*names[1:])
        return it
    return compose_names(it, *names[1:])
Example #2
0
File: ivy_ast.py Project: odedp/ivy
def str_subst(s,subst):
    names = split_name(s)
    it = subst.get(names[0],names[0])
    if isinstance(it,This):
        if len(names) > 1:
            return compose_names(*names[1:])
        return it
    return compose_names(it,*names[1:])
Example #3
0
def get_isolate_attr(isolate, attr, default=None):
    if isolate is None:
        return default
    attr = iu.compose_names(isolate, attr)
    if attr not in im.module.attributes:
        return default
    return im.module.attributes[attr].rep
Example #4
0
File: ivy_ast.py Project: odedp/ivy
def compose_atoms(pr,atom):
    if atom == None:
        return pr
    hname = compose_names(pr.rep,atom.rep)
    args = pr.args + atom.args
    res = type(atom)(hname,args)
    copy_attributes_ast(atom,res)
    return res
def compose_atoms(pr,atom):
    if atom == None:
        return pr
    hname = pr.rep if isinstance(atom.rep,This) else compose_names(pr.rep,atom.rep)
    args = pr.args + atom.args
    res = type(atom)(hname,args)
    copy_attributes_ast(atom,res)
    return res
Example #6
0
def compile_field_reference_rec(symbol_name, args, top=False):
    sym = ivy_logic.find_polymorphic_symbol(symbol_name, throw=False)
    if sym is None:
        parent_name, child_name = iu.parent_child_name(symbol_name)
        if parent_name == 'this':
            raise cfrfail(symbol_name)
        try:
            base = compile_field_reference_rec(parent_name, args)
        except cfrfail:
            raise cfrfail(symbol_name)
        sort = base.sort
        sort_parent, sort_child = iu.parent_child_name(sort.name)
        destr_name = iu.compose_names(sort_parent, child_name)
        if expr_context and top_context and destr_name in top_context.actions:
            args.insert(0, base)
            return field_reference_action(destr_name, args, top)
        sym = ivy_logic.find_polymorphic_symbol(destr_name)
        args.insert(0, base)
    if hasattr(sym.sort, 'dom') and len(sym.sort.dom) > 0:
        res = sym(*pull_args(args, len(sym.sort.dom), sym, top))
        return res
    return sym
def substitute_constants_ast2(ast,subs):
    """
    Substitute terms for variables in an ast. Here, subs is
    a dict from string names of variables to terms.
    """
    if (isinstance(ast, Atom) or isinstance(ast,App)) and not ast.args:
        if ast.rep in subs:
            return subs[ast.rep]
        names = split_name(ast.rep)
        if names[0] in subs:
            thing = type(ast)(compose_names(*names[1:]),ast.args)
            thing.lineno = ast.lineno
            res = MethodCall(subs[names[0]],thing)
            res.lineno = ast.lineno
            return res
        return ast
    else:
        if isinstance(ast,str):
            return ast
        new_args = [substitute_constants_ast2(x,subs) for x in ast.args]
        res = ast.clone(new_args)
        copy_attributes_ast(ast,res)
        return res
Example #8
0
def subst_subscripts(s,subst):
    return compose_names(*[subst_subscripts_comp(t,subst) for t in split_name(s)])
 def prefix_str(self,name,always):
     if not (self.pref and (always or self.to_pref == None or split_name(name)[0] in self.to_pref)):
         return name
     return iu.compose_names(self.pref.rep,name)
Example #10
0
def str_subst(s,subst):
    names = split_name(s)
    return compose_names(subst.get(names[0],names[0]),*names[1:])
Example #11
0
File: ivy_ast.py Project: asyaf/ivy
def compose_atoms(pr, atom):
    hname = compose_names(pr.rep, atom.rep)
    args = pr.args + atom.args
    res = type(atom)(hname, args)
    copy_attributes_ast(atom, res)
    return res
Example #12
0
File: ivy_ast.py Project: asyaf/ivy
def subst_subscripts(s, subst):
    return compose_names(
        *[subst_subscripts_comp(t, subst) for t in split_name(s)])
Example #13
0
def str_subst(s,subst):
    names = split_name(s)
    return compose_names(subst.get(names[0],names[0]),*names[1:])
Example #14
0
def check_module():
    # If user specifies an isolate, check it. Else, if any isolates
    # are specificied in the file, check all, else check globally.

    missing = []

    isolate = ivy_compiler.isolate.get()
    if isolate != None:
        isolates = [isolate]
    else:
        isolates = sorted(list(im.module.isolates))
        if len(isolates) == 0:
            isolates = [None]
        else:
            if coverage.get():
                missing = ivy_isolate.check_isolate_completeness()

    if missing:
        raise iu.IvyError(None, "Some assertions are not checked")

    for isolate in isolates:
        if isolate is not None and isolate in im.module.isolates:
            idef = im.module.isolates[isolate]
            if len(idef.verified()) == 0 or isinstance(
                    idef, ivy_ast.TrustedIsolateDef):
                continue  # skip if nothing to verify
        if isolate:
            print "\nIsolate {}:".format(isolate)
        if isolate is not None and iu.compose_names(
                isolate, 'macro_finder') in im.module.attributes:
            save_macro_finder = islv.opt_macro_finder.get()
            if save_macro_finder:
                print "Turning off macro_finder"
                islv.set_macro_finder(False)
        with im.module.copy():
            ivy_isolate.create_isolate(isolate)  # ,ext='ext'
            if opt_trusted.get():
                continue
            method_name = get_isolate_method(isolate)
            if method_name == 'mc':
                mc_isolate(isolate)
            elif method_name.startswith('bmc['):
                global some_bounded
                some_bounded = True
                _, prms = iu.parse_int_subscripts(method_name)
                if len(prms) != 1:
                    raise IvyError(
                        None,
                        'BMC method specifier should be bmc[<steps>]. Got "{}".'
                        .format(method_name))
                mc_isolate(isolate, lambda: ivy_bmc.check_isolate(prms[0]))
            else:
                check_isolate()
        if isolate is not None and iu.compose_names(
                isolate, 'macro_finder') in im.module.attributes:
            if save_macro_finder:
                print "Turning on macro_finder"
                islv.set_macro_finder(True)
    print ''
    if failures > 0:
        raise iu.IvyError(None, "failed checks: {}".format(failures))
    if checked_action.get() and not checked_action_found:
        raise iu.IvyError(
            None, "{} is not an exported action of any isolate".format(
                checked_action.get()))

    cact = checked_action.get()