Inheritance: ICSharpCode.NRefactory.Ast.Expression
Beispiel #1
0
 public override object VisitIndexerExpression(IndexerExpression indexer, object data)
 {
     if (GetPrecedence(indexer.TargetObject) >= GetPrecedence(indexer)) {
         indexer.TargetObject = Deparenthesize(indexer.TargetObject);
     }
     return base.VisitIndexerExpression(indexer, data);
 }
		public override object VisitIndexerExpression(IndexerExpression indexerExpression, object data)
		{
			List<int> indexes = new List<int>();
			foreach(Expression indexExpr in indexerExpression.Indexes) {
				Value indexValue = (Value)indexExpr.AcceptVisitor(this, null);
				if (!indexValue.Type.IsInteger) throw new GetValueException("Integer expected");
				indexes.Add((int)indexValue.PrimitiveValue);
			}
			Value target = (Value)indexerExpression.TargetObject.AcceptVisitor(this, null);
			if (!target.Type.IsArray) throw new GetValueException("Target is not array");
			return target.GetArrayElement(indexes.ToArray());
		}
        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;
        }
Beispiel #4
0
        private VariableDeclaration TransformMapDefinition()
        {
            var variableDeclaration = QueryParsingUtils.GetVariableDeclaration(indexDefinition.Map);
            var queryExpression = ((QueryExpression) variableDeclaration.Initializer);
            var expression = queryExpression.FromClause.InExpression;
            if(expression is MemberReferenceExpression) // collection
            {
                var mre = (MemberReferenceExpression)expression;
                queryExpression.FromClause.InExpression = mre.TargetObject;
                //doc["@metadata"]["Raven-Entity-Name"]
                var metadata = new IndexerExpression(
                    new IndexerExpression(new IdentifierExpression(queryExpression.FromClause.Identifier), new List<Expression> { new PrimitiveExpression("@metadata", "@metadata") }),
                    new List<Expression> { new PrimitiveExpression("Raven-Entity-Name", "Raven-Entity-Name") }
                    );
                queryExpression.MiddleClauses.Insert(0,
                    new QueryExpressionWhereClause
                    {
                        Condition =
                            new BinaryOperatorExpression(
                                metadata,
                                BinaryOperatorType.Equality,
                                new PrimitiveExpression(mre.MemberName, mre.MemberName)
                                )
                    });
            }
            var selectOrGroupClause = queryExpression.SelectOrGroupClause;
            var projection = ((QueryExpressionSelectClause) selectOrGroupClause).Projection;
            var objectInitializer = ((ObjectCreateExpression) projection).ObjectInitializer;

            var identifierExpression = new IdentifierExpression(queryExpression.FromClause.Identifier);
            objectInitializer.CreateExpressions.Add(
                new NamedArgumentExpression
                {
                    Name = "__document_id",
                    Expression = new MemberReferenceExpression(identifierExpression, "__document_id")
                });
            return variableDeclaration;
        }
		public override object TrackedVisitIndexerExpression(IndexerExpression indexerExpression, object data)
		{
			indexerExpression.TargetObject.AcceptVisitor(this, data);

			// Add indices.
			foreach (Expression expression in indexerExpression.Indexes) {
				Append("[");
				expression.AcceptVisitor(this, data);
				Append("]");
			}

			return null;
		}
Beispiel #6
0
		private VariableDeclaration TransformMapDefinitionFromLinqQuerySyntax(string query, out string entityName)
		{
			entityName = null;
			var variableDeclaration = QueryParsingUtils.GetVariableDeclarationForLinqQuery(query, RequiresSelectNewAnonymousType);
			var queryExpression = ((QueryExpression) variableDeclaration.Initializer);
			var expression = queryExpression.FromClause.InExpression;
			if(expression is MemberReferenceExpression) // collection
			{
				var mre = (MemberReferenceExpression)expression;
				entityName = mre.MemberName;
				queryExpression.FromClause.InExpression = mre.TargetObject;
				//doc["@metadata"]["Raven-Entity-Name"]
				var metadata = new IndexerExpression(
					new IndexerExpression(new IdentifierExpression(queryExpression.FromClause.Identifier), new List<Expression> { new PrimitiveExpression("@metadata", "@metadata") }),
					new List<Expression> { new PrimitiveExpression(Constants.RavenEntityName, Constants.RavenEntityName) }
					);
				queryExpression.MiddleClauses.Insert(0, 
				                                     new QueryExpressionWhereClause
				                                     {
				                                     	Condition = 
				                                     		new BinaryOperatorExpression(
				                                     		metadata,
				                                     		BinaryOperatorType.Equality,
				                                     		new PrimitiveExpression(mre.MemberName, mre.MemberName)
				                                     		)
				                                     });
			}
			var selectOrGroupClause = queryExpression.SelectOrGroupClause;
			var projection = ((QueryExpressionSelectClause) selectOrGroupClause).Projection;
			if(projection is ObjectCreateExpression == false)
				return variableDeclaration;

			var objectInitializer = ((ObjectCreateExpression) projection).ObjectInitializer;

			var identifierExpression = new IdentifierExpression(queryExpression.FromClause.Identifier);

			if (objectInitializer.CreateExpressions.OfType<NamedArgumentExpression>().Any(x => x.Name == Constants.DocumentIdFieldName))
				return variableDeclaration;

			objectInitializer.CreateExpressions.Add(
				new NamedArgumentExpression
				{
					Name = Constants.DocumentIdFieldName,
					Expression = new MemberReferenceExpression(identifierExpression, Constants.DocumentIdFieldName)
				});
			return variableDeclaration;
		}
