Beispiel #1
0
        internal override ImmutableArray <string> GetAppliedConditionalSymbols()
        {
            if (!_packedFlags.IsConditionalPopulated)
            {
                var result = _containingType.ContainingPEModule.Module.GetConditionalAttributeValues(_handle);
                Debug.Assert(!result.IsDefault);
                if (!result.IsEmpty)
                {
                    result = InterlockedOperations.Initialize(ref AccessUncommonFields()._lazyConditionalAttributeSymbols, result);
                }

                _packedFlags.SetIsConditionalAttributePopulated();
                return(result);
            }

            var uncommonFields = _uncommonFields;

            if (uncommonFields == null)
            {
                return(ImmutableArray <string> .Empty);
            }
            else
            {
                var result = uncommonFields._lazyConditionalAttributeSymbols;
                return(result.IsDefault
                    ? InterlockedOperations.Initialize(ref uncommonFields._lazyConditionalAttributeSymbols, ImmutableArray <string> .Empty)
                    : result);
            }
        }
        public override ImmutableArray <CSharpAttributeData> GetAttributes()
        {
            if (!_packedFlags.IsCustomAttributesPopulated)
            {
                // Compute the value
                var attributeData            = default(ImmutableArray <CSharpAttributeData>);
                var containingPEModuleSymbol = _containingType.ContainingPEModule;

                // Could this possibly be an extension method?
                bool alreadySet        = _packedFlags.IsExtensionMethodIsPopulated;
                bool checkForExtension = alreadySet
                    ? _packedFlags.IsExtensionMethod
                    : this.MethodKind == MethodKind.Ordinary &&
                                         IsValidExtensionMethodSignature() &&
                                         _containingType.MightContainExtensionMethods;

                bool isExtensionMethod = false;
                if (checkForExtension)
                {
                    containingPEModuleSymbol.LoadCustomAttributesFilterExtensions(_handle,
                                                                                  ref attributeData,
                                                                                  out isExtensionMethod);
                }
                else
                {
                    containingPEModuleSymbol.LoadCustomAttributes(_handle,
                                                                  ref attributeData);
                }

                if (!alreadySet)
                {
                    _packedFlags.InitializeIsExtensionMethod(isExtensionMethod);
                }

                // Store the result in uncommon fields only if it's not empty.
                Debug.Assert(!attributeData.IsDefault);
                if (!attributeData.IsEmpty)
                {
                    attributeData = InterlockedOperations.Initialize(ref AccessUncommonFields()._lazyCustomAttributes, attributeData);
                }

                _packedFlags.SetIsCustomAttributesPopulated();
                return(attributeData);
            }

            // Retrieve cached or inferred value.
            var uncommonFields = _uncommonFields;

            if (uncommonFields == null)
            {
                return(ImmutableArray <CSharpAttributeData> .Empty);
            }
            else
            {
                var attributeData = uncommonFields._lazyCustomAttributes;
                return(attributeData.IsDefault
                    ? InterlockedOperations.Initialize(ref uncommonFields._lazyCustomAttributes, ImmutableArray <CSharpAttributeData> .Empty)
                    : attributeData);
            }
        }
Beispiel #3
0
        private SignatureData LoadSignature()
        {
            var moduleSymbol = _containingType.ContainingPEModule;

            SignatureHeader         signatureHeader;
            BadImageFormatException mrEx;

            ParamInfo <TypeSymbol>[] paramInfo = new MetadataDecoder(moduleSymbol, this).GetSignatureForMethod(_handle, out signatureHeader, out mrEx, allowByRefReturn: true);
            bool makeBad = (mrEx != null);

            // If method is not generic, let's assign empty list for type parameters
            if (!signatureHeader.IsGeneric &&
                _lazyTypeParameters.IsDefault)
            {
                ImmutableInterlocked.InterlockedInitialize(ref _lazyTypeParameters,
                                                           ImmutableArray <TypeParameterSymbol> .Empty);
            }

            int count = paramInfo.Length - 1;
            ImmutableArray <ParameterSymbol> @params;
            bool isBadParameter;

            if (count > 0)
            {
                var builder = ImmutableArray.CreateBuilder <ParameterSymbol>(count);
                for (int i = 0; i < count; i++)
                {
                    builder.Add(PEParameterSymbol.Create(moduleSymbol, this, i, paramInfo[i + 1], out isBadParameter));
                    if (isBadParameter)
                    {
                        makeBad = true;
                    }
                }

                @params = builder.ToImmutable();
            }
            else
            {
                @params = ImmutableArray <ParameterSymbol> .Empty;
            }

            // Dynamify object type if necessary
            var returnType = paramInfo[0].Type.AsDynamicIfNoPia(_containingType);

            // Check for tuple type
            returnType = TupleTypeDecoder.DecodeTupleTypesIfApplicable(returnType, paramInfo[0].Handle, moduleSymbol);

            paramInfo[0].Type = returnType;

            var returnParam = PEParameterSymbol.Create(moduleSymbol, this, 0, paramInfo[0], out isBadParameter);

            if (makeBad || isBadParameter)
            {
                InitializeUseSiteDiagnostic(new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, this));
            }

            var signature = new SignatureData(signatureHeader, @params, returnParam);

            return(InterlockedOperations.Initialize(ref _lazySignature, signature));
        }
