Exemplo n.º 1
0
        public override void Format(NodeExpression finalExpression, IQueryMapping mapping)
        {
            MethodCallNode methodCallNode = (MethodCallNode)binary.LeftNode;
            ConstantNode   methodCallArg  = (ConstantNode)binary.RightNode;

            if (!mapping.Mappings.TryGetValue(methodCallNode.MemberName, out var identifier))
            {
                identifier = methodCallNode.MemberName;
            }

            finalExpression.Append('(');
            finalExpression.Append(identifier);

            finalExpression.Append(' ');
            finalExpression.Append(OperationAsString(binary.Operation));
            finalExpression.Append(' ');

            var parameterName = methodCallNode.MemberName.Replace(".", "");
            var type          = methodCallArg.ParameterType;


            if (type != typeof(string) && (type.IsArray || typeof(IEnumerable).IsAssignableFrom(type)))
            {
                parameterName += "Collection";
            }

            finalExpression.Append(methodCallNode.Formatter($"@{parameterName}"));

            finalExpression.Parameters.Add(new NodeParameter(parameterName, methodCallArg.Value));
            finalExpression.Append(')');
        }
Exemplo n.º 2
0
        public void PanickingMethodCallWithTwoOutputsThatDoesNotPanicIntoAdd_Execute_CorrectValue()
        {
            using (FeatureToggleSupport.TemporarilyEnableFeature(RebarFeatureToggles.ParametersAndCalls))
            {
                string calleeName = "callee";
                NIType calleeType = DefineFunctionTypeWithTwoIntOuts(calleeName);
                CompilableDefinitionName calleeDefinitionName = CreateTestCompilableDefinitionName(calleeName);
                DfirRoot       calleeFunction      = calleeType.CreateFunctionFromSignature(calleeDefinitionName);
                DataAccessor   outputDataAccessor0 = DataAccessor.Create(calleeFunction.BlockDiagram, calleeFunction.DataItems[0], Direction.Input);
                DataAccessor   outputDataAccessor1 = DataAccessor.Create(calleeFunction.BlockDiagram, calleeFunction.DataItems[1], Direction.Input);
                FunctionalNode unwrap = new FunctionalNode(calleeFunction.BlockDiagram, Signatures.UnwrapOptionType);
                ConnectSomeOfIntegerToInputTerminal(unwrap.InputTerminals[0], 1);
                Wire.Create(calleeFunction.BlockDiagram, unwrap.OutputTerminals[0], outputDataAccessor0.Terminal, outputDataAccessor1.Terminal);
                DfirRoot       callerFunction = DfirRoot.Create();
                var            methodCall     = new MethodCallNode(callerFunction.BlockDiagram, calleeDefinitionName, calleeType);
                FunctionalNode add            = new FunctionalNode(callerFunction.BlockDiagram, Signatures.DefinePureBinaryFunction("Add", NITypes.Int32, NITypes.Int32));
                Wire.Create(callerFunction.BlockDiagram, methodCall.OutputTerminals[0], add.InputTerminals[0]);
                Wire.Create(callerFunction.BlockDiagram, methodCall.OutputTerminals[1], add.InputTerminals[1]);
                FunctionalNode inspect = ConnectInspectToOutputTerminal(add.OutputTerminals[2]);

                TestExecutionInstance executionInstance = CompileAndExecuteFunction(callerFunction, calleeFunction);

                byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
                AssertByteArrayIsInt32(inspectValue, 2);
            }
        }
Exemplo n.º 3
0
        private void Visit(AssignNode node)
        {
            if (node.LValue.Expression is IndexNode)
            {
                var indexNode = node.LValue.Expression as IndexNode;

                var where = indexNode.Where;
                var args = new List <BasicNode>()
                {
                    indexNode.Index, node.Expression
                };

                var method = new MethodCallNode("Set", where, args);

                ReplaceNode(node.Parent, node.ChildIndex, method);

                Visit(indexNode.Where as dynamic);
                Visit(node.Expression as dynamic);
            }
            else
            {
                Visit(node.LValue as dynamic);

                Visit(node.Expression as dynamic);
            }
        }
