Spicy
expression.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <string>
6 #include <utility>
7 
8 #include <hilti/ast/attribute.h>
9 #include <hilti/ast/declaration.h>
10 #include <hilti/ast/expression.h>
11 #include <hilti/ast/id.h>
12 
13 namespace hilti {
14 namespace declaration {
15 
18 public:
19  Expression(ID id, hilti::Expression e, Linkage linkage = Linkage::Private, Meta m = Meta())
20  : NodeBase(nodes(std::move(id), std::move(e), node::none), std::move(m)), _linkage(linkage) {}
21  Expression(ID id, hilti::Expression e, std::optional<AttributeSet> attrs, Linkage linkage = Linkage::Private,
22  Meta m = Meta())
23  : NodeBase(nodes(std::move(id), std::move(e), std::move(attrs)), std::move(m)), _linkage(linkage) {}
24 
25  const auto& expression() const { return child<hilti::Expression>(1); }
26  auto attributes() const { return childs()[2].tryReferenceAs<AttributeSet>(); }
27 
28  bool operator==(const Expression& other) const { return id() == other.id() && expression() == other.expression(); }
29 
31  bool isConstant() const { return true; }
33  const ID& id() const { return child<ID>(0); }
35  Linkage linkage() const { return _linkage; }
37  std::string displayName() const { return "expression"; };
39  auto isEqual(const Declaration& other) const { return node::isEqual(this, other); }
40 
42  auto properties() const { return node::Properties{{"linkage", to_string(_linkage)}}; }
43 
44 private:
45  Linkage _linkage;
46 };
47 
48 } // namespace declaration
49 } // namespace hilti
auto & childs() const
Definition: node.h:445
const Node none
Definition: node.cc:12
Linkage linkage() const
Definition: expression.h:35
bool isConstant() const
Definition: expression.h:31
std::string displayName() const
Definition: expression.h:37
Definition: meta.h:18
Definition: attribute.h:159
Definition: expression.h:17
auto properties() const
Definition: expression.h:42
auto isEqual(const Declaration &other) const
Definition: expression.h:39
std::map< std::string, node::detail::PropertyValue > Properties
Definition: node.h:83
const ID & id() const
Definition: expression.h:33
Definition: declaration.h:15
Definition: id.h:18
Definition: node.h:318