Example #1
0
			public static string EvaluateMethodCoupling(InvocationExpression expression, MethodProperties meth)
			{
				Console.WriteLine(expression.ToString());
				
				meth.EfferentCoupling++;
				
				StringBuilder calleeName = new StringBuilder();
				List<string> paramList = new List<string>();
				MethodProperties methCallee = null;
				lock(coupleLock)
				{
					if(expression.TargetObject is MemberReferenceExpression) {
					
			   			calleeName.Append(ExtractCalleeFullName((MemberReferenceExpression)(expression.TargetObject), meth));
						paramList = ExtractParamList(expression, meth);
					
						try {
							methCallee = ComplexityMetrics.ProjProp.GetMethodReference(calleeName.ToString(), paramList);
							methCallee.AfferentCoupling++;
						} catch (Exception e) {
							Console.WriteLine(e.ToString());
						}
					
					} else if (expression.TargetObject is IdentifierExpression) {
					
						calleeName.Append(((IdentifierExpression)expression.TargetObject).Identifier);
						paramList = ExtractParamList(expression, meth);
					
						try {
							Console.WriteLine(calleeName.ToString());
							methCallee = ComplexityMetrics.ProjProp.GetMethodReference(calleeName.ToString(), paramList);
							methCallee.AfferentCoupling++;
						} catch (Exception e) {
							Console.WriteLine(e.ToString());
						}
					} 
				}
				return methCallee.Method.ReturnType.FullName;
			}
Example #2
0
	void PrimaryExpr(
#line  1888 "Frames/cs.ATG" 
out Expression pexpr) {

#line  1890 "Frames/cs.ATG" 
		TypeReference type = null;
		Expression expr;
		pexpr = null;
		

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

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

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

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

#line  1900 "Frames/cs.ATG" 
			pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
		} else if (
#line  1901 "Frames/cs.ATG" 
StartOfQueryExpression()) {
			QueryExpression(
#line  1902 "Frames/cs.ATG" 
out pexpr);
		} else if (
#line  1903 "Frames/cs.ATG" 
IdentAndDoubleColon()) {
			Identifier();

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

#line  1905 "Frames/cs.ATG" 
			pexpr = new TypeReferenceExpression(type); 
			Identifier();

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

#line  1910 "Frames/cs.ATG" 
			pexpr = new IdentifierExpression(t.val); 
			if (la.kind == 48 || 
#line  1913 "Frames/cs.ATG" 
IsGenericInSimpleNameOrMemberAccess()) {
				if (la.kind == 48) {
					ShortedLambdaExpression(
#line  1912 "Frames/cs.ATG" 
(IdentifierExpression)pexpr, out pexpr);
				} else {

#line  1914 "Frames/cs.ATG" 
					List<TypeReference> typeList; 
					TypeArgumentList(
#line  1915 "Frames/cs.ATG" 
out typeList, false);

#line  1916 "Frames/cs.ATG" 
					((IdentifierExpression)pexpr).TypeArguments = typeList; 
				}
			}
		} else if (
#line  1918 "Frames/cs.ATG" 
IsLambdaExpression()) {
			LambdaExpression(
#line  1919 "Frames/cs.ATG" 
out pexpr);
		} else if (la.kind == 20) {
			lexer.NextToken();
			Expr(
#line  1922 "Frames/cs.ATG" 
out expr);
			Expect(21);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#line  1941 "Frames/cs.ATG" 
				val = "System.Void"; 
				break;
			}
			}

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

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

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

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

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

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

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

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

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

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

#line  1966 "Frames/cs.ATG" 
		if (pexpr != null) {
		if (pexpr.StartLocation.IsEmpty)
			pexpr.StartLocation = startLocation;
		if (pexpr.EndLocation.IsEmpty)
			pexpr.EndLocation = t.EndLocation;
		}
		
		while (StartOf(36)) {
			if (la.kind == 31 || la.kind == 32) {

#line  1974 "Frames/cs.ATG" 
				startLocation = la.Location; 
				if (la.kind == 31) {
					lexer.NextToken();

#line  1976 "Frames/cs.ATG" 
					pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement); 
				} else if (la.kind == 32) {
					lexer.NextToken();

#line  1977 "Frames/cs.ATG" 
					pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); 
				} else SynErr(209);
			} else if (la.kind == 47) {
				PointerMemberAccess(
#line  1980 "Frames/cs.ATG" 
out pexpr, pexpr);
			} else if (la.kind == 15) {
				MemberAccess(
#line  1981 "Frames/cs.ATG" 
out pexpr, pexpr);
			} else if (la.kind == 20) {
				lexer.NextToken();

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

#line  1986 "Frames/cs.ATG" 
				pexpr = new InvocationExpression(pexpr, parameters); pexpr.StartLocation = startLocation; 
				if (StartOf(26)) {
					Argument(
#line  1987 "Frames/cs.ATG" 
out expr);

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

#line  1988 "Frames/cs.ATG" 
						SafeAdd(pexpr, parameters, expr); 
					}
				}
				Expect(21);
			} else {

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

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

#line  1998 "Frames/cs.ATG" 
					SafeAdd(pexpr, indices, expr); 
				}
				Expect(19);