Exemplo n.º 4
0
        private TypeDescriptor Visit(MethodCallNode node, Context context)
        {
            TypeDescriptor where = Visit(node.Where as dynamic, context);

            var whereType = where.Type as ClassType;

            if (whereType == null)
            {
                Log(string.Format("Невозможно вызвать метод {0}", node.MethodName), node);

                return(TypeDescriptor.Undefined);
            }

            List <TypeInfo> types = new List <TypeInfo>();

            foreach (dynamic item in node.Arguments)
            {
                var argType = Visit(item, context);

                types.Add(argType.Type);
            }

            var method = whereType.GetMethod(node.MethodName, types, !where.IsObject);

            if (method == null)
            {
                Log(string.Format("Метод {0} с данными аргументами не существует", node.MethodName), node);

                return(TypeDescriptor.Undefined);
            }

            return(new TypeDescriptor(false, method.Ret, true));
        }
Exemplo n.º 5
0
        public void VisitMethodCall(MocCommonMethodCall callStatic)
        {
            var methodCallDfir = new MethodCallNode(
                _currentDiagram,
                callStatic.SelectedMethodCallTarget.AssociatedEnvoy.GetCompilableDefinitionName(),
                callStatic.Signature);

            _map.AddMapping(callStatic, methodCallDfir);
            _map.MapTerminalsInOrder(callStatic, methodCallDfir);
        }
        public override void OnBodyGUI()
        {
            base.OnBodyGUI();

            if (node == null)
            {
                node = (MethodCallNode)target;
            }

            showSearchOptions = EditorGUILayout.Foldout(showSearchOptions, "Chooser Options");
            if (showSearchOptions)
            {
                hideUnityClasses = EditorGUILayout.Toggle("Hide Unity classes", hideUnityClasses);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("Search");
                searchString = EditorGUILayout.TextField(searchString);
                EditorGUILayout.EndHorizontal();
            }

            GUIContent label = (node.method.DeclaringType == null) ? new GUIContent("Select a type...") : new GUIContent(ObjectNames.NicifyVariableName(node.method.DeclaringType.Name));

            if (EditorGUILayout.DropdownButton(label, FocusType.Keyboard))
            {
                ShowTypeSelectMenu();
            }

            if (node.method.DeclaringType == null)
            {
                return;
            }

            label = (node.method.Method == null) ? new GUIContent("Select a method...") : new GUIContent(node.method.Method.Name);
            if (EditorGUILayout.DropdownButton(label, FocusType.Keyboard))
            {
                ShowMethodSelectMenu();
            }

            if (node.method.Method == null)
            {
                return;
            }

            //DrawInstanceDynamicPorts();

            if (node.methodArgs == null)
            {
                return;
            }

            //DrawParameterSection();
        }
Exemplo n.º 7
0
        //private TypeInfo Visit(PlusNode node)
        //{
        //    return BinaryOperator(node, "Plus");
        //}
        //private TypeInfo Visit(MinusNode node)
        //{
        //    return BinaryOperator(node, "Minus");
        //}
        //private TypeInfo Visit(MultNode node)
        //{
        //    return BinaryOperator(node, "Mul");
        //}
        //private TypeInfo Visit(DivNode node)
        //{
        //    return BinaryOperator(node, "Div");
        //}
        //private TypeInfo Visit(ModNode node)
        //{
        //    return BinaryOperator(node, "Mod");
        //}
        //private TypeInfo Visit(EqualNode node)
        //{
        //    return BinaryOperator(node, "Equals");
        //}
        //private TypeInfo Visit(NotEqualNode node)
        //{
        //    return BinaryOperator(node, "NotEquals");
        //}
        private void Visit(IndexNode node)
        {
            var where = node.Where;
            var args = new List <BasicNode>()
            {
                node.Index
            };

            var method = new MethodCallNode("Get", where, args);

            ReplaceNode(node.Parent, node.ChildIndex, method);

            Visit(where as dynamic);
            Visit(node.Index as dynamic);
        }
