Пример #1
0
        public static AttributeData TryCreateDoesNotReturnAttribute(this PhpCompilation compilation)
        {
            var attr = compilation.GetTypeByMetadataName("System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute");

            if (attr == null)
            {
                return(null);
            }

            // [DoesNotReturnAttribute()]
            return(new SynthesizedAttributeData(
                       (MethodSymbol)attr.InstanceConstructors.Single(),
                       ImmutableArray <TypedConstant> .Empty,
                       ImmutableArray <KeyValuePair <string, TypedConstant> > .Empty));
        }
Пример #2
0
        public override INamedTypeSymbol GetTypeSymbol(PhpCompilation compilation)
        {
            var resolved = (NamedTypeSymbol)compilation.GetTypeByMetadataName(MetadataHelpers.ComposeAritySuffixedMetadataName(QualifiedName.ClrName(), Arity));

            if (resolved.IsValidType())
            {
                // TODO: check _typeArguments are bound (no ErrorSymbol)

                var boundTypeArgs = _typeArguments.SelectAsArray(tref => (TypeSymbol)tref.GetTypeSymbol(compilation));

                return(resolved.Construct(boundTypeArgs));
            }
            else
            {
                return(compilation.CoreTypes.Object.Symbol);
            }
        }
Пример #3
0
        /// <summary>
        /// Gets <see cref="TypeSymbol"/> representing this type hint.
        /// </summary>
        /// <returns><see cref="TypeSymbol"/> or <c>null</c> in case the type hint is empty.</returns>
        internal TypeSymbol AsTypeSymbol(PhpCompilation compilation)
        {
            var ct = compilation.CoreTypes;

            if (IsPrimitiveType)
            {
                var qname = new QualifiedName(PrimitiveTypeName.Name);
                if (qname == QualifiedName.Integer || qname == QualifiedName.LongInteger)
                {
                    return(ct.Long);
                }
                if (qname == QualifiedName.String)
                {
                    return(ct.String);
                }
                if (qname == QualifiedName.Boolean)
                {
                    return(ct.Boolean);
                }
                if (qname == QualifiedName.Array)
                {
                    return(ct.PhpArray);
                }
                if (qname == QualifiedName.Callable)
                {
                    return(ct.IPhpCallable);
                }
                if (qname == QualifiedName.Object)
                {
                    return(ct.Object);
                }

                throw new NotImplementedException(qname.ToString() + " AsTypeSymbol");
            }
            else if (IsQualifiedName)
            {
                return((TypeSymbol)compilation.GetTypeByMetadataName(this.QualifiedName.ClrName()) ?? ct.Object);
            }
            else
            {
                return(null);
            }
        }