#line  2001 "Frames/cs.ATG" 
				if (pexpr != null) {
				pexpr.StartLocation = startLocation;
				pexpr.EndLocation = t.EndLocation;
				}
				
			}
		}
	}
		public sealed override object VisitInvocationExpression(InvocationExpression invocationExpression, object data) {
			this.BeginVisit(invocationExpression);
			object result = this.TrackedVisitInvocationExpression(invocationExpression, data);
			this.EndVisit(invocationExpression);
			return result;
		}
		public virtual object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data) {
			return base.VisitInvocationExpression(invocationExpression, data);
		}
		public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
		{
			IdentifierExpression ident = invocationExpression.TargetObject as IdentifierExpression;
			if (ident != null) {
				if ("IIF".Equals(ident.Identifier, StringComparison.InvariantCultureIgnoreCase)
				    && invocationExpression.Arguments.Count == 3)
				{
					ConditionalExpression ce = new ConditionalExpression(invocationExpression.Arguments[0],
					                                                     invocationExpression.Arguments[1],
					                                                     invocationExpression.Arguments[2]);
					ReplaceCurrentNode(new ParenthesizedExpression(ce));
					return base.VisitConditionalExpression(ce, data);
				}
				if ("IsNothing".Equals(ident.Identifier, StringComparison.InvariantCultureIgnoreCase)
				    && invocationExpression.Arguments.Count == 1)
				{
					BinaryOperatorExpression boe = new BinaryOperatorExpression(invocationExpression.Arguments[0],
					                                                            BinaryOperatorType.ReferenceEquality,
					                                                            new PrimitiveExpression(null, "null"));
					ReplaceCurrentNode(new ParenthesizedExpression(boe));
					return base.VisitBinaryOperatorExpression(boe, data);
				}
				if (methodTable == null) {
					methodTable = CreateDictionary("Conversion", "FileSystem", "Financial", "Information",
					                               "Interaction", "Strings", "VBMath");
				}
				Expression expr;
				if (methodTable.TryGetValue(ident.Identifier, out expr)) {
					MemberReferenceExpression fre = new MemberReferenceExpression(expr, ident.Identifier);
					invocationExpression.TargetObject = fre;
				}
			}
			return base.VisitInvocationExpression(invocationExpression, data);
		}
Example #6
0
			public void VisitExpression (InvocationExpression expression, MethodProperties meth)
			{
				//Coupling.EvaluateMethodCoupling(expression, meth);
			}
Example #7
0
	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);
			}
		}
		
	}
		public virtual object VisitInvocationExpression(InvocationExpression invocationExpression, object data) {
			throw new global::System.NotImplementedException("InvocationExpression");
		}
Example #9
0
	void InvocationExpression(
#line  1743 "VBNET.ATG" 
ref Expression pexpr) {

#line  1744 "VBNET.ATG" 
		List<Expression> parameters = null; 
		Expect(25);

#line  1746 "VBNET.ATG" 
		Location start = t.Location; 
		ArgumentList(
#line  1747 "VBNET.ATG" 
out parameters);
		Expect(26);

#line  1750 "VBNET.ATG" 
		pexpr = new InvocationExpression(pexpr, parameters);
		

#line  1752 "VBNET.ATG" 
		pexpr.StartLocation = start; pexpr.EndLocation = t.Location; 
	}
Example #10
0
			private static List<string> ExtractParamList(InvocationExpression expression, MethodProperties meth)
			{
				List<string> retVal = new List<string>();
				foreach(Expression param in expression.Arguments)
				{
					if(param is PrimitiveExpression) {
						retVal.Add(((PrimitiveExpression)param).Value.GetType().Name);
						continue;
					} else if(param is BinaryOperatorExpression) {
						if(((BinaryOperatorExpression)param).Op == BinaryOperatorType.LogicalAnd || ((BinaryOperatorExpression)param).Op == BinaryOperatorType.LogicalOr)
							retVal.Add("System.Boolean");
						continue;
					} else if (param is InvocationExpression) {
						// TODO Deal with method calls within method calls
						// Lots of cases
						retVal.Add(EvaluateMethodCoupling((InvocationExpression)param, meth));
					}
					
				}
				return retVal;
			}
