From 2513172db2942a364e8af4a0d21d0fb2de328af1 Mon Sep 17 00:00:00 2001 From: Adrian Negreanu Date: Thu, 11 Apr 2019 13:42:06 +0300 Subject: declinfo.l: enable reentrant * put the global variables in struct declinfoYY_state. * globally define yyscanner and declinfo_extra. these two should be per-thread. * add a new yyscan_t function parameter when these functions are referenced: - yyin, yyout, yyextra, yyleng, yytext, yylineno, yycolumn, and yy_flex_debug. - the macros BEGIN, YY_START, YYSTATE, yymore, unput, and yyless - the functions that deal with input buffers: yyrestart - others: yy_switch_to_buffer, yy_create_buffer, yy_delete_buffer, yy_flush_buffer, yypush_buffer_state, yypop_buffer_state, yy_scan_buffer, yy_scan_string, and yy_scan_bytes * add a new yyscan_t function parameter when globals are referenced, to get the yyextra out of the yyscanner. --- src/declinfo.l | 260 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 136 insertions(+), 124 deletions(-) diff --git a/src/declinfo.l b/src/declinfo.l index ade4168..696d000 100644 --- a/src/declinfo.l +++ b/src/declinfo.l @@ -18,6 +18,8 @@ %option prefix="declinfoYY" %option nounput %option noyywrap +%option reentrant +%option extra-type="struct declinfoYY_state *" %{ @@ -41,30 +43,32 @@ * * statics */ - -static const char * inputString; -static int inputPosition; -static QCString scope; -static QCString className; -static QCString classTempList; -static QCString funcTempList; -static QCString type; -static QCString name; -static QCString args; -static int sharpCount; -static bool classTempListFound; -static bool funcTempListFound; -static QCString exceptionString; -static bool insideObjC; +struct declinfoYY_state +{ + const char *inputString; + int inputPosition; + QCString scope; + QCString className; + QCString classTempList; + QCString funcTempList; + QCString type; + QCString name; + QCString args; + int sharpCount; + bool classTempListFound; + bool funcTempListFound; + QCString exceptionString; + bool insideObjC; +}; -static void addType(); -static void addTypeName(); -static int yyread(char *buf,int max_size); +static void addType(yyscan_t yyscanner); +static void addTypeName(yyscan_t yyscanner); +static int yyread(char *buf,int max_size, yyscan_t yyscanner); /* ----------------------------------------------------------------- */ #undef YY_INPUT -#define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size); +#define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size,yyscanner); %} B [ \t] @@ -83,17 +87,17 @@ ID "$"?([a-z_A-Z\x80-\xFF][a-z_A-Z0-9\x80-\xFF]*)|(@[0-9]+) %% "operator"/({B}*"["{B}*"]")* { // operator rule must be before {ID} rule - name += yytext; + yyextra->name += yytext; BEGIN(Operator); } {ID}{B}*"("{B}*{ID}{B}*")" { // Objective-C class categories - if (!insideObjC) + if (!yyextra->insideObjC) { REJECT; } else { - name += yytext; + yyextra->name += yytext; } } ([~!]{B}*)?{ID}/({B}*"["{B}*"]")* { // the []'s are for Java, @@ -101,180 +105,188 @@ ID "$"?([a-z_A-Z\x80-\xFF][a-z_A-Z0-9\x80-\xFF]*)|(@[0-9]+) // dimensional C++ arrays like A[][15] // the leading ~ is for a destructor // the leading ! is for a C++/CLI finalizer (see bug 456475 and 635198) - addTypeName(); - name += yytext; + addTypeName(yyscanner); + yyextra->name += yytext; } -{B}*"::"{B}* { // found a scope specifier - if (!scope.isEmpty()) +{B}*"::"{B}* { // found a yyextra->scope specifier + if (!yyextra->scope.isEmpty()) { - scope+="::"+name; // add name to scope + yyextra->scope+="::"+yyextra->name; // add yyextra->name to yyextra->scope } else { - scope = name.copy(); // scope becomes name + yyextra->scope = yyextra->name.copy(); // yyextra->scope becomes yyextra->name } - name.resize(0); + yyextra->name.resize(0); } {B}*":" { // Objective-C argument separator - name+=yytext; + yyextra->name+=yytext; } [*&]+ { - addType(); - type+=yytext; + addType(yyscanner); + yyextra->type+=yytext; } {B}+ { - addType(); + addType(yyscanner); } {B}*"("({ID}"::")*{B}*[&*]({B}*("const"|"volatile"){B}+)? { - addType(); + addType(yyscanner); QCString text=yytext; - type+=text.stripWhiteSpace(); + yyextra->type+=text.stripWhiteSpace(); } {B}*")" { - type+=")"; + yyextra->type+=")"; } {B}*"(" { // TODO: function pointers - args+="("; + yyextra->args+="("; BEGIN(ReadArgs); } {B}*"[" { - args+="["; + yyextra->args+="["; BEGIN(ReadArgs); } {B}*"<" { - name+="<"; - sharpCount=0; + yyextra->name+="<"; + yyextra->sharpCount=0; BEGIN(Template); } -