/// <summary> /// Clones the expression /// </summary> /// <returns></returns> protected virtual OqlExpression Clone() { OqlExpression exp = new OqlExpression(this.line, this.col); exp.children = children; exp.op = op; exp.unaryOp = unaryOp; exp.value = value; return(exp); }
/// <summary> /// Adds a child expression and an operator /// </summary> /// <param name="exp"></param> /// <param name="op"></param> public virtual void Add(OqlExpression exp, string op) { System.Diagnostics.Debug.Assert(this.children.Count > 0); if (this.Children.Count < 2) { this.children.Add(exp); this.op = op; } else if (this.op == op) { this.children.Add(exp); } else { OqlExpression left = this.Clone(); this.children.Clear(); this.children.Add(left); this.op = op; this.children.Add(exp); } }
//public List<object> Serialize() //{ // List<object> list = new List<object>(); // Serialize(list); //} //private void Serialize(List<object> list) //{ // if (this.IsTerminating) // { // list.Add(this); // } // else // { // if (this.hasBrackets) // list.Add("("); // if (this.unaryOp != null) // list.Add(this.unaryOp); // } //} ///<inheritdoc/> public override string ToString() { StringBuilder sb = new StringBuilder(); if (hasBrackets) { sb.Append('('); } if (unaryOp != null) { sb.Append(unaryOp); sb.Append(' '); } if (ExpressionType == Expressions.ExpressionType.Raw && value != null) { sb.Append(this.value.ToString()); if (!IsTerminating) { sb.Append(' '); } } else if (this.IsTerminating) { if (this.value is Double) { sb.Append(((Double)this.value).ToString(CultureInfo.InvariantCulture)); } else if (value != null) { sb.Append(this.value.ToString()); } } if (!this.IsTerminating) { string op1 = op; for (int i = 0; i < children.Count; i++) { OqlExpression child = this.children[i]; sb.Append(child.ToString()); if (i < children.Count - 1) { if (!String.IsNullOrEmpty(op)) { if (op != ",") { sb.Append(' '); } sb.Append(op1); if (op1 == "BETWEEN") { op1 = "AND"; } sb.Append(' '); } else { sb.Append(' '); } } } } if (hasBrackets) { sb.Append(')'); } return(sb.ToString()); }
/// <summary> /// Adds a child expressoin /// </summary> /// <param name="exp"></param> public virtual void Add(OqlExpression exp) { this.children.Add(exp); }
/// <summary> /// </summary> /// <param name="exp"></param> /// <remarks> /// Since there occurs a lot of shuffling around the children during the parse process /// we itererate through the tree after parsing and set the parent there. /// </remarks> void IManageExpression.SetParent(OqlExpression exp) { this.parent = exp; }