Spicy
default.h
1 // Copyright (c) 2020-now by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <utility>
6 
7 #include <hilti/ast/ctor.h>
8 #include <hilti/ast/expression.h>
9 #include <hilti/ast/type.h>
10 
11 namespace hilti::ctor {
12 
14 class Default : public Ctor {
15 public:
16  auto typeArguments() const { return children<Expression>(1, {}); }
17 
18  QualifiedType* type() const final { return child<QualifiedType>(0); }
19 
20  void setTypeArguments(ASTContext* ctx, const Expressions& exprs) {
21  removeChildren(1, {});
22  addChildren(ctx, exprs);
23  }
24 
26  static auto create(ASTContext* ctx, UnqualifiedType* type, const Meta& meta = {}) {
27  return ctx->make<Default>(ctx, {QualifiedType::create(ctx, type, Constness::Mutable, meta)}, meta);
28  }
29 
34  static auto create(ASTContext* ctx, UnqualifiedType* type, const Expressions& type_args, const Meta& meta = {}) {
35  return ctx->make<Default>(ctx,
36  node::flatten(QualifiedType::create(ctx, type, Constness::Mutable, meta), type_args),
37  meta);
38  }
39 
40 protected:
41  Default(ASTContext* ctx, Nodes children, Meta meta) : Ctor(ctx, NodeTags, std::move(children), std::move(meta)) {}
42 
43  HILTI_NODE_1(ctor::Default, Ctor, final);
44 };
45 
46 } // namespace hilti::ctor
Definition: ast-context.h:121
T * make(Args &&... args)
Definition: ast-context.h:366
Definition: ctor.h:14
Definition: meta.h:30
const auto & children() const
Definition: node.h:364
const auto & meta() const
Definition: node.h:306
void removeChildren(int begin, std::optional< int > end)
Definition: node.h:575
void addChildren(ASTContext *ctx, const Nodes &children)
Definition: node.h:545
Definition: forward.h:758
Definition: type.h:362
static auto create(ASTContext *ctx, UnqualifiedType *t, Constness const_, Meta m=Meta())
Definition: type.h:427
Definition: type.h:148
Definition: default.h:14
static auto create(ASTContext *ctx, UnqualifiedType *type, const Meta &meta={})
Definition: default.h:26
QualifiedType * type() const final
Definition: default.h:18
static auto create(ASTContext *ctx, UnqualifiedType *type, const Expressions &type_args, const Meta &meta={})
Definition: default.h:34