Example #11
0
		public override object VisitQueryExpression(QueryExpression queryExpression, object data)
		{
			if (this.queryExpression != null) // prevent endloss loop: var n = from n select n; n.$ (doesn't make sense, but you can type this)
				return null;
			this.queryExpression = queryExpression;
			IReturnType type = null;
			QueryExpressionSelectClause selectClause = queryExpression.SelectOrGroupClause as QueryExpressionSelectClause;
			if (selectClause != null) {
				InvocationExpression selectInvocation = new InvocationExpression (new MemberReferenceExpression (queryExpression.FromClause.InExpression, "Select"));
				LambdaExpression selectLambdaExpr = new LambdaExpression ();
				selectLambdaExpr.Parent = selectInvocation;
				selectLambdaExpr.Parameters.Add (new ParameterDeclarationExpression (null, "par"));
				selectLambdaExpr.ExpressionBody = selectClause.Projection;
				TypeReference typeRef = new TypeReference ("System.Func");
				typeRef.GenericTypes.Add (TypeReference.Null);
				ResolveResult result = resolver.ResolveExpression (selectLambdaExpr, resolver.ResolvePosition, false);
				
				typeRef.GenericTypes.Add (NRefactoryResolver.ConvertToTypeReference (result.ResolvedType));
				
				ObjectCreateExpression createExpression = new ObjectCreateExpression (typeRef, new List<Expression> (new Expression [] {
					null,
					selectLambdaExpr
				}));
				
				selectInvocation.Arguments.Add (createExpression);
				return CreateResult (ResolveType (selectInvocation));
			}
			
			QueryExpressionGroupClause groupClause = queryExpression.SelectOrGroupClause as QueryExpressionGroupClause;
			if (groupClause != null) {
				InvocationExpression groupInvocation = new InvocationExpression (new MemberReferenceExpression (queryExpression.FromClause.InExpression, "GroupBy"));
				
				LambdaExpression keyLambdaExpr = new LambdaExpression ();
				keyLambdaExpr.Parent = groupInvocation;
				keyLambdaExpr.Parameters.Add (new ParameterDeclarationExpression (null, "par"));
				keyLambdaExpr.ExpressionBody = groupClause.GroupBy;
				groupInvocation.Arguments.Add (keyLambdaExpr);
				
				LambdaExpression elementLambdaExpr = new LambdaExpression ();
				elementLambdaExpr.Parent = groupInvocation;
				elementLambdaExpr.Parameters.Add (new ParameterDeclarationExpression (null, "par"));
				elementLambdaExpr.ExpressionBody = groupClause.Projection;
				groupInvocation.Arguments.Add (elementLambdaExpr);
				return CreateResult (ResolveType (groupInvocation));
			}
			
			if (type != null) 
				return CreateResult (new DomReturnType("System.Collections.Generic.IEnumerable", false, new List<IReturnType> (new IReturnType[] { type })));
			return null;
		}
