~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to contrib/ICSharpCode.NRefactory.CSharp/Resolver/CSharpInvocationResolveResult.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
2
 
// 
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:
8
 
// 
9
 
// The above copyright notice and this permission notice shall be included in all copies or
10
 
// substantial portions of the Software.
11
 
// 
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.
18
 
 
19
 
using System;
20
 
using System.Collections.Generic;
21
 
using System.Linq;
22
 
using ICSharpCode.NRefactory.Semantics;
23
 
using ICSharpCode.NRefactory.TypeSystem;
24
 
 
25
 
namespace ICSharpCode.NRefactory.CSharp.Resolver
26
 
{
27
 
        /// <summary>
28
 
        /// Represents the result of a method invocation.
29
 
        /// </summary>
30
 
        public class CSharpInvocationResolveResult : InvocationResolveResult
31
 
        {
32
 
                public readonly OverloadResolutionErrors OverloadResolutionErrors;
33
 
                
34
 
                /// <summary>
35
 
                /// Gets whether this invocation is calling an extension method using extension method syntax.
36
 
                /// </summary>
37
 
                public readonly bool IsExtensionMethodInvocation;
38
 
                
39
 
                /// <summary>
40
 
                /// Gets whether this invocation is calling a delegate (without explicitly calling ".Invoke()").
41
 
                /// </summary>
42
 
                public readonly bool IsDelegateInvocation;
43
 
                
44
 
                /// <summary>
45
 
                /// Gets whether a params-Array is being used in its expanded form.
46
 
                /// </summary>
47
 
                public readonly bool IsExpandedForm;
48
 
                
49
 
                readonly IList<int> argumentToParameterMap;
50
 
                
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
60
 
                )
61
 
                        : base(targetResult, member, arguments, initializerStatements)
62
 
                {
63
 
                        this.OverloadResolutionErrors = overloadResolutionErrors;
64
 
                        this.IsExtensionMethodInvocation = isExtensionMethodInvocation;
65
 
                        this.IsExpandedForm = isExpandedForm;
66
 
                        this.IsDelegateInvocation = isDelegateInvocation;
67
 
                        this.argumentToParameterMap = argumentToParameterMap;
68
 
                }
69
 
                
70
 
                public override bool IsError {
71
 
                        get { return this.OverloadResolutionErrors != OverloadResolutionErrors.None; }
72
 
                }
73
 
                
74
 
                /// <summary>
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.
77
 
                /// 
78
 
                /// parameterIndex = ArgumentToParameterMap[argumentIndex]
79
 
                /// </summary>
80
 
                public IList<int> GetArgumentToParameterMap()
81
 
                {
82
 
                        return argumentToParameterMap;
83
 
                }
84
 
                
85
 
                public override IList<ResolveResult> GetArgumentsForCall()
86
 
                {
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++) {
91
 
                                int mappedTo;
92
 
                                if (argumentToParameterMap != null)
93
 
                                        mappedTo = argumentToParameterMap[i];
94
 
                                else
95
 
                                        mappedTo = IsExpandedForm ? Math.Min(i, results.Length - 1) : i;
96
 
                                
97
 
                                if (mappedTo >= 0 && mappedTo < results.Length) {
98
 
                                        if (IsExpandedForm && mappedTo == results.Length - 1)
99
 
                                                paramsArguments.Add(Arguments[i]);
100
 
                                        else
101
 
                                                results[mappedTo] = Arguments[i];
102
 
                                }
103
 
                        }
104
 
                        if (IsExpandedForm)
105
 
                                results[results.Length - 1] = new ArrayCreateResolveResult(Member.Parameters.Last().Type, null, paramsArguments.ToArray());
106
 
                        
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);
111
 
                                        } else {
112
 
                                                results[i] = ErrorResolveResult.UnknownError;
113
 
                                        }
114
 
                                }
115
 
                        }
116
 
                        
117
 
                        return results;
118
 
                }
119
 
        }
120
 
}