public static Block Parse(XmlNode node, ParserInfo parseInfo, bool canBeScheduled) { string id = ParseTools.ParseID(node); float value = ParseTools.ParseFloat(node, parseInfo, id); return(new Constant(value, parseInfo.GetUniqueAnonymousName(), id, canBeScheduled)); }
public static Block Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); string output = ParseTools.ParseString(node, OUTPUT_FLUID_FIELD_NAME); Validator.CheckVariableName(id, output); parserInfo.AddVariable(id, VariableType.FLUID, output); XmlNode innerNode = node.GetInnerBlockNode(INPUT_FLUID_FIELD_NAME, parserInfo, new MissingBlockException(id, "Fluid is missing fluid definition blocks.")); if (innerNode != null) { switch (innerNode.GetAttributeValue(Block.TYPE_FIELD_NAME)) { case HeaterUsage.XML_TYPE_NAME: return(HeaterUsage.CreateHeater(output, innerNode, dfg, parserInfo)); case Mixer.XmlTypeName: return(Mixer.CreateMixer(output, innerNode, dfg, parserInfo)); case Union.XML_TYPE_NAME: return(Union.CreateUnion(output, innerNode, dfg, parserInfo)); default: return(CreateFluid(output, innerNode, dfg, parserInfo)); } } return(null); }
public Direct GetProgram(XmlNode currentProgramXml, ParserInfo parserInfo) { string id = ParseTools.ParseID(currentProgramXml); InlineProgramInfo programInfo = GetInlineProgramInfo(currentProgramXml, parserInfo); CDFG newProgram = ProgramCDFG.Copy(); TransformCDFGToFunctionCDFG(newProgram, programInfo); TransformVariableNames(newProgram, programInfo, parserInfo.GetUniquePostFix()); ChangeIDs(newProgram, id); //Add new variables that this program added programInfo.OutputsFromTo.ForEach(x => parserInfo.AddVariable(string.Empty, VariableType.FLUID, x.Value)); DFG <Block> nextDFG = XmlParser.ParseNextDFG(currentProgramXml, parserInfo); DFG <Block> endDFG = newProgram.GetEndDFGInFirstScope(); int i = newProgram.Nodes.FindIndex(x => x.dfg == endDFG); if (newProgram.Nodes[i].control == null) { newProgram.Nodes[i] = (new Direct(nextDFG), endDFG); } else { newProgram.Nodes[i] = (newProgram.Nodes[i].control.GetNewControlWithNewEnd(nextDFG), endDFG); } //merge the programs together nd return the link between then parserInfo.cdfg.AddCDFG(newProgram); return(new Direct(newProgram.StartDFG)); }
public While(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); string mode = node.GetNodeWithAttributeValue(WHILE_MODE_FIELD_NAME).InnerText; if (mode != SUPPORTED_MODE) { parserInfo.ParseExceptions.Add(new ParseException(id, "While block only supports while mode.")); } XmlNode conditionalNode = node.GetInnerBlockNode(CONDITIONAL_BLOCK_FIELD_NAME, parserInfo, new MissingBlockException(id, "While block is missing its conditional block.")); VariableBlock decidingBlock = null; if (conditionalNode != null) { decidingBlock = (VariableBlock)XmlParser.ParseAndAddNodeToDFG(conditionalNode, dfg, parserInfo); } XmlNode guardedNode = node.GetInnerBlockNode(DO_BLOCK_FIELD_NAME, parserInfo, new MissingBlockException(id, "While block is missing blocks to execute.")); if (guardedNode != null) { DFG <Block> guardedDFG = XmlParser.ParseDFG(guardedNode, parserInfo); DFG <Block> nextDFG = XmlParser.ParseNextDFG(node, parserInfo); this.Cond = new Conditional(decidingBlock, guardedDFG, nextDFG); } }
public static DropletDeclaration Parse(XmlNode node, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); string output = ParseTools.ParseString(node, INPUT_FLUID_FIELD_NAME); parserInfo.AddVariable(id, VariableType.FLUID, output); return(new DropletDeclaration(output, id)); }
public static Block Parse(XmlNode node, ParserInfo parserInfo, bool canBeScheduled) { string id = ParseTools.ParseID(node); string arrayName = ParseTools.ParseString(node, ARRAY_NAME_FIELD_NAME); parserInfo.CheckVariable(id, new VariableType[] { VariableType.NUMBER_ARRAY, VariableType.FLUID_ARRAY }, arrayName); return(new GetArrayLength(arrayName, parserInfo.GetUniqueAnonymousName(), id, canBeScheduled)); }
public static Block Parse(XmlNode node, ParserInfo parserInfo, bool canBeScheduled) { string id = ParseTools.ParseID(node); string variableName = ParseTools.ParseString(node, VARIABLE_FIELD_NAME); parserInfo.CheckVariable(id, VariableType.NUMBER, variableName); return(new GetNumberVariable(variableName, parserInfo.GetUniqueAnonymousName(), id, canBeScheduled)); }
public static Block Parse(XmlNode node, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); string moduleName = ParseTools.ParseString(node, MODULE_NAME_FIELD_NAME); parserInfo.AddVariable(id, VariableType.WASTE, moduleName); return(new WasteDeclaration(moduleName, parserInfo.GetUniqueAnonymousName(), id)); }
public static InputDeclaration Parse(XmlNode node, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); float amount = ParseTools.ParseFloat(node, parserInfo, id, INPUT_AMOUNT_FIELD_NAME); string output = ParseTools.ParseString(node, INPUT_FLUID_FIELD_NAME); parserInfo.AddVariable(id, VariableType.FLUID, output); return(new InputDeclaration(output, amount, id)); }
private static Block CreateFluid(string output, XmlNode node, DFG <Block> dfg, ParserInfo parserInfo) { List <FluidInput> inputs = new List <FluidInput>(); inputs.Add(XmlParser.ParseFluidInput(node, dfg, parserInfo)); string id = ParseTools.ParseID(node); return(new Fluid(inputs, output, id)); }
public static Block Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo, bool canBeScheduled) { string id = ParseTools.ParseID(node); RoundOPTypes roundType = StringToRoundOPType(id, ParseTools.ParseString(node, OPTypeFieldName)); VariableBlock numberBlock = ParseTools.ParseBlock <VariableBlock>(node, dfg, parserInfo, id, NUMBER_FIELD_NAME, new MissingBlockException(id, "Number defining block is missing.")); dfg.AddNode(numberBlock); return(new RoundOP(numberBlock, parserInfo.GetUniqueAnonymousName(), roundType, id, canBeScheduled)); }
public static Block Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo, bool canBeScheduled) { string id = ParseTools.ParseID(node); string arrayName = ParseTools.ParseString(node, ARRAY_NAME_FIELD_NAME); parserInfo.CheckVariable(id, VariableType.NUMBER_ARRAY, arrayName); VariableBlock indexBlock = ParseTools.ParseBlock <VariableBlock>(node, dfg, parserInfo, id, INDEX_FIELD_NAME, new MissingBlockException(id, "Missing block which define the index into the array.")); dfg.AddNode(indexBlock); return(new GetArrayNumber(indexBlock, arrayName, parserInfo.GetUniqueAnonymousName(), id, canBeScheduled)); }
public static Block Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); string output = ParseTools.ParseString(node, VARIABLE_FIELD_NAME); parserInfo.AddVariable(id, VariableType.NUMBER, output); VariableBlock operandBlock = ParseTools.ParseBlock <VariableBlock>(node, dfg, parserInfo, id, INPUT_VARIABLE_FIELD_NAME, new MissingBlockException(id, "Missing block to define the variables value.")); dfg.AddNode(operandBlock); return(new SetNumberVariable(operandBlock, output, id)); }
public static Block Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); string arrayName = ParseTools.ParseString(node, ARRAY_NAME_FIELD_NAME); parserInfo.AddVariable(id, VariableType.NUMBER_ARRAY, arrayName); VariableBlock arrayLengthBlock = ParseTools.ParseBlock <VariableBlock>(node, dfg, parserInfo, id, ARRAY_LENGTH_FIELD_NAME, new MissingBlockException(id, "Missing block which define the length of the array.")); dfg.AddNode(arrayLengthBlock); return(new NumberArray(arrayName, arrayLengthBlock, id)); }
public static Block Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo, bool canBeScheduled) { string id = ParseTools.ParseID(node); BoolOPTypes opType = BoolOP.StringToBoolOPType(id, ParseTools.ParseString(node, OPTypeFieldName)); VariableBlock leftBoolBlock = ParseTools.ParseBlock <VariableBlock>(node, dfg, parserInfo, id, LeftBoolFieldName, new MissingBlockException(id, "Left side of boolean operator is missing a block.")); VariableBlock rightBoolBlock = ParseTools.ParseBlock <VariableBlock>(node, dfg, parserInfo, id, RightBoolFieldName, new MissingBlockException(id, "Right side of boolean operator is missing a block.")); dfg.AddNode(leftBoolBlock); dfg.AddNode(rightBoolBlock); return(new BoolOP(leftBoolBlock, rightBoolBlock, parserInfo.GetUniqueAnonymousName(), opType, id, canBeScheduled)); }
public static FluidInput Parse(XmlNode node, ParserInfo parserInfo, bool doVariableCheck = true) { string id = ParseTools.ParseID(node); string originalFluidName = ParseTools.ParseString(node, FLUID_NAME_FIELD_NAME); if (doVariableCheck) { parserInfo.CheckVariable(id, VariableType.FLUID, originalFluidName); } float amountInML = ParseTools.ParseFloat(node, parserInfo, id, FLUID_AMOUNT_FIELD_NAME); bool useAllFluid = FluidInput.StringToBool(ParseTools.ParseString(node, USE_ALL_FLUID_FIELD_NAME)); return(new BasicInput(id, originalFluidName, amountInML, useAllFluid)); }
public static WasteUsage Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); string moduleName = ParseTools.ParseString(node, MODULE_NAME_FIELD_NAME); parserInfo.CheckVariable(id, VariableType.WASTE, moduleName); FluidInput fluidInput = ParseTools.ParseFluidInput(node, dfg, parserInfo, id, INPUT_FLUID_FIELD_NAME, new MissingBlockException(id, "Waste is missing input fluid block.")); List <FluidInput> inputs = new List <FluidInput>(); inputs.Add(fluidInput); return(new WasteUsage(moduleName, inputs, null, id)); }
public static Block CreateMixer(string output, XmlNode node, DFG <Block> dfg, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); FluidInput fluidInput1 = ParseTools.ParseFluidInput(node, dfg, parserInfo, id, FirstInputFieldName, new MissingBlockException(id, "Mixer is missing input fluid block.")); FluidInput fluidInput2 = ParseTools.ParseFluidInput(node, dfg, parserInfo, id, SecondInputFieldName, new MissingBlockException(id, "Mixer is missing input fluid block.")); List <FluidInput> inputs = new List <FluidInput>(); inputs.Add(fluidInput1); inputs.Add(fluidInput2); return(new Mixer(inputs, output, id)); }
public static Block Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo, bool canBeScheduled) { string id = ParseTools.ParseID(node); string arrayName = ParseTools.ParseString(node, ARRAY_NAME_FIELD_NAME); parserInfo.CheckVariable(id, VariableType.NUMBER_ARRAY, arrayName); VariableBlock indexBlock = ParseTools.ParseBlock <VariableBlock>(node, dfg, parserInfo, id, INDEX_FIELD_NAME, new MissingBlockException(id, "Missing block to define the variables value.")); VariableBlock numberInput = ParseTools.ParseBlock <VariableBlock>(node, dfg, parserInfo, id, INPUT_NUMBER_FIELD_NAME, new MissingBlockException(id, "Mixer is missing input fluid block.")); dfg.AddNode(indexBlock); dfg.AddNode(numberInput); return(new SetArrayNumber(indexBlock, numberInput, arrayName, id, canBeScheduled)); }
public static Block CreateHeater(string output, XmlNode node, DFG <Block> dfg, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); string moduleName = ParseTools.ParseString(node, MODULE_NAME_FIELD_NAME); parserInfo.CheckVariable(id, VariableType.HEATER, moduleName); int temperature = (int)ParseTools.ParseFloat(node, parserInfo, id, TEMPERATURE_FIELD_NAME); int time = (int)ParseTools.ParseFloat(node, parserInfo, id, TIME_FIELD_NAME); FluidInput fluidInput = ParseTools.ParseFluidInput(node, dfg, parserInfo, id, INPUT_FLUID_FIELD_NAME, new MissingBlockException(id, "Heater is missing input fluid block.")); List <FluidInput> inputs = new List <FluidInput>(); inputs.Add(fluidInput); return(new HeaterUsage(moduleName, inputs, output, temperature, time, id)); }
public If(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); List <Conditional> conditionals = new List <Conditional>(); int IfBlocksCount = 1; bool hasElse = false; XmlNode mutatorNode = node.TryGetNodeWithName("mutation"); if (mutatorNode != null) { string elseifAttrib = mutatorNode.TryGetAttributeValue("elseif"); if (elseifAttrib != null) { IfBlocksCount += int.Parse(elseifAttrib); } hasElse = mutatorNode.TryGetAttributeValue("else") != null; } DFG <Block> nextDFG = null; for (int ifCounter = 0; ifCounter < IfBlocksCount; ifCounter++) { string exceptionStart = $"{ (ifCounter == 0 ? "If" : "Else if") } statement { (ifCounter == 0 ? String.Empty : $"Number {ifCounter}")}"; VariableBlock decidingBlock = null; XmlNode ifNode = node.GetInnerBlockNode(GetIfFieldName(ifCounter), parserInfo, new MissingBlockException(id, $"{exceptionStart} is missing its conditional block.")); if (ifNode != null) { decidingBlock = (VariableBlock)XmlParser.ParseAndAddNodeToDFG(ifNode, dfg, parserInfo); } XmlNode guardedDFGNode = node.GetInnerBlockNode(GetDoFieldName(ifCounter), parserInfo, new MissingBlockException(id, $"{exceptionStart} is missing blocks to execute.")); if (guardedDFGNode != null) { DFG <Block> guardedDFG = XmlParser.ParseDFG(guardedDFGNode, parserInfo); nextDFG = nextDFG ?? XmlParser.ParseNextDFG(node, parserInfo); conditionals.Add(new Conditional(decidingBlock, guardedDFG, nextDFG)); } }
public static FluidInput Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo, bool doVariableCheck = true) { string id = ParseTools.ParseID(node); string arrayName = ParseTools.ParseString(node, ARRAY_NAME_FIELD_NAME); if (doVariableCheck) { parserInfo.CheckVariable(id, VariableType.FLUID_ARRAY, arrayName); } float amountInML = ParseTools.ParseFloat(node, parserInfo, id, FLUID_AMOUNT_FIELD_NAME); bool useAllFluid = FluidInput.StringToBool(ParseTools.ParseString(node, USE_ALL_FLUID_FIELD_NAME)); VariableBlock indexBlock = ParseTools.ParseBlock <VariableBlock>(node, dfg, parserInfo, id, INDEX_FIELD_NAME, new MissingBlockException(id, "Missing block which define the index into the array.")); dfg.AddNode(indexBlock); return(new GetArrayFluid(indexBlock, arrayName, id, amountInML, useAllFluid)); }
public Repeat(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); XmlNode conditionalNode = node.GetInnerBlockNode(TimesBlockFieldName, parserInfo, new MissingBlockException(id, "Repeat block is missing its conditional block.")); VariableBlock decidingBlock = null; if (conditionalNode != null) { decidingBlock = (VariableBlock)XmlParser.ParseAndAddNodeToDFG(conditionalNode, dfg, parserInfo); } XmlNode guardedNode = node.GetInnerBlockNode(DoBlockFieldName, parserInfo, new MissingBlockException(id, "Repeat block is missing blocks to execute.")); if (guardedNode != null) { DFG <Block> guardedDFG = XmlParser.ParseDFG(guardedNode, parserInfo); DFG <Block> nextDFG = XmlParser.ParseNextDFG(node, parserInfo); this.Cond = new Conditional(decidingBlock, guardedDFG, nextDFG); } }
public static Block Parse(XmlNode node, DFG <Block> dfg, ParserInfo parserInfo) { string id = ParseTools.ParseID(node); string arrayName = ParseTools.ParseString(node, ARRAY_NAME_FIELD_NAME); parserInfo.CheckVariable(id, VariableType.FLUID_ARRAY, arrayName); VariableBlock indexBlock = ParseTools.ParseBlock <VariableBlock>(node, dfg, parserInfo, id, INDEX_FIELD_NAME, new MissingBlockException(id, "Missing block to define the index.")); FluidInput fluidInput = ParseTools.ParseFluidInput(node, dfg, parserInfo, id, INPUT_FLUID_FIELD_NAME, new MissingBlockException(id, "Missing input fluid block.")); dfg.AddNode(indexBlock); List <FluidInput> inputFluids = new List <FluidInput>(); inputFluids.Add(fluidInput); return(new SetArrayFluid(indexBlock, arrayName, inputFluids, id)); }