Example #12
0
		public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
		{
			if (invocationExpression == null) 
				return null;
			
			if (invocationDictionary.ContainsKey (invocationExpression))
				return invocationDictionary[invocationExpression];
			
			// add support for undocumented __makeref and __reftype keywords
			if (invocationExpression.TargetObject is IdentifierExpression) {
				IdentifierExpression idExpr = invocationExpression.TargetObject as IdentifierExpression;
				if (idExpr.Identifier == "__makeref") 
					return CreateResult ("System.TypedReference");
				if (idExpr.Identifier == "__reftype") 
					return CreateResult ("System.Type");
			}
			
			ResolveResult targetResult = Resolve (invocationExpression.TargetObject);
			if (targetResult is CombinedMethodResolveResult)
				targetResult = ((CombinedMethodResolveResult)targetResult).MethodResolveResult;
			bool targetIsStatic = targetResult.StaticResolve;
			targetResult.StaticResolve = false; // invocation results are never static because they return objects
			if (this.resolver.CallingType != null) {
				if (targetResult is ThisResolveResult) {
					targetResult = new MethodResolveResult (this.resolver.CallingType.Methods.Where (method => method.IsConstructor));
					((MethodResolveResult)targetResult).Type = this.resolver.CallingType;
					targetResult.CallingType   = resolver.CallingType;
					targetResult.CallingMember = resolver.CallingMember;
				} else if (targetResult is BaseResolveResult) {
					System.Collections.IEnumerable baseConstructors = null;
					IType firstBaseType = null;
					foreach (IReturnType bT in this.resolver.CallingType.BaseTypes) {
						IType resolvedBaseType = resolver.SearchType (bT);
						if (firstBaseType == null && resolvedBaseType.ClassType != MonoDevelop.Projects.Dom.ClassType.Interface)
							firstBaseType = resolvedBaseType;
						foreach (IType baseType in resolver.Dom.GetInheritanceTree (resolvedBaseType)) {
							if (baseType.ClassType == MonoDevelop.Projects.Dom.ClassType.Interface)
								break;
							baseConstructors = baseType.Methods.Where (method => method.IsConstructor);
							goto bailOut;
						}
					}
				bailOut:
					if (baseConstructors == null) {
						if (firstBaseType != null) {
							// if there is a real base type without a .ctor a default .ctor for this type is generated.
							DomMethod constructedConstructor;
							constructedConstructor = new DomMethod ();
							constructedConstructor.Name = ".ctor";
							constructedConstructor.MethodModifier = MethodModifier.IsConstructor;
							constructedConstructor.DeclaringType = firstBaseType;
							constructedConstructor.Modifiers = MonoDevelop.Projects.Dom.Modifiers.Public;
							baseConstructors = new IMethod[] {
								constructedConstructor
							};
						} else {
							baseConstructors = resolver.SearchType (DomReturnType.Object).SearchMember (".ctor", true);
						}
						
					}
					targetResult = new MethodResolveResult (baseConstructors);
					((MethodResolveResult)targetResult).Type = this.resolver.CallingType;
					targetResult.CallingType   = resolver.CallingType;
					targetResult.CallingMember = resolver.CallingMember;
				}
			}
			
			MethodResolveResult methodResult = targetResult as MethodResolveResult;
			if (methodResult != null) {
				methodResult.GetsInvoked = true;
//				Console.WriteLine ("--------------------");
//				Console.WriteLine ("i:" + methodResult.ResolvedType);
/*				foreach (var arg in methodResult.GenericArguments) {
					methodResult.AddGenericArgument (arg);
				}*/
				foreach (Expression arg in invocationExpression.Arguments) {
					var type = GetTypeSafe (arg);
					methodResult.AddArgument (type);
				}
				//Console.WriteLine ("--------------------");
				methodResult.StaticUsage = targetIsStatic;
				methodResult.ResolveExtensionMethods ();
//				Console.WriteLine ("i2:" + methodResult.ResolvedType);
			/*	MemberReferenceExpression mre = invocationExpression.TargetObject as MemberReferenceExpression;
				if (mre != null) {
					foreach (TypeReference typeReference in mre.TypeArguments) {
						methodResult.AddGenericArgument (new DomReturnType (String.IsNullOrEmpty (typeReference.SystemType) ? typeReference.Type : typeReference.SystemType));
					}
				}*/
//				return CreateResult (methodResult.Methods [0].ReturnType);
			}
			invocationDictionary[invocationExpression] = targetResult;
			return targetResult;
		}
		public virtual object VisitInvocationExpression(InvocationExpression invocationExpression, object data) {
			Debug.Assert((invocationExpression != null));
			Debug.Assert((invocationExpression.TargetObject != null));
			Debug.Assert((invocationExpression.Arguments != null));
			nodeStack.Push(invocationExpression.TargetObject);
			invocationExpression.TargetObject.AcceptVisitor(this, data);
			invocationExpression.TargetObject = ((Expression)(nodeStack.Pop()));
			for (int i = 0; i < invocationExpression.Arguments.Count; i++) {
				Expression o = invocationExpression.Arguments[i];
				Debug.Assert(o != null);
				nodeStack.Push(o);
				o.AcceptVisitor(this, data);
				o = (Expression)nodeStack.Pop();
				if (o == null)
					invocationExpression.Arguments.RemoveAt(i--);
				else
					invocationExpression.Arguments[i] = o;
			}
			return null;
		}
		void ConvertInterfaceImplementation(MethodDeclaration member)
		{
			// members without modifiers are already C# explicit interface implementations, do not convert them
			if (member.Modifier == Modifiers.None)
				return;
			while (member.InterfaceImplementations.Count > 0) {
				InterfaceImplementation impl = member.InterfaceImplementations[0];
				member.InterfaceImplementations.RemoveAt(0);
				if (member.Name != impl.MemberName) {
					MethodDeclaration newMember = new MethodDeclaration {
						Name = impl.MemberName,
						TypeReference = member.TypeReference,
						Parameters = member.Parameters,
						Body = new BlockStatement()
					};
					InvocationExpression callExpression = new InvocationExpression(new IdentifierExpression(member.Name));
					foreach (ParameterDeclarationExpression decl in member.Parameters) {
						callExpression.Arguments.Add(new IdentifierExpression(decl.ParameterName));
					}
					if (member.TypeReference.Type == "System.Void") {
						newMember.Body.AddChild(new ExpressionStatement(callExpression));
					} else {
						newMember.Body.AddChild(new ReturnStatement(callExpression));
					}
					newMember.InterfaceImplementations.Add(impl);
					InsertAfterSibling(member, newMember);
				}
			}
		}