Beispiel #4
0
        private ImmutableArray <TypeParameterSymbol> EnsureTypeParametersAreLoaded(ref DiagnosticInfo diagnosticInfo)
        {
            var typeParams = _lazyTypeParameters;

            if (!typeParams.IsDefault)
            {
                return(typeParams);
            }

            return(InterlockedOperations.Initialize(ref _lazyTypeParameters, LoadTypeParameters(ref diagnosticInfo)));
        }
Beispiel #5
0
        private DiagnosticInfo InitializeUseSiteDiagnostic(DiagnosticInfo diagnostic)
        {
            Debug.Assert(!CSDiagnosticInfo.IsEmpty(diagnostic));
            if (diagnostic != null)
            {
                diagnostic = InterlockedOperations.Initialize(ref AccessUncommonFields()._lazyUseSiteDiagnostic, diagnostic, CSDiagnosticInfo.EmptyErrorInfo);
            }

            _packedFlags.SetIsUseSiteDiagnosticPopulated();
            return(diagnostic);
        }
Beispiel #6
0
        GetCciAdapter()
        {
#if DEBUG
            if (_lazyAdapter is null)
            {
                return(InterlockedOperations.Initialize(ref _lazyAdapter, new EventSymbolAdapter(this)));
            }

            return(_lazyAdapter);
#else
            return(this);
#endif
        }
        private EmitBaseline.MetadataSymbols GetOrCreateMetadataSymbols(EmitBaseline initialBaseline, CSharpCompilation compilation)
        {
            if (initialBaseline.LazyMetadataSymbols != null)
            {
                return(initialBaseline.LazyMetadataSymbols);
            }

            var originalMetadata = initialBaseline.OriginalMetadata;

            // The purpose of this compilation is to provide PE symbols for original metadata.
            // We need to transfer the references from the current source compilation but don't need its syntax trees.
            var metadataCompilation = compilation.RemoveAllSyntaxTrees();

            var metadataAssembly       = metadataCompilation.GetBoundReferenceManager().CreatePEAssemblyForAssemblyMetadata(AssemblyMetadata.Create(originalMetadata), MetadataImportOptions.All);
            var metadataDecoder        = new MetadataDecoder(metadataAssembly.PrimaryModule);
            var metadataAnonymousTypes = GetAnonymousTypeMapFromMetadata(originalMetadata.MetadataReader, metadataDecoder);
            var metadataSymbols        = new EmitBaseline.MetadataSymbols(metadataAnonymousTypes, metadataDecoder);

            return(InterlockedOperations.Initialize(ref initialBaseline.LazyMetadataSymbols, metadataSymbols));
        }
Beispiel #8
0
        internal override DiagnosticInfo GetUseSiteDiagnostic()
        {
            if (!_packedFlags.IsUseSiteDiagnosticPopulated)
            {
                DiagnosticInfo result = null;
                CalculateUseSiteDiagnostic(ref result);
                EnsureTypeParametersAreLoaded(ref result);
                return(InitializeUseSiteDiagnostic(result));
            }

            var uncommonFields = _uncommonFields;

            if (uncommonFields == null)
            {
                return(null);
            }
            else
            {
                var result = uncommonFields._lazyUseSiteDiagnostic;
                return(CSDiagnosticInfo.IsEmpty(result)
                       ? InterlockedOperations.Initialize(ref uncommonFields._lazyUseSiteDiagnostic, null, CSDiagnosticInfo.EmptyErrorInfo)
                       : result);
            }
        }
Beispiel #9
0
 internal override bool TryGetThisParameter(out ParameterSymbol thisParameter)
 {
     thisParameter = IsStatic ? null :
                     _uncommonFields?._lazyThisParameter ?? InterlockedOperations.Initialize(ref AccessUncommonFields()._lazyThisParameter, new ThisParameterSymbol(this));
     return(true);
 }
Beispiel #10
0
        private UncommonFields AccessUncommonFields()
        {
            var retVal = _uncommonFields;

            return(retVal ?? InterlockedOperations.Initialize(ref _uncommonFields, CreateUncommonFields()));
        }