public void VBNetSimpleTypeOfIsExpression() { TypeOfIsExpression ce = ParseUtilVBNet.ParseExpression <TypeOfIsExpression>("TypeOf o Is MyObject"); Assert.AreEqual("MyObject", ce.TypeReference.Type); Assert.IsTrue(ce.Expression is IdentifierExpression); }
public void NullableIsExpression() { TypeOfIsExpression ce = ParseUtilCSharp.ParseExpression <TypeOfIsExpression>("o is int?"); Assert.AreEqual("System.Nullable", ce.TypeReference.Type); Assert.AreEqual("System.Int32", ce.TypeReference.GenericTypes[0].Type); Assert.IsTrue(ce.Expression is IdentifierExpression); }
public void VBNetGenericTypeOfIsExpression() { TypeOfIsExpression ce = ParseUtilVBNet.ParseExpression <TypeOfIsExpression>("TypeOf o Is List(of T)"); Assert.AreEqual("List", ce.TypeReference.Type); Assert.AreEqual("T", ce.TypeReference.GenericTypes[0].Type); Assert.IsTrue(ce.Expression is IdentifierExpression); }
public void GenericArrayIsExpression() { TypeOfIsExpression ce = ParseUtilCSharp.ParseExpression <TypeOfIsExpression>("o is List<string>[]"); Assert.AreEqual("List", ce.TypeReference.Type); Assert.AreEqual("System.String", ce.TypeReference.GenericTypes[0].Type); Assert.AreEqual(new int[] { 0 }, ce.TypeReference.RankSpecifier); Assert.IsTrue(ce.Expression is IdentifierExpression); }
private void Visit( TypeOfIsExpression expression, QualifiedModuleName module, Declaration scope, Declaration parent) { Visit(expression.Expression, module, scope, parent); Visit(expression.TypeExpression, module, scope, parent); }
public virtual object Visit(TypeOfIsExpression typeOfIsExpression, object data) { Debug.Assert(typeOfIsExpression != null); Debug.Assert(typeOfIsExpression.Expression != null); Debug.Assert(typeOfIsExpression.TypeReference != null); typeOfIsExpression.Expression.AcceptVisitor(this, data); typeOfIsExpression.TypeReference.AcceptVisitor(this, data); return(data); }
private void Visit( TypeOfIsExpression expression, QualifiedModuleName module, Declaration scope, Declaration parent, bool isAssignmentTarget, bool hasExplicitLetStatement) { Visit((dynamic)expression.Expression, module, scope, parent, false, false); Visit((dynamic)expression.TypeExpression, module, scope, parent, false, false); }
public void NullableIsExpressionInBinaryOperatorExpression() { BinaryOperatorExpression boe; boe = ParseUtilCSharp.ParseExpression <BinaryOperatorExpression>("o is int? == true"); TypeOfIsExpression ce = (TypeOfIsExpression)boe.Left; Assert.AreEqual("System.Nullable", ce.TypeReference.Type); Assert.AreEqual("System.Int32", ce.TypeReference.GenericTypes[0].Type); Assert.IsTrue(ce.Expression is IdentifierExpression); }
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 VisitTypeOfIsExpression(TypeOfIsExpression stmt, object data) { Console.WriteLine("TypeOfIsExpression"); IntegrateTemporaryVariableVisitorOptions options = (IntegrateTemporaryVariableVisitorOptions)data; if (IsExpressionToReplace(stmt.Expression, options)) { if (IsUnary(options.Initializer) || (options.Initializer is BinaryOperatorExpression && IsShiftOrHigher(((BinaryOperatorExpression)options.Initializer).Op))) { options.Changes.Add(ReplaceExpression(stmt.Expression, options.Initializer, options)); } else { options.Changes.Add(ReplaceExpression(stmt.Expression, new ParenthesizedExpression(options.Initializer), options)); } return(null); } else { return(base.VisitTypeOfIsExpression(stmt, data)); } }
private void RelationalExpr(ref Expression outExpr) { BinaryOperatorType none = BinaryOperatorType.None; this.ShiftExpr(ref outExpr); while (this.StartOf(0x1c)) { if (this.StartOf(0x1d)) { Expression expression; if (this.la.kind == 0x17) { base.lexer.NextToken(); none = BinaryOperatorType.LessThan; } else if (this.la.kind == 0x16) { base.lexer.NextToken(); none = BinaryOperatorType.GreaterThan; } else if (this.la.kind == 0x24) { base.lexer.NextToken(); none = BinaryOperatorType.LessThanOrEqual; } else if (this.la.kind == 0x23) { base.lexer.NextToken(); none = BinaryOperatorType.GreaterThanOrEqual; } else { base.SynErr(0xba); } this.UnaryExpr(out expression); this.ShiftExpr(ref expression); outExpr = new BinaryOperatorExpression(outExpr, none, expression); } else { TypeReference reference; if (this.la.kind == 0x54) { base.lexer.NextToken(); this.TypeWithRestriction(out reference, false, false); if ((this.la.kind == 12) && !Tokens.CastFollower[this.Peek(1).kind]) { this.NullableQuestionMark(ref reference); } outExpr = new TypeOfIsExpression(outExpr, reference); } else { if (this.la.kind == 0x31) { base.lexer.NextToken(); this.TypeWithRestriction(out reference, false, false); if ((this.la.kind == 12) && !Tokens.CastFollower[this.Peek(1).kind]) { this.NullableQuestionMark(ref reference); } outExpr = new CastExpression(reference, outExpr, CastType.TryCast); continue; } base.SynErr(0xbb); } } } }
public virtual object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { throw new global::System.NotImplementedException("TypeOfIsExpression"); }
public override object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { typeOfIsExpression.Expression.Parent = typeOfIsExpression; typeOfIsExpression.TypeReference.Parent = typeOfIsExpression; return(base.VisitTypeOfIsExpression(typeOfIsExpression, data)); }
public override void GenerateCode(List <AbstractNode> nodes, IList items) { TypeReference intReference = new TypeReference("System.Int32", true); MethodDeclaration method = new MethodDeclaration { Name = "GetHashCode", Modifier = Modifiers.Public | Modifiers.Override, TypeReference = intReference, Body = new BlockStatement() }; VariableDeclaration var; var = new VariableDeclaration("hashCode", new PrimitiveExpression(0, "0"), intReference); method.Body.AddChild(new LocalVariableDeclaration(var)); bool usePrimeMultiplication = currentClass.ProjectContent.Language == LanguageProperties.CSharp; BlockStatement hashCalculationBlock; if (usePrimeMultiplication) { hashCalculationBlock = new BlockStatement(); method.Body.AddChild(new UncheckedStatement(hashCalculationBlock)); } else { hashCalculationBlock = method.Body; } int fieldIndex = 0; Expression expr; foreach (IField field in currentClass.Fields) { if (field.IsStatic) { continue; } expr = new InvocationExpression(new MemberReferenceExpression(new IdentifierExpression(field.Name), "GetHashCode")); if (usePrimeMultiplication) { int prime = largePrimes[fieldIndex++ % largePrimes.Length]; expr = new AssignmentExpression( new IdentifierExpression(var.Name), AssignmentOperatorType.Add, new BinaryOperatorExpression(new PrimitiveExpression(prime, prime.ToString()), BinaryOperatorType.Multiply, expr)); } else { expr = new AssignmentExpression(new IdentifierExpression(var.Name), AssignmentOperatorType.ExclusiveOr, expr); } if (IsValueType(field.ReturnType)) { hashCalculationBlock.AddChild(new ExpressionStatement(expr)); } else { hashCalculationBlock.AddChild(new IfElseStatement( new BinaryOperatorExpression(new IdentifierExpression(field.Name), BinaryOperatorType.ReferenceInequality, new PrimitiveExpression(null, "null")), new ExpressionStatement(expr) )); } } method.Body.AddChild(new ReturnStatement(new IdentifierExpression(var.Name))); nodes.Add(method); TypeReference boolReference = new TypeReference("System.Boolean", true); TypeReference objectReference = new TypeReference("System.Object", true); method = new MethodDeclaration { Name = "Equals", Modifier = Modifiers.Public | Modifiers.Override, TypeReference = boolReference }; method.Parameters.Add(new ParameterDeclarationExpression(objectReference, "obj")); method.Body = new BlockStatement(); TypeReference currentType = ConvertType(currentClass.DefaultReturnType); if (currentClass.ClassType == Dom.ClassType.Struct) { // return obj is CurrentType && Equals((CurrentType)obj); expr = new TypeOfIsExpression(new IdentifierExpression("obj"), currentType); expr = new ParenthesizedExpression(expr); expr = new BinaryOperatorExpression( expr, BinaryOperatorType.LogicalAnd, new InvocationExpression( new IdentifierExpression("Equals"), new List <Expression> { new CastExpression(currentType, new IdentifierExpression("obj"), CastType.Cast) })); method.Body.AddChild(new ReturnStatement(expr)); nodes.Add(method); // IEquatable implementation: method = new MethodDeclaration { Name = "Equals", Modifier = Modifiers.Public | Modifiers.Override, TypeReference = boolReference }; method.Parameters.Add(new ParameterDeclarationExpression(currentType, "other")); method.Body = new BlockStatement(); } else { method.Body.AddChild(new LocalVariableDeclaration(new VariableDeclaration( "other", new CastExpression(currentType, new IdentifierExpression("obj"), CastType.TryCast), currentType))); method.Body.AddChild(new IfElseStatement( new BinaryOperatorExpression(new IdentifierExpression("other"), BinaryOperatorType.ReferenceEquality, new PrimitiveExpression(null, "null")), new ReturnStatement(new PrimitiveExpression(false, "false")))); // expr = new BinaryOperatorExpression(new ThisReferenceExpression(), // BinaryOperatorType.ReferenceEquality, // new IdentifierExpression("obj")); // method.Body.AddChild(new IfElseStatement(expr, new ReturnStatement(new PrimitiveExpression(true, "true")))); } expr = null; foreach (IField field in currentClass.Fields) { if (field.IsStatic) { continue; } if (expr == null) { expr = TestEquality("other", field); } else { expr = new BinaryOperatorExpression(expr, BinaryOperatorType.LogicalAnd, TestEquality("other", field)); } } method.Body.AddChild(new ReturnStatement(expr ?? new PrimitiveExpression(true, "true"))); nodes.Add(method); }
public override object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { return(CreateResult(typeof(System.Boolean).FullName)); }
public virtual object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { Debug.Assert((typeOfIsExpression != null)); Debug.Assert((typeOfIsExpression.Expression != null)); Debug.Assert((typeOfIsExpression.TypeReference != null)); typeOfIsExpression.Expression.AcceptVisitor(this, data); return typeOfIsExpression.TypeReference.AcceptVisitor(this, data); }
private bool IsMatch(TypeOfIsExpression left, TypeOfIsExpression data) { return(false); }
void RelationalExpr( #line 2209 "cs.ATG" ref Expression outExpr) { #line 2211 "cs.ATG" TypeReference type; Expression expr; BinaryOperatorType op = BinaryOperatorType.None; ShiftExpr( #line 2216 "cs.ATG" ref outExpr); while (StartOf(37)) { if (StartOf(38)) { if (la.kind == 23) { lexer.NextToken(); #line 2218 "cs.ATG" op = BinaryOperatorType.LessThan; } else if (la.kind == 22) { lexer.NextToken(); #line 2219 "cs.ATG" op = BinaryOperatorType.GreaterThan; } else if (la.kind == 36) { lexer.NextToken(); #line 2220 "cs.ATG" op = BinaryOperatorType.LessThanOrEqual; } else if (la.kind == 35) { lexer.NextToken(); #line 2221 "cs.ATG" op = BinaryOperatorType.GreaterThanOrEqual; } else SynErr(216); UnaryExpr( #line 2223 "cs.ATG" out expr); ShiftExpr( #line 2224 "cs.ATG" ref expr); #line 2225 "cs.ATG" outExpr = new BinaryOperatorExpression(outExpr, op, expr); } else { if (la.kind == 85) { lexer.NextToken(); TypeWithRestriction( #line 2228 "cs.ATG" out type, false, false); if ( #line 2229 "cs.ATG" la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) { NullableQuestionMark( #line 2230 "cs.ATG" ref type); } #line 2231 "cs.ATG" outExpr = new TypeOfIsExpression(outExpr, type); } else if (la.kind == 50) { lexer.NextToken(); TypeWithRestriction( #line 2233 "cs.ATG" out type, false, false); if ( #line 2234 "cs.ATG" la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) { NullableQuestionMark( #line 2235 "cs.ATG" ref type); } #line 2236 "cs.ATG" outExpr = new CastExpression(type, outExpr, CastType.TryCast); } else SynErr(217); } } }
private void Visit(TypeOfIsExpression expression, Declaration parent, IBoundExpression withExpression) { Visit(expression.Expression, parent, withExpression); Visit(expression.TypeExpression, parent, withExpression); }
public virtual object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { Debug.Assert((typeOfIsExpression != null)); Debug.Assert((typeOfIsExpression.Expression != null)); Debug.Assert((typeOfIsExpression.TypeReference != null)); nodeStack.Push(typeOfIsExpression.Expression); typeOfIsExpression.Expression.AcceptVisitor(this, data); typeOfIsExpression.Expression = ((Expression)(nodeStack.Pop())); nodeStack.Push(typeOfIsExpression.TypeReference); typeOfIsExpression.TypeReference.AcceptVisitor(this, data); typeOfIsExpression.TypeReference = ((TypeReference)(nodeStack.Pop())); return null; }
public sealed override object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { BeginVisit(typeOfIsExpression); object result = TrackedVisitTypeOfIsExpression(typeOfIsExpression, data); EndVisit(typeOfIsExpression); return result; }
public override object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { return(base.VisitTypeOfIsExpression(typeOfIsExpression, data)); }
public object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { throw new NotImplementedException(); }
public object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { return(new B.BinaryExpression(GetLexicalInfo(typeOfIsExpression), B.BinaryOperatorType.TypeTest, ConvertExpression(typeOfIsExpression.Expression), new B.TypeofExpression(GetLexicalInfo(typeOfIsExpression), ConvertTypeReference(typeOfIsExpression.TypeReference)))); }
void SimpleNonInvocationExpression( #line 1645 "VBNET.ATG" out Expression pexpr) { #line 1647 "VBNET.ATG" Expression expr; TypeReference type = null; string name = String.Empty; pexpr = null; if (StartOf(32)) { switch (la.kind) { case 3: { lexer.NextToken(); #line 1655 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 4: { lexer.NextToken(); #line 1656 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 7: { lexer.NextToken(); #line 1657 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 6: { lexer.NextToken(); #line 1658 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 5: { lexer.NextToken(); #line 1659 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 9: { lexer.NextToken(); #line 1660 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 8: { lexer.NextToken(); #line 1661 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 202: { lexer.NextToken(); #line 1663 "VBNET.ATG" pexpr = new PrimitiveExpression(true, "true"); break; } case 109: { lexer.NextToken(); #line 1664 "VBNET.ATG" pexpr = new PrimitiveExpression(false, "false"); break; } case 151: { lexer.NextToken(); #line 1665 "VBNET.ATG" pexpr = new PrimitiveExpression(null, "null"); break; } case 25: { lexer.NextToken(); Expr( #line 1666 "VBNET.ATG" out expr); Expect(26); #line 1666 "VBNET.ATG" pexpr = new ParenthesizedExpression(expr); break; } case 2: case 45: case 49: case 51: case 52: case 53: case 54: case 57: case 74: case 85: case 91: case 94: case 103: case 108: case 113: case 120: case 126: case 130: case 133: case 156: case 162: case 169: case 188: case 197: case 198: case 208: case 209: case 215: { Identifier(); #line 1668 "VBNET.ATG" pexpr = new IdentifierExpression(t.val); pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; if ( #line 1671 "VBNET.ATG" la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) { lexer.NextToken(); Expect(155); TypeArgumentList( #line 1672 "VBNET.ATG" ((IdentifierExpression)pexpr).TypeArguments); Expect(26); } break; } case 55: case 58: case 69: case 86: case 87: case 96: case 128: case 137: case 154: case 181: case 186: case 187: case 193: case 206: case 207: case 210: { #line 1674 "VBNET.ATG" string val = String.Empty; if (StartOf(11)) { PrimitiveTypeName( #line 1675 "VBNET.ATG" out val); } else if (la.kind == 154) { lexer.NextToken(); #line 1675 "VBNET.ATG" val = "System.Object"; } else SynErr(257); #line 1676 "VBNET.ATG" pexpr = new TypeReferenceExpression(new TypeReference(val, true)); break; } case 139: { lexer.NextToken(); #line 1677 "VBNET.ATG" pexpr = new ThisReferenceExpression(); break; } case 144: case 145: { #line 1678 "VBNET.ATG" Expression retExpr = null; if (la.kind == 144) { lexer.NextToken(); #line 1679 "VBNET.ATG" retExpr = new BaseReferenceExpression(); } else if (la.kind == 145) { lexer.NextToken(); #line 1680 "VBNET.ATG" retExpr = new ClassReferenceExpression(); } else SynErr(258); Expect(16); IdentifierOrKeyword( #line 1682 "VBNET.ATG" out name); #line 1682 "VBNET.ATG" pexpr = new MemberReferenceExpression(retExpr, name); break; } case 117: { lexer.NextToken(); Expect(16); Identifier(); #line 1684 "VBNET.ATG" type = new TypeReference(t.val ?? ""); #line 1686 "VBNET.ATG" type.IsGlobal = true; #line 1687 "VBNET.ATG" pexpr = new TypeReferenceExpression(type); break; } case 148: { ObjectCreateExpression( #line 1688 "VBNET.ATG" out expr); #line 1688 "VBNET.ATG" pexpr = expr; break; } case 81: case 93: case 204: { #line 1690 "VBNET.ATG" CastType castType = CastType.Cast; if (la.kind == 93) { lexer.NextToken(); } else if (la.kind == 81) { lexer.NextToken(); #line 1692 "VBNET.ATG" castType = CastType.Conversion; } else if (la.kind == 204) { lexer.NextToken(); #line 1693 "VBNET.ATG" castType = CastType.TryCast; } else SynErr(259); Expect(25); Expr( #line 1695 "VBNET.ATG" out expr); Expect(12); TypeName( #line 1695 "VBNET.ATG" out type); Expect(26); #line 1696 "VBNET.ATG" pexpr = new CastExpression(type, expr, castType); break; } case 63: case 64: case 65: case 66: case 67: case 68: case 70: case 72: case 73: case 77: case 78: case 79: case 80: case 82: case 83: case 84: { CastTarget( #line 1697 "VBNET.ATG" out type); Expect(25); Expr( #line 1697 "VBNET.ATG" out expr); Expect(26); #line 1697 "VBNET.ATG" pexpr = new CastExpression(type, expr, CastType.PrimitiveConversion); break; } case 44: { lexer.NextToken(); Expr( #line 1698 "VBNET.ATG" out expr); #line 1698 "VBNET.ATG" pexpr = new AddressOfExpression(expr); break; } case 116: { lexer.NextToken(); Expect(25); GetTypeTypeName( #line 1699 "VBNET.ATG" out type); Expect(26); #line 1699 "VBNET.ATG" pexpr = new TypeOfExpression(type); break; } case 205: { lexer.NextToken(); SimpleExpr( #line 1700 "VBNET.ATG" out expr); Expect(131); TypeName( #line 1700 "VBNET.ATG" out type); #line 1700 "VBNET.ATG" pexpr = new TypeOfIsExpression(expr, type); break; } case 122: { ConditionalExpression( #line 1701 "VBNET.ATG" out pexpr); break; } } } else if (la.kind == 16) { lexer.NextToken(); IdentifierOrKeyword( #line 1705 "VBNET.ATG" out name); #line 1705 "VBNET.ATG" pexpr = new MemberReferenceExpression(null, name); } else SynErr(260); }
List <MethodDeclaration> CreateEqualsOverrides(IClass currentClass) { List <MethodDeclaration> methods = new List <MethodDeclaration>(); TypeReference boolReference = new TypeReference("System.Boolean", true); TypeReference objectReference = new TypeReference("System.Object", true); MethodDeclaration method = new MethodDeclaration { Name = "Equals", Modifier = Modifiers.Public | Modifiers.Override, TypeReference = boolReference }; method.Parameters.Add(new ParameterDeclarationExpression(objectReference, "obj")); method.Body = new BlockStatement(); TypeReference currentType = ConvertType(currentClass.DefaultReturnType); Expression expr = null; if (currentClass.ClassType == Dom.ClassType.Struct) { // return obj is CurrentType && Equals((CurrentType)obj); expr = new TypeOfIsExpression(new IdentifierExpression("obj"), currentType); expr = new ParenthesizedExpression(expr); expr = new BinaryOperatorExpression( expr, BinaryOperatorType.LogicalAnd, new InvocationExpression( new IdentifierExpression("Equals"), new List <Expression> { new CastExpression(currentType, new IdentifierExpression("obj"), CastType.Cast) })); method.Body.AddChild(new ReturnStatement(expr)); methods.Add(method); // IEquatable implementation: method = new MethodDeclaration { Name = "Equals", Modifier = Modifiers.Public | Modifiers.Override, TypeReference = boolReference }; method.Parameters.Add(new ParameterDeclarationExpression(currentType, "other")); method.Body = new BlockStatement(); } else { method.Body.AddChild(new LocalVariableDeclaration(new VariableDeclaration( "other", new CastExpression(currentType, new IdentifierExpression("obj"), CastType.TryCast), currentType))); method.Body.AddChild(new IfElseStatement( new BinaryOperatorExpression(new IdentifierExpression("other"), BinaryOperatorType.ReferenceEquality, new PrimitiveExpression(null, "null")), new ReturnStatement(new PrimitiveExpression(false, "false")))); // expr = new BinaryOperatorExpression(new ThisReferenceExpression(), // BinaryOperatorType.ReferenceEquality, // new IdentifierExpression("obj")); // method.Body.AddChild(new IfElseStatement(expr, new ReturnStatement(new PrimitiveExpression(true, "true")))); } expr = null; foreach (IField field in currentClass.Fields) { if (field.IsStatic) { continue; } if (expr == null) { expr = TestEquality("other", field); } else { expr = new BinaryOperatorExpression(expr, BinaryOperatorType.LogicalAnd, TestEquality("other", field)); } } method.Body.AddChild(new ReturnStatement(expr ?? new PrimitiveExpression(true, "true"))); methods.Add(method); return(methods); }
public override object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { return(resolver.ProjectContent.SystemTypes.Boolean); }
public virtual object TrackedVisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { return base.VisitTypeOfIsExpression(typeOfIsExpression, data); }