Esempio n. 1
0
        internal override string ToCode(out SnapshotNodeType type)
        {
            string code = string.Format("{0} = {1}", this.Caption, this.Text);

            type = SnapshotNodeType.CodeBlock;
            return(code);
        }
Esempio n. 2
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. 3
0
        /// Checks if the string in code block node is a literal or an identifier or has multiple lines of code.
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static SnapshotNodeType AnalyzeString(string code)
        {
            SnapshotNodeType type = SnapshotNodeType.None;

            if (!code.EndsWith(";"))
            {
                code += ";";
            }
            List <ProtoCore.AST.Node> n = new List <ProtoCore.AST.Node>();

            try
            {
                ProtoCore.Options options = new ProtoCore.Options();
                options.RootModulePathName = string.Empty;

                ProtoCore.Core core = new ProtoCore.Core(options);
                core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
                core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));
                core.IsParsingPreloadedAssembly = false;
                core.IsParsingCodeBlockNode     = true;
                core.ParsingMode = ProtoCore.ParseMode.AllowNonAssignment;

                System.IO.MemoryStream memstream       = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(code));
                ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(memstream);
                ProtoCore.DesignScriptParser.Parser  p = new ProtoCore.DesignScriptParser.Parser(s, core);

                p.Parse();
                ProtoCore.AST.AssociativeAST.CodeBlockNode codeBlockNode = p.root as ProtoCore.AST.AssociativeAST.CodeBlockNode;
                n = p.GetParsedASTList(codeBlockNode);
            }
            catch (Exception)
            {
                //if syntax return SnapshotNodeType as None
                return(SnapshotNodeType.CodeBlock);
            }

            if (n.Count > 1 || n.Count == 0)
            {
                type = SnapshotNodeType.CodeBlock;
            }
            else if (n[0] is ProtoCore.AST.AssociativeAST.BinaryExpressionNode)
            {
                type = SnapshotNodeType.CodeBlock;
            }
            else if (n[0] is ProtoCore.AST.AssociativeAST.IdentifierNode)
            {
                type = SnapshotNodeType.Identifier;
            }
            else if (n[0] is ProtoCore.AST.AssociativeAST.IntNode || n[0] is ProtoCore.AST.AssociativeAST.DoubleNode || n[0] is ProtoCore.AST.AssociativeAST.StringNode || n[0] is ProtoCore.AST.AssociativeAST.FunctionCallNode || n[0] is ProtoCore.AST.AssociativeAST.RangeExprNode)
            {
                type = SnapshotNodeType.Literal;
            }
            else
            {
                type = SnapshotNodeType.CodeBlock;
            }
            return(type);
        }
Esempio n. 4
0
 public SnapshotNode(uint id, SnapshotNodeType type, string content)
 {
     this.Id            = id;
     this.Type          = type;
     this.Content       = content;
     Assignments        = new List <AssignmentStatement>();
     InputList          = new List <Connection>();
     OutputList         = new List <Connection>();
     UndefinedVariables = new List <string>();
 }
Esempio n. 5
0
        internal override string ToCode(out SnapshotNodeType type)
        {
            string replicationGuideString = string.Empty;
            int    i = 0;

            foreach (uint slot in inputSlots)
            {
                List <int> tmp = new List <int>();
                int        j   = 0;

                foreach (int value in replicationGuides[i])
                {
                    tmp.Add(value);
                    j++;
                }
                replicationGuideString += SnapshotNode.CreateReplicationGuideText(tmp);

                // The delimiter for a group of replication guides is'%'
                // Put all these characters in a definition structure or file
                replicationGuideString += GraphToDSCompiler.Constants.ReplicationGuideDelimiter;
                i++;
            }
            string assemblyPath = graphController.MapAssemblyPath(this.Assembly);

            // only external library need to convert the assembly path
            if (this.Assembly != assemblyPath)
            {
                assemblyPath = GraphUtilities.ConvertAbsoluteToRelative(assemblyPath);
            }

            if (this.MemberType == LibraryItem.MemberType.InstanceMethod || this.MemberType == LibraryItem.MemberType.InstanceProperty)
            {
                type = SnapshotNodeType.Method;
                string tempArgumentTypes = this.ArgumentTypes;
                // there is additional slot[0] with name "this" and type "this"
                // the "this" type need to be converted to proper class name(first part of the qualifiedName)
                //
                if (this.QualifiedName.Contains('.'))
                {
                    string className = this.QualifiedName.Substring(0, this.QualifiedName.IndexOf('.'));
                    tempArgumentTypes = tempArgumentTypes.Replace("this", className);
                }

                return(string.Format("{0};{1};{2};{3};{4}", assemblyPath, this.Caption, tempArgumentTypes, this.Text, replicationGuideString));
            }
            else
            {
                type = SnapshotNodeType.Function;
                return(string.Format("{0};{1};{2};{3};{4}", assemblyPath, this.QualifiedName, this.ArgumentTypes, this.Text, replicationGuideString));
            }
        }
Esempio n. 6
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 string ToCode(out SnapshotNodeType type)
        {
            string leftHandSideAssignment = this.outputLines.variable;

            if (Utilities.IsTempVariable(leftHandSideAssignment))
            {
                type = SnapshotNodeType.CodeBlock;
                return(string.Format("{0} = {1}", leftHandSideAssignment, this.Caption));
            }
            else
            {
                type = SnapshotNodeType.Identifier;
                return(string.Format("{0}", this.Caption));
            }
        }
