コード例 #1
0
        /// <summary>
        /// compile java script code to signal browser block
        /// </summary>
        /// <param name="sourceCode"></param>
        /// <returns></returns>
        public IBlockInfo Compile(string sourceCode)
        {
            //initialize main block
            BlockInfo     blockInfo      = new BlockInfo();
            StringBuilder stringBuilder  = new StringBuilder();
            bool          isStartFinding = false;

            for (int i = 0; i < sourceCode.Length; i++)
            {
                char currentChar = sourceCode[i];
                //don't need to calculate white spaces
                if (!isStartFinding && (currentChar == '\r' || currentChar == '\t' || currentChar == '\n' || currentChar == ' '))
                {
                    continue;
                }
                isStartFinding = true;
                stringBuilder.Append(currentChar);
                //if din chars == var then create a variable
                if (stringBuilder.Length == 3 && stringBuilder.ToString() == "var")
                {
                    i = VariableLine.GenerateVariable(i, ref sourceCode, blockInfo, this);
                    stringBuilder.Clear();
                    isStartFinding = false;
                    continue;
                }
            }
            return(blockInfo);
        }
コード例 #2
0
        public override bool Deserialize(IStorage storage)
        {
            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }

            try
            {
                base.Deserialize(storage);

                string variable = storage.ReadString(FieldCode.Variable);
                int    line     = storage.ReadInteger(FieldCode.Line);
                this.inputLines = new VariableLine(variable, line);

                variable         = storage.ReadString(FieldCode.Variable);
                line             = storage.ReadInteger(FieldCode.Line);
                this.outputLines = new VariableLine(variable, line);

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + "\n Identifier node deserialization failed.");
                return(false);
            }
        }
コード例 #3
0
        public void CreateOutputVariables(VariableLine outputVariable, List <MemberFunction> memberFunctions)
        {
            double rangeStart = Convert.ToDouble(outputVariable.Range[0]);
            double rangeEnd   = Convert.ToDouble(outputVariable.Range[1]);

            var variable = new Variable(outputVariable.VariableName, rangeStart, rangeEnd);

            foreach (var memberFunction in memberFunctions)
            {
                var       fuzzySet = new FuzzySet(memberFunction.SetName);
                IFunction function;
                switch (memberFunction.FunctionType)
                {
                case FunctionType.TriangleMF:
                {
                    function = new TriMF(Convert.ToDouble(memberFunction.FunctionPoints[0]),
                                         Convert.ToDouble(memberFunction.FunctionPoints[1]),
                                         Convert.ToDouble(memberFunction.FunctionPoints[2]));
                    break;
                }

                default:
                {
                    function = new TriMF(Convert.ToDouble(memberFunction.FunctionPoints[0]),
                                         Convert.ToDouble(memberFunction.FunctionPoints[1]),
                                         Convert.ToDouble(memberFunction.FunctionPoints[2]));
                    break;
                }
                }

                variable.AddFuzzySet(fuzzySet, function);
            }

            Output = variable;
        }
コード例 #4
0
        protected override void SwapAssignmentOnSlot(uint slotId)
        {
            // Swap inputLines adn outputLines
            VariableLine variableLine = this.inputLines;

            this.inputLines  = this.outputLines;
            this.outputLines = variableLine;

            // Update variable mapping
            RuntimeStates runtimeStates = graphController.GetRuntimeStates();

            runtimeStates.UpdateVariablesDefinedInNode(this, false);
        }