Beispiel #7
0
		public IProperty GetIndexer(IndexerExpression indexerExpression)
		{
			IReturnType type = (IReturnType)indexerExpression.TargetObject.AcceptVisitor(this, null);
			if (type == null) {
				return null;
			}
			List<IProperty> indexers = type.GetProperties();
			// remove non-indexers:
			for (int i = 0; i < indexers.Count; i++) {
				if (!indexers[i].IsIndexer)
					indexers.RemoveAt(i--);
			}
			IReturnType[] parameters = new IReturnType[indexerExpression.Indexes.Count];
			for (int i = 0; i < parameters.Length; i++) {
				Expression expr = indexerExpression.Indexes[i] as Expression;
				if (expr != null)
					parameters[i] = (IReturnType)expr.AcceptVisitor(this, null);
			}
			return MemberLookupHelper.FindOverload(indexers.ToArray(), parameters);
		}
Beispiel #8
0
 public virtual object VisitIndexerExpression(IndexerExpression indexerExpression, object data) {
     throw CreateException(indexerExpression);
 }
Beispiel #9
0
		public override object VisitIndexerExpression(IndexerExpression indexerExpression, object data)
		{
			IProperty i = GetIndexer(indexerExpression);
			if (i != null)
				return i.ReturnType;
			else
				return null;
		}
        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);
        }
 public object VisitIndexerExpression(IndexerExpression indexerExpression, object data)
 {
     throw new NotImplementedException ();
 }
Beispiel #12
0
 public override object VisitIndexerExpression(IndexerExpression indexerExpression, object data)
 {
     return new CodeIndexerExpression((CodeExpression)indexerExpression.TargetObject.AcceptVisitor(this, data), GetExpressionList(indexerExpression.Indexes));
 }
 public virtual bool VisitIndexerExpression(IndexerExpression indexerExpression, object d)
 {
     if ((indexerExpression == null)) {
         return SetFailure();
     }
     if ((d == null)) {
         return SetFailure();
     }
     if ((indexerExpression.TargetObject == null)) {
         return SetFailure();
     }
     if ((indexerExpression.Indexes == null)) {
         return SetFailure();
     }
     if(indexerExpression.GetType() != d.GetType()) {return SetFailure();}
     var data = (IndexerExpression)d;
     if (!IsMatch(indexerExpression, data)) {
         return SetFailure();
     }
     indexerExpression.TargetObject.AcceptVisitor(this, data.TargetObject);
     if (indexerExpression.Indexes.Count == data.Indexes.Count) {
     for (int i=0; i<indexerExpression.Indexes.Count;i++) {
         Expression o = indexerExpression.Indexes[i];
         if(o == null){return SetFailure();}
         if((bool)o.AcceptVisitor(this, data.Indexes[i]) == false) return SetFailure();
     }			}			else { return SetFailure(); }
     return true;
 }
		private void AddEntityNameFilteringIfNeeded(VariableDeclaration variableDeclaration, out string entityName)
		{
			entityName = null;
			var invocationExpression = ((InvocationExpression)variableDeclaration.Initializer);
			var targetExpression = ((MemberReferenceExpression)invocationExpression.TargetObject);
			while (targetExpression.TargetObject is InvocationExpression)
			{
				invocationExpression = (InvocationExpression) targetExpression.TargetObject;
				targetExpression = (MemberReferenceExpression)invocationExpression.TargetObject;
			}
			if (targetExpression.TargetObject is MemberReferenceExpression) // collection
			{
				var mre = (MemberReferenceExpression)targetExpression.TargetObject;
				entityName = mre.MemberName;
				//doc["@metadata"]["Raven-Entity-Name"]
				var metadata = new IndexerExpression(
					new IndexerExpression(new IdentifierExpression("__document"), new List<Expression> { new PrimitiveExpression("@metadata", "@metadata") }),
					new List<Expression> { new PrimitiveExpression(Constants.RavenEntityName, Constants.RavenEntityName) }
					);

				// string.Equals(doc["@metadata"]["Raven-Entity-Name"], "Blogs", StringComparison.InvariantCultureIgnoreCase)
				var binaryOperatorExpression =
					new InvocationExpression(
						new MemberReferenceExpression(new TypeReferenceExpression(new TypeReference("string", true)), "Equals"),
						new List<Expression>
						{
							metadata,
							new PrimitiveExpression(mre.MemberName, mre.MemberName),
							new MemberReferenceExpression(new TypeReferenceExpression(new TypeReference(typeof(StringComparison).FullName)),"InvariantCultureIgnoreCase")
						});
				var whereMethod = new InvocationExpression(new MemberReferenceExpression(mre.TargetObject, "Where"),
				                                           new List<Expression>
				                                           {
				                                           	new LambdaExpression
				                                           	{
				                                           		Parameters =
				                                           			{
				                                           				new ParameterDeclarationExpression(null, "__document")
				                                           			},
				                                           		ExpressionBody = binaryOperatorExpression
				                                           	}
				                                           });

				invocationExpression.TargetObject = new MemberReferenceExpression(whereMethod, targetExpression.MemberName);

			}
		}
