Esempio n. 1
0
        internal override ErrorType ValidateInputString(out string error)
        {
            error = string.Empty;
            List <string>    errors = new List <string>();
            SnapshotNodeType type   = SnapshotNodeType.None;

            type = GraphUtilities.AnalyzeString(this.Text);
            if (type != SnapshotNodeType.Literal)
            {
                errors.Add("Invalid value.");
            }

            type = GraphUtilities.AnalyzeString(this.Caption);
            if (type != SnapshotNodeType.Identifier)
            {
                errors.Add("Invalid variable name.");
            }

            for (int i = 0; i < errors.Count; i++)
            {
                error += errors[i];
                if (i != errors.Count - 1)
                {
                    error += "\n";
                }
            }

            if (error == string.Empty)
            {
                return(ErrorType.None);
            }
            return(ErrorType.Syntax);
        }
Esempio n. 2
0
        internal override ErrorType ValidateInputString(out string error)
        {
            error = string.Empty;
            SnapshotNodeType type = GraphUtilities.AnalyzeString(this.Text);

            if (type == SnapshotNodeType.Identifier)
            {
                return(ErrorType.None);
            }
            else
            {
                error = "Invalid variable name.";
                return(ErrorType.Syntax);
            }
        }
        internal override ErrorType ValidateInputString(out string error)
        {
            if (!this.graphController.FileLoadInProgress && !this.graphController.IsInUndoRedoCommand)
            {
                this.UpdateInternalData(false);
            }

            error = string.Empty;
            SnapshotNodeType type = GraphUtilities.AnalyzeString(this.Caption);

            if (type == SnapshotNodeType.Identifier)
            {
                return(ErrorType.None);
            }
            else
            {
                error = "Invalid variable name.";
                return(ErrorType.Syntax);
            }
        }
