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;
120 const std::shared_ptr<Misc> Eq;
124 std::shared_ptr<Expr> Value, std::shared_ptr<Misc> Eq)
125 :
Node(NK_Binding, Range), Path(std::move(Path)), Value(std::move(Value)),
127 assert(this->Path &&
"Path must not be null");
132 assert(Path &&
"Path must not be null");
136 [[nodiscard]]
const std::shared_ptr<Expr> &
value()
const {
return Value; }
138 [[nodiscard]]
const std::shared_ptr<Misc> &
eq()
const {
return Eq; }
141 return {Path.get(), Eq.get(), Value.get()};
146 const std::vector<std::shared_ptr<AttrName>> Names;
147 const std::shared_ptr<Expr> E;
151 std::shared_ptr<Expr> E)
152 :
Node(NK_Inherit, Range), Names(std::move(Names)), E(std::move(E)) {}
154 [[nodiscard]]
const std::vector<std::shared_ptr<AttrName>> &
names()
const {
158 [[nodiscard]]
bool hasExpr() {
return E !=
nullptr; }
160 [[nodiscard]]
const std::shared_ptr<Expr> &
expr()
const {
return E; }
164 Children.reserve(Names.size() + 1);
165 for (
const auto &Name : Names) {
166 Children.push_back(Name.get());
168 Children.push_back(E.get());
174 const std::vector<std::shared_ptr<Node>> Bindings;
178 :
Node(NK_Binds, Range), Bindings(std::move(Bindings)) {}
180 [[nodiscard]]
const std::vector<std::shared_ptr<Node>> &
bindings()
const {
186 Children.reserve(Bindings.size());
187 for (
const auto &
Binding : Bindings) {
188 Children.push_back(
Binding.get());
206 const std::shared_ptr<Node> Key;
207 const std::shared_ptr<Expr> Value;
211 Attribute(std::shared_ptr<Node> Key, std::shared_ptr<Expr> Value,
213 : Key(std::move(Key)), Value(std::move(Value)), Kind(Kind) {
214 assert(this->Key &&
"Key must not be null");
217 [[nodiscard]]
Node &
key()
const {
return *Key; }
219 [[nodiscard]]
Expr *
value()
const {
return Value.get(); }
240 std::map<std::string, Attribute> Static;
241 std::vector<Attribute> Dynamic;
243 const Misc *Recursive;
250 std::vector<Attribute> Dynamic,
Misc *Recursive)
251 : Static(std::move(Static)), Dynamic(std::move(Dynamic)),
252 Recursive(Recursive) {}
257 [[nodiscard]]
const std::map<std::string, Attribute> &
staticAttrs()
const {
273 const std::shared_ptr<Binds> Body;
274 const std::shared_ptr<Misc> Rec;
281 :
Expr(NK_ExprAttrs, Range), Body(std::move(Body)), Rec(std::move(Rec)),
284 [[nodiscard]]
const Binds *
binds()
const {
return Body.get(); }
285 [[nodiscard]]
const Misc *
rec()
const {
return Rec.get(); }
292 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)
Binding(LexerCursorRange Range, std::shared_ptr< AttrPath > Path, std::shared_ptr< Expr > Value, std::shared_ptr< Misc > Eq)
const AttrPath & path() const
ChildVector children() const override
const std::shared_ptr< Misc > & eq() const
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
Expr(NodeKind Kind, LexerCursorRange Range)
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
Node(NodeKind Kind, LexerCursorRange Range)
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.