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

« back to all changes in this revision

Viewing changes to contrib/ICSharpCode.NRefactory/Semantics/MemberResolveResult.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.Globalization;
22
 
using System.Linq;
23
 
 
24
 
using ICSharpCode.NRefactory.TypeSystem;
25
 
 
26
 
namespace ICSharpCode.NRefactory.Semantics
27
 
{
28
 
        /// <summary>
29
 
        /// Represents the result of a member invocation.
30
 
        /// </summary>
31
 
        public class MemberResolveResult : ResolveResult
32
 
        {
33
 
                readonly IMember member;
34
 
                readonly bool isConstant;
35
 
                readonly object constantValue;
36
 
                readonly ResolveResult targetResult;
37
 
                readonly bool isVirtualCall;
38
 
                
39
 
                public MemberResolveResult(ResolveResult targetResult, IMember member)
40
 
                        : base(member.EntityType == EntityType.Constructor ? member.DeclaringType : member.ReturnType)
41
 
                {
42
 
                        this.targetResult = targetResult;
43
 
                        this.member = member;
44
 
                        var thisRR = targetResult as ThisResolveResult;
45
 
                        this.isVirtualCall = member.IsOverridable && !(thisRR != null && thisRR.CausesNonVirtualInvocation);
46
 
                        
47
 
                        IField field = member as IField;
48
 
                        if (field != null) {
49
 
                                isConstant = field.IsConst;
50
 
                                if (isConstant)
51
 
                                        constantValue = field.ConstantValue;
52
 
                        }
53
 
                }
54
 
                
55
 
                public MemberResolveResult(ResolveResult targetResult, IMember member, bool isVirtualCall)
56
 
                        : base(member.EntityType == EntityType.Constructor ? member.DeclaringType : member.ReturnType)
57
 
                {
58
 
                        this.targetResult = targetResult;
59
 
                        this.member = member;
60
 
                        this.isVirtualCall = isVirtualCall;
61
 
                        IField field = member as IField;
62
 
                        if (field != null) {
63
 
                                isConstant = field.IsConst;
64
 
                                if (isConstant)
65
 
                                        constantValue = field.ConstantValue;
66
 
                        }
67
 
                }
68
 
                
69
 
                public MemberResolveResult(ResolveResult targetResult, IMember member, IType returnType, bool isConstant, object constantValue)
70
 
                        : base(returnType)
71
 
                {
72
 
                        this.targetResult = targetResult;
73
 
                        this.member = member;
74
 
                        this.isConstant = isConstant;
75
 
                        this.constantValue = constantValue;
76
 
                }
77
 
                
78
 
                public ResolveResult TargetResult {
79
 
                        get { return targetResult; }
80
 
                }
81
 
                
82
 
                /// <summary>
83
 
                /// Gets the member.
84
 
                /// This property never returns null.
85
 
                /// </summary>
86
 
                public IMember Member {
87
 
                        get { return member; }
88
 
                }
89
 
                
90
 
                /// <summary>
91
 
                /// Gets whether this MemberResolveResult is a virtual call.
92
 
                /// </summary>
93
 
                public bool IsVirtualCall {
94
 
                        get { return isVirtualCall; }
95
 
                }
96
 
                
97
 
                public override bool IsCompileTimeConstant {
98
 
                        get { return isConstant; }
99
 
                }
100
 
                
101
 
                public override object ConstantValue {
102
 
                        get { return constantValue; }
103
 
                }
104
 
                
105
 
                public override IEnumerable<ResolveResult> GetChildResults()
106
 
                {
107
 
                        if (targetResult != null)
108
 
                                return new[] { targetResult };
109
 
                        else
110
 
                                return Enumerable.Empty<ResolveResult>();
111
 
                }
112
 
                
113
 
                public override string ToString()
114
 
                {
115
 
                        return string.Format(CultureInfo.InvariantCulture, "[{0} {1}]", GetType().Name, member);
116
 
                }
117
 
                
118
 
                public override DomRegion GetDefinitionRegion()
119
 
                {
120
 
                        return member.Region;
121
 
                }
122
 
        }
123
 
}