Exemplo n.º 1
0
        public string AddBoolOPBlock(BoolOPTypes type, string leftBlock, string rightBlock)
        {
            string a = GetUniqueName();

            AddBlock(a, BoolOP.XML_TYPE_NAME);
            SetField(a, BoolOP.OPTypeFieldName, BoolOP.BoolOpTypeToString(type));
            AddConnection(a, BoolOP.LeftBoolFieldName, leftBlock);
            AddConnection(a, BoolOP.RightBoolFieldName, rightBlock);

            return(a);
        }
Exemplo n.º 2
0
        public void TestCopyBoolOPBlock()
        {
            VariableBlock[] blocks = new VariableBlock[3];
            blocks[0] = new Constant(10, "a", "", false);
            blocks[1] = new Constant(3, "b", "", false);
            blocks[2] = new BoolOP(blocks[0], blocks[1], "cake", BoolOPTypes.EQ, "", false);

            int[][] dependencyGraph = new int[][]
            {
                new int[] { },
                new int[] { },
                new int[] { 0, 1 }
            };

            CheckCopyMultiBlock(blocks[2], blocks, dependencyGraph);
        }
Exemplo n.º 3
0
        public void ParseBoolOPBlock()
        {
            JSProgram program = new JSProgram();
            string    a       = program.AddConstantBlock(20);
            string    b       = program.AddConstantBlock(12);

            program.AddBoolOPBlock(BoolOPTypes.EQ, a, b);
            TestTools.ExecuteJS(program);

            XmlNode    node       = TestTools.GetWorkspace();
            ParserInfo parserInfo = new ParserInfo();
            BoolOP     boolOP     = (BoolOP)XmlParser.ParseBlock(node, new DFG <Block>(), parserInfo);

            Assert.AreEqual(0, parserInfo.ParseExceptions.Count, parserInfo.ParseExceptions.FirstOrDefault()?.Message);
            Assert.AreEqual(BoolOPTypes.EQ, boolOP.OPType);
        }
Exemplo n.º 4
0
        public static Block ParseBlock(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo, bool allowDeclarationBlocks = false, bool canBeScheduled = true)
        {
            string id        = node.GetAttributeValue(Block.ID_FIELD_NAME);
            string blockType = node.GetAttributeValue(Block.TYPE_FIELD_NAME);

            switch (blockType)
            {
            case ArithOP.XML_TYPE_NAME:
                return(ArithOP.Parse(node, dfg, parserInfo, canBeScheduled));

            case Constant.XML_TYPE_NAME:
                return(Constant.Parse(node, parserInfo, canBeScheduled));

            case FluidArray.XML_TYPE_NAME:
                return(FluidArray.Parse(node, dfg, parserInfo));

            case SetArrayFluid.XML_TYPE_NAME:
                return(SetArrayFluid.Parse(node, dfg, parserInfo));

            case Fluid.XML_TYPE_NAME:
                return(Fluid.Parse(node, dfg, parserInfo));

            case InputDeclaration.XML_TYPE_NAME:
                if (!allowDeclarationBlocks)
                {
                    parserInfo.ParseExceptions.Add(new ParseException(id, "Declaration blocks has to be at the top of the program."));
                }
                return(InputDeclaration.Parse(node, parserInfo));

            case OutputDeclaration.XML_TYPE_NAME:
                if (!allowDeclarationBlocks)
                {
                    parserInfo.ParseExceptions.Add(new ParseException(id, "Declaration blocks has to be at the top of the program."));
                }
                return(OutputDeclaration.Parse(node, parserInfo));

            case WasteDeclaration.XML_TYPE_NAME:
                if (!allowDeclarationBlocks)
                {
                    parserInfo.ParseExceptions.Add(new ParseException(id, "Declaration blocks has to be at the top of the program."));
                }
                return(WasteDeclaration.Parse(node, parserInfo));

            case HeaterDeclaration.XML_TYPE_NAME:
                if (!allowDeclarationBlocks)
                {
                    parserInfo.ParseExceptions.Add(new ParseException(id, "Declaration blocks has to be at the top of the program."));
                }
                return(HeaterDeclaration.Parse(node, parserInfo));

            case OutputUsage.XML_TYPE_NAME:
                return(OutputUsage.Parse(node, dfg, parserInfo));

            case WasteUsage.XML_TYPE_NAME:
                return(WasteUsage.Parse(node, dfg, parserInfo));

            case DropletDeclaration.XML_TYPE_NAME:
                return(DropletDeclaration.Parse(node, parserInfo));

            case BoolOP.XML_TYPE_NAME:
                return(BoolOP.Parse(node, dfg, parserInfo, canBeScheduled));

            //case Sensor.XmlTypeName:
            //    return Sensor.Parse(node);
            case GetNumberVariable.XML_TYPE_NAME:
                return(GetNumberVariable.Parse(node, parserInfo, canBeScheduled));

            case SetNumberVariable.XML_TYPE_NAME:
                return(SetNumberVariable.Parse(node, dfg, parserInfo));

            case GetDropletCount.XML_TYPE_NAME:
                return(GetDropletCount.Parser(node, parserInfo, canBeScheduled));

            case GetArrayLength.XML_TYPE_NAME:
                return(GetArrayLength.Parse(node, parserInfo, canBeScheduled));

            case ImportVariable.XML_TYPE_NAME:
                return(ImportVariable.Parse(node, parserInfo, canBeScheduled));

            case NumberArray.XML_TYPE_NAME:
                return(NumberArray.Parse(node, dfg, parserInfo));

            case GetArrayNumber.XML_TYPE_NAME:
                return(GetArrayNumber.Parse(node, dfg, parserInfo, canBeScheduled));

            case SetArrayNumber.XML_TYPE_NAME:
                return(SetArrayNumber.Parse(node, dfg, parserInfo, canBeScheduled));

            case RoundOP.XML_TYPE_NAME:
                return(RoundOP.Parse(node, dfg, parserInfo, canBeScheduled));

            default:
                throw new UnknownBlockException(id);
            }
        }