void abstractVars(){ ATermList newSums, sums = MCRLgetListOfSummands(); ATermList vars, newVars; ATerm proc, sum; ATerm var, varSort, varName, oldVarSort; proc = MCRLgetProc(); newSums = ATmakeList0(); for(;!ATisEmpty(sums); sums= ATgetNext(sums)){ sum = ATgetFirst(sums); vars = (ATermList) ATgetArgument((ATermAppl) sum ,0); newVars = ATmakeList0(); for(;!ATisEmpty(vars); vars= ATgetNext(vars)){ var = (ATerm) ATgetFirst(vars); varName = (ATerm) ATgetArgument((ATermAppl) var, 0); varSort = (ATerm) ATgetArgument((ATermAppl) var, 1); oldVarSort = ATtableGet(var_tab, varName); if(oldVarSort != NULL) if(varSort != getConcrete(oldVarSort)){ PP("Variable "); ppTerm(varName); PP(" appears with two different types, "); ppTerm(varSort); PP(" and "); pTerm(oldVarSort); P("please modify the specification"); exit(-1); } if(toAbstractVar(varName)){ varSort = abstractSort(varSort); } if(toAbstractSort(varSort)){ varSort = abstractSort(varSort); } if(!toAbstractSort(varSort) && BUT_SORT){ varSort = getConcrete(varSort); } ATtablePut(var_tab, varName, varSort); var = (ATerm) ATsetArgument((ATermAppl) var, varSort, 1); newVars = ATinsert(newVars, var); } sum = (ATerm) ATsetArgument((ATermAppl) sum, (ATerm) ATreverse(newVars), 0); newSums = ATinsert(newSums, sum); } proc = (ATerm) ATsetArgument((ATermAppl) proc, (ATerm)ATreverse(newSums), 2); MCRLsetProc(proc); }
void abstractPars(){ ATermList pars = MCRLgetListOfPars(); ATermList newPars = ATmakeList0(); ATerm proc = MCRLgetProc(); ATerm par, parName, parSort; for(;!ATisEmpty(pars); pars= ATgetNext(pars)){ par = (ATerm) ATgetFirst(pars); parName = (ATerm) ATgetArgument((ATermAppl) par, 0); parSort = (ATerm) ATgetArgument((ATermAppl) par, 1); if(toAbstractPar(parName)){ parSort = liftSort(abstractSort(parSort)); } if(toAbstractSort(parSort)){ parSort = liftSort(abstractSort(parSort)); } if(!toAbstractSort(parSort) && BUT_SORT){ parSort = getConcrete(getUnLifted(parSort)); } par = (ATerm) ATsetArgument((ATermAppl) par, parSort, 1); newPars = ATappend(newPars, par); ATtablePut(par_tab, parName, parSort); } proc = (ATerm) ATsetArgument((ATermAppl)proc,(ATerm) newPars, 1); MCRLsetProc(proc); }
ATermList procAbstraction(ATermList procArgs){ ATerm procArg, newTerm, par, parSort, parName; ATermList newProcArgs = ATmakeList0(); ATermList pars = MCRLgetListOfPars(); ATerm termSort; for (;!ATisEmpty(procArgs); procArgs = ATgetNext(procArgs), pars = ATgetNext(pars)) { procArg = ATgetFirst(procArgs); par = ATgetFirst(pars); parSort = (ATerm) ATgetArgument((ATermAppl) par, 1); parName = (ATerm) ATgetArgument((ATermAppl) par, 0); newTerm = termAbstraction(procArg, parSort); termSort = getTermSort(newTerm); if(isAbstracted(termSort) && !isAbstracted(parSort)){ if(!isLifted(termSort)){ newTerm = createSingTerm(newTerm, liftSort(termSort)); termSort = liftSort(termSort); } newTerm = createGammaTerm(newTerm, termSort); if(-1 == ATindexOf(conflictingPars, parName , 0)) conflictingPars = ATappend(conflictingPars, parName); } newProcArgs = ATappend(newProcArgs, newTerm); } return newProcArgs; }
void specAbstraction(){ ATermList inits; ATermList newSums, sums; int i; ATerm proc, sum, var, varName, parName, par; ATermList vars, pars, newVars, newPars; proc = MCRLgetProc(); P("Specification Abstraction"); inits = MCRLgetListOfInitValues(); inits = initAbstraction(inits); proc = (ATerm) ATsetArgument((ATermAppl)proc, (ATerm) inits, 0); MCRLsetProc(proc); newSums = ATmakeList0(); sums = MCRLgetListOfSummands(); for(nSum = 1; !ATisEmpty(sums); sums= ATgetNext(sums), nSum++){ sum = ATgetFirst(sums); sum = sumAbstraction(sum); newSums = ATinsert(newSums, sum); fprintf(stderr,"."); } proc = (ATerm) ATsetArgument((ATermAppl) proc, (ATerm) newSums, 2); MCRLsetProc(proc); fprintf(stderr,"\n"); }
ATermList get_imports(ATermList decls) { ATerm decl, mod, spec; ATermList mods, new_decls; new_decls = ATmakeList0(); while(!ATisEmpty(decls)) { decl = ATgetFirst(decls); decls = ATgetNext(decls); if(ATmatch(decl, "Imports([<list>])", &mods)) { while(!ATisEmpty(mods)) { mod = ATgetFirst(mods); mods = ATgetNext(mods); if(ATindexOf(imported, mod, 0) == -1) { if(!silent) ATfprintf(stderr, " importing: %t\n", mod); imported = ATinsert(imported, mod); sprintf(file_name, "%s.r", t_string(mod)); spec = parse_file(file_name); new_decls = ATconcat(spec_decls(spec), new_decls); } else { if(!silent) ATfprintf(stderr, " importing: %t (done)\n", mod); } } } else { new_decls = ATinsert(new_decls, decl); } } return new_decls; }
int main(int argc, char *argv[]) { ATerm tree; ATinit(argc, argv, &tree); ATprotect((ATerm*)&imported); ATprotect(&parse_tree); ATprotect((ATerm*)&includes); process_options(argc, argv); imported = ATmakeList0(); yydebug = 0; open_dependencies(input_file); tree = parse_file(input_file); /* Open output file */ if (output_file == NULL) outfile = stdout; else outfile = fopen(output_file, "w"); if(binary_output) ATwriteToBinaryFile(tree, outfile); else ATwriteToTextFile(tree, outfile); /* print_dependencies(input_file, imported); */ exit(0); }
static ATbool Reduce(void) { ATerm proc = MCRLgetProc(); ATermList sums = MCRLgetListOfSummands(), pars = MCRLgetListOfPars(); ATermList newsums = ATmakeList0(); if (proverFlag) { Declare_vars(pars); if (invariant) MCRLparseInvariants(invariant); } else RWdeclareVariables(pars); for (cnt=0,newcnt = 0;!ATisEmpty(sums);sums=ATgetNext(sums),cnt++) { ATerm sum = ATgetFirst(sums), newsum = NULL; ATermList vars = (ATermList) ATgetArgument((ATermAppl) sum,0); ATerm actname = ATgetArgument((ATermAppl) sum, 1); ATermList actargs = (ATermList) ATgetArgument((ATermAppl) sum,2); ATerm procarg = ATgetArgument((ATermAppl) sum, 3); ATerm cond = ATgetArgument((ATermAppl) sum,4); ATbool invariantUsed = ATfalse; if (proverFlag) { if (!ATisEmpty(vars)) Declare_vars(vars); cond = Prove(cond); if (invariant) { ATerm cond1 = ProveCondition(cond); if (!ATisEqual(cond1, cond)) { invariantUsed = ATtrue; cond = cond1; } /* ATwarning("QQQ cond = %t", cond); */ } cond = RWrewrite(cond); } else { if (!ATisEmpty(vars)) RWdeclareVariables(vars); cond = RWrewrite(cond); } /* if (monitor) ATwarning("Condition of summand %d is rewritten", cnt+1); */ if (ATisEqual(cond, MCRLterm_false)) continue; newcnt++; actargs = RWrewriteList(actargs); if (!ATisEqual(procarg, MCRLterm_terminated)) { ATermList states = (ATermList) ATgetArgument((ATermAppl) procarg, 0); states = proverFlag?ProveList(states):RWrewriteList(states); procarg = (ATerm) ATmakeAppl1(MCRLsym_i, (ATerm) states); } newsum = ATmake("smd(<term>,<term>,<term>,<term>,<term>)",vars, actname, actargs,procarg, cond); newsums = ATinsert(newsums, newsum); if (monitor && !ATisEqual(sum, newsum)) ATwarning("Summand %d is rewritten %s", cnt+1, invariantUsed?"(invariant is used)":""); } MCRLsetProc(ATmake("initprocspec(<term>,<term>,<term>)", (ATerm) RWrewriteList((ATermList) MCRLgetListOfInitValues()), pars, (ATerm) ATreverse(newsums))); return !ATisEqual(MCRLgetProc(), proc); }
ATerm addVar(ATerm sum, ATerm varName, ATerm varSort){ ATermList vars = ATmakeList0(); ATerm var; AFun vTag = ATmakeSymbol("v",2, ATfalse); vars = (ATermList) ATgetArgument((ATermAppl) sum ,0); vars = ATinsert(vars,(ATerm)ATmakeAppl2(vTag,varName,varSort)); return (ATerm) ATsetArgument((ATermAppl) sum, (ATerm) vars, 0); }
ATermList generate_numbers(int max) { int i; ATermList numbers = ATmakeList0(); for(i=max; i>0; i--) numbers = ATinsert(numbers, (ATerm) ATmakeInt(i)); return numbers; }
void printResults(){ ATermList pars; ATermList vars; ATermList abstracted, lifted; ATerm par, parSort; ATerm var, varSort; abstracted = ATmakeList0(); lifted = ATmakeList0(); pars = ATtableKeys(par_tab); for(;!ATisEmpty(pars); pars = ATgetNext(pars)){ par = ATgetFirst(pars); parSort = ATtableGet(par_tab, par); if(isAbstracted(parSort)){ abstracted = ATinsert(abstracted, par); } else if (isLifted(parSort)){ lifted = ATinsert(lifted, par); } } fprintf(stderr, "%d Parameters Abstracted:\n", ATgetLength(abstracted)); pTerm((ATerm) abstracted); fprintf(stderr, "%d Parameters Lifted:\n", ATgetLength(lifted)); pTerm((ATerm) lifted); fprintf(stderr, "%d Conflicting Parameters:\n", ATgetLength(conflictingPars)); pTerm((ATerm) conflictingPars); abstracted = ATmakeList0(); vars = ATtableKeys(var_tab); for(;!ATisEmpty(vars); vars = ATgetNext(vars)){ var = ATgetFirst(vars); varSort = ATtableGet(var_tab, var); if(isAbstracted(varSort)){ abstracted = ATinsert(abstracted, var); } } fprintf(stderr, "%d Variables Abstracted:\n", ATgetLength(abstracted)); pTerm((ATerm) abstracted); }
ACB new_acb(ACData agent, ACData action) { ACCACB acb = (ACCACB)malloc(sizeof(struct accacb)); INIT_EXCEPTION_STACK(acb->exception_stack); INIT_DATA_STACK(acb->result); INIT_DATA_STACK(acb->data); acb->data = ATmakeList0(); acb->scope = ATmakeList0(); acb->saved_data = ATmakeList0(); acb->saved_scope = ATmakeList0(); ATprotect(&(acb->result)); ATprotect(&(acb->data)); ATprotect(&(acb->scope)); ATprotect(&(acb->saved_data)); ATprotect(&(acb->saved_scope)); acb->tagged_buffer = ATtableCreate(100, 80); acb->agent = agent; acb->action = action; ATprotect(&(acb->agent)); ATprotect(&(acb->action)); acb->return_stack.top = NULL; acb->exit_status = NORMAL_OUTCOME; acb->prev = NULL; return acb; }
ATermList actAbstraction (ATermList actArgs){ ATerm actArg, actArgSort, newTerm; ATermList newActArgs = ATmakeList0(); for(;!ATisEmpty(actArgs); actArgs = ATgetNext(actArgs)) { actArg = ATgetFirst(actArgs); actArgSort = getTermSort(actArg); if(toAbstractSort(actArgSort)){ actArgSort = liftSort(abstractSort(getUnLifted(actArgSort))); } newTerm = termAbstraction(actArg, actArgSort); newActArgs = ATappend(newActArgs, newTerm); } return newActArgs; }
void initAbsInt(){ ATbool ok; AFun memberTag; initTables(); conflictingPars = ATmakeList0(); ATprotect((ATerm *)&conflictingPars); memberTag = createNewFuncSym(memberSym, ATmakeList2(MCRLterm_bool, liftSort(MCRLterm_bool))); MCRLputMap((ATerm)ATmakeAppl2(memberTag, MCRLterm_bool, liftSort(MCRLterm_bool)), MCRLterm_bool, &ok); }
ATerm SSL_write_term_to_shared_string(ATerm term) { int i; int length; char* result = ATwriteToSharedString(term, &length); ATermList result_term = ATmakeList0();; if(result == NULL) { perror("SRTS/write_term_to_shared_string"); _fail(term); } for(i = length - 1; i >= 0; i--) { ATerm next = (ATerm) ATmakeInt(result[i]); result_term = ATinsert(result_term, next); } return (ATerm) result_term; }
void liftPars(){ ATermList sums, newSums; ATerm sum; ATerm procSpec, procArg; ATermList procArgs; ATermList pars, newPars; ATerm proc = MCRLgetProc(); ATerm par, parName, parSort; ATbool repeat; do{ repeat = ATfalse; sums = MCRLgetListOfSummands(); for(;!ATisEmpty(sums); sums= ATgetNext(sums)){ sum = ATgetFirst(sums); procSpec = ATgetArgument(sum, 3); procArgs = (ATermList)ATgetArgument((ATermAppl) procSpec,0); pars = MCRLgetListOfPars(); newPars = ATmakeList0(); for(;!ATisEmpty(procArgs); procArgs = ATgetNext(procArgs), pars = ATgetNext(pars)) { procArg = ATgetFirst(procArgs); par = ATgetFirst(pars); parSort = (ATerm) ATgetArgument((ATermAppl) par, 1); parName = (ATerm) ATgetArgument((ATermAppl) par, 0); if(!isLifted(parSort)){ if(toLiftTerm(procArg)){ repeat = ATtrue; parSort = liftSort(parSort); } } par = (ATerm) ATsetArgument((ATermAppl) par, parSort, 1); newPars = ATappend(newPars, par); ATtablePut(par_tab, parName, parSort); } proc = (ATerm) ATsetArgument((ATermAppl)proc,(ATerm) newPars, 1); MCRLsetProc(proc); if(repeat) break; fprintf(stderr,"."); } }while(repeat); }
ATermList filter_non_primes(ATermList numbers) { ATermList primes = ATmakeList0(); /* Skip 1, we dont want to filter that! */ numbers = ATgetNext(numbers); while(!ATisEmpty(numbers)) { /* The first number must be prime. remove it from numbers. */ ATerm prime = ATgetFirst(numbers); /* Remove all multiples of n, because they cannot be prime! */ numbers = filter_multiples(ATgetInt((ATermInt)prime), numbers); /*ATprintf("%d numbers.\n", ATgetLength(numbers));*/ /* Now add n to the list of primes */ primes = ATappend(primes, prime); } return (ATermList)ATmake("[1,<list>]", primes); }
void abstractSummands(){ ATermList mayMustSums, newSums, sums = MCRLgetListOfSummands(); ATerm proc, sum; proc = MCRLgetProc(); newSums = ATmakeList0(); P("Generating Abstract Summands"); sums = ATreverse(sums); for(nSum = 1; !ATisEmpty(sums); sums= ATgetNext(sums), nSum++){ sum = ATgetFirst(sums); mayMustSums = generateNewSums(sum); newSums = ATconcat(newSums, mayMustSums); fprintf(stderr,"."); } proc = (ATerm) ATsetArgument((ATermAppl) proc, (ATerm)newSums, 2); MCRLsetProc(proc); fprintf(stderr,"\n"); }
ATermList initAbstraction(ATermList inits){ ATermList pars = MCRLgetListOfPars(); ATermList newInits = ATmakeList0(); ATerm init, par, parSort, newTerm, initSort; for (;!ATisEmpty(inits); inits= ATgetNext(inits), pars = ATgetNext(pars)){ init = ATgetFirst(inits); par = ATgetFirst(pars); parSort = (ATerm) ATgetArgument((ATermAppl) par, 1); newTerm = init; initSort = getConcrete(getUnLifted(parSort)); if(isLifted(parSort)){ initSort = liftSort(initSort); newTerm = createSingTerm(newTerm, initSort); } if(isAbstracted(parSort)){ newTerm = createAlphaTerm(newTerm, initSort); } newInits = ATappend(newInits, newTerm); } return newInits; }
ATermList generateNewSums(ATerm sum){ ATerm maySum, mustSum; ATermList procArgs, newProcArgs; ATerm proc, procArg, procArgSort; ATermList actArgs; ATermList newActArgs; ATerm actArg, actArgSort; ATermList vars; ATerm var, varName, varSort; ATerm cond, auxMayCondition, auxMustCondition; int i; char auxVarName[NAME_LENGTH]; proc = (ATerm) ATgetArgument(sum, 3); procArgs = (ATermList)ATgetArgument(proc, 0); newProcArgs = ATmakeList0(); auxMayCondition = NULL; auxMustCondition = NULL; maySum = sum; mustSum = sum; if(HOMOMORPHISM){ for(i=0;!ATisEmpty(procArgs); procArgs= ATgetNext(procArgs)) { procArg = ATgetFirst(procArgs); procArgSort = getTermSort(procArg); if(isLifted(procArgSort)){ sprintf(auxVarName, "%s%d", auxVarPrefix, i); i++; varName = (ATerm)ATmakeAppl0(ATmakeAFun(auxVarName, 0, ATtrue)); varSort = getUnLifted(procArgSort); maySum = addVar(maySum, varName, varSort); newProcArgs = ATappend(newProcArgs, createSingleton(varName, varSort)); auxMayCondition = createMemberAuxCondition(auxMayCondition, varName, procArg, varSort); auxMustCondition = createSingletonAuxCondition(auxMustCondition, procArg, procArgSort); } else{ newProcArgs = ATappend(newProcArgs, procArg); } } proc = (ATerm)ATsetArgument((ATermAppl) proc, (ATerm) newProcArgs, 0); maySum = (ATerm)ATsetArgument((ATermAppl)maySum, proc, 3); mustSum = sum; actArgs = (ATermList)ATgetArgument(sum,2); newActArgs = ATmakeList0(); for(;!ATisEmpty(actArgs); actArgs= ATgetNext(actArgs),i++) { actArg = ATgetFirst(actArgs); actArgSort = getTermSort(actArg); if(isLifted(actArgSort)){ sprintf(auxVarName, "%s%d", auxVarPrefix, i); i++; varName = (ATerm)ATmakeAppl0(ATmakeAFun(auxVarName, 0, ATtrue)); varSort = getUnLifted(actArgSort); maySum = addVar(maySum, varName, varSort); mustSum = addVar(mustSum, varName, varSort); newActArgs = ATappend(newActArgs, varName); auxMayCondition = createMemberAuxCondition(auxMayCondition, varName, actArg, varSort); auxMustCondition = createMemberAuxCondition(auxMustCondition, varName, actArg, varSort); auxMustCondition = createSingletonAuxCondition(auxMustCondition, actArg, actArgSort); } else{ newActArgs = ATappend(newActArgs, actArg); } maySum = (ATerm)ATsetArgument((ATermAppl)maySum, (ATerm)newActArgs, 2); } } maySum = (ATerm)createMaySum(maySum); mustSum = (ATerm)createMustSum(mustSum); if(HOMOMORPHISM){ cond = ATgetArgument(maySum, 4); cond = createAuxCondition2(auxMayCondition, cond); maySum = (ATerm)ATsetArgument((ATermAppl)maySum, cond, 4); cond = ATgetArgument(mustSum, 4); cond = createAuxCondition2(auxMustCondition, cond); mustSum = (ATerm)ATsetArgument((ATermAppl)mustSum, cond, 4); } if(MAY && MUST) return ATmakeList2(maySum, mustSum); else if(MAY) return ATmakeList1(maySum); else if(MUST) return ATmakeList1(mustSum); }