2929#include  " wabt/opcode.h" 
3030#include  " wabt/type-checker.h" 
3131
32- #include  " wabt/binary-reader.h" //  For TypeMut.
33- 
3432namespace  wabt  {
3533
3634struct  ValidateOptions  {
@@ -43,7 +41,11 @@ struct ValidateOptions {
4341class  SharedValidator  {
4442 public: 
4543  WABT_DISALLOW_COPY_AND_ASSIGN (SharedValidator);
44+   using  TypeEntry = TypeChecker::TypeEntry;
4645  using  FuncType = TypeChecker::FuncType;
46+   using  StructType = TypeChecker::StructType;
47+   using  ArrayType = TypeChecker::ArrayType;
48+   using  RecursiveRange = TypeChecker::RecursiveRange;
4749  SharedValidator (Errors*, const  ValidateOptions& options);
4850
4951  //  TODO: Move into SharedValidator?
@@ -63,16 +65,28 @@ class SharedValidator {
6365
6466  Index GetLocalCount () const ;
6567
68+   //  The canonical index of a type is the index of the first type,
69+   //  which is equal to the original type. The canonical index is
70+   //  always less or equal than type_index.
71+   Index GetCanonicalTypeIndex (Index type_index);
72+ 
6673  Result EndModule ();
6774
75+   Result OnRecursiveType (Index first_type_index, Index type_count);
6876  Result OnFuncType (const  Location&,
6977                    Index param_count,
7078                    const  Type* param_types,
7179                    Index result_count,
7280                    const  Type* result_types,
73-                     Index type_index);
74-   Result OnStructType (const  Location&, Index field_count, TypeMut* fields);
75-   Result OnArrayType (const  Location&, TypeMut field);
81+                     Index type_index,
82+                     GCTypeExtension* gc_ext);
83+   Result OnStructType (const  Location&,
84+                       Index field_count,
85+                       TypeMut* fields,
86+                       GCTypeExtension* gc_ext);
87+   Result OnArrayType (const  Location&,
88+                      TypeMut field,
89+                      GCTypeExtension* gc_ext);
7690
7791  Result OnFunction (const  Location&, Var sig_var);
7892  Result OnTable (const  Location&, Type elem_type, const  Limits&, bool , bool );
@@ -225,20 +239,6 @@ class SharedValidator {
225239  Result OnUnreachable (const  Location&);
226240
227241 private: 
228-   struct  StructType  {
229-     StructType () = default ;
230-     StructType (const  TypeMutVector& fields) : fields(fields) {}
231- 
232-     TypeMutVector fields;
233-   };
234- 
235-   struct  ArrayType  {
236-     ArrayType () = default ;
237-     ArrayType (TypeMut field) : field(field) {}
238- 
239-     TypeMut field;
240-   };
241- 
242242  struct  TableType  {
243243    TableType () = default ;
244244    TableType (Type element, Limits limits) : element(element), limits(limits) {}
@@ -292,7 +292,11 @@ class SharedValidator {
292292                   Type actual,
293293                   Type expected,
294294                   const  char * desc);
295-   Result CheckReferenceType (const  Location&, Type type, const  char * desc);
295+   Result CheckReferenceType (const  Location&,
296+                             Type type,
297+                             Index end_index,
298+                             const  char * desc);
299+   Result CheckGCTypeExtension (const  Location&, GCTypeExtension* gc_ext);
296300  Result CheckLimits (const  Location&,
297301                     const  Limits&,
298302                     uint64_t  absolute_max,
@@ -337,17 +341,16 @@ class SharedValidator {
337341  void  RestoreLocalRefs (Result result);
338342  void  IgnoreLocalRefs ();
339343
344+   Index GetEndIndex ();
345+ 
340346  ValidateOptions options_;
341347  Errors* errors_;
342348  TypeChecker typechecker_;  //  TODO: Move into SharedValidator.
343349  //  Cached for access by OnTypecheckerError.
344350  Location expr_loc_ = Location(kInvalidOffset );
345351  bool  in_init_expr_ = false ;
346352
347-   Index num_types_ = 0 ;
348-   std::map<Index, FuncType> func_types_;
349-   std::map<Index, StructType> struct_types_;
350-   std::map<Index, ArrayType> array_types_;
353+   TypeChecker::TypeFields type_fields_;
351354
352355  std::vector<FuncType> funcs_;       //  Includes imported and defined.
353356  std::vector<TableType> tables_;     //  Includes imported and defined.
@@ -358,6 +361,9 @@ class SharedValidator {
358361  Index starts_ = 0 ;
359362  Index num_imported_globals_ = 0 ;
360363  Index data_segments_ = 0 ;
364+   Index last_rec_type_end_ = 0 ;
365+   //  Recursive type checks may enter to infinite loop for invalid values.
366+   Result type_validation_result_ = Result::Ok;
361367
362368  //  Includes parameters, since this is only used for validating
363369  //  local.{get,set,tee} instructions.
0 commit comments