|
26 | 26 |
|
27 | 27 | namespace Carbon { |
28 | 28 |
|
| 29 | +class MixinPseudoType; |
29 | 30 | class ConstraintType; |
30 | 31 |
|
31 | 32 | // Abstract base class of all AST nodes representing patterns. |
@@ -233,6 +234,70 @@ class ClassDeclaration : public Declaration { |
233 | 234 | std::vector<Nonnull<Declaration*>> members_; |
234 | 235 | }; |
235 | 236 |
|
| 237 | +// EXPERIMENTAL MIXIN FEATURE |
| 238 | +class MixinDeclaration : public Declaration { |
| 239 | + public: |
| 240 | + using ImplementsCarbonValueNode = void; |
| 241 | + |
| 242 | + MixinDeclaration(SourceLocation source_loc, std::string name, |
| 243 | + std::optional<Nonnull<TuplePattern*>> params, |
| 244 | + Nonnull<GenericBinding*> self, |
| 245 | + std::vector<Nonnull<Declaration*>> members) |
| 246 | + : Declaration(AstNodeKind::MixinDeclaration, source_loc), |
| 247 | + name_(std::move(name)), |
| 248 | + params_(std::move(params)), |
| 249 | + self_(self), |
| 250 | + members_(std::move(members)) {} |
| 251 | + |
| 252 | + static auto classof(const AstNode* node) -> bool { |
| 253 | + return InheritsFromMixinDeclaration(node->kind()); |
| 254 | + } |
| 255 | + |
| 256 | + auto name() const -> const std::string& { return name_; } |
| 257 | + auto params() const -> std::optional<Nonnull<const TuplePattern*>> { |
| 258 | + return params_; |
| 259 | + } |
| 260 | + auto params() -> std::optional<Nonnull<TuplePattern*>> { return params_; } |
| 261 | + auto self() const -> Nonnull<const GenericBinding*> { return self_; } |
| 262 | + auto self() -> Nonnull<GenericBinding*> { return self_; } |
| 263 | + auto members() const -> llvm::ArrayRef<Nonnull<Declaration*>> { |
| 264 | + return members_; |
| 265 | + } |
| 266 | + |
| 267 | + auto value_category() const -> ValueCategory { return ValueCategory::Let; } |
| 268 | + |
| 269 | + private: |
| 270 | + std::string name_; |
| 271 | + std::optional<Nonnull<TuplePattern*>> params_; |
| 272 | + Nonnull<GenericBinding*> self_; |
| 273 | + std::vector<Nonnull<Declaration*>> members_; |
| 274 | +}; |
| 275 | + |
| 276 | +// EXPERIMENTAL MIXIN FEATURE |
| 277 | +class MixDeclaration : public Declaration { |
| 278 | + public: |
| 279 | + MixDeclaration(SourceLocation source_loc, |
| 280 | + std::optional<Nonnull<Expression*>> mixin_type) |
| 281 | + : Declaration(AstNodeKind::MixDeclaration, source_loc), |
| 282 | + mixin_(mixin_type) {} |
| 283 | + |
| 284 | + static auto classof(const AstNode* node) -> bool { |
| 285 | + return InheritsFromMixDeclaration(node->kind()); |
| 286 | + } |
| 287 | + |
| 288 | + auto mixin() const -> const Expression& { return **mixin_; } |
| 289 | + auto mixin() -> Expression& { return **mixin_; } |
| 290 | + |
| 291 | + auto mixin_value() const -> const MixinPseudoType& { return *mixin_value_; } |
| 292 | + void set_mixin_value(Nonnull<const MixinPseudoType*> mixin_value) { |
| 293 | + mixin_value_ = mixin_value; |
| 294 | + } |
| 295 | + |
| 296 | + private: |
| 297 | + std::optional<Nonnull<Expression*>> mixin_; |
| 298 | + Nonnull<const MixinPseudoType*> mixin_value_; |
| 299 | +}; |
| 300 | + |
236 | 301 | class AlternativeSignature : public AstNode { |
237 | 302 | public: |
238 | 303 | AlternativeSignature(SourceLocation source_loc, std::string name, |
|
0 commit comments