Exemplo n.º 8
0
        public void ParseMethodWithException()
        {
            Expression <Func <int> > f = () => ThrowException();
            var node = NaturalExpressionParser.Parse(f.Body);

            var expected = new MethodCallNode
            {
                Container = new ConstantNode {
                    Text = "PowerAssertTests.ParserTest"
                },
                MemberName  = "ThrowException",
                MemberValue = @"DivideByZeroException: Attempted to divide by zero.",
            };

            Assert.AreEqual(expected, node);
        }
 public bool VisitMethodCallNode(MethodCallNode methodCallNode)
 {
     VisitFunctionSignatureNode(methodCallNode, methodCallNode.Signature);
     if (!RebarFeatureToggles.IsParametersAndCallsEnabled)
     {
         methodCallNode.SetDfirMessage(Messages.FeatureNotEnabled);
     }
     if (methodCallNode.TargetName.IsEmpty)
     {
         methodCallNode.SetDfirMessage(new DfirMessage(
                                           MessageSeverity.Error,
                                           SemanticAnalysisMessageCategories.Connection,
                                           AllModelsOfComputationErrorMessages.NoValidMethodCallTarget));
     }
     return(true);
 }
Exemplo n.º 10
0
        private TypeDescriptor TryToOverload(BinaryOperator node,
                                             TypeDescriptor leftType, TypeDescriptor rightType, Context context)
        {
            if (!leftType.IsObject || !operatorMethodsName.ContainsKey(node.Text))
            {
                Log(
                    String.Format("Оператор {0} не может применяться для типов {1} и {2}",
                                  node.Text,
                                  leftType.Type,
                                  rightType.Type),
                    node);
                return(TypeDescriptor.Undefined);
            }

            var classType = leftType.Type as ClassType;

            var method = classType.GetMethod(
                operatorMethodsName[node.Text],
                new List <TypeInfo>()
            {
                rightType.Type
            },
                false);

            if (method == null)
            {
                Log(
                    String.Format("Оператор {0} не может применяться для типов {1} и {2}",
                                  node.Text,
                                  leftType.Type,
                                  rightType.Type),
                    node);
                return(TypeDescriptor.Undefined);
            }

            var methodCallNode = new MethodCallNode(
                method.Name,
                node.LeftOperand,
                new List <BasicNode>()
            {
                node.RightOperand
            });

            ReplaceNode(node.Parent as CommonTree, node.ChildIndex, methodCallNode);

            return(new TypeDescriptor(false, method.Ret, true));
        }
Exemplo n.º 11
0
        public void PanickingMethodCallWithNoParametersThatDoesNotPanic_Execute_RuntimeDoesNotRegisterPanic()
        {
            using (FeatureToggleSupport.TemporarilyEnableFeature(RebarFeatureToggles.ParametersAndCalls))
            {
                string calleeName = "callee";
                NIType calleeType = calleeName.DefineMethodType().CreateType();
                CompilableDefinitionName calleeDefinitionName = CreateTestCompilableDefinitionName(calleeName);
                DfirRoot calleeFunction = calleeType.CreateFunctionFromSignature(calleeDefinitionName);
                CreateNonPanickingUnwrapOption(calleeFunction.BlockDiagram);
                DfirRoot callerFunction = DfirRoot.Create();
                var      methodCall     = new MethodCallNode(callerFunction.BlockDiagram, calleeDefinitionName, calleeType);

                TestExecutionInstance executionInstance = CompileAndExecuteFunction(callerFunction, calleeFunction);

                Assert.IsFalse(executionInstance.RuntimeServices.PanicOccurred);
            }
        }
