6 #ifndef GDCORE_EXPRESSIONLEFTSIDETYPEFINDER_H
7 #define GDCORE_EXPRESSIONLEFTSIDETYPEFINDER_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/ProjectScopedContainers.h"
22 class ObjectsContainer;
24 class ParameterMetadata;
25 class ExpressionMetadata;
46 platform, projectScopedContainers);
47 node.Visit(typeFinder);
54 ExpressionLeftSideTypeFinder(
const gd::Platform &platform_,
56 : platform(platform_),
57 projectScopedContainers(projectScopedContainers_),
64 void OnVisitSubExpressionNode(SubExpressionNode& node)
override {
65 node.expression->Visit(*
this);
67 void OnVisitOperatorNode(OperatorNode& node)
override {
68 node.leftHandSide->Visit(*
this);
74 if (type ==
"unknown" || type ==
"number|string") {
75 node.rightHandSide->Visit(*
this);
78 void OnVisitUnaryOperatorNode(UnaryOperatorNode& node)
override {
79 node.factor->Visit(*
this);
81 void OnVisitVariableBracketAccessorNode(
82 VariableBracketAccessorNode& node)
override {
83 node.expression->Visit(*
this);
85 void OnVisitNumberNode(NumberNode& node)
override {
88 void OnVisitTextNode(TextNode& node)
override {
91 void OnVisitFunctionCallNode(FunctionCallNode& node)
override {
93 platform, projectScopedContainers.GetObjectsContainersList(), node);
94 if (gd::MetadataProvider::IsBadExpressionMetadata(metadata)) {
98 type = metadata.GetReturnType();
101 void OnVisitVariableNode(VariableNode& node)
override {
104 projectScopedContainers.MatchIdentifierWithName<
void>(node.name,
125 void OnVisitVariableAccessorNode(VariableAccessorNode& node)
override {
128 void OnVisitIdentifierNode(IdentifierNode& node)
override {
130 projectScopedContainers.MatchIdentifierWithName<
void>(node.identifierName,
133 if (projectScopedContainers.GetObjectsContainersList()
134 .HasObjectOrGroupWithVariableNamed(
135 node.identifierName, node.childIdentifierName)
136 == ObjectsContainersList::VariableExistence::DoesNotExist) {
142 projectScopedContainers.GetObjectsContainersList()
143 .GetTypeOfObjectOrGroupVariable(node.identifierName,
144 node.childIdentifierName);
145 ReadTypeFromVariable(variableType);
149 const auto& variable =
150 projectScopedContainers.GetVariablesContainersList().Get(
151 node.identifierName);
153 if (node.childIdentifierName.empty()) {
154 ReadTypeFromVariable(variable.GetType());
156 if (!variable.HasChild(node.childIdentifierName)) {
161 ReadTypeFromVariable(
162 variable.GetChild(node.childIdentifierName).GetType());
167 .GetPropertiesContainersList().Get(node.identifierName).second;
169 if (property.GetType() ==
"Number") {
171 }
else if (property.GetType() ==
"Boolean") {
180 const auto& parametersVectorsList = projectScopedContainers.GetParametersVectorsList();
181 const auto& parameter = gd::ParameterMetadataTools::Get(parametersVectorsList, node.identifierName);
182 const auto& valueTypeMetadata = parameter.GetValueTypeMetadata();
183 if (valueTypeMetadata.IsNumber()) {
185 }
else if (valueTypeMetadata.IsString()) {
187 }
else if (valueTypeMetadata.IsBoolean()) {
197 void OnVisitEmptyNode(EmptyNode& node)
override {
200 void OnVisitObjectFunctionNameNode(ObjectFunctionNameNode& node)
override {
205 void ReadTypeFromVariable(gd::Variable::Type variableType) {
206 if (variableType == gd::Variable::Number) {
208 }
else if (variableType == gd::Variable::String) {
Find the type of the node at the left side of operations.
Definition: ExpressionLeftSideTypeFinder.h:35
static const gd::String GetType(const gd::Platform &platform, const gd::ProjectScopedContainers &projectScopedContainers, gd::ExpressionNode &node)
Helper function to find the type of the node at the left side of operations.
Definition: ExpressionLeftSideTypeFinder.h:42
The interface for any worker class ("visitor" pattern) that want to interact with the nodes of a pars...
Definition: ExpressionParser2NodeWorker.h:36
Used to describe a property shown in a property grid.
Definition: NamedPropertyDescriptor.h:21
Holds references to variables, objects, properties and other containers.
Definition: ProjectScopedContainers.h:30
String represents an UTF8 encoded string.
Definition: String.h:31
Definition: CommonTools.h:24
The base node, from which all nodes in the tree of an expression inherits from.
Definition: ExpressionParser2Node.h:93