public SourceParameterSymbol(SourceRoutineSymbol routine, FormalParam syntax, int relindex, PHPDocBlock.ParamTag ptagOpt) { Contract.ThrowIfNull(routine); Contract.ThrowIfNull(syntax); Debug.Assert(relindex >= 0); _routine = routine; _syntax = syntax; _relindex = relindex; _initializer = (syntax.InitValue != null) ? new SemanticsBinder(DeclaringCompilation, routine.ContainingFile.SyntaxTree, locals: null, routine: null, self: routine.ContainingType as SourceTypeSymbol) .BindWholeExpression(syntax.InitValue, BoundAccess.Read) .SingleBoundElement() : null; var phpattrs = _syntax.GetAttributes(); _attributes = phpattrs.Count != 0 ? new SemanticsBinder(DeclaringCompilation, routine.ContainingFile.SyntaxTree, locals: null, routine: routine, self: routine.ContainingType as SourceTypeSymbol) .BindAttributes(phpattrs) : ImmutableArray <AttributeData> .Empty; PHPDoc = ptagOpt; }
/// <summary> /// Gets parameter type from given PHPDoc block. /// </summary> public static PHPDocBlock.ParamTag GetParamTag(PHPDocBlock phpdoc, int paramIndex, string paramName) { PHPDocBlock.ParamTag result = null; if (phpdoc != null) { int pi = 0; var elements = phpdoc.Elements; foreach (var element in elements) { var ptag = element as PHPDocBlock.ParamTag; if (ptag != null) { if (string.IsNullOrEmpty(ptag.VariableName)) { if (pi == paramIndex) { result = ptag; // found @param by index } } else if (string.Equals(ptag.VariableName.Substring(1), paramName, StringComparison.OrdinalIgnoreCase)) { result = ptag; break; } // pi++; } } } return(result); }
public SourceParameterSymbol(SourceRoutineSymbol routine, FormalParam syntax, int index, PHPDocBlock.ParamTag ptagOpt) { Contract.ThrowIfNull(routine); Contract.ThrowIfNull(syntax); Debug.Assert(index >= 0); _routine = routine; _syntax = syntax; _index = index; _ptagOpt = ptagOpt; }
public SourceParameterSymbol(SourceRoutineSymbol routine, FormalParam syntax, int relindex, PHPDocBlock.ParamTag ptagOpt) { Contract.ThrowIfNull(routine); Contract.ThrowIfNull(syntax); Debug.Assert(relindex >= 0); _routine = routine; _syntax = syntax; _relindex = relindex; _ptagOpt = ptagOpt; _initializer = (syntax.InitValue != null) ? new SemanticsBinder(locals: null, diagnostics: DeclaringCompilation.DeclarationDiagnostics).BindWholeExpression(syntax.InitValue, BoundAccess.Read).GetOnlyBoundElement() : null; }
public SourceParameterSymbol(SourceRoutineSymbol routine, FormalParam syntax, int index, PHPDocBlock.ParamTag ptagOpt) { Contract.ThrowIfNull(routine); Contract.ThrowIfNull(syntax); Debug.Assert(index >= 0); _routine = routine; _syntax = syntax; _index = index; _ptagOpt = ptagOpt; _initializer = (syntax.InitValue != null) ? new SemanticsBinder(null).BindExpression(syntax.InitValue, BoundAccess.Read) : null; }
public SourceParameterSymbol(SourceRoutineSymbol routine, FormalParam syntax, int relindex, PHPDocBlock.ParamTag ptagOpt) { Contract.ThrowIfNull(routine); Contract.ThrowIfNull(syntax); Debug.Assert(relindex >= 0); _routine = routine; _syntax = syntax; _relindex = relindex; _ptagOpt = ptagOpt; _initializer = (syntax.InitValue != null) ? new SemanticsBinder(DeclaringCompilation, locals: null, routine: routine, self: routine.ContainingType as SourceTypeSymbol) .BindWholeExpression(syntax.InitValue, BoundAccess.Read) .SingleBoundElement() : null; }
/// <summary> /// Helper method getting parameter type. /// </summary> /// <param name="typeCtx">Routine type context.</param> /// <param name="paramTag">PHPDoc param tag if available.</param> /// <param name="signature">Call signature.</param> /// <param name="call">Call information if called specifically with given context.</param> /// <param name="paramIndex">Parameter index.</param> /// <returns>Expected type of parameter. Cannot be uninitialized.</returns> private static TypeRefMask GetParamType(TypeRefContext /*!*/ typeCtx, PHPDocBlock.ParamTag paramTag, FormalParam syntax, CallInfo call, int paramIndex) { Contract.ThrowIfNull(typeCtx); Debug.Assert(paramIndex >= 0); TypeRefMask result = 0; bool isvariadic = false; bool isalias = false; // lookup actual type hint if (syntax != null) { isvariadic = syntax.IsVariadic; isalias = syntax.PassedByRef || syntax.IsOut; var hint = syntax.TypeHint; if (hint != null) { result = typeCtx.GetTypeMaskFromTypeHint(syntax.TypeHint); if (isvariadic) // PHP 5.6 variadic parameter (...) // TypeHint -> TypeHint[] { result = typeCtx.GetArrayTypeMask(result); } } } if (result.IsUninitialized) { // lookup callInfo result = call.GetParamType(typeCtx, paramIndex); if (result.IsUninitialized) { // lookup PHPDoc if (paramTag != null && paramTag.TypeNamesArray.Length != 0) { result = PHPDoc.GetTypeMask(typeCtx, paramTag.TypeNamesArray); } if (result.IsUninitialized) { // NOTE: if still unknown, we can use type of the FormalParam.InitValue as Hint result = TypeRefMask.AnyType; } } // PHP 5.6, variadic parameter (...) is always of type array, // if specified else, user meant type of its elements if (isvariadic && !typeCtx.IsArray(result)) { result = typeCtx.GetArrayTypeMask(result); // hint -> hint[] } } // result.IsRef = isalias; // Debug.Assert(!result.IsUninitialized); return(result); }