6 #ifndef GDCORE_EXPRESSIONNODELOCATIONFINDER_H 
    7 #define GDCORE_EXPRESSIONNODELOCATIONFINDER_H 
   12 #include "GDCore/Events/Parsers/ExpressionParser2Node.h" 
   13 #include "GDCore/Events/Parsers/ExpressionParser2NodeWorker.h" 
   16 class ObjectsContainer;
 
   18 class ParameterMetadata;
 
   19 class ExpressionMetadata;
 
   36       : searchedPosition(searchedPosition_),
 
   38         parentNode(nullptr) {};
 
   46                                            size_t searchedPosition) {
 
   59                                                  size_t searchedPosition) {
 
   78     CheckSearchPositionInNode(node);
 
   79     node.expression->Visit(*
this);
 
   81   void OnVisitOperatorNode(OperatorNode& node)
 override {
 
   82     if (CheckSearchPositionInNode(node)) {
 
   83       node.leftHandSide->Visit(*
this);
 
   84       node.rightHandSide->Visit(*
this);
 
   87   void OnVisitUnaryOperatorNode(UnaryOperatorNode& node)
 override {
 
   88     CheckSearchPositionInNode(node);
 
   89     node.factor->Visit(*
this);
 
   91   void OnVisitNumberNode(NumberNode& node)
 override {
 
   92     CheckSearchPositionInNode(node);
 
   94   void OnVisitTextNode(TextNode& node)
 override {
 
   95     CheckSearchPositionInNode(node);
 
   97   void OnVisitVariableNode(VariableNode& node)
 override {
 
   98     if (CheckSearchPositionInNode(node)) {
 
   99       if (node.child) node.child->Visit(*
this);
 
  102   void OnVisitVariableAccessorNode(VariableAccessorNode& node)
 override {
 
  103     if (CheckSearchPositionInNode(node)) {
 
  104       if (node.child) node.child->Visit(*
this);
 
  107   void OnVisitVariableBracketAccessorNode(
 
  108       VariableBracketAccessorNode& node)
 override {
 
  109     if (CheckSearchPositionInNode(node)) {
 
  110       node.expression->Visit(*
this);
 
  111       if (node.child) node.child->Visit(*
this);
 
  114   void OnVisitIdentifierNode(IdentifierNode& node)
 override {
 
  115     CheckSearchPositionInNode(node);
 
  117   void OnVisitObjectFunctionNameNode(ObjectFunctionNameNode& node)
 override {
 
  118     CheckSearchPositionInNode(node);
 
  120   void OnVisitFunctionCallNode(FunctionCallNode& node)
 override {
 
  121     CheckSearchPositionInNode(node);
 
  122     for (
auto& parameter : node.parameters) {
 
  123       parameter->Visit(*
this);
 
  126   void OnVisitEmptyNode(EmptyNode& node)
 override {
 
  127     CheckSearchPositionInNode(node, 
true);
 
  131   bool CheckSearchPositionInNode(ExpressionNode& node, 
bool inclusive = 
false) {
 
  132     if (node.location.GetStartPosition() <= searchedPosition &&
 
  133         ((!inclusive && searchedPosition < node.location.GetEndPosition()) ||
 
  134          (inclusive && searchedPosition <= node.location.GetEndPosition()))) {
 
  135       parentNode = foundNode;
 
  143   size_t searchedPosition;
 
  144   ExpressionNode* foundNode;
 
  145   ExpressionNode* parentNode;
 
Find the deepest node at the specified location in an expression.
Definition: ExpressionNodeLocationFinder.h:30
 
static ExpressionNode * GetParentNodeAtPosition(gd::ExpressionNode &node, size_t searchedPosition)
Helper function to find the parent of the deepest node at the search position, if any.
Definition: ExpressionNodeLocationFinder.h:58
 
ExpressionNode * GetParentNode()
Return the parent of deepest node found at the search position, if any.
Definition: ExpressionNodeLocationFinder.h:74
 
ExpressionNode * GetNode()
Return the deepest node found at the search position, if any.
Definition: ExpressionNodeLocationFinder.h:68
 
ExpressionNodeLocationFinder(size_t searchedPosition_)
Initialize the finder to search at the specified position.
Definition: ExpressionNodeLocationFinder.h:35
 
static ExpressionNode * GetNodeAtPosition(gd::ExpressionNode &node, size_t searchedPosition)
Helper function to find the deepest node at the search position, if any.
Definition: ExpressionNodeLocationFinder.h:45
 
The interface for any worker class ("visitor" pattern) that want to interact with the nodes of a pars...
Definition: ExpressionParser2NodeWorker.h:36
 
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