MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / CompositeType

Class CompositeType

include/ast/type.h:174–232  ·  view source on GitHub ↗

AST CompositeType node for GC proposal.

Source from the content-addressed store, hash-verified

172
173/// AST CompositeType node for GC proposal.
174class CompositeType {
175public:
176 /// Constructors.
177 CompositeType() noexcept = default;
178 CompositeType(const FunctionType &FT) noexcept
179 : Type(TypeCode::Func), FType(FT) {}
180
181 /// Getter for content.
182 const FunctionType &getFuncType() const noexcept {
183 return *std::get_if<FunctionType>(&FType);
184 }
185 FunctionType &getFuncType() noexcept {
186 return *std::get_if<FunctionType>(&FType);
187 }
188 const std::vector<FieldType> &getFieldTypes() const noexcept {
189 return *std::get_if<std::vector<FieldType>>(&FType);
190 }
191
192 /// Setter for content.
193 void setArrayType(FieldType &&FT) noexcept {
194 Type = TypeCode::Array;
195 FType = std::vector<FieldType>{std::move(FT)};
196 }
197 void setStructType(std::vector<FieldType> &&VFT) noexcept {
198 Type = TypeCode::Struct;
199 FType = std::move(VFT);
200 }
201 void setFunctionType(FunctionType &&FT) noexcept {
202 Type = TypeCode::Func;
203 FType = std::move(FT);
204 }
205
206 /// Getter for content type.
207 TypeCode getContentTypeCode() const noexcept { return Type; }
208
209 /// Check whether this is a function type.
210 bool isFunc() const noexcept { return (Type == TypeCode::Func); }
211
212 /// Expand the composite type to its reference.
213 TypeCode expand() const noexcept {
214 switch (Type) {
215 case TypeCode::Func:
216 return TypeCode::FuncRef;
217 case TypeCode::Struct:
218 return TypeCode::StructRef;
219 case TypeCode::Array:
220 return TypeCode::ArrayRef;
221 default:
222 assumingUnreachable();
223 }
224 }
225
226private:
227 /// \name Data of CompositeType.
228 /// @{
229 TypeCode Type;
230 std::variant<std::vector<FieldType>, FunctionType> FType;
231 /// @}

Callers 1

TESTFunction · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68