Skip to content
Snippets Groups Projects
Select Git revision
  • 0d62634e522917aae972cda1b65a91862b21b12b
  • develop default protected
  • origin/stage/bouguettaia
  • feature/kinetic-schemes
  • feature/reconstruction
  • feature/local-dt-fsi
  • feature/composite-scheme-sources
  • feature/composite-scheme-other-fluxes
  • feature/serraille
  • feature/variational-hydro
  • feature/composite-scheme
  • hyperplastic
  • feature/polynomials
  • feature/gks
  • feature/implicit-solver-o2
  • feature/coupling_module
  • feature/implicit-solver
  • feature/merge-local-dt-fsi
  • master protected
  • feature/escobar-smoother
  • feature/hypoelasticity-clean
  • v0.5.0 protected
  • v0.4.1 protected
  • v0.4.0 protected
  • v0.3.0 protected
  • v0.2.0 protected
  • v0.1.0 protected
  • Kidder
  • v0.0.4 protected
  • v0.0.3 protected
  • v0.0.2 protected
  • v0 protected
  • v0.0.1 protected
33 results

BinaryOperatorProcessorBuilder.hpp

Blame
  • UtilsModule.cpp 3.17 KiB
    #include <language/modules/UtilsModule.hpp>
    
    #include <language/utils/ASTDotPrinter.hpp>
    #include <language/utils/ASTExecutionInfo.hpp>
    #include <language/utils/ASTPrinter.hpp>
    #include <language/utils/BuiltinFunctionEmbedder.hpp>
    #include <language/utils/SymbolTable.hpp>
    
    #include <fstream>
    
    UtilsModule::UtilsModule()
    {
      this->_addBuiltinFunction("getAST", std::make_shared<BuiltinFunctionEmbedder<std::string(void)>>(
    
                                            []() -> std::string {
                                              const auto& root_node = ASTExecutionInfo::current().rootNode();
    
                                              std::ostringstream os;
                                              os << ASTPrinter{root_node};
    
                                              return os.str();
                                            }
    
                                            ));
    
      this->_addBuiltinFunction("saveASTDot", std::make_shared<BuiltinFunctionEmbedder<void(const std::string&)>>(
    
                                                [](const std::string& dot_filename) -> void {
                                                  const auto& root_node = ASTExecutionInfo::current().rootNode();
    
                                                  std::ofstream fout(dot_filename);
    
                                                  if (not fout) {
                                                    std::ostringstream os;
                                                    os << "could not create file '" << dot_filename << "'\n";
                                                    throw NormalError(os.str());
                                                  }
    
                                                  ASTDotPrinter dot_printer{root_node};
                                                  fout << dot_printer;
    
                                                  if (not fout) {
                                                    std::ostringstream os;
                                                    os << "could not write AST to '" << dot_filename << "'\n";
                                                    throw NormalError(os.str());
                                                  }
                                                }
    
                                                ));
    
      this->_addBuiltinFunction("getFunctionAST",
                                std::make_shared<BuiltinFunctionEmbedder<std::string(const FunctionSymbolId&)>>(
    
                                  [](const FunctionSymbolId& function_symbol_id) -> std::string {
                                    auto& function_table = function_symbol_id.symbolTable().functionTable();
    
                                    const auto& function_descriptor = function_table[function_symbol_id.id()];
    
                                    std::ostringstream os;
                                    os << function_descriptor.name() << ": domain mapping\n";
                                    os << ASTPrinter(function_descriptor.domainMappingNode());
                                    os << function_descriptor.name() << ": definition\n";
                                    os << ASTPrinter(function_descriptor.definitionNode());
    
                                    return os.str();
                                  }
    
                                  ));
    }