NodeBase CreateLogicalNode(LogicalExpression exp) { NodeBase node = null; if (exp.HasUnary()) { node = new LogicalNode(m_Container); ((LogicalNode)node).m_LogicalType = LogicalOperatorType.NOT; node.AddChild(CreateLogicalNode(exp.GetUnary().GetLogicalExpression())); } else if (exp.HasRelational()) { node = new RelationalNode(m_Container); RelationalOperator op = exp.GetRelational().GetRelationalOperator(); if (op.HasEquals()) ((RelationalNode)node).m_RelationType = RelationType.EQUAL; else if (op.HasGreaterThan()) ((RelationalNode)node).m_RelationType = RelationType.GREATERTHAN; else if (op.HasGreaterThanOrEquals()) ((RelationalNode)node).m_RelationType = RelationType.GREATERTHANOREQUAL; else if (op.HasLessThan()) ((RelationalNode)node).m_RelationType = RelationType.LESSTHAN; else if (op.HasLessThanOrEquals()) ((RelationalNode)node).m_RelationType = RelationType.LESSTHANOREQUAL; else if (op.HasNotEquals()) ((RelationalNode)node).m_RelationType = RelationType.NOTEQUAL; node.AddChild(CreateArithmeticNode(exp.GetRelational().GetLHSArithmeticExpression())); node.AddChild(CreateArithmeticNode(exp.GetRelational().GetRHSArithmeticExpression())); } else if (exp.HasLogical()) { node = new LogicalNode(m_Container); if (exp.GetLogical().GetLogicalOperator().HasAnd()) ((LogicalNode)node).m_LogicalType = LogicalOperatorType.AND; else ((LogicalNode)node).m_LogicalType = LogicalOperatorType.OR; node.AddChild(CreateLogicalNode(exp.GetLogical().GetLHSLogicalExpression())); node.AddChild(CreateLogicalNode(exp.GetLogical().GetRHSLogicalExpression())); } else if (exp.HasValue()) { if (exp.GetValue().HasConstant()) { node = new ConstantNode(m_Container); ((ConstantNode)node).m_ConstantValue = exp.GetValue().GetConstant().GetBoolean().Value; ((ConstantNode)node).m_ConstantType = VariableType.BOOLEAN; } else { node = new VariableNode(m_Container); ((VariableNode)node).m_VariableName = exp.GetValue().GetVariable().GetName().Value; ((VariableNode)node).m_VariableType = VariableType.BOOLEAN; } } return node; }
NodeBase CreateArithmeticNode(ArithmeticExpression exp) { NodeBase node = null; if (exp.HasSubExpression()) { node = CreateMathNode(exp.GetSubExpression()); } else { if (exp.GetValue().HasConstant()) { node = new ConstantNode(m_Container); if (exp.GetValue().GetConstant().HasFloat2()) { ((ConstantNode)node).m_ConstantValue = (float)exp.GetValue().GetConstant().GetFloat2().Value; ((ConstantNode)node).m_ConstantType = VariableType.FLOAT; } else if (exp.GetValue().GetConstant().HasInteger()) { ((ConstantNode)node).m_ConstantValue = (int)exp.GetValue().GetConstant().GetInteger().Value; ((ConstantNode)node).m_ConstantType = VariableType.INT; } else if (exp.GetValue().GetConstant().HasBoolean()) { ((ConstantNode)node).m_ConstantValue = (bool)exp.GetValue().GetConstant().GetBoolean().Value; ((ConstantNode)node).m_ConstantType = VariableType.BOOLEAN; } else if (exp.GetValue().GetConstant().HasString2()) { ((ConstantNode)node).m_ConstantValue = (string)exp.GetValue().GetConstant().GetString2().Value; ((ConstantNode)node).m_ConstantType = VariableType.STRING; } } else { node = new VariableNode(m_Container); ((VariableNode)node).m_VariableName = exp.GetValue().GetVariable().GetName().Value; ((VariableNode)node).m_VariableType = (VariableType)exp.GetValue().GetVariable().GetType2().Value; } } return node; }
NodeBase CreateLogicalNode(LogicalExpression exp) { NodeBase node = null; if (exp.HasUnary()) { node = new LogicalNode(m_Container); ((LogicalNode)node).m_LogicalType = LogicalOperatorType.NOT; node.AddChild(CreateLogicalNode(exp.GetUnary().GetLogicalExpression())); } else if (exp.HasRelational()) { node = new RelationalNode(m_Container); RelationalOperator op = exp.GetRelational().GetRelationalOperator(); if (op.HasEquals()) { ((RelationalNode)node).m_RelationType = RelationType.EQUAL; } else if (op.HasGreaterThan()) { ((RelationalNode)node).m_RelationType = RelationType.GREATERTHAN; } else if (op.HasGreaterThanOrEquals()) { ((RelationalNode)node).m_RelationType = RelationType.GREATERTHANOREQUAL; } else if (op.HasLessThan()) { ((RelationalNode)node).m_RelationType = RelationType.LESSTHAN; } else if (op.HasLessThanOrEquals()) { ((RelationalNode)node).m_RelationType = RelationType.LESSTHANOREQUAL; } else if (op.HasNotEquals()) { ((RelationalNode)node).m_RelationType = RelationType.NOTEQUAL; } node.AddChild(CreateArithmeticNode(exp.GetRelational().GetLHSArithmeticExpression())); node.AddChild(CreateArithmeticNode(exp.GetRelational().GetRHSArithmeticExpression())); } else if (exp.HasLogical()) { node = new LogicalNode(m_Container); if (exp.GetLogical().GetLogicalOperator().HasAnd()) { ((LogicalNode)node).m_LogicalType = LogicalOperatorType.AND; } else { ((LogicalNode)node).m_LogicalType = LogicalOperatorType.OR; } node.AddChild(CreateLogicalNode(exp.GetLogical().GetLHSLogicalExpression())); node.AddChild(CreateLogicalNode(exp.GetLogical().GetRHSLogicalExpression())); } else if (exp.HasValue()) { if (exp.GetValue().HasConstant()) { node = new ConstantNode(m_Container); ((ConstantNode)node).m_ConstantValue = exp.GetValue().GetConstant().GetBoolean().Value; ((ConstantNode)node).m_ConstantType = VariableType.BOOLEAN; } else { node = new VariableNode(m_Container); ((VariableNode)node).m_VariableName = exp.GetValue().GetVariable().GetName().Value; ((VariableNode)node).m_VariableType = VariableType.BOOLEAN; } } return(node); }