// // SourceTokenizerC::doCommand_ifndef // void SourceTokenizerC::doCommand_ifndef(SourceTokenC *) { SourceTokenC::Reference name = getRaw(); doAssert(name, SourceTokenC::TT_NAM); doAssert(peekRaw(), SourceTokenC::TT_ENDL); addSkip(hasDefine(name->data) || hasMacro(name->data)); }
// // SourceTokenizerC::doCommand_undef // void SourceTokenizerC::doCommand_undef(SourceTokenC *) { SourceTokenC::Reference name = getRaw(); doAssert(name, SourceTokenC::TT_NAM); doAssert(peekRaw(), SourceTokenC::TT_ENDL); if (isSkip()) return; remDefine(name->data); }
// // SourceTokenizerC::doCommand_endif // void SourceTokenizerC::doCommand_endif(SourceTokenC *tok) { doAssert(peekRaw(), SourceTokenC::TT_ENDL); if (skipStack.empty()) Error(tok->pos, "unmatched #endif"); remSkip(); }
// // SourceTokenizerC::doCommand_else // void SourceTokenizerC::doCommand_else(SourceTokenC *tok) { doAssert(peekRaw(), SourceTokenC::TT_ENDL); if (skipStack.empty()) Error(tok->pos, "unmatched #else"); skipStack.back() = unskipStack.back(); unskipStack.back() = true; // If it wasn't, it is now. }
// // SourceTokenizerC::doCommand_elif // void SourceTokenizerC::doCommand_elif(SourceTokenC *tok) { if (skipStack.empty()) Error(tok->pos, "unmatched #elif"); bool ifResult = !!getExpr()->resolveINT(); doAssert(peekRaw(), SourceTokenC::TT_ENDL); skipStack.back() = unskipStack.back() || !ifResult; unskipStack.back() = unskipStack.back() || ifResult; }
// // SourceTokenizerC::doCommand_include // void SourceTokenizerC::doCommand_include(SourceTokenC *) { SourceTokenC::Reference inc = getRaw(); std::string filename; unsigned flags = SourceStream::ST_C; if(inc->type == SourceTokenC::TT_STR) filename = inc->data; else if(inc->type == SourceTokenC::TT_CMP_LT) { flags |= SourceStream::STF_NOUSER; for(char c; (c = inStack.back()->get()) != '>';) { if(c == '\n') Error(inc->pos, "unterminated include"); filename += c; } } else Error(inc->pos, "expected TT_STR or TT_CMP_LT"); doAssert(peekRaw(), SourceTokenC::TT_ENDL); if (isSkip()) return; try { inStack.push_back(new SourceStream(filename, flags)); ungetStack.push_back(static_cast<SourceTokenC::Reference>( new SourceTokenC(SourcePosition::builtin(), SourceTokenC::TT_ENDL))); } catch (std::exception const &) { Error(inc->pos, "file not found: %s", filename.c_str()); } }
jvalue_ref get() const { return peekRaw(); }
// // SourceTokenizerC::doCommand_if // void SourceTokenizerC::doCommand_if(SourceTokenC *) { addSkip(!getExpr()->resolveINT()); doAssert(peekRaw(), SourceTokenC::TT_ENDL); }