예제 #1
0
        public void ReproMAGN3603()
        {

            string code = @"a = 1 + (2 * 3);
                            b = (1 + 2) * 3;
                            c = 1 + 2 * 3;";

            ParseParam parseParam = new ParseParam(Guid.NewGuid(), code);
            Assert.IsTrue(GraphToDSCompiler.GraphUtilities.PreCompileCodeBlock(parseParam));
            Assert.IsTrue(parseParam.ParsedNodes != null && parseParam.ParsedNodes.Count() > 0);

            var parsedNode = parseParam.ParsedNodes.ElementAt(0);

            BinaryExpressionNode n = parsedNode as BinaryExpressionNode;
            FunctionCallNode funcCall = n.RightNode as FunctionCallNode;
            Assert.IsTrue(n != null && funcCall != null);
            IdentifierNode identNode = funcCall.Function as IdentifierNode;
            Assert.IsTrue(identNode != null && identNode.Value == "%add");
            var args = funcCall.FormalArguments;
            Assert.IsTrue(args.Count == 2);
            Assert.IsTrue(args[0] is IntNode);
            FunctionCallNode nestedFuncCall = args[1] as FunctionCallNode;
            Assert.IsTrue(nestedFuncCall != null && (nestedFuncCall.Function as IdentifierNode).Value == "%mul");

            parsedNode = parseParam.ParsedNodes.ElementAt(1);

            n = parsedNode as BinaryExpressionNode;
            funcCall = n.RightNode as FunctionCallNode;
            Assert.IsTrue(n != null && funcCall != null);
            identNode = funcCall.Function as IdentifierNode;
            Assert.IsTrue(identNode != null && identNode.Value == "%mul");
            args = funcCall.FormalArguments;
            Assert.IsTrue(args.Count == 2);
            Assert.IsTrue(args[1] is IntNode);
            nestedFuncCall = args[0] as FunctionCallNode;
            Assert.IsTrue(nestedFuncCall != null && (nestedFuncCall.Function as IdentifierNode).Value == "%add");

            parsedNode = parseParam.ParsedNodes.ElementAt(2);

            n = parsedNode as BinaryExpressionNode;
            funcCall = n.RightNode as FunctionCallNode;
            Assert.IsTrue(n != null && funcCall != null);
            identNode = funcCall.Function as IdentifierNode;
            Assert.IsTrue(identNode != null && identNode.Value == "%add");
            args = funcCall.FormalArguments;
            Assert.IsTrue(args.Count == 2);
            Assert.IsTrue(args[0] is IntNode);
            nestedFuncCall = args[1] as FunctionCallNode;
            Assert.IsTrue(nestedFuncCall != null && (nestedFuncCall.Function as IdentifierNode).Value == "%mul");
        }
예제 #2
0
        private void ProcessCode(ref string errorMessage, ref string warningMessage)
        {
            code = CodeBlockUtils.FormatUserText(code);
            codeStatements.Clear();

            if (string.IsNullOrEmpty(Code))
                previewVariable = null;

            try
            {
                ParseParam parseParam = new ParseParam(this.GUID, code);
                if (GraphToDSCompiler.GraphUtilities.PreCompileCodeBlock(parseParam))
                {
                    if (parseParam.ParsedNodes != null)
                    {
                        // Create an instance of statement for each code statement written by the user
                        foreach (var parsedNode in parseParam.ParsedNodes)
                        {
                            // Create a statement variable from the generated nodes
                            codeStatements.Add(Statement.CreateInstance(parsedNode));
                        }

                        SetPreviewVariable(parseParam.ParsedNodes);
                    }
                }

                if (parseParam.Errors != null && parseParam.Errors.Any())
                {
                    errorMessage = string.Join("\n", parseParam.Errors.Select(m => m.Message));
                    ProcessError();
                    CreateInputOutputPorts();
                    return;
                }

                if (parseParam.Warnings != null)
                {
                    // Unbound identifiers in CBN will have input slots.
                    // 
                    // To check function redefinition, we need to check other
                    // CBN to find out if it has been defined yet. Now just
                    // skip this warning.
                    var warnings = parseParam.Warnings.Where((w) =>
                    {
                        return w.ID != WarningID.kIdUnboundIdentifier
                            && w.ID != WarningID.kFunctionAlreadyDefined;
                    });

                    if (warnings.Any())
                    {
                        warningMessage = string.Join("\n", warnings.Select(m => m.Message));
                    }
                }

                if (parseParam.UnboundIdentifiers != null)
                    inputIdentifiers = new List<string>(parseParam.UnboundIdentifiers);
                else
                    inputIdentifiers.Clear();
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
                previewVariable = null;
                ProcessError();
                return;
            }

            // Set the input and output ports based on the statements
            CreateInputOutputPorts();
        }