]> git.gag.com Git - fw/sdcc/commitdiff
use dbuf for "_asm" definitions; my_unput() replaced by unput()
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 7 Oct 2003 05:01:47 +0000 (05:01 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 7 Oct 2003 05:01:47 +0000 (05:01 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2926 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCC.lex
src/SDCC.y

index e74a0fb284d719d01b17136b484b810cebc8e4ea..1e78e64dc8bc3502359ef2c1d043889427de17cf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-10-06  Borut Razem <borut.razem@siol.net>
+
+       * src/SDCC.lex, src/SDCC.lex: use dbuf for "_asm" definitions;
+         my_unput() replaced by unput()
+
 2003-10-05 Bernhard Held <bernhard@bernhardheld.de>
 
        * src/SDCCloop.c (assignmentsToSym, loopInduction): cast argument of
index 367ff42a4362818729be5945aaf91f6ec3d1ab60..79db56a788479719e7ae9a283e72699ac8ffba71 100644 (file)
    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 <stdio.h>
 #include <string.h>
 #include <ctype.h>
@@ -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);
 }
-<asm>"_endasm" { 
+<asm>"_endasm" {
   count();
-  *asmp = '\0';
-  yylval.yyinline = strdup (asmbuff);
+  yylval.yyinline = dbuf_c_str(&asmbuff);
+  dbuf_detach(&asmbuff);
   BEGIN(INITIAL);
   return (INLINEASM);
 }
-<asm>.         { 
-  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];
+<asm>\n        {
+  count();
+  dbuf_append(&asmbuff, yytext, 1);
 }
-<asm>\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' ;
+<asm>.         {
+  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))
index 67b898624c35d68ddfa2980c700b4737ab135f10..2ef823c93c0e07a1a29af9226af9f376b788dc58 100644 (file)
@@ -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 <yychar> IDENTIFIER TYPE_NAME