private ArrayTypeSymbol SubstituteArrayType(ArrayTypeSymbol t) { var oldElement = new TypeWithModifiers(t.ElementType, t.CustomModifiers); TypeWithModifiers element = oldElement.SubstituteType(this); if (element == oldElement) { return t; } if (t.IsSZArray) { ImmutableArray<NamedTypeSymbol> interfaces = t.Interfaces; //.InterfacesNoUseSiteDiagnostics(); Debug.Assert(0 <= interfaces.Length && interfaces.Length <= 2); if (interfaces.Length == 1) { Debug.Assert(interfaces[0] is NamedTypeSymbol); // IList<T> interfaces = ImmutableArray.Create<NamedTypeSymbol>((NamedTypeSymbol)SubstituteType(interfaces[0]).AsTypeSymbolOnly()); } else if (interfaces.Length == 2) { Debug.Assert(interfaces[0] is NamedTypeSymbol); // IList<T> interfaces = ImmutableArray.Create<NamedTypeSymbol>((NamedTypeSymbol)SubstituteType(interfaces[0]).AsTypeSymbolOnly(), (NamedTypeSymbol)SubstituteType(interfaces[1]).AsTypeSymbolOnly()); } else if (interfaces.Length != 0) { throw ExceptionUtilities.Unreachable; } return ArrayTypeSymbol.CreateSZArray( element.Type, t.BaseType, //.BaseTypeNoUseSiteDiagnostics, interfaces, element.CustomModifiers); } return ArrayTypeSymbol.CreateMDArray( element.Type, t.Rank, t.Sizes, t.LowerBounds, t.BaseType, //.BaseTypeNoUseSiteDiagnostics, element.CustomModifiers); }
internal static Cci.IArrayTypeReference Translate(ArrayTypeSymbol symbol) { return symbol; }
internal bool HasSameShapeAs(ArrayTypeSymbol other) { return(Rank == other.Rank && IsSZArray == other.IsSZArray); }
internal bool Equals(ArrayTypeSymbol other) { return(Equals(other, false, false)); }
TypeSymbol ResolveType() { if (IsThis) { // <this> parameter if (_routine is SourceGlobalMethodSymbol) { // "AnyType" in case of $this in global scope return(DeclaringCompilation.CoreTypes.PhpValue); } return(ContainingType); } //return DeclaringCompilation.GetTypeFromTypeRef(_routine, _routine.ControlFlowGraph.GetParamTypeMask(this)); // determine parameter type from the signature: // aliased parameter: if (_syntax.IsOut || _syntax.PassedByRef) { if (_syntax.IsVariadic) { // PhpAlias[] return(ArrayTypeSymbol.CreateSZArray(this.ContainingAssembly, DeclaringCompilation.CoreTypes.PhpAlias)); } else { // PhpAlias return(DeclaringCompilation.CoreTypes.PhpAlias); } } // 1. specified type hint var typeHint = _syntax.TypeHint; if (typeHint is ReservedTypeRef rtref) { // workaround for https://github.com/peachpiecompiler/peachpie/issues/281 // remove once it gets updated in parser if (rtref.Type == ReservedTypeRef.ReservedType.self) { return(_routine.ContainingType); // self } } var result = DeclaringCompilation.GetTypeFromTypeRef(typeHint, _routine.ContainingType as SourceTypeSymbol, nullable: DefaultsToNull); // 2. optionally type specified in PHPDoc if (result == null && _ptagOpt != null && _ptagOpt.TypeNamesArray.Length != 0 && (DeclaringCompilation.Options.PhpDocTypes & PhpDocTypes.ParameterTypes) != 0) { var typectx = _routine.TypeRefContext; var tmask = FlowAnalysis.PHPDoc.GetTypeMask(typectx, _ptagOpt.TypeNamesArray, _routine.GetNamingContext()); if (!tmask.IsVoid && !tmask.IsAnyType) { result = DeclaringCompilation.GetTypeFromTypeRef(typectx, tmask); } } // 3 default: if (result == null) { // TODO: use type from overriden method result = DeclaringCompilation.CoreTypes.PhpValue; } // variadic (result[]) if (_syntax.IsVariadic) { result = ArrayTypeSymbol.CreateSZArray(this.ContainingAssembly, result); } // return(result); }