void parse_block(ParseContext& pc, vector<BaseNode*>& nodes, size_t indent, bool fblock) { bool first = true; while (!pc.isFileEnd()) { if (pc.getTokens().empty()) continue; size_t line_indent = pc.getLine().indent; if ((first && line_indent != indent) || line_indent > indent) { parse_err(pc, "Improper indent level in block"); break; } else if (line_indent < indent) { break; } BaseNode* bn; if (fblock) { bn = parse_func(pc); if (!bn) { parse_err(pc, "Only function definitions expected in type block"); } } else bn = parse_line(pc); if (bn == NULL) return; nodes.push_back(bn); if (error()) break; first = false; } }
bool CSourceEmitter::createSourcesAtPath(const ParseContext& context, const std::string& outputBasePath) { Three::CCodeGenVisitor visitor; context.rootNode()->accept(visitor); std::ofstream bodyFile(outputBasePath + ".c"); assert(bodyFile); // make sure to import the headers visitor.addInternalHeader(true, outputBasePath + ".h"); visitor.addDeclarationsHeader(true, outputBasePath + "_internal.h"); bodyFile << "// Declarations" << std::endl; bodyFile << visitor.declarationsString(); bodyFile << std::endl << "// Definitions" << std::endl; bodyFile << visitor.bodyString(); std::ofstream internalHeaderFile(outputBasePath + "_internal.h"); internalHeaderFile << Three::CSource::includeGuard(""); internalHeaderFile << visitor.internalHeaderString(); std::ofstream externalHeaderFile(outputBasePath + ".h"); externalHeaderFile << Three::CSource::includeGuard(""); externalHeaderFile << visitor.externalHeaderString(); return true; }
static bool MaybeCheckEvalFreeVariables(ExclusiveContext *cxArg, HandleScript evalCaller, HandleObject scopeChain, Parser<FullParseHandler> &parser, ParseContext<FullParseHandler> &pc) { if (!evalCaller || !evalCaller->functionOrCallerFunction()) return true; // Eval scripts are only compiled on the main thread. JSContext *cx = cxArg->asJSContext(); // Watch for uses of 'arguments' within the evaluated script, both as // free variables and as variables redeclared with 'var'. RootedFunction fun(cx, evalCaller->functionOrCallerFunction()); HandlePropertyName arguments = cx->names().arguments; for (AtomDefnRange r = pc.lexdeps->all(); !r.empty(); r.popFront()) { if (r.front().key() == arguments) { if (!CheckArgumentsWithinEval(cx, parser, fun)) return false; } } for (AtomDefnListMap::Range r = pc.decls().all(); !r.empty(); r.popFront()) { if (r.front().key() == arguments) { if (!CheckArgumentsWithinEval(cx, parser, fun)) return false; } } // If the eval'ed script contains any debugger statement, force construction // of arguments objects for the caller script and any other scripts it is // transitively nested inside. The debugger can access any variable on the // scope chain. if (pc.sc->hasDebuggerStatement()) { RootedObject scope(cx, scopeChain); while (scope->is<ScopeObject>() || scope->is<DebugScopeObject>()) { if (scope->is<CallObject>() && !scope->as<CallObject>().isForEval()) { RootedScript script(cx, scope->as<CallObject>().callee().getOrCreateScript(cx)); if (!script) return false; if (script->argumentsHasVarBinding()) { if (!JSScript::argumentsOptimizationFailed(cx, script)) return false; } } scope = scope->enclosingScope(); } } return true; }
DeckRecord ParserRecord::parse(const ParseContext& parseContext , MessageContainer& msgContainer, RawRecord& rawRecord ) const { std::vector< DeckItem > items; items.reserve( this->size() + 20 ); for( const auto& parserItem : *this ) items.emplace_back( parserItem->scan( rawRecord ) ); if (rawRecord.size() > 0) { std::string msg = "The RawRecord for keyword \"" + rawRecord.getKeywordName() + "\" in file\"" + rawRecord.getFileName() + "\" contained " + std::to_string(rawRecord.size()) + " too many items according to the spec. RawRecord was: " + rawRecord.getRecordString(); parseContext.handleError(ParseContext::PARSE_EXTRA_DATA , msgContainer, msg); } return { std::move( items ) }; }
DeckRecord ParserRecord::parse(const ParseContext& parseContext , MessageContainer& msgContainer, RawRecord& rawRecord ) const { DeckRecord deckRecord( size() + 20 ); for (size_t i = 0; i < size(); i++) { auto parserItem = get(i); deckRecord.addItem( parserItem->scan( rawRecord ) ); } if (rawRecord.size() > 0) { std::string msg = "The RawRecord for keyword \"" + rawRecord.getKeywordName() + "\" in file\"" + rawRecord.getFileName() + "\" contained " + std::to_string(rawRecord.size()) + " too many items according to the spec. RawRecord was: " + rawRecord.getRecordString(); parseContext.handleError(ParseContext::PARSE_EXTRA_DATA , msgContainer, msg); } return deckRecord; }
void checkOptions(const DeckKeyword& keyword, std::multimap<std::string , PartiallySupported<T> >& map, const ParseContext& parseContext, ErrorGuard& errorGuard) { // check for partially supported keywords. typename std::multimap<std::string, PartiallySupported<T> >::iterator it, itlow, itup; itlow = map.lower_bound(keyword.name()); itup = map.upper_bound(keyword.name()); for (it = itlow; it != itup; ++it) { const auto& record = keyword.getRecord(0); if (record.getItem(it->second.item).template get<T>(0) != it->second.item_value) { std::string msg = "For keyword '" + it->first + "' only value " + boost::lexical_cast<std::string>(it->second.item_value) + " in item " + it->second.item + " is supported by flow.\n" + "In file " + keyword.getFileName() + ", line " + std::to_string(keyword.getLineNumber()) + "\n"; parseContext.handleError(ParseContext::SIMULATOR_KEYWORD_ITEM_NOT_SUPPORTED, msg, errorGuard); } } }
void checkKeywords(const Deck& deck, const ParseContext& parseContext, ErrorGuard& errorGuard) { // These keywords are supported by opm-parser, but are not supported // by flow. For some of them, only part of the options are supported. // The list is used to output messages only. std::unordered_set<std::string> unsupported_keywords = { "ACTION", "ACTIONX", "ADSALNOD", "API", "APIGROUP", "AQUCON", "AQUCT", "AQUTAB", "AQUNUM", "BRANPROP", "CARFIN", "COMPDATL", "COMPLUMP", "CONNECTION", "CPR", "DATE", "ENDACTIO", "ENDFIN" "ENDNUM", "ENDSKIP", "ENKSRVD", "ENPTVD", "EQLNUM", "EQUALREG", "EXCEL", "EXTRAPMS", "FILLEPS", "FIPNUM", "FLUXTYPE", "FULLIMP", "GCONSALE", "GCONSUMP", "GDORIENT", "GECON", "GLIFTOPT", "GNETINJE", "GPMAINT", "GRIDUNIT", "GRUPNET", "GSATPROD", "GUIDERAT", "IMKRVD", "IMPES", "IMPTVD", "LGR", "LIFTOPT", "MAPUNITS", "MAXVALUE", "MESSAGES", "MINVALUE", "MONITOR", "MSGFILE", "MULT_XYZ", "NETBALAN", "NEXTSTEP", "NOCASC", "NODEPROP", "NOGGF", "NOINSPEC", "NOMONITO", "NONNC", "NORSSPEC", "NOWARN", "NSTACK", "NUMRES", "NUPCOL", "OILVISCT", "OLDTRAN", "OPERATER", "OPTIONS", "PARALLEL", "PBVD", "PCG", "PERMR", "PERMTHT", "PERMXY", "PERMYZ", "PERMZX", "PIMULTAB", "PLYADSS", "PLYDHFLF", "PPCWMAX", "REFINE", "RADFIN4", "RHO", "RKTRMDIR", "ROCKCOMP", "ROCKOPTS", "ROCKTAB", "RPTGRID", "RPTONLY", "RPTONLYO", "RPTPROS", "PRTRST", "RPTRUNSP", "RPTSMRY", "RPTSOL", "RSCONST", "RSCONSTT", "RTEMP", "RTEMPA", "RTEMPVD", "RUNSUM", "SATOPTS", "SAVE", "SEPARATE", "SKIP", "SKIP100", "SKIP300", "SKIPREST", "SPECGRID", "SUMTHIN", "TEMP", "THCONR", "TRACER", "TRACERS", "VAPPARS", "VISCREF", "WARN", "WATVISCT", "WELPI", "WELSPECL", "WGASPROD", "WINJMULT", "WLIMTOL", "WORKTHP", "WPAVE", "WPITAB", "WTEMP", "WTRACER", "ZIPPY2" }; std::multimap<std::string, PartiallySupported<std::string> > string_options; std::multimap<std::string, PartiallySupported<int> > int_options; addSupported<ParserKeywords::COMPORD, ParserKeywords::COMPORD::ORDER_TYPE, std::string>(string_options , "DEPTH"); addSupported<ParserKeywords::ENDSCALE, ParserKeywords::ENDSCALE::DIRECT, std::string>(string_options, "NODIR"); addSupported<ParserKeywords::ENDSCALE, ParserKeywords::ENDSCALE::IRREVERS, std::string>(string_options, "REVER"); addSupported<ParserKeywords::PINCH, ParserKeywords::PINCH::CONTROL_OPTION, std::string>(string_options, "GAP"); addSupported<ParserKeywords::PINCH, ParserKeywords::PINCH::PINCHOUT_OPTION, std::string>(string_options, "TOPBOT"); addSupported<ParserKeywords::EHYSTR, ParserKeywords::EHYSTR::relative_perm_hyst, int>(int_options , 0); // check deck and keyword for flow and parser. for (size_t idx = 0; idx < deck.size(); ++idx) { const auto& keyword = deck.getKeyword(idx); std::unordered_set<std::string>::const_iterator it; it = unsupported_keywords.find(keyword.name()); if (it != unsupported_keywords.end()) { std::string msg = "Keyword '" + keyword.name() + "' is not supported by flow.\n" + "In file " + keyword.getFileName() + ", line " + std::to_string(keyword.getLineNumber()) + "\n"; parseContext.handleError(ParseContext::SIMULATOR_KEYWORD_NOT_SUPPORTED, msg, errorGuard); } checkOptions<std::string>(keyword, string_options, parseContext, errorGuard); checkOptions<int>(keyword, int_options, parseContext, errorGuard); } }