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

« back to all changes in this revision

Viewing changes to contrib/ICSharpCode.NRefactory/TypeSystem/ByReferenceType.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 ICSharpCode.NRefactory.TypeSystem.Implementation;
21
 
 
22
 
namespace ICSharpCode.NRefactory.TypeSystem
23
 
{
24
 
        public sealed class ByReferenceType : TypeWithElementType
25
 
        {
26
 
                public ByReferenceType(IType elementType) : base(elementType)
27
 
                {
28
 
                }
29
 
                
30
 
                public override TypeKind Kind {
31
 
                        get { return TypeKind.ByReference; }
32
 
                }
33
 
                
34
 
                public override string NameSuffix {
35
 
                        get {
36
 
                                return "&";
37
 
                        }
38
 
                }
39
 
                
40
 
                public override bool? IsReferenceType {
41
 
                        get { return null; }
42
 
                }
43
 
                
44
 
                public override int GetHashCode()
45
 
                {
46
 
                        return elementType.GetHashCode() ^ 91725813;
47
 
                }
48
 
                
49
 
                public override bool Equals(IType other)
50
 
                {
51
 
                        ByReferenceType a = other as ByReferenceType;
52
 
                        return a != null && elementType.Equals(a.elementType);
53
 
                }
54
 
                
55
 
                public override IType AcceptVisitor(TypeVisitor visitor)
56
 
                {
57
 
                        return visitor.VisitByReferenceType(this);
58
 
                }
59
 
                
60
 
                public override IType VisitChildren(TypeVisitor visitor)
61
 
                {
62
 
                        IType e = elementType.AcceptVisitor(visitor);
63
 
                        if (e == elementType)
64
 
                                return this;
65
 
                        else
66
 
                                return new ByReferenceType(e);
67
 
                }
68
 
                
69
 
                public override ITypeReference ToTypeReference()
70
 
                {
71
 
                        return new ByReferenceTypeReference(elementType.ToTypeReference());
72
 
                }
73
 
        }
74
 
        
75
 
        [Serializable]
76
 
        public sealed class ByReferenceTypeReference : ITypeReference, ISupportsInterning
77
 
        {
78
 
                ITypeReference elementType;
79
 
                
80
 
                public ByReferenceTypeReference(ITypeReference elementType)
81
 
                {
82
 
                        if (elementType == null)
83
 
                                throw new ArgumentNullException("elementType");
84
 
                        this.elementType = elementType;
85
 
                }
86
 
                
87
 
                public ITypeReference ElementType {
88
 
                        get { return elementType; }
89
 
                }
90
 
                
91
 
                public IType Resolve(ITypeResolveContext context)
92
 
                {
93
 
                        return new ByReferenceType(elementType.Resolve(context));
94
 
                }
95
 
                
96
 
                public override string ToString()
97
 
                {
98
 
                        return elementType.ToString() + "&";
99
 
                }
100
 
                
101
 
                void ISupportsInterning.PrepareForInterning(IInterningProvider provider)
102
 
                {
103
 
                        elementType = provider.Intern(elementType);
104
 
                }
105
 
                
106
 
                int ISupportsInterning.GetHashCodeForInterning()
107
 
                {
108
 
                        return elementType.GetHashCode() ^ 91725814;
109
 
                }
110
 
                
111
 
                bool ISupportsInterning.EqualsForInterning(ISupportsInterning other)
112
 
                {
113
 
                        ByReferenceTypeReference brt = other as ByReferenceTypeReference;
114
 
                        return brt != null && this.elementType == brt.elementType;
115
 
                }
116
 
        }
117
 
}