Beispiel #1
0
        public DynamoUnitConvert()
        {
            try
            {
                QuantityConversionSource   = DynamoUnits.Utilities.GetAllQuantities();
                SelectedQuantityConversion = QuantityConversionSource.ToList().Find(q => q.Name == defaultSelectedQuantity);
            }
            catch
            {
                //continue with empty node and warning
                Warning(Properties.Resources.SchemaLoadWarning + Utilities.SchemaDirectory, true);
            }

            AssociativeNode defaultNode = new DoubleNode(0.0);

            InPorts.Add(new PortModel(PortType.Input, this, new PortData("", Resources.CovertUnitInputTooltip, defaultNode)));
            OutPorts.Add(new PortModel(PortType.Output, this, new PortData("", Resources.CovertUnitOutputTooltip)));

            ShouldDisplayPreviewCore = true;
            RegisterAllPorts();
        }
Beispiel #2
0
        private DynamoUnitConvert(IEnumerable <PortModel> inPorts, IEnumerable <PortModel> outPorts) : base(inPorts, outPorts)
        {
            try
            {
                QuantityConversionSource = DynamoUnits.Utilities.GetAllQuantities();
            }
            catch
            {
                //continue with empty node and warning
                Warning(Properties.Resources.SchemaLoadWarning + Utilities.SchemaDirectory, true);
            }

            AssociativeNode defaultNode = new DoubleNode(0.0);

            if (inPorts != null)
            {
                inPorts.First().DefaultValue = defaultNode;
            }

            ShouldDisplayPreviewCore = true;
        }
        public void TestDoubleValueInDifferentCulture()
        {
            var frCulture = CultureInfo.CreateSpecificCulture("fr-FR");
            
            var currentCulture = Thread.CurrentThread.CurrentCulture;
            var currentUICulture = Thread.CurrentThread.CurrentUICulture;

            Thread.CurrentThread.CurrentCulture = frCulture;
            Thread.CurrentThread.CurrentUICulture = frCulture;

            // manually verified s="1,234";
            double d = 1.234;
            string s = d.ToString();

            DoubleNode d1 = new DoubleNode(1.234);
            string s1 = d1.ToString();
            Assert.AreEqual(s1, "1.234");

            ProtoCore.AST.ImperativeAST.DoubleNode d2 = new ProtoCore.AST.ImperativeAST.DoubleNode(1.234);
            string s2 = d2.ToString();
            Assert.AreEqual(s2, "1.234");

            Thread.CurrentThread.CurrentCulture = currentCulture;
            Thread.CurrentThread.CurrentUICulture = currentUICulture;
        }
        public DynamoConvert()
        {           
            SelectedMetricConversion = ConversionMetricUnit.Length;  
            AssociativeNode defaultNode = new DoubleNode(0.0);
            InPorts.Add(new PortModel(PortType.Input, this, new PortData("", Properties.Resources.UnitNodeFromPortTooltip, defaultNode)));
            OutPorts.Add(new PortModel(PortType.Output, this, new PortData("", Properties.Resources.UnitNodeToPortToolTip)));

            ShouldDisplayPreviewCore = true;
            IsSelectionFromBoxEnabled = true;
            RegisterAllPorts();
        }
