예제 #1
0
파일: list.c 프로젝트: alakasame/Ls
t_l		*listtr(t_l **file, char *str, char *path)
{
	t_arg	stmp;

	stmp.file = (*file);
	stmp.path = listadd(str);
/*	ft_putstr("\n list tr ------ ");
	ft_putstr(path);
	ft_putstr(" list tr ------ \n");
*/	stmp.npath = getpath(path, str);
	while (stmp.file != NULL)
	{
		stmp.lpath = getpath(path, stmp.file->str);
		if (stat(stmp.npath, &stmp.fs) < 0 || stat(stmp.lpath, &stmp.sf) < 0)
			return (0);
		if (stmp.fs.st_mtime < stmp.sf.st_mtime)
			return (cond1(&stmp, file));
		if (stmp.file->next == NULL)
		{
			stmp.file->next = stmp.path;
			stmp.path->back = stmp.file;
			return (freeret(&stmp.lpath, &stmp.npath, *(file)));
		}
		ft_memdel((void **)&stmp.lpath);
		stmp.file = stmp.file->next;
	}
	return ((*file));
}
예제 #2
0
bool Foam::functionEntries::ifeqEntry::execute
(
    DynamicList<filePos>& stack,
    dictionary& parentDict,
    Istream& is
)
{
    const label nNested = stack.size();

    stack.append(filePos(is.name(), is.lineNumber()));

    // Read first token and expand any string
    token cond1(is);
    cond1 = expand(parentDict, cond1);

    // Read second token and expand any string
    token cond2(is);
    cond2 = expand(parentDict, cond2);

    const bool equal = equalToken(cond1, cond2);

    // Info<< "Using #" << typeName << " " << cond1
    //     << " == " << cond2
    //     << " at line " << stack.last().second()
    //     << " in file " <<  stack.last().first() << endl;

    bool ok = ifeqEntry::execute(equal, stack, parentDict, is);

    if (stack.size() != nNested)
    {
        FatalIOErrorInFunction(parentDict)
            << "Did not find matching #endif for condition starting"
            << " at line " << stack.last().second()
            << " in file " <<  stack.last().first() << exit(FatalIOError);
    }

    return ok;
}
예제 #3
0
파일: mvnsub.c 프로젝트: cran/mprobit
void approx1(double w[], double x[], double r[][M], int m, int a[], 
     double p[], double pp[][M], double *rec, int *idet)
{  double pra,rec2;
   double lb[8],ub[8],eps,bound,s[22];
   int ii,a1,a2,idt,ifault,m1,inf[8];
   void mulnor(double [], double [], double [], double, int,
               int [], double *, double *, int *);
   double cond1(int, int [], double [], double [][M], int *);

   /* approx , biv prob and product of cond prob*/
   a1=a[1]; a2=a[2];
   m1=2; inf[0]=2; inf[1]=2;  eps=1.e-6;
   lb[0]=w[a1]; lb[1]=w[a2]; ub[0]=x[a1]; ub[1]=x[a2];
   s[0]=r[a1][a2];
   mulnor(ub,lb,s,eps,m1,inf,&rec2,&bound,&ifault);
   if(ifault!=0) printf("error in mulnor %d\n", ifault);
   *idet=1;
   for(ii=3;ii<=m;ii++)
   { pra=cond1(ii,a,p,pp,&idt);
     rec2*=pra;
     if(idt==0) *idet=0;
   }
   *rec=rec2;
}
/// add axioms corresponding to the String.compareTo java function
/// \par parameters: function application with two string arguments
/// \return a integer expression
exprt string_constraint_generatort::add_axioms_for_compare_to(
  const function_application_exprt &f)
{
  string_exprt s1=add_axioms_for_string_expr(args(f, 2)[0]);
  string_exprt s2=add_axioms_for_string_expr(args(f, 2)[1]);
  const typet &return_type=f.type();
  symbol_exprt res=fresh_symbol("compare_to", return_type);
  typet index_type=s1.length().type();

  // In the lexicographic comparison, x is the first point where the two
  // strings differ.
  // We add axioms:
  // a1 : res==0 => |s1|=|s2|
  // a2 : forall i<|s1|. s1[i]==s2[i]
  // a3 : exists x.
  // res!=0 ==> x> 0 &&
  //   ((|s1| <= |s2| &&x<|s1|) || (|s1| >= |s2| &&x<|s2|)
  //   &&res=s1[x]-s2[x] )
  // || cond2:
  //   (|s1|<|s2| &&x=|s1|) || (|s1| > |s2| &&x=|s2|) &&res=|s1|-|s2|)
  // a4 : forall i<x. res!=0 => s1[i]=s2[i]

  assert(return_type.id()==ID_signedbv);

  equal_exprt res_null=equal_exprt(res, from_integer(0, return_type));
  implies_exprt a1(res_null, s1.axiom_for_has_same_length_as(s2));
  axioms.push_back(a1);

  symbol_exprt i=fresh_univ_index("QA_compare_to", index_type);
  string_constraintt a2(i, s1.length(), res_null, equal_exprt(s1[i], s2[i]));
  axioms.push_back(a2);

  symbol_exprt x=fresh_exist_index("index_compare_to", index_type);
  equal_exprt ret_char_diff(
    res,
    minus_exprt(
      typecast_exprt(s1[x], return_type),
      typecast_exprt(s2[x], return_type)));
  equal_exprt ret_length_diff(
    res,
    minus_exprt(
      typecast_exprt(s1.length(), return_type),
      typecast_exprt(s2.length(), return_type)));
  or_exprt guard1(
    and_exprt(s1.axiom_for_is_shorter_than(s2),
              s1.axiom_for_is_strictly_longer_than(x)),
    and_exprt(s1.axiom_for_is_longer_than(s2),
              s2.axiom_for_is_strictly_longer_than(x)));
  and_exprt cond1(ret_char_diff, guard1);
  or_exprt guard2(
    and_exprt(s2.axiom_for_is_strictly_longer_than(s1),
              s1.axiom_for_has_length(x)),
    and_exprt(s1.axiom_for_is_strictly_longer_than(s2),
              s2.axiom_for_has_length(x)));
  and_exprt cond2(ret_length_diff, guard2);

  implies_exprt a3(
    not_exprt(res_null),
    and_exprt(
      binary_relation_exprt(x, ID_ge, from_integer(0, return_type)),
      or_exprt(cond1, cond2)));
  axioms.push_back(a3);

  string_constraintt a4(i, x, not_exprt(res_null), equal_exprt(s1[i], s2[i]));
  axioms.push_back(a4);

  return res;
}
예제 #5
0
    static void test_interval_relation() {
        smt_params params;
        ast_manager ast_m;
        register_engine re;
        context ctx(ast_m, re, params);    
        arith_util autil(ast_m);
        relation_manager & m = ctx.get_rel_context()->get_rmanager();
        m.register_plugin(alloc(interval_relation_plugin, m));
        interval_relation_plugin& ip = dynamic_cast<interval_relation_plugin&>(*m.get_relation_plugin(symbol("interval_relation")));
        SASSERT(&ip);
        
        relation_signature sig;
        sort* int_sort = autil.mk_int();
        sig.push_back(int_sort);
        sig.push_back(int_sort);
        sig.push_back(int_sort);
        sig.push_back(int_sort);

        interval_relation& i1 = dynamic_cast<interval_relation&>(*ip.mk_empty(sig));
        interval_relation& i2 = dynamic_cast<interval_relation&>(*ip.mk_full(0, sig));

        i1.display(std::cout);
        i2.display(std::cout);
        SASSERT(i1.empty());
        SASSERT(!i2.empty());

        app_ref cond1(ast_m), cond2(ast_m), cond3(ast_m);
        app_ref cond4(ast_m), cond5(ast_m), cond6(ast_m);
        app_ref num1(ast_m);
        cond1 = autil.mk_le(ast_m.mk_var(0, int_sort), autil.mk_numeral(rational(0), true));
        cond2 = autil.mk_le(ast_m.mk_var(1, int_sort), autil.mk_numeral(rational(1), true));
        cond3 = autil.mk_le(ast_m.mk_var(2, int_sort), autil.mk_numeral(rational(2), true));
        cond4 = autil.mk_ge(ast_m.mk_var(0, int_sort), autil.mk_numeral(rational(0), true));
        cond5 = autil.mk_ge(ast_m.mk_var(1, int_sort), autil.mk_numeral(rational(0), true));
        cond6 = autil.mk_ge(ast_m.mk_var(2, int_sort), autil.mk_numeral(rational(5), true));
        num1 = autil.mk_numeral(rational(4), true);
        i2.filter_interpreted(cond1);
        i2.display(std::cout);
        // x0 <= 0
        
        unsigned cols1[2] = { 1, 2};
        unsigned cols2[2] = { 2, 3};
        relation_join_fn* join1 = ip.mk_join_fn(i1, i2, 2, cols1, cols2);        
        relation_transformer_fn* proj1 = ip.mk_project_fn(i1, 2, cols2);
        relation_transformer_fn* ren1  = ip.mk_rename_fn(i1, 2, cols2);
        relation_union_fn*       union1 = ip.mk_union_fn(i1, i2, &i1);
        relation_mutator_fn*     filterId1 = ip.mk_filter_identical_fn(i1, 2, cols1);
        relation_mutator_fn*     filterEq1 = ip.mk_filter_equal_fn(i1, num1, 2);               
        relation_mutator_fn*     filterCond1 = ip.mk_filter_interpreted_fn(i1, cond2);

        relation_base* i3 = (*join1)(i2, i2);
        i3->display(std::cout);       
 
        relation_transformer_fn* proj2 = ip.mk_project_fn(*i3, 2, cols2);

        (*filterEq1)(i2);
        i2.display(std::cout);
        // x0 <= 0
        // x2 = 4

        (*filterId1)(i2);
        i2.display(std::cout);
        // x0 <= 0
        // x1 = x2 = 4       
        relation_fact fact1(ast_m);
        fact1.push_back(autil.mk_numeral(rational(0), true));
        fact1.push_back(autil.mk_numeral(rational(4), true));
        fact1.push_back(autil.mk_numeral(rational(4), true));
        fact1.push_back(autil.mk_numeral(rational(5), true));
        SASSERT(i2.contains_fact(fact1));
        fact1[0] = autil.mk_numeral(rational(-1), true);
        SASSERT(i2.contains_fact(fact1));
        fact1[0] = autil.mk_numeral(rational(1), true);
        SASSERT(!i2.contains_fact(fact1));

        relation_base* i5 = (*ren1)(i2);
        i2.display(std::cout << "Orig\n");
        i5->display(std::cout << "renamed 2 |-> 3 |-> 2\n");

        (*filterCond1)(i2);
        i2.display(std::cout);
        // empty
        SASSERT(i2.empty());

        relation_base* i4 = (*proj2)(*i3);
        i4->display(std::cout);      
        
        i1.deallocate();
        i2.deallocate();
        i3->deallocate();
        i4->deallocate();
        i5->deallocate();
        dealloc(join1);
        dealloc(proj1);
        dealloc(ren1);
        dealloc(union1);
        dealloc(filterId1);
        dealloc(filterEq1);
        dealloc(filterCond1);
    }
