7#ifndef PXR_USD_SDF_VARIABLE_EXPRESSION_AST_H
8#define PXR_USD_SDF_VARIABLE_EXPRESSION_AST_H
11#include "pxr/usd/sdf/api.h"
19PXR_NAMESPACE_OPEN_SCOPE
21namespace SdfVariableExpressionASTNodes
29 SDF_API
virtual ~Node();
30 SDF_API std::unique_ptr<Node> Clone()
const;
57 static_assert(std::is_base_of_v<Node, T>);
58 return dynamic_cast<T*
>(
this);
64 static_assert(std::is_base_of_v<Node, T>);
65 return dynamic_cast<const T*
>(
this);
72 virtual Node* _Clone()
const = 0;
82 NodeList(std::vector<std::unique_ptr<Node>>&& nodes);
88 SDF_API std::vector<const Node*>
GetNodes()
const;
97 SDF_API
void Set(
size_t i,
const Node& node);
119 std::vector<std::unique_ptr<Node>> _nodes;
135 bool, int64_t, std::string
139 void SetValue(
const LiteralValue& value) { _value = value; }
144 friend class _NodeCreator;
146 LiteralNode() =
default;
149 LiteralNode(T&& value)
150 : _value(
std::forward<T>(value))
153 Node* _Clone() const final;
171 const std::string& GetName()
const {
return _name; }
172 void SetName(
const std::string& name) { _name = name; }
176 friend class _NodeCreator;
179 _name(std::move(varName))
182 Node* _Clone()
const final;
198 NodeList& GetElements() {
return _elems; }
199 const NodeList& GetElements()
const {
return _elems; }
203 friend class _NodeCreator;
206 : _elems(std::move(elems))
209 Node* _Clone()
const final;
225 const std::string& GetName()
const {
return _functionName; }
226 void SetName(
const std::string& name) { _functionName = name; }
231 const NodeList& GetArguments()
const {
return _functionArgs; }
232 NodeList& GetArguments() {
return _functionArgs; }
236 friend class _NodeCreator;
239 : _functionName(std::move(functionName))
240 , _functionArgs(std::move(functionArgs))
243 Node* _Clone()
const final;
246 std::string _functionName;
282 SDF_API
explicit operator bool()
const;
286 SDF_API
const std::vector<std::string>&
GetErrors()
const;
311 std::unique_ptr<SdfVariableExpressionASTNodes::Node> _node;
312 std::vector<std::string> _errors;
315PXR_NAMESPACE_CLOSE_SCOPE
Helper class for storing intermediate results when building a variable expression.
Helper class for storing intermediate results when building a function variable expression.
Helper class for storing intermediate results when building a list variable expression.
Abstract syntax tree for an SdfVariableExpression.
SDF_API const SdfVariableExpressionASTNodes::Node * GetRoot() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
SDF_API SdfVariableExpressionASTNodes::Node * GetRoot()
Return the root node of the syntax tree corresponding to the outermost expression if this is a valid ...
SDF_API SdfVariableExpression GetExpression() const
Return the expression represented by this AST if this is a valid AST or a default constructed SdfVari...
SDF_API SdfVariableExpressionAST & operator=(const SdfVariableExpressionAST &rhs)
Assignment. Performs a deep copy of the AST in rhs.
SDF_API const std::vector< std::string > & GetErrors() const
Return list of errors encountered when parsing the expression passed to the constructor.
SDF_API SdfVariableExpressionAST()
Construct an invalid AST.
SDF_API SdfVariableExpressionAST(const std::string &expr)
Construct the AST for the variable expression expr.
SDF_API SdfVariableExpressionAST(const SdfVariableExpression &expr)
This is an overloaded member function, provided for convenience. It differs from the above function o...
SDF_API SdfVariableExpressionAST(const SdfVariableExpressionAST &rhs)
Copy constructor. Performs a deep copy of the AST in rhs.
Abstract syntax tree node representing a function call.
Abstract syntax tree node representing a list.
Abstract syntax tree node representing a literal value.
std::variant< std::monostate, bool, int64_t, std::string > LiteralValue
Variant representing possible literal value types.
Base class for nodes in the SdfVariableExpression abstract syntax tree.
SDF_API SdfVariableExpression GetExpression() const
Return SdfVariableExpression for this node.
SDF_API SdfVariableExpression::Builder GetExpressionBuilder() const
Return SdfVariableExpression::Builder for this node.
Ordered list of abstract syntax tree nodes.
SDF_API void Remove(size_t i)
Remove the node at index i.
SDF_API void Append(const Node &node)
Append a copy of node to the end of this collection.
SDF_API void Clear()
Clear all nodes.
SDF_API std::vector< Node * > GetNodes()
Return list of nodes in this collection.
SDF_API void Set(size_t i, const Node &node)
Set the node at index i to a copy of node.
SDF_API std::vector< const Node * > GetNodes() const
Return list of nodes in this collection.
SDF_API void Insert(size_t i, const Node &node)
Insert a copy of node at index i.
SDF_API NodeList Clone() const
Copy all nodes in this collection to a new collection.
Abstract syntax tree node representing a raw variable reference, i.e.
Class responsible for parsing and evaluating variable expressions.