Subversion Repositories SmartDukaan

Rev

Rev 30 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements. See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership. The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License. You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied. See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19
 
20
#ifndef T_SCOPE_H
21
#define T_SCOPE_H
22
 
23
#include <map>
24
#include <string>
25
 
26
#include "t_type.h"
27
#include "t_service.h"
28
 
29
/**
30
 * This represents a variable scope used for looking up predefined types and
31
 * services. Typically, a scope is associated with a t_program. Scopes are not
32
 * used to determine code generation, but rather to resolve identifiers at
33
 * parse time.
34
 *
35
 */
36
class t_scope {
37
 public:
38
  t_scope() {}
39
 
40
  void add_type(std::string name, t_type* type) {
41
    types_[name] = type;
42
  }
43
 
44
  t_type* get_type(std::string name) {
45
    return types_[name];
46
  }
47
 
48
  void add_service(std::string name, t_service* service) {
49
    services_[name] = service;
50
  }
51
 
52
  t_service* get_service(std::string name) {
53
    return services_[name];
54
  }
55
 
56
  void add_constant(std::string name, t_const* constant) {
57
    constants_[name] = constant;
58
  }
59
 
60
  t_const* get_constant(std::string name) {
61
    return constants_[name];
62
  }
63
 
64
  void print() {
65
    std::map<std::string, t_type*>::iterator iter;
66
    for (iter = types_.begin(); iter != types_.end(); ++iter) {
67
      printf("%s => %s\n",
68
             iter->first.c_str(),
69
             iter->second->get_name().c_str());
70
    }
71
  }
72
 
73
 private:
74
 
75
  // Map of names to types
76
  std::map<std::string, t_type*> types_;
77
 
78
  // Map of names to constants
79
  std::map<std::string, t_const*> constants_;
80
 
81
  // Map of names to services
82
  std::map<std::string, t_service*> services_;
83
 
84
};
85
 
86
#endif