* support/Util/SDCCerr.c,
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 19 Dec 2003 09:24:17 +0000 (09:24 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 19 Dec 2003 09:24:17 +0000 (09:24 +0000)
* src/SDCCast.h,
* src/SDCCast.c (createCase, createDefault, decorateType),
* src/SDCClabel.c (labelUnreach),
* src/SDCC.y (labeled_statement, jump_statement): More improvements
to error messages.
* support/Util/SDCCerr.c (werrorfl): fixed a non-standard declaration
(with thanks to Stas Sergeev)
* device/include/time.h,
* device/lib/time.c (CheckTime): suppress unreachable code warning

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3063 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
device/include/time.h
device/lib/time.c
src/SDCC.y
src/SDCCast.c
src/SDCCast.h
src/SDCClabel.c
support/Util/SDCCerr.c

index a6e261eb259c608634a168656f7840dbf5c1d9b8..9fdc955703c042413eadf9a9967ce7bd6c1a0610 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2003-12-19 Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
+       * support/Util/SDCCerr.c,
+       * src/SDCCast.h,
+       * src/SDCCast.c (createCase, createDefault, decorateType),
+       * src/SDCClabel.c (labelUnreach),
+       * src/SDCC.y (labeled_statement, jump_statement): More improvements
+       to error messages.
+       * support/Util/SDCCerr.c (werrorfl): fixed a non-standard declaration
+       (with thanks to Stas Sergeev)
+       * device/include/time.h,
+       * device/lib/time.c (CheckTime): suppress unreachable code warning
+
 2003-12-18 Erik Petrich <epetrich@ivorytower.norman.ok.us>
 
        * src/SDCCast.c (createIvalCharPtr),
index 5f4e8854ec203a288ad184efd6c8c26666723c5e..c8e85bfbde42c765cf6d09ab5f0f32f0a1283980 100755 (executable)
@@ -1,7 +1,11 @@
 #ifndef TIME_H
 #define TIME_H
 
-#if 1
+#ifndef __TIME_UNSIGNED
+#define __TIME_UNSIGNED 1
+#endif
+
+#if __TIME_UNSIGNED
 struct tm
 {
   unsigned char tm_sec;                   /* Seconds.     [0-60]      */
index 8cb00d1fb281e2711e61237d877dbf132041e343..f1fc5473d620ac5b2fc2d33af0dbdd70f0152b65 100755 (executable)
@@ -69,18 +69,21 @@ static char ascTimeBuffer[32];
 static void CheckTime(struct tm *timeptr) {
     // we could do some normalization here, e.g.
     // change 40 october to 9 november
+    #if !__TIME_UNSIGNED
     if (timeptr->tm_sec<0) timeptr->tm_sec=0;
-    else if (timeptr->tm_sec>59) timeptr->tm_sec=59;
     if (timeptr->tm_min<0) timeptr->tm_min=0;
-    else if (timeptr->tm_min>59) timeptr->tm_min=59;
     if (timeptr->tm_hour<0) timeptr->tm_hour=0;
-    else if (timeptr->tm_hour>23) timeptr->tm_hour=23;
     if (timeptr->tm_wday<0) timeptr->tm_wday=0;
-    else if (timeptr->tm_wday>6) timeptr->tm_wday=6;
+    if (timeptr->tm_mon<0) timeptr->tm_mon=0;
+    #endif
+    
+    if (timeptr->tm_sec>59) timeptr->tm_sec=59;
+    if (timeptr->tm_min>59) timeptr->tm_min=59;
+    if (timeptr->tm_hour>23) timeptr->tm_hour=23;
+    if (timeptr->tm_wday>6) timeptr->tm_wday=6;
     if (timeptr->tm_mday<1) timeptr->tm_mday=1;
     else if (timeptr->tm_mday>31) timeptr->tm_mday=31;
-    if (timeptr->tm_mon<0) timeptr->tm_mon=0;
-    else if (timeptr->tm_mon>11) timeptr->tm_mon=11;
+    if (timeptr->tm_mon>11) timeptr->tm_mon=11;
     if (timeptr->tm_year<0) timeptr->tm_year=0;
 }
 
index dc02c2c7b8defb1e6531d44b234d28812a985d74..5d1473bfd60ab44075c5c8addd28e2edce5a1286 100644 (file)
@@ -1324,8 +1324,20 @@ critical_statement
 labeled_statement
 //   : identifier ':' statement          {  $$ = createLabel($1,$3);  }   
    : identifier ':'                    {  $$ = createLabel($1,NULL);  }   
-   | CASE constant_expr ':' statement  {  $$ = createCase(STACK_PEEK(swStk),$2,$4); }
-   | DEFAULT ':' statement             {  $$ = createDefault(STACK_PEEK(swStk),$3); }
+   | CASE constant_expr ':' statement
+     {
+       if (STACK_EMPTY(swStk))
+         $$ = createCase(NULL,$2,$4);
+       else
+         $$ = createCase(STACK_PEEK(swStk),$2,$4);
+     }
+   | DEFAULT { $<asts>$ = newNode(DEFAULT,NULL,NULL); } ':' statement
+     {
+       if (STACK_EMPTY(swStk))
+         $$ = createDefault(NULL,$<asts>2,$4);
+       else
+         $$ = createDefault(STACK_PEEK(swStk),$<asts>2,$4);
+     }
    ;
 
 start_block : '{' { STACK_PUSH(blockNum,currBlockno); currBlockno = ++blockNo ;  }
@@ -1528,7 +1540,7 @@ jump_statement
                            }
    | CONTINUE ';'          {  
        /* make sure continue is in context */
-       if (STACK_PEEK(continueStack) == NULL) {
+       if (STACK_EMPTY(continueStack) || STACK_PEEK(continueStack) == NULL) {
           werror(E_BREAK_CONTEXT);
           $$ = NULL;
        }
@@ -1540,7 +1552,7 @@ jump_statement
        }
    }
    | BREAK ';'             { 
-       if (STACK_PEEK(breakStack) == NULL) {
+       if (STACK_EMPTY(breakStack) || STACK_PEEK(breakStack) == NULL) {
           werror(E_BREAK_CONTEXT);
           $$ = NULL;
        } else {
index 098cedbadc3c59c0d7a53dc98f6cd8a951e59676..3209c0c9eaf80b0633ab362ff092279a8380c81d 100644 (file)
@@ -3834,7 +3834,7 @@ decorateType (ast * tree)
 
       if (compareType (currFunc->type->next, RTYPE (tree)) == 0)
        {
-         werror (W_RETURN_MISMATCH);
+         werrorfl (tree->filename, tree->lineno, W_RETURN_MISMATCH);
          printFromToType (RTYPE(tree), currFunc->type->next);
          goto errorTreeReturn;
        }
@@ -3843,7 +3843,7 @@ decorateType (ast * tree)
          && tree->right &&
          !IS_VOID (RTYPE (tree)))
        {
-         werror (E_FUNC_VOID);
+         werrorfl (tree->filename, tree->lineno, E_FUNC_VOID);
          goto errorTreeReturn;
        }
 
@@ -3878,7 +3878,7 @@ decorateType (ast * tree)
       /* the switch value must be an integer */
       if (!IS_INTEGRAL (LTYPE (tree)))
        {
-         werror (E_SWITCH_NON_INTEGER);
+         werrorfl (tree->filename, tree->lineno, E_SWITCH_NON_INTEGER);
          goto errorTreeReturn;
        }
       LRVAL (tree) = 1;
@@ -4135,7 +4135,7 @@ createCase (ast * swStat, ast * caseVal, ast * stmnt)
   /* then case is out of context            */
   if (!swStat)
     {
-      werror (E_CASE_CONTEXT);
+      werrorfl (caseVal->filename, caseVal->lineno, E_CASE_CONTEXT);
       return NULL;
     }
 
@@ -4143,14 +4143,14 @@ createCase (ast * swStat, ast * caseVal, ast * stmnt)
   /* if not a constant then error  */
   if (!IS_LITERAL (caseVal->ftype))
     {
-      werror (E_CASE_CONSTANT);
+      werrorfl (caseVal->filename, caseVal->lineno, E_CASE_CONSTANT);
       return NULL;
     }
 
   /* if not a integer than error */
   if (!IS_INTEGRAL (caseVal->ftype))
     {
-      werror (E_CASE_NON_INTEGER);
+      werrorfl (caseVal->filename, caseVal->lineno, E_CASE_NON_INTEGER);
       return NULL;
     }
 
@@ -4173,6 +4173,12 @@ createCase (ast * swStat, ast * caseVal, ast * stmnt)
        {
          pval->next = caseVal->opval.val;
        }
+      else if ((int) floatFromVal (val) == cVal)
+       {
+         werrorfl (caseVal->filename, caseVal->lineno, E_DUPLICATE_LABEL,
+                   "case");
+         return NULL;
+       }
       else
        {
          /* we found a value greater than */
@@ -4205,7 +4211,7 @@ createCase (ast * swStat, ast * caseVal, ast * stmnt)
 /* createDefault - creates the parse tree for the default statement */
 /*-----------------------------------------------------------------*/
 ast *
-createDefault (ast * swStat, ast * stmnt)
+createDefault (ast * swStat, ast * defaultVal, ast * stmnt)
 {
   char defLbl[SDCC_NAME_MAX + 1];
 
@@ -4213,7 +4219,14 @@ createDefault (ast * swStat, ast * stmnt)
   /* then case is out of context            */
   if (!swStat)
     {
-      werror (E_CASE_CONTEXT);
+      werrorfl (defaultVal->filename, defaultVal->lineno, E_CASE_CONTEXT);
+      return NULL;
+    }
+
+  if (swStat->values.switchVals.swDefault)
+    {
+      werrorfl (defaultVal->filename, defaultVal->lineno, E_DUPLICATE_LABEL,
+               "default");
       return NULL;
     }
 
index 589141f9cb7e26af80b92ee410bc48c92fc65a17..6747881dd1d131396cd92f93562b390249c79f7a 100644 (file)
@@ -191,7 +191,7 @@ ast *createFunction (symbol *, ast *);
 ast *createBlock (symbol *, ast *);
 ast *createLabel (symbol *, ast *);
 ast *createCase (ast *, ast *, ast *);
-ast *createDefault (ast *, ast *);
+ast *createDefault (ast *, ast *, ast *);
 ast *forLoopOptForm (ast *);
 ast *argAst (ast *);
 ast *resolveSymbols (ast *);
index de023c83af72b365183a238cba640e4a9d2fbdd4..718e75f90fd3f7cb30ab7d57bf7ffb90c3276be4 100644 (file)
@@ -384,6 +384,7 @@ labelUnreach (iCode * ic)
       /* statement is not a label           */
       if (loop->op == GOTO || loop->op == RETURN)
        {
+         int warn = 0;
 
          if (loop->next &&
              (loop->next->op == LABEL ||
@@ -405,15 +406,22 @@ labelUnreach (iCode * ic)
                  hTabDeleteItem (&labelRef, IC_LABEL (tic)->key, tic, DELETE_ITEM, NULL);
                  break;
                case IFX:
+                 warn = 1;
                  if (IC_TRUE (tic))
                    hTabDeleteItem (&labelRef, IC_TRUE (tic)->key, tic, DELETE_ITEM, NULL);
                  else
                    hTabDeleteItem (&labelRef, IC_FALSE (tic)->key, tic, DELETE_ITEM, NULL);
                  break;
+               default:
+                 warn = 1;
 
                }
            }
 
+         if (warn)
+           werrorfl (loop->next->filename, loop->next->lineno,
+                     W_CODE_UNREACH);
+
          /* now set up the pointers */
          loop->next = loop2;
          if (loop2)
index 31b21d522a01b7eddd5cddfcee9f2cb67612976a..9720ce5769507a6815d257d4b8d984b3afdc0027 100644 (file)
@@ -133,7 +133,7 @@ struct
 { E_ARG_COUNT, ERROR_LEVEL_ERROR,
    "Function was expecting more arguments" },
 { E_FUNC_EXPECTED, ERROR_LEVEL_ERROR,
-   "Function name expected '%s'.ANSI style declaration REQUIRED" },
+   "Function name expected '%s'. ANSI style declaration REQUIRED" },
 { E_PLUS_INVALID, ERROR_LEVEL_ERROR,
    "invalid operand '%s'" },
 { E_PTR_PLUS_PTR, ERROR_LEVEL_ERROR,
@@ -155,7 +155,7 @@ struct
 { E_BIT_ARRAY, ERROR_LEVEL_ERROR,
    "Array or Pointer to bit|sbit|sfr not allowed.'%s'" },
 { E_DUPLICATE_TYPEDEF, ERROR_LEVEL_ERROR,
-   "typedef/enum '%s' duplicate.Previous definiton Ignored" },
+   "typedef/enum '%s' duplicate. Previous definiton Ignored" },
 { E_ARG_TYPE, ERROR_LEVEL_ERROR,
    "Actual Argument type different from declaration %d" },
 { E_RET_VALUE, ERROR_LEVEL_ERROR,
@@ -165,7 +165,7 @@ struct
 { E_FUNC_DEF, ERROR_LEVEL_ERROR,
    "ANSI Style declaration needed" },
 { E_DUPLICATE_LABEL, ERROR_LEVEL_ERROR,
-   "Label name redefined '%s'" },
+   "Duplicate label '%s'" },
 { E_LABEL_UNDEF, ERROR_LEVEL_ERROR,
    "Label undefined '%s'" },
 { E_FUNC_VOID, ERROR_LEVEL_ERROR,
@@ -175,9 +175,9 @@ struct
 { W_RETURN_MISMATCH, ERROR_LEVEL_WARNING,
    "function return value mismatch" },
 { E_CASE_CONTEXT, ERROR_LEVEL_ERROR,
-   "'case/default' found without 'switch'.statement ignored" },
+   "'case/default' found without 'switch'. Statement ignored" },
 { E_CASE_CONSTANT, ERROR_LEVEL_ERROR,
-   "'case' expression not constant. statement ignored" },
+   "'case' expression not constant. Statement ignored" },
 { E_BREAK_CONTEXT, ERROR_LEVEL_ERROR,
    "'break/continue' statement out of context" },
 { E_SWITCH_AGGR, ERROR_LEVEL_ERROR,
@@ -211,9 +211,9 @@ struct
 { E_INCOMPAT_TYPES, ERROR_LEVEL_ERROR,
    "incompatible types" },
 { W_LOOP_ELIMINATE, ERROR_LEVEL_WARNING,
-   "'while' loop with 'zero' constant.loop eliminated" },
+   "'while' loop with 'zero' constant. Loop eliminated" },
 { W_NO_SIDE_EFFECTS, ERROR_LEVEL_WARNING,
-   "%s expression has NO side effects.expr eliminated" },
+   "%s expression has NO side effects. Expr eliminated" },
 { W_CONST_TOO_LARGE, ERROR_LEVEL_PEDANTIC,
    "constant value '%s', out of range." },
 { W_BAD_COMPARE, ERROR_LEVEL_WARNING,
@@ -509,11 +509,11 @@ void werrorfl (char *newFilename, int newLineno, int errNum, ...)
 {
     char *oldFilename = filename;
     int oldLineno = lineno;
+    va_list marker;
 
     filename = newFilename;
     lineno = newLineno;
 
-    va_list marker;
     va_start(marker,errNum);
     vwerror(errNum, marker);
     va_end(marker);