Beispiel #15
0
 public override object VisitIndexerExpression(IndexerExpression indexerExpression, object data)
 {
     indexerExpression.TargetObject.Parent = indexerExpression;
     foreach (Expression expr in indexerExpression.Indexes)
     {
         expr.Parent = indexerExpression;
     }
     return base.VisitIndexerExpression(indexerExpression, data);
 }
 private AssignmentExpression InitArrayStatement(ArrayCreateExpression arrayCreateExpression, string variableName, List<Expression> creatExpressions, int index)
 {
     IdentifierExpression identifierExpression = new IdentifierExpression(variableName);
     List<Expression> indexes = new List<Expression>();
     indexes.Add(new PrimitiveExpression(index, index.ToString()));
     IndexerExpression left = new IndexerExpression(identifierExpression, indexes);
     string createType = arrayCreateExpression.CreateType.Type;
     ArrayCreateExpression right = new ArrayCreateExpression(new TypeReference(createType, new int[1]));
     right.ArrayInitializer = new CollectionInitializerExpression(creatExpressions);
     return new AssignmentExpression(left, AssignmentOperatorType.Assign, right);
 }
		public override object VisitIndexerExpression(IndexerExpression indexerExpression, object data)
		{
			return base.VisitIndexerExpression(indexerExpression, data);
		}
Beispiel #18
0
        private void AddEntityNameFilteringIfNeeded(VariableDeclaration variableDeclaration, out string entityName)
        {
            entityName = null;
            var invocationExpression = ((InvocationExpression)variableDeclaration.Initializer);
            var targetExpression = ((MemberReferenceExpression)invocationExpression.TargetObject);
            while (targetExpression.TargetObject is InvocationExpression)
            {
                invocationExpression = (InvocationExpression) targetExpression.TargetObject;
                targetExpression = (MemberReferenceExpression)invocationExpression.TargetObject;
            }
            if (targetExpression.TargetObject is MemberReferenceExpression) // collection
            {
                var mre = (MemberReferenceExpression)targetExpression.TargetObject;
                entityName = mre.MemberName;
                //doc["@metadata"]["Raven-Entity-Name"]
                var metadata = new IndexerExpression(
                    new IndexerExpression(new IdentifierExpression("__document"), new List<Expression> { new PrimitiveExpression("@metadata", "@metadata") }),
                    new List<Expression> { new PrimitiveExpression("Raven-Entity-Name", "Raven-Entity-Name") }
                    );
                var whereMethod = new InvocationExpression(new MemberReferenceExpression(mre.TargetObject, "Where"),
                                                           new List<Expression>
                                                           {
                                                           	new LambdaExpression
                                                           	{
                                                           		Parameters =
                                                           			{
                                                           				new ParameterDeclarationExpression(null, "__document")
                                                           			},
                                                           		ExpressionBody = new BinaryOperatorExpression(
                                                           			metadata,
                                                           			BinaryOperatorType.Equality,
                                                           			new PrimitiveExpression(mre.MemberName, mre.MemberName)
                                                           			)
                                                           	}
                                                           });

                invocationExpression.TargetObject = new MemberReferenceExpression(whereMethod, targetExpression.MemberName);

            }
        }