Esempio n. 8
0
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("------------------------------------------------\n");
            builder.Append(string.Format("Node Id: 0x{0} ({1})\n", nodeId.ToString("x8"), nodeType.ToString()));
            builder.Append(string.Format("Name: {0}\nCaption: {1}\n", this.Text, this.Caption));

            SnapshotNodeType snapshotNodeType = SnapshotNodeType.None;

            builder.Append(string.Format("Code representation: {0}\n", this.ToCode(out snapshotNodeType)));
            builder.Append(string.Format("Snapshot node type: {0}\n", snapshotNodeType.ToString()));

            if (inputSlots.Count > 0)
            {
                builder.Append("Input slots: ");
                foreach (uint slotId in inputSlots)
                {
                    builder.Append(string.Format("0x{0} ", slotId.ToString("x8")));
                }
                builder.Append("\n");
            }
            else
            {
                builder.Append("Input slots: <none>\n");
            }

            if (outputSlots.Count > 0)
            {
                builder.Append("Output slots: ");
                foreach (uint slotId in outputSlots)
                {
                    builder.Append(string.Format("0x{0} ", slotId.ToString("x8")));
                }
                builder.Append("\n");
            }
            else
            {
                builder.Append("Output slots: <none>\n");
            }

            builder.Append(string.Format("Position: {0}, {1}\n", nodePosition.X, nodePosition.Y));
            builder.Append(string.Format("Dimension: {0}, {1}\n", nodeDimension.Width, nodeDimension.Height));
            builder.Append(string.Format("Selected: {0}\n", this.Selected));
            return(builder.ToString());
        }
        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. 10
0
 internal override string ToCode(out SnapshotNodeType type)
 {
     string code = string.Format("{0} = {1}", this.Caption, this.Text);
     type = SnapshotNodeType.CodeBlock;
     return code;
 }
Esempio n. 11
0
 internal override string ToCode(out SnapshotNodeType type)
 {
     type = GraphUtilities.AnalyzeString(this.compilableText);
     int[] lineNumbers = this.GetAllLinesHavingInputConnection().Distinct().ToArray();
     return Utilities.DiscardTemporaryVariableAssignment(this.compilableText, lineNumbers);
 }
Esempio n. 12
0
 internal override string ToCode(out SnapshotNodeType type)
 {
     throw new NotImplementedException("Render node should not implement ToCode()");
 }
Esempio n. 13
0
 internal abstract string ToCode(out SnapshotNodeType type);
Esempio n. 14
0
 public SnapshotNode(uint id, SnapshotNodeType type, string content)
 {
     this.Id = id;
     this.Type = type;
     this.Content = content;
     Assignments = new List<AssignmentStatement>();
     InputList = new List<Connection>();
     OutputList = new List<Connection>();
     UndefinedVariables = new List<string>();
 }
Esempio n. 15
0
 internal abstract string ToCode(out SnapshotNodeType type);
Esempio n. 16
0
        public string GetVarName(uint uid, int index, SnapshotNodeType type)
        {
            Validity.Assert(type == SnapshotNodeType.CodeBlock);

            // The graph would have already been rewritten (split) for codeblock nodes
            Dictionary<int, uint> indexUIDMap = new Dictionary<int, uint>();
            bool foundUID = codeBlockUIDMap.TryGetValue(uid, out indexUIDMap);
            Validity.Assert(foundUID);

            uint slotGUID = 0;
            bool foundNewUID = indexUIDMap.TryGetValue(index, out slotGUID);
            Validity.Assert(foundNewUID);

            Node node = graph.GetNode(slotGUID);
            Block block = node as Block;
            Validity.Assert(block != null);

            return block.LHS;

        }
Esempio n. 17
0
 internal override string ToCode(out SnapshotNodeType type)
 {
     throw new NotImplementedException("Render node should not implement ToCode()");
 }
Esempio n. 18
0
        internal override string ToCode(out SnapshotNodeType type)
        {
            string replicationGuideString = string.Empty;
            int i = 0;
            foreach (uint slot in inputSlots)
            {
                List<int> tmp = new List<int>();
                int j = 0;

                foreach (int value in replicationGuides[i])
                {
                    tmp.Add(value);
                    j++;
                }
                replicationGuideString += SnapshotNode.CreateReplicationGuideText(tmp);

                // The delimiter for a group of replication guides is'%'
                // Put all these characters in a definition structure or file
                replicationGuideString += GraphToDSCompiler.Constants.ReplicationGuideDelimiter;
                i++;
            }
            string assemblyPath = graphController.MapAssemblyPath(this.Assembly);
            // only external library need to convert the assembly path
            if (this.Assembly != assemblyPath)
                assemblyPath = GraphUtilities.ConvertAbsoluteToRelative(assemblyPath);

            if (this.MemberType == LibraryItem.MemberType.InstanceMethod || this.MemberType == LibraryItem.MemberType.InstanceProperty)
            {
                type = SnapshotNodeType.Method;
                string tempArgumentTypes = this.ArgumentTypes;
                // there is additional slot[0] with name "this" and type "this"
                // the "this" type need to be converted to proper class name(first part of the qualifiedName)
                //
                if (this.QualifiedName.Contains('.'))
                {
                    string className = this.QualifiedName.Substring(0, this.QualifiedName.IndexOf('.'));
                    tempArgumentTypes = tempArgumentTypes.Replace("this", className);
                }

                return (string.Format("{0};{1};{2};{3};{4}", assemblyPath, this.Caption, tempArgumentTypes, this.Text, replicationGuideString));
            }
            else
            {
                type = SnapshotNodeType.Function;
                return (string.Format("{0};{1};{2};{3};{4}", assemblyPath, this.QualifiedName, this.ArgumentTypes, this.Text, replicationGuideString));
            }
        }