The newline in string constant.
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 23 Jun 2001 10:37:05 +0000 (10:37 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 23 Jun 2001 10:37:05 +0000 (10:37 +0000)
It throws a warning now and insert a \n

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

src/SDCC.lex
support/Util/SDCCerr.c
support/Util/SDCCerr.h

index d80995fbc2a8469723bd28e6e623d0ea0c544e91..365d56f27498e162b65761eccb9af0d863f11418 100644 (file)
@@ -305,9 +305,11 @@ void comment()
   char c, c1;
   
  loop:
-  while ((c = input()) != '*' && c)
-    if ( c == '\n')
-      yylineno++ ;
+  while ((c = input()) != '*' && c) {
+    if ( c == '\n') {
+      lineno=++yylineno;
+    }
+  }
   
   if (c && (c1 = input()) != '/') {
     unput(c1);
@@ -322,20 +324,19 @@ int plineIdx=0;
 
 void count()
 {
-       int i;
-       for (i = 0; yytext[i] != '\0'; i++)   {                         
-               if (yytext[i] == '\n')      {         
-                  column = 0;
-                  lineno = ++yylineno ;
-               }
-               else 
-                       if (yytext[i] == '\t')
-                               column += 8 - (column % 8);
-                       else
-                               column++;
-   }
-         
-   /* ECHO; */
+  int i;
+  for (i = 0; yytext[i] != '\0'; i++)   {                              
+    if (yytext[i] == '\n')      {         
+      column = 0;
+      lineno = ++yylineno ;
+    }
+    else 
+      if (yytext[i] == '\t')
+       column += 8 - (column % 8);
+      else
+       column++;
+  }
+  /* ECHO; */
 }
 
 int check_type()
@@ -351,7 +352,7 @@ int check_type()
        }
 }
 
-char strLitBuff[2048]                  ;
+char strLitBuff[2048]; // TODO: this is asking for the next bug :)
 
 /*
  * Change by JTV 2001-05-19 to not concantenate strings
@@ -373,14 +374,30 @@ char *stringLiteral () {
     
     /* if it is a \ then escape char's are allowed */
     if (ch == '\\') {
-      *str++ = ch; /* backslash in place */
-      *str++=input(); /* get the escape char, no check */
+      ch=input();
+      if (ch=='\r') {
+       // input() translates \n into \r\n
+       if ((ch=input())!='\n') {
+         unput (ch);
+       }
+       /* \<newline> is a continuator */
+       lineno=++yylineno;
+       continue;
+      }
+      *str++ = '\\'; /* backslash in place */
+      *str++ = ch; /* get the escape char, no further check */
       continue; /* carry on */
     }
     
-    /* if new line we have a new line break */
-    if (ch == '\n') {
-      yylineno++;
+    /* if new line we have a new line break, which is illegal */
+    if (ch == '\r') {
+      // input() translates \n into \r\n
+      if ((ch=input())!='\n') {
+       unput (ch);
+      }
+      werror (W_NEWLINE_IN_STRING);
+      *str++ = '\n';
+      lineno=++yylineno;
       continue;
     }
     
@@ -389,11 +406,10 @@ char *stringLiteral () {
     /* if that is a double quote then carry on    */
     if (ch == '\"') {
       *str++  = ch ; /* Pass end of this string or substring to evaluator */
-      
       while ((ch = input()) && (isspace(ch) || ch=='\\')) {
        switch (ch) {
        case '\\':
-         werror (W_STRAY_BACKSLASH, filename, yylineno);
+         //werror (W_STRAY_BACKSLASH)
          break;
        case '\n':
          yylineno++;
index db6d963d6f10b2e0f3573a24e4a430069290872d..5c27d41e032ffc66957a042f7247892cf27311fc 100644 (file)
@@ -353,6 +353,8 @@ struct
    "Option %s requires an argument." },
 { W_STRAY_BACKSLASH, ERROR_LEVEL_WARNING,
     "stray '\\' in program" },
+{ W_NEWLINE_IN_STRING, ERROR_LEVEL_WARNING,
+    "newline in string constant" },
 };
 
 /*
index a1e763d1757401bb86583a8680ff98797e65cd01..94d461706873ec24e29be81cb50fd0c15ef08e4d 100644 (file)
@@ -165,6 +165,7 @@ SDCCERR - SDCC Standard error handler
 #define W_EXESS_ARRAY_INITIALIZERS 147 /* too much initializers for array */
 #define        E_ARGUMENT_MISSING      148     /* Option requires an argument. */
 #define W_STRAY_BACKSLASH 149
+#define W_NEWLINE_IN_STRING 150 
 
 /** Describes the maximum error level that will be logged.  Any level
  *  includes all of the levels listed after it.