Beispiel #5
0
	void Associative_Number(out ProtoCore.AST.AssociativeAST.AssociativeNode node) {
		node = null; 
		int sign = 1;
		int line = ProtoCore.DSASM.Constants.kInvalidIndex; 
		int col = ProtoCore.DSASM.Constants.kInvalidIndex; 
		
		if (la.kind == 15) {
			Get();
			sign = -1; 
			line = t.line; 
			col = t.col; 
			
		}
		if (la.kind == 2) {
			Get();
			Int64 value;
			if (Int64.TryParse(t.val, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out value))
			{
			   node = new ProtoCore.AST.AssociativeAST.IntNode(value * sign);
			}
			else
			{
			   node = new ProtoCore.AST.AssociativeAST.NullNode();
			}
			
			if (ProtoCore.DSASM.Constants.kInvalidIndex == line
			   &&  ProtoCore.DSASM.Constants.kInvalidIndex == col)
			{
			   NodeUtils.SetNodeLocation(node, t);
			}
			else
			{
			   node.line = line; node.col = col;
			node.endLine = t.line; node.endCol = t.col;
			}
			
		} else if (la.kind == 3) {
			Get();
			double value;
			if (Double.TryParse(t.val, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out value))
			{
			   node = new ProtoCore.AST.AssociativeAST.DoubleNode(value * sign);
			}
			else
			{
			   node = new ProtoCore.AST.AssociativeAST.NullNode();
			}
			
			if (ProtoCore.DSASM.Constants.kInvalidIndex == line
			   &&  ProtoCore.DSASM.Constants.kInvalidIndex == col)
			{
			   NodeUtils.SetNodeLocation(node, t);
			}
			else
			{
			   node.line = line; node.col = col;
			}
			
		} else SynErr(98);
	}
        /// <summary>
        /// TODO: Deprecate
        /// Emit IntNode or DoubleNode
        /// </summary>
        /// <param name="node"></param>
        /// <param name="outnode"></param>
        private void EmitLiteralNode(LiteralNode node, out AssociativeNode outnode)
        {
            Validity.Assert(node != null);
            Validity.Assert(node.children.Count == 0);

            // Create temp identifier and assign it to the literal (IntNode or DoubleNode) to create a BinaryExpressionNode
            // Return the temp IdentifierNode
            //BinaryExpressionNode expressionNode = new BinaryExpressionNode();
            AssociativeNode rightNode = null;
            
            Int64 number;
            double real;
            bool flag;
            string val = node.ToScript();
            // If LiternalNode is double
            if(Double.TryParse(val, NumberStyles.Number, CultureInfo.InvariantCulture, out real))
            {
                rightNode = new DoubleNode(real); 
            }
            // If LiteralNode type is Int
            else if (Int64.TryParse(val, NumberStyles.Number, CultureInfo.InvariantCulture, out number))
            {
            
                rightNode = new IntNode(number);
            }            
            // If LiteralNode is bool
            else if (Boolean.TryParse(val, out flag))
            {
                rightNode = new BooleanNode(flag); 
            }

            /*IdentifierNode ident = CreateTempIdentifierNode(node);
            expressionNode.RightNode = rightNode;
            expressionNode.LeftNode = ident;
            expressionNode.Optr = ProtoCore.DSASM.Operator.assign;*/

            //(AstRootNode as CodeBlockNode).Body.Add(expressionNode);

            //outnode = expressionNode;
            outnode = CreateBinaryExpNode(node, rightNode);
        }
Beispiel #7
0
        void Associative_Number(out ProtoCore.AST.AssociativeAST.AssociativeNode node)
        {
            node = null; String localvalue = String.Empty;
            int line = ProtoCore.DSASM.Constants.kInvalidIndex; int col = ProtoCore.DSASM.Constants.kInvalidIndex;
            if (la.kind == 12) {
            Get();
            localvalue = "-"; line = t.line; col = t.col;
            }
            if (la.kind == 2) {
            Get();
            node = new ProtoCore.AST.AssociativeAST.IntNode() { value = localvalue + t.val };
            if (    ProtoCore.DSASM.Constants.kInvalidIndex == line
               &&  ProtoCore.DSASM.Constants.kInvalidIndex == col)
            {
               NodeUtils.SetNodeLocation(node, t);
            }
            else
            {
               node.line = line; node.col = col;
            }

            } else if (la.kind == 3) {
            Get();
            node = new ProtoCore.AST.AssociativeAST.DoubleNode() { value = localvalue + t.val };
            if (    ProtoCore.DSASM.Constants.kInvalidIndex == line
               &&  ProtoCore.DSASM.Constants.kInvalidIndex == col)
            {
               NodeUtils.SetNodeLocation(node, t);
            }
            else
            {
               node.line = line; node.col = col;
            }

            } else SynErr(101);
        }
