@@ -297,6 +297,20 @@ enum class TypeEntryKind {
297297 Array,
298298};
299299
300+ struct TypeEntryGCTypeExtension {
301+ TypeEntryGCTypeExtension (bool is_final_sub_type)
302+ : is_final_sub_type(is_final_sub_type) {}
303+
304+ void InitSubTypes (Index* sub_type_list, Index sub_type_count);
305+
306+ bool is_final_sub_type;
307+ // The binary format allows more subtypes, although
308+ // the validator limits the list to maximum 1 value.
309+ // Furthermore the text parser must allow future
310+ // references although the validator also disallows this.
311+ std::vector<Var> sub_types;
312+ };
313+
300314class TypeEntry {
301315 public:
302316 WABT_DISALLOW_COPY_AND_ASSIGN (TypeEntry);
@@ -307,12 +321,17 @@ class TypeEntry {
307321
308322 Location loc;
309323 std::string name;
324+ TypeEntryGCTypeExtension gc_ext;
310325
311326 protected:
312327 explicit TypeEntry (TypeEntryKind kind,
328+ bool is_final_sub_type,
313329 std::string_view name = std::string_view(),
314330 const Location& loc = Location())
315- : loc(loc), name(name), kind_(kind) {}
331+ : loc(loc),
332+ name(name),
333+ gc_ext(is_final_sub_type),
334+ kind_(kind) {}
316335
317336 TypeEntryKind kind_;
318337};
@@ -323,8 +342,8 @@ class FuncType : public TypeEntry {
323342 return entry->kind () == TypeEntryKind::Func;
324343 }
325344
326- explicit FuncType (std::string_view name = std::string_view())
327- : TypeEntry(TypeEntryKind::Func, name) {}
345+ explicit FuncType (bool is_final_sub_type, std::string_view name = std::string_view())
346+ : TypeEntry(TypeEntryKind::Func, is_final_sub_type, name) {}
328347
329348 Index GetNumParams () const { return sig.GetNumParams (); }
330349 Index GetNumResults () const { return sig.GetNumResults (); }
@@ -353,8 +372,8 @@ class StructType : public TypeEntry {
353372 return entry->kind () == TypeEntryKind::Struct;
354373 }
355374
356- explicit StructType (std::string_view name = std::string_view())
357- : TypeEntry(TypeEntryKind::Struct) {}
375+ explicit StructType (bool is_final_sub_type, std::string_view name = std::string_view())
376+ : TypeEntry(TypeEntryKind::Struct, is_final_sub_type, name ) {}
358377
359378 std::vector<Field> fields;
360379};
@@ -365,12 +384,17 @@ class ArrayType : public TypeEntry {
365384 return entry->kind () == TypeEntryKind::Array;
366385 }
367386
368- explicit ArrayType (std::string_view name = std::string_view())
369- : TypeEntry(TypeEntryKind::Array) {}
387+ explicit ArrayType (bool is_final_sub_type, std::string_view name = std::string_view())
388+ : TypeEntry(TypeEntryKind::Array, is_final_sub_type, name ) {}
370389
371390 Field field;
372391};
373392
393+ struct RecursiveRange {
394+ Index start_index;
395+ Index type_count;
396+ };
397+
374398struct FuncDeclaration {
375399 Index GetNumParams () const { return sig.GetNumParams (); }
376400 Index GetNumResults () const { return sig.GetNumResults (); }
@@ -1319,6 +1343,8 @@ struct Module {
13191343 std::vector<Import*> imports;
13201344 std::vector<Export*> exports;
13211345 std::vector<TypeEntry*> types;
1346+ // Ordered list of recursive ranges. Needed for binary search.
1347+ std::vector<RecursiveRange> recursive_ranges;
13221348 std::vector<Table*> tables;
13231349 std::vector<ElemSegment*> elem_segments;
13241350 std::vector<Memory*> memories;
0 commit comments