public MemberRefMetadataDecoder(
     PEModuleSymbol moduleSymbol,
     TypeSymbol containingType) :
     base(moduleSymbol, containingType as PENamedTypeSymbol)
 {
     Debug.Assert((object)containingType != null);
     _containingType = containingType;
 }
Esempio n. 2
0

        
Esempio n. 3
0
        internal static ObsoleteAttributeData GetObsoleteDataFromMetadata(
            EntityHandle token,
            PEModuleSymbol containingModule,
            bool ignoreByRefLikeMarker
            )
        {
            var obsoleteAttributeData =
                containingModule.Module.TryGetDeprecatedOrExperimentalOrObsoleteAttribute(
                    token,
                    new MetadataDecoder(containingModule),
                    ignoreByRefLikeMarker
                    );

            Debug.Assert(obsoleteAttributeData == null || !obsoleteAttributeData.IsUninitialized);
            return(obsoleteAttributeData);
        }
Esempio n. 4
0
            public PEPropertySymbolWithCustomModifiers(
                PEModuleSymbol moduleSymbol,
                PENamedTypeSymbol containingType,
                PropertyDefinitionHandle handle,
                PEMethodSymbol getMethod,
                PEMethodSymbol setMethod,
                ParamInfo <TypeSymbol>[] propertyParams,
                MetadataDecoder metadataDecoder)
                : base(moduleSymbol, containingType, handle, getMethod, setMethod,
                       propertyParams,
                       metadataDecoder)
            {
                var returnInfo = propertyParams[0];

                _refCustomModifiers = CSharpCustomModifier.Convert(returnInfo.RefCustomModifiers);
            }
Esempio n. 5
0
        /// <summary>
        /// Returns a string representation of IL read from metadata.
        /// </summary>
        /// <remarks>
        /// Currently unsupported IL decoding:
        /// - multidimensional arrays
        /// - vararg calls
        /// - winmd
        /// - global methods
        /// </remarks>
        internal unsafe static string VisualizeRealIL(PEModuleSymbol peModule, CompilationTestData.MethodData methodData, IReadOnlyDictionary <int, string> markers)
        {
            var typeName = GetContainingTypeMetadataName(methodData.Method);
            // TODO (tomat): global methods (typeName == null)

            var type = peModule.ContainingAssembly.GetTypeByMetadataName(typeName);

            // TODO (tomat): overloaded methods
            var method = (PEMethodSymbol)type.GetMembers(methodData.Method.MetadataName).Single();

            var bodyBlock = peModule.Module.GetMethodBodyOrThrow(method.Handle);

            Assert.NotNull(bodyBlock);

            var moduleDecoder = new MetadataDecoder(peModule);
            var peMethod      = (PEMethodSymbol)moduleDecoder.GetSymbolForILToken(method.Handle);

            StringBuilder sb      = new StringBuilder();
            var           ilBytes = bodyBlock.GetILContent();

            var ehHandlerRegions = ILVisualizer.GetHandlerSpans(bodyBlock.ExceptionRegions);

            var methodDecoder = new MetadataDecoder(peModule, peMethod);

            ImmutableArray <ILVisualizer.LocalInfo> localDefinitions;

            if (!bodyBlock.LocalSignature.IsNil)
            {
                var signature       = peModule.Module.MetadataReader.GetStandaloneSignature(bodyBlock.LocalSignature).Signature;
                var signatureReader = peModule.Module.GetMemoryReaderOrThrow(signature);
                var localInfos      = methodDecoder.DecodeLocalSignatureOrThrow(ref signatureReader);
                localDefinitions = ToLocalDefinitions(localInfos, methodData.ILBuilder);
            }
            else
            {
                localDefinitions = ImmutableArray.Create <ILVisualizer.LocalInfo>();
            }

            // TODO (tomat): the .maxstack in IL can't be less than 8, but many tests expect .maxstack < 8
            int maxStack = (bodyBlock.MaxStack == 8 && methodData.ILBuilder.MaxStack < 8) ? methodData.ILBuilder.MaxStack : bodyBlock.MaxStack;

            var visualizer = new Visualizer(new MetadataDecoder(peModule, peMethod));

            visualizer.DumpMethod(sb, maxStack, ilBytes, localDefinitions, ehHandlerRegions, markers);

            return(sb.ToString());
        }
