1 // Copyright 2017 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_TORQUE_TYPE_VISITOR_H_ 6 #define V8_TORQUE_TYPE_VISITOR_H_ 7 8 #include <string> 9 10 #include "src/torque/ast.h" 11 #include "src/torque/types.h" 12 13 namespace v8 { 14 namespace internal { 15 namespace torque { 16 17 class Scope; 18 19 class TypeVisitor { 20 public: ComputeTypeVector(const std::vector<TypeExpression * > & v)21 static TypeVector ComputeTypeVector(const std::vector<TypeExpression*>& v) { 22 TypeVector result; 23 for (TypeExpression* t : v) { 24 result.push_back(ComputeType(t)); 25 } 26 return result; 27 } 28 29 static const Type* ComputeType(TypeExpression* type_expression); 30 static void VisitClassFieldsAndMethods( 31 ClassType* class_type, const ClassDeclaration* class_declaration); 32 static void VisitStructMethods(StructType* struct_type, 33 const StructDeclaration* struct_declaration); 34 static Signature MakeSignature(const CallableDeclaration* declaration); 35 // Can return either StructType or BitFieldStructType, since they can both be 36 // used in struct expressions like `MyStruct{ a: 0, b: foo }` 37 static const Type* ComputeTypeForStructExpression( 38 TypeExpression* type_expression, 39 const std::vector<const Type*>& term_argument_types); 40 41 private: 42 friend class TypeAlias; 43 friend class TypeOracle; 44 static const Type* ComputeType( 45 TypeDeclaration* decl, 46 MaybeSpecializationKey specialized_from = base::nullopt, 47 Scope* specialization_requester = nullptr); 48 static const AbstractType* ComputeType( 49 AbstractTypeDeclaration* decl, MaybeSpecializationKey specialized_from); 50 static const Type* ComputeType(TypeAliasDeclaration* decl, 51 MaybeSpecializationKey specialized_from); 52 static const BitFieldStructType* ComputeType( 53 BitFieldStructDeclaration* decl, MaybeSpecializationKey specialized_from); 54 static const StructType* ComputeType(StructDeclaration* decl, 55 MaybeSpecializationKey specialized_from); 56 static const ClassType* ComputeType(ClassDeclaration* decl, 57 MaybeSpecializationKey specialized_from); 58 }; 59 60 } // namespace torque 61 } // namespace internal 62 } // namespace v8 63 64 #endif // V8_TORQUE_TYPE_VISITOR_H_ 65