コード例 #5
0
        internal void EnsureInputLines(uint codeBlockNodeId, Dictionary <int, List <VariableLine> > expectedInputs)
        {
            // Ensure we do have a valid node corresponding to the ID.
            VisualNode node = controller.GetVisualNode(codeBlockNodeId);

            Assert.AreNotEqual(null, node);

            // Make sure it is of type code block node.
            Assert.AreEqual(NodeType.CodeBlock, node.VisualType);
            CodeBlockNode codeBlockNode = node as CodeBlockNode;

            Assert.AreNotEqual(null, codeBlockNode);

            // The caller expects no output lines to be generated.
            if (null == expectedInputs || (expectedInputs.Count <= 0))
            {
                Assert.AreEqual(null, codeBlockNode.InputLines);
                return;
            }

            Dictionary <int, List <VariableLine> > actualInputs = codeBlockNode.InputLines;

            Assert.AreNotEqual(null, actualInputs);
            Assert.AreEqual(expectedInputs.Count, actualInputs.Count);

            foreach (KeyValuePair <int, List <VariableLine> > expectedInput in expectedInputs)
            {
                int statementIndex = expectedInput.Key; // Statement index.
                Assert.AreEqual(true, actualInputs.Keys.Contains(statementIndex));

                // Ensure that we have the right number of actual input lines.
                List <VariableLine> actualInput = actualInputs[statementIndex];
                Assert.AreNotEqual(null, actualInput);
                Assert.AreEqual(expectedInput.Value.Count, actualInput.Count);

                // Ensure that each of the input lines match up to the expectation.
                int lineCount = expectedInput.Value.Count;
                for (int index = 0; index < lineCount; ++index)
                {
                    VariableLine expected = expectedInput.Value[index];
                    VariableLine actual   = actualInput[index];
                    Assert.AreEqual(expected.line, actual.line);

                    // If the expected variable isn't a temporary.
                    if (!string.IsNullOrEmpty(expected.variable))
                    {
                        Assert.AreEqual(expected.variable, actual.variable);
                    }
                }
            }
        }
コード例 #6
0
        private static VariableType GetVariableType(VariableLine isoLine)
        {
            switch (isoLine.Type)
            {
            case IsoLineType.VlVariable:
                return(VariableType.VL);

            case IsoLineType.ExkVariable:
                return(VariableType.ExK);

            default:
                throw new ArgumentException();
            }
        }
コード例 #7
0
        internal void EnsureOutputLines(uint codeBlockNodeId, List <VariableLine> expectedLines)
        {
            // Ensure we do have a valid node corresponding to the ID.
            VisualNode node = controller.GetVisualNode(codeBlockNodeId);

            Assert.AreNotEqual(null, node);

            // Make sure it is of type code block node.
            Assert.AreEqual(NodeType.CodeBlock, node.VisualType);
            CodeBlockNode codeBlockNode = node as CodeBlockNode;

            Assert.AreNotEqual(null, codeBlockNode);

            // The caller expects no output lines to be generated.
            if (null == expectedLines || (expectedLines.Count <= 0))
            {
                Assert.AreEqual(null, codeBlockNode.OutputLines);
                return;
            }

            List <VariableLine> actualLines = codeBlockNode.OutputLines;

            Assert.AreNotEqual(null, actualLines);
            Assert.AreEqual(expectedLines.Count, actualLines.Count);

            // Ensure that each of the output lines match up to the expectation.
            int lineCount = expectedLines.Count;

            for (int index = 0; index < lineCount; ++index)
            {
                VariableLine expected = expectedLines[index];
                VariableLine actual   = actualLines[index];
                Assert.AreEqual(expected.line, actual.line);

                // If the expected variable isn't a temporary.
                if (!string.IsNullOrEmpty(expected.variable))
                {
                    Assert.AreEqual(expected.variable, actual.variable);
                }
            }
        }
コード例 #8
0
        private void UpdateInternalData(bool calledFromConstructor)
        {
            if (false != calledFromConstructor)
            {
                string tempVariable = this.graphController.GetRuntimeStates().GenerateTempVariable(uint.MaxValue);
                this.inputLines  = new VariableLine(this.Caption, 0);
                this.outputLines = new VariableLine(tempVariable, 0);
            }
            else
            {
                // Fix: IDE-1899 Rename identifier node displays warning and clears preview value.
                // This method is called at the end of a node-edit operation. For identifier node
                // the user is allowed only to rename the Caption of the node, which can either be
                // in "inputLines" (e.g. "t1 = Var1") or the "outputLines" (e.g. "Var1 = t1"),
                // depending on the connection of the input slot. Here we figure out where the
                // "Caption" resides and update the variable name accordingly.
                //
                bool inputIsTemp  = Utilities.IsTempVariable(inputLines.variable);
                bool outputIsTemp = Utilities.IsTempVariable(outputLines.variable);
                if (!(inputIsTemp ^ outputIsTemp))
                {
                    throw new InvalidOperationException("Either input or output can/must be temp (BBC71AACEE95)!");
                }

                if (false == inputIsTemp) // "inputLines" has the "Caption".
                {
                    inputLines.variable = this.Caption;
                }
                else // "outputLines" has the "Caption".
                {
                    outputLines.variable = this.Caption;
                }

                // Update variable mapping
                RuntimeStates runtimeStates = graphController.GetRuntimeStates();
                runtimeStates.UpdateVariablesDefinedInNode(this, false);
            }
        }
