6 #ifndef GDCORE_EXPRESSIONVARIABLEOWNERFINDER_H
7 #define GDCORE_EXPRESSIONVARIABLEOWNERFINDER_H
11 #include "GDCore/Events/Parsers/ExpressionParser2Node.h"
12 #include "GDCore/Events/Parsers/ExpressionParser2NodeWorker.h"
13 #include "GDCore/Extensions/Metadata/ExpressionMetadata.h"
14 #include "GDCore/Extensions/Metadata/MetadataProvider.h"
15 #include "GDCore/Extensions/Metadata/ObjectMetadata.h"
16 #include "GDCore/Extensions/Metadata/ParameterMetadata.h"
17 #include "GDCore/Project/Layout.h"
18 #include "GDCore/Project/ObjectsContainersList.h"
23 class ObjectsContainer;
25 class ParameterMetadata;
26 class ExpressionMetadata;
53 platform, objectsContainersList, rootObjectName);
54 node.Visit(typeFinder);
61 ExpressionVariableOwnerFinder(
const gd::Platform &platform_,
64 : platform(platform_),
65 objectsContainersList(objectsContainersList_),
66 rootObjectName(rootObjectName_),
68 variableNode(nullptr) {};
80 void OnVisitOperatorNode(OperatorNode& node)
override {}
81 void OnVisitUnaryOperatorNode(UnaryOperatorNode& node)
override {}
82 void OnVisitNumberNode(NumberNode& node)
override {}
83 void OnVisitTextNode(TextNode& node)
override {}
84 void OnVisitVariableNode(VariableNode& node)
override {
85 if (variableNode !=
nullptr) {
89 if (node.parent ==
nullptr) {
90 objectName = rootObjectName;
94 node.parent->Visit(*
this);
96 void OnVisitVariableAccessorNode(VariableAccessorNode& node)
override {}
97 void OnVisitIdentifierNode(IdentifierNode& node)
override {
98 if (variableNode !=
nullptr) {
102 if (node.parent ==
nullptr) {
103 objectName = rootObjectName;
108 variableNode = &node;
109 node.parent->Visit(*
this);
111 void OnVisitEmptyNode(EmptyNode& node)
override {}
112 void OnVisitObjectFunctionNameNode(ObjectFunctionNameNode& node)
override {}
113 void OnVisitVariableBracketAccessorNode(
114 VariableBracketAccessorNode& node)
override {}
115 void OnVisitFunctionCallNode(FunctionCallNode& functionCall)
override {
116 if (variableNode ==
nullptr) {
119 int parameterIndex = -1;
120 for (
int i = 0; i < functionCall.parameters.size(); i++) {
121 if (functionCall.parameters.at(i).get() == variableNode) {
126 if (parameterIndex < 0) {
130 MetadataProvider::GetFunctionCallParameterMetadata(
132 objectsContainersList,
135 if (parameterMetadata ==
nullptr
136 || parameterMetadata->
GetType() !=
"objectvar") {
142 objectName = functionCall.objectName;
143 for (
int previousIndex = parameterIndex - 1; previousIndex >= 0; previousIndex--) {
145 MetadataProvider::GetFunctionCallParameterMetadata(
147 objectsContainersList,
150 if (previousParameterMetadata !=
nullptr
152 auto previousParameterNode = functionCall.parameters[previousIndex].get();
153 IdentifierNode* objectNode =
dynamic_cast<IdentifierNode*
>(previousParameterNode);
154 objectName = objectNode->identifierName;
The interface for any worker class ("visitor" pattern) that want to interact with the nodes of a pars...
Definition: ExpressionParser2NodeWorker.h:36
Find the object name that should be used as a context of the expression or sub-expression that a give...
Definition: ExpressionVariableOwnerFinder.h:41
const gd::String & GetObjectName()
Get all the errors.
Definition: ExpressionVariableOwnerFinder.h:75
static const gd::String GetObjectName(const gd::Platform &platform, const gd::ObjectsContainersList &objectsContainersList, const gd::String &rootObjectName, gd::ExpressionNode &node)
Helper function to find the object name that should be used as a context of the expression or sub-exp...
Definition: ExpressionVariableOwnerFinder.h:48
A list of objects containers, useful for accessing objects in a scoped way, along with methods to acc...
Definition: ObjectsContainersList.h:29
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: CommonTools.h:24
The base node, from which all nodes in the tree of an expression inherits from.
Definition: ExpressionParser2Node.h:100
Definition: ExpressionParser2Node.h:115