public override void GenerateCode(List<AbstractNode> nodes, IList items) { TypeReference stringReference = new TypeReference("System.String", true); MethodDeclaration method = new MethodDeclaration { Name = "ToString", Modifier = Modifiers.Public | Modifiers.Override, TypeReference = stringReference, }; method.Body = new BlockStatement(); Expression target = new MemberReferenceExpression(new TypeReferenceExpression(stringReference), "Format"); InvocationExpression methodCall = new InvocationExpression(target); StringBuilder formatString = new StringBuilder(); formatString.Append('['); formatString.Append(currentClass.Name); for (int i = 0; i < items.Count; i++) { formatString.Append(' '); formatString.Append(codeGen.GetPropertyName(((FieldWrapper)items[i]).Field.Name)); formatString.Append("={"); formatString.Append(i); formatString.Append('}'); } formatString.Append(']'); methodCall.Arguments.Add(new PrimitiveExpression(formatString.ToString(), formatString.ToString())); foreach (FieldWrapper w in items) { methodCall.Arguments.Add(new MemberReferenceExpression(new ThisReferenceExpression(), w.Field.Name)); } method.Body.AddChild(new ReturnStatement(methodCall)); nodes.Add(method); }
//, AstExpression expression) public static MemberReferenceExpression add_MemberReference(this BlockStatement blockStatement, string memberName, string className) { var identifier = new IdentifierExpression(memberName); var memberReference = new MemberReferenceExpression(identifier, className); blockStatement.append(memberReference.expressionStatement()); return memberReference; }
//, AstExpression expression) public static InvocationExpression add_Invocation(this BlockStatement blockStatement, string typeName, string methodName, params object[] parameters) { if (methodName.valid().isFalse()) return null; Expression memberExpression = null; if (typeName.valid()) memberExpression = new MemberReferenceExpression(new IdentifierExpression(typeName), methodName); else memberExpression = new IdentifierExpression(methodName); var memberReference = new InvocationExpression(memberExpression); if (parameters != null) { var arguments = new List<Expression>(); foreach (var parameter in parameters) if (parameter is Expression) arguments.add(parameter as Expression); else arguments.add(new PrimitiveExpression(parameter, parameter.str())); memberReference.Arguments = arguments; } blockStatement.append(memberReference.expressionStatement()); return memberReference; }
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) { base.VisitTypeDeclaration(typeDeclaration, data); // visit methods typeDeclaration.Attributes.Clear(); typeDeclaration.BaseTypes.Clear(); // add constructor accepting the wrapped object and the field holding the object FieldDeclaration fd = new FieldDeclaration(null, // no attributes new TypeReference(typeDeclaration.Name), Modifiers.Private); fd.Fields.Add(new VariableDeclaration("wrappedObject")); typeDeclaration.AddChild(fd); typeDeclaration.Name += "Wrapper"; if (typeDeclaration.Type == ClassType.Interface) { typeDeclaration.Type = ClassType.Class; typeDeclaration.Name = typeDeclaration.Name.Substring(1); } ConstructorDeclaration cd = new ConstructorDeclaration(typeDeclaration.Name, Modifiers.Public, new List<ParameterDeclarationExpression>(), null); cd.Parameters.Add(new ParameterDeclarationExpression(fd.TypeReference, "wrappedObject")); // this.wrappedObject = wrappedObject; Expression fieldReference = new MemberReferenceExpression(new ThisReferenceExpression(), "wrappedObject"); Expression assignment = new AssignmentExpression(fieldReference, AssignmentOperatorType.Assign, new IdentifierExpression("wrappedObject")); cd.Body = new BlockStatement(); cd.Body.AddChild(new ExpressionStatement(assignment)); typeDeclaration.AddChild(cd); for (int i = 0; i < typeDeclaration.Children.Count; i++) { object child = typeDeclaration.Children[i]; if (child is MethodDeclaration) { MethodDeclaration method = (MethodDeclaration)child; if (method.Parameters.Count == 0 && (method.Name.StartsWith("Is") || method.Name.StartsWith("Get"))) { // replace the method with a property PropertyDeclaration prop = new PropertyDeclaration(method.Modifier, method.Attributes, method.Name, null); prop.TypeReference = method.TypeReference; prop.GetRegion = new PropertyGetRegion(method.Body, null); typeDeclaration.Children[i] = prop; } } } return null; }
public void MethodOnThisReferenceInvocation() { // InitializeComponents(); MemberReferenceExpression field = new MemberReferenceExpression(new ThisReferenceExpression(), "InitializeComponents"); InvocationExpression invocation = new InvocationExpression(field, new List<Expression>()); object output = invocation.AcceptVisitor(new CodeDomVisitor(), null); Assert.IsTrue(output is CodeMethodInvokeExpression); CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output; Assert.AreEqual("InitializeComponents", mie.Method.MethodName); Assert.IsTrue(mie.Method.TargetObject is CodeThisReferenceExpression); }
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) { if (memberReferenceExpression.TargetObject is IdentifierExpression) { var identifier = (IdentifierExpression) memberReferenceExpression.TargetObject; if (identifier.Identifier == "array" && memberReferenceExpression.MemberName == "Length") UnlockWith(memberReferenceExpression); } return base.VisitMemberReferenceExpression(memberReferenceExpression, data); }
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) { foreach (var forbidden in Members.Where(x => x.Names.Contains(memberReferenceExpression.MemberName))) { var identifierExpression = GetTarget(memberReferenceExpression); if(forbidden.TypeAliases.Contains(identifierExpression) == false) continue; var text = QueryParsingUtils.ToText(memberReferenceExpression); throw new InvalidOperationException(string.Format(forbidden.Error, text)); } return base.VisitMemberReferenceExpression(memberReferenceExpression, data); }
public void InvocationOfStaticMethod() { // System.Drawing.Color.FromArgb(); MemberReferenceExpression field = new MemberReferenceExpression(new IdentifierExpression("System"), "Drawing"); field = new MemberReferenceExpression(field, "Color"); field = new MemberReferenceExpression(field, "FromArgb"); InvocationExpression invocation = new InvocationExpression(field, new List<Expression>()); object output = invocation.AcceptVisitor(new CodeDomVisitor(), null); Assert.IsTrue(output is CodeMethodInvokeExpression); CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output; Assert.AreEqual("FromArgb", mie.Method.MethodName); Assert.IsTrue(mie.Method.TargetObject is CodeTypeReferenceExpression); Assert.AreEqual("System.Drawing.Color", (mie.Method.TargetObject as CodeTypeReferenceExpression).Type.BaseType); }
private static INode ModifyLambdaForSelect(ParenthesizedExpression parenthesizedlambdaExpression, MemberReferenceExpression target) { var parentInvocation = target.TargetObject as InvocationExpression; if(parentInvocation != null) { var parentTarget = parentInvocation.TargetObject as MemberReferenceExpression; if(parentTarget != null && parentTarget.MemberName == "GroupBy") { return new CastExpression(new TypeReference("Func<IGrouping<dynamic,dynamic>, dynamic>"), parenthesizedlambdaExpression, CastType.Cast); } } return new CastExpression(new TypeReference("Func<dynamic, dynamic>"), parenthesizedlambdaExpression, CastType.Cast); }
public override void GenerateCode(List<AbstractNode> nodes, IList items) { ConstructorDeclaration ctor = new ConstructorDeclaration(currentClass.Name, Modifiers.Public, null, null); ctor.Body = new BlockStatement(); foreach (FieldWrapper w in items) { string parameterName = codeGen.GetParameterName(w.Field.Name); ctor.Parameters.Add(new ParameterDeclarationExpression(ConvertType(w.Field.ReturnType), parameterName)); Expression left = new MemberReferenceExpression(new ThisReferenceExpression(), w.Field.Name); Expression right = new IdentifierExpression(parameterName); Expression expr = new AssignmentExpression(left, AssignmentOperatorType.Assign, right); ctor.Body.AddChild(new ExpressionStatement(expr)); } nodes.Add(ctor); }
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) { var identifierExpression = memberReferenceExpression.TargetObject as IdentifierExpression; if (identifierExpression == null || identifierExpression.Identifier != identifier) return base.VisitMemberReferenceExpression(memberReferenceExpression, data); var indexerExpression = new IndexerExpression( memberReferenceExpression.TargetObject, new List<Expression> { new PrimitiveExpression(memberReferenceExpression.MemberName, memberReferenceExpression.MemberName) }); ReplaceCurrentNode(indexerExpression); indexerExpression.Parent = memberReferenceExpression.Parent; return indexerExpression; }
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) { if (memberReferenceExpression.MemberName == "Abort") { if (memberReferenceExpression.TargetObject is IdentifierExpression) { var id = (IdentifierExpression)memberReferenceExpression.TargetObject; if (threadVars.Contains(id.Identifier)) { UnlockWith(memberReferenceExpression); } } } return base.VisitMemberReferenceExpression(memberReferenceExpression, data); }
public override object VisitMemberReferenceExpression(MemberReferenceExpression fieldReferenceExpression, object data) { ResolveResult fieldRR = base.VisitMemberReferenceExpression(fieldReferenceExpression, data) as ResolveResult; if (vbMyFormsClass != null && IsReferenceToInstanceMember(fieldRR)) { TypeResolveResult trr = Resolve(fieldReferenceExpression.TargetObject) as TypeResolveResult; if (trr != null && trr.ResolvedClass != null) { foreach (IProperty p in vbMyFormsClass.Properties) { if (p.ReturnType.FullyQualifiedName == trr.ResolvedClass.FullyQualifiedName) { fieldReferenceExpression.TargetObject = MakeFieldReferenceExpression("My.MyProject.Forms." + p.Name); } } } } return null; }
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) { IdentifierExpression id = memberReferenceExpression.TargetObject as IdentifierExpression; if (id != null) { if (id.Identifier == "System" || id.Identifier == currentClass) { ReplaceCurrentNode(new IdentifierExpression(memberReferenceExpression.MemberName)); return null; } if (id.Identifier.StartsWith("System.")) { id.Identifier = id.Identifier.Replace("System.", ""); return null; } } // we can't always remove "this", the field name might conflict with a parameter/local variable // if (memberReferenceExpression.TargetObject is ThisReferenceExpression) { // ReplaceCurrentNode(new IdentifierExpression(memberReferenceExpression.MemberName)); // return null; // } return base.VisitMemberReferenceExpression(memberReferenceExpression, data); }
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; } }
public override object TrackedVisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) { memberReferenceExpression.TargetObject.AcceptVisitor(this, data); if ((!(memberReferenceExpression.TargetObject is ThisReferenceExpression) ? true : this.IsProperty(memberReferenceExpression.MemberName))) { this.Append("."); } else { this.Append("._"); } this.Append(memberReferenceExpression.MemberName); return null; }
public virtual object TrackedVisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) { return base.VisitMemberReferenceExpression(memberReferenceExpression, data); }
public sealed override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) { this.BeginVisit(memberReferenceExpression); object result = this.TrackedVisitMemberReferenceExpression(memberReferenceExpression, data); this.EndVisit(memberReferenceExpression); return result; }
protected override IEnumerable<string> GenerateCode (INRefactoryASTProvider astProvider, string indent, List<IBaseMember> includedMembers) { StringBuilder format = new StringBuilder (); format.Append ("["); format.Append (Options.EnclosingType.Name); format.Append (": "); int i = 0; foreach (IMember member in includedMembers) { if (i > 0) format.Append (", "); format.Append (member.Name); format.Append ("={"); format.Append (i++); format.Append ("}"); } format.Append ("]"); MethodDeclaration methodDeclaration = new MethodDeclaration (); methodDeclaration.Name = "ToString"; methodDeclaration.TypeReference = DomReturnType.String.ConvertToTypeReference (); methodDeclaration.Modifier = ICSharpCode.NRefactory.Ast.Modifiers.Public | ICSharpCode.NRefactory.Ast.Modifiers.Override; methodDeclaration.Body = new BlockStatement (); MemberReferenceExpression formatReference = new MemberReferenceExpression (new TypeReferenceExpression (methodDeclaration.TypeReference), "Format"); List<Expression> arguments = new List<Expression> (); arguments.Add (new PrimitiveExpression (format.ToString ())); foreach (IMember member in includedMembers) { arguments.Add (new IdentifierExpression (member.Name)); } methodDeclaration.Body.AddChild (new ReturnStatement (new InvocationExpression (formatReference, arguments))); yield return astProvider.OutputNode (this.Options.Dom, methodDeclaration, indent); }
public virtual object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) { throw new global::System.NotImplementedException("MemberReferenceExpression"); }
bool FullyQualifyModuleMemberReference(MemberReferenceExpression mre, ResolveResult rr) { IReturnType containingType = GetContainingTypeOfStaticMember(rr); if (containingType == null) return false; ResolveResult targetRR = resolver.ResolveInternal(mre.TargetObject, ExpressionContext.Default); if (targetRR is NamespaceResolveResult) { mre.TargetObject = new TypeReferenceExpression(ConvertType(containingType)); return true; } return false; }
private static string GetTarget(MemberReferenceExpression memberReferenceExpression) { var identifierExpression = memberReferenceExpression.TargetObject as IdentifierExpression; if(identifierExpression!=null) return identifierExpression.Identifier; var mre = memberReferenceExpression.TargetObject as MemberReferenceExpression; if(mre != null) return GetTarget(mre) + "." + mre.MemberName; return null; }
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); }
void ReDimClauseInternal( #line 3146 "VBNET.ATG" ref Expression expr) { #line 3147 "VBNET.ATG" List<Expression> arguments; bool canBeNormal; bool canBeRedim; string name; while (la.kind == 16 || #line 3150 "VBNET.ATG" la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) { if (la.kind == 16) { lexer.NextToken(); IdentifierOrKeyword( #line 3149 "VBNET.ATG" out name); #line 3149 "VBNET.ATG" expr = new MemberReferenceExpression(expr, name); } else { InvocationExpression( #line 3151 "VBNET.ATG" ref expr); } } Expect(25); NormalOrReDimArgumentList( #line 3154 "VBNET.ATG" out arguments, out canBeNormal, out canBeRedim); Expect(26); #line 3156 "VBNET.ATG" expr = new InvocationExpression(expr, arguments); if (canBeRedim == false || canBeNormal && (la.kind == Tokens.Dot || la.kind == Tokens.OpenParenthesis)) { if (this.Errors.Count == 0) { // don't recurse on parse errors - could result in endless recursion ReDimClauseInternal(ref expr); } } }
void SimpleExpr( #line 1630 "VBNET.ATG" out Expression pexpr) { #line 1631 "VBNET.ATG" string name; SimpleNonInvocationExpression( #line 1633 "VBNET.ATG" out pexpr); while (la.kind == 16 || la.kind == 17 || la.kind == 25) { if (la.kind == 16) { lexer.NextToken(); IdentifierOrKeyword( #line 1635 "VBNET.ATG" out name); #line 1636 "VBNET.ATG" pexpr = new MemberReferenceExpression(pexpr, name); if ( #line 1637 "VBNET.ATG" la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) { lexer.NextToken(); Expect(155); TypeArgumentList( #line 1638 "VBNET.ATG" ((MemberReferenceExpression)pexpr).TypeArguments); Expect(26); } } else if (la.kind == 17) { lexer.NextToken(); IdentifierOrKeyword( #line 1640 "VBNET.ATG" out name); #line 1640 "VBNET.ATG" pexpr = new BinaryOperatorExpression(pexpr, BinaryOperatorType.DictionaryAccess, new PrimitiveExpression(name, name)); } else { InvocationExpression( #line 1641 "VBNET.ATG" ref pexpr); } } }
public override object VisitMemberReferenceExpression (MemberReferenceExpression e, object data) { IntegrateTemporaryVariableVisitorOptions options = (IntegrateTemporaryVariableVisitorOptions)data; if (IsExpressionToReplace (e.TargetObject, options)) { if (IsUnary (options.Initializer)) options.Changes.Add (ReplaceExpression (e.TargetObject, options.Initializer, options)); else options.Changes.Add (ReplaceExpression (e.TargetObject, new ParenthesizedExpression (options.Initializer), options)); return null; } else return e.TargetObject.AcceptVisitor (this, data); }
public static Expression AppendMemberReference(this Expression expresion, IDebugMemberInfo memberInfo, params Expression[] args) { Expression target; if (memberInfo.IsStatic) { target = new TypeReferenceExpression() { Type = memberInfo.DeclaringType.GetTypeReference() }; } else { target = CastTo(expresion, (DebugType)memberInfo.DeclaringType); } if (memberInfo is DebugFieldInfo) { if (args.Length > 0) { throw new DebuggerException("No arguments expected for a field"); } var mre = new MemberReferenceExpression() { Target = target.Clone(), MemberName = memberInfo.Name }; return(mre.SetStaticType(memberInfo.MemberType)); } if (memberInfo is MethodInfo) { var mre = new MemberReferenceExpression() { Target = target, MemberName = memberInfo.Name }; var ie = new InvocationExpression() { Target = mre.Clone() }; ie.Arguments.AddRange(AddExplicitTypes((MethodInfo)memberInfo, args)); return(ie.SetStaticType(memberInfo.MemberType)); } if (memberInfo is PropertyInfo) { PropertyInfo propInfo = (PropertyInfo)memberInfo; if (args.Length > 0) { if (memberInfo.Name != "Item") { throw new DebuggerException("Arguments expected only for the Item property"); } var ie = new IndexerExpression() { Target = target.Clone() }; ie.Arguments.AddRange(AddExplicitTypes(propInfo.GetGetMethod() ?? propInfo.GetSetMethod(), args)); return(ie.SetStaticType(memberInfo.MemberType)); } else { return((new MemberReferenceExpression() { Target = target.Clone(), MemberName = memberInfo.Name }).SetStaticType(memberInfo.MemberType)); } } throw new DebuggerException("Unknown member type " + memberInfo.GetType().FullName); }
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; } }
protected Expression MakeFieldReferenceExpression(string name) { Expression e = null; foreach (string n in name.Split('.')) { if (e == null) e = new IdentifierExpression(n); else e = new MemberReferenceExpression(e, n); } return e; }
void ReDimClauseInternal( //#line 3486 "VBNET.ATG" ref Expression expr) { //#line 3487 "VBNET.ATG" List<Expression> arguments; bool canBeNormal; bool canBeRedim; string name; Location startLocation = la.Location; while (la.kind == 26 || //#line 3490 "VBNET.ATG" la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) { if (la.kind == 26) { lexer.NextToken(); IdentifierOrKeyword( //#line 3489 "VBNET.ATG" out name); //#line 3489 "VBNET.ATG" expr = new MemberReferenceExpression(expr, name) { StartLocation = startLocation, EndLocation = t.EndLocation }; } else { InvocationExpression( //#line 3491 "VBNET.ATG" ref expr); //#line 3493 "VBNET.ATG" expr.StartLocation = startLocation; expr.EndLocation = t.EndLocation; } } Expect(37); NormalOrReDimArgumentList( //#line 3498 "VBNET.ATG" out arguments, out canBeNormal, out canBeRedim); Expect(38); //#line 3500 "VBNET.ATG" expr = new InvocationExpression(expr, arguments); if (canBeRedim == false || canBeNormal && (la.kind == Tokens.Dot || la.kind == Tokens.OpenParenthesis)) { if (this.Errors.Count == 0) { // don't recurse on parse errors - could result in endless recursion ReDimClauseInternal(ref expr); } } }
void MemberAccess( #line 2034 "cs.ATG" out Expression expr, Expression target) { #line 2035 "cs.ATG" List<TypeReference> typeList; #line 2037 "cs.ATG" if (ShouldConvertTargetExpressionToTypeReference(target)) { TypeReference type = GetTypeReferenceFromExpression(target); if (type != null) { target = new TypeReferenceExpression(type) { StartLocation = t.Location, EndLocation = t.EndLocation }; } } Expect(15); #line 2044 "cs.ATG" Location startLocation = t.Location; Identifier(); #line 2046 "cs.ATG" expr = new MemberReferenceExpression(target, t.val); expr.StartLocation = startLocation; expr.EndLocation = t.EndLocation; if ( #line 2047 "cs.ATG" IsGenericInSimpleNameOrMemberAccess()) { TypeArgumentList( #line 2048 "cs.ATG" out typeList, false); #line 2049 "cs.ATG" ((MemberReferenceExpression)expr).TypeArguments = typeList; } }