1486 {
1487
1490
1491 ASTNode* loc;
1492 ASTRunner runner(
g_,
opLabels_,
model_, generatePayLog, generatePayLog && includePastCashflows,
script, interactive,
1494
1495 randomvariable_output_pattern pattern;
1497 pattern = randomvariable_output_pattern(randomvariable_output_pattern::pattern::expectation);
1499 pattern = randomvariable_output_pattern(randomvariable_output_pattern::pattern::left_middle_right);
1500 } else {
1501 QL_FAIL("model type not handled when setting output pattern for random variables");
1502 }
1503
1504 DLOG(
"run computation graph builder, context is:");
1506
1507 if (interactive) {
1508 std::cerr << pattern << "\nInitial Context: \n" << (*context_) << std::endl;
1509 }
1510
1511 boost::timer::cpu_timer timer;
1512 try {
1514 root_->accept(runner);
1515 timer.stop();
1516 QL_REQUIRE(runner.value.size() == 1, "ComputationGraphBuilder::run(): value stack has wrong size ("
1517 << runner.value.size() << "), should be 1");
1518 QL_REQUIRE(runner.filter.size() == 1, "ComputationGraphBuilder::run(): filter stack has wrong size ("
1519 << runner.filter.size() << "), should be 1");
1520 QL_REQUIRE(runner.value_node.size() == 1, "ComputationGraphBuilder::run(): value_node stack has wrong size ("
1521 << runner.value_node.size() << "), should be 1");
1522 QL_REQUIRE(runner.filter_node.size() == 1, "ComputationGraphBuilder::run(): filter_node stack has wrong size ("
1523 << runner.filter_node.size() << "), should be 1");
1524 DLOG(
"computation graph builder successfully finished, context after run is:");
1525
1526 if (interactive) {
1527 std::cerr << "\ncomputation graph builder finished without errors. Context after run:" << std::endl;
1528 }
1529
1530 } catch (const std::exception& e) {
1531 std::ostringstream errorMessage;
1532 errorMessage << "Error during computation graph building: " << e.what() << " at "
1533 << (loc ?
to_string(loc->locationInfo) :
"(last visited ast node not known)") <<
": "
1535
1536 std::ostringstream strippedErrorMsg;
1537 strippedErrorMsg << "Error during computation graph building: " << e.what() << " at "
1538 << (loc ?
to_string(loc->locationInfo) :
"(last visited ast node not known)");
1539
1546
1547 if (interactive) {
1548 std::cerr << strippedErrorMsg.str() << "\n";
1550 std::cerr << "Context when hitting the error:" << std::endl;
1551 std::cerr << (*context_) << std::endl;
1552 std::cerr << "SSA-Form when hitting the error:";
1554 std::cin.get();
1555 }
1556
1557 QL_FAIL(errorMessage.str());
1558 }
1559
1561 DLOG(
"computation graph builder running time: " << timer.elapsed().wall / 1E3 <<
" mus");
1562
1563 if (interactive) {
1564 std::cerr << pattern <<
"<<<<\n" << *
context_ <<
">>>>\n" << std::endl;
1566 std::cin.get();
1567 }
1568}
std::set< std::size_t > keepNodes_
std::vector< PayLogEntry > payLogEntries_
#define DLOG(text)
Logging Macro (Level = Debug)
#define DLOGGERSTREAM(text)
std::string ssaForm(const ComputationGraph &g, const std::vector< std::string > &opCodeLabels, const std::vector< T > &values)
std::string printCodeContext(std::string script, const ASTNode *loc, bool compact)
void reset(const ASTNodePtr root)
std::string to_string(const LocationInfo &l)