Esempio n. 6
0
        /// <summary>
        /// </summary>
        /// <param name="peModuleSymbol">
        /// </param>
        /// <param name="genericContext">
        /// </param>
        /// <returns>
        /// </returns>
        internal static MetadataDecoder GetMetadataDecoder(this PEModuleSymbol peModuleSymbol, IGenericContext genericContext)
        {
            // TODO: make a review as you did for LocalVariables, so check if you need to use new MetadataDecoder(peModuleSymbol, peMethodSymbol) or new MetadataDecoder(peModuleSymbol, peTypeSymbol)
            if (genericContext != null)
            {
                var methodDefOrSpec = genericContext.MethodDefinition ?? genericContext.MethodSpecialization;
                if (methodDefOrSpec != null)
                {
                    var methodDef     = ((MetadataMethodAdapter)methodDefOrSpec).MethodDef;
                    var contextMethod = methodDef as PEMethodSymbol;
                    if (contextMethod != null)
                    {
                        return(new MetadataDecoder(peModuleSymbol, contextMethod));
                    }

                    var contextMethodOrig = methodDef.OriginalDefinition as PEMethodSymbol;
                    if (contextMethodOrig != null)
                    {
                        return(new MetadataDecoder(peModuleSymbol, contextMethodOrig));
                    }

                    Debug.Assert(false, "Could not resolve Generic");
                }

                var typeDefOrSpec = genericContext.TypeDefinition ?? genericContext.TypeSpecialization;
                if (typeDefOrSpec != null)
                {
                    var typeDef     = ((MetadataTypeAdapter)typeDefOrSpec).TypeDef;
                    var contextType = typeDef as PENamedTypeSymbol;
                    if (contextType != null)
                    {
                        return(new MetadataDecoder(peModuleSymbol, contextType));
                    }

                    var contextTypeOrig = typeDef.OriginalDefinition as PENamedTypeSymbol;
                    if (contextTypeOrig != null)
                    {
                        return(new MetadataDecoder(peModuleSymbol, contextTypeOrig));
                    }

                    Debug.Assert(false, "Could not resolve Generic");
                }
            }

            return(new MetadataDecoder(peModuleSymbol));
        }
Esempio n. 7
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="underlyingAssembly">
        /// The underlying AssemblySymbol, cannot be an instance of RetargetingAssemblySymbol.
        /// </param>
        /// <param name="isLinked">
        /// Assembly is /l-ed by compilation that is using it as a reference.
        /// </param>
        public RetargetingAssemblySymbol(SourceAssemblySymbol underlyingAssembly, bool isLinked)
        {
            Debug.Assert((object)underlyingAssembly != null);

            _underlyingAssembly = underlyingAssembly;

            ModuleSymbol[] modules = new ModuleSymbol[underlyingAssembly.Modules.Length];

            modules[0] = new RetargetingModuleSymbol(this, (SourceModuleSymbol)underlyingAssembly.Modules[0]);

            for (int i = 1; i < underlyingAssembly.Modules.Length; i++)
            {
                PEModuleSymbol under = (PEModuleSymbol)underlyingAssembly.Modules[i];
                modules[i] = new PEModuleSymbol(this, under.Module, under.ImportOptions, i);
            }

            _modules  = modules.AsImmutableOrNull();
            _isLinked = isLinked;
        }
