23 #include <torquescript/astvisitor.hpp>
24 #include <torquescript/stringtable.hpp>
25 #include <torquescript/instructionsequence.hpp>
43 virtual antlrcpp::Any accept(
ASTVisitor* visitor) = 0;
49 ProgramNode(
const std::vector<ASTNode*>& nodes) : mNodes(nodes)
62 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
64 return visitor->visitProgramNode(
this);
67 std::vector<ASTNode*> mNodes;
73 FunctionDeclarationNode(
const std::string space,
const std::string& name,
const std::vector<std::string>& parameterNames,
const std::vector<ASTNode*> body) :
74 mNameSpace(space), mName(name), mParameterNames(parameterNames), mBody(body)
87 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
89 return visitor->visitFunctionDeclarationNode(
this);
92 std::string mNameSpace;
94 std::vector<std::string> mParameterNames;
95 std::vector<ASTNode*> mBody;
101 PackageDeclarationNode(
const std::string& name,
const std::vector<ASTNode*>& functions) : mName(name), mFunctions(functions)
108 for (
ASTNode*
function : mFunctions)
114 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
116 return visitor->visitPackageDeclarationNode(
this);
120 std::vector<ASTNode*> mFunctions;
126 FieldAssignNode(
const std::string& fieldBaseName,
const std::vector<ASTNode*>& fieldExpressions,
ASTNode* right) : mFieldBaseName(fieldBaseName), mFieldExpressions(fieldExpressions), mRight(right)
131 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
133 return visitor->visitFieldAssignNode(
this);
136 std::string mFieldBaseName;
137 std::vector<ASTNode*> mFieldExpressions;
144 ObjectDeclarationNode(
ASTNode* name,
ASTNode* type,
const std::vector<ObjectDeclarationNode*>& children,
const std::vector<ASTNode*>& fields) : mName(name), mType(type), mChildren(children), mFields(fields)
148 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
150 return visitor->visitObjectDeclarationNode(
this);
156 std::vector<ObjectDeclarationNode*> mChildren;
157 std::vector<ASTNode*> mFields;
163 DatablockDeclarationNode(
const std::string& name,
const std::string& type,
const std::string& parentName,
const std::vector<ASTNode*>& fields) : mName(name), mType(type), mParentName(parentName), mFields(fields)
167 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
169 return visitor->visitDatablockDeclarationNode(
this);
174 std::string mParentName;
176 std::vector<ASTNode*> mFields;
182 FunctionCallNode(
const std::string& space,
const std::string& name,
const std::vector<ASTNode*> parameters) :
183 mNameSpace(space), mName(name), mParameters(parameters)
190 for (
ASTNode* parameter : mParameters)
196 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
198 return visitor->visitFunctionCallNode(
this);
201 std::string mNameSpace;
203 std::vector<ASTNode*> mParameters;
210 mTarget(target), mName(name), mParameters(parameters)
219 for (
ASTNode* parameter : mParameters)
225 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
227 return visitor->visitSubFunctionCallNode(
this);
232 std::vector<ASTNode*> mParameters;
238 SubFieldNode(
ASTNode* target,
const std::string& name,
const std::vector<ASTNode*>& indices) : mTarget(target), mName(name), mIndices(indices)
248 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
250 return visitor->visitSubFieldNode(
this);
255 std::vector<ASTNode*> mIndices;
285 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
287 return visitor->visitAddNode(
this);
299 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
301 return visitor->visitSubtractNode(
this);
313 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
315 return visitor->visitMultiplyNode(
this);
327 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
329 return visitor->visitDivideNode(
this);
341 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
343 return visitor->visitConcatNode(
this);
346 std::string mSeperator;
357 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
359 return visitor->visitEqualsNode(
this);
371 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
373 return visitor->visitAssignmentNode(
this);
385 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
387 return visitor->visitLessThanNode(
this);
415 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
417 return visitor->visitNegateNode(
this);
429 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
431 return visitor->visitNotNode(
this);
443 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
445 return visitor->visitIncrementNode(
this);
457 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
459 return visitor->visitDecrementNode(
this);
476 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
478 return visitor->visitIntegerNode(
this);
487 FloatNode(
const float value) : mValue(value)
492 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
494 return visitor->visitFloatNode(
this);
503 StringNode(
const std::string& value) : mValue(value)
508 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
510 return visitor->visitStringNode(
this);
524 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
526 return visitor->visitTaggedStringNode(
this);
540 std::string getName()
542 std::string result =
"";
543 for (
const std::string& component : mName)
545 if (result.size() == 0)
551 result +=
"::" + component;
557 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
559 return visitor->visitLocalVariableNode(
this);
562 std::vector<std::string> mName;
573 std::string getName()
575 std::string result =
"";
576 for (
const std::string& component : mName)
578 if (result.size() == 0)
584 result +=
"::" + component;
590 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
592 return visitor->visitGlobalVariableNode(
this);
595 std::vector<std::string> mName;
602 mTarget(target), mIndices(indices)
611 for (
ASTNode* index : mIndices)
617 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
619 return visitor->visitArrayNode(
this);
623 std::vector<ASTNode*> mIndices;
629 WhileNode(
ASTNode* expression,
const std::vector<ASTNode*>& body) : mExpression(expression), mBody(body)
644 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
646 return visitor->visitWhileNode(
this);
650 std::vector<ASTNode*> mBody;
657 mInitializer(initializer), mExpression(expression), mAdvance(advance), mBody(body)
674 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
676 return visitor->visitForNode(
this);
682 std::vector<ASTNode*> mBody;
701 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
703 return visitor->visitReturnNode(
this);
717 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
719 return visitor->visitBreakNode(
this);
727 mExpression(expression), mTrueValue(trueValue), mFalseValue(falseValue)
739 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
741 return visitor->visitTernaryNode(
this);
752 SwitchCaseNode(
const std::vector<ASTNode*> cases,
const std::vector<ASTNode*> body) : mCases(cases), mBody(body)
757 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
759 return visitor->visitSwitchCaseNode(
this);
762 std::vector<ASTNode*> mCases;
763 std::vector<ASTNode*> mBody;
769 SwitchNode(
ASTNode* expression,
const std::vector<SwitchCaseNode*> cases,
const std::vector<ASTNode*> defaultBody) :
770 mExpression(expression), mCases(cases), mDefaultBody(defaultBody)
784 for (
ASTNode* node : mDefaultBody)
790 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
792 return visitor->visitSwitchNode(
this);
796 std::vector<SwitchCaseNode*> mCases;
797 std::vector<ASTNode*> mDefaultBody;
803 ElseIfNode(
ASTNode* expression, std::vector<ASTNode*> body) : mExpression(expression), mBody(body)
818 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
820 return visitor->visitElseIfNode(
this);
824 std::vector<ASTNode*> mBody;
830 IfNode(
ASTNode* expression,
const std::vector<ASTNode*>& body,
const std::vector<ElseIfNode*>& elseIfs,
const std::vector<ASTNode*>& elseBody) :
831 mExpression(expression), mBody(body), mElseIfs(elseIfs), mElseBody(elseBody)
850 for (
ASTNode* node : mElseBody)
856 virtual antlrcpp::Any accept(
ASTVisitor* visitor)
858 return visitor->visitIfNode(
this);
862 std::vector<ASTNode*> mBody;
863 std::vector<ElseIfNode*> mElseIfs;
864 std::vector<ASTNode*> mElseBody;
Base AST node class. All AST nodes should derive from this class.
Definition: ast.hpp:36
Definition: astvisitor.hpp:65