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 | |
---|
19 | using System; |
---|
20 | |
---|
21 | namespace ICSharpCode.NRefactory.TypeSystem.Implementation |
---|
22 | { |
---|
23 | /// <summary> |
---|
24 | /// Default implementation of <see cref="IVariable"/>. |
---|
25 | /// </summary> |
---|
26 | public sealed class DefaultVariable : IVariable |
---|
27 | { |
---|
28 | readonly string name; |
---|
29 | readonly DomRegion region; |
---|
30 | readonly IType type; |
---|
31 | readonly object constantValue; |
---|
32 | readonly bool isConst; |
---|
33 | |
---|
34 | public DefaultVariable(IType type, string name) |
---|
35 | { |
---|
36 | if (type == null) |
---|
37 | throw new ArgumentNullException("type"); |
---|
38 | if (name == null) |
---|
39 | throw new ArgumentNullException("name"); |
---|
40 | this.type = type; |
---|
41 | this.name = name; |
---|
42 | } |
---|
43 | |
---|
44 | public DefaultVariable(IType type, string name, DomRegion region = default(DomRegion), |
---|
45 | bool isConst = false, object constantValue = null) |
---|
46 | : this(type, name) |
---|
47 | { |
---|
48 | this.region = region; |
---|
49 | this.isConst = isConst; |
---|
50 | this.constantValue = constantValue; |
---|
51 | } |
---|
52 | |
---|
53 | public string Name { |
---|
54 | get { return name; } |
---|
55 | } |
---|
56 | |
---|
57 | public DomRegion Region { |
---|
58 | get { return region; } |
---|
59 | } |
---|
60 | |
---|
61 | public IType Type { |
---|
62 | get { return type; } |
---|
63 | } |
---|
64 | |
---|
65 | public bool IsConst { |
---|
66 | get { return isConst; } |
---|
67 | } |
---|
68 | |
---|
69 | public object ConstantValue { |
---|
70 | get { return constantValue; } |
---|
71 | } |
---|
72 | |
---|
73 | public SymbolKind SymbolKind { |
---|
74 | get { return SymbolKind.Variable; } |
---|
75 | } |
---|
76 | |
---|
77 | public ISymbolReference ToReference() |
---|
78 | { |
---|
79 | return new VariableReference(type.ToTypeReference(), name, region, isConst, constantValue); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | public sealed class VariableReference : ISymbolReference |
---|
84 | { |
---|
85 | ITypeReference variableTypeReference; |
---|
86 | string name; |
---|
87 | DomRegion region; |
---|
88 | bool isConst; |
---|
89 | object constantValue; |
---|
90 | |
---|
91 | public VariableReference(ITypeReference variableTypeReference, string name, DomRegion region, bool isConst, object constantValue) |
---|
92 | { |
---|
93 | if (variableTypeReference == null) |
---|
94 | throw new ArgumentNullException("variableTypeReference"); |
---|
95 | if (name == null) |
---|
96 | throw new ArgumentNullException("name"); |
---|
97 | this.variableTypeReference = variableTypeReference; |
---|
98 | this.name = name; |
---|
99 | this.region = region; |
---|
100 | this.isConst = isConst; |
---|
101 | this.constantValue = constantValue; |
---|
102 | } |
---|
103 | |
---|
104 | public ISymbol Resolve(ITypeResolveContext context) |
---|
105 | { |
---|
106 | return new DefaultVariable(variableTypeReference.Resolve(context), name, region, isConst, constantValue); |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|