From 551b5c5f6e0c2592db0d1076bdd41c9822406406 Mon Sep 17 00:00:00 2001 From: borutr Date: Sat, 20 Jan 2007 15:41:17 +0000 Subject: [PATCH] * src/SDCC.lex, src/SDCCmain.c, sdc/SDCCglobl.h, doc/sdccman.lyx: implemented RFE #1470316: allow "$" in variable names git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4587 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- doc/sdccman.lyx | 23 ++++++++++++ src/SDCC.lex | 98 ++++++++++++++++++++++++++----------------------- src/SDCCglobl.h | 1 + src/SDCCmain.c | 6 +++ 4 files changed, 83 insertions(+), 45 deletions(-) diff --git a/doc/sdccman.lyx b/doc/sdccman.lyx index f410449d..eb16337e 100644 --- a/doc/sdccman.lyx +++ b/doc/sdccman.lyx @@ -8773,6 +8773,29 @@ status Collapsed Can be used for instance when using bank switching to put the const data in a bank. \layout List +\labelwidthstring 00.00.0000 + + +\series bold +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-fdollars-in-identifiers +\begin_inset LatexCommand \index{-\/-fdollars-in-identifiers} + +\end_inset + + +\series default + Permit '$' as an identifier character +\layout List \added_space_bottom bigskip \labelwidthstring 00.00.0000 diff --git a/src/SDCC.lex b/src/SDCC.lex index a338d9b0..06033d83 100644 --- a/src/SDCC.lex +++ b/src/SDCC.lex @@ -24,6 +24,7 @@ D [0-9] L [a-zA-Z_] +L_DOLL [a-zA-Z_$] H [a-fA-F0-9] E [Ee][+-]?{D}+ FS (f|F|l|L) @@ -55,6 +56,7 @@ static struct dbuf_s asmbuff; /* reusable _asm buffer */ /* forward declarations */ static const char *stringLiteral(void); static void count(void); +static void count_char(int); static int process_pragma(const char *); static int check_type(void); static int isTargetKeyword(const char *s); @@ -186,6 +188,15 @@ _?"_asm" { "inline" { count(); TKEYWORD99(INLINE); } "restrict" { count(); TKEYWORD99(RESTRICT); } {L}({L}|{D})* { count(); return(check_type()); } +{L_DOLL}({L_DOLL}|{D})* { + if (options.dollars_in_ident) + { + count(); + return(check_type()); + } + else + REJECT; +} 0[xX]{H}+{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); } 0[0-7]*{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); } [1-9]{D}*{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); } @@ -250,13 +261,14 @@ _?"_asm" { \\ { int ch = input(); - ++column; - if (ch != '\n') { - /* that could have been removed by the preprocessor anyway */ - werror (W_STRAY_BACKSLASH, column); - unput(ch); - --column; - } + if (ch == '\n') + count_char(ch); + else + { + /* that could have been removed by the preprocessor anyway */ + werror (W_STRAY_BACKSLASH, column); + unput(ch); + } } . { count(); } %% @@ -328,23 +340,31 @@ static int checkCurrFile (const char *s) return 0; } -static void count(void) +static void count_char(int ch) { - int i; - for (i = 0; yytext[i] != '\0'; i++) + switch (ch) { - if (yytext[i] == '\n') - { - column = 0; - ++lineno; - } - else - if (yytext[i] == '\t') - column += 8 - (column % 8); - else - column++; + case '\n': + column = 0; + ++lineno; + break; + + case '\t': + column += 8 - (column % 8); + break; + + default: + ++column; + break; } - /* ECHO; */ +} + +static void count(void) +{ + const char *p; + + for (p = yytext; *p; ++p) + count_char(*p); } static int check_type(void) @@ -384,7 +404,7 @@ static const char *stringLiteral(void) for (; ; ) { ch = input(); - ++column; + count_char(ch); if (ch == EOF) break; @@ -392,11 +412,11 @@ static const char *stringLiteral(void) { case '\\': /* if it is a \ then escape char's are allowed */ - if ((ch = input()) == '\n') + ch = input(); + count_char(ch); + if (ch == '\n') { /* \ is a continuator */ - ++lineno; - column = 0; } else { @@ -405,7 +425,6 @@ static const char *stringLiteral(void) if (ch == EOF) goto out; - ++column; buf[0] = '\\'; buf[1] = ch; dbuf_append(&dbuf, buf, 2); /* get the escape char, no further check */ @@ -416,8 +435,6 @@ static const char *stringLiteral(void) /* if new line we have a new line break, which is illegal */ werror(W_NEWLINE_IN_STRING); dbuf_append_char(&dbuf, '\n'); - ++lineno; - column = 0; break; case '"': @@ -427,31 +444,25 @@ static const char *stringLiteral(void) dbuf_append_char(&dbuf, '"'); /* Pass end of this string or substring to evaluator */ while ((ch = input()) && (isspace(ch) || ch == '\\' || ch == '#')) { - ++column; + count_char(ch); switch (ch) { case '\\': if ((ch = input()) != '\n') { - ++column; werror(W_STRAY_BACKSLASH, column); if (ch != EOF) - { - unput(ch); - --column; - } + unput(ch); + else + count_char(ch); } else - { - ++lineno; - column = 0; - } + count_char(ch); break; case '\n': - ++lineno; - column = 0; + count_char(ch); break; case '#': @@ -468,10 +479,7 @@ static const char *stringLiteral(void) dbuf_append_char(&linebuf, (char)ch); if (ch == '\n') - { - ++lineno; - column = 0; - } + count_char(ch); line = dbuf_c_str(&linebuf); @@ -492,9 +500,9 @@ static const char *stringLiteral(void) if (ch != '"') { unput(ch); - --column; goto out; } + count_char(ch); break; default: diff --git a/src/SDCCglobl.h b/src/SDCCglobl.h index 4c8062ea..11761f6d 100644 --- a/src/SDCCglobl.h +++ b/src/SDCCglobl.h @@ -255,6 +255,7 @@ struct options int no_std_crt0; /* for the z80/gbz80 do not link default crt0.o*/ int std_c99; /* enable C99 keywords/constructs */ int std_sdcc; /* enable SDCC extensions to C */ + int dollars_in_ident; /* zero means dollar signs are punctuation */ const char *code_seg; /* segment name to use instead of CSEG */ const char *const_seg; /* segment name to use instead of CONST */ /* sets */ diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 3460abbd..da935a7a 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -142,6 +142,7 @@ char buffer[PATH_MAX * 2]; #define OPTION_STD_SDCC99 "--std-sdcc99" #define OPTION_CODE_SEG "--codeseg" #define OPTION_CONST_SEG "--constseg" +#define OPTION_DOLLARS_IN_IDENT "--fdollars-in-identifiers" static const OPTION optionsTable[] = { @@ -176,6 +177,7 @@ optionsTable[] = { { 0, OPTION_STD_SDCC89, NULL, "Use C89 standard with SDCC extensions (default)" }, { 0, OPTION_STD_C99, NULL, "Use C99 standard only (incomplete)" }, { 0, OPTION_STD_SDCC99, NULL, "Use C99 standard with SDCC extensions (incomplete)" }, + { 0, OPTION_DOLLARS_IN_IDENT, &options.dollars_in_ident, "Permit '$' as an identifier character" }, { 0, NULL, NULL, "Code generation options"}, { 'm', NULL, NULL, "Set the port to use e.g. -mz80." }, @@ -2017,6 +2019,10 @@ preProcess (char **envp) addSet(&preArgvSet, buf); } + /* if using dollar signs in identifiers */ + if (options.dollars_in_ident) + addSet(&preArgvSet, Safe_strdup("--fdollars-in-identifiers")); + /* if using external stack define the macro */ if (options.useXstack) addSet(&preArgvSet, Safe_strdup("-DSDCC_USE_XSTACK")); -- 2.47.2