compile_functions.hpp
Go to the documentation of this file.
1 #ifndef STAN_LANG_COMPILE_FUNCTIONS_HPP
2 #define STAN_LANG_COMPILE_FUNCTIONS_HPP
3 
5 #include <stan/lang/parser.hpp>
6 
7 #include <iostream>
8 #include <string>
9 #include <vector>
10 
11 namespace stan {
12  namespace lang {
13 
14  /**
15  * Read a Stan file with only the functions block from the
16  * specified input, parse it, and write the C++ code for it
17  * to the specified output.
18  *
19  * @param[in] msgs Output stream for warning messages
20  * @param[in] stan_funcs_in Stan model specification
21  * @param[in] cpp_out C++ code output stream
22  * @param[in] namespaces Vector of namespace to generate the functions in
23  * @param[in] allow_undefined Permit undefined functions?
24  * @param filename name of file or other source from which input
25  * stream was derived
26  * @param include_paths array of paths to search for included files
27  * @return <code>false</code> if code could not be generated
28  * due to syntax error in the functions file;
29  * <code>true</code> otherwise.
30  */
31  bool compile_functions(std::ostream* msgs,
32  std::istream& stan_funcs_in,
33  std::ostream& cpp_out,
34  const std::vector<std::string>& namespaces,
35  const bool allow_undefined = false,
36  const std::string& filename = "unknown file name",
37  const std::vector<std::string>& include_paths
38  = std::vector<std::string>()) {
39  io::program_reader reader(stan_funcs_in, filename, include_paths);
40  std::string s = reader.program();
41  std::stringstream ss(s);
42  program prog;
43 
44  std::string name("functions_only_model");
45 
46  bool parsed_ok = parse(msgs, ss, name, reader, prog, allow_undefined);
47  if (!parsed_ok)
48  return false; // syntax error in program
49 
50  generate_standalone_functions(prog, namespaces,
51  reader.history(), cpp_out);
52  return true;
53  }
54 
55 
56  }
57 }
58 #endif
const XML_Char * name
Definition: expat.h:151
Float_t ss
Definition: plot.C:24
string filename
Definition: shutoffs.py:106
const XML_Char * s
Definition: expat.h:262
void generate_standalone_functions(const program &prog, const std::vector< std::string > &namespaces, const std::vector< io::preproc_event > &history, std::ostream &o)
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
bool compile_functions(std::ostream *msgs, std::istream &stan_funcs_in, std::ostream &cpp_out, const std::vector< std::string > &namespaces, const bool allow_undefined=false, const std::string &filename="unknown file name", const std::vector< std::string > &include_paths=std::vector< std::string >())
const std::vector< preproc_event > & history() const
std::string program() const
enum BeamMode string