void SceneParser::acceptToken(Scanner::tokenType t) { if(errorFlag == true) return; if(currentToken != t) error("unexpected " + tokenName(currentToken, false) + ", a " + tokenName(t, true) + " was expected"); }
nsresult KeyService::Init() { // Bring up psm nsCOMPtr<nsISupports> nss = do_GetService("@mozilla.org/psm;1"); SECStatus sv; mSlot = PK11_GetInternalKeySlot(); if (PK11_NeedUserInit(mSlot)) { NS_ConvertUTF8toUTF16 tokenName(PK11_GetTokenName(mSlot)); nsCOMPtr<nsITokenPasswordDialogs> dialogs; dialogs = do_GetService(NS_TOKENPASSWORDSDIALOG_CONTRACTID); if (!dialogs) return NS_ERROR_FAILURE; PRBool cancelled; nsresult rv = dialogs->SetPassword(nsnull, tokenName.get(), &cancelled); NS_ENSURE_SUCCESS(rv, rv); if (cancelled) return NS_ERROR_FAILURE; } if (PK11_NeedLogin(mSlot)) { sv = PK11_Authenticate(mSlot, PR_TRUE, NULL); if (sv != SECSuccess) return NS_ERROR_FAILURE; } return NS_OK; }
void CGameTokenSystem::RemoveTokenFromDebugList( const char* pToken ) { string tokenName( pToken ); TDebugListMap::iterator iter = m_debugList.find( tokenName ); if (iter!=m_debugList.end()) m_debugList.erase( iter ); }
ANTLR_USE_NAMESPACE(std)string MismatchedTokenException::getMessage() const { ANTLR_USE_NAMESPACE(std)string s; switch (mismatchType) { case TOKEN: s += "expecting " + tokenName(expecting) + ", found '" + tokenText + "'"; break; case NOT_TOKEN: s += "expecting anything but " + tokenName(expecting) + "; got it anyway"; break; case RANGE: s += "expecting token in range: " + tokenName(expecting) + ".." + tokenName(upper) + ", found '" + tokenText + "'"; break; case NOT_RANGE: s += "expecting token NOT in range: " + tokenName(expecting) + ".." + tokenName(upper) + ", found '" + tokenText + "'"; break; case SET: case NOT_SET: { s += ANTLR_USE_NAMESPACE(std)string("expecting ") + (mismatchType == NOT_SET ? "NOT " : "") + "one of ("; ANTLR_USE_NAMESPACE(std)vector<unsigned int> elems = set.toArray(); for ( unsigned int i = 0; i < elems.size(); i++ ) { s += " "; s += tokenName(elems[i]); } s += "), found '" + tokenText + "'"; } break; default: s = RecognitionException::getMessage(); break; } return s; }
std::string MismatchedTokenException::getErrorMessage() const { std::string s; switch (mismatchType) { case TOKEN: s += "expecting " + tokenName(expecting) + ", found '" + tokenText + "'"; break; case NOT_TOKEN: s += "expecting anything but " + tokenName(expecting) + "; got it anyway"; break; case RANGE: s += "expecting token in range: " + tokenName(expecting) + ".." + tokenName(upper) + ", found '" + tokenText + "'"; break; case NOT_RANGE: s += "expecting token NOT in range: " + tokenName(expecting) + ".." + tokenName(upper) + ", found '" + tokenText + "'"; break; case SET: case NOT_SET: { s += std::string("expecting ") + (mismatchType == NOT_SET ? "NOT " : "") + "one of ("; std::vector<int> elems = set.toArray(); for (int i = 0; i < (int) elems.size(); i++) { s += " "; s += tokenName(elems[i]); } s += "), found '" + tokenText + "'"; } break; default: s = ParserException::getMessage(); break; } return s; }
int V3PreProcImp::getFinalToken(string& buf) { // Return the next user-visible token in the input stream. // Includes and such are handled here, and are never seen by the caller. if (!m_finAhead) { m_finAhead = true; m_finToken = getStateToken(); m_finBuf = string (yyourtext(), yyourleng()); } int tok = m_finToken; buf = m_finBuf; if (0 && debug()>=5) { string bufcln = V3PreLex::cleanDbgStrg(buf); fprintf (stderr,"%d: FIN: %-10s: %s\n", m_lexp->m_tokFilelinep->lineno(), tokenName(tok), bufcln.c_str()); } // Track `line const char* bufp = buf.c_str(); while (*bufp == '\n') bufp++; if ((tok == VP_TEXT || tok == VP_LINE) && 0==strncmp(bufp,"`line ",6)) { int enter; m_finFilelinep->lineDirective(bufp, enter/*ref*/); } else { if (m_finAtBol && !(tok==VP_TEXT && buf=="\n") && m_preprocp->lineDirectives()) { if (int outBehind = m_lexp->m_tokFilelinep->lineno() - m_finFilelinep->lineno()) { if (debug()>=5) fprintf(stderr,"%d: FIN: readjust, fin at %d request at %d\n", m_lexp->m_tokFilelinep->lineno(), m_finFilelinep->lineno(), m_lexp->m_tokFilelinep->lineno()); m_finFilelinep = m_finFilelinep->create(m_lexp->m_tokFilelinep->filename(),m_lexp->m_tokFilelinep->lineno()); if (outBehind > 0 && outBehind <= (int)V3PreProc::NEWLINES_VS_TICKLINE) { // Output stream is behind, send newlines to get back in sync // (Most likely because we're completing a disabled `endif) if (m_preprocp->keepWhitespace()) { buf = string(outBehind,'\n'); return VP_TEXT; } } else { // Need to backup, use `line buf = m_finFilelinep->lineDirectiveStrg(0); return VP_LINE; } } } // Track newlines in prep for next token for (string::iterator cp=buf.begin(); cp!=buf.end(); ++cp) { if (*cp == '\n') { m_finAtBol = true; m_finFilelinep->linenoIncInPlace(); // Increment in place to avoid new/delete calls. It's private data. } else { m_finAtBol = false; } } } m_finAhead = false; // Consumed the token return tok; }
void V3PreProcImp::debugToken(int tok, const char* cmtp) { if (debug()>=5) { 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"); } fprintf (stderr, "%d: %s %s %s(%d) dr%d: <%d>%-10s: %s\n", m_lexp->m_tokFilelinep->lineno(), cmtp, m_off?"of":"on", procStateName(m_states.top()), (int)m_states.size(), (int)m_defRefs.size(), m_lexp->currentStartState(), tokenName(tok), buf.c_str()); } }
/* void changePassword (); */ NS_IMETHODIMP KeyService::ChangePassword() { NS_ConvertUTF8toUTF16 tokenName(PK11_GetTokenName(mSlot)); nsCOMPtr<nsITokenPasswordDialogs> dialogs; dialogs = do_GetService(NS_TOKENPASSWORDSDIALOG_CONTRACTID); if (!dialogs) return NS_ERROR_FAILURE; PRBool cancelled; return dialogs->SetPassword(nsnull, tokenName.get(), &cancelled); }
static void unparseJSONPrime(struct Buffer_char *buf, Node *node) { size_t i; const char *tmp; WRITE_ONE_BUFFER(*buf, '{'); if (node->tok) { Token *tok = node->tok; WRITE_BUFFER(*buf, "\"tok\":{\"type\":\"", 15); tmp = tokenName(tok->type); unparseJSONStr(buf, tmp); WRITE_ONE_BUFFER(*buf, '"'); if (tok->pre) { WRITE_BUFFER(*buf, ",\"pre\":\"", 8); unparseJSONStr(buf, tok->pre); WRITE_ONE_BUFFER(*buf, '"'); } if (tok->tok) { WRITE_BUFFER(*buf, ",\"tok\":\"", 8); unparseJSONStr(buf, tok->tok); WRITE_ONE_BUFFER(*buf, '"'); } WRITE_BUFFER(*buf, "},", 2); } WRITE_BUFFER(*buf, "\"type\":\"", 8); tmp = nodeName(node->type); unparseJSONStr(buf, tmp); WRITE_BUFFER(*buf, "\",\"children\":[", 14); for (i = 0; node->children[i]; i++) { if (i != 0) WRITE_ONE_BUFFER(*buf, ','); unparseJSONPrime(buf, node->children[i]); } WRITE_BUFFER(*buf, "]}", 2); }
/* void changePassword(); */ NS_IMETHODIMP nsSecretDecoderRing:: ChangePassword() { nsNSSShutDownPreventionLock locker; nsresult rv; PK11SlotInfo *slot; slot = PK11_GetInternalKeySlot(); if (!slot) return NS_ERROR_NOT_AVAILABLE; /* Convert UTF8 token name to UCS2 */ NS_ConvertUTF8toUTF16 tokenName(PK11_GetTokenName(slot)); PK11_FreeSlot(slot); /* Get the set password dialog handler imlementation */ nsCOMPtr<nsITokenPasswordDialogs> dialogs; rv = getNSSDialogs(getter_AddRefs(dialogs), NS_GET_IID(nsITokenPasswordDialogs), NS_TOKENPASSWORDSDIALOG_CONTRACTID); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIInterfaceRequestor> ctx = new nsSDRContext(); bool canceled; { nsPSMUITracker tracker; if (tracker.isUIForbidden()) { rv = NS_ERROR_NOT_AVAILABLE; } else { rv = dialogs->SetPassword(ctx, tokenName.get(), &canceled); } } /* canceled is ignored */ return rv; }
string V3PreProcImp::getline() { // Get a single line from the parse stream. Buffer unreturned text until the newline. if (isEof()) return ""; const char* rtnp; bool gotEof = false; while (NULL==(rtnp=strchr(m_lineChars.c_str(),'\n')) && !gotEof) { string buf; int tok = getFinalToken(buf/*ref*/); if (debug()>=5) { string bufcln = V3PreLex::cleanDbgStrg(buf); fprintf (stderr,"%d: GETFETC: %-10s: %s\n", m_lexp->m_tokFilelinep->lineno(), tokenName(tok), bufcln.c_str()); } if (tok==VP_EOF) { // Add a final newline, if the user forgot the final \n. if (m_lineChars != "" && m_lineChars[m_lineChars.length()-1] != '\n') { m_lineChars.append("\n"); } gotEof = true; } else { m_lineChars.append(buf); } } // Make new string with data up to the newline. int len = rtnp-m_lineChars.c_str()+1; string theLine(m_lineChars, 0, len); m_lineChars = m_lineChars.erase(0,len); // Remove returned characters if (debug()>=4) { string lncln = V3PreLex::cleanDbgStrg(theLine); fprintf (stderr,"%d: GETLINE: %s\n", m_lexp->m_tokFilelinep->lineno(), lncln.c_str()); } return theLine; }
// // printToken 用于输出Token的值 // ostream& operator<<(ostream& os, const Token& tk) { os << tk.content << "[" << tokenName(tk.type) << "]" << "(" << tk.line << ")" << endl; return os; }
void CGameTokenSystem::AddTokenToDebugList( const char* pToken ) { string tokenName( pToken ); m_debugList.insert( tokenName ); }
int V3PreProcImp::getStateToken() { // Return the next state-determined token while (1) { next_tok: if (isEof()) return VP_EOF; int tok = getRawToken(); ProcState state = m_states.top(); // Most states emit white space and comments between tokens. (Unless collecting a string) if (tok==VP_WHITE && state !=ps_STRIFY) return (tok); if (tok==VP_BACKQUOTE && state !=ps_STRIFY) { tok = VP_TEXT; } if (tok==VP_COMMENT) { if (!m_off) { if (m_lexp->m_keepComments == KEEPCMT_SUB) { string rtn; rtn.assign(yyourtext(),yyourleng()); comment(rtn); // Need to insure "foo/**/bar" becomes two tokens insertUnreadback (" "); } else if (m_lexp->m_keepComments) { return (tok); } else { // Need to insure "foo/**/bar" becomes two tokens insertUnreadback (" "); } } // 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 (size_t len=0; len<(size_t)yyourleng(); len++) { if (yyourtext()[len]=='\n') m_lineAdd++; } goto next_tok; } if (tok==VP_LINE) { addLineComment(m_lexp->m_enterExit); goto next_tok; } if (tok==VP_DEFREF_JOIN) { // Here's something fun and unspecified as yet: // The existance of non-existance of a base define changes `` expansion // `define QA_b zzz // `define Q1 `QA``_b // 1Q1 -> zzz // `define QA a // `Q1 -> a_b // Note parenthesis make this unambiguous // `define Q1 `QA()``_b // -> a_b // This may be a side effect of how `UNDEFINED remains as `UNDEFINED, // but it screws up our method here. So hardcode it. string name (yyourtext()+1,yyourleng()-1); if (defExists(name)) { // JOIN(DEFREF) // Put back the `` and process the defref UINFO(5,"```: define "<<name<<" exists, expand first\n"); m_defPutJoin = true; // After define, unputString("``"). Not now as would lose yyourtext() UINFO(5,"TOKEN now DEFREF\n"); tok = VP_DEFREF; } else { // DEFREF(JOIN) UINFO(5,"```: define "<<name<<" doesn't exist, join first\n"); // FALLTHRU, handle as with VP_SYMBOL_JOIN } } if (tok==VP_SYMBOL_JOIN || tok==VP_DEFREF_JOIN) { // not else if, can fallthru from above if() // a`` -> string doesn't include the ``, so can just grab next and continue string out (yyourtext(),yyourleng()); UINFO(5,"`` LHS:"<<out<<endl); // a``b``c can have multiple joins, so we need a stack m_joinStack.push(out); statePush(ps_JOIN); goto next_tok; } // Deal with some special parser states switch (state) { case ps_TOP: { break; } case ps_DEFNAME_UNDEF: // FALLTHRU case ps_DEFNAME_DEFINE: // FALLTHRU case ps_DEFNAME_IFDEF: // FALLTHRU case ps_DEFNAME_IFNDEF: // FALLTHRU case ps_DEFNAME_ELSIF: { if (tok==VP_SYMBOL) { m_lastSym.assign(yyourtext(),yyourleng()); if (state==ps_DEFNAME_IFDEF || state==ps_DEFNAME_IFNDEF) { bool enable = defExists(m_lastSym); UINFO(4,"Ifdef "<<m_lastSym<<(enable?" ON":" OFF")<<endl); if (state==ps_DEFNAME_IFNDEF) enable = !enable; m_ifdefStack.push(VPreIfEntry(enable,false)); if (!enable) parsingOff(); statePop(); goto next_tok; } else if (state==ps_DEFNAME_ELSIF) { if (m_ifdefStack.empty()) { error("`elsif with no matching `if\n"); } else { // Handle `else portion VPreIfEntry lastIf = m_ifdefStack.top(); m_ifdefStack.pop(); if (!lastIf.on()) parsingOn(); // Handle `if portion bool enable = !lastIf.everOn() && defExists(m_lastSym); UINFO(4,"Elsif "<<m_lastSym<<(enable?" ON":" OFF")<<endl); m_ifdefStack.push(VPreIfEntry(enable, lastIf.everOn())); if (!enable) parsingOff(); } statePop(); goto next_tok; } else if (state==ps_DEFNAME_UNDEF) { if (!m_off) { UINFO(4,"Undef "<<m_lastSym<<endl); undef(m_lastSym); } statePop(); goto next_tok; } else if (state==ps_DEFNAME_DEFINE) { // m_lastSym already set. stateChange(ps_DEFFORM); m_lexp->pushStateDefForm(); goto next_tok; } else fatalSrc("Bad case\n"); goto next_tok; } else if (tok==VP_TEXT) { // IE, something like comment between define and symbol if (!m_off) return tok; else goto next_tok; } else if (tok==VP_DEFREF) { // IE, `ifdef `MACRO(x): Substitue and come back here when state pops. break; } else { error((string)"Expecting define name. Found: "+tokenName(tok)+"\n"); goto next_tok; } } case ps_DEFFORM: { if (tok==VP_DEFFORM) { m_formals = m_lexp->m_defValue; if (debug()>=5) cout<<"DefFormals='"<<V3PreLex::cleanDbgStrg(m_formals)<<"'\n"; stateChange(ps_DEFVALUE); m_lexp->pushStateDefValue(); goto next_tok; } else if (tok==VP_TEXT) { // IE, something like comment in formals if (!m_off) return tok; else goto next_tok; } else { error((string)"Expecting define formal arguments. Found: "+tokenName(tok)+"\n"); goto next_tok; } } case ps_DEFVALUE: { static string newlines; newlines = "\n"; // Always start with trailing return if (tok == VP_DEFVALUE) { if (debug()>=5) cout<<"DefValue='"<<V3PreLex::cleanDbgStrg(m_lexp->m_defValue) <<"' formals='"<<V3PreLex::cleanDbgStrg(m_formals)<<"'\n"; // Add any formals string formals = m_formals; string value = m_lexp->m_defValue; // Remove returns // Not removing returns in values has two problems, // 1. we need to correct line numbers with `line after each substitution // 2. Substituting in " .... " with embedded returns requires \ escape. // This is very difficult in the presence of `", so we keep the \ before the newline. for (size_t i=0; i<formals.length(); i++) { if (formals[i] == '\n') { newlines += "\n"; } } for (size_t i=0; i<value.length(); i++) { if (value[i] == '\n') { newlines += "\n"; } } if (!m_off) { // Remove leading and trailing whitespace value = trimWhitespace(value, true); // Define it UINFO(4,"Define "<<m_lastSym<<" "<<formals <<" = '"<<V3PreLex::cleanDbgStrg(value)<<"'"<<endl); define(fileline(), m_lastSym, value, formals, false); } } else { string msg = string("Bad define text, unexpected ")+tokenName(tok)+"\n"; fatalSrc(msg); } statePop(); // DEFVALUE is terminated by a return, but lex can't return both tokens. // Thus, we emit a return here. yyourtext(newlines.c_str(), newlines.length()); return(VP_WHITE); } case ps_DEFPAREN: { if (tok==VP_TEXT && yyourleng()==1 && yyourtext()[0]=='(') { stateChange(ps_DEFARG); goto next_tok; } else { if (m_defRefs.empty()) fatalSrc("Shouldn't be in DEFPAREN w/o active defref"); V3DefineRef* refp = &(m_defRefs.top()); error((string)"Expecting ( to begin argument list for define reference `"+refp->name()+"\n"); statePop(); goto next_tok; } } case ps_DEFARG: { if (m_defRefs.empty()) fatalSrc("Shouldn't be in DEFARG w/o active defref"); 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 && yyourleng()==1 && yyourtext()[0]==',') { refp->args().push_back(refp->nextarg()); stateChange(ps_DEFARG); m_lexp->pushStateDefArg(1); refp->nextarg(""); goto next_tok; } else if (tok==VP_DEFARG && yyourleng()==1 && yyourtext()[0]==')') { // Substitute in and prepare for next action // Similar code in non-parenthesized define (Search for END_OF_DEFARG) refp->args().push_back(refp->nextarg()); string out; if (!m_off) { out = defineSubst(refp); //NOP: out = m_preprocp->defSubstitute(out); } m_defRefs.pop(); refp=NULL; if (m_defRefs.empty()) { statePop(); if (!m_off) unputDefrefString(out); m_lexp->m_parenLevel = 0; } else { // Finished a defref inside a upper defref // Can't subst now, or // `define a(ign) x,y // foo(`a(ign),`b) would break because a contains comma refp = &(m_defRefs.top()); // We popped, so new top refp->nextarg(refp->nextarg()+m_lexp->m_defValue+out); m_lexp->m_defValue=""; m_lexp->m_parenLevel = refp->parenLevel(); statePop(); // Will go to ps_DEFARG, as we're under another define } goto next_tok; } else if (tok==VP_DEFREF) { // Expand it, then state will come back here // Value of building argument is data before the lower defref // we'll append it when we push the argument. break; } else if (tok==VP_SYMBOL || tok==VP_STRING || VP_TEXT || VP_WHITE) { string rtn; rtn.assign(yyourtext(),yyourleng()); refp->nextarg(refp->nextarg()+rtn); goto next_tok; } else { error((string)"Expecting ) or , to end argument list for define reference. Found: "+tokenName(tok)); statePop(); goto next_tok; } } case ps_INCNAME: { if (tok==VP_STRING) { statePop(); m_lastSym.assign(yyourtext(),yyourleng()); UINFO(4,"Include "<<m_lastSym<<endl); // Drop leading and trailing quotes. m_lastSym.erase(0,1); m_lastSym.erase(m_lastSym.length()-1,1); include(m_lastSym); goto next_tok; } else if (tok==VP_TEXT && yyourleng()==1 && yyourtext()[0]=='<') { // include <filename> stateChange(ps_INCNAME); // Still m_lexp->pushStateIncFilename(); goto next_tok; } else if (tok==VP_DEFREF || tok==VP_STRIFY) { // Expand it, then state will come back here break; } else { statePop(); error((string)"Expecting include filename. Found: "+tokenName(tok)+"\n"); goto next_tok; } } case ps_ERRORNAME: { if (tok==VP_STRING) { if (!m_off) { m_lastSym.assign(yyourtext(),yyourleng()); error(m_lastSym); } statePop(); goto next_tok; } else { error((string)"Expecting `error string. Found: "+tokenName(tok)+"\n"); statePop(); goto next_tok; } } case ps_JOIN: { if (tok==VP_SYMBOL || tok==VP_TEXT) { if (m_joinStack.empty()) fatalSrc("`` join stack empty, but in a ``"); string lhs = m_joinStack.top(); m_joinStack.pop(); UINFO(5,"`` LHS:"<<lhs<<endl); string rhs (yyourtext(),yyourleng()); UINFO(5,"`` RHS:"<<rhs<<endl); string out = lhs+rhs; UINFO(5,"`` Out:"<<out<<endl); unputString(out); statePop(); goto next_tok; } else if (tok==VP_EOF || tok==VP_WHITE || tok == VP_COMMENT || tok==VP_STRING) { error((string)"Expecting symbol to terminate ``; whitespace etc cannot follow ``. Found: "+tokenName(tok)+"\n"); statePop(); goto next_tok; } else { // `define, etc, fall through and expand. Pop back here. break; } } case ps_STRIFY: { if (tok==VP_STRIFY) { // Quote what's in the middle of the stringification // Note a `" MACRO_WITH(`") `" doesn't need to be handled (we don't need a stack) // That behavior isn't specified, and other simulators vary widely string out = m_strify; m_strify = ""; // Convert any newlines to spaces, so we don't get a multiline "..." without \ escapes // The spec is silent about this either way; simulators vary string::size_type pos; while ((pos=out.find("\n")) != string::npos) { out.replace(pos, 1, " "); } unputString((string)"\""+out+"\""); statePop(); goto next_tok; } else if (tok==VP_EOF) { error("`\" not terminated at EOF\n"); } else if (tok==VP_BACKQUOTE) { m_strify += "\\\""; goto next_tok; } else if (tok==VP_DEFREF) { // Spec says to expand macros inside `" // Substitue it into the stream, then return here break; } else { // Append token to eventual string m_strify.append(yyourtext(),yyourleng()); goto next_tok; } } default: fatalSrc("Bad case\n"); } // Default is to do top level expansion of some tokens switch (tok) { case VP_INCLUDE: if (!m_off) { statePush(ps_INCNAME); } goto next_tok; case VP_UNDEF: statePush(ps_DEFNAME_UNDEF); goto next_tok; case VP_DEFINE: // No m_off check here, as a `ifdef NEVER `define FOO(`endif) should work statePush(ps_DEFNAME_DEFINE); goto next_tok; case VP_IFDEF: statePush(ps_DEFNAME_IFDEF); goto next_tok; case VP_IFNDEF: statePush(ps_DEFNAME_IFNDEF); goto next_tok; case VP_ELSIF: statePush(ps_DEFNAME_ELSIF); goto next_tok; case VP_ELSE: if (m_ifdefStack.empty()) { error("`else with no matching `if\n"); } else { VPreIfEntry lastIf = m_ifdefStack.top(); m_ifdefStack.pop(); bool enable = !lastIf.everOn(); UINFO(4,"Else "<<(enable?" ON":" OFF")<<endl); m_ifdefStack.push(VPreIfEntry(enable, lastIf.everOn())); if (!lastIf.on()) parsingOn(); if (!enable) parsingOff(); } goto next_tok; case VP_ENDIF: UINFO(4,"Endif "<<endl); if (m_ifdefStack.empty()) { error("`endif with no matching `if\n"); } else { VPreIfEntry lastIf = m_ifdefStack.top(); m_ifdefStack.pop(); if (!lastIf.on()) parsingOn(); // parsingOn() really only enables parsing if // all ifdef's above this want it on } goto next_tok; case VP_DEFREF: { // m_off not right here, but inside substitution, to make this work: `ifdef NEVER `DEFUN(`endif) string name (yyourtext()+1,yyourleng()-1); UINFO(4,"DefRef "<<name<<endl); if (m_defPutJoin) { m_defPutJoin = false; unputString("``"); } if (m_defDepth++ > V3PreProc::DEFINE_RECURSION_LEVEL_MAX) { error("Recursive `define substitution: `"+name); goto next_tok; } // substitute if (!defExists(name)) { // Not found, return original string as-is m_defDepth = 0; UINFO(4,"Defref `"<<name<<" => not_defined"<<endl); if (m_off) { goto next_tok; } else { return (VP_TEXT); } } else { string params = defParams(name); if (params=="0" || params=="") { // Found, as simple substitution if (m_off) { goto next_tok; } else { V3DefineRef tempref(name, ""); string out = defineSubst(&tempref); // Similar code in parenthesized define (Search for END_OF_DEFARG) //NOP: out = m_preprocp->defSubstitute(out); if (m_defRefs.empty()) { // Just output the substitution unputDefrefString(out); } else { // Inside another define. // Can't subst now, or // `define a x,y // foo(`a,`b) would break because a contains comma V3DefineRef* refp = &(m_defRefs.top()); refp->nextarg(refp->nextarg()+m_lexp->m_defValue+out); m_lexp->m_defValue=""; } goto next_tok; } } else { // Found, with parameters UINFO(4,"Defref `"<<name<<" => parameterized"<<endl); // The CURRENT macro needs the paren saved, it's not a property of the child macro if (!m_defRefs.empty()) m_defRefs.top().parenLevel(m_lexp->m_parenLevel); m_defRefs.push(V3DefineRef(name, params)); statePush(ps_DEFPAREN); m_lexp->pushStateDefArg(0); goto next_tok; } } fatalSrc("Bad case\n"); } case VP_ERROR: { statePush(ps_ERRORNAME); goto next_tok; } case VP_EOF: if (!m_ifdefStack.empty()) { error("`ifdef not terminated at EOF\n"); } return tok; case VP_UNDEFINEALL: if (!m_off) { UINFO(4,"Undefineall "<<endl); undefineall(); } goto next_tok; case VP_STRIFY: // We must expand macros in the body of the stringification // Then, when done, form a final string to return // (it could be used as a include filename, for example, so need the string token) statePush(ps_STRIFY); goto next_tok; case VP_SYMBOL: case VP_STRING: case VP_TEXT: { m_defDepth = 0; if (!m_off) return tok; else goto next_tok; } case VP_WHITE: // Handled at top of loop case VP_COMMENT: // Handled at top of loop case VP_DEFFORM: // Handled by state=ps_DEFFORM; case VP_DEFVALUE: // Handled by state=ps_DEFVALUE; default: fatalSrc((string)"Internal error: Unexpected token "+tokenName(tok)+"\n"); break; } return tok; } }