/* * Predicates to chk various types. Done as macros for efficiency. */ #ifndef typepredsIncluded #define typepredsIncluded #include "parse-tree.h" #include "type.h" #define isInt(t) (t == IntType) #define isCard(t) (t == CardType) #define isReal(t) (t == RealType) #define isLongInt(t) (t == LongIntType) #define isLongReal(t) (t == LongRealType) #define isChar(t) (t == CharType) #define isBool(t) (t == BoolType) #define isString(t) ((t == StringType) or (t == StringCharType)) #define isStringOrStringLit(t) (isString(t) or isStringLit(t)) #define isStringLit(t) (isLiteralType(t) and \ (t->components.type.kind.lit.type == StringType)) #define isStringChar(t) (t == StringCharType) #define isEnum(t) (t and t->header.name == '(') #define isArray(t) (t and ((t->header.name == YARRAY) or \ (t->header.name == YLIST))) #define isSubrange(t) (t and t->header.name == '[') #define isSubrangeable(t) \ (isCard(t) or isInt(t) or isLongInt(t) or isChar(t) or isEnum(t)) #define isSubrangeOfInt(t) (t and (t->header.name == '[') and \ isInt(t->components.type.kind.subrange.basetype)) #define isSubrangeOfCard(t) (t and (t->header.name == '[') and \ isCard(t->components.type.kind.subrange.basetype)) #define isIntLit(t) (t == IntLitType) or \ (t and (t->header.name == '\'') and \ (t->components.type.kind.lit.type == IntType)) //#define isIntOrIntLit(t) (isIntLit(t) or (isInt(t))) #define isIntOrIntLit(t) (compat2(t,IntType)) #define isIntOrCardOrSubrangeOfEither(t) (isIntLit(t) or \ isInt(t) or isCard(t) or isSubrangeOfInt(t) or isSubrangeOfCard(t)) #define isNumeric(t) (isIntOrCardOrSubrangeOfEither(t) or isReal(t) \ or isLongInt(t) or isLongReal(t) or isIntLit(t)) #define isSubrangeOfEnum(t) (t and isSubrange(t) and \ isEnum(t->components.type.kind.subrange.basetype)) #define isSubrangeOfChar(t) (t and isSubrange(t) and \ isChar(t->components.type.kind.subrange.basetype)) #define isSubrangeOfBool(t) (t and isSubrange(t) and \ isBool(t->components.type.kind.subrange.basetype)) #define isProc(t) (t and (t->header.name == YOP)) #define isProcedure(t) (t and t->header.kind == PROC_CALL_NODE) #define isOp(t) (t and t->header.name == YOP) #define isDProc(t) (t and t->header.name == ')') #define isStringArray(t) (t and isArray(t) and \ isChar(t->components.type.kind.arraytype.basetype) and \ isOneDArray(t) and \ isZeroToNSubrangeBounded(t)) #define isOneDArray(t) (t and t->components.type.kind.arraytype.bounds-> \ components.decl.next == null) static TypeStruct b___; #define isZeroToNSubrangeBounded(t) \ (t and (isSubrange((b___ = t->components.type.kind.arraytype.bounds-> \ components.decl.kind.type.type))) and \ (isCard(b___->components.type.kind.subrange.basetype)) and \ (b___->components.type.kind.subrange.lowerval == 0)) #define isModule(t) (t and t->header.name == YMODULE) #define isRecord(t) (t and (t->header.name == YRECORD)) #define isTuple(t) (t and (t->header.name == YRECORD)) #define isTupleOrUnion(t) (t and (t->header.name == YRECORD) or \ (t->header.name == YOR)) #define isUnion(t) (t and (t->header.name == YOR)) #define isAnonUnion(t) (isUnion(t) and \ (t->components.type.kind.arraytype.anon_base = true)) #define isPointer(t) (t and t->header.name == YPOINTER) #define isSet(t) (t and t->header.name == YSET) #define isOrdered(t) (true) #define isEquatable(t) (true) #define isIndexWorthy(t) \ (isChar(t) or isBool(t) or isEnum(t) or isSubrange(t)) #define isCaseable(t) \ (isCard(t) or isInt(t) or isLongInt(t) or isIntLit(t) or isChar(t) \ or isBool(t) or isEnum(t) or isSubrange(t)) #define isQid(t) (t and (t->header.name == Yident) or (t->header.name == ',')) #define isNil(t) (t == NilType) #define isIdentType(t) (t and (t->header.name == Yident) /* and \ (t->components.type.kind.ident.type->header.kind == ATOM_NODE) */) #define isListType(t) (t and ((t->header.name == YLIST) or \ (t->header.name == YARRAY) or \ isOneTupleList(t))) #define isElemOf(t1,t2) (compat(t1, \ t2->components.type.kind.arraytype.basetype)) #define isTypeSym(sym) (sym and \ ((sym->Class == C_Obj) || (sym->Class == C_Type))) #define isOneTuple(t) (isRecord(t) and \ (t->components.type.kind.record.numfields == 1)) #define isOneTupleArray(t) (isOneTuple(t) and \ isArray(t->components.type.kind.record.fields-> \ components.decl.kind.field.type)) #define isOneTupleString(t) (isOneTuple(t) and \ isString(t->components.type.kind.record.fields-> \ components.decl.kind.field.type)) #define isOneTupleList(t) (isOneTuple(t) and \ ((t->components.type.kind.record.fields-> \ components.decl.kind.field.type->header.name == YLIST) or \ (t->components.type.kind.record.fields-> \ components.decl.kind.field.type->header.name == YARRAY))) #define isTopLevelExpr(t) (t and \ (t->header.kind == EXPR_LIST_NODE)) #define isSymlitType(t) (t and (t->header.kind == TYPE_NODE) and \ (t->header.name == '\'')) #define isLiteralType(t) (t and (t->header.kind == TYPE_NODE) and \ (t->header.name == '\'')) #endif