예제 #6
0
    static void test_bound_relation() {

        std::cout << "bound relation\n";

        smt_params params;
        ast_manager ast_m;
        register_engine re;
        context ctx(ast_m, re, params);    
        arith_util autil(ast_m);
        relation_manager & m = ctx.get_rel_context()->get_rmanager();
        m.register_plugin(alloc(bound_relation_plugin, m));
        bound_relation_plugin& br = dynamic_cast<bound_relation_plugin&>(*m.get_relation_plugin(symbol("bound_relation")));
        SASSERT(&br);
        
        relation_signature sig;
        sort* int_sort = autil.mk_int();
        sig.push_back(int_sort);
        sig.push_back(int_sort);
        sig.push_back(int_sort);
        sig.push_back(int_sort);

        bound_relation& i1 = dynamic_cast<bound_relation&>(*br.mk_empty(sig));
        bound_relation& i2 = dynamic_cast<bound_relation&>(*br.mk_full(0, sig));

        i1.display(std::cout << "empty:\n");
        i2.display(std::cout << "full:\n");
        SASSERT(i1.empty());
        SASSERT(!i2.empty());

        app_ref cond1(ast_m), cond2(ast_m), cond3(ast_m);
        app_ref cond4(ast_m), cond5(ast_m), cond6(ast_m);
        app_ref num1(ast_m);
        cond1 = autil.mk_lt(ast_m.mk_var(0, int_sort), autil.mk_numeral(rational(0), true));
        cond2 = autil.mk_lt(ast_m.mk_var(1, int_sort), autil.mk_numeral(rational(1), true));
        cond3 = autil.mk_lt(ast_m.mk_var(2, int_sort), ast_m.mk_var(3, int_sort));
        cond4 = autil.mk_ge(ast_m.mk_var(0, int_sort), autil.mk_numeral(rational(0), true));
        cond5 = autil.mk_ge(ast_m.mk_var(1, int_sort), autil.mk_numeral(rational(0), true));
        cond6 = autil.mk_ge(ast_m.mk_var(2, int_sort), autil.mk_numeral(rational(5), true));

        app_ref lt_x0x1(ast_m), lt_x1x2(ast_m), lt_x0x3(ast_m), lt_x0x2(ast_m);
        lt_x0x1 = autil.mk_lt(ast_m.mk_var(0, int_sort), ast_m.mk_var(1, int_sort));
        lt_x1x2 = autil.mk_lt(ast_m.mk_var(1, int_sort), ast_m.mk_var(2, int_sort));
        lt_x0x2 = autil.mk_lt(ast_m.mk_var(0, int_sort), ast_m.mk_var(2, int_sort));
        lt_x0x3 = autil.mk_lt(ast_m.mk_var(0, int_sort), ast_m.mk_var(3, int_sort));

        num1 = autil.mk_numeral(rational(4), true);
        
        unsigned cols1[2] = { 1, 2};
        unsigned cols2[2] = { 2, 3};
        unsigned cols3[3] = { 0, 2, 3 };
        relation_join_fn* join1 = br.mk_join_fn(i1, i2, 2, cols1, cols2);        
        relation_transformer_fn* proj1 = br.mk_project_fn(i1, 2, cols2);
        relation_transformer_fn* ren1  = br.mk_rename_fn(i1, 3, cols3);
        relation_union_fn*       union1 = br.mk_union_fn(i1, i2, &i1);
        relation_mutator_fn*     filterId1 = br.mk_filter_identical_fn(i1, 2, cols1);
        relation_mutator_fn*     filterEq1 = br.mk_filter_equal_fn(i1, num1, 2);               
        relation_mutator_fn*     filterCond1 = br.mk_filter_interpreted_fn(i1, cond3);

        relation_base* i3 = (*join1)(i2, i2);
        i3->display(std::cout);       
 
        relation_transformer_fn* proj2 = br.mk_project_fn(*i3, 2, cols2);

        (*filterEq1)(i2);
        i2.display(std::cout << "no-op still full\n");
        // no-op
        
        (*filterCond1)(i2);
        i2.display(std::cout << "x2 < x3\n");
        // x2 < x3

        (*filterId1)(i2);
        i2.display(std::cout << "id\n");
        // x1 = x2 < x3    
        relation_fact fact1(ast_m);

        i2.display(std::cout << "Orig\n");
        std::cout << "renamed ";
        for (unsigned i = 0; i < 3; ++i) {
            std::cout << cols3[i] << " ";
        }
        std::cout << "\n";
        relation_base* i5 = (*ren1)(i2);
        i5->display(std::cout);

        //SASSERT(i2.empty());

        relation_base* i4 = (*proj2)(*i3);
        i4->display(std::cout);      

        // test that equivalence classes are expanded.
        // { x1 = x3, x0 < x1 x1 < x2} u { x2 = x3, x0 < x3 } = { x0 < x3 }
        {
            relation_base* b1 = br.mk_full(0, sig);
            relation_base* b2 = br.mk_full(0, sig);
            unsigned x1x3[2] = { 1, 3 };
            unsigned x2x3[2] = { 2, 3 };
            scoped_ptr<relation_mutator_fn> id1 = br.mk_filter_identical_fn(*b1, 2, x1x3);
            scoped_ptr<relation_mutator_fn> ltx0x1 = br.mk_filter_interpreted_fn(*b1, lt_x0x1);
            scoped_ptr<relation_mutator_fn> ltx1x2 = br.mk_filter_interpreted_fn(*b1, lt_x1x2);
            scoped_ptr<relation_mutator_fn> ltx0x3 = br.mk_filter_interpreted_fn(*b2, lt_x0x3);
            scoped_ptr<relation_mutator_fn> id2 = br.mk_filter_identical_fn(*b2, 2, x2x3);
            (*id1)(*b1);
            (*ltx0x1)(*b1);
            (*ltx1x2)(*b1);
            b2->display(std::cout << "b2:\n");
            (*id2)(*b2);
            b2->display(std::cout << "b2:\n");
            (*ltx0x3)(*b2);
            b2->display(std::cout << "b2:\n");
            scoped_ptr<relation_union_fn> u = br.mk_union_fn(*b1, *b2, 0);
            b1->display(std::cout << "b1:\n");
            b2->display(std::cout << "b2:\n");
            (*u)(*b1, *b2, 0);

            b1->display(std::cout << "b1 u b2:\n");

            // TBD check property;
            
            b1->deallocate();
            b2->deallocate();
        }

        // test that equivalence classes are expanded.
        // { x1 = x2 = x3, x0 < x1} u { x1 = x3, x0 < x3, x0 < x2 } = { x0 < x2, x0 < x3 }
        {
            relation_base* b1 = br.mk_full(0, sig);
            relation_base* b2 = br.mk_full(0, sig);
            unsigned x0x3[2] = { 0, 3 };
            unsigned x1x3[2] = { 1, 3 };
            unsigned x2x3[2] = { 2, 3 };
            scoped_ptr<relation_mutator_fn> id1 = br.mk_filter_identical_fn(*b1, 2, x1x3);
            scoped_ptr<relation_mutator_fn> id2 = br.mk_filter_identical_fn(*b1, 2, x2x3);
            scoped_ptr<relation_mutator_fn> ltx0x1 = br.mk_filter_interpreted_fn(*b1, lt_x0x1);
            scoped_ptr<relation_mutator_fn> ltx0x2 = br.mk_filter_interpreted_fn(*b2, lt_x0x2);
            scoped_ptr<relation_mutator_fn> ltx0x3 = br.mk_filter_interpreted_fn(*b2, lt_x0x3);
            scoped_ptr<relation_mutator_fn> id3 = br.mk_filter_identical_fn(*b2, 2, x1x3);
            (*id1)(*b1);
            (*id2)(*b1);
            (*ltx0x1)(*b1);
            (*id3)(*b2);
            (*ltx0x2)(*b2);
            (*ltx0x3)(*b2);
            scoped_ptr<relation_union_fn> u = br.mk_union_fn(*b1, *b2, 0);
            b1->display(std::cout << "b1:\n");
            b2->display(std::cout << "b2:\n");
            (*u)(*b1, *b2, 0);
            b1->display(std::cout << "b1 u b2:\n");

            // TBD check property;
            
            b1->deallocate();
            b2->deallocate();
        }
        
        i1.deallocate();
        i2.deallocate();
        i3->deallocate();
        i4->deallocate();
        i5->deallocate();
        dealloc(join1);
        dealloc(proj1);
        dealloc(ren1);
        dealloc(union1);
        dealloc(filterId1);
        dealloc(filterEq1);
        dealloc(filterCond1);
    }
