diff options
Diffstat (limited to 'src/constexp.l')
-rw-r--r-- | src/constexp.l | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/src/constexp.l b/src/constexp.l index b6b3c5c..eae8a3b 100644 --- a/src/constexp.l +++ b/src/constexp.l @@ -24,6 +24,7 @@ %{ #include "constexp.h" +#include "constexp_p.h" #include "cppvalue.h" #include "ce_parse.hpp" // generated header file #include "message.h" @@ -31,7 +32,6 @@ #define YY_NO_INPUT 1 #define YY_NO_UNISTD_H 1 - static const char *stateToString(int state); static int yyread(char *buf,int max_size,yyscan_t yyscanner); @@ -70,23 +70,23 @@ CONSTSUFFIX ([uU][lL]?[lL]?)|([lL][lL]?[uU]?) "(" { return TOK_LPAREN; } ")" { return TOK_RPAREN; } "'"(([^\'\n\r\\]+)|(\\(([ntvbrfa\\?'\"])|([0-9]+)|([xX][0-9a-fA-F]+))))"'" { - yyextra->g_strToken=yytext; + yyextra->strToken=yytext; return TOK_CHARACTER; } -0[0-7]*{CONSTSUFFIX}? { yyextra->g_strToken=yytext; +0[0-7]*{CONSTSUFFIX}? { yyextra->strToken=yytext; return TOK_OCTALINT; } -[1-9][0-9]*{CONSTSUFFIX}? { yyextra->g_strToken=yytext; +[1-9][0-9]*{CONSTSUFFIX}? { yyextra->strToken=yytext; return TOK_DECIMALINT; } -(0x|0X)[0-9a-fA-F]+{CONSTSUFFIX}? { yyextra->g_strToken=yytext+2; +(0x|0X)[0-9a-fA-F]+{CONSTSUFFIX}? { yyextra->strToken=yytext+2; return TOK_HEXADECIMALINT; } (([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+))([eE]([\-\+])?[0-9]+)?([fFlL])? { - yyextra->g_strToken=yytext; return TOK_FLOAT; + yyextra->strToken=yytext; return TOK_FLOAT; } ([0-9]+[eE])([\-\+])?[0-9]+([fFlL])? { - yyextra->g_strToken=yytext; return TOK_FLOAT; + yyextra->strToken=yytext; return TOK_FLOAT; } . \n @@ -97,43 +97,56 @@ static int yyread(char *buf,int max_size,yyscan_t yyscanner) { struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; int c=0; - while( c < max_size && yyextra->g_inputString[yyextra->g_inputPosition] ) + while( c < max_size && yyextra->inputString[yyextra->inputPosition] ) { - *buf = yyextra->g_inputString[yyextra->g_inputPosition++] ; + *buf = yyextra->inputString[yyextra->inputPosition++] ; c++; buf++; } return c; } +struct ConstExpressionParser::Private +{ + yyscan_t yyscanner; + struct constexpYY_state constexpYY_extra; +}; -static yyscan_t yyscanner; -static struct constexpYY_state constexpYY_extra; -bool parseconstexp(const char *fileName,int lineNr,const QCString &s) +ConstExpressionParser::ConstExpressionParser() { - constexpYYlex_init_extra(&constexpYY_extra, &yyscanner); - struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; + p = new Private; + constexpYYlex_init_extra(&p->constexpYY_extra, &p->yyscanner); +} + +ConstExpressionParser::~ConstExpressionParser() +{ + constexpYYlex_destroy(p->yyscanner); + delete p; +} + +bool ConstExpressionParser::parse(const char *fileName,int lineNr,const QCString &s) +{ + struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner; #ifdef FLEX_DEBUG yyset_debug(1,yyscanner); #endif - yyextra->g_constExpFileName = fileName; - yyextra->g_constExpLineNr = lineNr; - yyextra->g_inputString = s; - yyextra->g_inputPosition = 0; - constexpYYrestart( yyin, yyscanner ); + yyextra->constExpFileName = fileName; + yyextra->constExpLineNr = lineNr; + yyextra->inputString = s; + yyextra->inputPosition = 0; + constexpYYrestart( yyin, p->yyscanner ); printlex(yy_flex_debug, TRUE, __FILE__, fileName); //printf("Expression: '%s'\n",s.data()); - constexpYYparse(yyscanner); + constexpYYparse(p->yyscanner); //printf("Result: %ld\n",(long)g_resultValue); printlex(yy_flex_debug, FALSE, __FILE__, fileName); - bool result = (long)yyextra->g_resultValue!=0; + bool result = (long)yyextra->resultValue!=0; - constexpYYlex_destroy(yyscanner); return result; } |