Beispiel #19
0
	void PrimaryExpr(
#line  1895 "cs.ATG" 
out Expression pexpr) {

#line  1897 "cs.ATG" 
		TypeReference type = null;
		Expression expr;
		pexpr = null;
		

#line  1902 "cs.ATG" 
		Location startLocation = la.Location; 
		if (la.kind == 113) {
			lexer.NextToken();

#line  1904 "cs.ATG" 
			pexpr = new PrimitiveExpression(true, "true");  
		} else if (la.kind == 72) {
			lexer.NextToken();

#line  1905 "cs.ATG" 
			pexpr = new PrimitiveExpression(false, "false"); 
		} else if (la.kind == 90) {
			lexer.NextToken();

#line  1906 "cs.ATG" 
			pexpr = new PrimitiveExpression(null, "null");  
		} else if (la.kind == 2) {
			lexer.NextToken();

#line  1907 "cs.ATG" 
			pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
		} else if (
#line  1908 "cs.ATG" 
StartOfQueryExpression()) {
			QueryExpression(
#line  1909 "cs.ATG" 
out pexpr);
		} else if (
#line  1910 "cs.ATG" 
IdentAndDoubleColon()) {
			Identifier();

#line  1911 "cs.ATG" 
			type = new TypeReference(t.val); 
			Expect(10);

#line  1912 "cs.ATG" 
			pexpr = new TypeReferenceExpression(type); 
			Identifier();

#line  1913 "cs.ATG" 
			if (type.Type == "global") { type.IsGlobal = true; type.Type = t.val ?? "?"; } else type.Type += "." + (t.val ?? "?"); 
		} else if (la.kind == 64) {
			lexer.NextToken();
			AnonymousMethodExpr(
#line  1915 "cs.ATG" 
out expr);

#line  1915 "cs.ATG" 
			pexpr = expr; 
		} else if (
#line  1916 "cs.ATG" 
la.kind == Tokens.Async && Peek(1).kind == Tokens.Delegate) {
			Expect(145);
			Expect(64);
			AnonymousMethodExpr(
#line  1917 "cs.ATG" 
out expr);

#line  1917 "cs.ATG" 
			pexpr = expr; 

#line  1918 "cs.ATG" 
			((AnonymousMethodExpression)expr).IsAsync = true; 
		} else if (
#line  1920 "cs.ATG" 
la.kind == Tokens.Async && Peek(1).kind == Tokens.OpenParenthesis) {
			Expect(145);
			LambdaExpression(
#line  1922 "cs.ATG" 
out pexpr);

#line  1923 "cs.ATG" 
			((LambdaExpression)pexpr).IsAsync = true; 
		} else if (
#line  1925 "cs.ATG" 
la.kind == Tokens.Async && IsIdentifierToken(Peek(1))) {
			Expect(145);
			Identifier();

#line  1927 "cs.ATG" 
			pexpr = new IdentifierExpression(t.val); 
			ShortedLambdaExpression(
#line  1928 "cs.ATG" 
(IdentifierExpression)pexpr, out pexpr);

#line  1929 "cs.ATG" 
			((LambdaExpression)pexpr).IsAsync = true; 
		} else if (StartOf(18)) {
			Identifier();

#line  1933 "cs.ATG" 
			pexpr = new IdentifierExpression(t.val); 
			if (la.kind == 48 || 
#line  1936 "cs.ATG" 
IsGenericInSimpleNameOrMemberAccess()) {
				if (la.kind == 48) {
					ShortedLambdaExpression(
#line  1935 "cs.ATG" 
(IdentifierExpression)pexpr, out pexpr);
				} else {

#line  1937 "cs.ATG" 
					List<TypeReference> typeList; 
					TypeArgumentList(
#line  1938 "cs.ATG" 
out typeList, false);

#line  1939 "cs.ATG" 
					((IdentifierExpression)pexpr).TypeArguments = typeList; 
				}
			}
		} else if (
#line  1942 "cs.ATG" 
IsLambdaExpression()) {
			LambdaExpression(
#line  1943 "cs.ATG" 
out pexpr);
		} else if (la.kind == 20) {
			lexer.NextToken();
			Expr(
#line  1946 "cs.ATG" 
out expr);
			Expect(21);

#line  1946 "cs.ATG" 
			pexpr = new ParenthesizedExpression(expr); 
		} else if (StartOf(34)) {

#line  1949 "cs.ATG" 
			string val = null; 
			switch (la.kind) {
			case 52: {
				lexer.NextToken();

#line  1950 "cs.ATG" 
				val = "System.Boolean"; 
				break;
			}
			case 54: {
				lexer.NextToken();

#line  1951 "cs.ATG" 
				val = "System.Byte"; 
				break;
			}
			case 57: {
				lexer.NextToken();

#line  1952 "cs.ATG" 
				val = "System.Char"; 
				break;
			}
			case 62: {
				lexer.NextToken();

#line  1953 "cs.ATG" 
				val = "System.Decimal"; 
				break;
			}
			case 66: {
				lexer.NextToken();

#line  1954 "cs.ATG" 
				val = "System.Double"; 
				break;
			}
			case 75: {
				lexer.NextToken();

#line  1955 "cs.ATG" 
				val = "System.Single"; 
				break;
			}
			case 82: {
				lexer.NextToken();

#line  1956 "cs.ATG" 
				val = "System.Int32"; 
				break;
			}
			case 87: {
				lexer.NextToken();

#line  1957 "cs.ATG" 
				val = "System.Int64"; 
				break;
			}
			case 91: {
				lexer.NextToken();

#line  1958 "cs.ATG" 
				val = "System.Object"; 
				break;
			}
			case 102: {
				lexer.NextToken();

#line  1959 "cs.ATG" 
				val = "System.SByte"; 
				break;
			}
			case 104: {
				lexer.NextToken();

#line  1960 "cs.ATG" 
				val = "System.Int16"; 
				break;
			}
			case 108: {
				lexer.NextToken();

#line  1961 "cs.ATG" 
				val = "System.String"; 
				break;
			}
			case 116: {
				lexer.NextToken();

#line  1962 "cs.ATG" 
				val = "System.UInt32"; 
				break;
			}
			case 117: {
				lexer.NextToken();

#line  1963 "cs.ATG" 
				val = "System.UInt64"; 
				break;
			}
			case 120: {
				lexer.NextToken();

#line  1964 "cs.ATG" 
				val = "System.UInt16"; 
				break;
			}
			case 123: {
				lexer.NextToken();

#line  1965 "cs.ATG" 
				val = "System.Void"; 
				break;
			}
			}

#line  1967 "cs.ATG" 
			pexpr = new TypeReferenceExpression(new TypeReference(val, true)) { StartLocation = t.Location, EndLocation = t.EndLocation }; 
		} else if (la.kind == 111) {
			lexer.NextToken();

#line  1970 "cs.ATG" 
			pexpr = new ThisReferenceExpression(); pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; 
		} else if (la.kind == 51) {
			lexer.NextToken();

#line  1972 "cs.ATG" 
			pexpr = new BaseReferenceExpression(); pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; 
		} else if (la.kind == 89) {
			NewExpression(
#line  1975 "cs.ATG" 
out pexpr);
		} else if (la.kind == 115) {
			lexer.NextToken();
			Expect(20);
			if (
#line  1979 "cs.ATG" 
NotVoidPointer()) {
				Expect(123);

#line  1979 "cs.ATG" 
				type = new TypeReference("System.Void", true); 
			} else if (StartOf(10)) {
				TypeWithRestriction(
#line  1980 "cs.ATG" 
out type, true, true);
			} else SynErr(208);
			Expect(21);

#line  1982 "cs.ATG" 
			pexpr = new TypeOfExpression(type); 
		} else if (la.kind == 63) {
			lexer.NextToken();
			Expect(20);
			Type(
#line  1984 "cs.ATG" 
out type);
			Expect(21);

#line  1984 "cs.ATG" 
			pexpr = new DefaultValueExpression(type); 
		} else if (la.kind == 105) {
			lexer.NextToken();
			Expect(20);
			Type(
#line  1985 "cs.ATG" 
out type);
			Expect(21);

#line  1985 "cs.ATG" 
			pexpr = new SizeOfExpression(type); 
		} else if (la.kind == 58) {
			lexer.NextToken();
			Expect(20);
			Expr(
#line  1986 "cs.ATG" 
out expr);
			Expect(21);

#line  1986 "cs.ATG" 
			pexpr = new CheckedExpression(expr); 
		} else if (la.kind == 118) {
			lexer.NextToken();
			Expect(20);
			Expr(
#line  1987 "cs.ATG" 
out expr);
			Expect(21);

#line  1987 "cs.ATG" 
			pexpr = new UncheckedExpression(expr); 
		} else SynErr(209);

#line  1989 "cs.ATG" 
		if (pexpr != null) {
		if (pexpr.StartLocation.IsEmpty)
			pexpr.StartLocation = startLocation;
		if (pexpr.EndLocation.IsEmpty)
			pexpr.EndLocation = t.EndLocation;
		}
		
		while (StartOf(35)) {

#line  1997 "cs.ATG" 
			startLocation = la.Location; 
			switch (la.kind) {
			case 31: {
				lexer.NextToken();

#line  1999 "cs.ATG" 
				pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement); 
				break;
			}
			case 32: {
				lexer.NextToken();

#line  2001 "cs.ATG" 
				pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); 
				break;
			}
			case 47: {
				PointerMemberAccess(
#line  2003 "cs.ATG" 
out pexpr, pexpr);
				break;
			}
			case 15: {
				MemberAccess(
#line  2004 "cs.ATG" 
out pexpr, pexpr);
				break;
			}
			case 20: {
				lexer.NextToken();

#line  2008 "cs.ATG" 
				List<Expression> parameters = new List<Expression>(); 

#line  2009 "cs.ATG" 
				pexpr = new InvocationExpression(pexpr, parameters); 
				if (StartOf(25)) {
					Argument(
#line  2010 "cs.ATG" 
out expr);

#line  2010 "cs.ATG" 
					SafeAdd(pexpr, parameters, expr); 
					while (la.kind == 14) {
						lexer.NextToken();
						Argument(
#line  2011 "cs.ATG" 
out expr);

#line  2011 "cs.ATG" 
						SafeAdd(pexpr, parameters, expr); 
					}
				}
				Expect(21);
				break;
			}
			case 18: {

#line  2017 "cs.ATG" 
				List<Expression> indices = new List<Expression>();
				pexpr = new IndexerExpression(pexpr, indices);
				
				lexer.NextToken();
				Expr(
#line  2020 "cs.ATG" 
out expr);

#line  2020 "cs.ATG" 
				SafeAdd(pexpr, indices, expr); 
				while (la.kind == 14) {
					lexer.NextToken();
					Expr(
#line  2021 "cs.ATG" 
out expr);

#line  2021 "cs.ATG" 
					SafeAdd(pexpr, indices, expr); 
				}
				Expect(19);
				break;
			}
			}