예제 #7
0
int main(int argc, char* argv[])
{
    std::shared_ptr<Empty> blank;
    std::shared_ptr<Program> prg(new Program());

    std::shared_ptr<SharedDecl> shDecl1(new SharedDecl("y", blank));
    prg->Add(shDecl1);

    std::shared_ptr<Node> initX(new Atom("2"));
    std::shared_ptr<SharedDecl> shDecl2(new SharedDecl("x", initX));
    prg->Add(shDecl2);

    std::shared_ptr<Sub> sub1(new Sub("Main"));
    sub1->AddParam("a");
    sub1->AddParam("b");
    prg->Add(sub1);

    std::shared_ptr<Atom> atomA(new Atom("a"));
    std::shared_ptr<Atom> atomB(new Atom("b"));
    std::shared_ptr<BinaryOp> initRes(new BinaryOp("add", atomA, atomB));
    std::shared_ptr<VarDecl> resDecl(new VarDecl("res", initRes));
    sub1->Add(resDecl);

    std::shared_ptr<Atom> atom3i(new Atom("3"));
    std::shared_ptr<Atom> atom5i(new Atom("5"));
    std::shared_ptr<BinaryOp> newParam(new BinaryOp("add", atom3i, atom5i));
    std::shared_ptr<Allocation> allocat(new Allocation(newParam));
    std::shared_ptr<Atom> atomArr(new Atom("arr"));
    std::shared_ptr<Assignation> asignNew3(new Assignation(atomArr, allocat));
    sub1->Add(asignNew3);

    std::shared_ptr<Atom> atomArrBis(new Atom("arr"));
    std::shared_ptr<Deallocation> deallocat(new Deallocation(atomArrBis));
    sub1->Add(deallocat);

    std::shared_ptr<Atom> atomC(new Atom("res"));
    std::shared_ptr<BinaryOp> subCsumAB(new BinaryOp("substract", atomC, initRes));
    std::shared_ptr<Assignation> incC(new Assignation(atomC, subCsumAB));
    sub1->Add(incC);

    std::shared_ptr<Atom> atom0(new Atom("0"));
    std::shared_ptr<BinaryOp> cond1cond(new BinaryOp("equals", atomC, atom0));
    std::shared_ptr<If> cond1(new If(cond1cond, "10", "20"));
    sub1->Add(cond1);

    std::shared_ptr<Atom> atom1(new Atom("1"));
    std::shared_ptr<Atom> atom10(new Atom("10"));
    std::shared_ptr<For> for1(new For("i", atom1, atom10, atom1));
    sub1->Add(for1);

    std::shared_ptr<BinaryOp> addC1(new BinaryOp("add", atomC, atom1));
    std::shared_ptr<Assignation> incResActually(new Assignation(atomC, addC1));
    for1->Add(incResActually);

    std::shared_ptr<Loop> loop1(new Loop(cond1cond));
    loop1->Add(for1); // don't double reference ever in practice...
    loop1->Add(addC1);
    sub1->Add(loop1);

    std::shared_ptr<Call> call1(new Call("testFun", ""));
    call1->AddParam(atomA);
    call1->AddParam(addC1);
    sub1->Add(call1);

    std::shared_ptr<Return> ret1(new Return(atom0));
    sub1->Add(ret1);

    XMLDumpVisitor v;
    prg->Accept(&v);

    return 0;
}