// Try to fold a negated constant int32. We have to do this so that parsing int32.MinValue will work public override Node ExitNegateExpression(Production node) { IList childValues = this.GetChildValues(node); // Get last child ExpressionElement childElement = childValues[childValues.Count - 1] as ExpressionElement; // Is it an signed integer constant? if (object.ReferenceEquals(childElement.GetType(), typeof(Int32LiteralElement)) & childValues.Count == 2) { ((Int32LiteralElement)childElement).Negate(); // Add it directly instead of the negate element since it will already be negated node.AddValue(childElement); } else if (object.ReferenceEquals(childElement.GetType(), typeof(Int64LiteralElement)) & childValues.Count == 2) { ((Int64LiteralElement)childElement).Negate(); // Add it directly instead of the negate element since it will already be negated node.AddValue(childElement); } else { // No so just add a regular negate this.AddUnaryOp(node, typeof(NegateElement)); } return(node); }
private void AddUnaryOp(Production node, Type elementType) { IList childValues = this.GetChildValues(node); if (childValues.Count == 2) { UnaryElement element = Activator.CreateInstance(elementType) as UnaryElement; element.SetChild(childValues[1] as ExpressionElement); node.AddValue(element); } else { node.AddValue(childValues[0]); } }
public override Node ExitInListTargetExpression(Production node) { IList childValues = this.GetChildValues(node); node.AddValue(childValues); return(node); }
public override Node ExitInExpression(Production node) { IList childValues = this.GetChildValues(node); if (childValues.Count == 1) { this.AddFirstChildValue(node); return(node); } ExpressionElement operand = childValues[0] as ExpressionElement; childValues.RemoveAt(0); object second = childValues[0]; InElement op = default(InElement); if ((second) is IList) { op = new InElement(operand, (IList)second); } else { InvocationListElement il = new InvocationListElement(childValues, MyServices); op = new InElement(operand, il); } node.AddValue(op); return(node); }
public override Node ExitFieldPropertyExpression(Production node) { string name = (string)node.GetChildAt(0).GetValue(0); IdentifierElement elem = new IdentifierElement(name); node.AddValue(elem); return(node); }
public override Node ExitIfExpression(Production node) { IList childValues = this.GetChildValues(node); ConditionalElement op = new ConditionalElement(childValues[0] as ExpressionElement, childValues[1] as ExpressionElement, childValues[2] as ExpressionElement); node.AddValue(op); return(node); }
public override Node ExitMemberExpression(Production node) { IList childValues = this.GetChildValues(node); object first = childValues[0]; if (childValues.Count == 1 && !(first is MemberElement)) { node.AddValue(first); } else { InvocationListElement list = new InvocationListElement(childValues, MyServices); node.AddValue(list); } return(node); }
private void AddBinaryOp(Production node, Type elementType) { IList childValues = this.GetChildValues(node); if (childValues.Count > 1) { BinaryExpressionElement e = BinaryExpressionElement.CreateElement(childValues, elementType); node.AddValue(e); } else if (childValues.Count == 1) { node.AddValue(childValues[0]); } else { Debug.Assert(false, "wrong number of chilren"); } }
public override Node ExitIndexExpression(Production node) { IList childValues = this.GetChildValues(node); ArgumentList args = new ArgumentList(childValues); IndexerElement e = new IndexerElement(args); node.AddValue(e); return(node); }
public override Node ExitCastExpression(Production node) { IList childValues = this.GetChildValues(node); string[] destTypeParts = (string[])childValues[1]; bool isArray = (bool)childValues[2]; CastElement op = new CastElement(childValues[0] as ExpressionElement, destTypeParts, isArray, MyServices); node.AddValue(op); return(node); }
public override Node ExitFunctionCallExpression(Production node) { IList childValues = this.GetChildValues(node); string name = (string)childValues[0]; childValues.RemoveAt(0); ArgumentList args = new ArgumentList(childValues); FunctionCallElement funcCall = new FunctionCallElement(name, args); node.AddValue(funcCall); return(node); }
public override Node ExitCastTypeExpression(Production node) { IList childValues = this.GetChildValues(node); List <string> parts = new List <string>(); foreach (string part in childValues) { parts.Add(part); } bool isArray = false; if (parts[parts.Count - 1] == "[]") { isArray = true; parts.RemoveAt(parts.Count - 1); } node.AddValue(parts.ToArray()); node.AddValue(isArray); return(node); }
private void AddFirstChildValue(Production node) { node.AddValue(this.GetChildAt(node, 0).Values[0]); }
public override Node ExitMemberAccessExpression(Production node) { node.AddValue(node.GetChildAt(1).GetValue(0)); return(node); }