From f05d7ab6ff8b14b0d3fde04d1338a9060dbfeb57 Mon Sep 17 00:00:00 2001 From: borutr Date: Mon, 18 Dec 2006 22:22:08 +0000 Subject: [PATCH] * src/SDCC.lex: (stringLiteral) fixed bug #1351710 * support/regression/tests/bug-1351710.c: added regression test git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4519 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 4 +- src/SDCC.lex | 69 +++++++++++++++++++------- support/regression/tests/bug-1351710.c | 29 +++++++++++ 3 files changed, 84 insertions(+), 18 deletions(-) create mode 100644 support/regression/tests/bug-1351710.c diff --git a/ChangeLog b/ChangeLog index 3057a89d..30655baf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,10 +3,12 @@ * src/SDCCutil.c: fixed a bug in (get_pragma_token) * src/pic16/main.c, src/SDCC.lex, src/z80/main.c: small cosmetic changes + * src/SDCC.lex: (stringLiteral) fixed bug #1351710 + * support/regression/tests/bug-1351710.c: added regression test 2006-12-18 Frieder Ferlemann - * doc/sdccman.lyx: added the long missed iCode table + * doc/sdccman.lyx: added the long missed iCode table "", added links to wiki 2006-12-17 Borut Razem diff --git a/src/SDCC.lex b/src/SDCC.lex index 6979cf32..d4a037e7 100644 --- a/src/SDCC.lex +++ b/src/SDCC.lex @@ -60,8 +60,8 @@ static char *stringLiteral(void); static void count(void); static int process_pragma(const char *); static int check_type(void); -static int isTargetKeyword(char *s); -static int checkCurrFile(char *s); +static int isTargetKeyword(const char *s); +static int checkCurrFile(const char *s); %} %x asm @@ -265,7 +265,7 @@ _?"_asm" { #endif -static int checkCurrFile (char *s) +static int checkCurrFile (const char *s) { int lNum; char *tptr; @@ -289,8 +289,8 @@ static int checkCurrFile (char *s) s = tptr; /* now see if we have a file name */ - while (*s != '\"' && *s) - s++; + while (*s != '"' && *s) + ++s; /* if we don't have a filename then */ /* set the current line number to */ @@ -303,20 +303,24 @@ static int checkCurrFile (char *s) /* if we have a filename then check */ /* if it is "standard in" if yes then */ /* get the currentfile name info */ - s++ ; + ++s; /* in c1mode fullSrcFileName is NULL */ if (fullSrcFileName && strncmp(s, fullSrcFileName, strlen(fullSrcFileName)) == 0) { lineno = mylineno = lNum; currFname = fullSrcFileName; - } else { - char *sb = s; - /* mark the end of the filename */ - while (*s != '"') s++; - *s = '\0'; - currFname = strdup (sb); - lineno = mylineno = lNum; + } + else { + const char *sb = s; + + /* find the end of the filename */ + while (*s && *s != '"') + ++s; + currFname = Safe_malloc(s - sb + 1); + memcpy(currFname, sb, s - sb); + currFname[s - sb] = '\0'; + lineno = mylineno = lNum; } filename = currFname ; return 0; @@ -408,7 +412,7 @@ static char *stringLiteral(void) /* find the next non whitespace character */ /* if that is a double quote then carry on */ dbuf_append(&dbuf, "\"", 1); /* Pass end of this string or substring to evaluator */ - while ((ch = input()) && (isspace(ch) || ch == '\\')) { + while ((ch = input()) && (isspace(ch) || ch == '\\' || ch == '#')) { switch (ch) { case '\\': if ((ch = input()) != '\n') { @@ -422,15 +426,46 @@ static char *stringLiteral(void) break; case '\n': - mylineno++; + lineno = ++mylineno; + column = 0; break; + + case '#': + if (0 == column) { + /* # at the beginning of the line: collect the entire line */ + struct dbuf_s linebuf; + const char *line; + + dbuf_init(&linebuf, STR_BUF_CHUNCK_LEN); + dbuf_append(&linebuf, "#", 1); + + while ((ch = input()) && ch != '\n') { + buf[0] = ch; + dbuf_append(&linebuf, buf, 1); + } + + if (ch == '\n') { + lineno = ++mylineno; + column = 0; + } + + line = dbuf_c_str(&linebuf); + + /* process the line */ + if (startsWith(line, "#pragma")) + process_pragma(line); + else + checkCurrFile(line); + + dbuf_destroy(&linebuf); + } } } if (!ch) goto out; - if (ch != '\"') { + if (ch != '"') { unput(ch); goto out; } @@ -1033,7 +1068,7 @@ static int process_pragma(const char *s) /* will return 1 if the string is a part of a target specific keyword */ -static int isTargetKeyword(char *s) +static int isTargetKeyword(const char *s) { int i; diff --git a/support/regression/tests/bug-1351710.c b/support/regression/tests/bug-1351710.c new file mode 100644 index 00000000..20147a56 --- /dev/null +++ b/support/regression/tests/bug-1351710.c @@ -0,0 +1,29 @@ +/* + bug-1351710.c +*/ + +#include + +const char * +const_str(void) +{ +return "A" + + + +/* just for testing, actually nop */ +#pragma save + + + + + +"B"; +#pragma restore +} + +void +testBug(void) +{ + const char *str = const_str(); +} -- 2.47.2