* fixed GCC 4.4.0 mingw compilation:
[fw/sdcc] / src / SDCC.y
index e54f49e32d7a4253e3ae12476881bc62ccae6a5d..fa165cef8a7241af3357d437e5b64218ae986435 100644 (file)
@@ -198,7 +198,7 @@ function_attribute
 function_attributes
    :  USING constant_expr {
                         $$ = newLink(SPECIFIER) ;
-                        FUNC_REGBANK($$) = (int) floatFromVal(constExprValue($2,TRUE));
+                        FUNC_REGBANK($$) = (int) ulFromVal(constExprValue($2,TRUE));
                      }
    |  REENTRANT      {  $$ = newLink (SPECIFIER);
                         FUNC_ISREENT($$)=1;
@@ -520,14 +520,14 @@ declaration_specifiers
      else
        $$ = mergeSpec($1,$2, "type_specifier declaration_specifiers");
    }
-   | function_specifier                                    { $$ = $1; }
-   | function_specifier declaration_specifiers          { 
+   | function_specifier                             { $$ = $1; }
+   | function_specifier declaration_specifiers          {
      /* if the decl $2 is not a specifier */
      /* find the spec and replace it      */
      if ( !IS_SPEC($2)) {
        sym_link *lnk = $2 ;
        while (lnk && !IS_SPEC(lnk->next))
-        lnk = lnk->next;
+         lnk = lnk->next;
        lnk->next = mergeSpec($1,lnk->next, "function_specifier declaration_specifiers - skipped");
        $$ = $2 ;
      }
@@ -580,7 +580,7 @@ function_specifier
 Interrupt_storage
    : INTERRUPT { $$ = INTNO_UNSPEC ; }
    | INTERRUPT constant_expr
-        { int intno = (int) floatFromVal(constExprValue($2,TRUE));
+        { int intno = (int) ulFromVal(constExprValue($2,TRUE));
           if ((intno >= 0) && (intno <= INTNO_MAX))
             $$ = intno;
           else
@@ -598,7 +598,7 @@ type_specifier
            /* add this to the storage class specifier  */
            SPEC_ABSA($1) = 1;   /* set the absolute addr flag */
            /* now get the abs addr from value */
-           SPEC_ADDR($1) = (unsigned) floatFromVal(constExprValue($3,TRUE)) ;
+           SPEC_ADDR($1) = (unsigned int) ulFromVal(constExprValue($3,TRUE)) ;
         }
    ;
 
@@ -709,7 +709,7 @@ type_specifier2
             symbol *sym;
             sym_link   *p  ;
             sym = findSym(TypedefTab,NULL,$1) ;
-            $$ = p = copyLinkChain(sym->type);
+            $$ = p = copyLinkChain(sym ? sym->type : NULL);
             SPEC_TYPEDEF(getSpec(p)) = 0;
             ignoreTypedefType = 1;
          }
@@ -918,7 +918,7 @@ struct_declarator
    | ':' constant_expr  {
                            unsigned int bitsize;
                            $$ = newSymbol (genSymName(NestLevel),NestLevel) ;
-                           bitsize= (unsigned int) floatFromVal(constExprValue($2,TRUE));
+                           bitsize = (unsigned int) ulFromVal(constExprValue($2,TRUE));
                            if (bitsize > (port->s.int_size * 8)) {
                              bitsize = port->s.int_size * 8;
                              werror(E_BITFLD_SIZE, bitsize);
@@ -926,11 +926,12 @@ struct_declarator
                            if (!bitsize)
                              bitsize = BITVAR_PAD;
                            $$->bitVar = bitsize;
+                           $$->bitUnnamed = 1;
                         }
    | declarator ':' constant_expr
                         {
                           unsigned int bitsize;
-                          bitsize= (unsigned int) floatFromVal(constExprValue($3,TRUE));
+                          bitsize = (unsigned int) ulFromVal(constExprValue($3,TRUE));
                           if (bitsize > (port->s.int_size * 8)) {
                             bitsize = port->s.int_size * 8;
                             werror(E_BITFLD_SIZE, bitsize);
@@ -1028,7 +1029,7 @@ opt_assign_expr
                                 {
                                   werror(E_ENUM_NON_INTEGER);
                                   SNPRINTF(lbuff, sizeof(lbuff),
-                                          "%d",(int) floatFromVal(val));
+                                          "%d", (int) ulFromVal(val));
                                   val = constVal(lbuff);
                                 }
                               $$ = cenum = val ;
@@ -1036,11 +1037,11 @@ opt_assign_expr
    |                       {
                               if (cenum)  {
                                  SNPRINTF(lbuff, sizeof(lbuff),
-                                          "%d",(int) floatFromVal(cenum)+1);
+                                          "%d", (int) ulFromVal(cenum)+1);
                                  $$ = cenum = constVal(lbuff);
                               }
                               else {
-                                 $$ = cenum = constVal("0");
+                                 $$ = cenum = constCharVal(0);
                               }
                            }
    ;
@@ -1115,23 +1116,32 @@ declarator2
          }
    | declarator3 '[' constant_expr ']'
          {
-            sym_link   *p ;
-                        value *tval;
+            sym_link *p;
+            value *tval;
+            int size;
 
-            tval = constExprValue($3,TRUE);
+            tval = constExprValue($3, TRUE);
             /* if it is not a constant then Error  */
             p = newLink (DECLARATOR);
-            DCL_TYPE(p) = ARRAY ;
-            if ( !tval || (SPEC_SCLS(tval->etype) != S_LITERAL)) {
-               werror(E_CONST_EXPECTED) ;
-               /* Assume a single item array to limit the cascade */
-               /* of additional errors. */
-               DCL_ELEM(p) = 1;
-            }
-            else {
-               DCL_ELEM(p) = (int) floatFromVal(tval) ;
-            }
-            addDecl($1,0,p);
+            DCL_TYPE(p) = ARRAY;
+
+            if (!tval || (SPEC_SCLS(tval->etype) != S_LITERAL))
+              {
+                werror(E_CONST_EXPECTED);
+                /* Assume a single item array to limit the cascade */
+                /* of additional errors. */
+                size = 1;
+              }
+            else
+              {
+                if ((size = (int) ulFromVal(tval)) < 0)
+                  {
+                    werror(E_NEGATIVE_ARRAY_SIZE, $1->name);
+                    size = 1;
+                  }
+              }
+            DCL_ELEM(p) = size;
+            addDecl($1, 0, p);
          }
    ;
 
@@ -1194,40 +1204,40 @@ pointer
          }
    | unqualified_pointer type_specifier_list pointer
          {
-            $$ = $1 ;               
-            if (IS_SPEC($2) && DCL_TYPE($3) == UPOINTER) {
-                DCL_PTR_CONST($1) = SPEC_CONST($2);
-                DCL_PTR_VOLATILE($1) = SPEC_VOLATILE($2);
-                DCL_PTR_RESTRICT($1) = SPEC_RESTRICT($2);
-                switch (SPEC_SCLS($2)) {
-                case S_XDATA:
-                    DCL_TYPE($3) = FPOINTER;
-                    break;
-                case S_IDATA:
-                    DCL_TYPE($3) = IPOINTER ;
-                    break;
-                case S_PDATA:
-                    DCL_TYPE($3) = PPOINTER ;
-                    break;
-                case S_DATA:
-                    DCL_TYPE($3) = POINTER ;
-                    break;
-                case S_CODE:
-                    DCL_TYPE($3) = CPOINTER ;
-                    break;
-                case S_EEPROM:
-                    DCL_TYPE($3) = EEPPOINTER;
-                    break;
-                default:
-                  // this could be just "constant" 
-                  // werror(W_PTR_TYPE_INVALID);
-                    ;
-                }
-            }
-            else 
-                werror (W_PTR_TYPE_INVALID);
-            $$->next = $3 ;
-        }
+             $$ = $1 ;
+             if (IS_SPEC($2) && DCL_TYPE($3) == UPOINTER) {
+                 DCL_PTR_CONST($1) = SPEC_CONST($2);
+                 DCL_PTR_VOLATILE($1) = SPEC_VOLATILE($2);
+                 DCL_PTR_RESTRICT($1) = SPEC_RESTRICT($2);
+                 switch (SPEC_SCLS($2)) {
+                 case S_XDATA:
+                     DCL_TYPE($3) = FPOINTER;
+                     break;
+                 case S_IDATA:
+                     DCL_TYPE($3) = IPOINTER ;
+                     break;
+                 case S_PDATA:
+                     DCL_TYPE($3) = PPOINTER ;
+                     break;
+                 case S_DATA:
+                     DCL_TYPE($3) = POINTER ;
+                     break;
+                 case S_CODE:
+                     DCL_TYPE($3) = CPOINTER ;
+                     break;
+                 case S_EEPROM:
+                     DCL_TYPE($3) = EEPPOINTER;
+                     break;
+                 default:
+                   // this could be just "constant"
+                   // werror(W_PTR_TYPE_INVALID);
+                     ;
+                 }
+             }
+             else
+                 werror (W_PTR_TYPE_INVALID);
+             $$->next = $3 ;
+         }
    ;
 
 unqualified_pointer
