public EmbeddedParameter( EmbeddedTypesManager.CommonEmbeddedMember containingPropertyOrMethod, ParameterSymbolAdapter underlyingParameter ) : base(containingPropertyOrMethod, underlyingParameter) { Debug.Assert(underlyingParameter.AdaptedParameterSymbol.IsDefinition); }
private SubstitutedParameterSymbol(Symbol containingSymbol, TypeMap map, ParameterSymbol originalParameter) : base(originalParameter) { Debug.Assert(originalParameter.IsDefinition); _containingSymbol = containingSymbol; _mapOrType = map; }
internal DisplayClassInstanceFromParameter(ParameterSymbol parameter) { Debug.Assert((object)parameter != null); Debug.Assert(parameter.Name.EndsWith("this", StringComparison.Ordinal) || GeneratedNames.GetKind(parameter.Name) == GeneratedNameKind.TransparentIdentifier); this.Parameter = parameter; }
internal static BoundNode Rewrite( ParameterSymbol targetMethodThisParameter, Conversions conversions, ImmutableDictionary<string, DisplayClassVariable> displayClassVariables, BoundNode node, DiagnosticBag diagnostics) { var rewriter = new CapturedVariableRewriter(targetMethodThisParameter, conversions, displayClassVariables, diagnostics); return rewriter.Visit(node); }
private CapturedVariableRewriter( ParameterSymbol targetMethodThisParameter, Conversions conversions, ImmutableDictionary<string, DisplayClassVariable> displayClassVariables, DiagnosticBag diagnostics) { _targetMethodThisParameter = targetMethodThisParameter; _conversions = conversions; _displayClassVariables = displayClassVariables; _diagnostics = diagnostics; }
internal override bool TryGetThisParameter(out ParameterSymbol thisParameter) { Debug.Assert(!IsStatic); if ((object)_lazyThisParameter == null) { Interlocked.CompareExchange(ref _lazyThisParameter, new ThisParameterSymbol(this), null); } thisParameter = _lazyThisParameter; return true; }
internal override bool TryGetThisParameter(out ParameterSymbol thisParameter) { if (IsStatic) { thisParameter = null; return true; } if ((object)lazyThisParameter == null) { Interlocked.CompareExchange(ref lazyThisParameter, new ThisParameterSymbol(this), null); } thisParameter = lazyThisParameter; return true; }
internal AnonymousTypeConstructorSymbol(NamedTypeSymbol container, ImmutableArray<AnonymousTypePropertySymbol> properties) : base(container, WellKnownMemberNames.InstanceConstructorName) { // Create constructor parameters int fieldsCount = properties.Length; if (fieldsCount > 0) { ParameterSymbol[] paramsArr = new ParameterSymbol[fieldsCount]; for (int index = 0; index < fieldsCount; index++) { PropertySymbol property = properties[index]; paramsArr[index] = new SynthesizedParameterSymbol(this, property.Type, index, RefKind.None, property.Name); } _parameters = paramsArr.AsImmutableOrNull(); } else { _parameters = ImmutableArray<ParameterSymbol>.Empty; } }
internal static void VerifyParamArrayAttribute(ParameterSymbol parameter, SourceModuleSymbol module, bool expected = true, OutputKind outputKind = OutputKind.ConsoleApplication) { Assert.Equal(expected, parameter.IsParams); var emitModule = new PEAssemblyBuilder(module.ContainingSourceAssembly, null, outputKind, GetDefaultModulePropertiesForSerialization(), SpecializedCollections.EmptyEnumerable<ResourceDescription>()); var paramArrayAttributeCtor = (MethodSymbol)emitModule.Compilation.GetWellKnownTypeMember(WellKnownMember.System_ParamArrayAttribute__ctor); bool found = false; var context = new EmitContext(emitModule, null, new DiagnosticBag()); foreach (Microsoft.Cci.ICustomAttribute attr in parameter.GetSynthesizedAttributes()) { if (paramArrayAttributeCtor == (MethodSymbol)attr.Constructor(context)) { Assert.False(found, "Multiple ParamArrayAttribute"); found = true; } } Assert.Equal(expected, found); context.Diagnostics.Verify(); }
public ParameterTypeInformation(ParameterSymbol underlyingParameter) { Debug.Assert((object)underlyingParameter != null); this.UnderlyingParameter = underlyingParameter; }
private static TypedConstant GetParamArrayArgument(ParameterSymbol parameter, ImmutableArray<TypedConstant> constructorArgsArray, int argumentsCount, int argsConsumedCount, Conversions conversions) { Debug.Assert(argsConsumedCount <= argumentsCount); int paramArrayArgCount = argumentsCount - argsConsumedCount; if (paramArrayArgCount == 0) { return new TypedConstant(parameter.Type, ImmutableArray<TypedConstant>.Empty); } // If there's exactly one argument and it's an array of an appropriate type, then just return it. if (paramArrayArgCount == 1 && constructorArgsArray[argsConsumedCount].Kind == TypedConstantKind.Array) { TypeSymbol argumentType = (TypeSymbol)constructorArgsArray[argsConsumedCount].Type; // Easy out (i.e. don't both classifying conversion). if (argumentType == parameter.Type) { return constructorArgsArray[argsConsumedCount]; } HashSet<DiagnosticInfo> useSiteDiagnostics = null; // ignoring, since already bound argument and parameter Conversion conversion = conversions.ClassifyConversion(argumentType, parameter.Type, ref useSiteDiagnostics, builtinOnly: true); // NOTE: Won't always succeed, even though we've performed overload resolution. // For example, passing int[] to params object[] actually treats the int[] as an element of the object[]. if (conversion.IsValid && conversion.Kind == ConversionKind.ImplicitReference) { return constructorArgsArray[argsConsumedCount]; } } Debug.Assert(!constructorArgsArray.IsDefault); Debug.Assert(argsConsumedCount <= constructorArgsArray.Length); var values = new TypedConstant[paramArrayArgCount]; for (int i = 0; i < paramArrayArgCount; i++) { values[i] = constructorArgsArray[argsConsumedCount++]; } return new TypedConstant(parameter.Type, values.AsImmutableOrNull()); }
private TypedConstant GetMatchingNamedOrOptionalConstructorArgument( out int matchingArgumentIndex, ImmutableArray<TypedConstant> constructorArgsArray, ImmutableArray<string> constructorArgumentNamesOpt, ParameterSymbol parameter, int startIndex, int argumentsCount, ref int argsConsumedCount, AttributeSyntax syntax, DiagnosticBag diagnostics) { int index = GetMatchingNamedConstructorArgumentIndex(parameter.Name, constructorArgumentNamesOpt, startIndex, argumentsCount); if (index < argumentsCount) { // found a matching named argument Debug.Assert(index >= startIndex); // increment argsConsumedCount argsConsumedCount++; matchingArgumentIndex = index; return constructorArgsArray[index]; } else { matchingArgumentIndex = -1; return GetDefaultValueArgument(parameter, syntax, diagnostics); } }
protected override void EnterParameter(ParameterSymbol parameter) { // parameters are NOT intitially assigned here - if that is a problem, then // the parameters must be captured. GetOrCreateSlot(parameter); }
protected RetargetingParameterSymbol(ParameterSymbol underlyingParameter) { Debug.Assert(!(underlyingParameter is RetargetingParameterSymbol)); this.underlyingParameter = underlyingParameter; }
public RetargetingMethodParameterSymbol(RetargetingMethodSymbol retargetingMethod, ParameterSymbol underlyingParameter) : base(underlyingParameter) { Debug.Assert((object)retargetingMethod != null); this.retargetingMethod = retargetingMethod; }
public BoundParameter Parameter(ParameterSymbol p) { return new BoundParameter(Syntax, p, p.Type) { WasCompilerGenerated = true }; }
protected WrappedParameterSymbol(ParameterSymbol underlyingParameter) { Debug.Assert((object)underlyingParameter != null); this._underlyingParameter = underlyingParameter; }
internal NativeIntegerParameterSymbol(NativeIntegerTypeSymbol containingType, NativeIntegerMethodSymbol container, ParameterSymbol underlyingParameter) : base(underlyingParameter) { Debug.Assert(container != null); _containingType = containingType; _container = container; NativeIntegerTypeSymbol.VerifyEquality(this, underlyingParameter); }
internal override void GenerateMethodBody(TypeCompilationState compilationState, DiagnosticBag diagnostics) { SyntheticBoundNodeFactory F = new SyntheticBoundNodeFactory(this, this.GetNonNullSyntaxNode(), compilationState, diagnostics); F.CurrentMethod = this; try { LocalSymbol i = F.SynthesizedLocal(F.SpecialType(SpecialType.System_Int32), "i"); LocalSymbol hashCode = F.SynthesizedLocal(F.SpecialType(SpecialType.System_UInt32), "hashCode"); LabelSymbol again = F.GenerateLabel("again"); LabelSymbol start = F.GenerateLabel("start"); ParameterSymbol text = this.Parameters[0]; // This method should be kept consistent with ComputeStringHash //uint hashCode = 0; //if (text != null) //{ // hashCode = unchecked((uint)2166136261); // int i = 0; // goto start; //again: // hashCode = (text[i] ^ hashCode) * 16777619; // i = i + 1; //start: // if (i < text.Length) // goto again; //} //return hashCode; var body = F.Block( ImmutableArray.Create <LocalSymbol>(hashCode, i), F.If( F.Binary(BinaryOperatorKind.ObjectNotEqual, F.SpecialType(SpecialType.System_Boolean), F.Parameter(text), F.Null(text.Type)), F.Block( F.Assignment(F.Local(hashCode), F.Literal((uint)2166136261)), F.Assignment(F.Local(i), F.Literal(0)), F.Goto(start), F.Label(again), F.Assignment( F.Local(hashCode), F.Binary(BinaryOperatorKind.Multiplication, hashCode.Type, F.Binary(BinaryOperatorKind.Xor, hashCode.Type, F.Convert(hashCode.Type, F.Call( F.Parameter(text), (MethodSymbol)F.SpecialMember(SpecialMember.System_String__Chars), F.Local(i)), ConversionKind.ImplicitNumeric), F.Local(hashCode)), F.Literal(16777619))), F.Assignment( F.Local(i), F.Binary(BinaryOperatorKind.Addition, i.Type, F.Local(i), F.Literal(1))), F.Label(start), F.If( F.Binary(BinaryOperatorKind.LessThan, F.SpecialType(SpecialType.System_Boolean), F.Local(i), F.Call(F.Parameter(text), (MethodSymbol)F.SpecialMember(SpecialMember.System_String__Length))), F.Goto(again)))), F.Return(F.Local(hashCode)) ); // NOTE: we created this block in its most-lowered form, so analysis is unnecessary F.CloseMethod(body); } catch (SyntheticBoundNodeFactory.MissingPredefinedMember ex) { diagnostics.Add(ex.Diagnostic); F.CloseMethod(F.ThrowNull()); } }
static Location getLocation(ParameterSymbol parameter, Location location) => parameter.Locations.FirstOrDefault() ?? location;
internal override bool TryGetThisParameter(out ParameterSymbol thisParameter) { // Lambda symbols have no "this" parameter thisParameter = null; return(true); }
protected override void ReportUnassignedOutParameter(ParameterSymbol parameter, CSharpSyntaxNode node, Location location) { if (!dataFlowsOut.Contains(parameter) && (node == null || node is ReturnStatementSyntax)) { dataFlowsOut.Add(parameter); } base.ReportUnassignedOutParameter(parameter, node, location); }
internal SubstitutedParameterSymbol(PropertySymbol containingSymbol, TypeMap map, ParameterSymbol originalParameter) : this((Symbol)containingSymbol, map, originalParameter) { }
/// <returns> /// True if this <see cref="MethodSymbol"/> type supports retrieving the this parameter /// and false otherwise. Note that a return value of true does not guarantee a non-null /// <paramref name="thisParameter"/> (e.g. fails for static methods). /// </returns> internal virtual bool TryGetThisParameter(out ParameterSymbol thisParameter) { thisParameter = null; return(false); }
private void AppendParameterAndMethod( ArrayBuilder<LocalAndMethod> localBuilder, ArrayBuilder<MethodSymbol> methodBuilder, ParameterSymbol parameter, EENamedTypeSymbol container, int parameterIndex) { // Note: The native EE doesn't do this, but if we don't escape keyword identifiers, // the ResultProvider needs to be able to disambiguate cases like "this" and "@this", // which it can't do correctly without semantic information. var name = SyntaxHelpers.EscapeKeywordIdentifiers(parameter.Name); var methodName = GetNextMethodName(methodBuilder); var method = this.GetParameterMethod(container, methodName, name, parameterIndex); localBuilder.Add(new CSharpLocalAndMethod(name, name, method, DkmClrCompilationResultFlags.None)); methodBuilder.Add(method); }
public virtual void VisitParameter(ParameterSymbol symbol) { DefaultVisit(symbol); }
internal override bool TryGetThisParameter(out ParameterSymbol thisParameter) { // Lambda symbols have no "this" parameter thisParameter = null; return true; }
public RetargetingPropertyParameterSymbol(RetargetingPropertySymbol retargetingProperty, ParameterSymbol underlyingParameter) : base(underlyingParameter) { Debug.Assert((object)retargetingProperty != null); this.retargetingProperty = retargetingProperty; }
private static ParameterSymbol CopyParameter(ParameterSymbol parameter, MethodSymbol owner) { return new SynthesizedParameterSymbol( owner, parameter.Type, parameter.Ordinal, parameter.RefKind, GeneratedNames.LambdaCopyParameterName(parameter)); // Make sure nothing binds to this. }
private static bool CanBeOptional(ParameterSymbol parameter, bool isMethodGroupConversion) { // NOTE: Section 6.6 will be slightly updated: // // - The candidate methods considered are only those methods that are applicable in their // normal form (§7.5.3.1), and do not omit any optional parameters. Thus, candidate methods // are ignored if they are applicable only in their expanded form, or if one or more of their // optional parameters do not have a corresponding parameter in the targeted delegate type. // // Therefore, no parameters are optional when performing method group conversion. Alternatively, // we could eliminate methods based on the number of arguments, but then we wouldn't be able to // fall back on them if no other candidates were available. var refKind = parameter.RefKind; return !isMethodGroupConversion && parameter.IsOptional && (refKind == RefKind.None || (refKind == RefKind.Ref && parameter.ContainingSymbol.ContainingType.IsComImport)); }
internal override bool TryGetThisParameter(out ParameterSymbol thisParameter) { thisParameter = null; return(true); }
private ImmutableArray<ParameterSymbol> RetargetParameters() { var list = this.underlyingMethod.Parameters; int count = list.Length; if (count == 0) { return ImmutableArray<ParameterSymbol>.Empty; } else { ParameterSymbol[] parameters = new ParameterSymbol[count]; for (int i = 0; i < count; i++) { parameters[i] = new RetargetingMethodParameterSymbol(this, list[i]); } return parameters.AsImmutableOrNull(); } }
internal sealed override bool TryGetThisParameter(out ParameterSymbol thisParameter) { // Required in EE scenarios. Specifically, the EE binds in the context of a // substituted method, whereas the core compiler always binds within the // context of an original definition. // There should never be any reason to call this in normal compilation // scenarios, but the behavior should be sensible if it does occur. ParameterSymbol originalThisParameter; if (!originalDefinition.TryGetThisParameter(out originalThisParameter)) { thisParameter = null; return false; } thisParameter = (object)originalThisParameter != null ? new ThisParameterSymbol(this) : null; return true; }
private TypedConstant GetDefaultValueArgument(ParameterSymbol parameter, AttributeSyntax syntax, DiagnosticBag diagnostics) { var parameterType = parameter.Type; ConstantValue defaultConstantValue = parameter.IsOptional ? parameter.ExplicitDefaultConstantValue : ConstantValue.NotAvailable; TypedConstantKind kind; object defaultValue = null; if (!IsEarlyAttributeBinder && parameter.IsCallerLineNumber) { int line = syntax.SyntaxTree.GetDisplayLineNumber(syntax.Name.Span); kind = TypedConstantKind.Primitive; HashSet<DiagnosticInfo> useSiteDiagnostics = null; var conversion = Conversions.GetCallerLineNumberConversion(parameterType, ref useSiteDiagnostics); diagnostics.Add(syntax, useSiteDiagnostics); if (conversion.IsNumeric || conversion.IsConstantExpression) { // DoUncheckedConversion() keeps "single" floats as doubles internally to maintain higher // precision, so make sure they get cast to floats here. defaultValue = (parameterType.SpecialType == SpecialType.System_Single) ? (float)line : Binder.DoUncheckedConversion(parameterType.SpecialType, ConstantValue.Create(line)); } else { // Boxing or identity conversion: parameterType = Compilation.GetSpecialType(SpecialType.System_Int32); defaultValue = line; } } else if (!IsEarlyAttributeBinder && parameter.IsCallerFilePath) { parameterType = Compilation.GetSpecialType(SpecialType.System_String); kind = TypedConstantKind.Primitive; defaultValue = syntax.SyntaxTree.GetDisplayPath(syntax.Name.Span, Compilation.Options.SourceReferenceResolver); } else if (!IsEarlyAttributeBinder && parameter.IsCallerMemberName && (object)((ContextualAttributeBinder)this).AttributedMember != null) { parameterType = Compilation.GetSpecialType(SpecialType.System_String); kind = TypedConstantKind.Primitive; defaultValue = ((ContextualAttributeBinder)this).AttributedMember.GetMemberCallerName(); } else if (defaultConstantValue == ConstantValue.NotAvailable) { // There is no constant value given for the parameter in source/metadata. // For example, the attribute constructor with signature: M([Optional] int x), has no default value from syntax or attributes. // Default value for these cases is "default(parameterType)". // Optional parameter of System.Object type is treated specially though. // Native compiler treats "M([Optional] object x)" equivalent to "M(object x)" for attributes if parameter type is System.Object. // We generate a better diagnostic for this case by treating "x" in the above case as optional, but generating CS7067 instead. if (parameterType.SpecialType == SpecialType.System_Object) { // CS7067: Attribute constructor parameter '{0}' is optional, but no default parameter value was specified. diagnostics.Add(ErrorCode.ERR_BadAttributeParamDefaultArgument, syntax.Name.Location, parameter.Name); kind = TypedConstantKind.Error; } else { kind = TypedConstant.GetTypedConstantKind(parameterType, this.Compilation); Debug.Assert(kind != TypedConstantKind.Error); defaultConstantValue = parameterType.GetDefaultValue(); if (defaultConstantValue != null) { defaultValue = defaultConstantValue.Value; } } } else if (defaultConstantValue.IsBad) { // Constant value through syntax had errors, don't generate cascading diagnostics. kind = TypedConstantKind.Error; } else if (parameterType.SpecialType == SpecialType.System_Object && !defaultConstantValue.IsNull) { // error CS1763: '{0}' is of type '{1}'. A default parameter value of a reference type other than string can only be initialized with null diagnostics.Add(ErrorCode.ERR_NotNullRefDefaultParameter, syntax.Location, parameter.Name, parameterType); kind = TypedConstantKind.Error; } else { kind = TypedConstant.GetTypedConstantKind(parameterType, this.Compilation); Debug.Assert(kind != TypedConstantKind.Error); defaultValue = defaultConstantValue.Value; } if (kind == TypedConstantKind.Array) { Debug.Assert(defaultValue == null); return new TypedConstant(parameterType, default(ImmutableArray<TypedConstant>)); } else { return new TypedConstant(parameterType, kind, defaultValue); } }
internal static string LambdaCopyParameterName(ParameterSymbol sourceParameter) { return "<" + sourceParameter.Name + ">"; }
internal InvokeMethod(SynthesizedDelegateSymbol containingType, BitVector byRefParameters, TypeSymbol voidReturnTypeOpt) { var typeParams = containingType.TypeParameters; _containingType = containingType; // if we are given Void type the method returns Void, otherwise its return type is the last type parameter of the delegate: _returnType = voidReturnTypeOpt ?? typeParams.Last(); var parameters = new ParameterSymbol[typeParams.Length - ((object)voidReturnTypeOpt != null ? 0 : 1)]; for (int i = 0; i < parameters.Length; i++) { // we don't need to distinguish between out and ref since this is an internal synthesized symbol: var refKind = !byRefParameters.IsNull && byRefParameters[i] ? RefKind.Ref : RefKind.None; parameters[i] = SynthesizedParameterSymbol.Create(this, typeParams[i], i, refKind); } _parameters = parameters.AsImmutableOrNull(); }
/// <summary> /// Creates a SemanticModel for a parameter default value. /// </summary> internal static InitializerSemanticModel Create(CSharpCompilation compilation, ParameterSyntax syntax, ParameterSymbol parameterSymbol, Binder rootBinder) { return new InitializerSemanticModel(compilation, syntax, parameterSymbol, rootBinder); }
private bool FlowsOut(ParameterSymbol param) { return (object)param != null && param.RefKind != RefKind.None && !param.IsImplicitlyDeclared && !RegionContains(param.Locations[0].SourceSpan); }
private static ParameterSymbol CopyParameter(ParameterSymbol parameter, MethodSymbol owner) { return new SynthesizedParameterSymbol( owner, parameter.Type, parameter.Ordinal, parameter.RefKind, string.Empty); // Make sure nothing binds to this. }
/// <remarks> /// This method should be kept consistent with <see cref="SynthesizedStringSwitchHashMethod.ComputeStringHash"/> /// </remarks> internal override void GenerateMethodBody(TypeCompilationState compilationState, BindingDiagnosticBag diagnostics) { SyntheticBoundNodeFactory F = new SyntheticBoundNodeFactory(this, this.GetNonNullSyntaxNode(), compilationState, diagnostics); F.CurrentFunction = this; try { ParameterSymbol text = this.Parameters[0]; NamedTypeSymbol spanChar = F.WellKnownType(_isReadOnlySpan ? WellKnownType.System_ReadOnlySpan_T : WellKnownType.System_Span_T) .Construct(F.SpecialType(SpecialType.System_Char)); LocalSymbol i = F.SynthesizedLocal(F.SpecialType(SpecialType.System_Int32)); LocalSymbol hashCode = F.SynthesizedLocal(F.SpecialType(SpecialType.System_UInt32)); LabelSymbol again = F.GenerateLabel("again"); LabelSymbol start = F.GenerateLabel("start"); // uint hashCode = unchecked((uint)2166136261); // int i = 0; // goto start; //again: // hashCode = (text[i] ^ hashCode) * 16777619; // i = i + 1; //start: // if (i < text.Length) // goto again; // return hashCode; var body = F.Block( ImmutableArray.Create <LocalSymbol>(hashCode, i), F.Assignment(F.Local(hashCode), F.Literal((uint)2166136261)), F.Assignment(F.Local(i), F.Literal(0)), F.Goto(start), F.Label(again), F.Assignment( F.Local(hashCode), F.Binary(BinaryOperatorKind.Multiplication, hashCode.Type, F.Binary(BinaryOperatorKind.Xor, hashCode.Type, F.Convert(hashCode.Type, F.Call( F.Parameter(text), F.WellKnownMethod(_isReadOnlySpan ? WellKnownMember.System_ReadOnlySpan_T__get_Item : WellKnownMember.System_Span_T__get_Item).AsMember(spanChar), F.Local(i)), Conversion.ImplicitNumeric), F.Local(hashCode)), F.Literal(16777619))), F.Assignment( F.Local(i), F.Binary(BinaryOperatorKind.Addition, i.Type, F.Local(i), F.Literal(1))), F.Label(start), F.If( F.Binary(BinaryOperatorKind.LessThan, F.SpecialType(SpecialType.System_Boolean), F.Local(i), F.Call( F.Parameter(text), F.WellKnownMethod(_isReadOnlySpan ? WellKnownMember.System_ReadOnlySpan_T__get_Length : WellKnownMember.System_Span_T__get_Length).AsMember(spanChar))), F.Goto(again)), F.Return(F.Local(hashCode)) ); // NOTE: we created this block in its most-lowered form, so analysis is unnecessary F.CloseMethod(body); } catch (SyntheticBoundNodeFactory.MissingPredefinedMember ex) { diagnostics.Add(ex.Diagnostic); F.CloseMethod(F.ThrowNull()); } }
public ReducedExtensionMethodParameterSymbol(ReducedExtensionMethodSymbol containingMethod, ParameterSymbol underlyingParameter) : base(underlyingParameter) { Debug.Assert(underlyingParameter.Ordinal > 0); _containingMethod = containingMethod; }