-
Notifications
You must be signed in to change notification settings - Fork 4k
/
TypeInfo.cs
65 lines (55 loc) · 2.84 KB
/
TypeInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.CSharp.Symbols;
using System;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp
{
internal struct CSharpTypeInfo : IEquatable<CSharpTypeInfo>
{
internal static readonly CSharpTypeInfo None = new CSharpTypeInfo(null, null, Conversion.Identity);
// should be best guess if there is one, or error type if none.
/// <summary>
/// The type of the expression represented by the syntax node. For expressions that do not
/// have a type, null is returned. If the type could not be determined due to an error, than
/// an object derived from ErrorTypeSymbol is returned.
/// </summary>
public readonly TypeSymbol Type;
/// <summary>
/// The type of the expression after it has undergone an implicit conversion. If the type
/// did not undergo an implicit conversion, returns the same as Type.
/// </summary>
public readonly TypeSymbol ConvertedType;
/// <summary>
/// If the expression underwent an implicit conversion, return information about that
/// conversion. Otherwise, returns an identity conversion.
/// </summary>
public readonly Conversion ImplicitConversion;
internal CSharpTypeInfo(TypeSymbol type, TypeSymbol convertedType, Conversion implicitConversion)
{
// When constructing the result for the Caas API, we expose the underlying symbols that
// may have been hidden under error type, if the error type was immediate. We will
// expose error types that were constructed, or type parameters of constructed types.
this.Type = type.GetNonErrorGuess() ?? type;
this.ConvertedType = convertedType.GetNonErrorGuess() ?? convertedType;
this.ImplicitConversion = implicitConversion;
}
public static implicit operator TypeInfo(CSharpTypeInfo info)
{
return new TypeInfo(info.Type, info.ConvertedType, default, default);
}
public override bool Equals(object obj)
{
return obj is CSharpTypeInfo && Equals((CSharpTypeInfo)obj);
}
public bool Equals(CSharpTypeInfo other)
{
return this.ImplicitConversion.Equals(other.ImplicitConversion)
&& TypeSymbol.Equals(this.Type, other.Type, TypeCompareKind.ConsiderEverything2)
&& TypeSymbol.Equals(this.ConvertedType, other.ConvertedType, TypeCompareKind.ConsiderEverything2);
}
public override int GetHashCode()
{
return Hash.Combine(this.ConvertedType, Hash.Combine(this.Type, this.ImplicitConversion.GetHashCode()));
}
}
}