1 #ifndef STAN_LANG_AST_VARIABLE_MAP_DEF_HPP
2 #define STAN_LANG_AST_VARIABLE_MAP_DEF_HPP
3 
4 #include <stan/lang/ast.hpp>
5 #include <string>
6 #include <iostream>
7 
8 namespace stan {
9   namespace lang {
10 
exists(const std::string & name) const11     bool variable_map::exists(const std::string& name) const {
12       return map_.find(name) != map_.end();
13     }
14 
get(const std::string & name) const15     var_decl variable_map::get(const std::string& name) const {
16       if (!exists(name))
17         throw std::invalid_argument("variable does not exist");
18       return map_.find(name)->second.first;
19     }
20 
get_bare_type(const std::string & name) const21     bare_expr_type variable_map::get_bare_type(const std::string& name) const {
22       return get(name).bare_type_;
23     }
24 
get_scope(const std::string & name) const25     scope variable_map::get_scope(const std::string& name) const {
26       if (!exists(name))
27         throw std::invalid_argument("variable does not exist");
28       return map_.find(name)->second.second;
29     }
30 
add(const std::string & name,const var_decl & decl,const scope & scope_decl)31     void variable_map::add(const std::string& name,
32                            const var_decl& decl,
33                            const scope& scope_decl) {
34       map_[name] = range_t(decl, scope_decl);
35     }
36 
remove(const std::string & name)37     void variable_map::remove(const std::string& name) {
38       map_.erase(name);
39     }
40 
size() const41     size_t variable_map::size() const {
42       return map_.size();
43     }
44   }
45 }
46 #endif
47