// // SourceTokenizerC::doCommand_define // void SourceTokenizerC::doCommand_define(SourceTokenC *) { SourceTokenC::Reference name = getRaw(); doAssert(name, SourceTokenC::TT_NAM); if (inStack.back()->peek() == '(') { MacroData data; doAssert(getRaw(), SourceTokenC::TT_PAREN_O); SourceTokenC::Reference arg = getRaw(); if (arg->type != SourceTokenC::TT_PAREN_C) for (;;) { if (arg->type == SourceTokenC::TT_DOT3) { data.first.push_back(std::string()); doAssert((arg = getRaw()), SourceTokenC::TT_PAREN_C); break; } doAssert(arg, SourceTokenC::TT_NAM); data.first.push_back(arg->data); if ((arg = getRaw())->type == SourceTokenC::TT_PAREN_C) break; doAssert(arg, SourceTokenC::TT_COMMA); arg = getRaw(); } inStack.back()->disableQuote(); for (char c; (c = inStack.back()->get()) != '\n';) data.second += c; inStack.back()->enableQuote(); inStack.back()->unget('\n'); if (isSkip()) return; addMacro(name->data, data); } else { std::string data; inStack.back()->disableQuote(); for (char c; (c = inStack.back()->get()) != '\n';) data += c; inStack.back()->enableQuote(); inStack.back()->unget('\n'); if (isSkip()) return; addDefine(name->data, data); } }
// // SourceTokenizerC::doCommand // void SourceTokenizerC::doCommand() { SourceTokenC::Reference tok = getRaw(); doAssert(tok, SourceTokenC::TT_NAM); if (tok->data == "define") doCommand_define(tok); else if (tok->data == "else") doCommand_else(tok); else if (tok->data == "elif") doCommand_elif(tok); else if (tok->data == "endif") doCommand_endif(tok); else if (tok->data == "error") doCommand_error(tok); else if (tok->data == "if") doCommand_if(tok); else if (tok->data == "ifdef") doCommand_ifdef(tok); else if (tok->data == "ifndef") doCommand_ifndef(tok); else if (tok->data == "include") doCommand_include(tok); else if (tok->data == "undef") doCommand_undef(tok); else if (tok->data == "warning") doCommand_warning(tok); else if(isSkip()) { while(tok->type != SourceTokenC::TT_ENDL) tok = getRaw(); unget(tok); } else Error(tok->pos, "unknown command: %s", tok->data.c_str()); }
// // 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); }
void Graph::printRaw(FILE *fh) { // print survivors first nat num = previousState.size(); BIN_WRITE(num,fh); for(nat i = 0; i < num; ++i) { Node *node = previousState[i]; nat localNum = 0; if(node) localNum = node->id; BIN_WRITE(localNum,fh); } nat numberOfNodes = 0; // determine number nat end = nodMan.getNumberOfNodesUsed(); for(nat i = 1 ; i < end ; ++i) { Node *node = nodMan.getNode(i); assert(node); auto myInfo = nodMan.getInfo(node->id); if(NOT myInfo->isSkip()) ++numberOfNodes; } BIN_WRITE(numberOfNodes,fh); for(nat i = 1; i < end ; ++i) { Node *node = nodMan.getNode(i); assert(node) ; auto myInfo = nodMan.getInfo(node->id); if(myInfo->isSkip()) continue; else node->printRaw(fh); } }
// // SourceTokenizerC::doCommand_warning // void SourceTokenizerC::doCommand_warning(SourceTokenC *) { SourcePosition pos(inStack.back()->getFilename(), inStack.back()->getLineCount(), inStack.back()->getColumn()); std::string msg; char c; while((c = inStack.back()->get()) != '\n') msg += c; if(isSkip()) return; Warn(pos, "#warning%s", msg.c_str()); }
// // SourceTokenizerC::get // SourceTokenC::Reference SourceTokenizerC::get() { SourceTokenC::Pointer tok; for (;;) { tok = getExpand(); // Preprocessor directive. if (tok->type == SourceTokenC::TT_ENDL) { while (tok->type == SourceTokenC::TT_ENDL) tok = getExpand(); if (tok->type == SourceTokenC::TT_HASH1) { doCommand(); continue; } } if (isSkip()) continue; if (tok->type == SourceTokenC::TT_NONE) continue; break; } // String literal concatenation. if (tok->type == SourceTokenC::TT_STR) { SourceTokenC::Reference tmpTok = get(); if (tmpTok->type == SourceTokenC::TT_STR) tok = SourceTokenC::create(tok->pos, tok->data + tmpTok->data, tok->type); else unget(tmpTok); } return static_cast<SourceTokenC::Reference>(tok); }
// // 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()); } }