@@ -36,7 +36,7 @@ namespace wabt {
3636
3737struct Module ;
3838
39- enum class VarType {
39+ enum class VarType : uint16_t {
4040 Index,
4141 Name,
4242};
@@ -45,6 +45,7 @@ struct Var {
4545 explicit Var ();
4646 explicit Var (Index index, const Location& loc);
4747 explicit Var (std::string_view name, const Location& loc);
48+ explicit Var (Type type, const Location& loc);
4849 Var (Var&&);
4950 Var (const Var&);
5051 Var& operator =(const Var&);
@@ -54,6 +55,7 @@ struct Var {
5455 VarType type () const { return type_; }
5556 bool is_index () const { return type_ == VarType::Index; }
5657 bool is_name () const { return type_ == VarType::Name; }
58+ bool has_opt_type () const { return opt_type_ < 0 ; }
5759
5860 Index index () const {
5961 assert (is_index ());
@@ -63,17 +65,25 @@ struct Var {
6365 assert (is_name ());
6466 return name_;
6567 }
68+ Type::Enum opt_type () const {
69+ assert (has_opt_type ());
70+ return static_cast <Type::Enum>(opt_type_);
71+ }
6672
6773 void set_index (Index);
6874 void set_name (std::string&&);
6975 void set_name (std::string_view);
76+ void set_opt_type (Type::Enum);
77+ Type to_type () const ;
7078
7179 Location loc;
7280
7381 private:
7482 void Destroy ();
7583
7684 VarType type_;
85+ // Can be set to Type::Enum types, 0 represent no optional type.
86+ int16_t opt_type_;
7787 union {
7888 Index index_;
7989 std::string name_;
@@ -544,10 +554,10 @@ using MemoryCopyExpr = MemoryBinaryExpr<ExprType::MemoryCopy>;
544554template <ExprType TypeEnum>
545555class RefTypeExpr : public ExprMixin <TypeEnum> {
546556 public:
547- RefTypeExpr (Type type, const Location& loc = Location())
557+ RefTypeExpr (Var type, const Location& loc = Location())
548558 : ExprMixin<TypeEnum>(loc), type(type) {}
549559
550- Type type;
560+ Var type;
551561};
552562
553563using RefNullExpr = RefTypeExpr<ExprType::RefNull>;
@@ -734,9 +744,7 @@ class CallRefExpr : public ExprMixin<ExprType::CallRef> {
734744 explicit CallRefExpr (const Location& loc = Location())
735745 : ExprMixin<ExprType::CallRef>(loc) {}
736746
737- // This field is setup only during Validate phase,
738- // so keep that in mind when you use it.
739- Var function_type_index;
747+ Var function_type;
740748};
741749
742750template <ExprType TypeEnum>
@@ -924,6 +932,8 @@ struct Func {
924932
925933 std::string name;
926934 FuncDeclaration decl;
935+ // Contains references with unknown indicies.
936+ TypeVector local_type_list;
927937 LocalTypes local_types;
928938 BindingHash bindings;
929939 ExprList exprs;
@@ -941,7 +951,7 @@ struct Global {
941951 explicit Global (std::string_view name) : name(name) {}
942952
943953 std::string name;
944- Type type = Type::Void ;
954+ Var type;
945955 bool mutable_ = false ;
946956 ExprList init_expr;
947957};
0 commit comments