コード例 #1
0
        public override ImmutableArray <AttributeData> GetAttributes()
        {
            // [CompilerGenerated]
            var compilergenerated = (MethodSymbol)DeclaringCompilation.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor);

            return(base.GetAttributes().Add(
                       new SynthesizedAttributeData(compilergenerated, ImmutableArray <TypedConstant> .Empty, ImmutableArray <KeyValuePair <string, TypedConstant> > .Empty)
                       ));
        }
コード例 #2
0
        internal override IEnumerable <AttributeData> GetCustomAttributesToEmit(CommonModuleCompilationState compilationState)
        {
            if (IsParams)
            {
                yield return(new SynthesizedAttributeData(
                                 (MethodSymbol)DeclaringCompilation.GetWellKnownTypeMember(WellKnownMember.System_ParamArrayAttribute__ctor),
                                 ImmutableArray <TypedConstant> .Empty, ImmutableArray <KeyValuePair <string, TypedConstant> > .Empty));
            }

            yield break;
        }
コード例 #3
0
        internal override IEnumerable <AttributeData> GetCustomAttributesToEmit(CommonModuleCompilationState compilationState)
        {
            // [param]
            if (IsParams)
            {
                yield return(new SynthesizedAttributeData(
                                 (MethodSymbol)DeclaringCompilation.GetWellKnownTypeMember(WellKnownMember.System_ParamArrayAttribute__ctor),
                                 ImmutableArray <TypedConstant> .Empty, ImmutableArray <KeyValuePair <string, TypedConstant> > .Empty));
            }

            // [NotNull]
            if (IsNotNull && Type.IsReferenceType)
            {
                yield return(new SynthesizedAttributeData(
                                 DeclaringCompilation.CoreMethods.Ctors.NotNullAttribute,
                                 ImmutableArray <TypedConstant> .Empty, ImmutableArray <KeyValuePair <string, TypedConstant> > .Empty));
            }

            // [DefaultValue]
            if (this.Initializer is BoundArrayEx arr)
            {
                var typeParameter   = new KeyValuePair <string, TypedConstant>("Type", new TypedConstant(DeclaringCompilation.CoreTypes.DefaultValueType.Symbol, TypedConstantKind.Enum, 1 /*PhpArray*/));
                var namedparameters = ImmutableArray.Create(typeParameter);

                if (arr.Items.Length != 0)
                {
                    try
                    {
                        var byteSymbol      = DeclaringCompilation.GetSpecialType(SpecialType.System_Byte);
                        var serializedValue = Encoding.UTF8.GetBytes(arr.PhpSerializeOrThrow());
                        var p = new KeyValuePair <string, TypedConstant>(
                            "SerializedValue",
                            new TypedConstant(DeclaringCompilation.CreateArrayTypeSymbol(byteSymbol), serializedValue.Select(DeclaringCompilation.CreateTypedConstant).AsImmutable()));

                        namedparameters = namedparameters.Add(p);
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidOperationException($"Cannot construct serialized parameter default value. Routine '{Routine.Name}' in {Routine.ContainingFile.RelativeFilePath}, {ex.Message}.", ex);
                    }
                }

                yield return(new SynthesizedAttributeData(
                                 DeclaringCompilation.CoreMethods.Ctors.DefaultValueAttribute,
                                 ImmutableArray <TypedConstant> .Empty, namedparameters));
            }

            //
            yield break;
        }
コード例 #4
0
        public override ImmutableArray <AttributeData> GetAttributes()
        {
            // attributes from syntax node
            if (this.Syntax.TryGetCustomAttributes(out var attrs))
            {
                // initialize attribute data if necessary:
                attrs
                .OfType <SourceCustomAttribute>()
                .ForEach(x => x.Bind(this, this.ContainingFile));
            }
            else
            {
                attrs = ImmutableArray <AttributeData> .Empty;
            }

            // attributes from PHPDoc
            var phpdoc = this.PHPDocBlock;

            if (phpdoc != null)
            {
                var deprecated = phpdoc.GetElement <PHPDocBlock.DeprecatedTag>();
                if (deprecated != null)
                {
                    // [ObsoleteAttribute(message, false)]
                    attrs = attrs.Add(new SynthesizedAttributeData(
                                          (MethodSymbol)DeclaringCompilation.GetWellKnownTypeMember(WellKnownMember.System_ObsoleteAttribute__ctor),
                                          ImmutableArray.Create(
                                              new TypedConstant(DeclaringCompilation.CoreTypes.String.Symbol, TypedConstantKind.Primitive, deprecated.Version /*NOTE:Version contains the message*/),
                                              new TypedConstant(DeclaringCompilation.CoreTypes.Boolean.Symbol, TypedConstantKind.Primitive, false /*isError*/)),
                                          ImmutableArray <KeyValuePair <string, TypedConstant> > .Empty));
                }

                // ...
            }
            // [NotNullAttribute]
            // ...

            //
            return(base.GetAttributes().AddRange(attrs));
        }
コード例 #5
0
        public override ImmutableArray <AttributeData> GetAttributes()
        {
            var builder = ImmutableArray.CreateBuilder <AttributeData>();

            if (IsPhpHidden)
            {
                // [PhpHiddenAttribute]
                builder.Add(new SynthesizedAttributeData(
                                DeclaringCompilation.CoreMethods.Ctors.PhpHiddenAttribute,
                                ImmutableArray <TypedConstant> .Empty,
                                ImmutableArray <KeyValuePair <string, TypedConstant> > .Empty));
            }

            if (IsEditorBrowsableHidden)
            {
                builder.Add(new SynthesizedAttributeData(
                                (MethodSymbol)DeclaringCompilation.GetWellKnownTypeMember(WellKnownMember.System_ComponentModel_EditorBrowsableAttribute__ctor),
                                ImmutableArray.Create(
                                    new TypedConstant(
                                        DeclaringCompilation.GetWellKnownType(WellKnownType.System_ComponentModel_EditorBrowsableState),
                                        TypedConstantKind.Enum,
                                        System.ComponentModel.EditorBrowsableState.Never)),
                                ImmutableArray <KeyValuePair <string, TypedConstant> > .Empty));
            }

            if (this is SynthesizedPhpCtorSymbol sctor && sctor.IsInitFieldsOnly) // we do it here to avoid allocating new ImmutableArray in derived class
            {
                // [PhpFieldsOnlyCtorAttribute]
                builder.Add(new SynthesizedAttributeData(
                                DeclaringCompilation.CoreMethods.Ctors.PhpFieldsOnlyCtorAttribute,
                                ImmutableArray <TypedConstant> .Empty,
                                ImmutableArray <KeyValuePair <string, TypedConstant> > .Empty));

                // [CompilerGeneratedAttribute]
                builder.Add(DeclaringCompilation.CreateCompilerGeneratedAttribute());
            }

            return(builder.ToImmutable());
        }