Beispiel #8
0
        public void TestTypeSwitch()
        {
            object v = null;
            object node = null;

            DoubleNode doubleNode = new DoubleNode(1.2);
            node = doubleNode;
            TypeSwitch.Do(
                node,
                TypeSwitch.Case<IntNode>(n => v = n.Value),
                TypeSwitch.Case<DoubleNode>(n => v = n.Value),
                TypeSwitch.Case<BooleanNode>(n => v = n.Value),
                TypeSwitch.Case<StringNode>(n => v = n.Value),
                TypeSwitch.Default(() => v = null));
            Assert.AreEqual(v, 1.2);

            IntNode intNode = new IntNode(42);
            node = intNode;
            TypeSwitch.Do(
                node,
                TypeSwitch.Case<IntNode>(n => v = n.Value),
                TypeSwitch.Case<DoubleNode>(n => v = n.Value),
                TypeSwitch.Case<BooleanNode>(n => v = n.Value),
                TypeSwitch.Case<StringNode>(n => v = n.Value),
                TypeSwitch.Default(() => v = null));
            Assert.AreEqual(v, 42);

            StringNode sNode = new StringNode(); 
            node = sNode;
            TypeSwitch.Do(
                node,
                TypeSwitch.Case<IntNode>(n => v = n.Value),
                TypeSwitch.Case<DoubleNode>(n => v = n.Value),
                TypeSwitch.Case<BooleanNode>(n => v = n.Value),
                TypeSwitch.Default(() => v = 24));
            Assert.AreEqual(v, 24);
        }
 public DoubleNode(DoubleNode rhs)
     : base(rhs)
 {
     value = rhs.value;
 }
Beispiel #10
0
        public DynamoConvert()
        {           
            SelectedMetricConversion = ConversionMetricUnit.Length;  
            AssociativeNode defaultNode = new DoubleNode(0.0);
            InPortData.Add(new PortData("", "A numeric value for conversion.", defaultNode));
            OutPortData.Add(new PortData("", "A converted numeric value."));

            ShouldDisplayPreviewCore = true;
            IsSelectionFromBoxEnabled = true;
            RegisterAllPorts();
        }
Beispiel #11
0
	void Associative_Number(out ProtoCore.AST.AssociativeAST.AssociativeNode node) {
		node = null; 
		int sign = 1;
		int line = ProtoCore.DSASM.Constants.kInvalidIndex; 
		int col = ProtoCore.DSASM.Constants.kInvalidIndex; 
		
		if (la.kind == 13) {
			Get();
			sign = -1; 
			line = t.line; 
			col = t.col; 
			
		}
		if (la.kind == 2) {
			Get();
			Int64 value;
			if (Int64.TryParse(t.val, out value))
			{
			   node = new ProtoCore.AST.AssociativeAST.IntNode(value * sign);
			}
			else
			{
			   node = new ProtoCore.AST.AssociativeAST.NullNode();
			}
			
			if (ProtoCore.DSASM.Constants.kInvalidIndex == line
			   &&  ProtoCore.DSASM.Constants.kInvalidIndex == col)
			{
			   NodeUtils.SetNodeLocation(node, t);
			}
			else
			{
			   node.line = line; node.col = col;
			}
			
		} else if (la.kind == 3) {
			Get();
			double value;
			if (Double.TryParse(t.val, out value))
			{
			   node = new ProtoCore.AST.AssociativeAST.DoubleNode(value * sign);
			}
			else
			{
			   node = new ProtoCore.AST.AssociativeAST.NullNode();
			}
			
			if (ProtoCore.DSASM.Constants.kInvalidIndex == line
			   &&  ProtoCore.DSASM.Constants.kInvalidIndex == col)
			{
			   NodeUtils.SetNodeLocation(node, t);
			}
			else
			{
			   node.line = line; node.col = col;
			}
			
		} else SynErr(104);
	}
