/**** **** Definitions for typechk.c. ****/ #ifndef typeIncluded #define typeIncluded #include "parse-tree.h" /* * The representation of a type is a parse tree. See lecture notes for * discussion of this choice of type representation. */ typedef nodep TypeStruct; typedef struct node TypeNode; /* * Vars to hold base type structs. These vars are just for efficiency, so the * lookup only has to happen once at the beginning of type checking (in * InitBaseTypes). */ #ifdef USEWITHCPP extern "C" #endif TypeStruct IntType; #ifdef USEWITHCPP extern "C" #endif TypeStruct CardType; #ifdef USEWITHCPP extern "C" #endif TypeStruct RealType; #ifdef USEWITHCPP extern "C" #endif TypeStruct LongIntType; #ifdef USEWITHCPP extern "C" #endif TypeStruct LongRealType; #ifdef USEWITHCPP extern "C" #endif TypeStruct CharType; #ifdef USEWITHCPP extern "C" #endif TypeStruct BoolType; #ifdef USEWITHCPP extern "C" #endif TypeStruct StringType; #ifdef USEWITHCPP extern "C" #endif TypeStruct StringCharType; #ifdef USEWITHCPP extern "C" #endif TypeStruct IntLitType; #ifdef USEWITHCPP extern "C" #endif TypeStruct SymLitType; #ifdef USEWITHCPP extern "C" #endif TypeStruct NilType; /* * A fake parent entry for record symtabs. */ #ifdef USEWITHCPP extern "C" #endif struct Sym *ARecordEntry; /* * Global counter to hold running offset of static pool storage offset. All * module vars, whether global or local, are alloc'd in a single static pool. */ #ifdef USEWITHCPP extern "C" #endif int CurStaticOffset; /* * Counter to indicate when we're in a loop, in order to disallow exit stmts * except in loops. */ #ifdef USEWITHCPP extern "C" #endif int InLoop; /* * Value returned by upper-level type check functions. These return both a * size count, in the case of decls, and an error flag. */ typedef struct { int Size; bool Error; } *ChkStruct; /* * Visible type checking functions. */ #endif bool typechk( nodep t); bool chkModule( nodep t, int Offset); bool initModule( nodep t); void initSpecBody( nodep t); bool chkDecls( nodep t); bool chkStmts( nodep t); void chkPriority( nodep t, struct Sym *e); void chkImports( nodep t); void chkImportListItem(char*, bool, struct Symt*, nodep); bool InIdentList(char*, nodep); void chkExports( nodep t); void chkBlock( nodep t); void chkImpleModule( nodep t); TypeStruct chkExpr( nodep t, bool f, TypeStruct tt); TypeStruct chkConstExpr( nodep t); TypeStruct chkType( nodep t); void chkConstDecl( nodep t); void chkTypeDecl( nodep t); void chkVarDecl( nodep t); void chkProcDecl( nodep t); void chkParmDecls( nodep t); void chkModuleDecl( nodep t); TypeStruct chkProcCall( nodep t, TypeStruct tt); TypeStruct chkSpecialProc( struct Sym *p, nodep t); TypeStruct chkAssmnt( nodep t); bool isLVal( nodep t, bool assmnt); void chkIf( nodep t); void chkElseIf( nodep t); void chkCase( nodep t); void chkWhile( nodep t); void chkRepeat( nodep t); void chkLoop( nodep t); void chkFor( nodep t); void chkWith( nodep t); void chkReturn( nodep t); TypeStruct chkArithOp( nodep t, bool f); TypeStruct chkArithIntOp( nodep t, bool f); TypeStruct chkArithRealOp( nodep t, bool f); TypeStruct chkUnaryArithOp( nodep t, bool f); TypeStruct chkBoolOp( nodep t, bool f); TypeStruct chkNotOp( nodep t, bool f); TypeStruct chkRelOp( nodep t, bool f); TypeStruct chkEqOp( nodep t, bool f); TypeStruct chkAlmostEqOp( nodep t, bool f); TypeStruct chkInOp( nodep t, bool f); TypeStruct chkArrayRef( nodep t, bool f); TypeStruct chkRecordRef( nodep t, bool f); TypeStruct GetNthField(nodep fields, int n); TypeStruct chkPointerRef( nodep t, bool f); TypeStruct chkIdent( nodep t, bool f); TypeStruct chkIdentType( nodep t); TypeStruct chkEnumType( nodep t); TypeStruct chkSubrangeType( nodep t); int ComputeSubrangeBounds( nodep t); TypeStruct chkArrayType( nodep t); TypeStruct chkArrayType1( TypeStruct t, TypeStruct base, int level); int IndexSize( TypeStruct t, int *lbval, int *nubval); TypeStruct chkRecordType( nodep t); bool chkFieldListSeq( nodep t); bool chkPlainFieldList( nodep t); bool chkVariantPart( nodep t); bool chkCaseLabels( nodep cl, TypeStruct et, struct Symt* ctab, nodep stmts); TypeStruct chkSetType( nodep t); TypeStruct chkPointerType( nodep t); TypeStruct chkProcType( nodep t); bool compat( TypeStruct t1, TypeStruct t2); bool compat2( TypeStruct t1, TypeStruct t2); bool assmntCompat( TypeStruct lt, TypeStruct rt); bool stringCompat( TypeStruct at, TypeStruct st); bool procCompat( TypeStruct pt, TypeStruct dpt); bool arrayCompat( TypeStruct it, TypeStruct dt); bool parmCompat( struct Sym *fp, TypeStruct ap); #ifdef USEWITHCPP extern "C" #endif int TypeSize( TypeStruct t); void InitTypechk(); bool isNegInt( nodep t); TypeStruct BuildCompType( nodep t); TypeStruct BuildCompType1( nodep t); TypeStruct BuildAnd( nodep t); TypeStruct BuildAndOrFields( nodep t, int i, int* n, struct Symt** st, TokenType compop); nodep BuildRightField( nodep t, struct Symt** st, int i); void EnterAndField(nodep var, TypeStruct type, struct Symt** st, int i); nodep AllocFieldNode(nodep t); nodep AllocFieldNodeFromType(char* fname, TypeStruct type); TypeStruct BuildLeftField( nodep t, int *n, struct Symt** st); TypeStruct BuildOr( nodep t); TypeStruct BuildList( nodep t); TypeStruct BuildListFromBasetype( nodep t); TypeStruct BuildSubPart( nodep t, int* n); bool chkSpec(); void chkSpecBody( nodep t, int Offset); void chkObj( nodep t); void chkOp( nodep t); void chkObjPartsDecl( nodep t, struct Sym* sym); char* qidToString(nodep qid); void chkOpsDecl( nodep t); void chkEqnsDecl( nodep t); void chkObjAttrDecls( nodep t); void chkOpPartsDecl( nodep t, struct Sym* sym, unsigned int flags); void chkInsDecl( nodep t, struct Sym* sym); void chkOutsDecl( nodep t, struct Sym* sym); TypeStruct chkOrRef( nodep t, bool f); TypeStruct chkIfExpr( nodep t, bool f); bool isSubType( TypeStruct t1, TypeStruct t2); bool isMultValFcnType( TypeStruct t); bool oneLevelStructRecEquiv(); bool isIdentAtomNode(nodep t); bool isNameTypePair(nodep t); bool isOpaqueType(nodep t); bool isFullNameTypePair(nodep t); bool isList(nodep); bool isCoarityList(nodep t); bool isSymLit(nodep t); void chkPartsDecl( nodep t); void chkOpAttrDecls( nodep t, struct Sym* sym); TypeStruct BuildOpaqueType(nodep t); TypeStruct BuildNameTypePairType(nodep t); TypeStruct BuildLiteralType(nodep t); TypeStruct BuildAtomType(nodep t); TypeStruct BuildOrFetchSymLitType(nodep t); TypeStruct ResolveIdentType( TypeStruct t, /* Any type struct */ nodep errlocnode, /* Node for error message location */ bool doerror); /* True if error message should be issued */