Spicy
comment.h
1 // Copyright (c) 2020-now by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <string>
6 #include <utility>
7 
8 #include <hilti/ast/statement.h>
9 
10 namespace hilti::statement {
11 
12 namespace comment {
13 enum class Separator { After, BeforeAndAfter, Before };
14 
15 namespace detail {
16 constexpr util::enum_::Value<Separator> Conventions[] = {
17  {.value = Separator::After, .name = "after"},
18  {.value = Separator::BeforeAndAfter, .name = "before-and-after"},
19  {.value = Separator::Before, .name = "before"},
20 };
21 } // namespace detail
22 
23 constexpr auto to_string(Separator cc) { return util::enum_::to_string(cc, detail::Conventions); }
24 
25 } // namespace comment
26 
28 class Comment : public Statement {
29 public:
30  const auto& comment() const { return _comment; }
31  auto separator() const { return _separator; }
32 
33  node::Properties properties() const final {
34  auto p = node::Properties{{"comment", _comment}, {"separator", to_string(_separator)}};
35  return Statement::properties() + std::move(p);
36  }
37 
38  static auto create(ASTContext* ctx, std::string comment, comment::Separator separator = comment::Separator::Before,
39  Meta meta = {}) {
40  return ctx->make<Comment>(ctx, {}, std::move(comment), separator, std::move(meta));
41  }
42 
43 protected:
44  Comment(ASTContext* ctx, Nodes children, std::string comment, comment::Separator separator, Meta meta)
45  : Statement(ctx, NodeTags, std::move(children), std::move(meta)),
46  _comment(std::move(comment)),
47  _separator(separator) {}
48 
49  HILTI_NODE_1(statement::Comment, Statement, final);
50 
51 private:
52  std::string _comment;
53  comment::Separator _separator;
54 };
55 
56 } // namespace hilti::statement
Definition: ast-context.h:121
T * make(Args &&... args)
Definition: ast-context.h:366
Definition: meta.h:30
const auto & children() const
Definition: node.h:364
const auto & meta() const
Definition: node.h:306
virtual node::Properties properties() const
Definition: node.h:891
Definition: statement.h:15
Definition: comment.h:28
node::Properties properties() const final
Definition: comment.h:33