Example #15
0
	void EmbeddedStatement(
#line  2755 "VBNET.ATG" 
out Statement statement) {

#line  2757 "VBNET.ATG" 
		Statement embeddedStatement = null;
		statement = null;
		Expression expr = null;
		string name = String.Empty;
		List<Expression> p = null;
		
		if (la.kind == 107) {
			lexer.NextToken();

#line  2763 "VBNET.ATG" 
			ExitType exitType = ExitType.None; 
			switch (la.kind) {
			case 195: {
				lexer.NextToken();

#line  2765 "VBNET.ATG" 
				exitType = ExitType.Sub; 
				break;
			}
			case 114: {
				lexer.NextToken();

#line  2767 "VBNET.ATG" 
				exitType = ExitType.Function; 
				break;
			}
			case 171: {
				lexer.NextToken();

#line  2769 "VBNET.ATG" 
				exitType = ExitType.Property; 
				break;
			}
			case 95: {
				lexer.NextToken();

#line  2771 "VBNET.ATG" 
				exitType = ExitType.Do; 
				break;
			}
			case 111: {
				lexer.NextToken();

#line  2773 "VBNET.ATG" 
				exitType = ExitType.For; 
				break;
			}
			case 203: {
				lexer.NextToken();

#line  2775 "VBNET.ATG" 
				exitType = ExitType.Try; 
				break;
			}
			case 216: {
				lexer.NextToken();

#line  2777 "VBNET.ATG" 
				exitType = ExitType.While; 
				break;
			}
			case 182: {
				lexer.NextToken();

#line  2779 "VBNET.ATG" 
				exitType = ExitType.Select; 
				break;
			}
			default: SynErr(273); break;
			}

#line  2781 "VBNET.ATG" 
			statement = new ExitStatement(exitType); 
		} else if (la.kind == 203) {
			TryStatement(
#line  2782 "VBNET.ATG" 
out statement);
		} else if (la.kind == 76) {
			lexer.NextToken();

#line  2783 "VBNET.ATG" 
			ContinueType continueType = ContinueType.None; 
			if (la.kind == 95 || la.kind == 111 || la.kind == 216) {
				if (la.kind == 95) {
					lexer.NextToken();

#line  2783 "VBNET.ATG" 
					continueType = ContinueType.Do; 
				} else if (la.kind == 111) {
					lexer.NextToken();

#line  2783 "VBNET.ATG" 
					continueType = ContinueType.For; 
				} else {
					lexer.NextToken();

#line  2783 "VBNET.ATG" 
					continueType = ContinueType.While; 
				}
			}

#line  2783 "VBNET.ATG" 
			statement = new ContinueStatement(continueType); 
		} else if (la.kind == 200) {
			lexer.NextToken();
			if (StartOf(29)) {
				Expr(
#line  2785 "VBNET.ATG" 
out expr);
			}

#line  2785 "VBNET.ATG" 
			statement = new ThrowStatement(expr); 
		} else if (la.kind == 180) {
			lexer.NextToken();
			if (StartOf(29)) {
				Expr(
#line  2787 "VBNET.ATG" 
out expr);
			}

#line  2787 "VBNET.ATG" 
			statement = new ReturnStatement(expr); 
		} else if (la.kind == 196) {
			lexer.NextToken();
			Expr(
#line  2789 "VBNET.ATG" 
out expr);
			EndOfStmt();
			Block(
#line  2789 "VBNET.ATG" 
out embeddedStatement);
			Expect(100);
			Expect(196);

#line  2790 "VBNET.ATG" 
			statement = new LockStatement(expr, embeddedStatement); 
		} else if (la.kind == 174) {
			lexer.NextToken();
			Identifier();

#line  2792 "VBNET.ATG" 
			name = t.val; 
			if (la.kind == 25) {
				lexer.NextToken();
				if (StartOf(37)) {
					ArgumentList(
#line  2793 "VBNET.ATG" 
out p);
				}
				Expect(26);
			}

#line  2795 "VBNET.ATG" 
			statement = new RaiseEventStatement(name, p);
			
		} else if (la.kind == 218) {
			WithStatement(
#line  2798 "VBNET.ATG" 
out statement);
		} else if (la.kind == 43) {
			lexer.NextToken();

#line  2800 "VBNET.ATG" 
			Expression handlerExpr = null; 
			Expr(
#line  2801 "VBNET.ATG" 
out expr);
			Expect(12);
			Expr(
#line  2801 "VBNET.ATG" 
out handlerExpr);

#line  2803 "VBNET.ATG" 
			statement = new AddHandlerStatement(expr, handlerExpr);
			
		} else if (la.kind == 178) {
			lexer.NextToken();

#line  2806 "VBNET.ATG" 
			Expression handlerExpr = null; 
			Expr(
#line  2807 "VBNET.ATG" 
out expr);
			Expect(12);
			Expr(
#line  2807 "VBNET.ATG" 
out handlerExpr);

#line  2809 "VBNET.ATG" 
			statement = new RemoveHandlerStatement(expr, handlerExpr);
			
		} else if (la.kind == 216) {
			lexer.NextToken();
			Expr(
#line  2812 "VBNET.ATG" 
out expr);
			EndOfStmt();
			Block(
#line  2813 "VBNET.ATG" 
out embeddedStatement);
			Expect(100);
			Expect(216);

#line  2815 "VBNET.ATG" 
			statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start);
			
		} else if (la.kind == 95) {
			lexer.NextToken();

#line  2820 "VBNET.ATG" 
			ConditionType conditionType = ConditionType.None;
			
			if (la.kind == 209 || la.kind == 216) {
				WhileOrUntil(
#line  2823 "VBNET.ATG" 
out conditionType);
				Expr(
#line  2823 "VBNET.ATG" 
out expr);
				EndOfStmt();
				Block(
#line  2824 "VBNET.ATG" 
out embeddedStatement);
				Expect(138);

#line  2827 "VBNET.ATG" 
				statement = new DoLoopStatement(expr, 
				                               embeddedStatement, 
				                               conditionType == ConditionType.While ? ConditionType.DoWhile : conditionType, 
				                               ConditionPosition.Start);
				
			} else if (la.kind == 1 || la.kind == 11) {
				EndOfStmt();
				Block(
#line  2834 "VBNET.ATG" 
out embeddedStatement);
				Expect(138);
				if (la.kind == 209 || la.kind == 216) {
					WhileOrUntil(
#line  2835 "VBNET.ATG" 
out conditionType);
					Expr(
#line  2835 "VBNET.ATG" 
out expr);
				}

#line  2837 "VBNET.ATG" 
				statement = new DoLoopStatement(expr, embeddedStatement, conditionType, ConditionPosition.End);
				
			} else SynErr(274);
		} else if (la.kind == 111) {
			lexer.NextToken();

#line  2842 "VBNET.ATG" 
			Expression group = null;
			TypeReference typeReference;
			string        typeName;
			Location startLocation = t.Location;
			
			if (la.kind == 97) {
				lexer.NextToken();
				LoopControlVariable(
#line  2849 "VBNET.ATG" 
out typeReference, out typeName);
				Expect(125);
				Expr(
#line  2850 "VBNET.ATG" 
out group);
				EndOfStmt();
				Block(
#line  2851 "VBNET.ATG" 
out embeddedStatement);
				Expect(149);
				if (StartOf(29)) {
					Expr(
#line  2852 "VBNET.ATG" 
out expr);
				}

#line  2854 "VBNET.ATG" 
				statement = new ForeachStatement(typeReference, 
				                                typeName,
				                                group, 
				                                embeddedStatement, 
				                                expr);
				statement.StartLocation = startLocation;
				statement.EndLocation   = t.EndLocation;
				
				
			} else if (StartOf(38)) {

#line  2865 "VBNET.ATG" 
				Expression start = null;
				Expression end = null;
				Expression step = null;
				Expression variableExpr = null;
				Expression nextExpr = null;
				List<Expression> nextExpressions = null;
				
				if (
#line  2872 "VBNET.ATG" 
IsLoopVariableDeclaration()) {
					LoopControlVariable(
#line  2873 "VBNET.ATG" 
out typeReference, out typeName);
				} else {

#line  2875 "VBNET.ATG" 
					typeReference = null; typeName = null; 
					SimpleExpr(
#line  2876 "VBNET.ATG" 
out variableExpr);
				}
				Expect(10);
				Expr(
#line  2878 "VBNET.ATG" 
out start);
				Expect(201);
				Expr(
#line  2878 "VBNET.ATG" 
out end);
				if (la.kind == 190) {
					lexer.NextToken();
					Expr(
#line  2878 "VBNET.ATG" 
out step);
				}
				EndOfStmt();
				Block(
#line  2879 "VBNET.ATG" 
out embeddedStatement);
				Expect(149);
				if (StartOf(29)) {
					Expr(
#line  2882 "VBNET.ATG" 
out nextExpr);

#line  2884 "VBNET.ATG" 
					nextExpressions = new List<Expression>();
					nextExpressions.Add(nextExpr);
					
					while (la.kind == 12) {
						lexer.NextToken();
						Expr(
#line  2887 "VBNET.ATG" 
out nextExpr);

#line  2887 "VBNET.ATG" 
						nextExpressions.Add(nextExpr); 
					}
				}

#line  2890 "VBNET.ATG" 
				statement = new ForNextStatement {
				TypeReference = typeReference,
				VariableName = typeName, 
				LoopVariableExpression = variableExpr,
				Start = start, 
				End = end, 
				Step = step, 
				EmbeddedStatement = embeddedStatement, 
				NextExpressions = nextExpressions
				};
				
			} else SynErr(275);
		} else if (la.kind == 105) {
			lexer.NextToken();
			Expr(
#line  2903 "VBNET.ATG" 
out expr);

#line  2903 "VBNET.ATG" 
			statement = new ErrorStatement(expr); 
		} else if (la.kind == 176) {
			lexer.NextToken();

#line  2905 "VBNET.ATG" 
			bool isPreserve = false; 
			if (la.kind == 169) {
				lexer.NextToken();

#line  2905 "VBNET.ATG" 
				isPreserve = true; 
			}
			ReDimClause(
#line  2906 "VBNET.ATG" 
out expr);

#line  2908 "VBNET.ATG" 
			ReDimStatement reDimStatement = new ReDimStatement(isPreserve);
			statement = reDimStatement;
			SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression);
			
			while (la.kind == 12) {
				lexer.NextToken();
				ReDimClause(
#line  2912 "VBNET.ATG" 
out expr);

#line  2913 "VBNET.ATG" 
				SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression); 
			}
		} else if (la.kind == 104) {
			lexer.NextToken();
			Expr(
#line  2917 "VBNET.ATG" 
out expr);

#line  2919 "VBNET.ATG" 
			EraseStatement eraseStatement = new EraseStatement();
			if (expr != null) { SafeAdd(eraseStatement, eraseStatement.Expressions, expr);}
			
			while (la.kind == 12) {
				lexer.NextToken();
				Expr(
#line  2922 "VBNET.ATG" 
out expr);

#line  2922 "VBNET.ATG" 
				if (expr != null) { SafeAdd(eraseStatement, eraseStatement.Expressions, expr); }
			}

#line  2923 "VBNET.ATG" 
			statement = eraseStatement; 
		} else if (la.kind == 191) {
			lexer.NextToken();

#line  2925 "VBNET.ATG" 
			statement = new StopStatement(); 
		} else if (
#line  2927 "VBNET.ATG" 
la.kind == Tokens.If) {
			Expect(122);

#line  2928 "VBNET.ATG" 
			Location ifStartLocation = t.Location; 
			Expr(
#line  2928 "VBNET.ATG" 
out expr);
			if (la.kind == 199) {
				lexer.NextToken();
			}
			if (la.kind == 1 || la.kind == 11) {
				EndOfStmt();
				Block(
#line  2931 "VBNET.ATG" 
out embeddedStatement);

#line  2933 "VBNET.ATG" 
				IfElseStatement ifStatement = new IfElseStatement(expr, embeddedStatement);
				ifStatement.StartLocation = ifStartLocation;
				Location elseIfStart;
				
				while (la.kind == 99 || 
#line  2939 "VBNET.ATG" 
IsElseIf()) {
					if (
#line  2939 "VBNET.ATG" 
IsElseIf()) {
						Expect(98);

#line  2939 "VBNET.ATG" 
						elseIfStart = t.Location; 
						Expect(122);
					} else {
						lexer.NextToken();

#line  2940 "VBNET.ATG" 
						elseIfStart = t.Location; 
					}

#line  2942 "VBNET.ATG" 
					Expression condition = null; Statement block = null; 
					Expr(
#line  2943 "VBNET.ATG" 
out condition);
					if (la.kind == 199) {
						lexer.NextToken();
					}
					EndOfStmt();
					Block(
#line  2944 "VBNET.ATG" 
out block);

#line  2946 "VBNET.ATG" 
					ElseIfSection elseIfSection = new ElseIfSection(condition, block);
					elseIfSection.StartLocation = elseIfStart;
					elseIfSection.EndLocation = t.Location;
					elseIfSection.Parent = ifStatement;
					ifStatement.ElseIfSections.Add(elseIfSection);
					
				}
				if (la.kind == 98) {
					lexer.NextToken();
					EndOfStmt();
					Block(
#line  2955 "VBNET.ATG" 
out embeddedStatement);

#line  2957 "VBNET.ATG" 
					ifStatement.FalseStatement.Add(embeddedStatement);
					
				}
				Expect(100);
				Expect(122);

#line  2961 "VBNET.ATG" 
				ifStatement.EndLocation = t.Location;
				statement = ifStatement;
				
			} else if (StartOf(39)) {

#line  2966 "VBNET.ATG" 
				IfElseStatement ifStatement = new IfElseStatement(expr);
				ifStatement.StartLocation = ifStartLocation;
				
				SingleLineStatementList(
#line  2969 "VBNET.ATG" 
ifStatement.TrueStatement);
				if (la.kind == 98) {
					lexer.NextToken();
					if (StartOf(39)) {
						SingleLineStatementList(
#line  2972 "VBNET.ATG" 
ifStatement.FalseStatement);
					}
				}

#line  2974 "VBNET.ATG" 
				ifStatement.EndLocation = t.Location; statement = ifStatement; 
			} else SynErr(276);
		} else if (la.kind == 182) {
			lexer.NextToken();
			if (la.kind == 61) {
				lexer.NextToken();
			}
			Expr(
#line  2977 "VBNET.ATG" 
out expr);
			EndOfStmt();

#line  2978 "VBNET.ATG" 
			List<SwitchSection> selectSections = new List<SwitchSection>();
			Statement block = null;
			
			while (la.kind == 61) {

#line  2982 "VBNET.ATG" 
				List<CaseLabel> caseClauses = null; Location caseLocation = la.Location; 
				lexer.NextToken();
				CaseClauses(
#line  2983 "VBNET.ATG" 
out caseClauses);
				if (
#line  2983 "VBNET.ATG" 
IsNotStatementSeparator()) {
					lexer.NextToken();
				}
				EndOfStmt();

#line  2985 "VBNET.ATG" 
				SwitchSection selectSection = new SwitchSection(caseClauses);
				selectSection.StartLocation = caseLocation;
				
				Block(
#line  2988 "VBNET.ATG" 
out block);

#line  2990 "VBNET.ATG" 
				selectSection.Children = block.Children;
				selectSection.EndLocation = t.EndLocation;
				selectSections.Add(selectSection);
				
			}

#line  2996 "VBNET.ATG" 
			statement = new SwitchStatement(expr, selectSections);
			
			Expect(100);
			Expect(182);
		} else if (la.kind == 157) {

#line  2999 "VBNET.ATG" 
			OnErrorStatement onErrorStatement = null; 
			OnErrorStatement(
#line  3000 "VBNET.ATG" 
out onErrorStatement);

#line  3000 "VBNET.ATG" 
			statement = onErrorStatement; 
		} else if (la.kind == 119) {

#line  3001 "VBNET.ATG" 
			GotoStatement goToStatement = null; 
			GotoStatement(
#line  3002 "VBNET.ATG" 
out goToStatement);

#line  3002 "VBNET.ATG" 
			statement = goToStatement; 
		} else if (la.kind == 179) {

#line  3003 "VBNET.ATG" 
			ResumeStatement resumeStatement = null; 
			ResumeStatement(
#line  3004 "VBNET.ATG" 
out resumeStatement);

#line  3004 "VBNET.ATG" 
			statement = resumeStatement; 
		} else if (StartOf(38)) {

#line  3007 "VBNET.ATG" 
			Expression val = null;
			AssignmentOperatorType op;
			
			bool mustBeAssignment = la.kind == Tokens.Plus  || la.kind == Tokens.Minus ||
			                        la.kind == Tokens.Not   || la.kind == Tokens.Times;
			
			SimpleExpr(
#line  3013 "VBNET.ATG" 
out expr);
			if (StartOf(40)) {
				AssignmentOperator(
#line  3015 "VBNET.ATG" 
out op);
				Expr(
#line  3015 "VBNET.ATG" 
out val);

#line  3015 "VBNET.ATG" 
				expr = new AssignmentExpression(expr, op, val); 
			} else if (la.kind == 1 || la.kind == 11 || la.kind == 98) {

#line  3016 "VBNET.ATG" 
				if (mustBeAssignment) Error("error in assignment."); 
			} else SynErr(277);

#line  3019 "VBNET.ATG" 
			// a field reference expression that stands alone is a
			// invocation expression without parantheses and arguments
			if(expr is MemberReferenceExpression || expr is IdentifierExpression) {
				expr = new InvocationExpression(expr);
			}
			statement = new ExpressionStatement(expr);
			
		} else if (la.kind == 60) {
			lexer.NextToken();
			SimpleExpr(
#line  3026 "VBNET.ATG" 
out expr);

#line  3026 "VBNET.ATG" 
			statement = new ExpressionStatement(expr); 
		} else if (la.kind == 211) {
			lexer.NextToken();

#line  3028 "VBNET.ATG" 
			Statement block;  
			if (
#line  3029 "VBNET.ATG" 
Peek(1).kind == Tokens.As) {

#line  3030 "VBNET.ATG" 
				LocalVariableDeclaration resourceAquisition = new LocalVariableDeclaration(Modifiers.None); 
				VariableDeclarator(
#line  3031 "VBNET.ATG" 
resourceAquisition.Variables);
				while (la.kind == 12) {
					lexer.NextToken();
					VariableDeclarator(
#line  3033 "VBNET.ATG" 
resourceAquisition.Variables);
				}
				Block(
#line  3035 "VBNET.ATG" 
out block);

#line  3037 "VBNET.ATG" 
				statement = new UsingStatement(resourceAquisition, block);
				
			} else if (StartOf(29)) {
				Expr(
#line  3039 "VBNET.ATG" 
out expr);
				Block(
#line  3040 "VBNET.ATG" 
out block);

#line  3041 "VBNET.ATG" 
				statement = new UsingStatement(new ExpressionStatement(expr), block); 
			} else SynErr(278);
			Expect(100);
			Expect(211);
		} else if (StartOf(41)) {
			LocalDeclarationStatement(
#line  3044 "VBNET.ATG" 
out statement);
		} else SynErr(279);
	}
		public virtual object VisitInvocationExpression(InvocationExpression invocationExpression, object data) {
			Debug.Assert((invocationExpression != null));
			Debug.Assert((invocationExpression.TargetObject != null));
			Debug.Assert((invocationExpression.Arguments != null));
			invocationExpression.TargetObject.AcceptVisitor(this, data);
			foreach (Expression o in invocationExpression.Arguments) {
				Debug.Assert(o != null);
				o.AcceptVisitor(this, data);
			}
			return null;
		}
		public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
		{
			Expression     target     = invocationExpression.TargetObject;
			CodeExpression targetExpr;
			string         methodName = null;
			if (target == null) {
				targetExpr = new CodeThisReferenceExpression();
			} else if (target is MemberReferenceExpression) {
				MemberReferenceExpression fRef = (MemberReferenceExpression)target;
				targetExpr = null;
				if (fRef.TargetObject is MemberReferenceExpression) {
					if (IsPossibleTypeReference((MemberReferenceExpression)fRef.TargetObject)) {
						targetExpr = ConvertToTypeReference((MemberReferenceExpression)fRef.TargetObject);
					}
				}
				if (targetExpr == null)
					targetExpr = (CodeExpression)fRef.TargetObject.AcceptVisitor(this, data);
				
				methodName = fRef.MemberName;
				// HACK for : Microsoft.VisualBasic.ChrW(NUMBER)
				if (methodName == "ChrW") {
					return new CodeCastExpression("System.Char", GetExpressionList(invocationExpression.Arguments)[0]);
				}
			} else if (target is IdentifierExpression) {
				targetExpr = new CodeThisReferenceExpression();
				methodName = ((IdentifierExpression)target).Identifier;
			} else {
				targetExpr = (CodeExpression)target.AcceptVisitor(this, data);
			}
			return new CodeMethodInvokeExpression(targetExpr, methodName, GetExpressionList(invocationExpression.Arguments));
		}