Beispiel #12
0
 public void DFSTraverse(ref AST.AssociativeAST.AssociativeNode node)
 {
     if (node is AST.AssociativeAST.IdentifierNode)
     {
         EmitIdentifierNode(ref node);
     }
     else if (node is ProtoCore.AST.AssociativeAST.IdentifierListNode)
     {
         AST.AssociativeAST.IdentifierListNode identList = node as ProtoCore.AST.AssociativeAST.IdentifierListNode;
         EmitIdentifierListNode(ref identList);
     }
     else if (node is ProtoCore.AST.AssociativeAST.IntNode)
     {
         AST.AssociativeAST.IntNode intNode = node as ProtoCore.AST.AssociativeAST.IntNode;
         EmitIntNode(ref intNode);
     }
     else if (node is ProtoCore.AST.AssociativeAST.DoubleNode)
     {
         AST.AssociativeAST.DoubleNode doubleNode = node as ProtoCore.AST.AssociativeAST.DoubleNode;
         EmitDoubleNode(ref doubleNode);
     }
     else if (node is ProtoCore.AST.AssociativeAST.FunctionCallNode)
     {
         AST.AssociativeAST.FunctionCallNode funcCallNode = node as ProtoCore.AST.AssociativeAST.FunctionCallNode;
         EmitFunctionCallNode(ref funcCallNode);
     }
     else if (node is ProtoCore.AST.AssociativeAST.FunctionDotCallNode)
     {
         AST.AssociativeAST.FunctionDotCallNode funcDotCall = node as ProtoCore.AST.AssociativeAST.FunctionDotCallNode;
         EmitFunctionDotCallNode(ref funcDotCall);
     }
     else if (node is ProtoCore.AST.AssociativeAST.BinaryExpressionNode)
     {
         ProtoCore.AST.AssociativeAST.BinaryExpressionNode binaryExpr = node as ProtoCore.AST.AssociativeAST.BinaryExpressionNode;
         if (binaryExpr.Optr != DSASM.Operator.assign)
         {
             ;
         }
         //EmitCode("(");
         EmitBinaryNode(ref binaryExpr);
         if (binaryExpr.Optr == DSASM.Operator.assign)
         {
             //EmitCode(ProtoCore.DSASM.Constants.termline);
         }
         if (binaryExpr.Optr != DSASM.Operator.assign)
         {
             ;
         }
         //EmitCode(")");
     }
     else if (node is ProtoCore.AST.AssociativeAST.FunctionDefinitionNode)
     {
         AST.AssociativeAST.FunctionDefinitionNode funcDefNode = node as ProtoCore.AST.AssociativeAST.FunctionDefinitionNode;
         EmitFunctionDefNode(ref funcDefNode);
     }
     else if (node is ProtoCore.AST.AssociativeAST.ClassDeclNode)
     {
         AST.AssociativeAST.ClassDeclNode classDeclNode = node as ProtoCore.AST.AssociativeAST.ClassDeclNode;
         EmitClassDeclNode(ref classDeclNode);
     }
     else if (node is ProtoCore.AST.AssociativeAST.NullNode)
     {
         AST.AssociativeAST.NullNode nullNode = node as ProtoCore.AST.AssociativeAST.NullNode;
         EmitNullNode(ref nullNode);
     }
     else if (node is ProtoCore.AST.AssociativeAST.ArrayIndexerNode)
     {
         AST.AssociativeAST.ArrayIndexerNode arrIdxNode = node as ProtoCore.AST.AssociativeAST.ArrayIndexerNode;
         EmitArrayIndexerNode(ref arrIdxNode);
     }
     else if (node is ProtoCore.AST.AssociativeAST.ExprListNode)
     {
         AST.AssociativeAST.ExprListNode exprListNode = node as ProtoCore.AST.AssociativeAST.ExprListNode;
         EmitExprListNode(ref exprListNode);
     }
 }