OpenVDB  8.1.1
AST.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 
26 
27 #ifndef OPENVDB_AX_AST_HAS_BEEN_INCLUDED
28 #define OPENVDB_AX_AST_HAS_BEEN_INCLUDED
29 
30 #include "Tokens.h"
31 
32 #include <openvdb/version.h>
33 
34 #include <memory>
35 #include <utility>
36 #include <vector>
37 
38 namespace openvdb {
40 namespace OPENVDB_VERSION_NAME {
41 
42 namespace ax {
43 namespace ast {
44 
50 struct Tree;
51 
54 
87 
90 
101 struct Node
102 {
103  using Ptr = std::shared_ptr<Node>;
104  using UniquePtr = std::unique_ptr<Node>;
105 
117  enum NodeType {
144  ValueStrNode
145  };
146 
147  Node() = default;
148  virtual ~Node() = default;
149 
152  virtual Node* copy() const = 0;
153 
156 
160  virtual NodeType nodetype() const = 0;
161 
164  virtual const char* nodename() const = 0;
165 
168  virtual const char* subname() const = 0;
169 
175  virtual const Node* basetype() const { return nullptr; }
176 
183  template <typename NodeT>
184  inline bool isType() const {
185  return dynamic_cast<const NodeT*>(this);
186  }
187 
189 
192 
196  virtual size_t children() const = 0;
197 
205  virtual const Node* child(const size_t index) const = 0;
206 
211  inline int64_t childidx() const
212  {
213  const Node* p = this->parent();
214  if (!p) return -1;
215  size_t i = 0;
216  const size_t count = p->children();
217  for (; i < count; ++i) {
218  if (p->child(i) == this) break;
219  }
220  if (i == count) return -1;
221  return static_cast<int64_t>(i);
222  }
223 
225 
228 
247  inline bool replace(Node* node)
248  {
249  const int64_t idx = this->childidx();
250  if (idx == -1) return false; // avoid second vcall
251  return this->parent()->replacechild(idx, node);
252  }
253 
260  inline virtual bool replacechild(const size_t index, Node* node);
261 
263 
266 
271  inline const Node* parent() const { return mParent; }
272 
276  inline void setParent(Node* parent) {
277 #ifndef NDEBUG
278  bool hasChild = false;
279  for (size_t i = 0; i < parent->children(); ++i)
280  hasChild |= parent->child(i) == this;
281  assert(hasChild);
282 #endif
283  mParent = parent;
284  }
285 
286 private:
292  inline Node* parent() { return mParent; }
293 
295 
296  Node* mParent = nullptr;
297 };
298 
299 inline bool Node::replacechild(const size_t, Node*) { return false; }
300 
301 
304 
306 
311 struct Statement : public Node
312 {
313  using UniquePtr = std::unique_ptr<Statement>;
314  ~Statement() override = default;
315  virtual Statement* copy() const override = 0;
316  const Node* basetype() const override { return this; }
317 };
318 
325 struct Expression : public Statement
326 {
327  using UniquePtr = std::unique_ptr<Expression>;
328  ~Expression() override = default;
329  virtual Expression* copy() const override = 0;
330  const Statement* basetype() const override { return this; }
331 };
332 
336 struct Variable : public Expression
337 {
338  using UniquePtr = std::unique_ptr<Variable>;
339 
340  Variable(const std::string& name)
341  : Expression(), mName(name) {}
342  Variable(const Variable& other)
343  : Expression(), mName(other.mName) {}
344  ~Variable() override = default;
345 
346  virtual Variable* copy() const override = 0;
347  const Expression* basetype() const override { return this; }
348  //
349  size_t children() const override { return 0; }
350  const Node* child(const size_t) const override { return nullptr; }
351  //
352  inline const std::string& name() const { return mName; }
353 
354 private:
355  const std::string mName;
356 };
357 
360 struct ValueBase : public Expression
361 {
362  using UniquePtr = std::unique_ptr<ValueBase>;
363  ~ValueBase() override = default;
364  virtual Expression* copy() const override = 0;
365  const Expression* basetype() const override { return this; }
366  //
367  size_t children() const override { return 0; }
368  const Node* child(const size_t) const override { return nullptr; }
369 };
370 
371 
374 
376 
385 struct StatementList : public Statement
386 {
387  using UniquePtr = std::unique_ptr<StatementList>;
388 
390  StatementList() : mList() {}
397  : mList() {
398  this->addStatement(statement);
399  }
405  StatementList(const std::vector<Statement*>& statements)
406  : mList() {
407  for (Statement* statement : statements) {
408  this->addStatement(statement);
409  }
410  }
415  StatementList(const StatementList& other) : mList() {
416  for (const Statement::UniquePtr& stmnt : other.mList) {
417  this->addStatement(stmnt->copy());
418  }
419  }
420  ~StatementList() override = default;
421 
423  StatementList* copy() const override { return new StatementList(*this); }
425  NodeType nodetype() const override { return Node::StatementListNode; }
427  const char* nodename() const override { return "statement list"; }
429  const char* subname() const override { return "stml"; }
431  const Statement* basetype() const override { return this; }
432 
434  size_t children() const override final { return this->size(); }
436  const Statement* child(const size_t i) const override final {
437  if (i >= mList.size()) return nullptr;
438  return mList[i].get();
439  }
441  inline bool replacechild(const size_t i, Node* node) override final {
442  if (mList.size() <= i) return false;
443  Expression* expr = dynamic_cast<Expression*>(node);
444  if (!expr) return false;
445  mList[i].reset(expr);
446  mList[i]->setParent(this);
447  return true;
448  }
449 
451  inline size_t size() const { return mList.size(); }
455  inline void addStatement(Statement* stmnt) {
456  if (stmnt) {
457  mList.emplace_back(stmnt);
458  stmnt->setParent(this);
459  }
460  }
461 private:
462  std::vector<Statement::UniquePtr> mList;
463 };
464 
475 struct Block : public Statement
476 {
477  using UniquePtr = std::unique_ptr<Block>;
478 
480  Block() : mList() {}
486  Block(Statement* statement)
487  : mList() {
488  this->addStatement(statement);
489  }
495  Block(const std::vector<Statement*>& statements)
496  : mList() {
497  for (Statement* statement : statements) {
498  this->addStatement(statement);
499  }
500  }
504  Block(const Block& other) : mList() {
505  for (const Statement::UniquePtr& stmnt : other.mList) {
506  this->addStatement(stmnt->copy());
507  }
508  }
509  ~Block() override = default;
510 
512  Block* copy() const override final { return new Block(*this); }
514  NodeType nodetype() const override { return Node::BlockNode; }
516  const char* nodename() const override { return "scoped block"; }
518  const char* subname() const override { return "blk"; }
520  const Statement* basetype() const override { return this; }
521 
523  size_t children() const override final { return this->size(); }
525  const Statement* child(const size_t i) const override final {
526  if (i >= mList.size()) return nullptr;
527  return mList[i].get();
528  }
530  inline bool replacechild(const size_t i, Node* node) override final {
531  if (mList.size() <= i) return false;
532  Expression* expr = dynamic_cast<Expression*>(node);
533  if (!expr) return false;
534  mList[i].reset(expr);
535  mList[i]->setParent(this);
536  return true;
537  }
538 
540  inline size_t size() const { return mList.size(); }
544  inline void addStatement(Statement* stmnt) {
545  if (stmnt) {
546  mList.emplace_back(stmnt);
547  stmnt->setParent(this);
548  }
549  }
550 private:
551  std::vector<Statement::UniquePtr> mList;
552 };
553 
561 struct Tree : public Node
562 {
563  using Ptr = std::shared_ptr<Tree>;
564  using ConstPtr = std::shared_ptr<const Tree>;
565  using UniquePtr = std::unique_ptr<Tree>;
566 
571  Tree(Block* block = new Block())
572  : mBlock(block) {
573  mBlock->setParent(this);
574  }
578  Tree(const Tree& other)
579  : mBlock(new Block(*other.mBlock)) {
580  mBlock->setParent(this);
581  }
582  ~Tree() override = default;
583 
585  Tree* copy() const override final { return new Tree(*this); }
587  NodeType nodetype() const override { return Node::TreeNode; }
589  const char* nodename() const override { return "tree"; }
591  const char* subname() const override { return "tree"; }
593  const Node* basetype() const override { return this; }
594 
596  size_t children() const override final { return 1; }
598  const Block* child(const size_t i) const override final {
599  if (i == 0) return mBlock.get();
600  return nullptr;
601  }
602 private:
603  Block::UniquePtr mBlock;
604 };
605 
606 struct CommaOperator : public Expression
607 {
608  using UniquePtr = std::unique_ptr<CommaOperator>;
609 
611  CommaOperator() : mExpressions() {}
618  : mExpressions() {
619  this->append(expression);
620  }
626  CommaOperator(const std::vector<Expression*>& expressions)
627  : mExpressions() {
628  mExpressions.reserve(expressions.size());
629  for (Expression* expression : expressions) {
630  this->append(expression);
631  }
632  }
638  : mExpressions() {
639  mExpressions.reserve(other.mExpressions.size());
640  for (const Expression::UniquePtr& expr : other.mExpressions) {
641  this->append(expr->copy());
642  }
643  }
644  ~CommaOperator() override = default;
645 
647  CommaOperator* copy() const override final {
648  return new CommaOperator(*this);
649  }
651  NodeType nodetype() const override { return Node::CommaOperatorNode; }
653  const char* nodename() const override { return "comma"; }
655  const char* subname() const override { return "comma"; }
657  const Expression* basetype() const override { return this; }
658 
660  size_t children() const override final { return this->size(); }
662  const Expression* child(const size_t i) const override final {
663  if (i >= mExpressions.size()) return nullptr;
664  return mExpressions[i].get();
665  }
667  inline bool replacechild(const size_t i, Node* node) override final {
668  if (mExpressions.size() <= i) return false;
669  Expression* expr = dynamic_cast<Expression*>(node);
670  mExpressions[i].reset(expr);
671  mExpressions[i]->setParent(this);
672  return true;
673  }
674 
676  inline size_t size() const { return mExpressions.size(); }
679  inline bool empty() const { return mExpressions.empty(); }
683  inline void append(Expression* expr) {
684  if (expr) {
685  mExpressions.emplace_back(expr);
686  expr->setParent(this);
687  }
688  }
689 private:
690  std::vector<Expression::UniquePtr> mExpressions;
691 };
692 
707 struct Loop : public Statement
708 {
709  using UniquePtr = std::unique_ptr<Loop>;
710 
722  Loop(const tokens::LoopToken loopType,
723  Statement* condition,
724  Block* body,
725  Statement* init = nullptr,
726  Expression* iter = nullptr)
727  : mLoopType(loopType)
728  , mConditional(condition)
729  , mBody(body)
730  , mInitial(init)
731  , mIteration(iter) {
732  assert(mConditional);
733  assert(mBody);
734  mConditional->setParent(this);
735  mBody->setParent(this);
736  if (mInitial) {
737  assert(mLoopType == tokens::LoopToken::FOR);
738  mInitial->setParent(this);
739  }
740  if (mIteration) {
741  assert(mLoopType == tokens::LoopToken::FOR);
742  mIteration->setParent(this);
743  }
744  }
749  Loop(const Loop& other)
750  : mLoopType(other.mLoopType)
751  , mConditional(other.mConditional->copy())
752  , mBody(other.mBody->copy())
753  , mInitial(other.hasInit() ? other.mInitial->copy() : nullptr)
754  , mIteration(other.hasIter() ? other.mIteration->copy() : nullptr) {
755  mConditional->setParent(this);
756  mBody->setParent(this);
757  if (mInitial) {
758  assert(mLoopType == tokens::LoopToken::FOR);
759  mInitial->setParent(this);
760  }
761  if (mIteration) {
762  assert(mLoopType == tokens::LoopToken::FOR);
763  mIteration->setParent(this);
764  }
765  }
766  ~Loop() override = default;
767 
769  Loop* copy() const override final { return new Loop(*this); }
771  NodeType nodetype() const override { return Node::LoopNode; }
773  const char* nodename() const override { return "loop"; }
775  const char* subname() const override { return "loop"; }
777  const Statement* basetype() const override { return this; }
778 
780  size_t children() const override final { return 4; }
782  const Statement* child(const size_t i) const override final {
783  if (i == 0) return mConditional.get();
784  if (i == 1) return mBody.get();
785  if (i == 2) return mInitial.get();
786  if (i == 3) return mIteration.get();
787  return nullptr;
788  }
790  inline bool replacechild(const size_t i, Node* node) override final
791  {
792  if (i == 0 || i == 2) {
793  Statement* stmt = dynamic_cast<Statement*>(node);
794  if (!stmt) return false;
795  if (i == 0) {
796  mConditional.reset(stmt);
797  mConditional->setParent(this);
798  }
799  else {
800  mInitial.reset(stmt);
801  mInitial->setParent(this);
802  }
803  return true;
804  }
805  else if (i == 1) {
806  Block* blk = dynamic_cast<Block*>(node);
807  if (!blk) return false;
808  mBody.reset(blk);
809  mBody->setParent(this);
810  return true;
811  }
812  else if (i == 3) {
813  Expression* expr = dynamic_cast<Expression*>(node);
814  if (!expr) return false;
815  mIteration.reset(expr);
816  mIteration->setParent(expr);
817  return true;
818  }
819  return false;
820  }
821 
824  inline tokens::LoopToken loopType() const { return mLoopType; }
827  inline bool hasInit() const { return static_cast<bool>(this->initial()); }
830  inline bool hasIter() const { return static_cast<bool>(this->iteration()); }
834  const Statement* condition() const { return mConditional.get(); }
837  const Block* body() const { return mBody.get(); }
841  const Statement* initial() const { return mInitial.get(); }
844  const Expression* iteration() const { return mIteration.get(); }
845 
846 private:
847  const tokens::LoopToken mLoopType;
848  Statement::UniquePtr mConditional;
849  Block::UniquePtr mBody;
850  Statement::UniquePtr mInitial;
851  Expression::UniquePtr mIteration;
852 };
853 
864 {
865  using UniquePtr = std::unique_ptr<ConditionalStatement>;
866 
878  Block* trueBlock,
879  Block* falseBlock = nullptr)
880  : mConditional(conditional)
881  , mTrueBranch(trueBlock)
882  , mFalseBranch(falseBlock) {
883  assert(mConditional);
884  assert(mTrueBranch);
885  mConditional->setParent(this);
886  mTrueBranch->setParent(this);
887  if (mFalseBranch) mFalseBranch->setParent(this);
888  }
895  : mConditional(other.mConditional->copy())
896  , mTrueBranch(other.mTrueBranch->copy())
897  , mFalseBranch(other.hasFalse() ? other.mFalseBranch->copy() : nullptr) {
898  mConditional->setParent(this);
899  mTrueBranch->setParent(this);
900  if (mFalseBranch) mFalseBranch->setParent(this);
901  }
902  ~ConditionalStatement() override = default;
903 
905  ConditionalStatement* copy() const override final {
906  return new ConditionalStatement(*this);
907  }
909  NodeType nodetype() const override { return Node::ConditionalStatementNode; }
911  const char* nodename() const override { return "conditional statement"; }
913  const char* subname() const override { return "cond"; }
915  const Statement* basetype() const override { return this; }
916 
918  size_t children() const override final { return 3; }
920  const Statement* child(const size_t i) const override final {
921  if (i == 0) return this->condition();
922  if (i == 1) return this->trueBranch();
923  if (i == 2) return this->falseBranch();
924  return nullptr;
925  }
927  inline bool replacechild(const size_t i, Node* node) override final
928  {
929  if (i == 0) {
930  Expression* expr = dynamic_cast<Expression*>(node);
931  if (!expr) return false;
932  mConditional.reset(expr);
933  mConditional->setParent(this);
934  return true;
935  }
936  else if (i == 1 || i == 2) {
937  Block* blk = dynamic_cast<Block*>(node);
938  if (!blk) return false;
939  if (i == 1) {
940  mTrueBranch.reset(blk);
941  mTrueBranch->setParent(this);
942  }
943  else {
944  mFalseBranch.reset(blk);
945  mFalseBranch->setParent(this);
946  }
947  return true;
948  }
949  return false;
950  }
951 
954  inline bool hasFalse() const {
955  return static_cast<bool>(this->falseBranch());
956  }
960  size_t branchCount() const {
961  return this->hasFalse() ? 2 : 1;
962  }
966  const Expression* condition() const { return mConditional.get(); }
970  const Block* trueBranch() const { return mTrueBranch.get(); }
974  const Block* falseBranch() const { return mFalseBranch.get(); }
975 private:
976  Expression::UniquePtr mConditional;
977  Block::UniquePtr mTrueBranch;
978  Block::UniquePtr mFalseBranch;
979 };
980 
987 struct BinaryOperator : public Expression
988 {
989  using UniquePtr = std::unique_ptr<BinaryOperator>;
990 
1000  Expression* right,
1001  const tokens::OperatorToken op)
1002  : mLeft(left)
1003  , mRight(right)
1004  , mOperation(op) {
1005  assert(mLeft);
1006  assert(mRight);
1007  mLeft->setParent(this);
1008  mRight->setParent(this);
1009  }
1016  Expression* right,
1017  const std::string& op)
1018  : BinaryOperator(left, right, tokens::operatorTokenFromName(op)) {}
1024  : mLeft(other.mLeft->copy())
1025  , mRight(other.mRight->copy())
1026  , mOperation(other.mOperation) {
1027  mLeft->setParent(this);
1028  mRight->setParent(this);
1029  }
1030  ~BinaryOperator() override = default;
1031 
1033  BinaryOperator* copy() const override final {
1034  return new BinaryOperator(*this);
1035  }
1037  NodeType nodetype() const override { return Node::BinaryOperatorNode; }
1039  const char* nodename() const override { return "binary"; }
1041  const char* subname() const override { return "bin"; }
1043  const Expression* basetype() const override { return this; }
1045  size_t children() const override final { return 2; }
1047  const Expression* child(const size_t i) const override final {
1048  if (i == 0) return mLeft.get();
1049  if (i == 1) return mRight.get();
1050  return nullptr;
1051  }
1053  inline bool replacechild(const size_t i, Node* node) override final {
1054  if (i > 1) return false;
1055  Expression* expr = dynamic_cast<Expression*>(node);
1056  if (!expr) return false;
1057  if (i == 0) {
1058  mLeft.reset(expr);
1059  mLeft->setParent(this);
1060  }
1061  else if (i == 1) {
1062  mRight.reset(expr);
1063  mRight->setParent(this);
1064  }
1065  return true;
1066  }
1067 
1070  inline tokens::OperatorToken operation() const { return mOperation; }
1074  const Expression* lhs() const { return mLeft.get(); }
1078  const Expression* rhs() const { return mRight.get(); }
1079 private:
1080  Expression::UniquePtr mLeft;
1081  Expression::UniquePtr mRight;
1082  const tokens::OperatorToken mOperation;
1083 };
1084 
1092 {
1093  using UniquePtr = std::unique_ptr<TernaryOperator>;
1094 
1105  Expression* trueExpression,
1106  Expression* falseExpression)
1107  : mConditional(conditional)
1108  , mTrueBranch(trueExpression)
1109  , mFalseBranch(falseExpression) {
1110  assert(mConditional);
1111  assert(mFalseBranch);
1112  mConditional->setParent(this);
1113  if (mTrueBranch) mTrueBranch->setParent(this);
1114  mFalseBranch->setParent(this);
1115  }
1121  : mConditional(other.mConditional->copy())
1122  , mTrueBranch(other.hasTrue() ? other.mTrueBranch->copy() : nullptr)
1123  , mFalseBranch(other.mFalseBranch->copy()) {
1124  mConditional->setParent(this);
1125  if (mTrueBranch) mTrueBranch->setParent(this);
1126  mFalseBranch->setParent(this);
1127  }
1128  ~TernaryOperator() override = default;
1129 
1131  TernaryOperator* copy() const override final {
1132  return new TernaryOperator(*this);
1133  }
1135  NodeType nodetype() const override { return Node::TernaryOperatorNode; }
1137  const char* nodename() const override { return "ternary"; }
1139  const char* subname() const override { return "tern"; }
1141  const Expression* basetype() const override { return this; }
1143  size_t children() const override final { return 3; }
1145  const Expression* child(const size_t i) const override final {
1146  if (i == 0) return mConditional.get();
1147  if (i == 1) return mTrueBranch.get();
1148  if (i == 2) return mFalseBranch.get();
1149  return nullptr;
1150  }
1152  inline bool replacechild(const size_t i, Node* node) override final {
1153  if (i > 2) return false;
1154  Expression* expr = dynamic_cast<Expression*>(node);
1155  if (!expr) return false;
1156  if (i == 0) {
1157  mConditional.reset(expr);
1158  mConditional->setParent(this);
1159  }
1160  else if (i == 1) {
1161  mTrueBranch.reset(expr);
1162  mTrueBranch->setParent(this);
1163  }
1164  else if (i == 2) {
1165  mFalseBranch.reset(expr);
1166  mFalseBranch->setParent(this);
1167  }
1168  return true;
1169  }
1170 
1172  bool hasTrue() const { return static_cast<bool>(this->trueBranch()); }
1176  const Expression* condition() const { return mConditional.get(); }
1180  const Expression* trueBranch() const { return mTrueBranch.get(); }
1184  const Expression* falseBranch() const { return mFalseBranch.get(); }
1185 private:
1186  Expression::UniquePtr mConditional;
1187  Expression::UniquePtr mTrueBranch;
1188  Expression::UniquePtr mFalseBranch;
1189 };
1190 
1198 {
1199  using UniquePtr = std::unique_ptr<AssignExpression>;
1200 
1209  : mLHS(lhs)
1210  , mRHS(rhs)
1211  , mOperation(op) {
1212  assert(mLHS);
1213  assert(mRHS);
1214  mLHS->setParent(this);
1215  mRHS->setParent(this);
1216  }
1223  : mLHS(other.mLHS->copy())
1224  , mRHS(other.mRHS->copy())
1225  , mOperation(other.mOperation) {
1226  mLHS->setParent(this);
1227  mRHS->setParent(this);
1228  }
1229  ~AssignExpression() override = default;
1230 
1232  AssignExpression* copy() const override final {
1233  return new AssignExpression(*this);
1234  }
1236  NodeType nodetype() const override { return Node::AssignExpressionNode; }
1238  const char* nodename() const override { return "assignment expression"; }
1240  const char* subname() const override { return "asgn"; }
1242  const Expression* basetype() const override { return this; }
1244  size_t children() const override final { return 2; }
1246  const Expression* child(const size_t i) const override final {
1247  if (i == 0) return this->lhs();
1248  if (i == 1) return this->rhs();
1249  return nullptr;
1250  }
1252  inline bool replacechild(const size_t i, Node* node) override final {
1253  if (i > 1) return false;
1254  Expression* expr = dynamic_cast<Expression*>(node);
1255  if (!expr) return false;
1256  if (i == 0) {
1257  mLHS.reset(expr);
1258  mLHS->setParent(this);
1259  }
1260  else if (i == 1) {
1261  mRHS.reset(expr);
1262  mRHS->setParent(this);
1263  }
1264  return true;
1265  }
1266 
1271  inline bool isCompound() const { return mOperation != tokens::EQUALS; }
1275  inline tokens::OperatorToken operation() const { return mOperation; }
1279  const Expression* lhs() const { return mLHS.get(); }
1283  const Expression* rhs() const { return mRHS.get(); }
1284 private:
1285  Expression::UniquePtr mLHS;
1286  Expression::UniquePtr mRHS;
1287  const tokens::OperatorToken mOperation;
1288 };
1289 
1293 struct Crement : public Expression
1294 {
1295  using UniquePtr = std::unique_ptr<Crement>;
1296 
1298  enum Operation {
1300  Decrement
1301  };
1302 
1310  Crement(Expression* expr, const Operation op, bool post)
1311  : mExpression(expr)
1312  , mOperation(op)
1313  , mPost(post) {
1314  mExpression->setParent(this);
1315  }
1320  Crement(const Crement& other)
1321  : mExpression(other.mExpression->copy())
1322  , mOperation(other.mOperation)
1323  , mPost(other.mPost) {
1324  mExpression->setParent(this);
1325  }
1326  ~Crement() override = default;
1327 
1329  Crement* copy() const override final { return new Crement(*this); }
1331  NodeType nodetype() const override { return Node::CrementNode; }
1333  const char* nodename() const override { return "crement"; }
1335  const char* subname() const override { return "crmt"; }
1337  const Expression* basetype() const override { return this; }
1338  //
1340  size_t children() const override final { return 1; }
1342  const Expression* child(const size_t i) const override final {
1343  if (i == 0) return this->expression();
1344  return nullptr;
1345  }
1347  inline bool replacechild(const size_t i, Node* node) override final {
1348  if (i != 0) return false;
1349  Expression* expr = dynamic_cast<Expression*>(node);
1350  if (!expr) return false;
1351  mExpression.reset(expr);
1352  mExpression->setParent(this);
1353  return true;
1354  }
1355 
1360  inline Operation operation() const { return mOperation; }
1363  inline bool increment() const { return mOperation == Increment; }
1366  inline bool decrement() const { return mOperation == Decrement; }
1369  inline bool pre() const { return !mPost; }
1372  inline bool post() const { return mPost; }
1376  const Expression* expression() const { return mExpression.get(); }
1377 private:
1378  Expression::UniquePtr mExpression;
1379  const Operation mOperation;
1380  const bool mPost;
1381 };
1382 
1388 struct UnaryOperator : public Expression
1389 {
1390  using UniquePtr = std::unique_ptr<UnaryOperator>;
1391 
1398  : mExpression(expr)
1399  , mOperation(op) {
1400  assert(mExpression);
1401  mExpression->setParent(this);
1402  }
1407  UnaryOperator(Expression* expr, const std::string& op)
1408  : UnaryOperator(expr, tokens::operatorTokenFromName(op)) {}
1414  : mExpression(other.mExpression->copy())
1415  , mOperation(other.mOperation) {
1416  mExpression->setParent(this);
1417  }
1418  ~UnaryOperator() override = default;
1419 
1421  UnaryOperator* copy() const override final { return new UnaryOperator(*this); }
1423  NodeType nodetype() const override { return Node::UnaryOperatorNode; }
1425  const char* nodename() const override { return "unary"; }
1427  const char* subname() const override { return "unry"; }
1429  const Expression* basetype() const override { return this; }
1431  size_t children() const override final { return 1; }
1433  const Expression* child(const size_t i) const override final {
1434  if (i == 0) return this->expression();
1435  return nullptr;
1436  }
1438  inline bool replacechild(const size_t i, Node* node) override final {
1439  if (i != 0) return false;
1440  Expression* expr = dynamic_cast<Expression*>(node);
1441  if (!expr) return false;
1442  mExpression.reset(expr);
1443  mExpression->setParent(this);
1444  return true;
1445  }
1446 
1449  inline tokens::OperatorToken operation() const { return mOperation; }
1453  const Expression* expression() const { return mExpression.get(); }
1454 private:
1455  Expression::UniquePtr mExpression;
1456  const tokens::OperatorToken mOperation;
1457 };
1458 
1463 struct Cast : public Expression
1464 {
1465  using UniquePtr = std::unique_ptr<Cast>;
1466 
1472  Cast(Expression* expr, const tokens::CoreType type)
1473  : Expression()
1474  , mType(type)
1475  , mExpression(expr) {
1476  assert(mExpression);
1477  mExpression->setParent(this);
1478  }
1483  Cast(const Cast& other)
1484  : Expression()
1485  , mType(other.mType)
1486  , mExpression(other.mExpression->copy()) {
1487  mExpression->setParent(this);
1488  }
1489  ~Cast() override = default;
1490 
1492  Cast* copy() const override final { return new Cast(*this); }
1494  NodeType nodetype() const override { return Node::CastNode; }
1496  const char* nodename() const override { return "cast"; }
1498  const char* subname() const override { return "cast"; }
1500  const Expression* basetype() const override { return this; }
1502  size_t children() const override final { return 1; }
1504  const Expression* child(const size_t i) const override final {
1505  if (i == 0) return this->expression();
1506  return nullptr;
1507  }
1509  inline bool replacechild(const size_t i, Node* node) override final {
1510  if (i != 0) return false;
1511  Expression* expr = dynamic_cast<Expression*>(node);
1512  if (!expr) return false;
1513  mExpression.reset(expr);
1514  mExpression->setParent(this);
1515  return true;
1516  }
1517 
1520  inline tokens::CoreType type() const { return mType; }
1525  inline std::string typestr() const {
1526  return ast::tokens::typeStringFromToken(mType);
1527  }
1531  const Expression* expression() const { return mExpression.get(); }
1532 private:
1533  const tokens::CoreType mType;
1534  Expression::UniquePtr mExpression;
1535 };
1536 
1540 struct FunctionCall : public Expression
1541 {
1542  using UniquePtr = std::unique_ptr<FunctionCall>;
1543 
1550  FunctionCall(const std::string& function,
1551  Expression* argument = nullptr)
1552  : mFunctionName(function)
1553  , mArguments() {
1554  this->append(argument);
1555  }
1562  FunctionCall(const std::string& function,
1563  const std::vector<Expression*>& arguments)
1564  : mFunctionName(function)
1565  , mArguments() {
1566  mArguments.reserve(arguments.size());
1567  for (Expression* arg : arguments) {
1568  this->append(arg);
1569  }
1570  }
1576  : mFunctionName(other.mFunctionName)
1577  , mArguments() {
1578  mArguments.reserve(other.mArguments.size());
1579  for (const Expression::UniquePtr& expr : other.mArguments) {
1580  this->append(expr->copy());
1581  }
1582  }
1583  ~FunctionCall() override = default;
1584 
1586  FunctionCall* copy() const override final { return new FunctionCall(*this); }
1588  NodeType nodetype() const override { return Node::FunctionCallNode; }
1590  const char* nodename() const override { return "function call"; }
1592  const char* subname() const override { return "call"; }
1594  const Expression* basetype() const override { return this; }
1596  size_t children() const override final { return this->size(); }
1598  const Expression* child(const size_t i) const override final {
1599  if (i >= mArguments.size()) return nullptr;
1600  return mArguments[i].get();
1601  }
1603  inline bool replacechild(const size_t i, Node* node) override final {
1604  if (mArguments.size() <= i) return false;
1605  Expression* expr = dynamic_cast<Expression*>(node);
1606  mArguments[i].reset(expr);
1607  mArguments[i]->setParent(this);
1608  return true;
1609  }
1610 
1613  inline const std::string& name() const { return mFunctionName; }
1616  inline size_t numArgs() const { return mArguments.size(); }
1617 
1619  inline size_t size() const { return mArguments.size(); }
1622  inline bool empty() const { return mArguments.empty(); }
1626  inline void append(Expression* expr) {
1627  if (expr) {
1628  mArguments.emplace_back(expr);
1629  expr->setParent(this);
1630  }
1631  }
1632 private:
1633  const std::string mFunctionName;
1634  std::vector<Expression::UniquePtr> mArguments;
1635 };
1636 
1640 struct Keyword : public Statement
1641 {
1642  using UniquePtr = std::unique_ptr<Keyword>;
1643 
1647  : mKeyword(keyw) {}
1650  Keyword(const Keyword& other)
1651  : mKeyword(other.mKeyword) {}
1652  ~Keyword() override = default;
1653 
1655  Keyword* copy() const override final { return new Keyword(*this); }
1657  NodeType nodetype() const override { return Node::KeywordNode; }
1659  const char* nodename() const override { return "keyword"; }
1661  const char* subname() const override { return "keyw"; }
1663  const Statement* basetype() const override { return this; }
1665  size_t children() const override final { return 0; }
1667  const Node* child(const size_t) const override final {
1668  return nullptr;
1669  }
1672  inline tokens::KeywordToken keyword() const { return mKeyword; }
1673 
1674 private:
1675  const tokens::KeywordToken mKeyword;
1676 };
1677 
1685 struct ArrayUnpack : public Expression
1686 {
1687  using UniquePtr = std::unique_ptr<ArrayUnpack>;
1688 
1699  Expression* component0,
1700  Expression* component1 = nullptr)
1701  : mIdx0(component0)
1702  , mIdx1(component1)
1703  , mExpression(expr) {
1704  assert(mIdx0);
1705  assert(mExpression);
1706  mIdx0->setParent(this);
1707  if(mIdx1) mIdx1->setParent(this);
1708  mExpression->setParent(this);
1709  }
1714  ArrayUnpack(const ArrayUnpack& other)
1715  : ArrayUnpack(other.mExpression->copy(),
1716  other.mIdx0->copy(),
1717  other.mIdx1 ? other.mIdx1->copy() : nullptr) {}
1718 
1719  ~ArrayUnpack() override = default;
1720 
1722  ArrayUnpack* copy() const override final { return new ArrayUnpack(*this); }
1724  NodeType nodetype() const override { return Node::ArrayUnpackNode; }
1726  const char* nodename() const override { return "array unpack"; }
1728  const char* subname() const override { return "unpk"; }
1730  const Expression* basetype() const override { return this; }
1732  size_t children() const override final { return 3; }
1734  const Statement* child(const size_t i) const override final {
1735  if (i == 0) return this->component0();
1736  if (i == 1) return this->component1();
1737  if (i == 2) return this->expression();
1738  return nullptr;
1739  }
1741  inline bool replacechild(const size_t i, Node* node) override final {
1742  if (i > 2) return false;
1743  Expression* expr = dynamic_cast<Expression*>(node);
1744  if (!expr) return false;
1745  if (i == 0) mIdx0.reset(expr);
1746  if (i == 1) mIdx1.reset(expr);
1747  if (i == 2) mExpression.reset(expr);
1748  expr->setParent(this);
1749  return true;
1750  }
1751 
1755  inline const Expression* component0() const { return mIdx0.get(); }
1760  inline const Expression* component1() const { return mIdx1.get(); }
1764  inline const Expression* expression() const { return mExpression.get(); }
1773  inline bool isMatrixIndex() const {
1774  // assumes that component0 is always valid
1775  return static_cast<bool>(this->component1());
1776  }
1777 private:
1778  Expression::UniquePtr mIdx0, mIdx1;
1779  Expression::UniquePtr mExpression;
1780 };
1781 
1784 struct ArrayPack : public Expression
1785 {
1786  using UniquePtr = std::unique_ptr<ArrayPack>;
1787 
1793  ArrayPack(Expression* expression)
1794  : mExpressions() {
1795  this->append(expression);
1796  }
1801  ArrayPack(const std::vector<Expression*>& arguments)
1802  : mExpressions() {
1803  mExpressions.reserve(arguments.size());
1804  for (Expression* arg : arguments) {
1805  this->append(arg);
1806  }
1807  }
1811  ArrayPack(const ArrayPack& other)
1812  : mExpressions() {
1813  mExpressions.reserve(other.mExpressions.size());
1814  for (const Expression::UniquePtr& expr : other.mExpressions) {
1815  this->append(expr->copy());
1816  }
1817  }
1818  ~ArrayPack() override = default;
1819 
1821  ArrayPack* copy() const override final { return new ArrayPack(*this); }
1823  NodeType nodetype() const override { return Node::ArrayPackNode; }
1825  const char* nodename() const override { return "array pack"; }
1827  const char* subname() const override { return "pack"; }
1829  const Expression* basetype() const override { return this; }
1831  size_t children() const override final { return this->size(); }
1833  const Expression* child(const size_t i) const override final {
1834  if (i >= mExpressions.size()) return nullptr;
1835  return mExpressions[i].get();
1836  }
1838  inline bool replacechild(const size_t i, Node* node) override final {
1839  if (mExpressions.size() <= i) return false;
1840  Expression* expr = dynamic_cast<Expression*>(node);
1841  mExpressions[i].reset(expr);
1842  mExpressions[i]->setParent(this);
1843  return true;
1844  }
1845 
1847  inline size_t size() const { return mExpressions.size(); }
1850  inline bool empty() const { return mExpressions.empty(); }
1854  inline void append(Expression* expr) {
1855  if (expr) {
1856  mExpressions.emplace_back(expr);
1857  expr->setParent(this);
1858  }
1859  }
1860 private:
1861  std::vector<Expression::UniquePtr> mExpressions;
1862 };
1863 
1873 struct Attribute : public Variable
1874 {
1875  using UniquePtr = std::unique_ptr<Attribute>;
1876 
1884  Attribute(const std::string& name, const tokens::CoreType type,
1885  const bool inferred = false)
1886  : Variable(name)
1887  , mType(type)
1888  , mTypeInferred(inferred) {}
1896  Attribute(const std::string& name, const std::string& token,
1897  const bool inferred = false)
1898  : Attribute(name, tokens::tokenFromTypeString(token), inferred) {}
1903  Attribute(const Attribute& other)
1904  : Variable(other)
1905  , mType(other.mType)
1906  , mTypeInferred(other.mTypeInferred) {}
1907  ~Attribute() override = default;
1908 
1910  Attribute* copy() const override final { return new Attribute(*this); }
1912  NodeType nodetype() const override { return Node::AttributeNode; }
1914  const char* nodename() const override { return "attribute"; }
1916  const char* subname() const override { return "atr"; }
1918  const Variable* basetype() const override { return this; }
1919 
1923  inline bool inferred() const { return mTypeInferred; }
1926  inline tokens::CoreType type() const { return mType; }
1931  inline std::string typestr() const {
1932  return ast::tokens::typeStringFromToken(mType);
1933  }
1937  inline std::string tokenname() const {
1938  return Attribute::tokenFromNameType(this->name(), this->type());
1939  }
1940 
1944  static inline char symbolseparator() { return '@'; }
1957  static inline std::string
1958  tokenFromNameType(const std::string& name, const tokens::CoreType type) {
1959  return ast::tokens::typeStringFromToken(type) +
1960  Attribute::symbolseparator() + name;
1961  }
1973  static inline bool
1974  nametypeFromToken(const std::string& token, std::string* name, std::string* type) {
1975  const size_t at = token.find(symbolseparator());
1976  if (at == std::string::npos) return false;
1977  if (type) {
1978  *type = token.substr(0, at);
1979  if (type->empty()) {
1981  }
1982  }
1983  if (name) *name = token.substr(at + 1, token.size());
1984  return true;
1985  }
1986 private:
1987  const tokens::CoreType mType;
1988  const bool mTypeInferred;
1989 };
1990 
2002 {
2003  using UniquePtr = std::unique_ptr<ExternalVariable>;
2004 
2008  ExternalVariable(const std::string& name, const tokens::CoreType type)
2009  : Variable(name)
2010  , mType(type) {}
2016  ExternalVariable(const std::string& name, const std::string& token)
2017  : ExternalVariable(name, tokens::tokenFromTypeString(token)) {}
2024  : Variable(other)
2025  , mType(other.mType) {}
2026  ~ExternalVariable() override = default;
2027 
2029  ExternalVariable* copy() const override final {
2030  return new ExternalVariable(*this);
2031  }
2033  NodeType nodetype() const override { return Node::ExternalVariableNode; }
2035  const char* nodename() const override { return "external"; }
2037  const char* subname() const override { return "ext"; }
2039  const Variable* basetype() const override { return this; }
2040 
2043  inline tokens::CoreType type() const { return mType; }
2048  inline std::string typestr() const {
2049  return ast::tokens::typeStringFromToken(mType);
2050  }
2054  inline const std::string tokenname() const {
2055  return ExternalVariable::tokenFromNameType(this->name(), this->type());
2056  }
2057 
2061  static inline char symbolseparator() { return '$'; }
2074  static inline std::string
2075  tokenFromNameType(const std::string& name, const tokens::CoreType type) {
2076  return ast::tokens::typeStringFromToken(type) +
2077  ExternalVariable::symbolseparator() + name;
2078  }
2090  static inline bool
2091  nametypeFromToken(const std::string& token, std::string* name, std::string* type) {
2092  const size_t at = token.find(symbolseparator());
2093  if (at == std::string::npos) return false;
2094  if (type) {
2095  *type = token.substr(0, at);
2096  if (type->empty()) {
2098  }
2099  }
2100  if (name) *name = token.substr(at + 1, token.size());
2101  return true;
2102  }
2103 private:
2104  const tokens::CoreType mType;
2105 };
2106 
2111 struct Local : public Variable
2112 {
2113  using UniquePtr = std::unique_ptr<Local>;
2114 
2117  Local(const std::string& name)
2118  : Variable(name) {}
2119  ~Local() override = default;
2120 
2122  Local* copy() const override final { return new Local(*this); }
2124  NodeType nodetype() const override { return Node::LocalNode; }
2126  const char* nodename() const override { return "local"; }
2128  const char* subname() const override { return "lcl"; }
2130  const Variable* basetype() const override { return this; }
2131 };
2132 
2138 struct DeclareLocal : public Statement
2139 {
2140  using UniquePtr = std::unique_ptr<DeclareLocal>;
2141 
2146  DeclareLocal(const tokens::CoreType type, Local* local, Expression* init = nullptr)
2147  : mType(type)
2148  , mLocal(local)
2149  , mInit(init) {
2150  assert(mLocal);
2151  mLocal->setParent(this);
2152  if (mInit) mInit->setParent(this);
2153  }
2159  : mType(other.mType)
2160  , mLocal(other.mLocal->copy())
2161  , mInit(other.hasInit() ? other.mInit->copy() : nullptr) {
2162  mLocal->setParent(this);
2163  if (mInit) mInit->setParent(this);
2164  }
2165  ~DeclareLocal() override = default;
2166 
2168  DeclareLocal* copy() const override final { return new DeclareLocal(*this); }
2170  NodeType nodetype() const override { return Node::DeclareLocalNode; }
2172  const char* nodename() const override { return "declaration"; }
2174  const char* subname() const override { return "dcl"; }
2176  const Statement* basetype() const override { return this; }
2178  size_t children() const override final { return 2; }
2180  const Expression* child(const size_t i) const override final {
2181  if (i == 0) return this->local();
2182  if (i == 1) return this->init();
2183  return nullptr;
2184  }
2186  inline bool replacechild(const size_t i, Node* node) override final {
2187  if (i > 1) return false;
2188  if (i == 0) {
2189  Local* local = dynamic_cast<Local*>(node);
2190  if (!local) return false;
2191  mLocal.reset(local);
2192  mLocal->setParent(this);
2193  }
2194  else {
2195  Expression* init = dynamic_cast<Expression*>(node);
2196  if (!init) return false;
2197  mInit.reset(init);
2198  mInit->setParent(this);
2199  }
2200  return true;
2201  }
2202 
2206  inline tokens::CoreType type() const { return mType; }
2211  inline std::string typestr() const {
2212  return ast::tokens::typeStringFromToken(mType);
2213  }
2216  inline bool hasInit() const { return static_cast<bool>(this->init()); }
2217 
2220  const Local* local() const { return mLocal.get(); }
2223  const Expression* init() const { return mInit.get(); }
2224 
2225 private:
2226  const tokens::CoreType mType;
2227  Local::UniquePtr mLocal; // could be Variable for attribute declaration
2228  Expression::UniquePtr mInit;
2229 };
2230 
2231 
2251 template <typename T>
2252 struct Value : public ValueBase
2253 {
2254  using UniquePtr = std::unique_ptr<Value<T>>;
2255 
2256  using Type = T;
2260  using ContainerType = typename std::conditional<
2261  std::is_integral<T>::value, uint64_t, T>::type;
2262 
2265  static constexpr bool IsSupported =
2266  std::is_same<T, bool>::value ||
2267  std::is_same<T, int16_t>::value ||
2268  std::is_same<T, int32_t>::value ||
2269  std::is_same<T, int64_t>::value ||
2270  std::is_same<T, float>::value ||
2271  std::is_same<T, double>::value;
2272  static_assert(IsSupported, "Incompatible ast::Value node instantiated.");
2273 
2277  Value(const ContainerType value)
2278  : mValue(value) {}
2283  Value(const Value<T>& other)
2284  : mValue(other.mValue) {}
2285  ~Value() override = default;
2286 
2288  Value<Type>* copy() const override final { return new Value<Type>(*this); }
2290  NodeType nodetype() const override {
2291  if (std::is_same<T, bool>::value) return Node::ValueBoolNode;
2292  if (std::is_same<T, int16_t>::value) return Node::ValueInt16Node;
2293  if (std::is_same<T, int32_t>::value) return Node::ValueInt32Node;
2294  if (std::is_same<T, int64_t>::value) return Node::ValueInt64Node;
2295  if (std::is_same<T, float>::value) return Node::ValueFloatNode;
2296  if (std::is_same<T, double>::value) return Node::ValueDoubleNode;
2297  }
2299  const char* nodename() const override {
2300  if (std::is_same<T, bool>::value) return "boolean literal";
2301  if (std::is_same<T, int16_t>::value) return "int16 literal";
2302  if (std::is_same<T, int32_t>::value) return "int32 literal";
2303  if (std::is_same<T, int64_t>::value) return "int64 literal";
2304  if (std::is_same<T, float>::value) return "float (32bit) literal";
2305  if (std::is_same<T, double>::value) return "double (64bit) literal";
2306  }
2308  const char* subname() const override {
2309  if (std::is_same<T, bool>::value) return "bool";
2310  if (std::is_same<T, int16_t>::value) return "i16";
2311  if (std::is_same<T, int32_t>::value) return "i32";
2312  if (std::is_same<T, int64_t>::value) return "i64";
2313  if (std::is_same<T, float>::value) return "flt";
2314  if (std::is_same<T, double>::value) return "dbl";
2315  }
2317  const ValueBase* basetype() const override { return this; }
2318 
2321  inline ContainerType asContainerType() const { return mValue; }
2324  inline T value() const { return static_cast<T>(mValue); }
2325 
2326 private:
2327  // A container of a max size defined by LiteralValueContainer to hold values
2328  // which may be out of scope. This is only used for warnings
2329  const ContainerType mValue;
2330 };
2331 
2333 template <>
2334 struct Value<std::string> : public ValueBase
2335 {
2336  using UniquePtr = std::unique_ptr<Value<std::string>>;
2337 
2338  using Type = std::string;
2341  Value(const Type& value) : mValue(value) {}
2346  Value(const Value<Type>& other) : mValue(other.mValue) {}
2347  ~Value() override = default;
2348 
2349  Value<Type>* copy() const override final { return new Value<Type>(*this); }
2350  NodeType nodetype() const override { return Node::ValueStrNode; }
2351  const char* nodename() const override { return "string value"; }
2352  const char* subname() const override { return "str"; }
2353  const ValueBase* basetype() const override { return this; }
2354 
2357  inline const std::string& value() const { return mValue; }
2358 private:
2359  const Type mValue;
2360 };
2361 
2362 // fwd declaration for backwards compatibility, see Parse.h/.cc for definition
2363 openvdb::ax::ast::Tree::Ptr parse(const char* code);
2364 
2365 } // namespace ast
2366 } // namespace ax
2367 
2368 } // namespace OPENVDB_VERSION_NAME
2369 } // namespace openvdb
2370 
2371 #endif // OPENVDB_AX_AST_HAS_BEEN_INCLUDED
2372 
KeywordToken
Definition: Tokens.h:314
size_t size() const
Alias for StatementList::children.
Definition: AST.h:451
const Statement * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:915
CoreType
Definition: Tokens.h:31
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:514
static bool nametypeFromToken(const std::string &token, std::string *name, std::string *type)
Static method which splits a valid attribute token into its name and type counterparts. If the token cannot be split, neither name or type are updated and false is returned.
Definition: AST.h:1974
const Expression * child(const size_t i) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:1047
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:1045
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:1236
bool replacechild(const size_t i, Node *node) override final
Virtual method that attempted to replace a child at a given index with a provided node type...
Definition: AST.h:441
FunctionCall * copy() const override final
The deep copy method for a Node.
Definition: AST.h:1586
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:2308
FunctionCall(const std::string &function, Expression *argument=nullptr)
Construct a new FunctionCall with a given function identifier and an optional argument, transferring ownership of any provided argument to the FunctionCall and updating parent data on the arguments.
Definition: AST.h:1550
A BinaryOperator represents a single binary operation between a left hand side (LHS) and right hand s...
Definition: AST.h:987
size_t size() const
Alias for CommaOperator::children.
Definition: AST.h:676
A Value (literal) AST node holds either literal text or absolute value information on all numerical...
Definition: AST.h:2252
std::unique_ptr< Node > UniquePtr
Definition: AST.h:104
FunctionCall(const std::string &function, const std::vector< Expression * > &arguments)
Construct a new FunctionCall with a given function identifier and optional argument list...
Definition: AST.h:1562
const Block * child(const size_t i) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:598
std::string typestr() const
Get the access type as a front end AX type/token string.
Definition: AST.h:1931
const Block * body() const
Access a const pointer to the Loop body as a Block.
Definition: AST.h:837
ValueBases are a base class for anything that holds a value (literal). Derived classes store the actu...
Definition: AST.h:360
const Expression * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:1337
std::shared_ptr< Node > Ptr
Definition: AST.h:103
LoopToken
Definition: Tokens.h:296
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:1502
ArrayPack(const ArrayPack &other)
Deep copy constructor for a ArrayPack, performing a deep copy on all held arguments, ensuring parent information is updated.
Definition: AST.h:1811
bool replacechild(const size_t i, Node *node) override final
Virtual method that attempted to replace a child at a given index with a provided node type...
Definition: AST.h:1509
BinaryOperator(Expression *left, Expression *right, const tokens::OperatorToken op)
Construct a new BinaryOperator with a given tokens::OperatorToken and a valid LHS and RHS expression...
Definition: AST.h:999
AssignExpressions represents a similar object construction to a BinaryOperator. AssignExpressions can...
Definition: AST.h:1197
Block()
Construct a new Block with an empty list.
Definition: AST.h:480
size_t numArgs() const
Query the total number of arguments stored on this function.
Definition: AST.h:1616
std::string tokenname() const
Construct and return the full attribute token identifier. See Attribute::tokenFromNameType.
Definition: AST.h:1937
std::unique_ptr< CommaOperator > UniquePtr
Definition: AST.h:608
AssignExpression(Expression *lhs, Expression *rhs, const tokens::OperatorToken op=tokens::EQUALS)
Construct a new AssignExpression with valid LHS and RHS expressions, transferring ownership of the ex...
Definition: AST.h:1207
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:1912
Attribute(const std::string &name, const tokens::CoreType type, const bool inferred=false)
Construct a new Attribute with a given name and type. Optionally also mark it as inferred type creati...
Definition: AST.h:1884
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:1427
StatementList(Statement *statement)
Construct a new StatementList with a single statement, transferring ownership of the statement to the...
Definition: AST.h:396
bool replacechild(const size_t i, Node *node) override final
Virtual method that attempted to replace a child at a given index with a provided node type...
Definition: AST.h:1053
bool hasInit() const
Query if this declaration has an initialiser.
Definition: AST.h:2216
const Variable * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:2130
const Expression * lhs() const
Access a const pointer to the AssignExpression LHS as an abstract expression.
Definition: AST.h:1279
const Statement * child(const size_t i) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:436
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:434
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:1039
Block(const Block &other)
Deep copy constructor for a Block, performing a deep copy on every held statement, ensuring parent information is updated.
Definition: AST.h:504
static std::string tokenFromNameType(const std::string &name, const tokens::CoreType type)
Static method returning the full unique external token identifier by consolidating its name and type ...
Definition: AST.h:2075
Block(Statement *statement)
Construct a new Block with a single statement, transferring ownership of the statement to the block a...
Definition: AST.h:486
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:596
CommaOperator()
Construct a new CommaOperator with an expr set.
Definition: AST.h:611
tokens::OperatorToken operation() const
Query the type of binary operation held on this node.
Definition: AST.h:1070
const Node * parent() const
Access a const pointer to this nodes parent.
Definition: AST.h:271
const Expression * child(const size_t i) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:1504
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:2290
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:589
ArrayPack(Expression *expression)
Construct a new ArrayPack with a single expression, transferring ownership of the expression to the A...
Definition: AST.h:1793
Variable(const Variable &other)
Definition: AST.h:342
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:1431
TernaryOperator * copy() const override final
The deep copy method for a Node.
Definition: AST.h:1131
ArrayUnpack(Expression *expr, Expression *component0, Expression *component1=nullptr)
Construct a new ArrayUnpack with a valid expression, an initial component (as an expression) to the f...
Definition: AST.h:1698
const Expression * init() const
Access a const pointer to the initialiser.
Definition: AST.h:2223
std::unique_ptr< Statement > UniquePtr
Definition: AST.h:313
const Block * trueBranch() const
Access a const pointer to the ConditionalStatements &#39;true&#39; branch as a Block.
Definition: AST.h:970
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:1143
A UnaryOperator represents a single unary operation on an expression. The operation type is stored as...
Definition: AST.h:1388
const std::string & value() const
Access the string.
Definition: AST.h:2357
Definition: axparser.h:115
const Variable * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:2039
Attributes represent any access to a primitive value, typically associated with the &#39;@&#39; symbol syntax...
Definition: AST.h:1873
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:1137
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:1661
DeclareLocal(const tokens::CoreType type, Local *local, Expression *init=nullptr)
Construct a new DeclareLocal with a given name and type.
Definition: AST.h:2146
StatementList(const std::vector< Statement * > &statements)
Construct a new StatementList from a vector of statements, transferring ownership of all valid statem...
Definition: AST.h:405
bool hasInit() const
Query if this Loop has a valid initial statement.
Definition: AST.h:827
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:1240
Concrete AST nodes.
Definition: AST.h:385
virtual const Node * child(const size_t index) const =0
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
bool replacechild(const size_t i, Node *node) override final
Virtual method that attempted to replace a child at a given index with a provided node type...
Definition: AST.h:1347
tokens::LoopToken loopType() const
Query the type of loop held on this node.
Definition: AST.h:824
openvdb::ax::ast::Tree::Ptr parse(const char *code)
Construct an abstract syntax tree from a code snippet. A runtime exception will be thrown with the fi...
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:1238
const Expression * child(const size_t i) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:1145
bool isType() const
Query whether or not this node is of a specific (derived) type. This method should be used to check i...
Definition: AST.h:184
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:1494
Definition: Coord.h:587
const Expression * condition() const
Access a const pointer to the ConditionalStatements condition as an abstract expression.
Definition: AST.h:966
tokens::OperatorToken operation() const
Query the actual operational type of this AssignExpression. For simple (non-compound) AssignExpressio...
Definition: AST.h:1275
std::unique_ptr< Local > UniquePtr
Definition: AST.h:2113
bool pre() const
Query if this Crement node represents a pre crement ++a.
Definition: AST.h:1369
Tree(Block *block=new Block())
Construct a new Tree from a given Block, transferring ownership of the Block to the tree and updating...
Definition: AST.h:571
Loops represent for, while and do-while loop constructs. These all consist of a condition - evaluated...
Definition: AST.h:707
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:1498
const Statement * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:431
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:655
const Expression * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:1500
const Statement * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:520
size_t size() const
Alias for Block::children.
Definition: AST.h:540
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:2299
Definition: axparser.h:63
Value< Type > * copy() const override final
The deep copy method for a Node.
Definition: AST.h:2349
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:1333
std::unique_ptr< Expression > UniquePtr
Definition: AST.h:327
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:2352
const Expression * child(const size_t i) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:1246
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:1831
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:1657
const Statement * child(const size_t i) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:1734
CoreType tokenFromTypeString(const std::string &type)
Definition: Tokens.h:66
Value(const Value< Type > &other)
Deep copy constructor for a Value string.
Definition: AST.h:2346
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:1724
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:2170
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:2124
ExternalVariable * copy() const override final
The deep copy method for a Node.
Definition: AST.h:2029
std::string typestr() const
Get the declaration type as a front end AX type/token string.
Definition: AST.h:2211
static bool nametypeFromToken(const std::string &token, std::string *name, std::string *type)
Static method which splits a valid external token into its name and type counterparts. If the token cannot be split, neither name or type are updated and false is returned.
Definition: AST.h:2091
FunctionCalls represent a single call to a function and any provided arguments. The argument list can...
Definition: AST.h:1540
Tree * copy() const override final
The deep copy method for a Node.
Definition: AST.h:585
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:2174
const Statement * child(const size_t i) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:782
A Tree is the highest concrete (non-abstract) node in the entire AX AST hierarchy. It represents an entire conversion of a valid AX string.
Definition: AST.h:561
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:1592
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:523
Operation
A simple enum representing the crement type.
Definition: AST.h:1298
StatementList * copy() const override
The deep copy method for a Node.
Definition: AST.h:423
const Expression * expression() const
Access a const pointer to the Cast node&#39;s expression as an abstract expression.
Definition: AST.h:1531
T value() const
Access the value as its requested (templated) type.
Definition: AST.h:2324
bool replacechild(const size_t i, Node *node) override final
Virtual method that attempted to replace a child at a given index with a provided node type...
Definition: AST.h:1603
DeclareLocal AST nodes symbolize a single type declaration of a local variable. These store the local...
Definition: AST.h:2138
BinaryOperator * copy() const override final
The deep copy method for a Node.
Definition: AST.h:1033
ExternalVariable represent any access to external (custom) data, typically associated with the &#39;$&#39; sy...
Definition: AST.h:2001
ExternalVariable(const ExternalVariable &other)
Deep copy constructor for a ExternalVariable.
Definition: AST.h:2023
tokens::OperatorToken operation() const
Query the type of unary operation held on this node.
Definition: AST.h:1449
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:2126
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:2033
CommaOperator(const std::vector< Expression * > &expressions)
Construct a new CommaOperator from a vector of expression, transferring ownership of all valid expres...
Definition: AST.h:626
const Node * child(const size_t) const override
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:350
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:780
A TernaryOperator represents a ternary (conditional) expression &#39;a ? b : c&#39; which evaluates to &#39;b&#39; if...
Definition: AST.h:1091
ArrayPacks represent temporary container creations of arbitrary sizes, typically generated through th...
Definition: AST.h:1784
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:1596
const Statement * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:2176
const Variable * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:1918
const Expression * trueBranch() const
Access a const pointer to the TernaryOperator true expression as an abstract expression.
Definition: AST.h:1180
Abstract (pure-virtual) AST nodes.
Definition: AST.h:311
const ValueBase * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:2317
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:1823
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:1914
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:1037
Attribute(const std::string &name, const std::string &token, const bool inferred=false)
Construct a new Attribute with a given name and type/token string, delegating construction to the abo...
Definition: AST.h:1896
const std::string & name() const
Definition: AST.h:352
void addStatement(Statement *stmnt)
Adds a statement to this statement list, transferring ownership to the statement list and updating pa...
Definition: AST.h:455
ContainerType asContainerType() const
Access the value as its stored type.
Definition: AST.h:2321
TernaryOperator(const TernaryOperator &other)
Deep copy constructor for a TernaryOperator, performing a deep copy on held expressions, ensuring parent information is updated.
Definition: AST.h:1120
const Expression * lhs() const
Access a const pointer to the BinaryOperator LHS as an abstract expression.
Definition: AST.h:1074
const Expression * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:365
Value(const Value< T > &other)
Deep copy constructor for a Value.
Definition: AST.h:2283
tokens::CoreType type() const
Access to the target type.
Definition: AST.h:1520
const Statement * initial() const
Access a const pointer to the Loop initial statement as an abstract statement.
Definition: AST.h:841
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:425
Block(const std::vector< Statement * > &statements)
Construct a new Block from a vector of statements, transferring ownership of all valid statements to ...
Definition: AST.h:495
std::unique_ptr< StatementList > UniquePtr
Definition: AST.h:387
const Statement * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:1663
size_t size() const
Alias for FunctionCall::children.
Definition: AST.h:1619
const Expression * condition() const
Access a const pointer to the TernaryOperator conditional as an abstract expression.
Definition: AST.h:1176
ExternalVariable(const std::string &name, const std::string &token)
Construct a new ExternalVariable with a given name and type/token string, delegating construction to ...
Definition: AST.h:2016
typename std::conditional< std::is_integral< T >::value, uint64_t, T >::type ContainerType
Integers and Floats store their value as ContainerType, which is guaranteed to be at least large enou...
Definition: AST.h:2261
const Expression * expression() const
Access a const pointer to the expression being indexed as an abstract Expression. ...
Definition: AST.h:1764
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:2037
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:1244
bool replace(Node *node)
In place replacement. Attempts to replace this node at its specific location within its Abstract Synt...
Definition: AST.h:247
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:1496
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:911
std::shared_ptr< const Tree > ConstPtr
Definition: AST.h:564
static std::string tokenFromNameType(const std::string &name, const tokens::CoreType type)
Static method returning the full unique attribute token identifier by consolidating its name and type...
Definition: AST.h:1958
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:518
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:1825
DeclareLocal * copy() const override final
The deep copy method for a Node.
Definition: AST.h:2168
ConditionalStatement * copy() const override final
The deep copy method for a Node.
Definition: AST.h:905
size_t size() const
Alias for ArrayPack::children.
Definition: AST.h:1847
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:1827
Crement * copy() const override final
The deep copy method for a Node.
Definition: AST.h:1329
std::unique_ptr< Block > UniquePtr
Definition: AST.h:477
size_t branchCount() const
Query the number of branches held by this ConditionalStatement. This is only ever 1 or 2...
Definition: AST.h:960
const std::string & name() const
Access the function name/identifier.
Definition: AST.h:1613
bool replacechild(const size_t i, Node *node) override final
Virtual method that attempted to replace a child at a given index with a provided node type...
Definition: AST.h:927
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:773
bool replacechild(const size_t i, Node *node) override final
Virtual method that attempted to replace a child at a given index with a provided node type...
Definition: AST.h:2186
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:1590
ConditionalStatement(const ConditionalStatement &other)
Deep copy constructor for an ConditionalStatement, performing a deep copy on the condition and both h...
Definition: AST.h:894
bool hasFalse() const
Query if this ConditionalStatement has a valid &#39;false&#39; branch.
Definition: AST.h:954
static char symbolseparator()
Static method returning the symbol associated with an ExternalVariable access as defined by AX Gramma...
Definition: AST.h:2061
Loop * copy() const override final
The deep copy method for a Node.
Definition: AST.h:769
Tree(const Tree &other)
Deep copy constructor for a Tree, performing a deep copy on the held Block, ensuring parent informati...
Definition: AST.h:578
Definition: openvdb/Exceptions.h:13
CommaOperator(const CommaOperator &other)
Deep copy constructor for an CommaOperator, performing a deep copy on every held expression, ensuring parent information is updated.
Definition: AST.h:637
bool empty() const
Query whether this Expression list holds any valid expressions.
Definition: AST.h:1850
const Expression * iteration() const
Access a const pointer to the Loop iteration Expression.
Definition: AST.h:844
bool isCompound() const
Query whether or not this is a compound AssignExpression. Compound AssignExpressions are assignments ...
Definition: AST.h:1271
const Expression * falseBranch() const
Access a const pointer to the TernaryOperator false expression as an abstract expression.
Definition: AST.h:1184
StatementList(const StatementList &other)
Deep copy constructor for a StatementList, performing a deep copy on every held statement, ensuring parent information is updated.
Definition: AST.h:415
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:2172
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:1728
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:2178
void addStatement(Statement *stmnt)
Adds a statement to this block, transferring ownership to the block and updating parent data on the s...
Definition: AST.h:544
The base abstract node which determines the interface and required methods for all derived concrete n...
Definition: AST.h:101
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:1588
const Node * child(const size_t) const override
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:368
ConditionalStatements represents all combinations of &#39;if&#39;, &#39;else&#39; and &#39;else if&#39; syntax and semantics...
Definition: AST.h:863
tokens::CoreType type() const
Access the type that was used to access this attribute.
Definition: AST.h:1926
Attribute * copy() const override final
The deep copy method for a Node.
Definition: AST.h:1910
bool replacechild(const size_t i, Node *node) override final
Virtual method that attempted to replace a child at a given index with a provided node type...
Definition: AST.h:1741
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:2350
const Block * falseBranch() const
Access a const pointer to the ConditionalStatements &#39;false&#39; branch as a Block.
Definition: AST.h:974
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:516
const Statement * condition() const
Access a const pointer to the Loop condition as an abstract statement.
Definition: AST.h:834
Variables are a base type for Locals, Attributes and ExternalVariables. Unlike other abstract types...
Definition: AST.h:336
void append(Expression *expr)
Appends an argument to this ArrayPack, transferring ownership to the ArrayPack and updating parent da...
Definition: AST.h:1854
const Expression * child(const size_t i) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:1833
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:651
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:1331
ConditionalStatement(Expression *conditional, Block *trueBlock, Block *falseBlock=nullptr)
Construct a new ConditionalStatement with an Expression representing the primary condition, a Block representing the &#39;true&#39; branch and an optional Block representing the &#39;false&#39; branch. Ownership of all arguments is transferred to the ConditionalStatement. All arguments have their parent data updated.
Definition: AST.h:877
const Expression * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:1594
const Expression * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:657
bool replacechild(const size_t i, Node *node) override final
Virtual method that attempted to replace a child at a given index with a provided node type...
Definition: AST.h:667
const Expression * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:1829
Keyword * copy() const override final
The deep copy method for a Node.
Definition: AST.h:1655
int64_t childidx() const
Returns the child index of this node in relation to its parent, or -1 if no valid index is found (usu...
Definition: AST.h:211
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:591
const Local * local() const
Access a const pointer to the Local.
Definition: AST.h:2220
const Expression * child(const size_t i) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:662
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:429
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:918
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:909
const Expression * component0() const
Access a const pointer to the first component being used as an abstract Expression.
Definition: AST.h:1755
const Node * child(const size_t) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:1667
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:1726
std::string typestr() const
Get the target type as a front end AX type/token string.
Definition: AST.h:1525
bool post() const
Query if this Crement node represents a post crement a++.
Definition: AST.h:1372
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:1135
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:1732
std::string typeStringFromToken(const CoreType type)
Definition: Tokens.h:118
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:1041
const Expression * child(const size_t i) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:1433
Cast(const Cast &other)
Deep copy constructor for a Cast node, performing a deep copy on the underlying expressions, ensuring parent information is updated.
Definition: AST.h:1483
const Expression * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:347
bool decrement() const
Query if this Crement node represents an decrement –.
Definition: AST.h:1366
const Expression * rhs() const
Access a const pointer to the AssignExpression RHS as an.
Definition: AST.h:1283
const Expression * expression() const
Access a const pointer to the expression being crements as an abstract Expression.
Definition: AST.h:1376
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:653
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:1335
Keyword(const Keyword &other)
Deep copy constructor for a Keyword.
Definition: AST.h:1650
std::string Type
Definition: AST.h:2338
ArrayUnpack represent indexing operations into AX container types, primarily vectors and matrices ind...
Definition: AST.h:1685
ArrayPack * copy() const override final
The deep copy method for a Node.
Definition: AST.h:1821
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:2035
StatementList()
Construct a new StatementList with an empty list.
Definition: AST.h:390
bool isMatrixIndex() const
Query whether this ArrayUnpack operation must be a matrix indexing operation by checking the presence...
Definition: AST.h:1773
const Expression * expression() const
Access a const pointer to the UnaryOperator expression as an abstract expression. ...
Definition: AST.h:1453
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:660
AssignExpression(const AssignExpression &other)
Deep copy constructor for an AssignExpression, performing a deep copy on both held expressions...
Definition: AST.h:1222
UnaryOperator(const UnaryOperator &other)
Deep copy constructor for a UnaryOperator, performing a deep copy on the underlying expressions...
Definition: AST.h:1413
virtual const Node * basetype() const
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:175
bool hasIter() const
Query if this Loop has a valid iteration expression list.
Definition: AST.h:830
Crement(Expression *expr, const Operation op, bool post)
Construct a new Crement with a valid expression, transferring ownership of the expression to the Crem...
Definition: AST.h:1310
ArrayUnpack(const ArrayUnpack &other)
Deep copy constructor for a ArrayUnpack, performing a deep copy on the expression being indexed and a...
Definition: AST.h:1714
size_t children() const override
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:349
Loop(const Loop &other)
Deep copy constructor for an Loop, performing a deep copy on the condition, body and initial Statemen...
Definition: AST.h:749
std::string typestr() const
Get the access type as a front end AX type/token string.
Definition: AST.h:2048
OperatorToken operatorTokenFromName(const std::string &name)
Definition: Tokens.h:221
Various function and operator tokens used throughout the AST and code generation. ...
Keywords represent keyword statements defining changes in execution. These include those that define ...
Definition: AST.h:1640
const Node * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:593
NodeType
An enumerated list of node types for all concrete node types. These can be used for faster evaluation...
Definition: AST.h:117
UnaryOperator(Expression *expr, const std::string &op)
Construct a new UnaryOperator with a string, delegating construction to the above UnaryOperator const...
Definition: AST.h:1407
AssignExpression * copy() const override final
The deep copy method for a Node.
Definition: AST.h:1232
Loop(const tokens::LoopToken loopType, Statement *condition, Block *body, Statement *init=nullptr, Expression *iter=nullptr)
Construct a new Loop with the type defined by a tokens::LoopToken, a condition Statement, a Block representing the body and for for-loops an optional initial Statement and iteration Expression. Ownership of all arguments is transferred to the Loop. All arguments have their parent data updated.
Definition: AST.h:722
Keyword(const tokens::KeywordToken keyw)
Construct a new Keyword with a given tokens::KeywordToken.
Definition: AST.h:1646
bool hasTrue() const
Query whether or not this has an optional if-true branch.
Definition: AST.h:1172
void append(Expression *expr)
Append an expression to this CommaOperator, transferring ownership to the CommaOperator and updating ...
Definition: AST.h:683
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:2351
const Expression * child(const size_t i) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:1342
bool replacechild(const size_t i, Node *node) override final
Virtual method that attempted to replace a child at a given index with a provided node type...
Definition: AST.h:790
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:2128
bool inferred() const
Query whether this attribute was accessed via inferred syntax i.e. @P or @myattribute.
Definition: AST.h:1923
bool replacechild(const size_t i, Node *node) override final
Virtual method that attempted to replace a child at a given index with a provided node type...
Definition: AST.h:530
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:1139
bool increment() const
Query if this Crement node represents an incrementation ++.
Definition: AST.h:1363
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:775
UnaryOperator * copy() const override final
The deep copy method for a Node.
Definition: AST.h:1421
CommaOperator * copy() const override final
The deep copy method for a Node.
Definition: AST.h:647
void append(Expression *expr)
Appends an argument to this function call, transferring ownership to the FunctionCall and updating pa...
Definition: AST.h:1626
T Type
Definition: AST.h:2256
bool replacechild(const size_t i, Node *node) override final
Virtual method that attempted to replace a child at a given index with a provided node type...
Definition: AST.h:1438
Cast(Expression *expr, const tokens::CoreType type)
Construct a new Cast with a valid expression and a target tokens::CoreType, transferring ownership of...
Definition: AST.h:1472
BinaryOperator(const BinaryOperator &other)
Deep copy constructor for a BinaryOperator, performing a deep copy on both held expressions, ensuring parent information is updated.
Definition: AST.h:1023
bool replacechild(const size_t i, Node *node) override final
Virtual method that attempted to replace a child at a given index with a provided node type...
Definition: AST.h:1838
CommaOperator(Expression *expression)
Construct a new CommaOperator with a single expression, transferring ownership of the expression to t...
Definition: AST.h:617
static char symbolseparator()
Static method returning the symbol associated with an Attribute access as defined by AX Grammar...
Definition: AST.h:1944
DeclareLocal(const DeclareLocal &other)
Deep copy constructor for a DeclareLocal.
Definition: AST.h:2158
Local AST nodes represent a single accesses to a local variable. The only store the name of the varia...
Definition: AST.h:2111
ArrayUnpack * copy() const override final
The deep copy method for a Node.
Definition: AST.h:1722
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:587
A Block node represents a scoped list of statements. It may comprise of 0 or more statements...
Definition: AST.h:475
Definition: axparser.h:75
const Statement * child(const size_t i) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:920
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:771
const Node * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:316
Variable(const std::string &name)
Definition: AST.h:340
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:1659
const Expression * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:1043
const Expression * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:1429
Operation operation() const
Query the type of the Crement operation. This does not hold post or pre-crement information.
Definition: AST.h:1360
ArrayPack(const std::vector< Expression * > &arguments)
Construct a new ArrayPack transferring ownership of any provided arguments to the ArrayPack and updat...
Definition: AST.h:1801
ExternalVariable(const std::string &name, const tokens::CoreType type)
Construct a new ExternalVariable with a given name and type.
Definition: AST.h:2008
const Expression * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:1730
const Statement * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:330
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
Cast * copy() const override final
The deep copy method for a Node.
Definition: AST.h:1492
const Expression * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:1141
tokens::KeywordToken keyword() const
Query the keyword held on this node.
Definition: AST.h:1672
tokens::CoreType type() const
Access the type that was specified at which to create the given local.
Definition: AST.h:2206
const Expression * child(const size_t i) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:1598
const ValueBase * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:2353
const Expression * child(const size_t i) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:2180
Crement(const Crement &other)
Deep copy constructor for a Crement, performing a deep copy on the underlying expressions, ensuring parent information is updated.
Definition: AST.h:1320
Expressions are comprised of full or potentially partial parts of a full statement that may not neces...
Definition: AST.h:325
UnaryOperator(Expression *expr, const tokens::OperatorToken op)
Construct a new UnaryOperator with a given tokens::OperatorToken and a valid expression, transferring ownership of the expression to the UnaryOperator and updating parent data on the expression.
Definition: AST.h:1397
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:1340
FunctionCall(const FunctionCall &other)
Deep copy constructor for a FunctionCall, performing a deep copy on all held function arguments...
Definition: AST.h:1575
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:427
bool empty() const
Query whether this Expression list holds any valid expressions.
Definition: AST.h:1622
Attribute(const Attribute &other)
Deep copy constructor for a Attribute.
Definition: AST.h:1903
size_t children() const override
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:367
virtual size_t children() const =0
Virtual method for accessing child information. Returns the number of children a given AST node owns...
bool replacechild(const size_t i, Node *node) override final
Virtual method that attempted to replace a child at a given index with a provided node type...
Definition: AST.h:1252
Value(const ContainerType value)
Directly construct a Value from a source integer, float or boolean, guaranteeing valid construction...
Definition: AST.h:2277
Value(const Type &value)
Construct a new Value string from a string.
Definition: AST.h:2341
const char * nodename() const override
Virtual method for accessing node name information.
Definition: AST.h:1425
const Expression * rhs() const
Access a const pointer to the BinaryOperator RHS as an abstract expression.
Definition: AST.h:1078
A Crement node represents a single increment &#39;++&#39; and decrement &#39;–&#39; operation. As well as it&#39;s creme...
Definition: AST.h:1293
bool replacechild(const size_t i, Node *node) override final
Virtual method that attempted to replace a child at a given index with a provided node type...
Definition: AST.h:1152
Local(const std::string &name)
Construct a Local with a given name.
Definition: AST.h:2117
const Expression * component1() const
Access a const pointer to the second component being used as an abstract Expression.
Definition: AST.h:1760
OperatorToken
Definition: Tokens.h:150
BinaryOperator(Expression *left, Expression *right, const std::string &op)
Construct a new BinaryOperator with a string, delegating construction to the above BinaryOperator con...
Definition: AST.h:1015
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:913
Block * copy() const override final
The deep copy method for a Node.
Definition: AST.h:512
const Statement * child(const size_t i) const override final
Virtual method for accessing child information. Returns a const pointer to a child node at the given ...
Definition: AST.h:525
NodeType nodetype() const override
Virtual method for accessing node type information.
Definition: AST.h:1423
size_t children() const override final
Virtual method for accessing child information. Returns the number of children a given AST node owns...
Definition: AST.h:1665
TernaryOperator(Expression *conditional, Expression *trueExpression, Expression *falseExpression)
Construct a new TernaryOperator with a conditional expression and true (optional) and false expressio...
Definition: AST.h:1104
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:178
void setParent(Node *parent)
Set this node&#39;s parent. This is used during construction of an AST and should not be used...
Definition: AST.h:276
tokens::CoreType type() const
Access the type that was used to access this external variable.
Definition: AST.h:2043
bool empty() const
Query whether this Expression list holds any valid expressions.
Definition: AST.h:679
Local * copy() const override final
The deep copy method for a Node.
Definition: AST.h:2122
const char * subname() const override
Virtual method for accessing node name information.
Definition: AST.h:1916
std::unique_ptr< ArrayPack > UniquePtr
Definition: AST.h:1786
Value< Type > * copy() const override final
The deep copy method for a Node.
Definition: AST.h:2288
const Statement * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:777
const Expression * basetype() const override
Virtual method for accessing a node&#39;s base class. Note that if this is called explicitly on an instan...
Definition: AST.h:1242
const std::string tokenname() const
Construct and return the full external token identifier. See ExternalVariable::tokenFromNameType.
Definition: AST.h:2054
Cast nodes represent the conversion of an underlying expression to a target type. Cast nodes are typi...
Definition: AST.h:1463
std::unique_ptr< FunctionCall > UniquePtr
Definition: AST.h:1542