#line  2024 "cs.ATG" 
			if (pexpr != null) {
			if (pexpr.StartLocation.IsEmpty)
				pexpr.StartLocation = startLocation;
			if (pexpr.EndLocation.IsEmpty)
				pexpr.EndLocation = t.EndLocation;
			}
			
		}
	}
		public override object VisitIndexerExpression(IndexerExpression indexerExpression, object data)
		{
			IReturnType target = ResolveType(indexerExpression.TargetObject);
			return CreateMemberResolveResult(
				GetIndexer(target, indexerExpression.Indexes)
			);
		}
		public virtual object VisitIndexerExpression(IndexerExpression indexerExpression, object data) {
			throw new global::System.NotImplementedException("IndexerExpression");
		}
Beispiel #22
0
		public override object VisitIndexerExpression(IndexerExpression indexerExpression, object data)
		{
			if (indexerExpression.Indexes == null || indexerExpression.Indexes.Count == 0)
				return null;
			ResolveResult result = Resolve (indexerExpression.TargetObject);
			
			if (result.ResolvedType != null && result.ResolvedType.ArrayDimensions > 0) {
				((DomReturnType)result.ResolvedType).ArrayDimensions--;
				return CreateResult (result.ResolvedType);
			}
			
			IType resolvedType = resolver.Dom.GetType (result.ResolvedType);
			if (resolvedType != null) {
				foreach (IType curType in resolver.Dom.GetInheritanceTree (resolvedType)) {
					foreach (IProperty property in curType.Properties) {
						if (property.IsExplicitDeclaration)
							continue;
						if (property.IsIndexer)
							return CreateResult (property.ReturnType);
					}
				}
			}
			if (result.ResolvedType != null && result.ResolvedType.GenericArguments.Count > 0) {
				return CreateResult (result.ResolvedType.GenericArguments[0]);
			}
			return result;
		}
		public sealed override object VisitIndexerExpression(IndexerExpression indexerExpression, object data) {
			this.BeginVisit(indexerExpression);
			object result = this.TrackedVisitIndexerExpression(indexerExpression, data);
			this.EndVisit(indexerExpression);
			return result;
		}
