File: Synopsis/SymbolLookup/Symbol.hh 1
2
3
4
5
6
7#ifndef Synopsis_SymbolLookup_Symbol_hh_
8#define Synopsis_SymbolLookup_Symbol_hh_
9
10#include <Synopsis/PTree/Encoding.hh>
11#include <Synopsis/PTree/Lists.hh>
12
13namespace Synopsis
14{
15namespace SymbolLookup
16{
17
18class Symbol;
19class VariableName;
20class ConstName;
21class TypeName;
22class TypedefName;
23class ClassName;
24class EnumName;
25class ClassTemplateName;
26class FunctionName;
27class FunctionTemplateName;
28class NamespaceName;
29
30class SymbolVisitor
31{
32public:
33 virtual ~SymbolVisitor() {}
34
35 virtual void visit(Symbol const *) = 0;
36 virtual void visit(VariableName const *) = 0;
37 virtual void visit(ConstName const *) = 0;
38 virtual void visit(TypeName const *) = 0;
39 virtual void visit(TypedefName const *) = 0;
40 virtual void visit(ClassName const *) = 0;
41 virtual void visit(EnumName const *) = 0;
42 virtual void visit(ClassTemplateName const *) = 0;
43 virtual void visit(FunctionName const *) = 0;
44 virtual void visit(FunctionTemplateName const *) = 0;
45 virtual void visit(NamespaceName const *) = 0;
46};
47
48class Scope;
49class Class;
50class Namespace;
51class FunctionScope;
52
53class Symbol
54{
55public:
56 Symbol(PTree::Encoding const &t, PTree::Node const *p, bool def, Scope *s)
57 : my_type(t), my_ptree(p), my_definition(def), my_scope(s) {}
58 virtual ~Symbol(){}
59 virtual void accept(SymbolVisitor *v) const { v->visit(this);}
60 PTree::Encoding const & type() const { return my_type;}
61 PTree::Node const * ptree() const { return my_ptree;}
62 bool is_definition() const { return my_definition;}
63 Scope * scope() const { return my_scope;}
64private:
65 PTree::Encoding my_type;
66 PTree::Node const * my_ptree;
67 bool my_definition;
68 Scope * my_scope;
69};
70
71class VariableName : public Symbol
72{
73public:
74 VariableName(PTree::Encoding const &type, PTree::Node const *ptree,
75 bool def, Scope *s)
76 : Symbol(type, ptree, def, s) {}
77 virtual void accept(SymbolVisitor *v) const { v->visit(this);}
78};
79
80class ConstName : public VariableName
81{
82public:
83 ConstName(PTree::Encoding const &type, long v,
84 PTree::Node const *ptree, bool def, Scope *s)
85 : VariableName(type, ptree, def, s), my_defined(true), my_value(v) {}
86 ConstName(PTree::Encoding const &type,
87 PTree::Node const *ptree, bool def, Scope *s)
88 : VariableName(type, ptree, def, s), my_defined(false) {}
89 virtual void accept(SymbolVisitor *v) const { v->visit(this);}
90 bool defined() const { return my_defined;}
91 long value() const { return my_value;}
92private:
93 bool my_defined;
94 long my_value;
95};
96
97class TypeName : public Symbol
98{
99public:
100 TypeName(PTree::Encoding const &type, PTree::Node const *ptree,
101 bool def, Scope *s)
102 : Symbol(type, ptree, def, s) {}
103 virtual void accept(SymbolVisitor *v) const { v->visit(this);}
104};
105
106class TypedefName : public TypeName
107{
108public:
109 TypedefName(PTree::Encoding const &type, PTree::Node const *ptree, Scope *scope)
110 : TypeName(type, ptree, false, scope) {}
111 virtual void accept(SymbolVisitor *v) const { v->visit(this);}
112};
113
114class ClassName : public TypeName
115{
116public:
117 ClassName(PTree::Encoding const &type, PTree::Node const *ptree, bool def, Scope *s)
118 : TypeName(type, ptree, def, s) {}
119 virtual void accept(SymbolVisitor *v) const { v->visit(this);}
120
121
122
123 Class *as_scope() const;
124};
125
126class EnumName : public TypeName
127{
128public:
129 EnumName(PTree::Encoding const &type, PTree::Node const *ptree, Scope *scope)
130 : TypeName(type, ptree, true, scope) {}
131 virtual void accept(SymbolVisitor *v) const { v->visit(this);}
132};
133
134class ClassTemplateName : public Symbol
135{
136public:
137 ClassTemplateName(PTree::Encoding const &type, PTree::Node const *ptree, bool def,
138 Scope *s)
139 : Symbol(type, ptree, def, s) {}
140 virtual void accept(SymbolVisitor *v) const { v->visit(this);}
141
142
143
144 Class *as_scope() const;
145};
146
147class FunctionName : public Symbol
148{
149public:
150 FunctionName(PTree::Encoding const &type, PTree::Node const *ptree,
151 bool def, Scope *s)
152 : Symbol(type, ptree, def, s) {}
153 virtual void accept(SymbolVisitor *v) const { v->visit(this);}
154
155
156
157 FunctionScope *as_scope() const;
158};
159
160class FunctionTemplateName : public Symbol
161{
162public:
163 FunctionTemplateName(PTree::Encoding const &type, PTree::Node const *ptree, Scope *s)
164 : Symbol(type, ptree, true, s) {}
165 virtual void accept(SymbolVisitor *v) const { v->visit(this);}
166
167
168
169 FunctionScope *as_scope() const;
170};
171
172class NamespaceName : public Symbol
173{
174public:
175 NamespaceName(PTree::Encoding const &type, PTree::Node const *ptree,
176 bool def, Scope *s)
177 : Symbol(type, ptree, def, s) {}
178 virtual void accept(SymbolVisitor *v) const { v->visit(this);}
179
180
181
182 Namespace *as_scope() const;
183};
184
185}
186}
187
188#endif
Generated on Thu Apr 16 16:28:04 2009 by
synopsis (version devel)