16 const std::shared_ptr<Identifier> ID;
17 const std::shared_ptr<ExprString> String;
18 const std::shared_ptr<Interpolation> Interp;
24 :
Node(NK_AttrName, Range), Kind(
ANK_ID), ID(std::move(ID)) {
25 assert(this->ID &&
"ID must not be null");
30 String(std::move(String)) {
31 assert(this->String &&
"String must not be null");
34 AttrName(std::shared_ptr<Interpolation> Interp)
36 Interp(std::move(Interp)) {
37 assert(this->Interp &&
"Interpolation must not be null");
51 assert(
isStatic() &&
"must be static");
60 assert(Interp &&
"Interpolation must not be null");
64 [[nodiscard]]
const std::shared_ptr<Identifier> &
id()
const {
71 assert(String &&
"String must not be null");
80 return {String.get()};
82 return {Interp.get()};
84 assert(
false &&
"invalid AttrNameKind");
86 __builtin_unreachable();
91 const std::vector<std::shared_ptr<AttrName>> Names;
92 const std::vector<std::shared_ptr<Dot>> Dots;
96 std::vector<std::shared_ptr<Dot>> Dots)
97 :
Node(NK_AttrPath, Range), Names(std::move(Names)),
98 Dots(std::move(Dots)) {}
100 [[nodiscard]]
const std::vector<std::shared_ptr<AttrName>> &
names()
const {
106 Children.reserve(Names.size() + Dots.size());
107 for (
const auto &Name : Names)
108 Children.push_back(Name.get());
109 for (
const auto &
Dot : Dots)
110 Children.emplace_back(
Dot.get());
116 const std::shared_ptr<AttrPath> Path;
117 const std::shared_ptr<Expr> Value;
121 std::shared_ptr<Expr> Value)
122 :
Node(NK_Binding, Range), Path(std::move(Path)),
123 Value(std::move(Value)) {
124 assert(this->Path &&
"Path must not be null");
129 assert(Path &&
"Path must not be null");
133 [[nodiscard]]
const std::shared_ptr<Expr> &
value()
const {
return Value; }
136 return {Path.get(), Value.get()};
141 const std::vector<std::shared_ptr<AttrName>> Names;
142 const std::shared_ptr<Expr> E;
146 std::shared_ptr<Expr> E)
147 :
Node(NK_Inherit, Range), Names(std::move(Names)), E(std::move(E)) {}
149 [[nodiscard]]
const std::vector<std::shared_ptr<AttrName>> &
names()
const {
153 [[nodiscard]]
bool hasExpr() {
return E !=
nullptr; }
155 [[nodiscard]]
const std::shared_ptr<Expr> &
expr()
const {
return E; }
159 Children.reserve(Names.size() + 1);
160 for (
const auto &Name : Names) {
161 Children.push_back(Name.get());
163 Children.push_back(E.get());
169 const std::vector<std::shared_ptr<Node>> Bindings;
173 :
Node(NK_Binds, Range), Bindings(std::move(Bindings)) {}
175 [[nodiscard]]
const std::vector<std::shared_ptr<Node>> &
bindings()
const {
181 Children.reserve(Bindings.size());
182 for (
const auto &
Binding : Bindings) {
183 Children.push_back(
Binding.get());
201 const std::shared_ptr<Node> Key;
202 const std::shared_ptr<Expr> Value;
206 Attribute(std::shared_ptr<Node> Key, std::shared_ptr<Expr> Value,
208 : Key(std::move(Key)), Value(std::move(Value)), Kind(Kind) {
209 assert(this->Key &&
"Key must not be null");
212 [[nodiscard]]
Node &
key()
const {
return *Key; }
214 [[nodiscard]]
Expr *
value()
const {
return Value.get(); }
235 std::map<std::string, Attribute> Static;
236 std::vector<Attribute> Dynamic;
238 const Misc *Recursive;
245 std::vector<Attribute> Dynamic,
Misc *Recursive)
246 : Static(std::move(Static)), Dynamic(std::move(Dynamic)),
247 Recursive(Recursive) {}
252 [[nodiscard]]
const std::map<std::string, Attribute> &
staticAttrs()
const {
268 const std::shared_ptr<Binds> Body;
269 const std::shared_ptr<Misc> Rec;
276 :
Expr(NK_ExprAttrs, Range), Body(std::move(Body)), Rec(std::move(Rec)),
279 [[nodiscard]]
const Binds *
binds()
const {
return Body.get(); }
280 [[nodiscard]]
const Misc *
rec()
const {
return Rec.get(); }
287 return {Body.get(), Rec.get()};
const std::string & staticName() const
AttrName(std::shared_ptr< Interpolation > Interp)
const std::shared_ptr< Identifier > & id() const
AttrName(std::shared_ptr< ExprString > String)
AttrNameKind kind() const
const ExprString & string() const
const Interpolation & interpolation() const
ChildVector children() const override
AttrName(std::shared_ptr< Identifier > ID, LexerCursorRange Range)
AttrPath(LexerCursorRange Range, std::vector< std::shared_ptr< AttrName > > Names, std::vector< std::shared_ptr< Dot > > Dots)
ChildVector children() const override
const std::vector< std::shared_ptr< AttrName > > & names() const
AttributeKind kind() const
@ InheritFrom
inherit (expr) a b c
Attribute(std::shared_ptr< Node > Key, std::shared_ptr< Expr > Value, AttributeKind Kind)
const AttrPath & path() const
Binding(LexerCursorRange Range, std::shared_ptr< AttrPath > Path, std::shared_ptr< Expr > Value)
ChildVector children() const override
const std::shared_ptr< Expr > & value() const
ChildVector children() const override
Binds(LexerCursorRange Range, std::vector< std::shared_ptr< Node > > Bindings)
const std::vector< std::shared_ptr< Node > > & bindings() const
Holds a "." in the language.
ChildVector children() const override
const SemaAttrs & sema() const
ExprAttrs(LexerCursorRange Range, std::shared_ptr< Binds > Body, std::shared_ptr< Misc > Rec, SemaAttrs SA)
const Binds * binds() const
const std::string & literal() const
const std::shared_ptr< Expr > & expr() const
const std::vector< std::shared_ptr< AttrName > > & names() const
ChildVector children() const override
Inherit(LexerCursorRange Range, std::vector< std::shared_ptr< AttrName > > Names, std::shared_ptr< Expr > E)
Misc node, used for parentheses, keywords, etc.
boost::container::small_vector< Node *, 8 > ChildVector
LexerCursorRange range() const
Attribute set after deduplication.
SemaAttrs(std::map< std::string, Attribute > Static, std::vector< Attribute > Dynamic, Misc *Recursive)
SemaAttrs(Misc *Recursive)
bool isRecursive() const
If the attribute set is rec.
const std::vector< Attribute > & dynamicAttrs() const
Dynamic attributes, require evaluation to get the key.
const std::map< std::string, Attribute > & staticAttrs() const
Static attributes, do not require evaluation to get the key.