Beispiel #24
0
 public virtual object VisitIndexerExpression(IndexerExpression indexerExpression, object data)
 {
     Debug.Assert((indexerExpression != null));
     Debug.Assert((indexerExpression.TargetObject != null));
     Debug.Assert((indexerExpression.Indexes != null));
     indexerExpression.TargetObject.AcceptVisitor(this, data);
     foreach (Expression o in indexerExpression.Indexes) {
         Debug.Assert(o != null);
         o.AcceptVisitor(this, data);
     }
     return null;
 }
 private bool IsMatch(IndexerExpression left, IndexerExpression right)
 {
     return true;
 }
			public override object VisitIndexerExpression (IndexerExpression 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));
				} else
					e.TargetObject.AcceptVisitor (this, data);
				
				foreach (Expression o in e.Indexes) {
					o.AcceptVisitor(this, data);
				}
				return null;
			}
Beispiel #27
0
	void PrimaryExpr(
#line  1849 "cs.ATG" 
out Expression pexpr) {

#line  1851 "cs.ATG" 
		TypeReference type = null;
		Expression expr;
		pexpr = null;
		

#line  1856 "cs.ATG" 
		Location startLocation = la.Location; 
		if (la.kind == 113) {
			lexer.NextToken();

#line  1858 "cs.ATG" 
			pexpr = new PrimitiveExpression(true, "true");  
		} else if (la.kind == 72) {
			lexer.NextToken();

#line  1859 "cs.ATG" 
			pexpr = new PrimitiveExpression(false, "false"); 
		} else if (la.kind == 90) {
			lexer.NextToken();

#line  1860 "cs.ATG" 
			pexpr = new PrimitiveExpression(null, "null");  
		} else if (la.kind == 2) {
			lexer.NextToken();

#line  1861 "cs.ATG" 
            PrimitiveExpression primitiveExpression = new PrimitiveExpression(t.literalValue, t.val);
            primitiveExpression.LiteralFormat = t.literalFormat;
            pexpr = primitiveExpression;
            
		} else if (
#line  1862 "cs.ATG" 
StartOfQueryExpression()) {
			QueryExpression(
#line  1863 "cs.ATG" 
out pexpr);
		} else if (
#line  1864 "cs.ATG" 
IdentAndDoubleColon()) {
			Identifier();

#line  1865 "cs.ATG" 
			type = new TypeReference(t.val); 
			Expect(10);

#line  1866 "cs.ATG" 
			pexpr = new TypeReferenceExpression(type); 
			Identifier();

#line  1867 "cs.ATG" 
			if (type.Type == "global") { type.IsGlobal = true; type.Type = t.val ?? "?"; } else type.Type += "." + (t.val ?? "?"); 
		} else if (StartOf(19)) {
			Identifier();

#line  1871 "cs.ATG" 
			pexpr = new IdentifierExpression(t.val); 
			if (la.kind == 48 || 
#line  1874 "cs.ATG" 
IsGenericInSimpleNameOrMemberAccess()) {
				if (la.kind == 48) {
					ShortedLambdaExpression(
#line  1873 "cs.ATG" 
(IdentifierExpression)pexpr, out pexpr);
				} else {

#line  1875 "cs.ATG" 
					List<TypeReference> typeList; 
					TypeArgumentList(
#line  1876 "cs.ATG" 
out typeList, false);

#line  1877 "cs.ATG" 
					((IdentifierExpression)pexpr).TypeArguments = typeList; 
				}
			}
		} else if (
#line  1879 "cs.ATG" 
IsLambdaExpression()) {
			LambdaExpression(
#line  1880 "cs.ATG" 
out pexpr);
		} else if (la.kind == 20) {
			lexer.NextToken();
			Expr(
#line  1883 "cs.ATG" 
out expr);
			Expect(21);

#line  1883 "cs.ATG" 
			pexpr = new ParenthesizedExpression(expr); 
		} else if (StartOf(35)) {

#line  1886 "cs.ATG" 
			string val = null; 
			switch (la.kind) {
			case 52: {
				lexer.NextToken();

#line  1887 "cs.ATG" 
				val = "System.Boolean"; 
				break;
			}
			case 54: {
				lexer.NextToken();

#line  1888 "cs.ATG" 
				val = "System.Byte"; 
				break;
			}
			case 57: {
				lexer.NextToken();

#line  1889 "cs.ATG" 
				val = "System.Char"; 
				break;
			}
			case 62: {
				lexer.NextToken();

#line  1890 "cs.ATG" 
				val = "System.Decimal"; 
				break;
			}
			case 66: {
				lexer.NextToken();

#line  1891 "cs.ATG" 
				val = "System.Double"; 
				break;
			}
			case 75: {
				lexer.NextToken();

#line  1892 "cs.ATG" 
				val = "System.Single"; 
				break;
			}
			case 82: {
				lexer.NextToken();

#line  1893 "cs.ATG" 
				val = "System.Int32"; 
				break;
			}
			case 87: {
				lexer.NextToken();

#line  1894 "cs.ATG" 
				val = "System.Int64"; 
				break;
			}
			case 91: {
				lexer.NextToken();

#line  1895 "cs.ATG" 
				val = "System.Object"; 
				break;
			}
			case 102: {
				lexer.NextToken();

#line  1896 "cs.ATG" 
				val = "System.SByte"; 
				break;
			}
			case 104: {
				lexer.NextToken();

#line  1897 "cs.ATG" 
				val = "System.Int16"; 
				break;
			}
			case 108: {
				lexer.NextToken();

#line  1898 "cs.ATG" 
				val = "System.String"; 
				break;
			}
			case 116: {
				lexer.NextToken();

#line  1899 "cs.ATG" 
				val = "System.UInt32"; 
				break;
			}
			case 117: {
				lexer.NextToken();

#line  1900 "cs.ATG" 
				val = "System.UInt64"; 
				break;
			}
			case 120: {
				lexer.NextToken();

#line  1901 "cs.ATG" 
				val = "System.UInt16"; 
				break;
			}
			case 123: {
				lexer.NextToken();

#line  1902 "cs.ATG" 
				val = "System.Void"; 
				break;
			}
			}

#line  1904 "cs.ATG" 
			pexpr = new TypeReferenceExpression(new TypeReference(val, true));
            pexpr.StartLocation = t.Location;
            pexpr.EndLocation = t.EndLocation; 
		} else if (la.kind == 111) {
			lexer.NextToken();

#line  1907 "cs.ATG" 
			pexpr = new ThisReferenceExpression(); pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; 
		} else if (la.kind == 51) {
			lexer.NextToken();

#line  1909 "cs.ATG" 
			pexpr = new BaseReferenceExpression(); pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; 
		} else if (la.kind == 89) {
			NewExpression(
#line  1912 "cs.ATG" 
out pexpr);
		} else if (la.kind == 115) {
			lexer.NextToken();
			Expect(20);
			if (
#line  1916 "cs.ATG" 
NotVoidPointer()) {
				Expect(123);

#line  1916 "cs.ATG" 
				type = new TypeReference("System.Void", true); 
			} else if (StartOf(10)) {
				TypeWithRestriction(
#line  1917 "cs.ATG" 
out type, true, true);
			} else SynErr(207);
			Expect(21);

#line  1919 "cs.ATG" 
			pexpr = new TypeOfExpression(type); 
		} else if (la.kind == 63) {
			lexer.NextToken();
			Expect(20);
			Type(
#line  1921 "cs.ATG" 
out type);
			Expect(21);

#line  1921 "cs.ATG" 
			pexpr = new DefaultValueExpression(type); 
		} else if (la.kind == 105) {
			lexer.NextToken();
			Expect(20);
			Type(
#line  1922 "cs.ATG" 
out type);
			Expect(21);

#line  1922 "cs.ATG" 
			pexpr = new SizeOfExpression(type); 
		} else if (la.kind == 58) {
			lexer.NextToken();
			Expect(20);
			Expr(
#line  1923 "cs.ATG" 
out expr);
			Expect(21);

#line  1923 "cs.ATG" 
			pexpr = new CheckedExpression(expr); 
		} else if (la.kind == 118) {
			lexer.NextToken();
			Expect(20);
			Expr(
#line  1924 "cs.ATG" 
out expr);
			Expect(21);

#line  1924 "cs.ATG" 
			pexpr = new UncheckedExpression(expr); 
		} else if (la.kind == 64) {
			lexer.NextToken();
			AnonymousMethodExpr(
#line  1925 "cs.ATG" 
out expr);

#line  1925 "cs.ATG" 
			pexpr = expr; 
		} else SynErr(208);

#line  1927 "cs.ATG" 
		if (pexpr != null) {
		if (pexpr.StartLocation.IsEmpty)
			pexpr.StartLocation = startLocation;
		if (pexpr.EndLocation.IsEmpty)
			pexpr.EndLocation = t.EndLocation;
		}
		
		while (StartOf(36)) {

#line  1935 "cs.ATG" 
			startLocation = la.Location; 
			switch (la.kind) {
			case 31: {
				lexer.NextToken();

#line  1937 "cs.ATG" 
				pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement); 
				break;
			}
			case 32: {
				lexer.NextToken();

#line  1939 "cs.ATG" 
				pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); 
				break;
			}
			case 47: {
				PointerMemberAccess(
#line  1941 "cs.ATG" 
out pexpr, pexpr);
				break;
			}
			case 15: {
				MemberAccess(
#line  1942 "cs.ATG" 
out pexpr, pexpr);
				break;
			}
			case 20: {
				lexer.NextToken();

#line  1946 "cs.ATG" 
				List<Expression> parameters = new List<Expression>(); 

#line  1947 "cs.ATG" 
				pexpr = new InvocationExpression(pexpr, parameters); 
				if (StartOf(26)) {
					Argument(
#line  1948 "cs.ATG" 
out expr);

#line  1948 "cs.ATG" 
					SafeAdd(pexpr, parameters, expr); 
					while (la.kind == 14) {
						lexer.NextToken();
						Argument(
#line  1949 "cs.ATG" 
out expr);

#line  1949 "cs.ATG" 
						SafeAdd(pexpr, parameters, expr); 
					}
				}
				Expect(21);
				break;
			}
			case 18: {

#line  1955 "cs.ATG" 
				List<Expression> indices = new List<Expression>();
				pexpr = new IndexerExpression(pexpr, indices);
				
				lexer.NextToken();
				Expr(
#line  1958 "cs.ATG" 
out expr);

#line  1958 "cs.ATG" 
				SafeAdd(pexpr, indices, expr); 
				while (la.kind == 14) {
					lexer.NextToken();
					Expr(
#line  1959 "cs.ATG" 
out expr);

#line  1959 "cs.ATG" 
					SafeAdd(pexpr, indices, expr); 
				}
				Expect(19);
				break;
			}
			}