Esempio n. 8
0
 internal static void InitializeObsoleteDataFromMetadata(
     ref ObsoleteAttributeData data,
     EntityHandle token,
     PEModuleSymbol containingModule,
     bool ignoreByRefLikeMarker
     )
 {
     if (ReferenceEquals(data, ObsoleteAttributeData.Uninitialized))
     {
         ObsoleteAttributeData obsoleteAttributeData = GetObsoleteDataFromMetadata(
             token,
             containingModule,
             ignoreByRefLikeMarker
             );
         Interlocked.CompareExchange(
             ref data,
             obsoleteAttributeData,
             ObsoleteAttributeData.Uninitialized
             );
     }
 }
        internal static string GetDocumentationComment(
            Symbol symbol,
            PEModuleSymbol containingPEModule,
            CultureInfo preferredCulture,
            CancellationToken cancellationToken,
            ref Tuple <CultureInfo, string> lazyDocComment
            )
        {
            // Have we cached anything?
            if (lazyDocComment == null)
            {
                Interlocked.CompareExchange(
                    ref lazyDocComment,
                    Tuple.Create(
                        preferredCulture,
                        containingPEModule.DocumentationProvider.GetDocumentationForSymbol(
                            symbol.GetDocumentationCommentId(),
                            preferredCulture,
                            cancellationToken
                            )
                        ),
                    null
                    );
            }

            // Does the cached version match the culture we asked for?
            if (object.Equals(lazyDocComment.Item1, preferredCulture))
            {
                return(lazyDocComment.Item2);
            }

            // We've already cached a different culture - create a fresh version.
            return(containingPEModule.DocumentationProvider.GetDocumentationForSymbol(
                       symbol.GetDocumentationCommentId(),
                       preferredCulture,
                       cancellationToken
                       ));
        }
Esempio n. 10
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="underlyingAssembly">
        /// The underlying AssemblySymbol, cannot be an instance of CSharpAssemblySymbol.
        /// </param>
        internal CSharpAssemblySymbol(CSharpSymbols.AssemblySymbol underlyingAssembly)
        {
            Debug.Assert((object)underlyingAssembly != null);

            _underlyingAssembly = underlyingAssembly;

            ModuleSymbol[] modules = new CSharpModuleSymbol[underlyingAssembly.Modules.Length];

            modules[0] = new CSharpModuleSymbol(this, underlyingAssembly.Modules[0], 0);

            for (int i = 1; i < underlyingAssembly.Modules.Length; i++)
            {
                PEModuleSymbol under = (PEModuleSymbol)underlyingAssembly.Modules[i];
                modules[i] = new CSharpModuleSymbol(this, new PEModuleSymbol((PEAssemblySymbol)this._underlyingAssembly, under.Module, under.ImportOptions, i), i);
            }

            _modules = modules.AsImmutableOrNull();

            foreach (var module in _modules)
            {
                CSharpSymbolMap.RegisterModuleSymbol((CSharpModuleSymbol)module);
            }
        }
Esempio n. 11
0
        private static PENamedTypeSymbol GetType(PEModuleSymbol module, TypeDefinitionHandle typeHandle)
        {
            var metadataDecoder = new MetadataDecoder(module);

            return((PENamedTypeSymbol)metadataDecoder.GetTypeOfToken(typeHandle));
        }
 internal static string GetDocumentationComment(
     Symbol symbol,
     PEModuleSymbol containingPEModule,
     CultureInfo preferredCulture,
     CancellationToken cancellationToken,
     ref (CultureInfo Culture, string XmlText) lazyDocComment)
Esempio n. 13
0
 private NullableAttributesVisitor(PEModuleSymbol module, StringBuilder builder)
 {
     _module   = module;
     _builder  = builder;
     _reported = new HashSet <Symbol>();
 }
