static void writeAnnotatedNode(A2PWriter writer, A2PType expected, ATermAppl node, ATermList annotations){ A2PNodeType t = (A2PNodeType) expected->theType; AFun fun = ATgetAFun(node); int arity = ATgetArity(fun); char *name = ATgetName(fun); int nrOfAnnotations = ATgetLength(annotations); int i; ATerm annotationLabel; ATerm annotationValue; unsigned int hash = hashString(name); int nodeNameId = ISstore(writer->nameSharingMap, (void*) name, hash); if(nodeNameId == -1){ int nameLength = dataArraySize(name); writeByteToBuffer(writer->buffer, PDB_ANNOTATED_NODE_HEADER); printInteger(writer->buffer, nameLength); writeDataToBuffer(writer->buffer, name, nameLength); }else{ writeByteToBuffer(writer->buffer, PDB_ANNOTATED_NODE_HEADER | PDB_NAME_SHARED_FLAG); printInteger(writer->buffer, nodeNameId); } printInteger(writer->buffer, arity); for(i = 0; i < arity; i++){ doSerialize(writer, A2PvalueType(), ATgetArgument(node, i)); } /* Annotations. */ if((nrOfAnnotations % 2) == 1){ fprintf(stderr, "Detected corrupt annotations (Unbalanced).\n"); exit(1); } printInteger(writer->buffer, nrOfAnnotations); do{ char *label; int labelLength; A2PType annotationType; annotationLabel = ATgetFirst(annotations); annotations = ATgetNext(annotations); annotationValue = ATgetFirst(annotations); annotations = ATgetNext(annotations); if(ATgetType(annotationLabel) != AT_APPL){ fprintf(stderr, "Detected corrupt annotation; label term is not a 'string'.\n"); exit(1); } label = ATgetName(ATgetAFun((ATermAppl) annotationLabel)); labelLength = dataArraySize(label); printInteger(writer->buffer, labelLength); writeDataToBuffer(writer->buffer, label, labelLength); annotationType = (A2PType) HTget(t->declaredAnnotations, (void*) label, hashString(label)); doSerialize(writer, annotationType, annotationValue); }while(!ATisEmpty(annotations)); }
static void writeAnnotatedConstructor(A2PWriter writer, A2PType expected, ATermAppl constructor, ATermList annotations){ A2PConstructorType t = (A2PConstructorType) expected->theType; ISIndexedSet sharedTypes = writer->typeSharingMap; int typeHash = hashType(expected); int constructorTypeId = ISget(sharedTypes, (void*) expected, typeHash); int arity = ATgetArity(ATgetAFun(constructor)); int nrOfAnnotations = ATgetLength(annotations); int i; ATerm annotationLabel; ATerm annotationValue; if(constructorTypeId == -1){ writeByteToBuffer(writer->buffer, PDB_ANNOTATED_CONSTRUCTOR_HEADER); doWriteType(writer, expected); ISstore(sharedTypes, (void*) expected, typeHash); }else{ writeByteToBuffer(writer->buffer, PDB_ANNOTATED_CONSTRUCTOR_HEADER | PDB_TYPE_SHARED_FLAG); printInteger(writer->buffer, constructorTypeId); } printInteger(writer->buffer, arity); for(i = 0; i < arity; i++){ doSerialize(writer, ((A2PTupleType) t->children->theType)->fieldTypes[i], ATgetArgument(constructor, i)); } /* Annotations. */ if((nrOfAnnotations % 2) == 1){ fprintf(stderr, "Detected corrupt annotations (Unbalanced).\n"); exit(1); } printInteger(writer->buffer, nrOfAnnotations); do{ char *label; int labelLength; A2PType annotationType; annotationLabel = ATgetFirst(annotations); annotations = ATgetNext(annotations); annotationValue = ATgetFirst(annotations); annotations = ATgetNext(annotations); if(ATgetType(annotationLabel) != AT_APPL){ fprintf(stderr, "Detected corrupt annotation; label term is not a 'string'.\n"); exit(1); } label = ATgetName(ATgetAFun((ATermAppl) annotationLabel)); labelLength = dataArraySize(label); printInteger(writer->buffer, labelLength); writeDataToBuffer(writer->buffer, label, labelLength); annotationType = (A2PType) HTget(t->declaredAnnotations, (void*) label, hashString(label)); doSerialize(writer, annotationType, annotationValue); }while(!ATisEmpty(annotations)); }
ATerm funcAbstraction(ATerm func, ATerm dstSort){ ATermList argSorts; ATerm newTerm, newTermSort; ATerm arg, argSort, fSort, argSortAux; ATbool modified; int i, j; char *fName; AFun fun; argSorts = getFuncSortList(func); fSort = getTermSort(func); fun = ATgetAFun(func); fName = ATgetName(fun); if(reservedFunc(fun)) return func; do{ modified = ATfalse; for(i=0; i< ATgetArity(ATgetAFun(func)); i++){ arg = ATgetArgument((ATermAppl) func, i); argSort = ATelementAt(argSorts, i); if(toAbstractArg(argSort, argSorts, fSort)) argSort = liftSort(abstractSort(getUnLifted(argSort))); newTerm = termAbstraction(arg, argSort); newTermSort = getTermSort(newTerm); if(newTerm != arg) modified = ATtrue; func = (ATerm) ATsetArgument((ATermAppl) func, newTerm, i); argSorts = ATreplace(argSorts, newTermSort, i); if(toAbstractTarget(newTermSort, fSort)) fSort = liftSort(abstractSort(getUnLifted(fSort))); if(toLiftTarget(newTermSort, fSort)) fSort = liftSort(fSort); if(modified) break; } } while(modified); if(toAbstractSort(fSort) && abstractedSorts(argSorts)) fSort = liftSort(abstractSort(getUnLifted(fSort))); func = createNewFuncTerm(func, argSorts, fSort); return func; }
static ATerm CaseRewrite(ATerm t) { AFun f = ATgetAFun(t); int n = ATgetArity(f); ATerm u; // ATwarning("%t", t); if (n==0) return tasks->RWrewrite(t); u = ATtableGet(norm, t); if (u) return u; { int i; ATerm *a = calloc(n, sizeof(ATerm)); ATbool changed = ATfalse; ATprotectArray(a, n); for (i=0; i<n; i++) { ATerm arg = ATgetArgument((ATermAppl) t, i); a[i] = CaseRewrite(arg); if (!ATisEqual(a[i], arg)) changed = ATtrue; } u = CaseRewriteStep(changed?(ATerm) ATmakeApplArray(f, a):t); ATtablePut(norm, t, u); ATunprotect(a); free(a); return u; } }
static void writeNode(A2PWriter writer, A2PType expected, ATermAppl node){ AFun fun = ATgetAFun(node); int arity = ATgetArity(fun); char *name = ATgetName(fun); int i; unsigned int hash = hashString(name); int nodeNameId = ISstore(writer->nameSharingMap, (void*) name, hash); if(nodeNameId == -1){ int nameLength = dataArraySize(name); writeByteToBuffer(writer->buffer, PDB_NODE_HEADER); printInteger(writer->buffer, nameLength); writeDataToBuffer(writer->buffer, name, nameLength); }else{ writeByteToBuffer(writer->buffer, PDB_NODE_HEADER | PDB_NAME_SHARED_FLAG); printInteger(writer->buffer, nodeNameId); } printInteger(writer->buffer, arity); for(i = 0; i < arity; i++){ doSerialize(writer, A2PvalueType(), ATgetArgument(node, i)); } }
static void unexpected(ATerm tree, int n, char *str) { ATfprintf(stderr, "The %dth argument was expected to be %s\n%a\n", n, str, ATgetAFun(tree)); exit(1); }
static void writeADT(A2PWriter writer, A2PType expected, ATerm value){ int termType = ATgetType(value); if(termType == AT_APPL){ ATermAppl appl = (ATermAppl) value; AFun fun = ATgetAFun(appl); char *name = ATgetName(fun); int arity = ATgetArity(fun); A2PType constructorType = A2PlookupConstructorType(expected, name, arity); if(constructorType == NULL){ fprintf(stderr, "Unable to find a constructor that matches the given ADT type. Name: %s, arity: %d, ADT name: %s.\n", name, arity, ((A2PAbstractDataType) expected->theType)->name); exit(1); } writeConstructor(writer, constructorType, appl); }else{ A2PType wrapper; switch(termType){ case AT_INT: wrapper = A2PlookupConstructorWrapper(expected, A2PintegerType()); break; case AT_REAL: wrapper = A2PlookupConstructorWrapper(expected, A2PrealType()); break; default: fprintf(stderr, "The given ATerm of type: %d, can not be a constructor.\n", termType); exit(1); } if(wrapper == NULL){ fprintf(stderr, "Unable to find constructor wrapper for ATerm with type : %d.\n", termType); exit(1);} writeConstructor(writer, wrapper, ATmakeAppl1(ATmakeAFun(((A2PConstructorType) wrapper->theType)->name, 1, ATfalse), value)); } }
static void writeConstructor(A2PWriter writer, A2PType expected, ATermAppl constructor){ A2PConstructorType t = (A2PConstructorType) expected->theType; A2PTupleType children = ((A2PTupleType) t->children->theType); int nrOfChildren = typeArraySize(children->fieldTypes); ISIndexedSet sharedTypes = writer->typeSharingMap; int typeHash = hashType(expected); int constructorTypeId = ISget(sharedTypes, (void*) expected, typeHash); int arity = ATgetArity(ATgetAFun(constructor)); int i; if(arity != nrOfChildren){ fprintf(stderr, "Arity (%d) is unequal to the number of children (%d); term was:\n%s\n", arity, nrOfChildren, ATwriteToString((ATerm) constructor)); exit(1);} if(constructorTypeId == -1){ writeByteToBuffer(writer->buffer, PDB_CONSTRUCTOR_HEADER); doWriteType(writer, expected); ISstore(sharedTypes, (void*) expected, typeHash); }else{ writeByteToBuffer(writer->buffer, PDB_CONSTRUCTOR_HEADER | PDB_TYPE_SHARED_FLAG); printInteger(writer->buffer, constructorTypeId); } printInteger(writer->buffer, arity); for(i = 0; i < arity; i++){ doSerialize(writer, children->fieldTypes[i], ATgetArgument(constructor, i)); } }
void RWdeclareVariables(ATermList variable_names) { if (ATisEmpty(variable_names)) return; tasks->RWdeclareVariables(variable_names); if (!currentAdt) return; if (ATgetArity(ATgetAFun(ATgetFirst(variable_names)))==0) MCRLdeclareVarNames(variable_names); else MCRLdeclareVars(variable_names); }
static void writeString(A2PWriter writer, ATermAppl string){ char *stringValue = ATgetName(ATgetAFun(string)); int stringValueLength = dataArraySize(stringValue); writeByteToBuffer(writer->buffer, PDB_STRING_HEADER); printInteger(writer->buffer, stringValueLength); writeDataToBuffer(writer->buffer, stringValue, stringValueLength); }
static ATermList ProveList(ATermList args) { ATermList r = ATempty; AFun bool = ATgetAFun(MCRLterm_bool); for (;!ATisEmpty(args);args=ATgetNext(args)) { ATerm arg = ATgetFirst(args); r = ATinsert(r, MCRLgetSort(arg)==bool? RWrewrite(Prove(arg)):RWrewrite(arg)); } return ATreverse(r); }
static void writeBool(A2PWriter writer, ATermAppl boolean){ char *boolName = ATgetName(ATgetAFun(boolean)); writeByteToBuffer(writer->buffer, PDB_BOOL_HEADER); if(strncmp(boolName, "true", 4) == 0){ printInteger(writer->buffer, 1); }else{ printInteger(writer->buffer, 0); } }
static void checkAlias(ATerm alias) { if (ATgetType(alias) == AT_APPL) { ATermAppl appl = (ATermAppl)alias; AFun afun = ATgetAFun(appl); if (ATgetArity(afun) == 0 && !ATisQuoted(afun)) { return; } } ATfprintf(stderr, "incorrect alias: %t\n", alias); exit(1); }
ATerm get_new_module_name(int cid, ATerm searchPaths, const char *path, const char* id) { ATermList search = (ATermList) searchPaths; char chosenPath[PATH_LEN] = ""; int chosenPathLen = 0; char chosenId[PATH_LEN]; /* We will choose the longest search path that matches the path of * the chosen module. */ for (; !ATisEmpty(search); search = ATgetNext(search)) { char *current = ATgetName(ATgetAFun((ATermAppl) ATgetArgument(ATgetFirst(search), 1))); int currentLen = strlen(current); if (strncmp(current, path, currentLen) == 0) { if (currentLen > chosenPathLen) { strcpy(chosenPath, current); chosenPathLen = currentLen; } } } /* Now construct a compound module id to complete * the filename. */ if (chosenPathLen > 0) { int i = chosenPathLen; while (path[i] == SEP) { i++; } if (strcmp(chosenPath, path) == 0) { strcpy(chosenId, id); } else { sprintf(chosenId, "%s%c%s", path+i, SEP, id); } return ATmake("snd-value(new-module-name(<str>,<str>))", chosenPath, chosenId); } else { return ATmake("snd-value(module-name-inconsistent)"); } }
int ACR_NatConToInt(ANK_NatCon natcon) { char *s = ATgetName(ATgetAFun(natcon)); int len = strlen(s); char *buf; int n; #ifdef DEBUG ATwarning("s = %s\n",s); ATwarning("len = %d\n",len); #endif buf = alloca(len+1); strncpy(buf,s, len); n = atoi(buf); #ifdef DEBUG ATwarning("n = %d\n",n); #endif return n; }
ATerm CO_unquoteAppl(ATerm appl) { AFun fun; int arity; char *name = NULL; ATermList args = NULL; assert(ATgetType(appl) == AT_APPL); fun = ATgetAFun((ATermAppl) appl); arity = ATgetArity(fun); name = ATgetName(fun); args = ATgetArguments((ATermAppl) appl); fun = ATmakeAFun(name, arity, ATfalse); return (ATerm) ATmakeApplList(fun, args); }
static void writeTuple(A2PWriter writer, A2PType expected, ATermAppl tuple){ A2PTupleType t = (A2PTupleType) expected->theType; A2PType *fieldTypes = t->fieldTypes; int numberOfFieldTypes = typeArraySize(fieldTypes); int arity = ATgetArity(ATgetAFun(tuple)); int i; if(numberOfFieldTypes != arity){ fprintf(stderr, "The number of children specified in the type is not equal to the arity of this tuple.\n"); exit(1); } writeByteToBuffer(writer->buffer, PDB_TUPLE_HEADER); printInteger(writer->buffer, arity); for(i = 0; i < arity; i++){ doSerialize(writer, fieldTypes[i], ATgetArgument(tuple, i)); } }
ATbool toLiftFunc(ATerm func){ ATerm arg; int i; ATermList argSorts, args; ATerm fSort, argSort; fSort = getTermSort(func); argSorts = getFuncSortList(func); if(toAbstractSort(fSort)) return ATtrue; for(i=0; i< ATgetArity(ATgetAFun(func)); i++){ arg = ATgetArgument((ATermAppl) func, i); if(toLiftTerm(arg)) return ATtrue; } return ATfalse; }
static ATerm _ProveCondition(ATerm c) { /* Obliged that last branch must be "if (b, T, F)" Invariant will be used at each first argument of "if" */ ATerm result = c; ATermList ts = ATempty; while (ATgetAFun(c)==MCRLsym_ite && ATgetArgument((ATermAppl) c, 2) == MCRLterm_false) { ts = ATinsert(ts, ATgetArgument((ATermAppl) c, 0)); c = ATgetArgument((ATermAppl) c, 1); } if (ATisEmpty(ts)) return result; else { int n = ATgetLength (ts), i; DECLA(ATerm, l, n);DECLA(ATerm, r, n); DECLA(ATerm, s, n); ATerm I = MCRLgetInvariant(0); for (i=n-1;i>=0;i--, ts = ATgetNext(ts)) l[i] = ATgetFirst(ts); for (i=0;i<n;i++) { int j, p; for (p = 0, j=n-1;j>=0;j--) if (i!=j) { s[p] = (ATerm) ATmakeAppl3(MCRLsym_ite, l[j], p>0?s[p-1]:MCRLterm_true,MCRLterm_false); p++; } r[i] = p>0?s[p-1]:MCRLterm_true; } for (i=0;i<n;i++) { /* If proven (I and r) -> l then (c = l and r) will be replaced by r */ ATerm IandR = (ATerm) ATmakeAppl2(MCRLsym_and, I, r[i]), arrow = Prove((ATerm) ATmakeAppl3(MCRLsym_ite, IandR, l[i], MCRLterm_true)); /* ATwarning("QQQA %t", MCRLprint(arrow)); */ if (ATisEqual(arrow, MCRLterm_true)) { return r[i]; } } return result; } }
static void serializeUntypedTerm(A2PWriter writer, ATerm value){ int type = ATgetType(value); switch(type){ case AT_INT: writeInteger(writer, (ATermInt) value); break; case AT_REAL: writeDouble(writer, (ATermReal) value); break; case AT_APPL: { ATermAppl appl = (ATermAppl) value; AFun fun = ATgetAFun(appl); if(ATisQuoted(fun) == ATfalse){ A2PType expected = A2PnodeType(); ATermList annotations = (ATermList) ATgetAnnotations(value); if(annotations == NULL){ writeNode(writer, expected, appl); }else{ if(((A2PNodeType) expected->theType)->declaredAnnotations == NULL){ fprintf(stderr, "Node term has annotations, but none are declared.\n"); exit(1); } writeAnnotatedNode(writer, expected, appl, annotations); } }else{ if(ATgetArity(fun) != 0){ fprintf(stderr, "Quoted appl (assumed to be a string) has a non-zero arity.\n"); exit(1);} writeString(writer, appl); } } break; case AT_LIST: writeList(writer, A2PlistType(A2PvalueType()), (ATermList) value); break; default: fprintf(stderr, "Encountered unwriteable type: %d.\n", type); exit(1); } }
unsigned int calc_hash(ATerm t) { unsigned int hnr = 0; switch(ATgetType(t)) { case AT_APPL: { ATermAppl appl = (ATermAppl)t; AFun sym = ATgetAFun(appl); int i, arity = ATgetArity(sym); hnr = AT_hashSymbol(ATgetName(sym), arity); for(i=0; i<arity; i++) { hnr = hnr * MAGIC_HASH_CONST_APPL + calc_hash(ATgetArgument(appl, i)); } } break; case AT_INT: hnr = ATgetInt((ATermInt)t); break; case AT_LIST: { ATermList list = (ATermList)t; hnr = 123; while(!ATisEmpty(list)) { hnr = hnr * MAGIC_HASH_CONST_LIST + calc_hash(ATgetFirst(list)); list = ATgetNext(list); } } break; } return hnr; }
int doConvert(FILE *fpOut, int traceLevel) { SVCstateIndex fromState, toState; SVClabelIndex label/*,taulabel*/; SVCparameterIndex parameter; SVCbool tempbool=0; char name[256], *first, *last; if (traceLevel>0){ /* Get file header info */ fprintf(stderr, "Svc version %s %s\n", SVCgetFormatVersion(&inFile), SVCgetIndexFlag(&inFile)?"(indexed)":""); fprintf(stderr, " filename %s\n", SVCgetFilename(&inFile)); fprintf(stderr, " date %s\n", SVCgetDate(&inFile)); fprintf(stderr, " version %s\n", SVCgetVersion(&inFile)); fprintf(stderr, " type %s\n", SVCgetType(&inFile)); fprintf(stderr, " creator %s\n", SVCgetCreator(&inFile)); fprintf(stderr, " states %ld\n", SVCnumStates(&inFile)); fprintf(stderr, " transitions %ld\n", SVCnumTransitions(&inFile)); fprintf(stderr, " labels %ld\n", SVCnumLabels(&inFile)); fprintf(stderr, " parameters %ld\n", SVCnumParameters(&inFile)); ATfprintf(stderr, " initial state %t\n", SVCstate2ATerm(&inFile,SVCgetInitialState(&inFile))); fprintf(stderr, " comments %s\n", SVCgetComments(&inFile)); } /* base name of input file */ strncpy(name, SVCgetFilename(&inFile), 256); first = strrchr(name,'/'); if (!first) first = name; last = strrchr(first,'.'); if (last && !strcmp(last,INFILE_EXT)) *last ='\0'; /* fprintf(fpOut, "des(%ld,%ld,%ld)\n", SVCgetInitialState(&inFile), SVCnumTransitions(&inFile), SVCnumStates(&inFile)); while (SVCgetNextTransition(&inFile, &fromState, &label, &toState, ¶meter)) { ATfprintf(fpOut, "(%d, %t, %d)\n", fromState, SVClabel2ATerm(&inFile,label), toState); } */ /* adaption to output dot files (by Jan Friso Groote) */ /* taulabel=SVCnewLabel(&inFile,ATmake("\"tau\""),&tempbool); if (tempbool) { *//* the label tau did not exist yet, let's try i */ /* taulabel=SVCnewLabel(&inFile,ATmake("\"i\""),&tempbool); if (tempbool) { *//* the label i does not exist also, so forget about tau's */ /* taulabel=0; } }*/ fprintf(fpOut,"digraph \"%s\" {\n", first); /* fprintf(fpOut,"size=\"7,10.5\";\n"); */ fprintf(fpOut,"center=TRUE;\n"); fprintf(fpOut,"mclimit=10.0;\n"); fprintf(fpOut,"nodesep=0.05;\n"); fprintf(fpOut,"node[width=0.25,height=0.25,label=\"\"];\n"); fprintf(fpOut,"%d[peripheries=2];\n",SVCgetInitialState(&inFile)); while (SVCgetNextTransition(&inFile, &fromState, &label, &toState, ¶meter)) { ATerm t = SVClabel2ATerm(&inFile,label); AFun s = ATgetAFun(t); if (ATisQuoted(s) && ATgetArity(s)==0) ATfprintf(fpOut, "%d->%d[label=%t];\n",fromState, toState, t); else ATfprintf(fpOut, "%d->%d[label=\"%t\"];\n",fromState, toState, t); /* if (label==taulabel) ATfprintf(fpOut,"color=\"grey\",fontsize=\"18\"]\n"); else ATfprintf(fpOut,"fontsize=\"32\", weight=\"4\"]\n"); */ } fprintf(fpOut,"}\n"); if (SVCclose(&inFile)<0){ if (traceLevel>0) { fprintf(stderr, "File trailer corrupt...\n"); } return -1; } fclose(fpOut); return EXIT_OK; } /* doConvert */
void init_Graph_dict() { ATermList afuns, terms; _Graph_dict = ATreadFromBinaryString(_Graph_dict_baf, _Graph_dict_LEN); ATprotect(&_Graph_dict); afuns = (ATermList)ATelementAt((ATermList)_Graph_dict, 0); afun16 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun16); afuns = ATgetNext(afuns); afun15 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun15); afuns = ATgetNext(afuns); afun14 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun14); afuns = ATgetNext(afuns); afun13 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun13); afuns = ATgetNext(afuns); afun39 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun39); afuns = ATgetNext(afuns); afun38 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun38); afuns = ATgetNext(afuns); afun19 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun19); afuns = ATgetNext(afuns); afun37 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun37); afuns = ATgetNext(afuns); afun18 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun18); afuns = ATgetNext(afuns); afun36 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun36); afuns = ATgetNext(afuns); afun17 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun17); afuns = ATgetNext(afuns); afun35 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun35); afuns = ATgetNext(afuns); afun22 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun22); afuns = ATgetNext(afuns); afun40 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun40); afuns = ATgetNext(afuns); afun23 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun23); afuns = ATgetNext(afuns); afun41 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun41); afuns = ATgetNext(afuns); afun20 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun20); afuns = ATgetNext(afuns); afun21 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun21); afuns = ATgetNext(afuns); afun4 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun4); afuns = ATgetNext(afuns); afun5 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun5); afuns = ATgetNext(afuns); afun2 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun2); afuns = ATgetNext(afuns); afun3 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun3); afuns = ATgetNext(afuns); afun0 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun0); afuns = ATgetNext(afuns); afun1 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun1); afuns = ATgetNext(afuns); afun29 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun29); afuns = ATgetNext(afuns); afun28 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun28); afuns = ATgetNext(afuns); afun8 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun8); afuns = ATgetNext(afuns); afun25 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun25); afuns = ATgetNext(afuns); afun24 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun24); afuns = ATgetNext(afuns); afun9 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun9); afuns = ATgetNext(afuns); afun6 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun6); afuns = ATgetNext(afuns); afun27 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun27); afuns = ATgetNext(afuns); afun7 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun7); afuns = ATgetNext(afuns); afun26 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun26); afuns = ATgetNext(afuns); afun31 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun31); afuns = ATgetNext(afuns); afun32 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun32); afuns = ATgetNext(afuns); afun33 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun33); afuns = ATgetNext(afuns); afun34 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun34); afuns = ATgetNext(afuns); afun10 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun10); afuns = ATgetNext(afuns); afun11 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun11); afuns = ATgetNext(afuns); afun12 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun12); afuns = ATgetNext(afuns); afun30 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); ATprotectAFun(afun30); afuns = ATgetNext(afuns); terms = (ATermList)ATelementAt((ATermList)_Graph_dict, 1); }
ATerm toolbus_start(int conn, const char *script, ATerm args) { int i, pid, cid; char *argv[MAX_ARGS]; char sockets[2][BUFSIZ]; WellKnownSocketPort = TB_PORT; if (mk_server_ports(0) == TB_ERROR) { ATerror("cannot create server ports, giving up!\n"); } else { fprintf(stderr, "server ports created at %d\n", WellKnownSocketPort); } pid = fork(); if (pid == -1) { ATerror("cannot fork toolbus-adapter, giving up!\n"); } else if (pid > 0) { /* Parent */ /* connect to child toolbus! */ int attempts = 0; do { cid = ATBconnect(NULL, NULL, WellKnownSocketPort, toolbus_adapter_handler); if (cid < 0) { tb_sleep(0, 500000); } } while (cid < 0 && attempts++ < MAX_ATTEMPTS); if (cid < 0) { return ATparse("snd-value(toolbus-error)"); } else { if (cid > max_cid) { max_cid = cid; } return ATmake("snd-value(toolbus-started(<int>))", cid); } } else { /* Child */ /*{{{ setup arguments */ int argc = 0; ATermList arg_list; sprintf(sockets[0], "%d", WellKnownLocalSocket); sprintf(sockets[1], "%d", WellKnownGlobalSocket); argv[argc++] = TBPROG; argv[argc++] = "-TB_USE_SOCKETS"; argv[argc++] = sockets[0]; argv[argc++] = sockets[1]; assert(ATgetType(args) == AT_LIST); arg_list = (ATermList)args; while (!ATisEmpty(arg_list)) { ATerm arg = ATgetFirst(arg_list); arg_list = ATgetNext(arg_list); if (ATgetType(arg) == AT_APPL) { argv[argc++] = ATgetName(ATgetAFun((ATermAppl)arg)); } else { argv[argc] = strdup(ATwriteToString(arg)); assert(argv[argc]); argc++; } } /* Jurgen added this (char*) cast to prevent a compiler warning. * But this code has more problems: we know that updating * argv[] arrays is not portable, so the following code is actually * wrong: */ argv[argc++] = (char*) script; argv[argc] = NULL; for (i=0; i<argc; i++) { fprintf(stderr, "argv[%d] = %s\n", i, argv[i]); } /*}}} */ if (execv(TBPROG, argv) < 0) { perror(TBPROG); ATerror("cannot execute toolbus executable, giving up!\n"); } } return NULL; }
void init_AIL_dict() { ATermList afuns, terms; _AIL_dict = (ATermList)ATreadFromBinaryString(_AIL_dict_baf, _AIL_dict_LEN); ATprotect((ATerm *)&_AIL_dict); afuns = (ATermList)ATelementAt(_AIL_dict, 0); AIL_afun0 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun1 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun2 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun3 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun4 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun5 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun6 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun7 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun8 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun9 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun10 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun11 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun12 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun13 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun14 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun15 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun16 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun17 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun18 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun19 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun20 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun21 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun22 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun23 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun24 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun25 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun26 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun27 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun28 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun29 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun30 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun31 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun32 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun33 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun34 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun35 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun36 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun37 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun38 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun39 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun40 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun41 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun42 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun43 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun44 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); AIL_afun45 = ATgetAFun((ATermAppl)ATgetFirst(afuns)); afuns = ATgetNext(afuns); terms = (ATermList)ATelementAt(_AIL_dict, 1); AIL_patternStatementListMany = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternStatementListSingle = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternStatementListEmpty = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternProgramProgram = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternArgLabel = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternArgAterm = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternArgCode = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternArgNumber = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternStatementInstruction = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternStatementLabelDef = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternInstructionWithArg = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternInstructionWithoutArg = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternSignatureListMany = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternSignatureListSingle = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternSignatureListEmpty = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternDefinitionDefault = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternSignatureWithoutPattern = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternSignatureWithPattern = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternPatternCode = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternPatternLabel = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternPatternAterm = ATgetFirst(terms); terms = ATgetNext(terms); AIL_patternPatternInt = ATgetFirst(terms); terms = ATgetNext(terms); }
int SG_Batch (int argc, char **argv) { ATerm parse_tree; parse_tree = SGparseFileUsingTable(program_name, parse_table_name, start_symbol, input_file_name, output_file_name); if (!SG_OUTPUT) { return 0; } if (!parse_tree) { ATwarning("%s: error in %s: unexpected error\n", program_name, input_file_name); return 2; } if (SGisParseError(parse_tree)) { ATermList errlist; ATerm errcode; AFun err; int c, line, col; errlist = (ATermList) ATgetArgument((ATermAppl) parse_tree, 0); errcode = ATgetArgument((ATermAppl) parse_tree, 1); c = ATgetInt((ATermInt) ATgetArgument(ATelementAt(errlist, 0), 0)); line = ATgetInt((ATermInt) ATgetArgument(ATelementAt(errlist, 1), 0)); col = ATgetInt((ATermInt) ATgetArgument(ATelementAt(errlist, 2), 0)); err = ATgetAFun(errcode); if (err == SG_EOF_Error_AFun) { ATwarning("%s: error in %s, line %d, col %d: end of file unexpected\n", program_name, input_file_name, line, col); } else if (err == SG_Plain_Error_AFun) { if (isprint(c)) { ATwarning("%s: error in %s, line %d, col %d: character `%c' (\\x%2.2x)" " unexpected\n", program_name, input_file_name, line, col, c, c); } else { ATwarning("%s: error in %s, line %d, col %d: character \\x%2.2x" " unexpected\n", program_name, input_file_name, line, col, c); } } else if (err == SG_Cycle_Error_AFun) { ATwarning("%s: error in %s, line %d, col %d: cycle detected, productions: %t\n", program_name, input_file_name, line, col, ATgetArgument(errcode, 0)); } else if (err == SG_Amb_Error_AFun) { int ambiescount = ATgetInt((ATermInt) ATgetArgument(errcode,0)); ATwarning("%s: error in %s, line %d, col %d: cannot represent %d ambiguit%s\n", program_name, input_file_name, line, col, ambiescount, (ambiescount > 1) ? "ies" : "y" ); } else if (err == SG_Too_Many_Ambiguities_Error_AFun) { ATwarning("%s: error in %s, line %d, col %d: too many ambiguities\n", program_name, input_file_name, line, col); } else { ATwarning("%s: error in %s, line %d, col %d: unknown error\n", program_name, input_file_name, line, col); } return 1; } else if(!SGisParseTree(parse_tree)) { ATwarning("%s: error: neither parse tree nor parse error for %s\n", program_name, input_file_name); return 1; } IF_VERBOSE( int nrambs; char *sort; nrambs = SGnrAmb(SG_NR_ASK); sort = SGsort(SG_GET, NULL); ATwarning("%s: %s parsed %s as sort %s, with %d ambiguit%s\n", program_name, parse_table_name, input_file_name, sort ? sort : "[undetermined]", nrambs, (nrambs==1)?"y":"ies"); );
static void doSerialize(A2PWriter writer, A2PType expected, ATerm value){ DKISIndexedSet sharedValues = writer->valueSharingMap; int valueHash = hashValue(value); int valueId = DKISget(sharedValues, (void*) value, (void*) expected, valueHash); /* TODO: Fix sharing (check types). */ if(valueId != -1){ writeByteToBuffer(writer->buffer, PDB_SHARED_FLAG); printInteger(writer->buffer, valueId); return; } switch(expected->id){ case PDB_VALUE_TYPE_HEADER: serializeUntypedTerm(writer, value); break; case PDB_BOOL_TYPE_HEADER: if(ATgetType(value) != AT_APPL){ fprintf(stderr, "Boolean didn't have AT_APPL type.\n"); exit(1); } writeBool(writer, (ATermAppl) value); break; case PDB_INTEGER_TYPE_HEADER: if(ATgetType(value) != AT_INT){ fprintf(stderr, "Integer didn't have AT_INT type.\n"); exit(1); } writeInteger(writer, (ATermInt) value); break; case PDB_DOUBLE_TYPE_HEADER: if(ATgetType(value) != AT_REAL){ fprintf(stderr, "Double didn't have AT_REAL type.\n"); exit(1); } writeDouble(writer, (ATermReal) value); break; case PDB_STRING_TYPE_HEADER: if(ATgetType(value) != AT_APPL || ATisQuoted(ATgetAFun((ATermAppl) value)) == ATfalse){ fprintf(stderr, "String didn't have 'quoted' AT_APPL type.\n"); ATabort(""); exit(1); } writeString(writer, (ATermAppl) value); break; case PDB_SOURCE_LOCATION_TYPE_HEADER: if(ATgetType(value) != AT_APPL){ fprintf(stderr, "Source location didn't have AT_APPL type.\n"); exit(1); } writeSourceLocation(writer, (ATermAppl) value); break; case PDB_NODE_TYPE_HEADER: if(ATgetType(value) != AT_APPL){ fprintf(stderr, "Node didn't have AT_APPL type.\n"); exit(1); } { ATermList annotations = (ATermList) ATgetAnnotations(value); if(annotations == NULL){ writeNode(writer, expected, (ATermAppl) value); }else{ if(((A2PNodeType) expected->theType)->declaredAnnotations == NULL){ fprintf(stderr, "Node term has annotations, but none are declared.\n"); exit(1); } writeAnnotatedNode(writer, expected, (ATermAppl) value, annotations); } } break; case PDB_TUPLE_TYPE_HEADER: if(ATgetType(value) != AT_APPL){ fprintf(stderr, "Tuple didn't have AT_APPL type.\n"); exit(1); } writeTuple(writer, expected, (ATermAppl) value); break; case PDB_LIST_TYPE_HEADER: if(ATgetType(value) != AT_LIST){ fprintf(stderr, "List didn't have AT_LIST type.\n"); exit(1); } writeList(writer, expected, (ATermList) value); break; case PDB_SET_TYPE_HEADER: if(ATgetType(value) != AT_LIST){ fprintf(stderr, "Set didn't have AT_LIST type.\n"); exit(1); } writeSet(writer, expected, (ATermList) value); break; case PDB_RELATION_TYPE_HEADER: if(ATgetType(value) != AT_LIST){ fprintf(stderr, "Relation didn't have AT_LIST type.\n"); exit(1); } writeRelation(writer, expected, (ATermList) value); break; case PDB_MAP_TYPE_HEADER: if(ATgetType(value) != AT_LIST){ fprintf(stderr, "Map didn't have AT_LIST type.\n"); exit(1); } writeMap(writer, expected, (ATermList) value); break; case PDB_CONSTRUCTOR_TYPE_HEADER: if(ATgetType(value) != AT_APPL){ fprintf(stderr, "Constructor didn't have AT_APPL type.\n"); exit(1); } { ATermList annotations = (ATermList) ATgetAnnotations(value); if(annotations == NULL){ writeConstructor(writer, expected, (ATermAppl) value); }else{ if(((A2PConstructorType) expected->theType)->declaredAnnotations == NULL){ fprintf(stderr, "Constructor term has annotations, but none are declared.\n"); exit(1); } writeAnnotatedConstructor(writer, expected, (ATermAppl) value, annotations); } } break; case PDB_ADT_TYPE_HEADER: writeADT(writer, expected, value); break; default: fprintf(stderr, "Unserializable type: %d\n.", expected->id); exit(1); } DKISstore(sharedValues, (void*) value, (void*) expected, valueHash); }
ATbool isConstant(ATerm term){ return (ATgetArity(ATgetAFun(term)) == 0); }