From aa38ff4a9307eb7974deb9c6c76b5dd566ac7adb Mon Sep 17 00:00:00 2001 From: borutr Date: Tue, 7 Oct 2003 05:01:47 +0000 Subject: [PATCH] use dbuf for "_asm" definitions; my_unput() replaced by unput() git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2926 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 5 +++ src/SDCC.lex | 99 ++++++++++++++++++++++------------------------------ src/SDCC.y | 6 ++-- 3 files changed, 49 insertions(+), 61 deletions(-) diff --git a/ChangeLog b/ChangeLog index e74a0fb2..1e78e64d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-10-06 Borut Razem + + * src/SDCC.lex, src/SDCC.lex: use dbuf for "_asm" definitions; + my_unput() replaced by unput() + 2003-10-05 Bernhard Held * src/SDCCloop.c (assignmentsToSym, loopInduction): cast argument of diff --git a/src/SDCC.lex b/src/SDCC.lex index 367ff42a..79db56a7 100644 --- a/src/SDCC.lex +++ b/src/SDCC.lex @@ -22,14 +22,14 @@ what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -D [0-9] -L [a-zA-Z_] -H [a-fA-F0-9] -E [Ee][+-]?{D}+ -FS (f|F|l|L) -IS (u|U|l|L)* -%{ +D [0-9] +L [a-zA-Z_] +H [a-fA-F0-9] +E [Ee][+-]?{D}+ +FS (f|F|l|L) +IS (u|U|l|L)* +%{ #include #include #include @@ -37,63 +37,51 @@ IS (u|U|l|L)* #include "newalloc.h" #include "dbuf.h" -static char *stringLiteral(void); -char *currFname; +#define TKEYWORD(token) return (isTargetKeyword(yytext) ? token :\ + check_type()) extern int lineno, column; extern char *filename; -int mylineno = 1; + +/* global definitions */ +char *currFname; +int mylineno = 1; + +/* local definitions */ +static struct optimize save_optimize; +static struct options save_options; +static struct dbuf_s asmbuff; + +/* forward declarations */ +static char *stringLiteral(void); static void count(void); static int process_pragma(char *); -static void my_unput(char c); - -#define TKEYWORD(token) return (isTargetKeyword(yytext) ? token :\ - check_type()) -char *asmbuff=NULL; -int asmbuffSize=0; -char *asmp ; static int check_type(void); static int isTargetKeyword(char *s); -static int checkCurrFile (char *s); -struct optimize save_optimize; -struct options save_options; +static int checkCurrFile(char *s); %} %x asm %% -"_asm" { - count(); - asmp = asmbuff = realloc (asmbuff, INITIAL_INLINEASM); - asmbuffSize=INITIAL_INLINEASM; - BEGIN(asm) ; +"_asm" { + count(); + assert(asmbuff.alloc == 0 && asmbuff.len == 0 && asmbuff.buf == NULL); + dbuf_init(&asmbuff, INITIAL_INLINEASM); + BEGIN(asm); } -"_endasm" { +"_endasm" { count(); - *asmp = '\0'; - yylval.yyinline = strdup (asmbuff); + yylval.yyinline = dbuf_c_str(&asmbuff); + dbuf_detach(&asmbuff); BEGIN(INITIAL); return (INLINEASM); } -. { - if (asmp-asmbuff >= asmbuffSize-2) { - /* increase the buffersize with 50% */ - int size=asmp-asmbuff; - asmbuffSize=asmbuffSize*3/2; - asmbuff = realloc (asmbuff, asmbuffSize); - asmp=asmbuff+size; - } - *asmp++ = yytext[0]; +\n { + count(); + dbuf_append(&asmbuff, yytext, 1); } -\n { - count(); - if (asmp-asmbuff >= asmbuffSize-3) { - /* increase the buffersize with 50% */ - int size=asmp-asmbuff; - asmbuffSize=asmbuffSize*3/2; - asmbuff = realloc (asmbuff, asmbuffSize); - asmp=asmbuff+size; - } - *asmp++ = '\n' ; +. { + dbuf_append(&asmbuff, yytext, 1); } "at" { count(); TKEYWORD(AT) ; } "auto" { count(); return(AUTO); } @@ -215,11 +203,11 @@ struct options save_options; "\n" { count(); } [ \t\v\f] { count(); } \\ { - char ch=input(); - if (ch!='\n') { + int ch = input(); + if (ch != '\n') { /* that could have been removed by the preprocessor anyway */ werror (W_STRAY_BACKSLASH, column); - my_unput(ch); + unput(ch); } } . { count() ; } @@ -362,12 +350,12 @@ 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 == '\\')) { switch (ch) { case '\\': if ((ch = input()) != '\n') { werror(W_STRAY_BACKSLASH, column); - my_unput((char)ch); + unput(ch); } else { lineno = ++mylineno; @@ -385,7 +373,7 @@ static char *stringLiteral(void) goto out; if (ch != '\"') { - my_unput((char)ch) ; + unput(ch) ; goto out; } break; @@ -641,11 +629,6 @@ static int isTargetKeyword(char *s) return 0; } -static void my_unput(char c) -{ - yyunput(c, (yytext_ptr)); -} - int yywrap(void) { if (!STACK_EMPTY(options_stack) || !STACK_EMPTY(optimize_stack)) diff --git a/src/SDCC.y b/src/SDCC.y index 67b89862..2ef823c9 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -66,12 +66,12 @@ bool uselessDecl = TRUE; symbol *sym ; /* symbol table pointer */ structdef *sdef; /* structure definition */ char yychar[SDCC_NAME_MAX+1]; - sym_link *lnk ; /* declarator or specifier */ + sym_link *lnk ; /* declarator or specifier */ int yyint; /* integer value returned */ value *val ; /* for integer constant */ initList *ilist; /* initial list */ - char *yyinline; /* inlined assembler code */ - ast *asts; /* expression tree */ + const char *yyinline; /* inlined assembler code */ + ast *asts; /* expression tree */ } %token IDENTIFIER TYPE_NAME -- 2.47.2