internal static ImmutableArray<SyntaxNode> GetDeclarators(SourceMethodSymbol method) { var builder = ArrayBuilder<SyntaxNode>.GetInstance(); var visitor = new LocalVariableDeclaratorsCollector(builder); visitor.Visit(method.BodySyntax); return builder.ToImmutableAndFree(); }
internal static BoundBlock Rewrite(SourceMethodSymbol sourceMethodSymbol, MethodContractSyntax contract, BoundBlock body, TypeCompilationState compilationState, DiagnosticBag diagsForCurrentMethod) { var binder = compilationState.Compilation.GetBinderFactory(sourceMethodSymbol.SyntaxTree) .GetBinder(body.Syntax); SyntheticBoundNodeFactory factory = new SyntheticBoundNodeFactory(sourceMethodSymbol, sourceMethodSymbol.SyntaxNode, compilationState, diagsForCurrentMethod); var contractType = compilationState.Compilation.GetTypeByReflectionType(typeof(System.Diagnostics.Contracts.Contract), diagsForCurrentMethod); var contractStatements = ArrayBuilder<BoundStatement>.GetInstance(contract.Requires.Count); foreach (var requires in contract.Requires) { var condition = binder.BindExpression(requires.Condition, diagsForCurrentMethod); var methodCall = factory.StaticCall(contractType, "Requires", condition); var statement = factory.ExpressionStatement(methodCall); contractStatements.Add(statement); } foreach (var requires in contract.Ensures) { var condition = binder.BindExpression(requires.Condition, diagsForCurrentMethod); var methodCall = factory.StaticCall(contractType, "Ensures", condition); var statement = factory.ExpressionStatement(methodCall); contractStatements.Add(statement); } return body.Update(body.Locals, body.Statements.InsertRange(0, contractStatements.ToImmutableAndFree())); }
// NOTE: hasByRefBeforeCustomModifiers is always false since RefKind is always None. public SynthesizedAccessorValueParameterSymbol(SourceMethodSymbol accessor, TypeSymbol paramType, int ordinal, ImmutableArray<CustomModifier> customModifiers) : base(accessor, ordinal, paramType, RefKind.None, customModifiers, false, ParameterSymbol.ValueParameterName, accessor.Locations, syntaxRef: null, defaultSyntaxValue: ConstantValue.Unset, // the default value can be set via [param: DefaultParameterValue] applied on the accessor isParams: false, isExtensionMethodThis: false) { }
// NOTE: hasByRefBeforeCustomModifiers is always false since RefKind is always None. public SynthesizedAccessorValueParameterSymbol(SourceMethodSymbol accessor, TypeSymbol paramType, int ordinal, ImmutableArray <CustomModifier> customModifiers) : base(accessor, ordinal, paramType, RefKind.None, customModifiers, false, ParameterSymbol.ValueParameterName, accessor.Locations, syntaxRef: null, defaultSyntaxValue: ConstantValue.Unset, // the default value can be set via [param: DefaultParameterValue] applied on the accessor isParams: false, isExtensionMethodThis: false) { }
public SourceMethodTypeParameterSymbol( SourceMethodSymbol owner, string name, int ordinal, ImmutableArray <Location> locations, ImmutableArray <SyntaxReference> syntaxRefs ) : base(name, ordinal, locations, syntaxRefs) { _owner = owner; }
private AsyncRewriter( BoundStatement body, SourceMethodSymbol method, int methodOrdinal, AsyncStateMachine stateMachineType, VariableSlotAllocator slotAllocatorOpt, TypeCompilationState compilationState, DiagnosticBag diagnostics) : base(body, method, stateMachineType, slotAllocatorOpt, compilationState, diagnostics) { try { _constructedSuccessfully = AsyncMethodBuilderMemberCollection.TryCreate(F, method, this.stateMachineType.TypeMap, out _asyncMethodBuilderMemberCollection); } catch (SyntheticBoundNodeFactory.MissingPredefinedMember ex) { diagnostics.Add(ex.Diagnostic); _constructedSuccessfully = false; } _methodOrdinal = methodOrdinal; _ignoreAccessibility = compilationState.ModuleBuilderOpt.IgnoreAccessibility; }
private static void GenerateExternalMethodWarnings(SourceMethodSymbol methodSymbol, DiagnosticBag diagnostics) { if (methodSymbol.GetAttributes().IsEmpty && !methodSymbol.ContainingType.IsComImport) { // external method with no attributes var errorCode = (methodSymbol.MethodKind == MethodKind.Constructor || methodSymbol.MethodKind == MethodKind.StaticConstructor) ? ErrorCode.WRN_ExternCtorNoImplementation : ErrorCode.WRN_ExternMethodNoImplementation; diagnostics.Add(errorCode, methodSymbol.Locations[0], methodSymbol); } }
/// <summary> /// Construct a body for an auto-property accessor (updating or returning the backing field). /// </summary> internal static BoundBlock ConstructAutoPropertyAccessorBody(SourceMethodSymbol accessor) { Debug.Assert(accessor.MethodKind == MethodKind.PropertyGet || accessor.MethodKind == MethodKind.PropertySet); var property = (SourcePropertySymbol)accessor.AssociatedSymbol; CSharpSyntaxNode syntax = property.CSharpSyntaxNode; BoundExpression thisReference = null; if (!accessor.IsStatic) { var thisSymbol = accessor.ThisParameter; thisReference = new BoundThisReference(syntax, thisSymbol.Type) { WasCompilerGenerated = true }; } var field = property.BackingField; var fieldAccess = new BoundFieldAccess(syntax, thisReference, field, ConstantValue.NotAvailable) { WasCompilerGenerated = true }; BoundStatement statement; if (accessor.MethodKind == MethodKind.PropertyGet) { statement = new BoundReturnStatement(syntax, fieldAccess) { WasCompilerGenerated = true }; } else { Debug.Assert(accessor.MethodKind == MethodKind.PropertySet); var parameter = accessor.Parameters[0]; statement = new BoundExpressionStatement( syntax, new BoundAssignmentOperator( syntax, fieldAccess, new BoundParameter(syntax, parameter) { WasCompilerGenerated = true }, property.Type) { WasCompilerGenerated = true }) { WasCompilerGenerated = true }; } statement = new BoundSequencePoint(accessor.SyntaxNode, statement) { WasCompilerGenerated = true }; return new BoundBlock(syntax, ImmutableArray<LocalSymbol>.Empty, ImmutableArray.Create<BoundStatement>(statement)) { WasCompilerGenerated = true }; }
private Binder AddInitializersLocalsScope(Binder outer, TypeDeclarationSyntax typeDecl, SourceMethodSymbol constructorSymbol) { if ((object)((SourceMemberContainerTypeSymbol)constructorSymbol.ContainingSymbol).PrimaryCtor == constructorSymbol) { foreach (FieldInitializers siblingInitializers in ((SourceMemberContainerTypeSymbol)constructorSymbol.ContainingType).InstanceInitializers) { if (siblingInitializers.TypeDeclarationSyntax != null && siblingInitializers.TypeDeclarationSyntax.SyntaxTree == this.syntaxTree && siblingInitializers.TypeDeclarationSyntax.GetSyntax() == typeDecl) { FieldInitializersInfo initializersInfo = GetFieldInitializersInfo(instanceInitializersInfo, siblingInitializers); if (!initializersInfo.Locals.IsDefaultOrEmpty) { return new SimpleLocalScopeBinder(initializersInfo.Locals, outer); } return outer; } } } return outer; }
internal sealed override void SetReplacedBy(Symbol replacedBy) { this._replacedBy = (SourceMethodSymbol)replacedBy; }
internal sealed override void SetReplaced(Symbol replaced) { this._replaced = (SourceMethodSymbol)replaced; }