#line  1962 "cs.ATG" 
			if (pexpr != null) {
			if (pexpr.StartLocation.IsEmpty)
				pexpr.StartLocation = startLocation;
			if (pexpr.EndLocation.IsEmpty)
				pexpr.EndLocation = t.EndLocation;
			}
			
		}
	}
		public virtual object TrackedVisitIndexerExpression(IndexerExpression indexerExpression, object data) {
			return base.VisitIndexerExpression(indexerExpression, data);
		}
		public override object VisitIndexerExpression(IndexerExpression indexerExpression, object data)
		{
			TypedValue target = Evaluate(indexerExpression.TargetObject);
			
			if (target.Type.IsArray) {
				List<int> intIndexes = new List<int>();
				foreach(Expression indexExpr in indexerExpression.Indexes) {
					intIndexes.Add(EvaluateAsInt(indexExpr));
				}
				return new TypedValue(
					target.Value.GetArrayElement(intIndexes.ToArray()),
					(DebugType)target.Type.GetElementType()
				);
			} else if (target.Type.FullName == typeof(string).FullName) {
				if (indexerExpression.Indexes.Count != 1)
					throw new GetValueException("Single index expected");
				
				int index = EvaluateAsInt(indexerExpression.Indexes[0]);
				string str = (string)target.PrimitiveValue;
				if (index < 0 || index >= str.Length)
					throw new GetValueException("Index was outside the bounds of the array.");
				return CreateValue(str[index]);
			} else {
				List<TypedValue> indexes = EvaluateAll(indexerExpression.Indexes);
				DebugPropertyInfo pi = (DebugPropertyInfo)target.Type.GetProperty("Item", GetTypes(indexes));
				if (pi == null)
					throw new GetValueException("The object does not have an indexer property");
				return new TypedValue(
					target.Value.GetPropertyValue(pi, GetValues(indexes)),
					(DebugType)pi.PropertyType
				);
			}
		}
 public override object TrackedVisitIndexerExpression(IndexerExpression indexerExpression, object data)
 {
     indexerExpression.TargetObject.AcceptVisitor(this, data);
     foreach (Expression index in indexerExpression.Indexes)
     {
         this.Append("[");
         index.AcceptVisitor(this, data);
         this.Append("]");
     }
     return null;
 }
		public virtual object VisitIndexerExpression(IndexerExpression indexerExpression, object data) {
			Debug.Assert((indexerExpression != null));
			Debug.Assert((indexerExpression.TargetObject != null));
			Debug.Assert((indexerExpression.Indexes != null));
			nodeStack.Push(indexerExpression.TargetObject);
			indexerExpression.TargetObject.AcceptVisitor(this, data);
			indexerExpression.TargetObject = ((Expression)(nodeStack.Pop()));
			for (int i = 0; i < indexerExpression.Indexes.Count; i++) {
				Expression o = indexerExpression.Indexes[i];
				Debug.Assert(o != null);
				nodeStack.Push(o);
				o.AcceptVisitor(this, data);
				o = (Expression)nodeStack.Pop();
				if (o == null)
					indexerExpression.Indexes.RemoveAt(i--);
				else
					indexerExpression.Indexes[i] = o;
			}
			return null;
		}