コード例 #9
0
ファイル: GraphUtilities.cs プロジェクト: TheChosen0ne/Dynamo
        private static void GetOutputLines(string code, ProtoCore.Core core, HashSet<VariableLine> outputLines)
        {
            foreach (var astNode in core.AstNodeList)
            {
                var binaryExpr = astNode as ProtoCore.AST.AssociativeAST.BinaryExpressionNode;
                while (binaryExpr != null)
                {
                    var lhsVariable = binaryExpr.LeftNode as ProtoCore.AST.AssociativeAST.IdentifierNode;
                    if (lhsVariable != null)
                    {
                        var varlinePair = new VariableLine(lhsVariable.Name, lhsVariable.line);
                        outputLines.Add(varlinePair);
                    }
                    else
                    {
                        var lhs = binaryExpr.LeftNode as ProtoCore.AST.AssociativeAST.IdentifierListNode;
                        Validity.Assert(lhs != null);

                        // TODO: Get identifier list name by DFS Traversing the node
                        /*List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
                        astList.Add(lhs as ProtoCore.AST.AssociativeAST.AssociativeNode);
                        ProtoCore.SourceGen codegen = new ProtoCore.SourceGen(astList);
                        codegen.GenerateCode();*/

                        string stmt = ProtoCore.Utils.ParserUtils.ExtractStatementFromCode(code, lhs);
                        int equalIndex = stmt.IndexOf('=');
                        string identListName = ProtoCore.Utils.ParserUtils.GetLHSatAssignment(stmt, equalIndex)[0]; // codegen.Code;

                        string varname = identListName.Split('.')[0];
                        var varlinePair = new VariableLine(varname, lhs.line);
                        //var varlinePair = new VariableLine(identListName, lhs.line);
                        outputLines.Add(varlinePair);
                    }

                    // deal with the case of continuous assingment
                    binaryExpr = binaryExpr.RightNode as ProtoCore.AST.AssociativeAST.BinaryExpressionNode;
                }
            }
        }
コード例 #10
0
ファイル: GraphUtilities.cs プロジェクト: TheChosen0ne/Dynamo
 private bool Equals(VariableLine variableLine)
 {
     return (this.variable == variableLine.variable) && (this.line == variableLine.line);
 }
コード例 #11
0
 /// <summary>
 /// Returns the variable of the line
 /// </summary>
 /// <param name="lineParameters">line in array</param>
 /// <param name="variable">variable to return from the array</param>
 /// <returns></returns>
 private string GetVariable(string[] lineParameters, VariableLine variable)
 {
     return(lineParameters[Convert.ToInt32(variable)]);
 }
コード例 #12
0
        public RuleCreateLine(Dictionary <VariableLine, List <MemberFunction> > variablesFunctions, VariableLine outputVariable, List <MemberFunction> outputFunctions)
        {
            this.Orientation = Orientation.Horizontal;

            variablesListBoxes    = new Dictionary <VariableLine, ListBox>();
            outputVariableListBox = new Dictionary <VariableLine, ListBox>();

            listBoxOperator             = new ListBox();
            listBoxOperator.ItemsSource = new List <string> {
                "AND", "OR"
            };
            this.Children.Add(listBoxOperator);

            foreach (var variableFunction in variablesFunctions)
            {
                var label1 = new Label();
                label1.Content = variableFunction.Key.VariableName;
                var listBoxInput = new ListBox();
                listBoxInput.Width             = 120;
                listBoxInput.Height            = 80;
                listBoxInput.ItemsSource       = variableFunction.Value;
                listBoxInput.DisplayMemberPath = "SetName";

                this.Children.Add(label1);
                this.Children.Add(listBoxInput);
                variablesListBoxes.Add(variableFunction.Key, listBoxInput);
            }

            var label2 = new Label();

            label2.Content = outputVariable.VariableName;
            var listBoxOutput = new ListBox();

            listBoxOutput.Width             = 120;
            listBoxOutput.Height            = 80;
            listBoxOutput.ItemsSource       = outputFunctions;
            listBoxOutput.DisplayMemberPath = "SetName";

            this.Children.Add(label2);
            this.Children.Add(listBoxOutput);
            outputVariableListBox.Add(outputVariable, listBoxOutput);
        }