blob: 504393bb5fc67d4cbef53dbd09b1f608de2bc1dd [file] [log] [blame]
Mark Sleef0712dc2006-10-25 19:03:57 +00001#ifndef T_SCOPE_H
2#define T_SCOPE_H
3
4#include <map>
5#include <string>
6
7#include "t_type.h"
8#include "t_service.h"
9
10/**
11 * This represents a variable scope used for looking up predefined types and
12 * services. Typically, a scope is associated with a t_program. Scopes are not
13 * used to determine code generation, but rather to resolve identifiers at
14 * parse time.
15 *
16 * @author Mark Slee <mcslee@facebook.com>
17 */
18class t_scope {
19 public:
20 t_scope() {}
21
22 void add_type(std::string name, t_type* type) {
23 types_[name] = type;
24 }
25
26 t_type* get_type(std::string name) {
27 return types_[name];
28 }
29
30 void add_service(std::string name, t_service* service) {
31 services_[name] = service;
32 }
33
34 t_service* get_service(std::string name) {
35 return services_[name];
36 }
37
38 void print() {
39 std::map<std::string, t_type*>::iterator iter;
40 for (iter = types_.begin(); iter != types_.end(); ++iter) {
41 printf("%s => %s\n",
42 iter->first.c_str(),
43 iter->second->get_name().c_str());
44 }
45 }
46
47 private:
48
49 // Map of names to types
50 std::map<std::string, t_type*> types_;
51
52 // Map of names to services
53 std::map<std::string, t_service*> services_;
54
55};
56
57#endif