1 /*
2 This file is part of solidity.
3
4 solidity is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 solidity is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with solidity. If not, see <http://www.gnu.org/licenses/>.
16 */
17 // SPDX-License-Identifier: GPL-3.0
18
19 #include <libsolidity/ast/AST.h>
20 #include <libsolidity/ast/TypeProvider.h>
21 #include <boost/algorithm/string.hpp>
22 #include <boost/algorithm/string/split.hpp>
23
24 using namespace std;
25 using namespace solidity;
26 using namespace solidity::frontend;
27 using namespace solidity::util;
28
29 BoolType const TypeProvider::m_boolean{};
30 InaccessibleDynamicType const TypeProvider::m_inaccessibleDynamic{};
31
32 /// The string and bytes unique_ptrs are initialized when they are first used because
33 /// they rely on `byte` being available which we cannot guarantee in the static init context.
34 unique_ptr<ArrayType> TypeProvider::m_bytesStorage;
35 unique_ptr<ArrayType> TypeProvider::m_bytesMemory;
36 unique_ptr<ArrayType> TypeProvider::m_bytesCalldata;
37 unique_ptr<ArrayType> TypeProvider::m_stringStorage;
38 unique_ptr<ArrayType> TypeProvider::m_stringMemory;
39
40 TupleType const TypeProvider::m_emptyTuple{};
41 AddressType const TypeProvider::m_payableAddress{StateMutability::Payable};
42 AddressType const TypeProvider::m_address{StateMutability::NonPayable};
43
44 array<unique_ptr<IntegerType>, 32> const TypeProvider::m_intM{{
45 {make_unique<IntegerType>(8 * 1, IntegerType::Modifier::Signed)},
46 {make_unique<IntegerType>(8 * 2, IntegerType::Modifier::Signed)},
47 {make_unique<IntegerType>(8 * 3, IntegerType::Modifier::Signed)},
48 {make_unique<IntegerType>(8 * 4, IntegerType::Modifier::Signed)},
49 {make_unique<IntegerType>(8 * 5, IntegerType::Modifier::Signed)},
50 {make_unique<IntegerType>(8 * 6, IntegerType::Modifier::Signed)},
51 {make_unique<IntegerType>(8 * 7, IntegerType::Modifier::Signed)},
52 {make_unique<IntegerType>(8 * 8, IntegerType::Modifier::Signed)},
53 {make_unique<IntegerType>(8 * 9, IntegerType::Modifier::Signed)},
54 {make_unique<IntegerType>(8 * 10, IntegerType::Modifier::Signed)},
55 {make_unique<IntegerType>(8 * 11, IntegerType::Modifier::Signed)},
56 {make_unique<IntegerType>(8 * 12, IntegerType::Modifier::Signed)},
57 {make_unique<IntegerType>(8 * 13, IntegerType::Modifier::Signed)},
58 {make_unique<IntegerType>(8 * 14, IntegerType::Modifier::Signed)},
59 {make_unique<IntegerType>(8 * 15, IntegerType::Modifier::Signed)},
60 {make_unique<IntegerType>(8 * 16, IntegerType::Modifier::Signed)},
61 {make_unique<IntegerType>(8 * 17, IntegerType::Modifier::Signed)},
62 {make_unique<IntegerType>(8 * 18, IntegerType::Modifier::Signed)},
63 {make_unique<IntegerType>(8 * 19, IntegerType::Modifier::Signed)},
64 {make_unique<IntegerType>(8 * 20, IntegerType::Modifier::Signed)},
65 {make_unique<IntegerType>(8 * 21, IntegerType::Modifier::Signed)},
66 {make_unique<IntegerType>(8 * 22, IntegerType::Modifier::Signed)},
67 {make_unique<IntegerType>(8 * 23, IntegerType::Modifier::Signed)},
68 {make_unique<IntegerType>(8 * 24, IntegerType::Modifier::Signed)},
69 {make_unique<IntegerType>(8 * 25, IntegerType::Modifier::Signed)},
70 {make_unique<IntegerType>(8 * 26, IntegerType::Modifier::Signed)},
71 {make_unique<IntegerType>(8 * 27, IntegerType::Modifier::Signed)},
72 {make_unique<IntegerType>(8 * 28, IntegerType::Modifier::Signed)},
73 {make_unique<IntegerType>(8 * 29, IntegerType::Modifier::Signed)},
74 {make_unique<IntegerType>(8 * 30, IntegerType::Modifier::Signed)},
75 {make_unique<IntegerType>(8 * 31, IntegerType::Modifier::Signed)},
76 {make_unique<IntegerType>(8 * 32, IntegerType::Modifier::Signed)}
77 }};
78
79 array<unique_ptr<IntegerType>, 32> const TypeProvider::m_uintM{{
80 {make_unique<IntegerType>(8 * 1, IntegerType::Modifier::Unsigned)},
81 {make_unique<IntegerType>(8 * 2, IntegerType::Modifier::Unsigned)},
82 {make_unique<IntegerType>(8 * 3, IntegerType::Modifier::Unsigned)},
83 {make_unique<IntegerType>(8 * 4, IntegerType::Modifier::Unsigned)},
84 {make_unique<IntegerType>(8 * 5, IntegerType::Modifier::Unsigned)},
85 {make_unique<IntegerType>(8 * 6, IntegerType::Modifier::Unsigned)},
86 {make_unique<IntegerType>(8 * 7, IntegerType::Modifier::Unsigned)},
87 {make_unique<IntegerType>(8 * 8, IntegerType::Modifier::Unsigned)},
88 {make_unique<IntegerType>(8 * 9, IntegerType::Modifier::Unsigned)},
89 {make_unique<IntegerType>(8 * 10, IntegerType::Modifier::Unsigned)},
90 {make_unique<IntegerType>(8 * 11, IntegerType::Modifier::Unsigned)},
91 {make_unique<IntegerType>(8 * 12, IntegerType::Modifier::Unsigned)},
92 {make_unique<IntegerType>(8 * 13, IntegerType::Modifier::Unsigned)},
93 {make_unique<IntegerType>(8 * 14, IntegerType::Modifier::Unsigned)},
94 {make_unique<IntegerType>(8 * 15, IntegerType::Modifier::Unsigned)},
95 {make_unique<IntegerType>(8 * 16, IntegerType::Modifier::Unsigned)},
96 {make_unique<IntegerType>(8 * 17, IntegerType::Modifier::Unsigned)},
97 {make_unique<IntegerType>(8 * 18, IntegerType::Modifier::Unsigned)},
98 {make_unique<IntegerType>(8 * 19, IntegerType::Modifier::Unsigned)},
99 {make_unique<IntegerType>(8 * 20, IntegerType::Modifier::Unsigned)},
100 {make_unique<IntegerType>(8 * 21, IntegerType::Modifier::Unsigned)},
101 {make_unique<IntegerType>(8 * 22, IntegerType::Modifier::Unsigned)},
102 {make_unique<IntegerType>(8 * 23, IntegerType::Modifier::Unsigned)},
103 {make_unique<IntegerType>(8 * 24, IntegerType::Modifier::Unsigned)},
104 {make_unique<IntegerType>(8 * 25, IntegerType::Modifier::Unsigned)},
105 {make_unique<IntegerType>(8 * 26, IntegerType::Modifier::Unsigned)},
106 {make_unique<IntegerType>(8 * 27, IntegerType::Modifier::Unsigned)},
107 {make_unique<IntegerType>(8 * 28, IntegerType::Modifier::Unsigned)},
108 {make_unique<IntegerType>(8 * 29, IntegerType::Modifier::Unsigned)},
109 {make_unique<IntegerType>(8 * 30, IntegerType::Modifier::Unsigned)},
110 {make_unique<IntegerType>(8 * 31, IntegerType::Modifier::Unsigned)},
111 {make_unique<IntegerType>(8 * 32, IntegerType::Modifier::Unsigned)}
112 }};
113
114 array<unique_ptr<FixedBytesType>, 32> const TypeProvider::m_bytesM{{
115 {make_unique<FixedBytesType>(1)},
116 {make_unique<FixedBytesType>(2)},
117 {make_unique<FixedBytesType>(3)},
118 {make_unique<FixedBytesType>(4)},
119 {make_unique<FixedBytesType>(5)},
120 {make_unique<FixedBytesType>(6)},
121 {make_unique<FixedBytesType>(7)},
122 {make_unique<FixedBytesType>(8)},
123 {make_unique<FixedBytesType>(9)},
124 {make_unique<FixedBytesType>(10)},
125 {make_unique<FixedBytesType>(11)},
126 {make_unique<FixedBytesType>(12)},
127 {make_unique<FixedBytesType>(13)},
128 {make_unique<FixedBytesType>(14)},
129 {make_unique<FixedBytesType>(15)},
130 {make_unique<FixedBytesType>(16)},
131 {make_unique<FixedBytesType>(17)},
132 {make_unique<FixedBytesType>(18)},
133 {make_unique<FixedBytesType>(19)},
134 {make_unique<FixedBytesType>(20)},
135 {make_unique<FixedBytesType>(21)},
136 {make_unique<FixedBytesType>(22)},
137 {make_unique<FixedBytesType>(23)},
138 {make_unique<FixedBytesType>(24)},
139 {make_unique<FixedBytesType>(25)},
140 {make_unique<FixedBytesType>(26)},
141 {make_unique<FixedBytesType>(27)},
142 {make_unique<FixedBytesType>(28)},
143 {make_unique<FixedBytesType>(29)},
144 {make_unique<FixedBytesType>(30)},
145 {make_unique<FixedBytesType>(31)},
146 {make_unique<FixedBytesType>(32)}
147 }};
148
149 array<unique_ptr<MagicType>, 4> const TypeProvider::m_magics{{
150 {make_unique<MagicType>(MagicType::Kind::Block)},
151 {make_unique<MagicType>(MagicType::Kind::Message)},
152 {make_unique<MagicType>(MagicType::Kind::Transaction)},
153 {make_unique<MagicType>(MagicType::Kind::ABI)}
154 // MetaType is stored separately
155 }};
156
clearCache(Type const & type)157 inline void clearCache(Type const& type)
158 {
159 type.clearCache();
160 }
161
162 template <typename T>
clearCache(unique_ptr<T> const & type)163 inline void clearCache(unique_ptr<T> const& type)
164 {
165 // Some lazy-initialized types might not exist yet.
166 if (type)
167 type->clearCache();
168 }
169
170 template <typename Container>
clearCaches(Container & container)171 inline void clearCaches(Container& container)
172 {
173 for (auto const& e: container)
174 clearCache(e);
175 }
176
reset()177 void TypeProvider::reset()
178 {
179 clearCache(m_boolean);
180 clearCache(m_inaccessibleDynamic);
181 clearCache(m_bytesStorage);
182 clearCache(m_bytesMemory);
183 clearCache(m_bytesCalldata);
184 clearCache(m_stringStorage);
185 clearCache(m_stringMemory);
186 clearCache(m_emptyTuple);
187 clearCache(m_payableAddress);
188 clearCache(m_address);
189 clearCaches(instance().m_intM);
190 clearCaches(instance().m_uintM);
191 clearCaches(instance().m_bytesM);
192 clearCaches(instance().m_magics);
193
194 instance().m_generalTypes.clear();
195 instance().m_stringLiteralTypes.clear();
196 instance().m_ufixedMxN.clear();
197 instance().m_fixedMxN.clear();
198 }
199
200 template <typename T, typename... Args>
createAndGet(Args &&..._args)201 inline T const* TypeProvider::createAndGet(Args&& ... _args)
202 {
203 instance().m_generalTypes.emplace_back(make_unique<T>(std::forward<Args>(_args)...));
204 return static_cast<T const*>(instance().m_generalTypes.back().get());
205 }
206
fromElementaryTypeName(ElementaryTypeNameToken const & _type,std::optional<StateMutability> _stateMutability)207 Type const* TypeProvider::fromElementaryTypeName(ElementaryTypeNameToken const& _type, std::optional<StateMutability> _stateMutability)
208 {
209 solAssert(
210 TokenTraits::isElementaryTypeName(_type.token()),
211 "Expected an elementary type name but got " + _type.toString()
212 );
213
214 unsigned const m = _type.firstNumber();
215 unsigned const n = _type.secondNumber();
216
217 switch (_type.token())
218 {
219 case Token::IntM:
220 return integer(m, IntegerType::Modifier::Signed);
221 case Token::UIntM:
222 return integer(m, IntegerType::Modifier::Unsigned);
223 case Token::Byte:
224 return byte();
225 case Token::BytesM:
226 return fixedBytes(m);
227 case Token::FixedMxN:
228 return fixedPoint(m, n, FixedPointType::Modifier::Signed);
229 case Token::UFixedMxN:
230 return fixedPoint(m, n, FixedPointType::Modifier::Unsigned);
231 case Token::Int:
232 return integer(256, IntegerType::Modifier::Signed);
233 case Token::UInt:
234 return integer(256, IntegerType::Modifier::Unsigned);
235 case Token::Fixed:
236 return fixedPoint(128, 18, FixedPointType::Modifier::Signed);
237 case Token::UFixed:
238 return fixedPoint(128, 18, FixedPointType::Modifier::Unsigned);
239 case Token::Address:
240 {
241 if (_stateMutability)
242 {
243 solAssert(*_stateMutability == StateMutability::Payable, "");
244 return payableAddress();
245 }
246 return address();
247 }
248 case Token::Bool:
249 return boolean();
250 case Token::Bytes:
251 return bytesStorage();
252 case Token::String:
253 return stringStorage();
254 default:
255 solAssert(
256 false,
257 "Unable to convert elementary typename " + _type.toString() + " to type."
258 );
259 }
260 }
261
fromElementaryTypeName(string const & _name)262 Type const* TypeProvider::fromElementaryTypeName(string const& _name)
263 {
264 vector<string> nameParts;
265 boost::split(nameParts, _name, boost::is_any_of(" "));
266 solAssert(nameParts.size() == 1 || nameParts.size() == 2, "Cannot parse elementary type: " + _name);
267
268 Token token;
269 unsigned short firstNum, secondNum;
270 tie(token, firstNum, secondNum) = TokenTraits::fromIdentifierOrKeyword(nameParts[0]);
271
272 auto t = fromElementaryTypeName(ElementaryTypeNameToken(token, firstNum, secondNum));
273 if (auto* ref = dynamic_cast<ReferenceType const*>(t))
274 {
275 DataLocation location = DataLocation::Storage;
276 if (nameParts.size() == 2)
277 {
278 if (nameParts[1] == "storage")
279 location = DataLocation::Storage;
280 else if (nameParts[1] == "calldata")
281 location = DataLocation::CallData;
282 else if (nameParts[1] == "memory")
283 location = DataLocation::Memory;
284 else
285 solAssert(false, "Unknown data location: " + nameParts[1]);
286 }
287 return withLocation(ref, location, true);
288 }
289 else if (t->category() == Type::Category::Address)
290 {
291 if (nameParts.size() == 2)
292 {
293 if (nameParts[1] == "payable")
294 return payableAddress();
295 else
296 solAssert(false, "Invalid state mutability for address type: " + nameParts[1]);
297 }
298 return address();
299 }
300 else
301 {
302 solAssert(nameParts.size() == 1, "Storage location suffix only allowed for reference types");
303 return t;
304 }
305 }
306
bytesStorage()307 ArrayType const* TypeProvider::bytesStorage()
308 {
309 if (!m_bytesStorage)
310 m_bytesStorage = make_unique<ArrayType>(DataLocation::Storage, false);
311 return m_bytesStorage.get();
312 }
313
bytesMemory()314 ArrayType const* TypeProvider::bytesMemory()
315 {
316 if (!m_bytesMemory)
317 m_bytesMemory = make_unique<ArrayType>(DataLocation::Memory, false);
318 return m_bytesMemory.get();
319 }
320
bytesCalldata()321 ArrayType const* TypeProvider::bytesCalldata()
322 {
323 if (!m_bytesCalldata)
324 m_bytesCalldata = make_unique<ArrayType>(DataLocation::CallData, false);
325 return m_bytesCalldata.get();
326 }
327
stringStorage()328 ArrayType const* TypeProvider::stringStorage()
329 {
330 if (!m_stringStorage)
331 m_stringStorage = make_unique<ArrayType>(DataLocation::Storage, true);
332 return m_stringStorage.get();
333 }
334
stringMemory()335 ArrayType const* TypeProvider::stringMemory()
336 {
337 if (!m_stringMemory)
338 m_stringMemory = make_unique<ArrayType>(DataLocation::Memory, true);
339 return m_stringMemory.get();
340 }
341
forLiteral(Literal const & _literal)342 Type const* TypeProvider::forLiteral(Literal const& _literal)
343 {
344 switch (_literal.token())
345 {
346 case Token::TrueLiteral:
347 case Token::FalseLiteral:
348 return boolean();
349 case Token::Number:
350 return rationalNumber(_literal);
351 case Token::StringLiteral:
352 case Token::UnicodeStringLiteral:
353 case Token::HexStringLiteral:
354 return stringLiteral(_literal.value());
355 default:
356 return nullptr;
357 }
358 }
359
rationalNumber(Literal const & _literal)360 RationalNumberType const* TypeProvider::rationalNumber(Literal const& _literal)
361 {
362 solAssert(_literal.token() == Token::Number, "");
363 std::tuple<bool, rational> validLiteral = RationalNumberType::isValidLiteral(_literal);
364 if (std::get<0>(validLiteral))
365 {
366 Type const* compatibleBytesType = nullptr;
367 if (_literal.isHexNumber())
368 {
369 size_t const digitCount = _literal.valueWithoutUnderscores().length() - 2;
370 if (digitCount % 2 == 0 && (digitCount / 2) <= 32)
371 compatibleBytesType = fixedBytes(static_cast<unsigned>(digitCount / 2));
372 }
373
374 return rationalNumber(std::get<1>(validLiteral), compatibleBytesType);
375 }
376 return nullptr;
377 }
378
stringLiteral(string const & literal)379 StringLiteralType const* TypeProvider::stringLiteral(string const& literal)
380 {
381 auto i = instance().m_stringLiteralTypes.find(literal);
382 if (i != instance().m_stringLiteralTypes.end())
383 return i->second.get();
384 else
385 return instance().m_stringLiteralTypes.emplace(literal, make_unique<StringLiteralType>(literal)).first->second.get();
386 }
387
fixedPoint(unsigned m,unsigned n,FixedPointType::Modifier _modifier)388 FixedPointType const* TypeProvider::fixedPoint(unsigned m, unsigned n, FixedPointType::Modifier _modifier)
389 {
390 auto& map = _modifier == FixedPointType::Modifier::Unsigned ? instance().m_ufixedMxN : instance().m_fixedMxN;
391
392 auto i = map.find(make_pair(m, n));
393 if (i != map.end())
394 return i->second.get();
395
396 return map.emplace(
397 make_pair(m, n),
398 make_unique<FixedPointType>(m, n, _modifier)
399 ).first->second.get();
400 }
401
tuple(vector<Type const * > members)402 TupleType const* TypeProvider::tuple(vector<Type const*> members)
403 {
404 if (members.empty())
405 return &m_emptyTuple;
406
407 return createAndGet<TupleType>(move(members));
408 }
409
withLocation(ReferenceType const * _type,DataLocation _location,bool _isPointer)410 ReferenceType const* TypeProvider::withLocation(ReferenceType const* _type, DataLocation _location, bool _isPointer)
411 {
412 if (_type->location() == _location && _type->isPointer() == _isPointer)
413 return _type;
414
415 instance().m_generalTypes.emplace_back(_type->copyForLocation(_location, _isPointer));
416 return static_cast<ReferenceType const*>(instance().m_generalTypes.back().get());
417 }
418
function(FunctionDefinition const & _function,FunctionType::Kind _kind)419 FunctionType const* TypeProvider::function(FunctionDefinition const& _function, FunctionType::Kind _kind)
420 {
421 return createAndGet<FunctionType>(_function, _kind);
422 }
423
function(VariableDeclaration const & _varDecl)424 FunctionType const* TypeProvider::function(VariableDeclaration const& _varDecl)
425 {
426 return createAndGet<FunctionType>(_varDecl);
427 }
428
function(EventDefinition const & _def)429 FunctionType const* TypeProvider::function(EventDefinition const& _def)
430 {
431 return createAndGet<FunctionType>(_def);
432 }
433
function(ErrorDefinition const & _def)434 FunctionType const* TypeProvider::function(ErrorDefinition const& _def)
435 {
436 return createAndGet<FunctionType>(_def);
437 }
438
function(FunctionTypeName const & _typeName)439 FunctionType const* TypeProvider::function(FunctionTypeName const& _typeName)
440 {
441 return createAndGet<FunctionType>(_typeName);
442 }
443
function(strings const & _parameterTypes,strings const & _returnParameterTypes,FunctionType::Kind _kind,bool _arbitraryParameters,StateMutability _stateMutability)444 FunctionType const* TypeProvider::function(
445 strings const& _parameterTypes,
446 strings const& _returnParameterTypes,
447 FunctionType::Kind _kind,
448 bool _arbitraryParameters,
449 StateMutability _stateMutability
450 )
451 {
452 return createAndGet<FunctionType>(
453 _parameterTypes, _returnParameterTypes,
454 _kind, _arbitraryParameters, _stateMutability
455 );
456 }
457
function(TypePointers const & _parameterTypes,TypePointers const & _returnParameterTypes,strings _parameterNames,strings _returnParameterNames,FunctionType::Kind _kind,bool _arbitraryParameters,StateMutability _stateMutability,Declaration const * _declaration,bool _gasSet,bool _valueSet,bool _bound,bool _saltSet)458 FunctionType const* TypeProvider::function(
459 TypePointers const& _parameterTypes,
460 TypePointers const& _returnParameterTypes,
461 strings _parameterNames,
462 strings _returnParameterNames,
463 FunctionType::Kind _kind,
464 bool _arbitraryParameters,
465 StateMutability _stateMutability,
466 Declaration const* _declaration,
467 bool _gasSet,
468 bool _valueSet,
469 bool _bound,
470 bool _saltSet
471 )
472 {
473 return createAndGet<FunctionType>(
474 _parameterTypes,
475 _returnParameterTypes,
476 _parameterNames,
477 _returnParameterNames,
478 _kind,
479 _arbitraryParameters,
480 _stateMutability,
481 _declaration,
482 _gasSet,
483 _valueSet,
484 _bound,
485 _saltSet
486 );
487 }
488
rationalNumber(rational const & _value,Type const * _compatibleBytesType)489 RationalNumberType const* TypeProvider::rationalNumber(rational const& _value, Type const* _compatibleBytesType)
490 {
491 return createAndGet<RationalNumberType>(_value, _compatibleBytesType);
492 }
493
array(DataLocation _location,bool _isString)494 ArrayType const* TypeProvider::array(DataLocation _location, bool _isString)
495 {
496 if (_isString)
497 {
498 if (_location == DataLocation::Storage)
499 return stringStorage();
500 if (_location == DataLocation::Memory)
501 return stringMemory();
502 }
503 else
504 {
505 if (_location == DataLocation::Storage)
506 return bytesStorage();
507 if (_location == DataLocation::Memory)
508 return bytesMemory();
509 }
510 return createAndGet<ArrayType>(_location, _isString);
511 }
512
array(DataLocation _location,Type const * _baseType)513 ArrayType const* TypeProvider::array(DataLocation _location, Type const* _baseType)
514 {
515 return createAndGet<ArrayType>(_location, _baseType);
516 }
517
array(DataLocation _location,Type const * _baseType,u256 const & _length)518 ArrayType const* TypeProvider::array(DataLocation _location, Type const* _baseType, u256 const& _length)
519 {
520 return createAndGet<ArrayType>(_location, _baseType, _length);
521 }
522
arraySlice(ArrayType const & _arrayType)523 ArraySliceType const* TypeProvider::arraySlice(ArrayType const& _arrayType)
524 {
525 return createAndGet<ArraySliceType>(_arrayType);
526 }
527
contract(ContractDefinition const & _contractDef,bool _isSuper)528 ContractType const* TypeProvider::contract(ContractDefinition const& _contractDef, bool _isSuper)
529 {
530 return createAndGet<ContractType>(_contractDef, _isSuper);
531 }
532
enumType(EnumDefinition const & _enumDef)533 EnumType const* TypeProvider::enumType(EnumDefinition const& _enumDef)
534 {
535 return createAndGet<EnumType>(_enumDef);
536 }
537
module(SourceUnit const & _source)538 ModuleType const* TypeProvider::module(SourceUnit const& _source)
539 {
540 return createAndGet<ModuleType>(_source);
541 }
542
typeType(Type const * _actualType)543 TypeType const* TypeProvider::typeType(Type const* _actualType)
544 {
545 return createAndGet<TypeType>(_actualType);
546 }
547
structType(StructDefinition const & _struct,DataLocation _location)548 StructType const* TypeProvider::structType(StructDefinition const& _struct, DataLocation _location)
549 {
550 return createAndGet<StructType>(_struct, _location);
551 }
552
modifier(ModifierDefinition const & _def)553 ModifierType const* TypeProvider::modifier(ModifierDefinition const& _def)
554 {
555 return createAndGet<ModifierType>(_def);
556 }
557
magic(MagicType::Kind _kind)558 MagicType const* TypeProvider::magic(MagicType::Kind _kind)
559 {
560 solAssert(_kind != MagicType::Kind::MetaType, "MetaType is handled separately");
561 return m_magics.at(static_cast<size_t>(_kind)).get();
562 }
563
meta(Type const * _type)564 MagicType const* TypeProvider::meta(Type const* _type)
565 {
566 solAssert(
567 _type && (
568 _type->category() == Type::Category::Contract ||
569 _type->category() == Type::Category::Integer ||
570 _type->category() == Type::Category::Enum
571 ),
572 "Only enum, contracts or integer types supported for now."
573 );
574 return createAndGet<MagicType>(_type);
575 }
576
mapping(Type const * _keyType,Type const * _valueType)577 MappingType const* TypeProvider::mapping(Type const* _keyType, Type const* _valueType)
578 {
579 return createAndGet<MappingType>(_keyType, _valueType);
580 }
581
userDefinedValueType(UserDefinedValueTypeDefinition const & _definition)582 UserDefinedValueType const* TypeProvider::userDefinedValueType(UserDefinedValueTypeDefinition const& _definition)
583 {
584 return createAndGet<UserDefinedValueType>(_definition);
585 }
586