1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
3
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4
// software and associated documentation files (the "Software"), to deal in the Software
5
// without restriction, including without limitation the rights to use, copy, modify, merge,
6
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7
// to whom the Software is furnished to do so, subject to the following conditions:
9
// The above copyright notice and this permission notice shall be included in all copies or
10
// substantial portions of the Software.
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17
// DEALINGS IN THE SOFTWARE.
20
using System.Collections.Generic;
22
using ICSharpCode.NRefactory.Semantics;
23
using ICSharpCode.NRefactory.TypeSystem;
25
namespace ICSharpCode.NRefactory.CSharp.Resolver
28
/// Represents the result of a method invocation.
30
public class CSharpInvocationResolveResult : InvocationResolveResult
32
public readonly OverloadResolutionErrors OverloadResolutionErrors;
35
/// Gets whether this invocation is calling an extension method using extension method syntax.
37
public readonly bool IsExtensionMethodInvocation;
40
/// Gets whether this invocation is calling a delegate (without explicitly calling ".Invoke()").
42
public readonly bool IsDelegateInvocation;
45
/// Gets whether a params-Array is being used in its expanded form.
47
public readonly bool IsExpandedForm;
49
readonly IList<int> argumentToParameterMap;
51
public CSharpInvocationResolveResult(
52
ResolveResult targetResult, IParameterizedMember member,
53
IList<ResolveResult> arguments,
54
OverloadResolutionErrors overloadResolutionErrors = OverloadResolutionErrors.None,
55
bool isExtensionMethodInvocation = false,
56
bool isExpandedForm = false,
57
bool isDelegateInvocation = false,
58
IList<int> argumentToParameterMap = null,
59
IList<ResolveResult> initializerStatements = null
61
: base(targetResult, member, arguments, initializerStatements)
63
this.OverloadResolutionErrors = overloadResolutionErrors;
64
this.IsExtensionMethodInvocation = isExtensionMethodInvocation;
65
this.IsExpandedForm = isExpandedForm;
66
this.IsDelegateInvocation = isDelegateInvocation;
67
this.argumentToParameterMap = argumentToParameterMap;
70
public override bool IsError {
71
get { return this.OverloadResolutionErrors != OverloadResolutionErrors.None; }
75
/// Gets an array that maps argument indices to parameter indices.
76
/// For arguments that could not be mapped to any parameter, the value will be -1.
78
/// parameterIndex = ArgumentToParameterMap[argumentIndex]
80
public IList<int> GetArgumentToParameterMap()
82
return argumentToParameterMap;
85
public override IList<ResolveResult> GetArgumentsForCall()
87
ResolveResult[] results = new ResolveResult[Member.Parameters.Count];
88
List<ResolveResult> paramsArguments = IsExpandedForm ? new List<ResolveResult>() : null;
89
// map arguments to parameters:
90
for (int i = 0; i < Arguments.Count; i++) {
92
if (argumentToParameterMap != null)
93
mappedTo = argumentToParameterMap[i];
95
mappedTo = IsExpandedForm ? Math.Min(i, results.Length - 1) : i;
97
if (mappedTo >= 0 && mappedTo < results.Length) {
98
if (IsExpandedForm && mappedTo == results.Length - 1)
99
paramsArguments.Add(Arguments[i]);
101
results[mappedTo] = Arguments[i];
105
results[results.Length - 1] = new ArrayCreateResolveResult(Member.Parameters.Last().Type, null, paramsArguments.ToArray());
107
for (int i = 0; i < results.Length; i++) {
108
if (results[i] == null) {
109
if (Member.Parameters[i].IsOptional) {
110
results[i] = new ConstantResolveResult(Member.Parameters[i].Type, Member.Parameters[i].ConstantValue);
112
results[i] = ErrorResolveResult.UnknownError;