Exemplo n.º 12
0
        public void ParseMethodWithException()
        {
            Expression <Func <int> > f = () => ThrowException();
            var p    = new ExpressionParser(f.Body);
            var node = p.Parse();

            var expected = new MethodCallNode
            {
                Container = new ConstantNode {
                    Text = "PowerAssertTests.ParserTest"
                },
                MemberName  = "ThrowException",
                MemberValue = @"(threw DivideByZeroException)",
            };

            Assert.AreEqual(expected, node);
        }
Exemplo n.º 13
0
        private TypeInfo Visit(MethodCallNode node, MethodBuilder builder, CodegenContext context)
        {
            ClassType type = Visit(node.Where as dynamic, builder, context) as ClassType;

            var argList = new List <TypeInfo>();

            foreach (dynamic item in node.Arguments)
            {
                var arg = Visit(item, builder, context);

                argList.Add(arg);
            }

            //TODO ПЛОХО
            var methodInfo = type.GetMethod(node.MethodName, argList, type is PackageType);

            builder.Call(methodInfo);

            return(methodInfo.Ret);
        }
        public Tuple <bool, MethodCallNode> CheckMethodCall(string value)
        {
            MethodCallNode methodCallNode = new MethodCallNode();

            methodCallNode.Name = value;
            var currentToken = NextToken();

            if (currentToken.Type == TokenType.OPENBRACKET)
            {
                Match(TokenType.IDENT);
                return(new Tuple <bool, MethodCallNode>(true, methodCallNode));
            }
            else if (currentToken.Type == TokenType.LIKE)
            {
                Rewind();
                return(new Tuple <bool, MethodCallNode>(false, null));
            }
            else
            {
                return(new Tuple <bool, MethodCallNode>(false, null));
            }
        }
Exemplo n.º 15
0
        public void ParseMethodAccess()
        {
            string s = "hello";
            Expression <Func <string> > f = () => s.Substring(1);
            var node = NaturalExpressionParser.Parse(f.Body);

            var expected = new MethodCallNode
            {
                Container = new ConstantNode {
                    Text = "s", Value = @"""hello"""
                },
                MemberName  = "Substring",
                MemberValue = @"""ello""",
                Parameters  = new List <Node>()
                {
                    new ConstantNode {
                        Text = "1"
                    }
                }
            };

            Assert.AreEqual(expected, node);
        }
Exemplo n.º 16
0
        public void PanickingMethodCallWithInputAndOutputThatPanicsIntoOutput_Execute_NoOutputValue()
        {
            using (FeatureToggleSupport.TemporarilyEnableFeature(RebarFeatureToggles.ParametersAndCalls))
            {
                string calleeName = "callee";
                NIType calleeType = DefineFunctionTypeWithOptionIntInAndIntOut(calleeName);
                CompilableDefinitionName calleeDefinitionName = CreateTestCompilableDefinitionName(calleeName);
                DfirRoot       calleeFunction     = calleeType.CreateFunctionFromSignature(calleeDefinitionName);
                DataAccessor   inputDataAccessor  = DataAccessor.Create(calleeFunction.BlockDiagram, calleeFunction.DataItems[0], Direction.Output);
                DataAccessor   outputDataAccessor = DataAccessor.Create(calleeFunction.BlockDiagram, calleeFunction.DataItems[1], Direction.Input);
                FunctionalNode unwrap             = new FunctionalNode(calleeFunction.BlockDiagram, Signatures.UnwrapOptionType);
                Wire.Create(calleeFunction.BlockDiagram, inputDataAccessor.Terminal, unwrap.InputTerminals[0]);
                Wire.Create(calleeFunction.BlockDiagram, unwrap.OutputTerminals[0], outputDataAccessor.Terminal);
                DfirRoot       callerFunction = DfirRoot.Create();
                var            methodCall     = new MethodCallNode(callerFunction.BlockDiagram, calleeDefinitionName, calleeType);
                FunctionalNode noneInteger    = CreateNoneOfOptionIntegerType(callerFunction.BlockDiagram);
                Wire.Create(callerFunction.BlockDiagram, noneInteger.OutputTerminals[0], methodCall.InputTerminals[0]);
                ConnectOutputToOutputTerminal(methodCall.OutputTerminals[0]);

                TestExecutionInstance executionInstance = CompileAndExecuteFunction(callerFunction, calleeFunction);

                AssertNoOutput(executionInstance);
            }
        }
