Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory-5.5.0/Semantics/MemberResolveResult.cs @ 16713

Last change on this file since 16713 was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 4.6 KB
Line 
1// Copyright (c) 2010-2013 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
19using System;
20using System.Collections.Generic;
21using System.Globalization;
22using System.Linq;
23
24using ICSharpCode.NRefactory.TypeSystem;
25
26namespace ICSharpCode.NRefactory.Semantics
27{
28  /// <summary>
29  /// Represents the result of a member invocation.
30  /// Used for field/property/event access.
31  /// Also, <see cref="InvocationResolveResult"/> derives from MemberResolveResult.
32  /// </summary>
33  public class MemberResolveResult : ResolveResult
34  {
35    readonly IMember member;
36    readonly bool isConstant;
37    readonly object constantValue;
38    readonly ResolveResult targetResult;
39    readonly bool isVirtualCall;
40   
41    public MemberResolveResult(ResolveResult targetResult, IMember member, IType returnTypeOverride = null)
42      : base(returnTypeOverride ?? ComputeType(member))
43    {
44      this.targetResult = targetResult;
45      this.member = member;
46      var thisRR = targetResult as ThisResolveResult;
47      this.isVirtualCall = member.IsOverridable && !(thisRR != null && thisRR.CausesNonVirtualInvocation);
48     
49      IField field = member as IField;
50      if (field != null) {
51        isConstant = field.IsConst;
52        if (isConstant)
53          constantValue = field.ConstantValue;
54      }
55    }
56   
57    public MemberResolveResult(ResolveResult targetResult, IMember member, bool isVirtualCall, IType returnTypeOverride = null)
58      : base(returnTypeOverride ?? ComputeType(member))
59    {
60      this.targetResult = targetResult;
61      this.member = member;
62      this.isVirtualCall = isVirtualCall;
63      IField field = member as IField;
64      if (field != null) {
65        isConstant = field.IsConst;
66        if (isConstant)
67          constantValue = field.ConstantValue;
68      }
69    }
70   
71    static IType ComputeType(IMember member)
72    {
73      switch (member.SymbolKind) {
74        case SymbolKind.Constructor:
75          return member.DeclaringType;
76        case SymbolKind.Field:
77          if (((IField)member).IsFixed)
78            return new PointerType(member.ReturnType);
79          break;
80      }
81      return member.ReturnType;
82    }
83   
84    public MemberResolveResult(ResolveResult targetResult, IMember member, IType returnType, bool isConstant, object constantValue)
85      : base(returnType)
86    {
87      this.targetResult = targetResult;
88      this.member = member;
89      this.isConstant = isConstant;
90      this.constantValue = constantValue;
91    }
92   
93    public MemberResolveResult(ResolveResult targetResult, IMember member, IType returnType, bool isConstant, object constantValue, bool isVirtualCall)
94      : base(returnType)
95    {
96      this.targetResult = targetResult;
97      this.member = member;
98      this.isConstant = isConstant;
99      this.constantValue = constantValue;
100      this.isVirtualCall = isVirtualCall;
101    }
102   
103    public ResolveResult TargetResult {
104      get { return targetResult; }
105    }
106   
107    /// <summary>
108    /// Gets the member.
109    /// This property never returns null.
110    /// </summary>
111    public IMember Member {
112      get { return member; }
113    }
114   
115    /// <summary>
116    /// Gets whether this MemberResolveResult is a virtual call.
117    /// </summary>
118    public bool IsVirtualCall {
119      get { return isVirtualCall; }
120    }
121   
122    public override bool IsCompileTimeConstant {
123      get { return isConstant; }
124    }
125   
126    public override object ConstantValue {
127      get { return constantValue; }
128    }
129   
130    public override IEnumerable<ResolveResult> GetChildResults()
131    {
132      if (targetResult != null)
133        return new[] { targetResult };
134      else
135        return Enumerable.Empty<ResolveResult>();
136    }
137   
138    public override string ToString()
139    {
140      return string.Format(CultureInfo.InvariantCulture, "[{0} {1}]", GetType().Name, member);
141    }
142   
143    public override DomRegion GetDefinitionRegion()
144    {
145      return member.Region;
146    }
147  }
148}
Note: See TracBrowser for help on using the repository browser.