int condition() { Token op; int changeSpot = 0; if(token.sym == oddsym) { getToken(); expression(); //odd command emit(2, 0, 6); } else { expression(); if(!isRelation()) getError(8); op = token; getToken(); expression(); changeSpot = writeRelation(op.sym); } return changeSpot; }
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); }