Exemplo n.º 17
0
 internal override void Visit(MethodCallNode node)
 {
 }
 bool IDfirNodeVisitor <bool> .VisitMethodCallNode(MethodCallNode methodCallNode)
 {
     AutoBorrowNodeFacade.GetNodeFacade(methodCallNode).SetLifetimeInterruptedVariables(_lifetimeVariableAssociation);
     return(true);
 }
 bool IDfirNodeVisitor <bool> .VisitMethodCallNode(MethodCallNode methodCallNode)
 {
     VisitFunctionSignatureNode(methodCallNode, methodCallNode.Signature);
     return(true);
 }
Exemplo n.º 20
0
        public static LLVMValueRef GetImportedSynchronousFunction(this FunctionModuleContext moduleContext, MethodCallNode methodCallNode)
        {
            string targetFunctionName = FunctionCompileHandler.FunctionLLVMName(methodCallNode.TargetName);

            return(moduleContext.GetImportedFunction(
                       FunctionNames.GetSynchronousFunctionName(targetFunctionName),
                       () => moduleContext.LLVMContext.TranslateFunctionType(methodCallNode.Signature)));
        }
Exemplo n.º 21
0
 bool IDfirNodeVisitor <bool> .VisitMethodCallNode(MethodCallNode methodCallNode)
 {
     methodCallNode.CreateFacadesForFunctionSignatureNode(methodCallNode.Signature);
     return(true);
 }
