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