1 // Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20
21 #include "CoreTypes.h"
22 #include "TypeVisitor.h"
23 #include "Matcher.h"
24 #include "Names.h"
25 #include <algorithm>
26
27 using namespace CPlusPlus;
28
accept0(TypeVisitor * visitor)29 void UndefinedType::accept0(TypeVisitor *visitor)
30 { visitor->visit(this); }
31
match0(const Type * otherType,Matcher * matcher) const32 bool UndefinedType::match0(const Type *otherType, Matcher *matcher) const
33 {
34 if (const UndefinedType *otherUndefinedTy = otherType->asUndefinedType())
35 return matcher->match(this, otherUndefinedTy);
36
37 return false;
38 }
39
accept0(TypeVisitor * visitor)40 void VoidType::accept0(TypeVisitor *visitor)
41 { visitor->visit(this); }
42
match0(const Type * otherType,Matcher * matcher) const43 bool VoidType::match0(const Type *otherType, Matcher *matcher) const
44 {
45 if (const VoidType *otherVoidTy = otherType->asVoidType())
46 return matcher->match(this, otherVoidTy);
47
48 return false;
49 }
50
PointerToMemberType(const Name * memberName,const FullySpecifiedType & elementType)51 PointerToMemberType::PointerToMemberType(const Name *memberName, const FullySpecifiedType &elementType)
52 : _memberName(memberName),
53 _elementType(elementType)
54 { }
55
~PointerToMemberType()56 PointerToMemberType::~PointerToMemberType()
57 { }
58
memberName() const59 const Name *PointerToMemberType::memberName() const
60 { return _memberName; }
61
elementType() const62 FullySpecifiedType PointerToMemberType::elementType() const
63 { return _elementType; }
64
accept0(TypeVisitor * visitor)65 void PointerToMemberType::accept0(TypeVisitor *visitor)
66 { visitor->visit(this); }
67
match0(const Type * otherType,Matcher * matcher) const68 bool PointerToMemberType::match0(const Type *otherType, Matcher *matcher) const
69 {
70 if (const PointerToMemberType *otherTy = otherType->asPointerToMemberType())
71 return matcher->match(this, otherTy);
72
73 return false;
74 }
75
PointerType(const FullySpecifiedType & elementType)76 PointerType::PointerType(const FullySpecifiedType &elementType)
77 : _elementType(elementType)
78 { }
79
~PointerType()80 PointerType::~PointerType()
81 { }
82
accept0(TypeVisitor * visitor)83 void PointerType::accept0(TypeVisitor *visitor)
84 { visitor->visit(this); }
85
match0(const Type * otherType,Matcher * matcher) const86 bool PointerType::match0(const Type *otherType, Matcher *matcher) const
87 {
88 if (const PointerType *otherTy = otherType->asPointerType())
89 return matcher->match(this, otherTy);
90
91 return false;
92 }
93
elementType() const94 FullySpecifiedType PointerType::elementType() const
95 { return _elementType; }
96
ReferenceType(const FullySpecifiedType & elementType,bool rvalueRef)97 ReferenceType::ReferenceType(const FullySpecifiedType &elementType, bool rvalueRef)
98 : _elementType(elementType), _rvalueReference(rvalueRef)
99 { }
100
~ReferenceType()101 ReferenceType::~ReferenceType()
102 { }
103
accept0(TypeVisitor * visitor)104 void ReferenceType::accept0(TypeVisitor *visitor)
105 { visitor->visit(this); }
106
match0(const Type * otherType,Matcher * matcher) const107 bool ReferenceType::match0(const Type *otherType, Matcher *matcher) const
108 {
109 if (const ReferenceType *otherTy = otherType->asReferenceType())
110 return matcher->match(this, otherTy);
111
112 return false;
113 }
114
elementType() const115 FullySpecifiedType ReferenceType::elementType() const
116 { return _elementType; }
117
isRvalueReference() const118 bool ReferenceType::isRvalueReference() const
119 { return _rvalueReference; }
120
IntegerType(int kind)121 IntegerType::IntegerType(int kind)
122 : _kind(kind)
123 { }
124
~IntegerType()125 IntegerType::~IntegerType()
126 { }
127
accept0(TypeVisitor * visitor)128 void IntegerType::accept0(TypeVisitor *visitor)
129 { visitor->visit(this); }
130
match0(const Type * otherType,Matcher * matcher) const131 bool IntegerType::match0(const Type *otherType, Matcher *matcher) const
132 {
133 if (const IntegerType *otherTy = otherType->asIntegerType())
134 return matcher->match(this, otherTy);
135
136 return false;
137 }
138
kind() const139 int IntegerType::kind() const
140 { return _kind; }
141
FloatType(int kind)142 FloatType::FloatType(int kind)
143 : _kind(kind)
144 { }
145
~FloatType()146 FloatType::~FloatType()
147 { }
148
accept0(TypeVisitor * visitor)149 void FloatType::accept0(TypeVisitor *visitor)
150 { visitor->visit(this); }
151
match0(const Type * otherType,Matcher * matcher) const152 bool FloatType::match0(const Type *otherType, Matcher *matcher) const
153 {
154 if (const FloatType *otherTy = otherType->asFloatType())
155 return matcher->match(this, otherTy);
156
157 return false;
158 }
159
kind() const160 int FloatType::kind() const
161 { return _kind; }
162
ArrayType(const FullySpecifiedType & elementType,unsigned size)163 ArrayType::ArrayType(const FullySpecifiedType &elementType, unsigned size)
164 : _elementType(elementType), _size(size)
165 { }
166
~ArrayType()167 ArrayType::~ArrayType()
168 { }
169
accept0(TypeVisitor * visitor)170 void ArrayType::accept0(TypeVisitor *visitor)
171 { visitor->visit(this); }
172
match0(const Type * otherType,Matcher * matcher) const173 bool ArrayType::match0(const Type *otherType, Matcher *matcher) const
174 {
175 if (const ArrayType *otherTy = otherType->asArrayType())
176 return matcher->match(this, otherTy);
177
178 return false;
179 }
180
elementType() const181 FullySpecifiedType ArrayType::elementType() const
182 { return _elementType; }
183
size() const184 unsigned ArrayType::size() const
185 { return _size; }
186
NamedType(const Name * name)187 NamedType::NamedType(const Name *name)
188 : _name(name)
189 { }
190
~NamedType()191 NamedType::~NamedType()
192 { }
193
name() const194 const Name *NamedType::name() const
195 { return _name; }
196
accept0(TypeVisitor * visitor)197 void NamedType::accept0(TypeVisitor *visitor)
198 { visitor->visit(this); }
199
match0(const Type * otherType,Matcher * matcher) const200 bool NamedType::match0(const Type *otherType, Matcher *matcher) const
201 {
202 if (const NamedType *otherTy = otherType->asNamedType())
203 return matcher->match(this, otherTy);
204
205 return false;
206 }
207