Exemplo n.º 22
0
        private void DecomposeMethodCall(MethodCallNode methodCallNode, bool isYielding, bool mayPanic)
        {
            NIType outputType;
            // TODO: try to use something like Unit or Void
            NIType emptyOutputType = NITypes.Boolean;

            switch (methodCallNode.OutputTerminals.Count)
            {
            case 0:
                outputType = emptyOutputType;
                break;

            case 1:
                outputType = methodCallNode.OutputTerminals[0].GetTrueVariable().Type;
                break;

            default:
                outputType = methodCallNode.OutputTerminals.Select(t => t.GetTrueVariable().Type).DefineTupleType();
                break;
            }

            AutoBorrowNodeFacade methodCallNodeFacade = AutoBorrowNodeFacade.GetNodeFacade(methodCallNode);
            AwaitNode            awaitNode            = null;

            if (isYielding)
            {
                CreateMethodCallPromise createMethodCallPromise       = new CreateMethodCallPromise(methodCallNode.ParentDiagram, methodCallNode.Signature, methodCallNode.TargetName);
                AutoBorrowNodeFacade    createMethodCallPromiseFacade = AutoBorrowNodeFacade.GetNodeFacade(createMethodCallPromise);
                foreach (var terminalPair in methodCallNode.InputTerminals.Zip(createMethodCallPromise.InputTerminals))
                {
                    Terminal methodCallTerminal = terminalPair.Key, createMethodCallPromiseTerminal = terminalPair.Value;
                    methodCallTerminal.ConnectedTerminal.ConnectTo(createMethodCallPromiseTerminal);
                    createMethodCallPromiseFacade[createMethodCallPromiseTerminal] = methodCallNodeFacade[methodCallTerminal];
                }

                Terminal methodCallOutputTerminal = methodCallNode.OutputTerminals.FirstOrDefault();
                NIType   awaitOutputType          = mayPanic ? outputType.CreatePanicResult() : outputType;
                NIType   promiseType     = awaitOutputType.CreateMethodCallPromise();
                Terminal promiseTerminal = createMethodCallPromise.OutputTerminals[0];
                createMethodCallPromiseFacade[promiseTerminal] = new SimpleTerminalFacade(
                    promiseTerminal,
                    createMethodCallPromise.GetTypeVariableSet().CreateTypeVariableReferenceFromNIType(promiseType));

                awaitNode = ConnectNewNodeToOutputTerminalWithOutputFacade(createMethodCallPromise, diagram => new AwaitNode(diagram), awaitOutputType);
                VariableSet           variableSet            = awaitNode.GetVariableSet();
                TypeVariableReference outputTypeVariable     = awaitNode.OutputTerminal.GetTrueVariable().TypeVariableReference;
                TypeVariableReference pollResultTypeVariable = variableSet.TypeVariableSet.CreateReferenceToOptionType(outputTypeVariable);
                awaitNode.PollResultVariable = variableSet.CreateNewVariable(
                    diagramId: 0,
                    variableType: pollResultTypeVariable,
                    mutable: false);
            }

            Node outputNode = awaitNode;

            if (mayPanic)
            {
                Node panicOrContinueInput = awaitNode;
                if (!isYielding)
                {
                    // Create PanickingMethodCall as input to PanicOrContinue
                    throw new NotImplementedException("Calling non-yielding panicking methods not supported yet.");
                }
                outputNode = ConnectNewNodeToOutputTerminalWithOutputFacade(
                    panicOrContinueInput,
                    diagram => new PanicOrContinueNode(diagram),
                    outputType);
            }

            Terminal outputNodeTerminal = outputNode.OutputTerminals[0];

            switch (methodCallNode.OutputTerminals.Count)
            {
            case 0:
                // no method call output terminals; drop the result of the await
                InsertDropTransform.InsertDropForVariable(outputNode.ParentDiagram, LiveVariable.FromTerminal(outputNodeTerminal), _unificationResultFactory);
                break;

            case 1:
                ConnectOutputTerminal(methodCallNode.OutputTerminals[0], outputNodeTerminal);
                break;

            default:
            {
                // for >1 method call output terminals, decompose the tuple result of the await and match each
                // decomposed terminal to a method call terminal
                DecomposeTupleNode decomposeTupleNode = InsertDropTransform.InsertDecompositionForTupleVariable(
                    methodCallNode.ParentDiagram,
                    LiveVariable.FromTerminal(outputNodeTerminal),
                    _unificationResultFactory);
                foreach (var pair in methodCallNode.OutputTerminals.Zip(decomposeTupleNode.OutputTerminals))
                {
                    Terminal methodCallTerminal = pair.Key, decomposeTupleTerminal = pair.Value;
                    ConnectOutputTerminal(methodCallTerminal, decomposeTupleTerminal);
                }
                break;
            }
            }

            methodCallNode.RemoveFromGraph();
        }
