compiler.hpp
Go to the documentation of this file.
1 #ifndef STAN_LANG_COMPILER_HPP
2 #define STAN_LANG_COMPILER_HPP
3 
5 #include <stan/lang/ast.hpp>
7 #include <stan/lang/parser.hpp>
8 #include <iostream>
9 #include <sstream>
10 #include <string>
11 #include <vector>
12 
13 namespace stan {
14  namespace lang {
15 
16  /**
17  * Read a Stan model specification from the specified input, parse
18  * it, and write the C++ code for it to the specified output,
19  * allowing undefined function declarations if the flag is set to
20  * true and searching the specified include path for included
21  * files.
22  *
23  * @param msgs Output stream for warning messages
24  * @param in Stan model specification
25  * @param out C++ code output stream
26  * @param name Name of model class
27  * @param allow_undefined true if permits undefined functions
28  * @param filename name of file or other source from which input
29  * stream was derived
30  * @param include_paths array of paths to search for included files
31  * @return <code>false</code> if code could not be generated due
32  * to syntax error in the Stan model; <code>true</code>
33  * otherwise.
34  */
35  bool compile(std::ostream* msgs, std::istream& in, std::ostream& out,
36  const std::string& name, const bool allow_undefined = false,
37  const std::string& filename = "unknown file name",
38  const std::vector<std::string>& include_paths
39  = std::vector<std::string>()) {
40  io::program_reader reader(in, filename, include_paths);
41  std::string s = reader.program();
42  std::stringstream ss(s);
43  program prog;
44  bool parse_succeeded = parse(msgs, ss, name, reader, prog,
45  allow_undefined);
46  if (!parse_succeeded)
47  return false;
48  generate_cpp(prog, name, reader.history(), out);
49  return true;
50  }
51 
52  }
53 }
54 #endif
const XML_Char * name
Definition: expat.h:151
bool compile(std::ostream *msgs, std::istream &in, std::ostream &out, const std::string &name, const bool allow_undefined=false, const std::string &filename="unknown file name", const std::vector< std::string > &include_paths=std::vector< std::string >())
Definition: compiler.hpp:35
Float_t ss
Definition: plot.C:24
string filename
Definition: shutoffs.py:106
const XML_Char * s
Definition: expat.h:262
bool parse(std::ostream *out, std::istream &in, const std::string &name, const io::program_reader &reader, program &prog, const bool allow_undefined=false)
Definition: parser.hpp:35
double lang
Definition: runWimpSim.h:113
void generate_cpp(const program &prog, const std::string &model_name, const std::vector< io::preproc_event > &history, std::ostream &o)
const std::vector< preproc_event > & history() const
std::string program() const
ifstream in
Definition: comparison.C:7
enum BeamMode string