예제 #1
0
 public object VisitInvocationExpression(InvocationExpression ie, object data)
 {
     B.Expression e = ConvertExpression(ie.TargetObject);
     if (e == null)
     {
         return(null);
     }
     if (settings.IsVisualBasic && ie.TargetObject is IdentifierExpression && currentStatement != null)
     {
         VariableResolver resolver = new VariableResolver(nameComparer);
         TypeReference    typeRef  = resolver.FindType((ie.TargetObject as IdentifierExpression).Identifier, currentStatement);
         if (typeRef != null && typeRef.IsArrayType)
         {
             // Visual Basic: indexer expression
             B.SlicingExpression s = new B.SlicingExpression(GetLexicalInfo(ie));
             s.Target = e;
             foreach (Expression expr in ie.Arguments)
             {
                 s.Indices.Add(new B.Slice(ConvertExpression(expr)));
             }
             return(s);
         }
     }
     B.MethodInvocationExpression r = new B.MethodInvocationExpression(GetLexicalInfo(ie), e);
     foreach (Expression expr in ie.Arguments)
     {
         e = ConvertExpression(expr);
         if (e != null)
         {
             r.Arguments.Add(e);
         }
     }
     return(r);
 }
예제 #2
0
        public object VisitReDimStatement(ReDimStatement reDimStatement, object data)
        {
            // Redim [Preserve] a(newBounds)
            // without preserve:
            //    a = array(Type, newBounds)
            // with preserve:
            //    ??1 = array(Type, newBounds)
            //    Array.Copy(a, ??1, System.Math.Min(a.Length, ??1.Length))
            //    a = ??1
            if (reDimStatement.IsPreserve)
            {
                AddError(reDimStatement, "Redim Preserve is not supported.");
            }
            ArrayList list = new ArrayList();

            foreach (InvocationExpression o in reDimStatement.ReDimClauses)
            {
                IdentifierExpression identifier = o.TargetObject as IdentifierExpression;
                if (identifier == null)
                {
                    AddError(o, "Sorry, that expression is too complex to be resolved by the converter.");
                }
                else
                {
                    if (identifier.TypeArguments != null && identifier.TypeArguments.Count > 0)
                    {
                        AddError(o, "Type parameters are not allowed here.");
                    }

                    // first we need to find out the array type
                    VariableResolver resolver = new VariableResolver(nameComparer);
                    TypeReference    r        = resolver.FindType(identifier.Identifier, reDimStatement);
                    if (r == null)
                    {
                        AddError(o, "The name '" + identifier.Identifier + "' could not be resolved by the converter.");
                    }
                    else if (!r.IsArrayType)
                    {
                        AddError(o, identifier.Identifier + " is not an array.");
                    }
                    else
                    {
                        ArrayCreateExpression ace = new ArrayCreateExpression(r);
                        foreach (Expression boundExpr in o.Arguments)
                        {
                            ace.Arguments.Add(Expression.AddInteger((Expression)boundExpr, 1));
                        }
                        ace.StartLocation = o.StartLocation;
                        B.Expression expr = new B.ReferenceExpression(GetLexicalInfo(identifier), identifier.Identifier);
                        expr = new B.BinaryExpression(GetLexicalInfo(reDimStatement), B.BinaryOperatorType.Assign, expr, ConvertExpression(ace));
                        list.Add(new B.ExpressionStatement(expr));
                    }
                }
            }
            return(list);
        }
		public object VisitReDimStatement(ReDimStatement reDimStatement, object data)
		{
			// Redim [Preserve] a(newBounds)
			// without preserve:
			//    a = array(Type, newBounds)
			// with preserve:
			//    ??1 = array(Type, newBounds)
			//    Array.Copy(a, ??1, System.Math.Min(a.Length, ??1.Length))
			//    a = ??1
			if (reDimStatement.IsPreserve)
				AddError(reDimStatement, "Redim Preserve is not supported.");
			ArrayList list = new ArrayList();
			foreach (InvocationExpression o in reDimStatement.ReDimClauses) {
				IdentifierExpression identifier = o.TargetObject as IdentifierExpression;
				if (identifier == null) {
					AddError(o, "Sorry, that expression is too complex to be resolved by the converter.");
				} else {
					if (identifier.TypeArguments != null && identifier.TypeArguments.Count > 0) {
						AddError(o, "Type parameters are not allowed here.");
					}
					
					// first we need to find out the array type
					VariableResolver resolver = new VariableResolver(nameComparer);
					TypeReference r = resolver.FindType(identifier.Identifier, reDimStatement);
					if (r == null) {
						AddError(o, "The name '" + identifier.Identifier + "' could not be resolved by the converter.");
					} else if (!r.IsArrayType) {
						AddError(o, identifier.Identifier + " is not an array.");
					} else {
						ArrayCreateExpression ace = new ArrayCreateExpression(r);
						foreach (Expression boundExpr in o.Arguments) {
							ace.Arguments.Add(Expression.AddInteger((Expression)boundExpr, 1));
						}
						ace.StartLocation = o.StartLocation;
						B.Expression expr = new B.ReferenceExpression(GetLexicalInfo(identifier), identifier.Identifier);
						expr = new B.BinaryExpression(GetLexicalInfo(reDimStatement), B.BinaryOperatorType.Assign, expr, ConvertExpression(ace));
						list.Add(new B.ExpressionStatement(expr));
					}
				}
			}
			return list;
		}
		public object VisitInvocationExpression(InvocationExpression ie, object data)
		{
			B.Expression e = ConvertExpression(ie.TargetObject);
			if (e == null)
				return null;
			if (settings.IsVisualBasic && ie.TargetObject is IdentifierExpression && currentStatement != null) {
				VariableResolver resolver = new VariableResolver(nameComparer);
				TypeReference typeRef = resolver.FindType((ie.TargetObject as IdentifierExpression).Identifier, currentStatement);
				if (typeRef != null && typeRef.IsArrayType) {
					// Visual Basic: indexer expression
					B.SlicingExpression s = new B.SlicingExpression(GetLexicalInfo(ie));
					s.Target = e;
					foreach (Expression expr in ie.Arguments) {
						s.Indices.Add(new B.Slice(ConvertExpression(expr)));
					}
					return s;
				}
			}
			B.MethodInvocationExpression r = new B.MethodInvocationExpression(GetLexicalInfo(ie), e);
			foreach (Expression expr in ie.Arguments) {
				e = ConvertExpression(expr);
				if (e != null) {
					r.Arguments.Add(e);
				}
			}
			return r;
		}