GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
ExpressionVariableNameFinder.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-present Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 #pragma once
7 
8 #include "GDCore/Events/Parsers/ExpressionParser2Node.h"
9 #include "GDCore/Events/Parsers/ExpressionParser2NodeWorker.h"
10 
11 namespace gd {
12 
19  public:
20 
21  static const gd::String GetVariableName(gd::ExpressionNode& node) {
23  node.Visit(typeFinder);
24  return typeFinder.variableName;
25  }
26 
27  virtual ~ExpressionVariableNameFinder(){};
28 
29  protected:
31  : variableName("") {};
32 
33  void OnVisitSubExpressionNode(SubExpressionNode& node) override {}
34  void OnVisitOperatorNode(OperatorNode& node) override {}
35  void OnVisitUnaryOperatorNode(UnaryOperatorNode& node) override {}
36  void OnVisitNumberNode(NumberNode& node) override {}
37  void OnVisitTextNode(TextNode& node) override {}
38  void OnVisitVariableNode(VariableNode& node) override {
39  variableName = node.name;
40  }
41  void OnVisitVariableAccessorNode(VariableAccessorNode& node) override {}
42  void OnVisitIdentifierNode(IdentifierNode& node) override {
43  variableName = node.identifierName;
44  }
45  void OnVisitEmptyNode(EmptyNode& node) override {}
46  void OnVisitObjectFunctionNameNode(ObjectFunctionNameNode& node) override {}
47  void OnVisitVariableBracketAccessorNode(
48  VariableBracketAccessorNode& node) override {}
49  void OnVisitFunctionCallNode(FunctionCallNode& functionCall) override {}
50 
51  private:
52  gd::String variableName;
53 };
54 
55 } // namespace gd
The interface for any worker class ("visitor" pattern) that want to interact with the nodes of a pars...
Definition: ExpressionParser2NodeWorker.h:36
Find the variable name from a variable expression.
Definition: ExpressionVariableNameFinder.h:18
String represents an UTF8 encoded string.
Definition: String.h:31
Definition: CommonTools.h:24
An empty node, used when parsing failed/a syntax error was encountered and any other node could not m...
Definition: ExpressionParser2Node.h:423
The base node, from which all nodes in the tree of an expression inherits from.
Definition: ExpressionParser2Node.h:100
A function call node (either free function, object function or object behavior function)....
Definition: ExpressionParser2Node.h:371
An identifier node, usually representing an object or a variable with an optional function name or ch...
Definition: ExpressionParser2Node.h:204
gd::String identifierName
The object or variable name.
Definition: ExpressionParser2Node.h:219
A number node. For example: "123". Its type is always "number".
Definition: ExpressionParser2Node.h:161
The name of a function to call on an object or the behavior For example: "MyObject....
Definition: ExpressionParser2Node.h:321
An operator node. For example: "lhs + rhs".
Definition: ExpressionParser2Node.h:129
Definition: ExpressionParser2Node.h:115
A text node. For example: "Hello World". Its type is always "string".
Definition: ExpressionParser2Node.h:177
A unary operator node. For example: "-2".
Definition: ExpressionParser2Node.h:145
A direct accessor to a child variable. Example: MyChild in MyVariable.MyChild.
Definition: ExpressionParser2Node.h:282
A bracket accessor to a child variable. Example: ["MyChild"] (in MyVariable["MyChild"]).
Definition: ExpressionParser2Node.h:300
A variable, or object variable, with bracket accessor or at least 2 "dot" accessors.
Definition: ExpressionParser2Node.h:261