X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCast.c;h=25640f80b516a75ac0f34a730d41a3c8fbd5fdef;hb=d29d3bd3d0ba71cced0f534b9c08c41d042a5a38;hp=8399cca05515f48b8c302fd624a054cc044310d6;hpb=bd163ec21dcae5a2927f76a02b62a1c7936bd853;p=fw%2Fsdcc diff --git a/src/SDCCast.c b/src/SDCCast.c index 8399cca0..25640f80 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -46,7 +46,6 @@ int labelKey = 1; #define ALLOCATE 1 #define DEALLOCATE 2 -char buffer[1024]; int noLineno = 0; int noAlloc = 0; symbol *currFunc; @@ -610,7 +609,6 @@ processParms (ast * func, int *parmNumber, bool rightmost) { - int castError=0; sym_link *fetype = func->etype; /* if none of them exist */ @@ -746,36 +744,8 @@ processParms (ast * func, /* the parameter type must be at least castable */ - if (compareType (defParm->type, actParm->ftype) == 0) - { - castError++; - } - -#ifdef JWK20010916 - if (!IS_SPEC(defParm->type) && !IS_SPEC(actParm->ftype)) { - // now we have two pointers, check if they point to the same - sym_link *dtype=defParm->type, *atype=actParm->ftype; - do { - dtype=dtype->next; - atype=atype->next; - if ( - (dtype->next && !atype->next) || - (!dtype->next && atype->next) || - compareType (dtype, atype)!=1) { - castError++; - } - } while (dtype->next && atype->next); - if (IS_SPEC(dtype) && IS_SPEC(atype)) { - // ok so far, we have two etypes, they must have the same SCLASS - if (SPEC_SCLS(dtype)!=SPEC_SCLS(atype)) { - castError++; - } - } - } -#endif - - if (castError) { - werror (W_INCOMPAT_CAST); + if (compareType (defParm->type, actParm->ftype) == 0) { + werror (E_INCOMPAT_TYPES); fprintf (stderr, "type --> '"); printTypeChain (actParm->ftype, stderr); fprintf (stderr, "' "); @@ -1136,7 +1106,7 @@ gatherAutoInit (symbol * autoChain) /* insert the symbol into the symbol table */ /* with level = 0 & name = rname */ newSym = copySymbol (sym); - addSym (SymbolTab, newSym, newSym->name, 0, 0, 1); + addSym (SymbolTab, newSym, newSym->rname, 0, 0, 1); /* now lift the code to main */ if (IS_AGGREGATE (sym->type)) @@ -1250,6 +1220,7 @@ processBlockVars (ast * tree, int *stack, int action) /*-----------------------------------------------------------------*/ /* constExprValue - returns the value of a constant expression */ +/* or NULL if it is not a constant expression */ /*-----------------------------------------------------------------*/ value * constExprValue (ast * cexpr, int check) @@ -2111,7 +2082,7 @@ decorateType (ast * tree) { sym_link *ltc = (tree->right ? RTYPE (tree) : LTYPE (tree)); COPYTYPE (TTYPE (tree), TETYPE (tree), ltc); - if (!tree->initMode && IS_CONSTANT (TETYPE (tree))) + if (!tree->initMode && IS_CONSTANT(TETYPE(tree))) werror (E_CODE_WRITE, "++/--"); if (tree->right) @@ -2761,6 +2732,7 @@ decorateType (ast * tree) /* make sure the type is complete and sane */ checkTypeSanity(LETYPE(tree), "(cast)"); +#if 0 /* if the right is a literal replace the tree */ if (IS_LITERAL (RETYPE (tree))) { if (!IS_PTR (LTYPE (tree))) { @@ -2772,7 +2744,8 @@ decorateType (ast * tree) tree->right = NULL; TTYPE (tree) = tree->opval.val->type; tree->values.literalFromCast = 1; - } else if (IS_GENPTR(LTYPE(tree)) && !IS_PTR(RTYPE(tree))) { + } else if (IS_GENPTR(LTYPE(tree)) && !IS_PTR(RTYPE(tree)) && + ((int)floatFromVal(valFromType(RETYPE(tree)))) !=0 ) /* special case of NULL */ { sym_link *rest = LTYPE(tree)->next; werror(W_LITERAL_GENERIC); TTYPE(tree) = newLink(); @@ -2788,6 +2761,22 @@ decorateType (ast * tree) TTYPE (tree) = LTYPE (tree); LRVAL (tree) = 1; } +#else + /* if the right is a literal replace the tree */ + if (IS_LITERAL (RETYPE (tree)) && !IS_PTR (LTYPE (tree))) { + tree->type = EX_VALUE; + tree->opval.val = + valCastLiteral (LTYPE (tree), + floatFromVal (valFromType (RETYPE (tree)))); + tree->left = NULL; + tree->right = NULL; + TTYPE (tree) = tree->opval.val->type; + tree->values.literalFromCast = 1; + } else { + TTYPE (tree) = LTYPE (tree); + LRVAL (tree) = 1; + } +#endif TETYPE (tree) = getSpec (TTYPE (tree)); @@ -3117,22 +3106,13 @@ decorateType (ast * tree) fprintf (stderr, "'\n"); } - /* extra checks for pointer types */ - if (IS_PTR (LTYPE (tree)) && IS_PTR (RTYPE (tree)) && - !IS_GENPTR (LTYPE (tree))) - { - if (DCL_TYPE (LTYPE (tree)) != DCL_TYPE (RTYPE (tree))) - werror (W_PTR_ASSIGN); - } - TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree)); RRVAL (tree) = 1; LLVAL (tree) = 1; if (!tree->initMode ) { - if (IS_CONSTANT (LETYPE (tree))) { - werror (E_CODE_WRITE, " "); - } + if ((IS_SPEC(LETYPE(tree)) && IS_CONSTANT (LETYPE (tree)))) + werror (E_CODE_WRITE, " "); } if (LRVAL (tree)) {