Exemplo n.º 23
0
        //implementation with List and Operator Stack convert infix espression (5 + 3 * 2 - 1) to postfix expression and then calculate value ( 10 )
        //first convert infix to postfix expression and save in list (5 + 3 * 2 - 1 => 5 3 2 * 1 - +)
        //5 => to List ( 5 )
        //+ => to Operator Stack ( + )
        //3 => to List ( 5, 3 )
        //* => to Operator Stack ( +, * )
        //2 => to List ( 5, 3, 2 )
        //- => lower precedence than * on Stack => to List ( 5, 3, 2, * ) => Operator Stack ( +, - )
        //1 => to List ( 5, 3, 2, *, 1 )
        //pop Operator Stack ( +, - ) => to List ( 5, 3, 2, *, 1, -, + )
        //second calculate the result out of the genenerated list with the postfix expression with a Stack
        //5 => Stack ( 5 )
        //3 => Stack ( 5, 3 )
        //2 => Stack ( 5, 3, 2 )
        //* => 2 from Stack 3 from Stack change operators ( 5 ) => calculate 3 * 2 = 6 => Stack ( 5, 6 )
        //1 => Stack ( 5, 6, 1 )
        //- => 1 from Stack 6 from Stack change operators ( 5 ) => calculate 6 - 1 = 5 => Stack ( 5, 5 )
        //+ => 5 from Stack 5 from Stack change operators ( ) => calculate 5 + 5 => Stack ( 10 )
        public List <AbstractSyntaxTreeNode> ConvertInfixToPostfix(List <AbstractSyntaxTreeNode> postfixList)
        {
            List <AbstractSyntaxTreeNode>  returnList    = new List <AbstractSyntaxTreeNode>();
            Stack <AbstractSyntaxTreeNode> operatorStack = new Stack <AbstractSyntaxTreeNode>();
            var            position            = 0;
            var            methodParameterMode = false;
            MethodCallNode methodCallNode      = null;

            for (int i = position; i < postfixList.Count; i++)
            {
                var item = postfixList[i];
                if (item is IntegerNode || item is DoubleNode || item is VariableNode ||
                    item is BooleanNode || item is StringNode || item is NullNode)
                {
                    if (methodParameterMode)
                    {
                    }
                    else
                    {
                        returnList.Add(item);
                    }
                }
                else if (item is OpenBracketNode)
                {
                    if (methodParameterMode)
                    {
                    }
                    else
                    {
                        i = ConvertInfixToPostfixBracket(i, postfixList, returnList);
                    }
                }
                else if (item is CloseBracketNode)
                {
                    methodParameterMode = false;
                }
                else if (item is OrNode || item is AndNode)
                {
                    while (operatorStack.Count > 0)
                    {
                        var abstractSyntaxTreeNode = operatorStack.Pop();
                        returnList.Add(abstractSyntaxTreeNode);
                    }
                    operatorStack.Push(item);
                }
                else if (item is GreaterThenNode || item is GreaterThenOrEqualNode ||
                         item is SmallerThenNode || item is SmallerThenOrEqualNode ||
                         item is EqualNode || item is UnEqualNode || item is IsNode || item is LikeNode)
                {
                    if (operatorStack.Count() > 0 && (operatorStack.Peek() is MulNode ||
                                                      operatorStack.Peek() is DivNode ||
                                                      operatorStack.Peek() is ModuloNode))
                    {
                        AbstractSyntaxTreeNode node = operatorStack.Pop();
                        returnList.Add(node);
                    }
                    else if (operatorStack.Count() > 0 && (operatorStack.Peek() is AddNode ||
                                                           operatorStack.Peek() is SubNode))
                    {
                        AbstractSyntaxTreeNode node = operatorStack.Pop();
                        returnList.Add(node);
                    }
                    operatorStack.Push(item);
                }
                else if (item is AddNode || item is SubNode)
                {
                    if (operatorStack.Count() > 0 && (operatorStack.Peek() is MulNode ||
                                                      operatorStack.Peek() is DivNode ||
                                                      operatorStack.Peek() is ModuloNode))
                    {
                        AbstractSyntaxTreeNode node = operatorStack.Pop();
                        returnList.Add(node);
                    }
                    operatorStack.Push(item);
                }
                else if (item is MulNode || item is DivNode || item is ModuloNode)
                {
                    operatorStack.Push(item);
                }
                else if (item is SetNode || item is ThenNode || item is ElseNode)
                {
                    if (postfixList[i + 1] is MethodCallNode)
                    {
                        methodCallNode = (MethodCallNode)postfixList[i + 1];
                        i = ConvertMethodInfixToPostfixBracket(i + 1, postfixList, methodCallNode);
                        returnList.Add(item);
                        returnList.Add(methodCallNode);
                    }
                    else
                    {
                        operatorStack.Push(item);
                    }
                }
                else if (item is MethodCallNode)
                {
                    methodCallNode = (MethodCallNode)item;
                    i = ConvertMethodInfixToPostfixBracket(i, postfixList, methodCallNode);
                    returnList.Add(methodCallNode);
                }
                position++;
            }
            while (operatorStack.Count > 0)
            {
                var abstractSyntaxTreeNode = operatorStack.Pop();
                returnList.Add(abstractSyntaxTreeNode);
            }
            return(returnList);
        }
