public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { if (binaryOperatorExpression.Op == BinaryOperatorType.LogicalOr) UnlockWith(binaryOperatorExpression); return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data); }
public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { switch (binaryOperatorExpression.Op) { case BinaryOperatorType.NullCoalescing: return binaryOperatorExpression.Right.AcceptVisitor(this, data); case BinaryOperatorType.DivideInteger: return resolver.ProjectContent.SystemTypes.Int32; case BinaryOperatorType.Concat: return resolver.ProjectContent.SystemTypes.String; case BinaryOperatorType.Equality: case BinaryOperatorType.InEquality: case BinaryOperatorType.ReferenceEquality: case BinaryOperatorType.ReferenceInequality: case BinaryOperatorType.LogicalAnd: case BinaryOperatorType.LogicalOr: case BinaryOperatorType.LessThan: case BinaryOperatorType.LessThanOrEqual: case BinaryOperatorType.GreaterThan: case BinaryOperatorType.GreaterThanOrEqual: return resolver.ProjectContent.SystemTypes.Boolean; default: return MemberLookupHelper.GetCommonType(resolver.ProjectContent, binaryOperatorExpression.Left.AcceptVisitor(this, data) as IReturnType, binaryOperatorExpression.Right.AcceptVisitor(this, data) as IReturnType); } }
private CastExpression GetCastExpression(BinaryOperatorExpression binaryOperatorExpression) { TypeReference leftType = GetExpressionType(binaryOperatorExpression.Left); CastExpression castedUnsignedShift = new CastExpression(new TypeReference("u" + leftType.Type), binaryOperatorExpression, CastType.Cast); ParenthesizedExpression parenthesizedCastedUnsignedShift = new ParenthesizedExpression(castedUnsignedShift); return new CastExpression(new TypeReference(leftType.Type), parenthesizedCastedUnsignedShift, CastType.Cast); }
/// <summary> /// Turns "(a.b as T).d.e" into "(a != null) && (a.b is T) && ((a.b as T).d != null)" /// </summary> Expression BuildCondition(Expression targetExpr) { var parts = GetConditionParts(targetExpr); Expression condition = null; foreach (var part in parts) { if (condition == null) { // first condition = new ParenthesizedExpression(part); } else { condition = new BinaryOperatorExpression(new ParenthesizedExpression(part), BinaryOperatorType.LogicalAnd, condition); } } return condition; }
/// <summary> /// Returns the existing expression plus the specified integer value. /// The old <paramref name="expr"/> object is not modified, but might be a subobject on the new expression /// (and thus its parent property is modified). /// </summary> public static Expression AddInteger(Expression expr, int value) { PrimitiveExpression pe = expr as PrimitiveExpression; if (pe != null && pe.Value is int) { int newVal = (int)pe.Value + value; return new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); } BinaryOperatorExpression boe = expr as BinaryOperatorExpression; if (boe != null && boe.Op == BinaryOperatorType.Add) { // clone boe: boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right); boe.Right = AddInteger(boe.Right, value); if (boe.Right is PrimitiveExpression && ((PrimitiveExpression)boe.Right).Value is int) { int newVal = (int)((PrimitiveExpression)boe.Right).Value; if (newVal == 0) { return boe.Left; } else if (newVal < 0) { ((PrimitiveExpression)boe.Right).Value = -newVal; boe.Op = BinaryOperatorType.Subtract; } } return boe; } if (boe != null && boe.Op == BinaryOperatorType.Subtract) { pe = boe.Right as PrimitiveExpression; if (pe != null && pe.Value is int) { int newVal = (int)pe.Value - value; if (newVal == 0) return boe.Left; // clone boe: boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right); if (newVal < 0) { newVal = -newVal; boe.Op = BinaryOperatorType.Add; } boe.Right = new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); return boe; } } BinaryOperatorType opType = BinaryOperatorType.Add; if (value < 0) { value = -value; opType = BinaryOperatorType.Subtract; } return new BinaryOperatorExpression(expr, opType, new PrimitiveExpression(value, value.ToString(System.Globalization.NumberFormatInfo.InvariantInfo))); }
public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binary, object data) { int? myPrecedence = GetPrecedence(binary); if (GetPrecedence(binary.Left) > myPrecedence) { binary.Left = Deparenthesize(binary.Left); } if (GetPrecedence(binary.Right) > myPrecedence) { binary.Right = Deparenthesize(binary.Right); } // Associativity if (GetPrecedence(binary.Left) == myPrecedence && myPrecedence.HasValue) { binary.Left = Deparenthesize(binary.Left); } return base.VisitBinaryOperatorExpression(binary, data); }
/// <summary> /// We have to replace code such as: /// doc.FirstName ?? "" /// Into /// doc.FirstName != null ? doc.FirstName : "" /// Because we use DynamicNullObject instead of null, and that preserve the null coallasing semantics. /// </summary> public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { if(binaryOperatorExpression.Op==BinaryOperatorType.NullCoalescing) { var node = new ConditionalExpression( new BinaryOperatorExpression(binaryOperatorExpression.Left, BinaryOperatorType.ReferenceInequality, new PrimitiveExpression(null, null)), binaryOperatorExpression.Left, binaryOperatorExpression.Right ); ReplaceCurrentNode(node); return null; } return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data); }
public override void GenerateCode(List<AbstractNode> nodes, IList items) { TypeReference intReference = new TypeReference("System.Int32"); MethodDeclaration method = new MethodDeclaration("GetHashCode", Modifiers.Public | Modifiers.Override, intReference, null, null); Expression expr = CallGetHashCode(new IdentifierExpression(currentClass.Fields[0].Name)); for (int i = 1; i < currentClass.Fields.Count; i++) { IdentifierExpression identifier = new IdentifierExpression(currentClass.Fields[i].Name); expr = new BinaryOperatorExpression(expr, BinaryOperatorType.ExclusiveOr, CallGetHashCode(identifier)); } method.Body = new BlockStatement(); method.Body.AddChild(new ReturnStatement(expr)); nodes.Add(method); TypeReference boolReference = new TypeReference("System.Boolean"); TypeReference objectReference = new TypeReference("System.Object"); method = new MethodDeclaration("Equals", Modifiers.Public | Modifiers.Override, boolReference, null, null); method.Parameters.Add(new ParameterDeclarationExpression(objectReference, "obj")); method.Body = new BlockStatement(); TypeReference currentType = ConvertType(currentClass.DefaultReturnType); expr = new TypeOfIsExpression(new IdentifierExpression("obj"), currentType); expr = new ParenthesizedExpression(expr); expr = new UnaryOperatorExpression(expr, UnaryOperatorType.Not); method.Body.AddChild(new IfElseStatement(expr, new ReturnStatement(new PrimitiveExpression(false, "false")))); expr = new BinaryOperatorExpression(new ThisReferenceExpression(), BinaryOperatorType.Equality, new IdentifierExpression("obj")); method.Body.AddChild(new IfElseStatement(expr, new ReturnStatement(new PrimitiveExpression(true, "true")))); VariableDeclaration var = new VariableDeclaration("my" + currentClass.Name, new CastExpression(currentType, new IdentifierExpression("obj"), CastType.Cast), currentType); method.Body.AddChild(new LocalVariableDeclaration(var)); expr = TestEquality(var.Name, currentClass.Fields[0]); for (int i = 1; i < currentClass.Fields.Count; i++) { expr = new BinaryOperatorExpression(expr, BinaryOperatorType.LogicalAnd, TestEquality(var.Name, currentClass.Fields[i])); } method.Body.AddChild(new ReturnStatement(expr)); nodes.Add(method); }
public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { bool leftdangerous = false; bool rightdangerous = false; if(binaryOperatorExpression.Op== BinaryOperatorType.Equality) { if(binaryOperatorExpression.Left is PrimitiveExpression) { PrimitiveExpression prim = (PrimitiveExpression) binaryOperatorExpression.Left; if (prim.LiteralFormat == LiteralFormat.DecimalNumber) leftdangerous = true; } else if (binaryOperatorExpression.Left is IdentifierExpression) { IdentifierExpression idexpr = (IdentifierExpression) binaryOperatorExpression.Left; if (_doublefloatvariables.Contains(idexpr.Identifier)) { leftdangerous = true; } } if (binaryOperatorExpression.Right is PrimitiveExpression) { PrimitiveExpression prim = (PrimitiveExpression)binaryOperatorExpression.Right; if (prim.LiteralFormat == LiteralFormat.DecimalNumber) rightdangerous = true; } else if (binaryOperatorExpression.Right is IdentifierExpression) { IdentifierExpression idexpr = (IdentifierExpression)binaryOperatorExpression.Right; if (_doublefloatvariables.Contains(idexpr.Identifier)) { rightdangerous = true; } } if(leftdangerous || rightdangerous) { UnlockWith(binaryOperatorExpression); } } return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data); }
// The following conversions are implemented: // a == null -> a Is Nothing // a != null -> a Is Not Nothing // i++ / ++i as statement: convert to i += 1 // i-- / --i as statement: convert to i -= 1 // ForStatement -> ForNextStatement when for-loop is simple // if (Event != null) Event(this, bla); -> RaiseEvent Event(this, bla) // Casts to value types are marked as conversions public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { if (binaryOperatorExpression.Op == BinaryOperatorType.Equality || binaryOperatorExpression.Op == BinaryOperatorType.InEquality) { if (IsNullLiteralExpression(binaryOperatorExpression.Left)) { Expression tmp = binaryOperatorExpression.Left; binaryOperatorExpression.Left = binaryOperatorExpression.Right; binaryOperatorExpression.Right = tmp; } if (IsNullLiteralExpression(binaryOperatorExpression.Right)) { if (binaryOperatorExpression.Op == BinaryOperatorType.Equality) { binaryOperatorExpression.Op = BinaryOperatorType.ReferenceEquality; } else { binaryOperatorExpression.Op = BinaryOperatorType.ReferenceInequality; } } } return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data); }
public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { base.VisitBinaryOperatorExpression(binaryOperatorExpression, data); if (IsEmptyStringLiteral(binaryOperatorExpression.Right)) { if (binaryOperatorExpression.Op == BinaryOperatorType.Equality) { ReplaceCurrentNode(CallStringIsNullOrEmpty(binaryOperatorExpression.Left)); } else if (binaryOperatorExpression.Op == BinaryOperatorType.InEquality) { ReplaceCurrentNode(new UnaryOperatorExpression(CallStringIsNullOrEmpty(binaryOperatorExpression.Left), UnaryOperatorType.Not)); } } else if (IsEmptyStringLiteral(binaryOperatorExpression.Left)) { if (binaryOperatorExpression.Op == BinaryOperatorType.Equality) { ReplaceCurrentNode(CallStringIsNullOrEmpty(binaryOperatorExpression.Right)); } else if (binaryOperatorExpression.Op == BinaryOperatorType.InEquality) { ReplaceCurrentNode(new UnaryOperatorExpression(CallStringIsNullOrEmpty(binaryOperatorExpression.Right), UnaryOperatorType.Not)); } } return null; }
public override object TrackedVisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { Expression left = binaryOperatorExpression.Left; TypeReference leftType = GetExpressionType(left); if (leftType != null && (leftType.RankSpecifier == null || leftType.RankSpecifier.Length == 0) && (binaryOperatorExpression.Right is PrimitiveExpression)) { string fullName = GetFullName(leftType); if (types.Contains(fullName)) { Expression minValue = (Expression) values[fullName]; PrimitiveExpression nullRight = (PrimitiveExpression) binaryOperatorExpression.Right; if (nullRight.Value == null) { BinaryOperatorExpression replacedBinOP = binaryOperatorExpression; replacedBinOP.Right = minValue; ReplaceCurrentNode(replacedBinOP); } } } return base.TrackedVisitBinaryOperatorExpression(binaryOperatorExpression, data); }
public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { base.VisitBinaryOperatorExpression(binaryOperatorExpression, data); if (resolver.CompilationUnit == null) return null; switch (binaryOperatorExpression.Op) { case BinaryOperatorType.Equality: case BinaryOperatorType.InEquality: ConvertEqualityToReferenceEqualityIfRequired(binaryOperatorExpression); break; case BinaryOperatorType.Add: ConvertArgumentsForStringConcatenationIfRequired(binaryOperatorExpression); break; case BinaryOperatorType.Divide: ConvertDivisionToIntegerDivisionIfRequired(binaryOperatorExpression); break; } return null; }
public override object TrackedVisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { if (binaryOperatorExpression.Op == BinaryOperatorType.UnsignedShiftRight) { binaryOperatorExpression.Op = BinaryOperatorType.ShiftRight; CastExpression castExpression = GetCastExpression(binaryOperatorExpression); ReplaceCurrentNode(castExpression); } else if (binaryOperatorExpression.Op == BinaryOperatorType.UnsignedShiftRightAssign) { Expression left = binaryOperatorExpression.Left; Expression right = new BinaryOperatorExpression(left, BinaryOperatorType.ShiftRight, binaryOperatorExpression.Right); right.Parent = binaryOperatorExpression.Parent; CastExpression castExpression = GetCastExpression((BinaryOperatorExpression) right); right.Parent = castExpression; AssignmentExpression assignment = new AssignmentExpression(left, AssignmentOperatorType.Assign, castExpression); assignment.Parent = binaryOperatorExpression.Parent; ReplaceCurrentNode(assignment); } return base.TrackedVisitBinaryOperatorExpression(binaryOperatorExpression, data); }
public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { bool lhs = binaryOperatorExpression.Left.AcceptVisitor(this, data) == SymbolDefined; bool rhs = binaryOperatorExpression.Right.AcceptVisitor(this, data) == SymbolDefined; bool result; switch (binaryOperatorExpression.Op) { case BinaryOperatorType.LogicalAnd: result = lhs && rhs; break; case BinaryOperatorType.LogicalOr: result = lhs || rhs; break; case BinaryOperatorType.Equality: result = lhs == rhs; break; case BinaryOperatorType.InEquality: result = lhs != rhs; break; default: return null; } return result ? SymbolDefined : null; }
void ConjunctionExpr( //#line 1977 "VBNET.ATG" out Expression outExpr) { //#line 1979 "VBNET.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; Location startLocation = la.Location; NotExpr( //#line 1983 "VBNET.ATG" out outExpr); while (la.kind == 60 || la.kind == 61) { if (la.kind == 60) { lexer.NextToken(); //#line 1986 "VBNET.ATG" op = BinaryOperatorType.BitwiseAnd; } else { lexer.NextToken(); //#line 1987 "VBNET.ATG" op = BinaryOperatorType.LogicalAnd; } NotExpr( //#line 1989 "VBNET.ATG" out expr); //#line 1989 "VBNET.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; } }
void ConditionalExpression( //#line 1890 "VBNET.ATG" out Expression expr) { //#line 1892 "VBNET.ATG" ConditionalExpression conditionalExpression = new ConditionalExpression(); BinaryOperatorExpression binaryOperatorExpression = new BinaryOperatorExpression(); conditionalExpression.StartLocation = binaryOperatorExpression.StartLocation = la.Location; Expression condition = null; Expression trueExpr = null; Expression falseExpr = null; Expect(135); Expect(37); Expr( //#line 1901 "VBNET.ATG" out condition); Expect(22); Expr( //#line 1901 "VBNET.ATG" out trueExpr); if (la.kind == 22) { lexer.NextToken(); Expr( //#line 1901 "VBNET.ATG" out falseExpr); } Expect(38); //#line 1903 "VBNET.ATG" if(falseExpr != null) { conditionalExpression.Condition = condition; conditionalExpression.TrueExpression = trueExpr; conditionalExpression.FalseExpression = falseExpr; conditionalExpression.EndLocation = t.EndLocation; expr = conditionalExpression; } else { binaryOperatorExpression.Left = condition; binaryOperatorExpression.Right = trueExpr; binaryOperatorExpression.Op = BinaryOperatorType.NullCoalescing; binaryOperatorExpression.EndLocation = t.EndLocation; expr = binaryOperatorExpression; } }
void SimpleNonInvocationExpression( //#line 1723 "VBNET.ATG" out Expression pexpr) { //#line 1725 "VBNET.ATG" Expression expr; CollectionInitializerExpression cie; TypeReference type = null; string name = String.Empty; Location startLocation = la.Location; pexpr = null; if (StartOf(34)) { switch (la.kind) { case 3: { lexer.NextToken(); //#line 1735 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 4: { lexer.NextToken(); //#line 1736 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 7: { lexer.NextToken(); //#line 1737 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 6: { lexer.NextToken(); //#line 1738 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 5: { lexer.NextToken(); //#line 1739 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 9: { lexer.NextToken(); //#line 1740 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 8: { lexer.NextToken(); //#line 1741 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 217: { lexer.NextToken(); //#line 1743 "VBNET.ATG" pexpr = new PrimitiveExpression(true, "true"); break; } case 122: { lexer.NextToken(); //#line 1744 "VBNET.ATG" pexpr = new PrimitiveExpression(false, "false"); break; } case 165: { lexer.NextToken(); //#line 1745 "VBNET.ATG" pexpr = new PrimitiveExpression(null, "null"); break; } case 37: { lexer.NextToken(); Expr( //#line 1746 "VBNET.ATG" out expr); Expect(38); //#line 1746 "VBNET.ATG" pexpr = new ParenthesizedExpression(expr); break; } case 2: case 58: case 62: case 64: case 65: case 66: case 67: case 70: case 87: case 98: case 104: case 107: case 116: case 121: case 126: case 133: case 139: case 143: case 146: case 147: case 170: case 176: case 178: case 184: case 203: case 212: case 213: case 223: case 224: case 230: { Identifier(); //#line 1748 "VBNET.ATG" pexpr = new IdentifierExpression(t.val); pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; if ( //#line 1751 "VBNET.ATG" la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) { lexer.NextToken(); Expect(169); TypeArgumentList( //#line 1752 "VBNET.ATG" ((IdentifierExpression)pexpr).TypeArguments); Expect(38); } break; } case 68: case 71: case 82: case 99: case 100: case 109: case 141: case 151: case 168: case 196: case 201: case 202: case 208: case 221: case 222: case 225: { //#line 1754 "VBNET.ATG" string val = String.Empty; if (StartOf(12)) { PrimitiveTypeName( //#line 1755 "VBNET.ATG" out val); } else if (la.kind == 168) { lexer.NextToken(); //#line 1755 "VBNET.ATG" val = "System.Object"; } else SynErr(280); //#line 1756 "VBNET.ATG" pexpr = new TypeReferenceExpression(new TypeReference(val, true)); break; } case 153: { lexer.NextToken(); //#line 1757 "VBNET.ATG" pexpr = new ThisReferenceExpression(); break; } case 158: case 159: { //#line 1758 "VBNET.ATG" Expression retExpr = null; if (la.kind == 158) { lexer.NextToken(); //#line 1759 "VBNET.ATG" retExpr = new BaseReferenceExpression() { StartLocation = t.Location, EndLocation = t.EndLocation }; } else if (la.kind == 159) { lexer.NextToken(); //#line 1760 "VBNET.ATG" retExpr = new ClassReferenceExpression() { StartLocation = t.Location, EndLocation = t.EndLocation }; } else SynErr(281); Expect(26); IdentifierOrKeyword( //#line 1762 "VBNET.ATG" out name); //#line 1762 "VBNET.ATG" pexpr = new MemberReferenceExpression(retExpr, name) { StartLocation = startLocation, EndLocation = t.EndLocation }; break; } case 130: { lexer.NextToken(); Expect(26); Identifier(); //#line 1764 "VBNET.ATG" type = new TypeReference(t.val ?? ""); //#line 1766 "VBNET.ATG" type.IsGlobal = true; //#line 1767 "VBNET.ATG" pexpr = new TypeReferenceExpression(type); break; } case 162: { ObjectCreateExpression( //#line 1768 "VBNET.ATG" out expr); //#line 1768 "VBNET.ATG" pexpr = expr; break; } case 35: { CollectionInitializer( //#line 1769 "VBNET.ATG" out cie); //#line 1769 "VBNET.ATG" pexpr = cie; break; } case 94: case 106: case 219: { //#line 1771 "VBNET.ATG" CastType castType = CastType.Cast; if (la.kind == 106) { lexer.NextToken(); } else if (la.kind == 94) { lexer.NextToken(); //#line 1773 "VBNET.ATG" castType = CastType.Conversion; } else if (la.kind == 219) { lexer.NextToken(); //#line 1774 "VBNET.ATG" castType = CastType.TryCast; } else SynErr(282); Expect(37); Expr( //#line 1776 "VBNET.ATG" out expr); Expect(22); TypeName( //#line 1776 "VBNET.ATG" out type); Expect(38); //#line 1777 "VBNET.ATG" pexpr = new CastExpression(type, expr, castType); break; } case 76: case 77: case 78: case 79: case 80: case 81: case 83: case 85: case 86: case 90: case 91: case 92: case 93: case 95: case 96: case 97: { CastTarget( //#line 1778 "VBNET.ATG" out type); Expect(37); Expr( //#line 1778 "VBNET.ATG" out expr); Expect(38); //#line 1778 "VBNET.ATG" pexpr = new CastExpression(type, expr, CastType.PrimitiveConversion); break; } case 57: { lexer.NextToken(); Expr( //#line 1779 "VBNET.ATG" out expr); //#line 1779 "VBNET.ATG" pexpr = new AddressOfExpression(expr); break; } case 129: { lexer.NextToken(); Expect(37); GetTypeTypeName( //#line 1780 "VBNET.ATG" out type); Expect(38); //#line 1780 "VBNET.ATG" pexpr = new TypeOfExpression(type); break; } case 220: { lexer.NextToken(); SimpleExpr( //#line 1781 "VBNET.ATG" out expr); Expect(144); TypeName( //#line 1781 "VBNET.ATG" out type); //#line 1781 "VBNET.ATG" pexpr = new TypeOfIsExpression(expr, type); break; } case 135: { ConditionalExpression( //#line 1782 "VBNET.ATG" out pexpr); break; } case 10: case 16: case 17: case 18: case 19: { XmlLiteralExpression( //#line 1783 "VBNET.ATG" out pexpr); break; } } } else if (StartOf(35)) { if (la.kind == 26) { lexer.NextToken(); if (la.kind == 10) { lexer.NextToken(); IdentifierOrKeyword( //#line 1789 "VBNET.ATG" out name); Expect(11); //#line 1790 "VBNET.ATG" pexpr = new XmlMemberAccessExpression(null, XmlAxisType.Element, name, true) { StartLocation = startLocation, EndLocation = t.EndLocation }; } else if (StartOf(33)) { IdentifierOrKeyword( //#line 1791 "VBNET.ATG" out name); //#line 1792 "VBNET.ATG" pexpr = new MemberReferenceExpression(null, name) { StartLocation = startLocation, EndLocation = t.EndLocation }; } else SynErr(283); } else if (la.kind == 29) { lexer.NextToken(); IdentifierOrKeyword( //#line 1794 "VBNET.ATG" out name); //#line 1794 "VBNET.ATG" pexpr = new BinaryOperatorExpression(null, BinaryOperatorType.DictionaryAccess, new PrimitiveExpression(name, name) { StartLocation = t.Location, EndLocation = t.EndLocation }); } else { //#line 1795 "VBNET.ATG" XmlAxisType axisType = XmlAxisType.Element; bool isXmlIdentifier = false; if (la.kind == 27) { lexer.NextToken(); //#line 1796 "VBNET.ATG" axisType = XmlAxisType.Descendents; } else if (la.kind == 28) { lexer.NextToken(); //#line 1796 "VBNET.ATG" axisType = XmlAxisType.Attribute; } else SynErr(284); if (la.kind == 10) { lexer.NextToken(); //#line 1797 "VBNET.ATG" isXmlIdentifier = true; } IdentifierOrKeyword( //#line 1797 "VBNET.ATG" out name); if (la.kind == 11) { lexer.NextToken(); } //#line 1798 "VBNET.ATG" pexpr = new XmlMemberAccessExpression(null, axisType, name, isXmlIdentifier); } } else SynErr(285); //#line 1803 "VBNET.ATG" if (pexpr != null) { pexpr.StartLocation = startLocation; pexpr.EndLocation = t.EndLocation; } }
void MultiplicativeExpr( //#line 2080 "VBNET.ATG" out Expression outExpr) { //#line 2082 "VBNET.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; Location startLocation = la.Location; UnaryExpr( //#line 2086 "VBNET.ATG" out outExpr); while (la.kind == 24 || la.kind == 34) { if (la.kind == 34) { lexer.NextToken(); //#line 2089 "VBNET.ATG" op = BinaryOperatorType.Multiply; } else { lexer.NextToken(); //#line 2090 "VBNET.ATG" op = BinaryOperatorType.Divide; } UnaryExpr( //#line 2092 "VBNET.ATG" out expr); //#line 2092 "VBNET.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; } }
void ModuloExpr( //#line 2068 "VBNET.ATG" out Expression outExpr) { //#line 2069 "VBNET.ATG" Expression expr; Location startLocation = la.Location; IntegerDivisionExpr( //#line 2071 "VBNET.ATG" out outExpr); while (la.kind == 154) { lexer.NextToken(); IntegerDivisionExpr( //#line 2071 "VBNET.ATG" out expr); //#line 2071 "VBNET.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Modulus, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; } }
void ConcatenationExpr( //#line 2046 "VBNET.ATG" out Expression outExpr) { //#line 2047 "VBNET.ATG" Expression expr; Location startLocation = la.Location; AdditiveExpr( //#line 2049 "VBNET.ATG" out outExpr); while (la.kind == 23) { lexer.NextToken(); AdditiveExpr( //#line 2049 "VBNET.ATG" out expr); //#line 2049 "VBNET.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Concat, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; } }
/// <summary> /// Returns the existing expression plus the specified integer value. /// The old <paramref name="expr"/> object is not modified, but might be a subobject on the new expression /// (and thus its parent property is modified). /// </summary> public static Expression AddInteger(Expression expr, int value) { PrimitiveExpression pe = expr as PrimitiveExpression; if (pe != null && pe.Value is int) { int newVal = (int)pe.Value + value; return(new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo))); } BinaryOperatorExpression boe = expr as BinaryOperatorExpression; if (boe != null && boe.Op == BinaryOperatorType.Add) { // clone boe: boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right); boe.Right = AddInteger(boe.Right, value); if (boe.Right is PrimitiveExpression && ((PrimitiveExpression)boe.Right).Value is int) { int newVal = (int)((PrimitiveExpression)boe.Right).Value; if (newVal == 0) { return(boe.Left); } else if (newVal < 0) { ((PrimitiveExpression)boe.Right).Value = -newVal; boe.Op = BinaryOperatorType.Subtract; } } return(boe); } if (boe != null && boe.Op == BinaryOperatorType.Subtract) { pe = boe.Right as PrimitiveExpression; if (pe != null && pe.Value is int) { int newVal = (int)pe.Value - value; if (newVal == 0) { return(boe.Left); } // clone boe: boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right); if (newVal < 0) { newVal = -newVal; boe.Op = BinaryOperatorType.Add; } boe.Right = new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); return(boe); } } BinaryOperatorType opType = BinaryOperatorType.Add; if (value < 0) { value = -value; opType = BinaryOperatorType.Subtract; } return(new BinaryOperatorExpression(expr, opType, new PrimitiveExpression(value, value.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)))); }
void ComparisonExpr( //#line 2002 "VBNET.ATG" out Expression outExpr) { //#line 2004 "VBNET.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; Location startLocation = la.Location; ShiftExpr( //#line 2008 "VBNET.ATG" out outExpr); while (StartOf(40)) { switch (la.kind) { case 40: { lexer.NextToken(); //#line 2011 "VBNET.ATG" op = BinaryOperatorType.LessThan; break; } case 39: { lexer.NextToken(); //#line 2012 "VBNET.ATG" op = BinaryOperatorType.GreaterThan; break; } case 43: { lexer.NextToken(); //#line 2013 "VBNET.ATG" op = BinaryOperatorType.LessThanOrEqual; break; } case 42: { lexer.NextToken(); //#line 2014 "VBNET.ATG" op = BinaryOperatorType.GreaterThanOrEqual; break; } case 41: { lexer.NextToken(); //#line 2015 "VBNET.ATG" op = BinaryOperatorType.InEquality; break; } case 20: { lexer.NextToken(); //#line 2016 "VBNET.ATG" op = BinaryOperatorType.Equality; break; } case 150: { lexer.NextToken(); //#line 2017 "VBNET.ATG" op = BinaryOperatorType.Like; break; } case 144: { lexer.NextToken(); //#line 2018 "VBNET.ATG" op = BinaryOperatorType.ReferenceEquality; break; } case 145: { lexer.NextToken(); //#line 2019 "VBNET.ATG" op = BinaryOperatorType.ReferenceInequality; break; } } if (StartOf(41)) { ShiftExpr( //#line 2022 "VBNET.ATG" out expr); //#line 2022 "VBNET.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; } else if (la.kind == 164) { //#line 2023 "VBNET.ATG" Location startLocation2 = la.Location; lexer.NextToken(); ShiftExpr( //#line 2025 "VBNET.ATG" out expr); //#line 2025 "VBNET.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, new UnaryOperatorExpression(expr, UnaryOperatorType.Not) { StartLocation = startLocation2, EndLocation = t.EndLocation }) { StartLocation = startLocation, EndLocation = t.EndLocation }; } else SynErr(295); } }
void ShiftExpr( //#line 2030 "VBNET.ATG" out Expression outExpr) { //#line 2032 "VBNET.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; Location startLocation = la.Location; ConcatenationExpr( //#line 2036 "VBNET.ATG" out outExpr); while (la.kind == 44 || la.kind == 45) { if (la.kind == 44) { lexer.NextToken(); //#line 2039 "VBNET.ATG" op = BinaryOperatorType.ShiftLeft; } else { lexer.NextToken(); //#line 2040 "VBNET.ATG" op = BinaryOperatorType.ShiftRight; } ConcatenationExpr( //#line 2042 "VBNET.ATG" out expr); //#line 2042 "VBNET.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; } }
public virtual object TrackedVisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data); }
void AdditiveExpr( //#line 2052 "VBNET.ATG" out Expression outExpr) { //#line 2054 "VBNET.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; Location startLocation = la.Location; ModuloExpr( //#line 2058 "VBNET.ATG" out outExpr); while (la.kind == 30 || la.kind == 31) { if (la.kind == 31) { lexer.NextToken(); //#line 2061 "VBNET.ATG" op = BinaryOperatorType.Add; } else { lexer.NextToken(); //#line 2062 "VBNET.ATG" op = BinaryOperatorType.Subtract; } ModuloExpr( //#line 2064 "VBNET.ATG" out expr); //#line 2064 "VBNET.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; } }
public override object TrackedVisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { binaryOperatorExpression.Left.AcceptVisitor(this, data); this.Append(" "); this.Append(NRefactoryToPythonConverter.GetBinaryOperator(binaryOperatorExpression.Op)); this.Append(" "); binaryOperatorExpression.Right.AcceptVisitor(this, data); return null; }
void IntegerDivisionExpr( //#line 2074 "VBNET.ATG" out Expression outExpr) { //#line 2075 "VBNET.ATG" Expression expr; Location startLocation = la.Location; MultiplicativeExpr( //#line 2077 "VBNET.ATG" out outExpr); while (la.kind == 25) { lexer.NextToken(); MultiplicativeExpr( //#line 2077 "VBNET.ATG" out expr); //#line 2077 "VBNET.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.DivideInteger, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; } }
void DisjunctionExpr( //#line 1960 "VBNET.ATG" out Expression outExpr) { //#line 1962 "VBNET.ATG" Expression expr; BinaryOperatorType op = BinaryOperatorType.None; Location startLocation = la.Location; ConjunctionExpr( //#line 1966 "VBNET.ATG" out outExpr); while (la.kind == 175 || la.kind == 177 || la.kind == 236) { if (la.kind == 175) { lexer.NextToken(); //#line 1969 "VBNET.ATG" op = BinaryOperatorType.BitwiseOr; } else if (la.kind == 177) { lexer.NextToken(); //#line 1970 "VBNET.ATG" op = BinaryOperatorType.LogicalOr; } else { lexer.NextToken(); //#line 1971 "VBNET.ATG" op = BinaryOperatorType.ExclusiveOr; } ConjunctionExpr( //#line 1973 "VBNET.ATG" out expr); //#line 1973 "VBNET.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; } }
void ExponentiationExpr( //#line 2117 "VBNET.ATG" out Expression outExpr) { //#line 2118 "VBNET.ATG" Expression expr; Location startLocation = la.Location; SimpleExpr( //#line 2120 "VBNET.ATG" out outExpr); while (la.kind == 32) { lexer.NextToken(); SimpleExpr( //#line 2120 "VBNET.ATG" out expr); //#line 2120 "VBNET.ATG" outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Power, expr) { StartLocation = startLocation, EndLocation = t.EndLocation }; } }
void SimpleExpr( //#line 1693 "VBNET.ATG" out Expression pexpr) { //#line 1694 "VBNET.ATG" string name; Location startLocation = la.Location; SimpleNonInvocationExpression( //#line 1697 "VBNET.ATG" out pexpr); while (StartOf(32)) { if (la.kind == 26) { lexer.NextToken(); if (la.kind == 10) { lexer.NextToken(); IdentifierOrKeyword( //#line 1700 "VBNET.ATG" out name); Expect(11); //#line 1701 "VBNET.ATG" pexpr = new XmlMemberAccessExpression(pexpr, XmlAxisType.Element, name, true); } else if (StartOf(33)) { IdentifierOrKeyword( //#line 1702 "VBNET.ATG" out name); //#line 1703 "VBNET.ATG" pexpr = new MemberReferenceExpression(pexpr, name) { StartLocation = startLocation, EndLocation = t.EndLocation }; } else SynErr(278); if ( //#line 1705 "VBNET.ATG" la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) { lexer.NextToken(); Expect(169); TypeArgumentList( //#line 1706 "VBNET.ATG" ((MemberReferenceExpression)pexpr).TypeArguments); Expect(38); } } else if (la.kind == 29) { lexer.NextToken(); IdentifierOrKeyword( //#line 1708 "VBNET.ATG" out name); //#line 1708 "VBNET.ATG" pexpr = new BinaryOperatorExpression(pexpr, BinaryOperatorType.DictionaryAccess, new PrimitiveExpression(name, name) { StartLocation = t.Location, EndLocation = t.EndLocation }); } else if (la.kind == 27 || la.kind == 28) { //#line 1709 "VBNET.ATG" XmlAxisType type = XmlAxisType.Attribute; bool isXmlName = false; if (la.kind == 28) { lexer.NextToken(); } else if (la.kind == 27) { lexer.NextToken(); //#line 1710 "VBNET.ATG" type = XmlAxisType.Descendents; } else SynErr(279); if (la.kind == 10) { lexer.NextToken(); //#line 1710 "VBNET.ATG" isXmlName = true; } IdentifierOrKeyword( //#line 1710 "VBNET.ATG" out name); if (la.kind == 11) { lexer.NextToken(); } //#line 1711 "VBNET.ATG" pexpr = new XmlMemberAccessExpression(pexpr, type, name, isXmlName); } else { InvocationExpression( //#line 1712 "VBNET.ATG" ref pexpr); } } //#line 1716 "VBNET.ATG" if (pexpr != null) { pexpr.StartLocation = startLocation; pexpr.EndLocation = t.EndLocation; } }