Esempio n. 4
0
        //
        // TODO Jun: Re-evaluate the topsort implementation
        //
        static void DFSVisit(Node node, Dictionary <Node, int> nodeStateMap, List <Node> list, AST statementList)
        {
            nodeStateMap.Add(node, VISITING);
            List <Node>            nodes   = node.GetChildren();
            Dictionary <int, Node> nodeDic = node.GetChildrenWithIndices();
            IEnumerable            iter    = nodes;
            int j = 0;

            foreach (Node nodeI in iter)
            {
                if (node is IdentNode && nodeI is LiteralNode)
                {
                    BuildIdentToLiteralStatement(node, nodeI, statementList);
                }
                else if (node is IdentNode && nodeI is IdentNode)
                {
                    BuildIdentToIdentStatement(node, nodeI, statementList);
                }
                else if (node is IdentNode && nodeI is Block)
                {
                    Block blocknode = (Block)nodeI;
                    if (GraphUtilities.AnalyzeString(blocknode.Name) == SnapshotNodeType.Literal)
                    {
                        LiteralNode literal = new LiteralNode(blocknode.content, nodeI.Guid);
                        BuildIdentToLiteralStatement(node, literal, statementList);
                    }
                    else
                    {
                        j = BuildIdentToCodeBlockIdentStatement(node, nodeI, nodes, statementList, j);
                    }
                }
                else if (node is Operator && nodeI is Block)
                {
                    j = BuildOperatorToBlockStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Func && nodeI is Block)
                {
                    j = BuildFuncToBlockStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Func && nodeI is IdentNode)
                {
                    j = BuildFuncToIdentStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is IdentNode && nodeI is Operator)
                {
                    BuildIdentToOperatorStatement(node, statementList, nodeI);
                }
                else if (node is Operator && nodeI is Operator)
                {
                    j = BuildOperatorToOperatorStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is IdentNode && nodeI is Func)
                {
                    BuildIdentToFuncStatement(node, nodeI, statementList);
                }
                else if (node is Func && nodeI is Func)
                {
                    j = BuildFuncToFuncStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Operator && nodeI is Func)
                {
                    j = BuildOperatorToOperatorStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if (node is Func && nodeI is Operator)
                {
                    j = BuildFuncToFuncStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if ((node is Operator && nodeI is ArrayNode) || (node is Operator && nodeI is LiteralNode))
                {
                    j = BuildOperatorToOperatorStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if ((node is Func && nodeI is ArrayNode) || (node is Func && nodeI is LiteralNode))
                {
                    j = BuildFuncToFuncStatement(node, nodeI, nodeDic, statementList, j);
                }
                else if ((node is Block && nodeI is Block))
                {
                    BuildBlockToBlockStatement(node, nodeI, statementList);
                }
                else if ((node is Block && nodeI is Func))
                {
                    BuildBlockToFuncStatement(node, nodeI, statementList);
                }
                else if ((node is Block && nodeI is Operator))
                {
                    BuildBlockToFuncStatement(node, nodeI, statementList);
                }
                else if ((node is Block && nodeI is IdentNode))
                {
                    BuildBlockToIdentStatement(node, nodeI, statementList);
                }
                /*Block to Operator*/
                else if (node is Block && nodeI is Operator)
                {
                    //BuildBlockToOperatorStatement(node, nodeI, statementList);
                }
                //else if ((node is Block && nodeI is Func))
                //{
                //    BuildBlockToBlockStatement(node, nodeI, statementList);
                //}
                else
                {
                    if (node is Operator)
                    {
                        if (nodes.IndexOf(nodeI, j) == 0)
                        {
                            Assignment a = (Assignment)statementList.GetNode(node.Guid);
                            ((BinExprNode)a.right).left = nodeI;
                            ++j;
                        }
                        else
                        {
                            Assignment a = (Assignment)statementList.GetNode(node.Guid);
                            ((BinExprNode)a.right).right = nodeI;
                        }
                    }
                    else if (node is Func)
                    {
                        Assignment   a = (Assignment)statementList.GetNode(node.Guid);
                        FunctionCall f = ((FunctionCall)a.right);
                        f.parameters[nodes.IndexOf(nodeI, j)] = nodeI;
                        j = 0;
                    }
                }

                if (IsNotVisited(nodeI, nodeStateMap))
                {
                    DFSVisit(nodeI, nodeStateMap, list, statementList);
                }
            }
            nodeStateMap[node] = VISITED;
            list.Add(node);
        }
        private void AddNodesToAST(List <SnapshotNode> nodesToAdd)
        {
            foreach (SnapshotNode node in nodesToAdd)
            {
                switch (node.Type)
                {
                case SnapshotNodeType.Identifier: gc.CreateIdentifierNode(node.Id, node.Content); break;

                case SnapshotNodeType.Literal:

                    // TODO Jun: This may have to be removed and just moved to the contion where CodeBlocks are processed
                    object parameter1  = null;
                    string caption1    = node.Content;
                    int    intResult1  = 0;
                    bool   boolResult1 = false;
                    double dblResult1  = 0;
                    if (Int32.TryParse(caption1, out intResult1))
                    {
                        parameter1 = intResult1;
                    }
                    else if (Double.TryParse(caption1, out dblResult1))
                    {
                        parameter1 = dblResult1;
                    }
                    else if (Boolean.TryParse(caption1, out boolResult1))
                    {
                        parameter1 = boolResult1;
                    }
                    else
                    {
                        parameter1 = caption1;
                    }
                    gc.CreateLiteralNode(node.Id, parameter1);
                    break;

                case SnapshotNodeType.Function:
                    string[] functionQualifers = node.Content.Split(';');
                    int      funcargs          = 0;
                    string[] argtypes          = functionQualifers[2].Split(',');
                    if (!string.IsNullOrEmpty(functionQualifers[2]))
                    {
                        funcargs = argtypes.Length;
                    }
                    switch (functionQualifers[1])
                    {
                    case "+":
                    case "-":
                    case "*":
                    case "/":
                    case "%":
                    case "==":
                    case "!=":
                    case ">=":
                    case ">":
                    case "<=":
                    case "<":
                    case "&&":
                    case "||":
                    case "&":
                    case "|":
                    case "^": if (functionQualifers.Length < 5)
                        {
                            gc.CreateOperatorNode(node.Id, functionQualifers[1], functionQualifers[3]);
                        }
                        else
                        {
                            gc.CreateOperatorNode(node.Id, functionQualifers[1], functionQualifers[3], functionQualifers[4]);
                        }
                        break;

                    // Cooresponding to DSS.Graph.Core/Resoueces/library.xml
                    case "Range.ByIntervals":
                        if (functionQualifers.Length < 5)
                        {
                            gc.CreateRangeNode(node.Id, functionQualifers[1], funcargs, 2, functionQualifers[3]);
                        }
                        else
                        {
                            gc.CreateRangeNode(node.Id, functionQualifers[1], funcargs, 2, functionQualifers[3], functionQualifers[4]);
                        } break;

                    case "Range.ByIncrementValue":
                        if (functionQualifers.Length < 5)
                        {
                            gc.CreateRangeNode(node.Id, functionQualifers[1], funcargs, 0, functionQualifers[3]);
                        }
                        else
                        {
                            gc.CreateRangeNode(node.Id, functionQualifers[1], funcargs, 0, functionQualifers[3], functionQualifers[4]);
                        } break;

                    case "Range.ByApproximateIncrementValue":
                        if (functionQualifers.Length < 5)
                        {
                            gc.CreateRangeNode(node.Id, functionQualifers[1], funcargs, 1, functionQualifers[3]);
                        }
                        else
                        {
                            gc.CreateRangeNode(node.Id, functionQualifers[1], funcargs, 1, functionQualifers[3], functionQualifers[4]);
                        } break;

                    case "Range":
                        if (functionQualifers.Length < 5)
                        {
                            gc.CreateRangeNode(node.Id, functionQualifers[1], funcargs, 1, functionQualifers[3]);
                        }
                        else
                        {
                            gc.CreateRangeNode(node.Id, functionQualifers[1], funcargs, 1, functionQualifers[3], functionQualifers[4]);
                        } break;

                    default: if (functionQualifers.Length < 5)
                        {
                            if (!(functionQualifers[0]).Equals("Built-in Functions"))
                            {
                                CreateImportNodeIfRequired(functionQualifers[0]);
                            }
                            gc.CreateFunctionNode(node.Id, functionQualifers[1], funcargs, functionQualifers[3]);
                        }
                        else
                        {
                            if (!(functionQualifers[0]).Equals("Built-in Functions"))
                            {
                                //if (functionQualifers[0].Contains(@":\"))
                                //    functionQualifers[0] = GraphUtilities.ConvertAbsoluteToRelative(functionQualifers[0]);
                                CreateImportNodeIfRequired(functionQualifers[0]);
                            }
                            gc.CreateFunctionNode(node.Id, functionQualifers[1], funcargs, functionQualifers[3], functionQualifers[4]);
                        } break;
                    }
                    break;

                case SnapshotNodeType.Method:
                    string[] methodQualifers = node.Content.Split(';');
                    int      args            = 0;
                    string[] methargtypes    = methodQualifers[2].Split(',');
                    if (!string.IsNullOrEmpty(methodQualifers[2]))
                    {
                        args = methargtypes.Length;
                    }
                    if (methodQualifers.Length < 5)
                    {
                        CreateImportNodeIfRequired(methodQualifers[0]);

                        //gc.CreateImportNode(importNodesMapping[methodQualifers[0]], methodQualifers[0]);
                        gc.CreateMethodNode(node.Id, methodQualifers[1], args, methodQualifers[3], true);
                    }
                    else
                    {
                        CreateImportNodeIfRequired(methodQualifers[0]);

                        gc.CreateMethodNode(node.Id, methodQualifers[1], args, methodQualifers[3], methodQualifers[4], true);
                    }
                    break;

                case SnapshotNodeType.Property: string[] propertyQualifers = node.Content.Split(';');
                    CreateImportNodeIfRequired(propertyQualifers[0]);

                    //gc.CreateImportNode(importNodesMapping[propertyQualifers[0]], propertyQualifers[0]);
                    gc.CreatePropertyNode(node.Id, propertyQualifers[1], propertyQualifers[2]); break;

                case SnapshotNodeType.CodeBlock:
                {
                    string caption = node.Content;
                    if (GraphUtilities.AnalyzeString(caption) == SnapshotNodeType.Literal)
                    {
                        object parameter  = null;
                        int    intResult  = 0;
                        bool   boolResult = false;
                        double dblResult  = 0;
                        if (Int32.TryParse(caption, out intResult))
                        {
                            parameter = intResult;
                        }
                        else if (Double.TryParse(caption, out dblResult))
                        {
                            parameter = dblResult;
                        }
                        else if (Boolean.TryParse(caption, out boolResult))
                        {
                            parameter = boolResult;
                        }
                        else
                        {
                            parameter = caption;
                        }
                        gc.CreateLiteralNode(node.Id, parameter);
                    }
                    else
                    {
                        // Aparajit: Temporarily importing all the imported libraries by default to be able to
                        // call these functions from within a CodeBlock node

                        GraphUtilities.ForEachImportNodes((string hash, string path) => CreateImportNodeIfRequired(path, hash));

                        gc.CreateCodeblockNode(node);
                    }
                } break;

                case SnapshotNodeType.Array: gc.CreateArrayNode(node.Id, node.Content); break;
                }
            }
        }