Esempio n. 14
0
        public static ImportValueAttributeData HasImportValueAttribute(EntityHandle token, PEModuleSymbol containingModule)
        {
            var metadataReader = containingModule.Module.MetadataReader;

            foreach (var attr in metadataReader.GetCustomAttributes(token))
            {
                if (containingModule.Module.IsTargetAttribute(attr, CoreTypes.PeachpieRuntimeNamespace, "ImportValueAttribute", out _))
                {
                    // [ImportValue(Int32)]
                    if (ReadCustomAttributeValue(attr, containingModule.Module, out var valuespec))
                    {
                        Debug.Assert(valuespec != 0);
                        return(new ImportValueAttributeData {
                            Value = (ImportValueAttributeData.ValueSpec)valuespec
                        });
                    }
                }
            }

            //
            return(default);
Esempio n. 15
0
 public static bool HasPhpFieldsOnlyCtorAttribute(EntityHandle token, PEModuleSymbol containingModule)
 {
     return(containingModule != null && PEModule.FindTargetAttribute(containingModule.Module.MetadataReader, token, PhpFieldsOnlyCtorAttribute).HasValue);
 }
Esempio n. 16
0
 internal PEPropertyAccessorSymbol(PEModuleSymbol moduleSymbol, PEPropertySymbol propertySymbol, MethodKind methodKind, Rid methodRid) :
     base(moduleSymbol, (PENamedTypeSymbol)propertySymbol.ContainingType, methodKind, methodRid)
 {
     this.propertySymbol = propertySymbol;
 }
Esempio n. 17
0
 public static bool HasPhpTraitAttribute(EntityHandle token, PEModuleSymbol containingModule)
 {
     return(PEModule.FindTargetAttribute(containingModule.Module.MetadataReader, token, PhpTraitAttribute).HasValue);
 }
 /// <summary>
 /// Initialize the ObsoleteAttributeData by fetching attributes and decoding ObsoleteAttributeData. This can be
 /// done for Metadata symbol easily whereas trying to do this for source symbols could result in cycles.
 /// </summary>
 internal static void InitializeObsoleteDataFromMetadata(ref ObsoleteAttributeData data, Handle token, PEModuleSymbol containingModule)
 {
     if (ReferenceEquals(data, ObsoleteAttributeData.Uninitialized))
     {
         ObsoleteAttributeData obsoleteAttributeData;
         bool isObsolete = containingModule.Module.HasDeprecatedOrObsoleteAttribute(token, out obsoleteAttributeData);
         Debug.Assert(isObsolete == (obsoleteAttributeData != null));
         Debug.Assert(obsoleteAttributeData == null || !obsoleteAttributeData.IsUninitialized);
         Interlocked.CompareExchange(ref data, obsoleteAttributeData, ObsoleteAttributeData.Uninitialized);
     }
 }
 public CSharpEESymbolProvider(SourceAssemblySymbol sourceAssembly, PEModuleSymbol module, PEMethodSymbol method)
 {
     _metadataDecoder = new MetadataDecoder(module, method);
     _sourceAssembly  = sourceAssembly;
     _method          = method;
 }
 private NullableAttributesVisitor(PEModuleSymbol module, StringBuilder builder) : base(builder)
 {
     _module = module;
 }
Esempio n. 22
0
 internal PEPropertyAccessorSymbol(PEModuleSymbol moduleSymbol, PEPropertySymbol propertySymbol, MethodKind methodKind, Rid methodRid) :
     base(moduleSymbol, (PENamedTypeSymbol)propertySymbol.ContainingType, methodKind, methodRid)
 {
     this.propertySymbol = propertySymbol;
 }
Esempio n. 23
0
 /// <summary>
 /// </summary>
 /// <param name="peModuleSymbol">
 /// </param>
 /// <param name="peMethodSymbol">
 /// </param>
 private void GetPEFieldSymbol(out PEModuleSymbol peModuleSymbol, out PEFieldSymbol peMethodSymbol)
 {
     peModuleSymbol = this.fieldDef.ContainingModule as PEModuleSymbol;
     peMethodSymbol = this.fieldDef as PEFieldSymbol ?? this.fieldDef.OriginalDefinition as PEFieldSymbol;
 }
Esempio n. 24
0
 public static bool HasCastToFalse(EntityHandle token, PEModuleSymbol containingModule)
 {
     return(containingModule != null && PEModule.FindTargetAttribute(containingModule.Module.MetadataReader, token, CastToFalse).HasValue);
 }
Esempio n. 25
0
        internal void AssertDeclaresType(PEModuleSymbol peModule, WellKnownType type, Accessibility expectedAccessibility)
        {
            var name = MetadataTypeName.FromFullName(type.GetMetadataName());

            Assert.Equal(expectedAccessibility, peModule.LookupTopLevelMetadataType(ref name).DeclaredAccessibility);
        }
Esempio n. 26
0
    internal static DiagnosticInfo?DeriveCompilerFeatureRequiredAttributeDiagnostic(Symbol symbol, PEModuleSymbol module, EntityHandle handle, CompilerFeatureRequiredFeatures allowedFeatures, MetadataDecoder decoder)
    {
        string?disallowedFeature = module.Module.GetFirstUnsupportedCompilerFeatureFromToken(handle, decoder, allowedFeatures);

        return(disallowedFeature != null
            ?  // '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler.
               new CSDiagnosticInfo(ErrorCode.ERR_UnsupportedCompilerFeature, symbol, disallowedFeature)
            : null);
    }