Cleanup flex compiles again - remove yyleng from preproc.cpp

This commit is contained in:
Wilson Snyder 2010-03-05 12:02:56 -05:00
parent 381972c923
commit 0f9e3f0767
4 changed files with 35 additions and 30 deletions

View File

@ -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 );

View File

@ -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(); }

View File

@ -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; len<yyleng; len++) { if (yytext[len]=='\n') m_lineAdd++; }
for (int len=0; len<yyourleng(); len++) { if (yyourtext()[len]=='\n') m_lineAdd++; }
goto next_tok;
}
if (tok==VP_LINE) {
@ -777,7 +777,7 @@ int V3PreProcImp::getToken() {
case ps_DEFNAME: {
if (tok==VP_SYMBOL) {
m_state = ps_TOP;
m_lastSym.assign(yytext,yyleng);
m_lastSym.assign(yyourtext(),yyourleng());
if (m_stateFor==VP_IFDEF
|| m_stateFor==VP_IFNDEF) {
bool enable = defExists(m_lastSym);
@ -879,11 +879,11 @@ int V3PreProcImp::getToken() {
m_state = ps_TOP;
// DEFVALUE is terminated by a return, but lex can't return both tokens.
// Thus, we emit a return here.
yytext=(char*)(newlines.c_str()); yyleng=newlines.length();
yyourtext(newlines.c_str(), newlines.length());
return(VP_WHITE);
}
case ps_DEFPAREN: {
if (tok==VP_TEXT && yyleng==1 && yytext[0]=='(') {
if (tok==VP_TEXT && yyourleng()==1 && yyourtext()[0]=='(') {
m_state = ps_DEFARG;
goto next_tok;
} else {
@ -899,13 +899,13 @@ int V3PreProcImp::getToken() {
V3DefineRef* refp = &(m_defRefs.top());
refp->nextarg(refp->nextarg()+m_lexp->m_defValue); m_lexp->m_defValue="";
UINFO(4,"defarg++ "<<refp->nextarg()<<endl);
if (tok==VP_DEFARG && yyleng==1 && yytext[0]==',') {
if (tok==VP_DEFARG && yyourleng()==1 && yyourtext()[0]==',') {
refp->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_lastSym<<endl);
// Drop leading and trailing quotes.
m_lastSym.erase(0,1);
@ -952,7 +952,7 @@ int V3PreProcImp::getToken() {
include(m_lastSym);
goto next_tok;
}
else if (tok==VP_TEXT && yyleng==1 && yytext[0]=='<') {
else if (tok==VP_TEXT && yyourleng()==1 && yyourtext()[0]=='<') {
// include <filename>
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 "<<name<<endl);
if (m_defDepth++ > 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());
}
}

View File

@ -30,8 +30,6 @@ foreach my $line (<STDIN>) {
$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!;