コード例 #1
0
        public void TypeReferencingAnotherTypeThatUsesAPublicIsByRefLikeAttributeFromAThirdNotReferencedAssemblyShouldGenerateItsOwn()
        {
            var options = TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All);

            var code1 = CreateCompilation(@"
namespace System.Runtime.CompilerServices
{
    public class IsByRefLikeAttribute : System.Attribute { }
}");

            var code2 = CreateCompilation(@"
public class Test1
{
	public ref struct S1{}
}", references: new[] { code1.ToMetadataReference() }, options: options);

            CompileAndVerify(code2, verify: Verification.Passes, symbolValidator: module =>
            {
                // IsByRefLike is not generated in assembly
                var isByRefLikeAttributeName = WellKnownTypes.GetMetadataName(WellKnownType.System_Runtime_CompilerServices_IsByRefLikeAttribute);
                Assert.Null(module.ContainingAssembly.GetTypeByMetadataName(isByRefLikeAttributeName));
            });

            var code3 = CreateCompilation(@"
public class Test2
{
	public ref struct S1{}
}", references: new[] { code2.ToMetadataReference() }, options: options);

            CompileAndVerify(code3, symbolValidator: module =>
            {
                // IsByRefLike is generated in assembly
                AssertGeneratedEmbeddedAttribute(module.ContainingAssembly, AttributeDescription.CodeAnalysisEmbeddedAttribute.FullName);
                AssertGeneratedEmbeddedAttribute(module.ContainingAssembly, AttributeDescription.IsByRefLikeAttribute.FullName);
            });
        }
コード例 #2
0
ファイル: AssemblySymbol.cs プロジェクト: yonifra/roslyn
 internal NamedTypeSymbol GetWellKnownType(WellKnownType type)
 {
     return(this.GetTypeByMetadataName(WellKnownTypes.GetMetadataName(type)));
 }
コード例 #3
0
ファイル: CoreType.cs プロジェクト: toreinar/peachpie
        public CoreTypes(PhpCompilation compilation)
        {
            Contract.ThrowIfNull(compilation);
            _compilation = compilation;
            _table       = new Dictionary <string, CoreType>();

            Void                = Create(SpecialType.System_Void);
            Object              = Create(SpecialType.System_Object);
            Int32               = Create(SpecialType.System_Int32);
            Long                = Create(SpecialType.System_Int64);
            Double              = Create(SpecialType.System_Double);
            Boolean             = Create(SpecialType.System_Boolean);
            String              = Create(SpecialType.System_String);
            Exception           = CreateFromFullName(WellKnownTypes.GetMetadataName(WellKnownType.System_Exception));
            RuntimeTypeHandle   = Create(SpecialType.System_RuntimeTypeHandle);
            RuntimeMethodHandle = Create(SpecialType.System_RuntimeMethodHandle);

            PhpNumber                    = Create("PhpNumber");
            PhpAlias                     = Create("PhpAlias");
            PhpValue                     = Create("PhpValue");
            PhpString                    = Create("PhpString");
            PhpArray                     = Create("PhpArray");
            PhpResource                  = Create("PhpResource");
            IPhpArray                    = Create("IPhpArray");
            IPhpEnumerable               = Create("IPhpEnumerable");
            IPhpCallable                 = Create("IPhpCallable");
            IPhpConvertible              = Create("IPhpConvertible");
            PhpString_Blob               = Create("PhpString+Blob");
            IntStringKey                 = Create("IntStringKey");
            PhpHashtable                 = Create("PhpHashtable");
            ScriptDiedException          = Create("ScriptDiedException");
            Context                      = Create("Context");
            Operators                    = Create("Operators");
            Comparison                   = Create("Comparison");
            StrictComparison             = Create("StrictComparison");
            Convert                      = Create("Convert");
            PhpException                 = Create("PhpException");
            ScriptAttribute              = Create("ScriptAttribute");
            PhpTraitAttribute            = Create(PhpTraitAttributeName);
            PhpTypeAttribute             = Create("PhpTypeAttribute");
            PhpHiddenAttribute           = Create("PhpHiddenAttribute");
            PhpFieldsOnlyCtorAttribute   = Create(PhpFieldsOnlyCtorAttributeName);
            NotNullAttribute             = Create("NotNullAttribute");
            PhpMemberVisibilityAttribute = Create(PhpMemberVisibilityAttributeName);
            IStaticInit                  = Create("IStaticInit");
            RoutineInfo                  = Create("Reflection.RoutineInfo");
            stdClass                     = CreateFromFullName("stdClass");
            ArrayAccess                  = CreateFromFullName("ArrayAccess");
            Closure                      = CreateFromFullName("Closure");

            BinderFactory       = Create("Dynamic.BinderFactory");
            GetClassConstBinder = Create("Dynamic.GetClassConstBinder");
            GetFieldBinder      = Create("Dynamic.GetFieldBinder");
            SetFieldBinder      = Create("Dynamic.SetFieldBinder");
            AccessMask          = CreateFromFullName("Pchp.CodeAnalysis.Semantics.AccessMask");

            Dynamic_NameParam_T      = Create("Dynamic.NameParam`1");
            Dynamic_TargetTypeParam  = Create("Dynamic.TargetTypeParam");
            Dynamic_CallerTypeParam  = Create("Dynamic.CallerTypeParam");
            Dynamic_UnpackingParam_T = Create("Dynamic.UnpackingParam`1");

            PhpTypeInfoExtension = Create("Reflection.PhpTypeInfoExtension");
            PhpTypeInfo          = Create("Reflection.PhpTypeInfo");
            CommonPhpArrayKeys   = Create("CommonPhpArrayKeys");

            Iterator  = CreateFromFullName("Iterator");
            Generator = CreateFromFullName("Generator");
            GeneratorStateMachineDelegate = CreateFromFullName("GeneratorStateMachineDelegate");

            IntPtr = CreateFromFullName("System.IntPtr");
        }
コード例 #4
0
        private static void AssertNoIsReadOnlyAttributeExists(AssemblySymbol assembly)
        {
            var isReadOnlyAttributeTypeName = WellKnownTypes.GetMetadataName(WellKnownType.System_Runtime_CompilerServices_IsReadOnlyAttribute);

            Assert.Null(assembly.GetTypeByMetadataName(isReadOnlyAttributeTypeName));
        }
コード例 #5
0
ファイル: CoreType.cs プロジェクト: kendallb/peachpie
        public CoreTypes(PhpCompilation compilation)
        {
            Contract.ThrowIfNull(compilation);
            _compilation = compilation;
            _table       = new Dictionary <string, CoreType>();

            Void                = Create(SpecialType.System_Void);
            Object              = Create(SpecialType.System_Object);
            Byte                = Create(SpecialType.System_Byte);
            Int32               = Create(SpecialType.System_Int32);
            Long                = Create(SpecialType.System_Int64);
            Double              = Create(SpecialType.System_Double);
            Boolean             = Create(SpecialType.System_Boolean);
            String              = Create(SpecialType.System_String);
            Exception           = CreateFromFullName(WellKnownTypes.GetMetadataName(WellKnownType.System_Exception));
            RuntimeTypeHandle   = Create(SpecialType.System_RuntimeTypeHandle);
            RuntimeMethodHandle = Create(SpecialType.System_RuntimeMethodHandle);

            PhpNumber                    = Create("PhpNumber");
            PhpAlias                     = Create("PhpAlias");
            PhpValue                     = Create("PhpValue");
            PhpString                    = Create("PhpString");
            PhpArray                     = Create("PhpArray");
            PhpResource                  = Create("PhpResource");
            IPhpArray                    = Create("IPhpArray");
            IPhpEnumerable               = Create("IPhpEnumerable");
            IPhpCallable                 = Create("IPhpCallable");
            IPhpConvertible              = Create("IPhpConvertible");
            PhpString_Blob               = Create("PhpString+Blob");
            IntStringKey                 = Create("IntStringKey");
            PhpHashtable                 = Create("PhpHashtable");
            ScriptDiedException          = Create("ScriptDiedException");
            Context                      = Create("Context");
            Operators                    = Create("Operators");
            Comparison                   = Create("Comparison");
            StrictComparison             = Create("StrictComparison");
            Convert                      = Create("Convert");
            StrictConvert                = Create("StrictConvert");
            PhpException                 = Create("PhpException");
            PhpCallableToDelegate        = Create("PhpCallableToDelegate`1"); // Arity 1
            ScriptAttribute              = Create("ScriptAttribute");
            PhpTraitAttribute            = Create(PhpTraitAttributeName);
            PharAttribute                = Create("PharAttribute");
            PhpTypeAttribute             = Create("PhpTypeAttribute");
            PhpHiddenAttribute           = Create("PhpHiddenAttribute");
            ImportValueAttribute         = Create("ImportValueAttribute");
            DummyFieldsOnlyCtor          = Create("DummyFieldsOnlyCtor");
            PhpFieldsOnlyCtorAttribute   = Create(PhpFieldsOnlyCtorAttributeName);
            DefaultValueAttribute        = Create("DefaultValueAttribute");
            PhpCustomAtribute            = Create(nameof(PhpCustomAtribute));
            PhpMemberVisibilityAttribute = Create(PhpMemberVisibilityAttributeName);
            NullableAttribute            = CreateFromFullName("System.Runtime.CompilerServices.NullableAttribute");
            NullableContextAttribute     = CreateFromFullName("System.Runtime.CompilerServices.NullableContextAttribute");
            IStaticInit                  = Create("IStaticInit");
            RoutineInfo                  = Create("Reflection.RoutineInfo");
            IndirectLocal                = Create("IndirectLocal");
            stdClass                     = CreateFromFullName("stdClass");
            ArrayAccess                  = CreateFromFullName("ArrayAccess");
            Closure                      = CreateFromFullName("Closure");

            BinderFactory       = Create("Dynamic.BinderFactory");
            GetClassConstBinder = Create("Dynamic.GetClassConstBinder");
            GetFieldBinder      = Create("Dynamic.GetFieldBinder");
            SetFieldBinder      = Create("Dynamic.SetFieldBinder");
            AccessMask          = CreateFromFullName("Pchp.CodeAnalysis.Semantics.AccessMask");

            Dynamic_NameParam_T         = Create("Dynamic.NameParam`1");
            Dynamic_TargetTypeParam     = Create("Dynamic.TargetTypeParam");
            Dynamic_LateStaticTypeParam = Create("Dynamic.LateStaticTypeParam");
            Dynamic_CallerTypeParam     = Create("Dynamic.CallerTypeParam");
            Dynamic_UnpackingParam_T    = Create("Dynamic.UnpackingParam`1");

            RuntimeChain_ChainEnd       = Create("Dynamic.RuntimeChain.ChainEnd");
            RuntimeChain_Value_T        = Create("Dynamic.RuntimeChain.Value`1");
            RuntimeChain_Property_T     = Create("Dynamic.RuntimeChain.Property`1");
            RuntimeChain_ArrayItem_T    = Create("Dynamic.RuntimeChain.ArrayItem`1");
            RuntimeChain_ArrayNewItem_T = Create("Dynamic.RuntimeChain.ArrayNewItem`1");

            PhpTypeInfoExtension = Create("Reflection.PhpTypeInfoExtension");
            PhpTypeInfo          = Create("Reflection.PhpTypeInfo");
            CommonPhpArrayKeys   = Create("CommonPhpArrayKeys");
            Helpers           = Create("Utilities.Helpers");
            PhpValueConverter = Create(nameof(PhpValueConverter));

            Iterator    = CreateFromFullName("Iterator");
            Traversable = CreateFromFullName("Traversable");
            Stringable  = CreateFromFullName("Stringable");
            Generator   = CreateFromFullName("Generator");
            GeneratorStateMachineDelegate = CreateFromFullName("GeneratorStateMachineDelegate");

            MainDelegate = Create("Context+MainDelegate");
            IntPtr       = CreateFromFullName("System.IntPtr");
            IDictionary  = CreateFromFullName("System.Collections.IDictionary");
        }