Exemplo n.º 24
0
        public int ConvertInfixToPostfixBracket(int position,
                                                List <AbstractSyntaxTreeNode> postfixList, List <AbstractSyntaxTreeNode> returnList)
        {
            Stack <AbstractSyntaxTreeNode> operatorStack = new Stack <AbstractSyntaxTreeNode>();
            int            i = 0;
            var            methodParameterMode = false;
            MethodCallNode methodCallNode      = null;

            for (i = position + 1; i < postfixList.Count; i++)
            {
                var item = postfixList[i];
                if (item is CloseBracketNode)
                {
                    break;
                }
                if (item is IntegerNode || item is DoubleNode || item is VariableNode ||
                    item is FieldNode || item is CollectionNode || item is ObjectNode ||
                    item is BooleanNode || item is StringNode)
                {
                    if (methodParameterMode)
                    {
                    }
                    else
                    {
                        returnList.Add(item);
                    }
                }
                else if (item is UpperNode || item is LowerNode || item is LengthNode ||
                         item is TrimNode || item is LeftTrimNode || item is RightTrimNode)
                {
                    returnList.Add(item);
                }
                else if (item is OpenBracketNode)
                {
                    if (methodParameterMode)
                    {
                    }
                    else
                    {
                        i = ConvertInfixToPostfixBracket(i, postfixList, returnList);
                    }
                }
                else if (item is OrNode || item is AndNode)
                {
                    while (operatorStack.Count > 0)
                    {
                        var abstractSyntaxTreeNode = operatorStack.Pop();
                        returnList.Add(abstractSyntaxTreeNode);
                    }
                    operatorStack.Push(item);
                }
                else if (item is GreaterThenNode || item is GreaterThenOrEqualNode ||
                         item is SmallerThenNode || item is SmallerThenOrEqualNode ||
                         item is EqualNode || item is UnEqualNode)
                {
                    if (operatorStack.Count() > 0 && (operatorStack.Peek() is MulNode || operatorStack.Peek() is DivNode ||
                                                      operatorStack.Peek() is ModuloNode))
                    {
                        AbstractSyntaxTreeNode node = operatorStack.Pop();
                        returnList.Add(node);
                    }
                    if (operatorStack.Count() > 0 && (operatorStack.Peek() is AddNode || operatorStack.Peek() is SubNode))
                    {
                        AbstractSyntaxTreeNode node = operatorStack.Pop();
                        returnList.Add(node);
                    }
                    operatorStack.Push(item);
                }
                else if (item is AddNode || item is SubNode)
                {
                    if (operatorStack.Count() > 0 && (operatorStack.Peek() is MulNode || operatorStack.Peek() is DivNode ||
                                                      operatorStack.Peek() is ModuloNode))
                    {
                        AbstractSyntaxTreeNode node = operatorStack.Pop();
                        returnList.Add(node);
                    }
                    operatorStack.Push(item);
                }
                else if (item is MulNode || item is DivNode || item is ModuloNode)
                {
                    operatorStack.Push(item);
                }
                else if (item is MethodCallNode)
                {
                    methodParameterMode = true;
                    methodCallNode      = (MethodCallNode)item;
                    i = ConvertMethodInfixToPostfixBracket(i, postfixList, methodCallNode);
                    returnList.Add(methodCallNode);
                    methodParameterMode = false;
                }
                position++;
            }
            while (operatorStack.Count > 0)
            {
                var abstractSyntaxTreeNode = operatorStack.Pop();
                returnList.Add(abstractSyntaxTreeNode);
            }
            return(i);
        }