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 "src/torque/ast.h" 9 #include "src/torque/types.h" 10 11 namespace v8 { 12 namespace internal { 13 namespace torque { 14 15 class Scope; 16 17 class TypeVisitor { 18 public: ComputeTypeVector(const std::vector<TypeExpression * > & v)19 static TypeVector ComputeTypeVector(const std::vector<TypeExpression*>& v) { 20 TypeVector result; 21 for (TypeExpression* t : v) { 22 result.push_back(ComputeType(t)); 23 } 24 return result; 25 } 26 27 static const Type* ComputeType(TypeExpression* type_expression); 28 static void VisitClassFieldsAndMethods( 29 ClassType* class_type, const ClassDeclaration* class_declaration); 30 static void VisitStructMethods(StructType* struct_type, 31 const StructDeclaration* struct_declaration); 32 static Signature MakeSignature(const CallableDeclaration* declaration); 33 // Can return either StructType or BitFieldStructType, since they can both be 34 // used in struct expressions like `MyStruct{ a: 0, b: foo }` 35 static const Type* ComputeTypeForStructExpression( 36 TypeExpression* type_expression, 37 const std::vector<const Type*>& term_argument_types); 38 39 private: 40 friend class TypeAlias; 41 friend class TypeOracle; 42 static const Type* ComputeType( 43 TypeDeclaration* decl, 44 MaybeSpecializationKey specialized_from = base::nullopt, 45 Scope* specialization_requester = nullptr); 46 static const AbstractType* ComputeType( 47 AbstractTypeDeclaration* decl, MaybeSpecializationKey specialized_from); 48 static const Type* ComputeType(TypeAliasDeclaration* decl, 49 MaybeSpecializationKey specialized_from); 50 static const BitFieldStructType* ComputeType( 51 BitFieldStructDeclaration* decl, MaybeSpecializationKey specialized_from); 52 static const StructType* ComputeType(StructDeclaration* decl, 53 MaybeSpecializationKey specialized_from); 54 static const ClassType* ComputeType(ClassDeclaration* decl, 55 MaybeSpecializationKey specialized_from); 56 }; 57 58 } // namespace torque 59 } // namespace internal 60 } // namespace v8 61 62 #endif // V8_TORQUE_TYPE_VISITOR_H_ 63