@@ -1340,7 +1350,7 @@ abstract_declarator2
                                        value *val ;
                                        $$ = newLink (DECLARATOR);
                                        DCL_TYPE($$) = ARRAY ;
-                                       DCL_ELEM($$) = (int) floatFromVal(val = constExprValue($2,TRUE));
+                                       DCL_ELEM($$) = (int) ulFromVal(val = constExprValue($2,TRUE));
                                     }
    | abstract_declarator2 '[' ']'   {
                                        $$ = newLink (DECLARATOR);
@@ -1353,7 +1363,7 @@ abstract_declarator2
                                        value *val ;
                                        $$ = newLink (DECLARATOR);
                                        DCL_TYPE($$) = ARRAY ;
-                                       DCL_ELEM($$) = (int) floatFromVal(val = constExprValue($3,TRUE));
+                                       DCL_ELEM($$) = (int) ulFromVal(val = constExprValue($3,TRUE));
                                        $$->next = $1 ;
                                     }
    | '(' ')'                        { $$ = NULL;}
@@ -1541,6 +1551,8 @@ selection_statement
                            {
                               noLineno++ ;
                               $$ = createIf ($3, $6, $7 );
+                              $$->lineno = $3->lineno;
+                              $$->filename = $3->filename;
                               noLineno--;
                            }
    | SWITCH '(' expr ')'   {
@@ -1621,7 +1633,8 @@ iteration_statement
                            noLineno++ ;
                            $$ = createWhile ( $1, STACK_POP(continueStack),
                                               STACK_POP(breakStack), $3, $6 );
-                           $$->lineno = $1->lineDef ;
+                           $$->lineno = $1->lineDef;
+                           $$->filename = $1->fileDef;
                            noLineno-- ;
                          }
    | do statement   WHILE '(' expr ')' ';'
@@ -1630,7 +1643,8 @@ iteration_statement
                           noLineno++ ;
                           $$ = createDo ( $1 , STACK_POP(continueStack),
                                           STACK_POP(breakStack), $5, $2);
-                          $$->lineno = $1->lineDef ;
+                          $$->lineno = $1->lineDef;
+                          $$->filename = $1->fileDef;
                           noLineno-- ;
                         }
    | for '(' expr_opt   ';' expr_opt ';' expr_opt ')'  statement
@@ -1718,4 +1732,3 @@ identifier
    : IDENTIFIER   { $$ = newSymbol ($1,NestLevel) ; }
    ;
 %%
-