NullableWalker.ObjectCreationPlaceholderLocal.cs 4.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// 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 System;
using System.Collections.Immutable;
using System.Diagnostics;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CSharp
{
11
    internal partial class NullableWalker
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
    {
        /// <summary>
        /// A symbol to represent a placeholder for an instance being constructed by
        /// <see cref="BoundObjectCreationExpression"/>. It is used to track the state 
        /// of members being initialized.
        /// </summary>
        private class ObjectCreationPlaceholderLocal : LocalSymbol
        {
            private readonly Symbol _containingSymbol;
            private readonly TypeSymbolWithAnnotations _type;
            public readonly BoundExpression ObjectCreationExpression;

            public ObjectCreationPlaceholderLocal(Symbol containingSymbol, BoundExpression objectCreationExpression)
            {
                _containingSymbol = containingSymbol;
27
                _type = TypeSymbolWithAnnotations.Create(objectCreationExpression.Type, isNullableIfReferenceType: false);
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
                ObjectCreationExpression = objectCreationExpression;
            }

            public override bool Equals(object obj)
            {
                if ((object)this == obj)
                {
                    return true;
                }

                var other = obj as ObjectCreationPlaceholderLocal;

                return (object)other != null && (object)ObjectCreationExpression == other.ObjectCreationExpression;
            }

            public override int GetHashCode()
            {
                return ObjectCreationExpression.GetHashCode();
            }

C
Charles Stoner 已提交
48 49 50 51 52 53 54 55
            internal override SyntaxNode ScopeDesignatorOpt
            {
                get
                {
                    return null;
                }
            }

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
            public override Symbol ContainingSymbol
            {
                get
                {
                    return _containingSymbol;
                }
            }

            public override ImmutableArray<SyntaxReference> DeclaringSyntaxReferences
            {
                get
                {
                    return ImmutableArray<SyntaxReference>.Empty;
                }
            }

            public override ImmutableArray<Location> Locations
            {
                get
                {
                    return ImmutableArray<Location>.Empty;
                }
            }

            public override TypeSymbolWithAnnotations Type
            {
                get
                {
                    return _type;
                }
            }

            internal override LocalDeclarationKind DeclarationKind
            {
                get
                {
                    return LocalDeclarationKind.None;
                }
            }

            internal override SyntaxToken IdentifierToken
            {
                get
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }

            internal override bool IsCompilerGenerated
            {
                get
                {
                    return true;
                }
            }

            internal override bool IsImportedFromMetadata
            {
                get
                {
                    return false;
                }
            }

            internal override bool IsPinned
            {
                get
                {
                    return false;
                }
            }

C
Charles Stoner 已提交
128
            public override RefKind RefKind
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
            {
                get
                {
                    return RefKind.None;
                }
            }

            internal override SynthesizedLocalKind SynthesizedKind
            {
                get
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }

            internal override ConstantValue GetConstantValue(SyntaxNode node, LocalSymbol inProgress, DiagnosticBag diagnostics = null)
            {
                return null; 
            }

            internal override ImmutableArray<Diagnostic> GetConstantValueDiagnostics(BoundExpression boundInitValue)
            {
                return ImmutableArray<Diagnostic>.Empty;
            }

            internal override SyntaxNode GetDeclaratorSyntax()
            {
                throw ExceptionUtilities.Unreachable;
            }

            internal override LocalSymbol WithSynthesizedLocalKindAndSyntax(SynthesizedLocalKind kind, SyntaxNode syntax)
            {
                throw ExceptionUtilities.Unreachable;
            }
C
Charles Stoner 已提交
163 164 165 166

            internal override uint ValEscapeScope => throw ExceptionUtilities.Unreachable;

            internal override uint RefEscapeScope => throw ExceptionUtilities.Unreachable;
167 168
        }
    }
169
}