From 9a41b4db10ee40ac3a381f4dbbfd3cc2fa9014a6 Mon Sep 17 00:00:00 2001 From: johanknol Date: Thu, 13 Mar 2003 17:29:53 +0000 Subject: [PATCH] hack up const and volatile modifiers in type chains a bit git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2384 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCC.y | 1 - src/SDCCast.c | 45 ++++++++++++++++++--------------------------- src/SDCCglue.c | 2 -- src/SDCCicode.c | 28 ++++++++++++++++++---------- src/SDCCsymt.c | 31 ++++++++++++++++--------------- src/SDCCsymt.h | 15 ++++++++++----- src/SDCCval.c | 2 -- 7 files changed, 62 insertions(+), 62 deletions(-) diff --git a/src/SDCC.y b/src/SDCC.y index 24741ae5..16839f81 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -1009,7 +1009,6 @@ pointer DCL_TYPE($3) = POINTER ; break; case S_CODE: - DCL_PTR_CONST($3) = 1; DCL_TYPE($3) = CPOINTER ; break; case S_EEPROM: diff --git a/src/SDCCast.c b/src/SDCCast.c index ddad9125..093a9043 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -2061,9 +2061,6 @@ decorateType (ast * tree) } RRVAL (tree) = 1; COPYTYPE (TTYPE (tree), TETYPE (tree), LTYPE (tree)->next); - if (IS_PTR(LTYPE(tree))) { - SPEC_CONST (TETYPE (tree)) = DCL_PTR_CONST (LTYPE(tree)); - } return tree; /*------------------------------------------------------------------*/ @@ -2144,8 +2141,8 @@ 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))) - werror (E_CODE_WRITE, "++/--"); + if (!tree->initMode && IS_CONSTANT (TTYPE (tree))) + werror (E_CODE_WRITE, tree->opval.op==INC_OP ? "++" : "--"); if (tree->right) RLVAL (tree) = 1; @@ -2241,10 +2238,7 @@ decorateType (ast * tree) goto errorTreeReturn; } if (SPEC_SCLS (tree->left->etype) == S_CODE) - { - DCL_TYPE (p) = CPOINTER; - DCL_PTR_CONST (p) = port->mem.code_ro; - } + DCL_TYPE (p) = CPOINTER; else if (SPEC_SCLS (tree->left->etype) == S_XDATA) DCL_TYPE (p) = FPOINTER; else if (SPEC_SCLS (tree->left->etype) == S_XSTACK) @@ -2267,8 +2261,6 @@ decorateType (ast * tree) p->next = LTYPE (tree); TTYPE (tree) = p; TETYPE (tree) = getSpec (TTYPE (tree)); - DCL_PTR_CONST (p) = SPEC_CONST (TETYPE (tree)); - DCL_PTR_VOLATILE (p) = SPEC_VOLATILE (TETYPE (tree)); LLVAL (tree) = 1; TLVAL (tree) = 1; return tree; @@ -2401,7 +2393,6 @@ decorateType (ast * tree) TTYPE (tree) = copyLinkChain ((IS_PTR (LTYPE (tree)) || IS_ARRAY (LTYPE (tree))) ? LTYPE (tree)->next : NULL); TETYPE (tree) = getSpec (TTYPE (tree)); - SPEC_CONST (TETYPE (tree)) = DCL_PTR_CONST (LTYPE(tree)); return tree; } @@ -3099,12 +3090,12 @@ decorateType (ast * tree) RRVAL (tree) = 1; TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree)); - if (!tree->initMode && IS_CONSTANT (LETYPE (tree))) - werror (E_CODE_WRITE, " "); + if (!tree->initMode && IS_CONSTANT (LTYPE (tree))) + werror (E_CODE_WRITE, *tree->opval.op==MUL_ASSIGN ? "*=" : "/="); if (LRVAL (tree)) { - werror (E_LVALUE_REQUIRED, "*= or /="); + werror (E_LVALUE_REQUIRED, *tree->opval.op==MUL_ASSIGN ? "*=" : "/="); goto errorTreeReturn; } LLVAL (tree) = 1; @@ -3126,8 +3117,8 @@ decorateType (ast * tree) RRVAL (tree) = 1; TETYPE (tree) = getSpec (TTYPE (tree) = LTYPE (tree)); - if (!tree->initMode && IS_CONSTANT (LETYPE (tree))) - werror (E_CODE_WRITE, " "); + if (!tree->initMode && IS_CONSTANT (LTYPE (tree))) + werror (E_CODE_WRITE, "&= or |= or ^= or >>= or <<="); if (LRVAL (tree)) { @@ -3161,8 +3152,8 @@ decorateType (ast * tree) computeType (LTYPE (tree), RTYPE (tree))); - if (!tree->initMode && IS_CONSTANT (LETYPE (tree))) - werror (E_CODE_WRITE, " "); + if (!tree->initMode && IS_CONSTANT (LTYPE (tree))) + werror (E_CODE_WRITE, "-="); if (LRVAL (tree)) { @@ -3202,8 +3193,8 @@ decorateType (ast * tree) computeType (LTYPE (tree), RTYPE (tree))); - if (!tree->initMode && IS_CONSTANT (LETYPE (tree))) - werror (E_CODE_WRITE, " "); + if (!tree->initMode && IS_CONSTANT (LTYPE (tree))) + werror (E_CODE_WRITE, "+="); if (LRVAL (tree)) { @@ -3250,8 +3241,8 @@ decorateType (ast * tree) RRVAL (tree) = 1; LLVAL (tree) = 1; if (!tree->initMode ) { - if ((IS_SPEC(LETYPE(tree)) && IS_CONSTANT (LETYPE (tree)))) - werror (E_CODE_WRITE, " "); + if (IS_CONSTANT (LTYPE (tree))) + werror (E_CODE_WRITE, "="); } if (LRVAL (tree)) { @@ -4426,7 +4417,7 @@ skipall: } -#define INDENT(x,f) { int i ; for (i=0;i < x; i++) fprintf(f," "); } +#define INDENT(x,f) { int i ; fprintf (f, "%d:", tree->lineno); for (i=0;i < x; i++) fprintf(f," "); } /*-----------------------------------------------------------------*/ /* ast_print : prints the ast (for debugging purposes) */ /*-----------------------------------------------------------------*/ @@ -4916,14 +4907,14 @@ void ast_print (ast * tree, FILE *outfile, int indent) ast_print(tree->right,outfile,indent+2); return; case OR_ASSIGN: - fprintf(outfile,"ORASS(*=) (%p) type (",tree); + fprintf(outfile,"ORASS(|=) (%p) type (",tree); printTypeChain(tree->ftype,outfile); fprintf(outfile,")\n"); ast_print(tree->left,outfile,indent+2); ast_print(tree->right,outfile,indent+2); return; case XOR_ASSIGN: - fprintf(outfile,"XORASS(*=) (%p) type (",tree); + fprintf(outfile,"XORASS(^=) (%p) type (",tree); printTypeChain(tree->ftype,outfile); fprintf(outfile,")\n"); ast_print(tree->left,outfile,indent+2); @@ -4937,7 +4928,7 @@ void ast_print (ast * tree, FILE *outfile, int indent) ast_print(tree->right,outfile,indent+2); return; case LEFT_ASSIGN: - fprintf(outfile,"LSHFTASS(*=) (%p) type (",tree); + fprintf(outfile,"LSHFTASS(<<=) (%p) type (",tree); printTypeChain(tree->ftype,outfile); fprintf(outfile,")\n"); ast_print(tree->left,outfile,indent+2); diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 8dced77b..e72964cd 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -408,7 +408,6 @@ initPointer (initList * ilist, sym_link *toType) val->type = newLink (); if (SPEC_SCLS (expr->left->etype) == S_CODE) { DCL_TYPE (val->type) = CPOINTER; - DCL_PTR_CONST (val->type) = port->mem.code_ro; } else if (SPEC_SCLS (expr->left->etype) == S_XDATA) DCL_TYPE (val->type) = FPOINTER; @@ -467,7 +466,6 @@ initPointer (initList * ilist, sym_link *toType) val->type = newLink (); if (SPEC_SCLS (expr->right->etype) == S_CODE) { DCL_TYPE (val->type) = CPOINTER; - DCL_PTR_CONST (val->type) = port->mem.code_ro; } else if (SPEC_SCLS (expr->right->etype) == S_XDATA) DCL_TYPE (val->type) = FPOINTER; diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 9c37fe0a..32f913ae 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -845,14 +845,7 @@ isOperandVolatile (operand * op, bool chkTemp) if (IS_ITEMP (op) && !chkTemp) return 0; - opetype = getSpec (optype = operandType (op)); - - if (IS_PTR (optype) && DCL_PTR_VOLATILE (optype)) - return 1; - - if (IS_VOLATILE (opetype)) - return 1; - return 0; + return IS_VOLATILE(operandType(op)); } /*-----------------------------------------------------------------*/ @@ -2128,7 +2121,9 @@ aggrToPtr (sym_link * type, bool force) ptype = newLink (); ptype->next = type; - /* if the output class is generic */ + +#ifdef JWK + /* if the output class is code */ if ((DCL_TYPE (ptype) = PTR_TYPE (SPEC_OCLS (etype))) == CPOINTER) DCL_PTR_CONST (ptype) = port->mem.code_ro; @@ -2140,6 +2135,10 @@ aggrToPtr (sym_link * type, bool force) /* the variable was volatile then pointer to volatile */ if (IS_VOLATILE (etype)) DCL_PTR_VOLATILE (ptype) = 1; +#else + DCL_TYPE (ptype) = PTR_TYPE (SPEC_OCLS (etype)); +#endif + return ptype; } @@ -2152,11 +2151,11 @@ geniCodeArray2Ptr (operand * op) sym_link *optype = operandType (op); sym_link *opetype = getSpec (optype); +#ifdef JWK /* set the pointer depending on the storage class */ if ((DCL_TYPE (optype) = PTR_TYPE (SPEC_OCLS (opetype))) == CPOINTER) DCL_PTR_CONST (optype) = port->mem.code_ro; - /* if the variable was declared a constant */ /* then the pointer points to a constant */ if (IS_CONSTANT (opetype)) @@ -2165,6 +2164,10 @@ geniCodeArray2Ptr (operand * op) /* the variable was volatile then pointer to volatile */ if (IS_VOLATILE (opetype)) DCL_PTR_VOLATILE (optype) = 1; +#else + DCL_TYPE (optype) = PTR_TYPE (SPEC_OCLS (opetype)); +#endif + op->isaddr = 0; return op; } @@ -2451,6 +2454,7 @@ geniCodeAddressOf (operand * op) p = newLink (); p->class = DECLARATOR; +#ifdef JWK /* set the pointer depending on the storage class */ if ((DCL_TYPE (p) = PTR_TYPE (SPEC_OCLS (opetype))) == CPOINTER) DCL_PTR_CONST (p) = port->mem.code_ro; @@ -2461,6 +2465,10 @@ geniCodeAddressOf (operand * op) if (IS_VOLATILE (opetype)) DCL_PTR_VOLATILE (p) = 1; +#else + DCL_TYPE (p) = PTR_TYPE (SPEC_OCLS (opetype)); +#endif + p->next = copyLinkChain (optype); diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index b160c7f7..0dce6fa4 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -347,8 +347,6 @@ pointerTypes (sym_link * ptr, sym_link * type) storage class of the type */ if (IS_SPEC (type)) { - DCL_PTR_CONST (ptr) = SPEC_CONST (type); - DCL_PTR_VOLATILE (ptr) = SPEC_VOLATILE (type); switch (SPEC_SCLS (type)) { case S_XDATA: @@ -364,7 +362,6 @@ pointerTypes (sym_link * ptr, sym_link * type) DCL_TYPE (ptr) = POINTER; break; case S_CODE: - DCL_PTR_CONST (ptr) = port->mem.code_ro; DCL_TYPE (ptr) = CPOINTER; break; case S_EEPROM: @@ -457,22 +454,26 @@ addDecl (symbol * sym, int type, sym_link * p) } /* if the type is an unknown pointer and has - a tspec then take the storage class const & volatile + a tspec then take the const & volatile attribute from the tspec & make it those of this symbol */ + if (p && - !IS_SPEC (p) && - //DCL_TYPE (p) == UPOINTER && + IS_DECL (p) && + DCL_TYPE (p) == UPOINTER && DCL_TSPEC (p)) { + // only for declarators + wassert (IS_DECL(sym->type)); + if (!IS_SPEC (sym->etype)) { sym->etype = sym->etype->next = newLink (); sym->etype->class = SPECIFIER; } - SPEC_SCLS (sym->etype) = SPEC_SCLS (DCL_TSPEC (p)); - SPEC_CONST (sym->etype) = SPEC_CONST (DCL_TSPEC (p)); - SPEC_VOLATILE (sym->etype) = SPEC_VOLATILE (DCL_TSPEC (p)); + + DCL_PTR_CONST (sym->type) = SPEC_CONST (DCL_TSPEC (p)); + DCL_PTR_VOLATILE (sym->type) = SPEC_VOLATILE (DCL_TSPEC (p)); DCL_TSPEC (p) = NULL; } @@ -2096,12 +2097,12 @@ printTypeChain (sym_link * start, FILE * of) break; } } - /* search entry in list before "type" */ - for (search = start; search && search->next != type;) - search = search->next; - type = search; - if (type) - fputc (' ', of); + /* search entry in list before "type" */ + for (search = start; search && search->next != type;) + search = search->next; + type = search; + if (type) + fputc (' ', of); } if (nlr) fprintf (of, "\n"); diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index f1cc4de7..f49036fa 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -177,8 +177,8 @@ typedef struct declarator { DECLARATOR_TYPE dcl_type; /* POINTER,ARRAY or FUNCTION */ unsigned int num_elem; /* # of elems if type==array */ - short ptr_const:1; /* pointer is constant */ - short ptr_volatile:1; /* pointer is volatile */ + unsigned ptr_const:1; /* pointer is constant */ + unsigned ptr_volatile:1; /* pointer is volatile */ struct sym_link *tspec; /* pointer type specifier */ } declarator; @@ -203,7 +203,6 @@ typedef struct sym_link unsigned hasVargs:1; /* functions has varargs */ unsigned calleeSaves:1; /* functions uses callee save */ unsigned hasbody:1; /* function body defined */ - //unsigned ret:1; /* return statement for a function */ unsigned hasFcall:1; /* does it call other functions */ unsigned reent:1; /* function is reentrant */ unsigned naked:1; /* naked function */ @@ -414,7 +413,10 @@ symbol; #define IS_LONG(x) (IS_SPEC(x) && x->select.s._long) #define IS_UNSIGNED(x) (IS_SPEC(x) && x->select.s._unsigned) #define IS_TYPEDEF(x)(IS_SPEC(x) && x->select.s._typedef) -#define IS_CONSTANT(x) (IS_SPEC(x) && ( x->select.s._const == 1)) +#define IS_CONSTANT(x) (!x ? 0 : \ + IS_SPEC(x) ? \ + x->select.s._const == 1 : \ + x->select.d.ptr_const) #define IS_STRUCT(x) (IS_SPEC(x) && x->select.s.noun == V_STRUCT) #define IS_ABSOLUTE(x) (IS_SPEC(x) && x->select.s._absadr ) #define IS_REGISTER(x) (IS_SPEC(x) && SPEC_SCLS(x) == S_REGISTER) @@ -424,7 +426,10 @@ symbol; #define IS_VOID(x) (IS_SPEC(x) && x->select.s.noun == V_VOID) #define IS_CHAR(x) (IS_SPEC(x) && x->select.s.noun == V_CHAR) #define IS_EXTERN(x) (IS_SPEC(x) && x->select.s._extern) -#define IS_VOLATILE(x) (IS_SPEC(x) && x->select.s._volatile ) +#define IS_VOLATILE(x) (!x ? 0 : \ + IS_SPEC(x) ? \ + x->select.s._volatile : \ + x->select.d.ptr_volatile) #define IS_INTEGRAL(x) (IS_SPEC(x) && (x->select.s.noun == V_INT || \ x->select.s.noun == V_CHAR || \ x->select.s.noun == V_BIT || \ diff --git a/src/SDCCval.c b/src/SDCCval.c index 4a223058..b2a98996 100644 --- a/src/SDCCval.c +++ b/src/SDCCval.c @@ -1546,7 +1546,6 @@ valForArray (ast * arrExpr) if (SPEC_SCLS (arrExpr->left->etype) == S_CODE) { DCL_TYPE (val->type) = CPOINTER; - DCL_PTR_CONST (val->type) = port->mem.code_ro; } else if (SPEC_SCLS (arrExpr->left->etype) == S_XDATA) DCL_TYPE (val->type) = FPOINTER; @@ -1617,7 +1616,6 @@ valForStructElem (ast * structT, ast * elemT) if (SPEC_SCLS (structT->etype) == S_CODE) { DCL_TYPE (val->type) = CPOINTER; - DCL_PTR_CONST (val->type) = port->mem.code_ro; } else if (SPEC_SCLS (structT->etype) == S_XDATA) DCL_TYPE (val->type) = FPOINTER; -- 2.30.2