X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCC.lex;h=4f9b51887143ffac7c794b995ac355ef74005628;hb=c295cb1801e51adf80fe38235d41085aca7ca064;hp=3b537bbd198c6e885fedf527b55fbe0def7b46c2;hpb=aa19331a763254d88391d0d953725162a654da14;p=fw%2Fsdcc diff --git a/src/SDCC.lex b/src/SDCC.lex index 3b537bbd..4f9b5188 100644 --- a/src/SDCC.lex +++ b/src/SDCC.lex @@ -40,6 +40,11 @@ IS (u|U|l|L)* #define TKEYWORD(token) return (isTargetKeyword(yytext) ? token :\ check_type()) +#define TKEYWORDSDCC(token) return (options.std_sdcc && isTargetKeyword(yytext)\ + ? token : check_type()) + +#define TKEYWORD99(token) return (options.std_c99 ? token : check_type()) + extern int lineno, column; extern char *filename; @@ -61,18 +66,27 @@ static int checkCurrFile(char *s); %x asm %% -"_asm" { +_?"_asm" { count(); + if (!options.std_sdcc && yytext[1] != '_') + return check_type(); assert(asmbuff.alloc == 0 && asmbuff.len == 0 && asmbuff.buf == NULL); dbuf_init(&asmbuff, INITIAL_INLINEASM); BEGIN(asm); } -"_endasm" { +_?"_endasm" { count(); - yylval.yyinline = dbuf_c_str(&asmbuff); - dbuf_detach(&asmbuff); - BEGIN(INITIAL); - return (INLINEASM); + if (!options.std_sdcc && yytext[1] != '_') + { + dbuf_append(&asmbuff, yytext, strlen(yytext)); + } + else + { + yylval.yyinline = dbuf_c_str(&asmbuff); + dbuf_detach(&asmbuff); + BEGIN(INITIAL); + return (INLINEASM); + } } \n { count(); @@ -81,47 +95,75 @@ static int checkCurrFile(char *s); . { dbuf_append(&asmbuff, yytext, 1); } -"at" { count(); TKEYWORD(AT); } +"at" { count(); TKEYWORDSDCC(AT); } +"__at" { count(); TKEYWORD(AT); } "auto" { count(); return(AUTO); } -"bit" { count(); TKEYWORD(BIT); } +"bit" { count(); TKEYWORDSDCC(BIT); } +"__bit" { count(); TKEYWORD(BIT); } "break" { count(); return(BREAK); } "case" { count(); return(CASE); } "char" { count(); return(CHAR); } -"code" { count(); TKEYWORD(CODE); } +"code" { count(); TKEYWORDSDCC(CODE); } +"__code" { count(); TKEYWORD(CODE); } "const" { count(); return(CONST); } "continue" { count(); return(CONTINUE); } -"critical" { count(); TKEYWORD(CRITICAL); } -"data" { count(); TKEYWORD(DATA); } +"critical" { count(); TKEYWORDSDCC(CRITICAL); } +"__critical" { count(); TKEYWORD(CRITICAL); } +"data" { count(); TKEYWORDSDCC(DATA); } +"__data" { count(); TKEYWORD(DATA); } "default" { count(); return(DEFAULT); } "do" { count(); return(DO); } "double" { count(); werror(W_DOUBLE_UNSUPPORTED);return(FLOAT); } "else" { count(); return(ELSE); } "enum" { count(); return(ENUM); } "extern" { count(); return(EXTERN); } -"far" { count(); TKEYWORD(XDATA); } -"eeprom" { count(); TKEYWORD(EEPROM); } +"far" { count(); TKEYWORDSDCC(XDATA); } +"__far" { count(); TKEYWORD(XDATA); } +"eeprom" { count(); TKEYWORDSDCC(EEPROM); } +"__eeprom" { count(); TKEYWORD(EEPROM); } "float" { count(); return(FLOAT); } -"flash" { count(); TKEYWORD(CODE); } +"fixed16x16" { count(); TKEYWORDSDCC(FIXED16X16); } +"__fixed16x16" { count(); TKEYWORD(FIXED16X16); } +"flash" { count(); TKEYWORDSDCC(CODE); } +"__flash" { count(); TKEYWORD(CODE); } "for" { count(); return(FOR); } "goto" { count(); return(GOTO); } -"idata" { count(); TKEYWORD(IDATA); } +"idata" { count(); TKEYWORDSDCC(IDATA); } +"__idata" { count(); TKEYWORD(IDATA); } "if" { count(); return(IF); } "int" { count(); return(INT); } -"interrupt" { count(); return(INTERRUPT); } -"nonbanked" { count(); TKEYWORD(NONBANKED); } -"banked" { count(); TKEYWORD(BANKED); } +"interrupt" { count(); TKEYWORDSDCC(INTERRUPT); } +"__interrupt" { count(); TKEYWORD(INTERRUPT); } +"nonbanked" { count(); TKEYWORDSDCC(NONBANKED); } +"__nonbanked" { count(); TKEYWORD(NONBANKED); } +"banked" { count(); TKEYWORDSDCC(BANKED); } +"__banked" { count(); TKEYWORD(BANKED); } "long" { count(); return(LONG); } -"near" { count(); TKEYWORD(DATA); } -"pdata" { count(); TKEYWORD(PDATA); } -"reentrant" { count(); TKEYWORD(REENTRANT); } +"near" { count(); TKEYWORDSDCC(DATA); } +"__near" { count(); TKEYWORD(DATA); } +"pdata" { count(); TKEYWORDSDCC(PDATA); } +"__pdata" { count(); TKEYWORD(PDATA); } +"reentrant" { count(); TKEYWORDSDCC(REENTRANT); } +"__reentrant" { count(); TKEYWORD(REENTRANT); } +"shadowregs" { count(); TKEYWORDSDCC(SHADOWREGS); } +"__shadowregs" { count(); TKEYWORD(SHADOWREGS); } +"wparam" { count(); TKEYWORDSDCC(WPARAM); } +"__wparam" { count(); TKEYWORD(WPARAM); } "register" { count(); return(REGISTER); } "return" { count(); return(RETURN); } -"sfr" { count(); TKEYWORD(SFR); } -"sbit" { count(); TKEYWORD(SBIT); } +"sfr" { count(); TKEYWORDSDCC(SFR); } +"__sfr" { count(); TKEYWORD(SFR); } +"sfr16" { count(); TKEYWORDSDCC(SFR16); } +"__sfr16" { count(); TKEYWORD(SFR16); } +"sfr32" { count(); TKEYWORDSDCC(SFR32); } +"__sfr32" { count(); TKEYWORD(SFR32); } +"sbit" { count(); TKEYWORDSDCC(SBIT); } +"__sbit" { count(); TKEYWORD(SBIT); } "short" { count(); return(SHORT); } "signed" { count(); return(SIGNED); } "sizeof" { count(); return(SIZEOF); } -"sram" { count(); TKEYWORD(XDATA); } +"sram" { count(); TKEYWORDSDCC(XDATA); } +"__sram" { count(); TKEYWORD(XDATA); } "static" { count(); return(STATIC); } "struct" { count(); return(STRUCT); } "switch" { count(); return(SWITCH); } @@ -130,18 +172,24 @@ static int checkCurrFile(char *s); "unsigned" { count(); return(UNSIGNED); } "void" { count(); return(VOID); } "volatile" { count(); return(VOLATILE); } -"using" { count(); TKEYWORD(USING); } -"_naked" { count(); TKEYWORD(NAKED); } +"using" { count(); TKEYWORDSDCC(USING); } +"__using" { count(); TKEYWORD(USING); } +"_naked" { count(); TKEYWORDSDCC(NAKED); } +"__naked" { count(); TKEYWORD(NAKED); } "while" { count(); return(WHILE); } -"xdata" { count(); TKEYWORD(XDATA); } +"xdata" { count(); TKEYWORDSDCC(XDATA); } +"__xdata" { count(); TKEYWORD(XDATA); } "..." { count(); return(VAR_ARGS); } "__typeof" { count(); return TYPEOF; } "_JavaNative" { count(); TKEYWORD(JAVANATIVE); } -"_overlay" { count(); TKEYWORD(OVERLAY); } +"_overlay" { count(); TKEYWORDSDCC(OVERLAY); } +"__overlay" { count(); TKEYWORD(OVERLAY); } +"inline" { count(); TKEYWORD99(INLINE); } +"restrict" { count(); TKEYWORD99(RESTRICT); } {L}({L}|{D})* { count(); return(check_type()); } 0[xX]{H}+{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); } -0{D}+{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); } -{D}+{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); } '(\\.|[^\\'])+' { count();yylval.val = charVal (yytext); return(CONSTANT); /* ' make syntax highliter happy */ } {D}+{E}{FS}? { count(); yylval.val = constFloatVal(yytext);return(CONSTANT); } {D}*"."{D}+({E})?{FS}? { count(); yylval.val = constFloatVal(yytext);return(CONSTANT); } @@ -169,12 +217,12 @@ static int checkCurrFile(char *s); "==" { count(); return(EQ_OP); } "!=" { count(); return(NE_OP); } ";" { count(); return(';'); } -"{" { count(); NestLevel++ ; return('{'); } +"{" { count(); NestLevel++ ; ignoreTypedefType = 0; return('{'); } "}" { count(); NestLevel--; return('}'); } "," { count(); return(','); } ":" { count(); return(':'); } "=" { count(); return('='); } -"(" { count(); return('('); } +"(" { count(); ignoreTypedefType = 0; return('('); } ")" { count(); return(')'); } "[" { count(); return('['); } "]" { count(); return(']'); } @@ -236,7 +284,7 @@ static int checkCurrFile (char *s) /* get the line number */ lNum = strtol(s, &tptr, 10); - if (tptr == s || !isspace(*tptr)) + if (tptr == s || !isspace((unsigned char)*tptr)) return 0; s = tptr; @@ -296,8 +344,11 @@ static void count(void) static int check_type(void) { - /* check if it is in the typedef table */ - if (findSym(TypedefTab, NULL, yytext)) { + symbol *sym = findSym(SymbolTab, NULL, yytext); + + /* check if it is in the table as a typedef */ + if (!ignoreTypedefType && sym && IS_SPEC (sym->etype) + && SPEC_TYPEDEF (sym->etype)) { strncpyz(yylval.yychar, yytext, SDCC_NAME_MAX); return (TYPE_NAME); } @@ -309,7 +360,7 @@ static int check_type(void) /* * Change by JTV 2001-05-19 to not concantenate strings - * to support ANSI hex and octal escape sequences in string liteals + * to support ANSI hex and octal escape sequences in string literals */ static char *stringLiteral(void) @@ -411,8 +462,18 @@ enum pragma_id { P_EXCLUDE, P_NOIV, P_LOOPREV, - P_OVERLAY_ /* I had a strange conflict with P_OVERLAY while */ + P_OVERLAY_, /* I had a strange conflict with P_OVERLAY while */ /* cross-compiling for MINGW32 with gcc 3.2 */ + P_DISABLEWARN, + P_OPTCODESPEED, + P_OPTCODESIZE, + P_OPTCODEBALANCED, + P_STD_C89, + P_STD_C99, + P_STD_SDCC89, + P_STD_SDCC99, + P_CODESEG, + P_CONSTSEG }; @@ -421,6 +482,7 @@ enum pragma_id { STACK_DCL(options_stack, struct options *, SAVE_RESTORE_SIZE) STACK_DCL(optimize_stack, struct optimize *, SAVE_RESTORE_SIZE) +STACK_DCL(SDCCERRG_stack, struct SDCCERRG *, SAVE_RESTORE_SIZE) /* * cloneXxx functions should be updated every time a new set is @@ -449,7 +511,7 @@ static struct optimize *cloneOptimize(struct optimize *opt) { struct optimize *new_opt; - new_opt = Safe_malloc(sizeof (struct options)); + new_opt = Safe_malloc(sizeof (struct optimize)); /* clone scalar values */ *new_opt = *opt; @@ -457,6 +519,18 @@ static struct optimize *cloneOptimize(struct optimize *opt) return new_opt; } +static struct SDCCERRG *cloneSDCCERRG (struct SDCCERRG *val) +{ + struct SDCCERRG *new_val; + + new_val = Safe_malloc(sizeof (struct SDCCERRG)); + + /* clone scalar values */ + *new_val = *val; + + return new_val; +} + static void copyAndFreeOptions(struct options *dest, struct options *src) { /* delete dest sets */ @@ -465,7 +539,7 @@ static void copyAndFreeOptions(struct options *dest, struct options *src) /* not implemented yet: */ /* deleteSet(&dest->olaysSet); */ - /* dopy src to dest */ + /* copy src to dest */ *dest = *src; Safe_free(src); @@ -473,7 +547,15 @@ static void copyAndFreeOptions(struct options *dest, struct options *src) static void copyAndFreeOptimize(struct optimize *dest, struct optimize *src) { - /* dopy src to dest */ + /* copy src to dest */ + *dest = *src; + + Safe_free(src); +} + +static void copyAndFreeSDCCERRG(struct SDCCERRG *dest, struct SDCCERRG *src) +{ + /* copy src to dest */ *dest = *src; Safe_free(src); @@ -481,11 +563,14 @@ static void copyAndFreeOptimize(struct optimize *dest, struct optimize *src) static void doPragma(int op, char *cp) { + int i; + switch (op) { case P_SAVE: { STACK_PUSH(options_stack, cloneOptions(&options)); STACK_PUSH(optimize_stack, cloneOptimize(&optimize)); + STACK_PUSH(SDCCERRG_stack, cloneSDCCERRG(&_SDCCERRG)); } break; @@ -493,12 +578,16 @@ static void doPragma(int op, char *cp) { struct options *optionsp; struct optimize *optimizep; + struct SDCCERRG *sdccerrgp; optionsp = STACK_POP(options_stack); copyAndFreeOptions(&options, optionsp); optimizep = STACK_POP(optimize_stack); copyAndFreeOptimize(&optimize, optimizep); + + sdccerrgp = STACK_POP(SDCCERRG_stack); + copyAndFreeSDCCERRG(&_SDCCERRG, sdccerrgp); } break; @@ -532,6 +621,7 @@ static void doPragma(int op, char *cp) case P_LESSPEDANTIC: options.lessPedantic = 1; + setErrorLogLevel(ERROR_LEVEL_WARNING); break; case P_CALLEE_SAVES: @@ -557,6 +647,70 @@ static void doPragma(int op, char *cp) case P_OVERLAY_: break; /* notyet */ + + case P_DISABLEWARN: + if (sscanf(cp, "%d", &i) && (iprocess_pragma && !port->process_pragma(cp)) return 0; - for (i = 0; i < NELEM(pragma_tbl); i++) { - /* now compare and do what needs to be done */ - size_t len = strlen(pragma_tbl[i].name); + for (i = 0; i < NELEM(pragma_tbl); i++) + { + /* now compare and do what needs to be done */ + size_t len = strlen(pragma_tbl[i].name); - if (strncmp(cp, pragma_tbl[i].name, len) == 0) { - doPragma(pragma_tbl[i].id, cp + len); - return 0; + if (strncmp(cp, pragma_tbl[i].name, len) == 0) + { + if (pragma_tbl[i].deprecated != 0) + werror(W_DEPRECATED_PRAGMA, pragma_tbl[i].name); + + doPragma(pragma_tbl[i].id, s); + return 0; + } } - } - werror(W_UNKNOWN_PRAGMA,cp); + werror(W_UNKNOWN_PRAGMA, cp); return 0; } @@ -629,12 +826,30 @@ static int isTargetKeyword(char *s) if (port->keywords == NULL) return 0; - for (i = 0 ; port->keywords[i] ; i++ ) { - if (strcmp(port->keywords[i],s) == 0) - return 1; - } + + if (s[0] == '_' && s[1] == '_') + { + /* Keywords in the port's array have either 0 or 1 underscore, */ + /* so skip over the appropriate number of chars when comparing */ + for (i = 0 ; port->keywords[i] ; i++ ) + { + if (port->keywords[i][0] == '_' && + strcmp(port->keywords[i],s+1) == 0) + return 1; + else if (strcmp(port->keywords[i],s+2) == 0) + return 1; + } + } + else + { + for (i = 0 ; port->keywords[i] ; i++ ) + { + if (strcmp(port->keywords[i],s) == 0) + return 1; + } + } - return 0; + return 0; } int yywrap(void)