what you give them. Help stamp out software-hoarding!
-------------------------------------------------------------------------*/
-%option noyywrap
-
-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>
#include "newalloc.h"
#include "dbuf.h"
-char *stringLiteral();
-char *currFname;
+#define TKEYWORD(token) return (isTargetKeyword(yytext) ? token :\
+ check_type())
extern int lineno, column;
-extern char *filename ;
-int mylineno = 1 ;
-void count() ;
-int process_pragma(char *);
-#undef yywrap
-
-#ifndef YYPROTO
-
-#ifdef YY_USE_PROTOS
-#define YY_PROTO(proto) proto
-#else
-#define YY_PROTO(proto) ()
-#endif
-
-#endif
-
-int yywrap YY_PROTO((void))
-{
- return(1);
-}
-
-static void yyunput (int, char *);
-
-static void my_unput(char c)
-{
- yyunput(c, (yytext_ptr));
-}
+extern char *filename;
-#define TKEYWORD(token) return (isTargetKeyword(yytext) ? token :\
- check_type(yytext))
-char *asmbuff=NULL;
-int asmbuffSize=0;
-char *asmp ;
-extern int check_type ();
- extern int isTargetKeyword ();
-extern int checkCurrFile (char *);
-extern int processPragma (char *);
-extern int printListing (int );
-struct optimize save_optimize ;
-struct options save_options ;
+/* global definitions */
+char *currFname;
+int mylineno = 1;
+
+/* local definitions */
+static struct dbuf_s asmbuff;
+
+/* forward declarations */
+static char *stringLiteral(void);
+static void count(void);
+static int process_pragma(char *);
+static int check_type(void);
+static int isTargetKeyword(char *s);
+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); }
"\n" { count(); }
[ \t\v\f] { count(); }
\\ {
- char ch=input();
- if (ch!='\n') {
- // that could have been removed by the preprocessor anyway
+ 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() ; }
/* 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(ch);
+ unput(ch);
}
else {
lineno = ++mylineno;
goto out;
if (ch != '\"') {
- my_unput(ch) ;
+ unput(ch) ;
goto out;
}
break;
return 0;
}
+int yywrap(void)
+{
+ if (!STACK_EMPTY(options_stack) || !STACK_EMPTY(optimize_stack))
+ werror(W_SAVE_RESTORE);
+
+ return 1;
+}
+
int yyerror(char *s)
{
fflush(stdout);
if (mylineno && filename) {
if(options.vc_err_style)
- fprintf(stdout,"\n%s(%d) : %s: token -> '%s' ; column %d\n",
+ fprintf(stderr,"\n%s(%d) : %s: token -> '%s' ; column %d\n",
filename,mylineno,
s,yytext,column);
else
- fprintf(stdout,"\n%s:%d: %s: token -> '%s' ; column %d\n",
+ fprintf(stderr,"\n%s:%d: %s: token -> '%s' ; column %d\n",
filename,mylineno,
s,yytext,column);
fatalError++;