From 7bcf5c2d729ccd9c2bcd05b5f8033b1507707a74 Mon Sep 17 00:00:00 2001 From: johanknol Date: Sat, 23 Jun 2001 10:37:05 +0000 Subject: [PATCH] The newline in string constant. 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 | 66 ++++++++++++++++++++++++++---------------- support/Util/SDCCerr.c | 2 ++ support/Util/SDCCerr.h | 1 + 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/SDCC.lex b/src/SDCC.lex index d80995fb..365d56f2 100644 --- a/src/SDCC.lex +++ b/src/SDCC.lex @@ -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); + } + /* \ 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++; diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index db6d963d..5c27d41e 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -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" }, }; /* diff --git a/support/Util/SDCCerr.h b/support/Util/SDCCerr.h index a1e763d1..94d46170 100644 --- a/support/Util/SDCCerr.h +++ b/support/Util/SDCCerr.h @@ -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. -- 2.30.2