X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCast.c;h=1399fbd8b2ffa2fbcafed208873de860c078ef59;hb=c37413e10ff08713c0689e1a3ef1b90d8ad343aa;hp=0962481a8c8aaf5cc23b165b3ca6c1a1f18e77f7;hpb=a27e7a4d14e0da24074864d363eb08700d6893ed;p=fw%2Fsdcc diff --git a/src/SDCCast.c b/src/SDCCast.c index 0962481a..1399fbd8 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -47,7 +47,7 @@ int labelKey = 1; int noLineno = 0; int noAlloc = 0; -symbol *currFunc; +symbol *currFunc=NULL; static ast *createIval (ast *, sym_link *, initList *, ast *); static ast *createIvalCharPtr (ast *, sym_link *, ast *); static ast *optimizeCompare (ast *); @@ -78,7 +78,7 @@ newAst_ (unsigned type) ex = Safe_alloc ( sizeof (ast)); ex->type = type; - ex->lineno = (noLineno ? oldLineno : yylineno); + ex->lineno = (noLineno ? oldLineno : mylineno); ex->filename = currFname; ex->level = NestLevel; ex->block = currBlockno; @@ -110,14 +110,6 @@ newAst_LINK (sym_link * val) return ex; } -ast * -newAst_STMNT (unsigned val) -{ - ast *ex = newAst_ (EX_STMNT); - ex->opval.stmnt = val; - return ex; -} - /*-----------------------------------------------------------------*/ /* newNode - creates a new node */ /*-----------------------------------------------------------------*/ @@ -1211,14 +1203,14 @@ processBlockVars (ast * tree, int *stack, int action) ast *autoInit; if (action == ALLOCATE) - { + { *stack += allocVariables (tree->values.sym); autoInit = gatherAutoInit (tree->values.sym); - + /* if there are auto inits then do them */ if (autoInit) tree->left = newNode (NULLOP, autoInit, tree->left); - } + } else /* action is deallocate */ deallocLocal (tree->values.sym); } @@ -1275,7 +1267,7 @@ bool constExprTree (ast *cexpr) { return constExprTree(cexpr->right); } if (cexpr->opval.op==CAST) { - // jwk: cast ignored, maybe we should throw a warning here + // cast ignored, maybe we should throw a warning here? return constExprTree(cexpr->right); } if (cexpr->opval.op=='&') { @@ -1287,6 +1279,8 @@ bool constExprTree (ast *cexpr) { if (constExprTree(cexpr->left) && constExprTree(cexpr->right)) { return TRUE; } + case EX_OPERAND: + return IS_CONSTANT(operandType(cexpr->opval.oprnd)); } return FALSE; } @@ -2144,7 +2138,7 @@ decorateType (ast * tree) { sym_link *ltc = (tree->right ? RTYPE (tree) : LTYPE (tree)); COPYTYPE (TTYPE (tree), TETYPE (tree), ltc); - if (!tree->initMode && IS_CONSTANT (TTYPE (tree))) + if (!tree->initMode && IS_CONSTANT(TETYPE(tree))) werror (E_CODE_WRITE, tree->opval.op==INC_OP ? "++" : "--"); if (tree->right) @@ -2563,7 +2557,7 @@ decorateType (ast * tree) return tree; } LRVAL (tree) = 1; - TTYPE (tree) = LTYPE (tree); + TETYPE(tree) = getSpec (TTYPE (tree) = LTYPE (tree)); return tree; } @@ -2930,7 +2924,7 @@ decorateType (ast * tree) } /* if unsigned value < 0 then always false */ /* if (unsigned value) > 0 then (unsigned value) */ - if (SPEC_USIGN(LETYPE(tree)) && IS_LITERAL(RTYPE(tree)) && + if (SPEC_USIGN(LETYPE(tree)) && IS_LITERAL(RTYPE(tree)) && ((int) floatFromVal (valFromType (RETYPE (tree)))) == 0) { if (tree->opval.op == '<') { @@ -3124,7 +3118,7 @@ decorateType (ast * tree) RRVAL (tree) = 1; TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree)); - if (!tree->initMode && IS_CONSTANT (LTYPE (tree))) + if (!tree->initMode && IS_CONSTANT (LETYPE (tree))) werror (E_CODE_WRITE, "&= or |= or ^= or >>= or <<="); if (LRVAL (tree)) @@ -3159,7 +3153,7 @@ decorateType (ast * tree) computeType (LTYPE (tree), RTYPE (tree))); - if (!tree->initMode && IS_CONSTANT (LTYPE (tree))) + if (!tree->initMode && IS_CONSTANT (LETYPE (tree))) werror (E_CODE_WRITE, "-="); if (LRVAL (tree)) @@ -3200,7 +3194,7 @@ decorateType (ast * tree) computeType (LTYPE (tree), RTYPE (tree))); - if (!tree->initMode && IS_CONSTANT (LTYPE (tree))) + if (!tree->initMode && IS_CONSTANT (LETYPE (tree))) werror (E_CODE_WRITE, "+="); if (LRVAL (tree)) @@ -3232,7 +3226,6 @@ decorateType (ast * tree) { werror (E_TYPE_MISMATCH, "assignment", " "); printFromToType(RTYPE(tree),LTYPE(tree)); - //goto errorTreeReturn; } /* if the left side of the tree is of type void @@ -3248,7 +3241,7 @@ decorateType (ast * tree) RRVAL (tree) = 1; LLVAL (tree) = 1; if (!tree->initMode ) { - if (IS_CONSTANT (LTYPE (tree))) + if ((IS_SPEC(LETYPE(tree)) && IS_CONSTANT (LETYPE (tree)))) werror (E_CODE_WRITE, "="); } if (LRVAL (tree)) @@ -3283,12 +3276,15 @@ decorateType (ast * tree) if ((options.stackAuto || IFFUNC_ISREENT (LTYPE (tree))) && !IFFUNC_ISBUILTIN(LTYPE(tree))) { - //FUNC_ARGS(tree->left->ftype) = - //reverseVal (FUNC_ARGS(tree->left->ftype)); reverseParms (tree->right); } - TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree)->next); + if (IS_CODEPTR(LTYPE(tree))) { + TTYPE(tree) = LTYPE(tree)->next->next; + } else { + TTYPE(tree) = LTYPE(tree)->next; + } + TETYPE (tree) = getSpec (TTYPE (tree)); return tree; /*------------------------------------------------------------------*/ @@ -3330,7 +3326,7 @@ decorateType (ast * tree) if (!IS_VOID (currFunc->type->next) && tree->right == NULL) { - werror (E_VOID_FUNC, currFunc->name); + werror (W_VOID_FUNC, currFunc->name); goto errorTreeReturn; } @@ -3540,12 +3536,12 @@ createBlock (symbol * decl, ast * body) ast *ex; /* if the block has nothing */ - if (!body) + if (!body && !decl) return NULL; ex = newNode (BLOCK, NULL, body); ex->values.sym = decl; - + ex->right = ex->right; ex->level++; ex->lineno = 0; @@ -4318,7 +4314,7 @@ createFunction (symbol * name, ast * body) addSymChain (name); allocVariables (name); } - name->lastLine = yylineno; + name->lastLine = mylineno; currFunc = name; /* set the stack pointer */ @@ -4397,6 +4393,7 @@ skipall: /* dealloc the block variables */ processBlockVars (body, &stack, DEALLOCATE); + outputDebugStackSymbols(); /* deallocate paramaters */ deallocParms (FUNC_ARGS(name->type)); @@ -4411,8 +4408,8 @@ skipall: addSet (&operKeyReset, name); applyToSet (operKeyReset, resetParmKey); - if (options.debug) - cdbStructBlock (1, cdbFile); + if (options.debug) + cdbStructBlock(1); cleanUpLevel (LabelTab, 0); cleanUpBlock (StructTab, 1); @@ -4458,7 +4455,7 @@ void ast_print (ast * tree, FILE *outfile, int indent) value *args=FUNC_ARGS(tree->left->opval.val->type); fprintf(outfile,"FUNCTION (%s=%p) type (", tree->left->opval.val->name, tree); - printTypeChain (tree->ftype,outfile); + printTypeChain (tree->left->opval.val->type->next,outfile); fprintf(outfile,") args ("); do { if (arg) {