From 0f9e3f07676b5adf4d8dba63b83a68317a4ff450 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Fri, 5 Mar 2010 12:02:56 -0500 Subject: [PATCH] Cleanup flex compiles again - remove yyleng from preproc.cpp --- src/V3PreLex.h | 18 ++++++++++-------- src/V3PreLex.l | 5 +++++ src/V3PreProc.cpp | 40 ++++++++++++++++++++-------------------- src/flexfix | 2 -- 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/V3PreLex.h b/src/V3PreLex.h index 6c28b4ec1..7cfd21b98 100644 --- a/src/V3PreLex.h +++ b/src/V3PreLex.h @@ -84,22 +84,24 @@ # define yyerrorf V3PreLexerrorf #endif +#ifndef yyourleng +# define yyourleng V3PreLexourleng +# define yyourtext V3PreLexourtext +#endif + #ifndef YY_BUFFER_STATE struct yy_buffer_state; typedef struct yy_buffer_state *YY_BUFFER_STATE; # define YY_BUF_SIZE 16384 #endif -// Older flex'es don't have this defined, so make everyone happy -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - extern int yylex(); extern void yyrestart(FILE*); -extern char* yytext; -extern yy_size_t yyleng; + +// Accessors, because flex keeps changing the type of yyleng +extern char* yyourtext(); +extern size_t yyourleng(); +extern void yyourtext(const char* textp, size_t size); // Must call with static YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ); diff --git a/src/V3PreLex.l b/src/V3PreLex.l index bac2e7bab..6793a72db 100644 --- a/src/V3PreLex.l +++ b/src/V3PreLex.l @@ -33,6 +33,11 @@ V3PreLex* V3PreLex::s_currentLexp = NULL; // Current lexing point #define LEXP V3PreLex::s_currentLexp +// Accessors, because flex keeps changing the type of yyleng +char* yyourtext() { return yytext; } +size_t yyourleng() { return yyleng; } +void yyourtext(const char* textp, size_t size) { yytext=(char*)textp; yyleng=size; } + // Prevent conflicts from perl version static void linenoInc() {LEXP->incLineno();} static bool optPsl() { return V3PreProc::optPsl(); } diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index 192c128fb..12a0ee97c 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -683,7 +683,7 @@ int V3PreProcImp::getRawToken() { if (m_lineAdd) { m_lineAdd--; m_rawAtBol = true; - yytext=(char*)"\n"; yyleng=1; + yyourtext("\n",1); if (debug()) debugToken(VP_WHITE, "LNA"); return (VP_WHITE); } @@ -695,11 +695,11 @@ int V3PreProcImp::getRawToken() { if (!m_rawAtBol) rtncmt = "\n"+rtncmt; m_lineCmtNl = false; } - yytext=(char*)rtncmt.c_str(); yyleng=rtncmt.length(); + yyourtext(rtncmt.c_str(), rtncmt.length()); m_lineCmt = ""; - if (yyleng) m_rawAtBol = (yytext[yyleng-1]=='\n'); + if (yyourleng()) m_rawAtBol = (yyourtext()[yyourleng()-1]=='\n'); if (m_state==ps_DEFVALUE) { - V3PreLex::s_currentLexp->appendDefValue(yytext,yyleng); + V3PreLex::s_currentLexp->appendDefValue(yyourtext(),yyourleng()); goto next_tok; } else { if (debug()) debugToken(VP_TEXT, "LCM"); @@ -721,14 +721,14 @@ int V3PreProcImp::getRawToken() { goto next_tok; // Parse parent, or find the EOF. } - if (yyleng) m_rawAtBol = (yytext[yyleng-1]=='\n'); + if (yyourleng()) m_rawAtBol = (yyourtext()[yyourleng()-1]=='\n'); return tok; } } void V3PreProcImp::debugToken(int tok, const char* cmtp) { if (debug()>4) { - string buf = string (yytext, yyleng); + string buf = string (yyourtext(), yyourleng()); string::size_type pos; while ((pos=buf.find("\n")) != string::npos) { buf.replace(pos, 1, "\\n"); } while ((pos=buf.find("\r")) != string::npos) { buf.replace(pos, 1, "\\r"); } @@ -753,7 +753,7 @@ int V3PreProcImp::getToken() { if (tok==VP_COMMENT) { if (!m_off) { if (m_lexp->m_keepComments == KEEPCMT_SUB) { - string rtn; rtn.assign(yytext,yyleng); + string rtn; rtn.assign(yyourtext(),yyourleng()); comment(rtn); } else { return (tok); @@ -762,7 +762,7 @@ int V3PreProcImp::getToken() { // We're off or processed the comment specially. If there are newlines // in it, we also return the newlines as TEXT so that the linenumber // count is maintained for downstream tools - for (int len=0; lennextarg(refp->nextarg()+m_lexp->m_defValue); m_lexp->m_defValue=""; UINFO(4,"defarg++ "<nextarg()<args().push_back(refp->nextarg()); m_state = ps_DEFARG; m_lexp->pushStateDefArg(1); refp->nextarg(""); goto next_tok; - } else if (tok==VP_DEFARG && yyleng==1 && yytext[0]==')') { + } else if (tok==VP_DEFARG && yyourleng()==1 && yyourtext()[0]==')') { refp->args().push_back(refp->nextarg()); string out = defineSubst(refp); // Substitute in and prepare for next action @@ -932,7 +932,7 @@ int V3PreProcImp::getToken() { // we'll append it when we push the argument. break; } else if (tok==VP_SYMBOL || tok==VP_STRING || VP_TEXT || VP_WHITE || VP_PSL) { - string rtn; rtn.assign(yytext,yyleng); + string rtn; rtn.assign(yyourtext(),yyourleng()); refp->nextarg(refp->nextarg()+rtn); goto next_tok; } else { @@ -944,7 +944,7 @@ int V3PreProcImp::getToken() { case ps_INCNAME: { if (tok==VP_STRING) { m_state = ps_TOP; - m_lastSym.assign(yytext,yyleng); + m_lastSym.assign(yyourtext(),yyourleng()); UINFO(4,"Include "< m_state = ps_INCNAME; // Still m_lexp->pushStateIncFilename(); @@ -972,7 +972,7 @@ int V3PreProcImp::getToken() { if (tok==VP_STRING) { m_state = ps_TOP; if (!m_off) { - m_lastSym.assign(yytext,yyleng); + m_lastSym.assign(yyourtext(),yyourleng()); fileline()->v3error(m_lastSym); } goto next_tok; @@ -1025,7 +1025,7 @@ int V3PreProcImp::getToken() { case VP_DEFREF: { if (!m_off) { - string name; name.append(yytext+1,yyleng-1); + string name; name.append(yyourtext()+1,yyourleng()-1); UINFO(4,"DefRef "< V3PreProc::DEFINE_RECURSION_LEVEL_MAX) { fileline()->v3error("Recursive `define substitution: `"+name); @@ -1112,7 +1112,7 @@ string V3PreProcImp::getline() { while (NULL==(rtnp=strchr(m_lineChars.c_str(),'\n')) && !gotEof) { int tok = getToken(); if (debug()>4) { - string buf = string (yytext, yyleng); + string buf = string (yyourtext(), yyourleng()); string::size_type pos; while ((pos=buf.find("\n")) != string::npos) { buf.replace(pos, 1, "\\n"); } while ((pos=buf.find("\r")) != string::npos) { buf.replace(pos, 1, "\\r"); } @@ -1131,7 +1131,7 @@ string V3PreProcImp::getline() { m_lineChars.append(" psl "); } else { - m_lineChars.append(yytext,0,yyleng); + m_lineChars.append(yyourtext(),0,yyourleng()); } } diff --git a/src/flexfix b/src/flexfix index 3c85d89d8..8b494ccda 100755 --- a/src/flexfix +++ b/src/flexfix @@ -30,8 +30,6 @@ foreach my $line () { $line =~ s!for \( n = 0; n < max_size && !for ( n = 0; ((size_t)n < (size_t)max_size) && !g; # Fix flex 2.5.4 and GCC 4.0.2 under FLEX_DEBUG $line =~ s!--accepting rule at line %d !--accepting rule at line %ld !g; - # Fix flex 2.5.35 to match patches on Mac OS-X - $line =~ s!(extern |)int (${Opt_Prefix}leng;)!#ifndef YY_TYPEDEF_YY_SIZE_T\n#define YY_TYPEDEF_YY_SIZE_T\ntypedef size_t yy_size_t;\n#endif\n$1yy_size_t $2;!; # Fix compiler warning filenames $line =~ s!(#line \d+ ".*)_pretmp!$1!;