internal SynthesizedLambdaMethod(NamedTypeSymbol containingType, MethodSymbol topLevelMethod, BoundLambda node, bool isStatic, TypeCompilationState compilationState) : base(containingType, node.Symbol, null, node.SyntaxTree.GetReference(node.Body.Syntax), node.Syntax.GetLocation(), GeneratedNames.MakeLambdaMethodName(topLevelMethod.Name, compilationState.GenerateTempNumber()), (containingType is LambdaFrame ? DeclarationModifiers.Internal : DeclarationModifiers.Private) | (isStatic ? DeclarationModifiers.Static : 0) | (node.Symbol.IsAsync ? DeclarationModifiers.Async : 0)) { TypeMap typeMap; ImmutableArray<TypeParameterSymbol> typeParameters; LambdaFrame lambdaFrame; if (!topLevelMethod.IsGenericMethod) { typeMap = TypeMap.Empty; typeParameters = ImmutableArray<TypeParameterSymbol>.Empty; } else if ((object)(lambdaFrame = this.ContainingType as LambdaFrame) != null) { typeMap = lambdaFrame.TypeMap; typeParameters = ImmutableArray<TypeParameterSymbol>.Empty; } else { typeMap = TypeMap.Empty.WithAlphaRename(topLevelMethod, this, out typeParameters); } AssignTypeMapAndTypeParameters(typeMap, typeParameters); }
public EEAssemblyBuilder( SourceAssemblySymbol sourceAssembly, EmitOptions emitOptions, ImmutableArray<MethodSymbol> methods, ModulePropertiesForSerialization serializationProperties, ImmutableArray<NamedTypeSymbol> additionalTypes, NamedTypeSymbol dynamicOperationContextType, CompilationTestData testData) : base( sourceAssembly, emitOptions, outputKind: OutputKind.DynamicallyLinkedLibrary, serializationProperties: serializationProperties, manifestResources: SpecializedCollections.EmptyEnumerable<ResourceDescription>(), additionalTypes: additionalTypes) { Methods = ImmutableHashSet.CreateRange(methods); _dynamicOperationContextType = dynamicOperationContextType; if (testData != null) { this.SetMethodTestData(testData.Methods); testData.Module = this; } }
public LocalFunctionSymbol( Binder binder, NamedTypeSymbol containingType, Symbol containingSymbol, LocalFunctionStatementSyntax syntax) { _syntax = syntax; _containingSymbol = containingSymbol; _refKind = syntax.RefKeyword.Kind().GetRefKind(); _declarationModifiers = DeclarationModifiers.Private | DeclarationModifiers.Static | syntax.Modifiers.ToDeclarationModifiers(); var diagnostics = DiagnosticBag.GetInstance(); if (_syntax.TypeParameterList != null) { binder = new WithMethodTypeParametersBinder(this, binder); _typeParameters = MakeTypeParameters(diagnostics); } else { _typeParameters = ImmutableArray<TypeParameterSymbol>.Empty; } if (IsExtensionMethod) { diagnostics.Add(ErrorCode.ERR_BadExtensionAgg, Locations[0]); } _binder = binder; _diagnostics = diagnostics.ToReadOnlyAndFree(); }
internal SynthesizedEntryPointSymbol(NamedTypeSymbol containingType, TypeSymbol returnType, DiagnosticBag diagnostics) { Debug.Assert((object)containingType != null); _containingType = containingType; if (containingType.ContainingAssembly.IsInteractive) { var submissionArrayType = this.DeclaringCompilation.CreateArrayTypeSymbol(this.DeclaringCompilation.GetSpecialType(SpecialType.System_Object)); var useSiteDiagnostic = submissionArrayType.GetUseSiteDiagnostic(); if (useSiteDiagnostic != null) { Symbol.ReportUseSiteDiagnostic(useSiteDiagnostic, diagnostics, NoLocation.Singleton); } _parameters = ImmutableArray.Create<ParameterSymbol>(new SynthesizedParameterSymbol(this, submissionArrayType, 0, RefKind.None, "submissionArray")); _name = "<Factory>"; } else { _parameters = ImmutableArray<ParameterSymbol>.Empty; _name = "<Main>"; } if (this.DeclaringCompilation.IsSubmission) { returnType = this.DeclaringCompilation.GetSpecialType(SpecialType.System_Object); } _returnType = returnType; }
/// <summary> /// SubstType, but for NamedTypeSymbols only. This is used for concrete types, so no alpha substitution appears in the result. /// </summary> internal NamedTypeSymbol SubstituteNamedType(NamedTypeSymbol previous) { if (ReferenceEquals(previous, null)) return null; if (previous.IsUnboundGenericType) return previous; if (previous.IsAnonymousType) { ImmutableArray<TypeSymbol> oldFieldTypes = AnonymousTypeManager.GetAnonymousTypePropertyTypes(previous); ImmutableArray<TypeSymbol> newFieldTypes = SubstituteTypes(oldFieldTypes); return (oldFieldTypes == newFieldTypes) ? previous : AnonymousTypeManager.ConstructAnonymousTypeSymbol(previous, newFieldTypes); } // TODO: we could construct the result's ConstructedFrom lazily by using a "deep" // construct operation here (as VB does), thereby avoiding alpha renaming in most cases. // Aleksey has shown that would reduce GC pressure if substitutions of deeply nested generics are common. NamedTypeSymbol oldConstructedFrom = previous.ConstructedFrom; NamedTypeSymbol newConstructedFrom = SubstituteMemberType(oldConstructedFrom); ImmutableArray<TypeSymbol> oldTypeArguments = previous.TypeArgumentsNoUseSiteDiagnostics; ImmutableArray<TypeSymbol> newTypeArguments = SubstituteTypes(oldTypeArguments); if (ReferenceEquals(oldConstructedFrom, newConstructedFrom) && oldTypeArguments == newTypeArguments) { return previous; } return newConstructedFrom.ConstructIfGeneric(newTypeArguments); }
internal SynthesizedEntryPointSymbol(NamedTypeSymbol containingType, TypeSymbol returnType, DiagnosticBag diagnostics) { Debug.Assert((object)containingType != null); this.containingType = containingType; if (containingType.ContainingAssembly.IsInteractive) { var interactiveSessionType = this.DeclaringCompilation.GetWellKnownType(WellKnownType.Microsoft_CSharp_RuntimeHelpers_Session); var useSiteDiagnostic = interactiveSessionType.GetUseSiteDiagnostic(); if (useSiteDiagnostic != null) { Symbol.ReportUseSiteDiagnostic(useSiteDiagnostic, diagnostics, NoLocation.Singleton); } this.parameters = ImmutableArray.Create<ParameterSymbol>(new SynthesizedParameterSymbol(this, interactiveSessionType, 0, RefKind.None, "session")); this.name = "<Factory>"; } else { this.parameters = ImmutableArray<ParameterSymbol>.Empty; this.name = "<Main>"; } this.returnType = returnType; }
public PartialTypeDocumentationCommentTests() { var tree1 = Parse( @" /// <summary>Summary on first file's Foo.</summary> partial class Foo { /// <summary>Summary on MethodWithNoImplementation.</summary> partial void MethodWithNoImplementation(); /// <summary>Summary in file one which should be shadowed.</summary> partial void ImplementedMethodWithNoSummaryOnImpl(); partial void ImplementedMethod(); }", options: TestOptions.RegularWithDocumentationComments); var tree2 = Parse( @" /// <summary>Summary on second file's Foo.</summary> partial class Foo { /// <remarks>Foo.</remarks> partial void ImplementedMethodWithNoSummaryOnImpl() { } /// <summary>Implemented method.</summary> partial void ImplementedMethod() { } }", options: TestOptions.RegularWithDocumentationComments); _compilation = CreateCompilationWithMscorlib(new[] { tree1, tree2 }); _fooClass = _compilation.GlobalNamespace.GetTypeMembers("Foo").Single(); }
public SynthesizedExplicitImplementationMethod( MethodSymbol interfaceMethod, MethodSymbol implementingMethod, NamedTypeSymbol implementingType) : base(interfaceMethod, implementingType) { this.implementingMethod = implementingMethod; }
public override void VisitNamedType(NamedTypeSymbol symbol) { _cancellationToken.ThrowIfCancellationRequested(); var sourceTypeSymbol = symbol as SourceMemberContainerTypeSymbol; if ((object)sourceTypeSymbol != null) { if (_moduleBeingBuilt != null) { // In some circumstances (e.g. implicit implementation of an interface method by a non-virtual method in a // base type from another assembly) it is necessary for the compiler to generate explicit implementations for // some interface methods. They don't go in the symbol table, but if we are emitting metadata, then we should // generate MethodDef entries for them. foreach (var synthesizedExplicitImpl in sourceTypeSymbol.GetSynthesizedExplicitImplementations(_cancellationToken)) { _moduleBeingBuilt.AddSynthesizedDefinition(symbol, synthesizedExplicitImpl); } } } foreach (Symbol member in symbol.GetMembers()) { switch (member.Kind) { case SymbolKind.Property: case SymbolKind.NamedType: member.Accept(this); break; } } }
public static SourcePropertyAccessorSymbol CreateAccessorSymbol( NamedTypeSymbol containingType, SourcePropertySymbol property, DeclarationModifiers propertyModifiers, string propertyName, ArrowExpressionClauseSyntax syntax, PropertySymbol explicitlyImplementedPropertyOpt, string aliasQualifierOpt, DiagnosticBag diagnostics) { string name; ImmutableArray<MethodSymbol> explicitInterfaceImplementations; GetNameAndExplicitInterfaceImplementations( explicitlyImplementedPropertyOpt, propertyName, property.IsCompilationOutputWinMdObj(), aliasQualifierOpt, isGetMethod: true, name: out name, explicitInterfaceImplementations: out explicitInterfaceImplementations); return new SourcePropertyAccessorSymbol( containingType, name, property, propertyModifiers, explicitInterfaceImplementations, syntax.Expression.GetLocation(), syntax, diagnostics); }
public DelegateConstructor(NamedTypeSymbol containingType, TypeSymbol objectType, TypeSymbol intPtrType) : base(containingType) { _parameters = ImmutableArray.Create<ParameterSymbol>( new SynthesizedParameterSymbol(this, objectType, 0, RefKind.None, "object"), new SynthesizedParameterSymbol(this, intPtrType, 1, RefKind.None, "method")); }
private static SmallDictionary<TypeParameterSymbol, TypeWithModifiers> ForType(NamedTypeSymbol containingType) { var substituted = containingType as SubstitutedNamedTypeSymbol; return (object)substituted != null ? new SmallDictionary<TypeParameterSymbol, TypeWithModifiers>(substituted.TypeSubstitution.Mapping, ReferenceEqualityComparer.Instance) : new SmallDictionary<TypeParameterSymbol, TypeWithModifiers>(ReferenceEqualityComparer.Instance); }
internal SourceAttributeData( SyntaxReference applicationNode, NamedTypeSymbol attributeClass, MethodSymbol attributeConstructor, ImmutableArray<TypedConstant> constructorArguments, ImmutableArray<int> constructorArgumentsSourceIndices, ImmutableArray<KeyValuePair<string, TypedConstant>> namedArguments, bool hasErrors, bool isConditionallyOmitted) { Debug.Assert(!isConditionallyOmitted || (object)attributeClass != null && attributeClass.IsConditional); Debug.Assert(!constructorArguments.IsDefault); Debug.Assert(!namedArguments.IsDefault); Debug.Assert(constructorArgumentsSourceIndices.IsDefault || constructorArgumentsSourceIndices.Any() && constructorArgumentsSourceIndices.Length == constructorArguments.Length); this.attributeClass = attributeClass; this.attributeConstructor = attributeConstructor; this.constructorArguments = constructorArguments; this.constructorArgumentsSourceIndices = constructorArgumentsSourceIndices; this.namedArguments = namedArguments; this.isConditionallyOmitted = isConditionallyOmitted; this.hasErrors = hasErrors; this.applicationNode = applicationNode; }
private static void StructDependsClosure(TypeSymbol type, HashSet<Symbol> partialClosure, NamedTypeSymbol on) { if ((object)type == null) { return; } var nt = type as NamedTypeSymbol; if ((object)nt != null && ReferenceEquals(nt.OriginalDefinition, on)) { // found a possibly expanding cycle, for example // struct X<T> { public T t; } // struct W<T> { X<W<W<T>>> x; } // while not explicitly forbidden by the spec, it should be. partialClosure.Add(on); return; } if ((object)nt != null && partialClosure.Add(nt)) { foreach (var member in type.GetMembersUnordered()) { var field = member as FieldSymbol; if ((object)field == null || field.Type.TypeKind != TypeKind.Struct || field.IsStatic) { continue; } StructDependsClosure(field.Type, partialClosure, on); } } }
public EmbeddedType(EmbeddedTypesManager typeManager, NamedTypeSymbolAdapter underlyingNamedType) : base(typeManager, underlyingNamedType) { Debug.Assert(underlyingNamedType.AdaptedNamedTypeSymbol.IsDefinition); Debug.Assert(underlyingNamedType.AdaptedNamedTypeSymbol.IsTopLevelType()); Debug.Assert(!underlyingNamedType.AdaptedNamedTypeSymbol.IsGenericType); }
public EmbeddedType(EmbeddedTypesManager typeManager, NamedTypeSymbol underlyingNamedType) : base(typeManager, underlyingNamedType) { Debug.Assert(underlyingNamedType.IsDefinition); Debug.Assert(underlyingNamedType.IsTopLevelType()); Debug.Assert(!underlyingNamedType.IsGenericType); }
public TypeDocumentationCommentTests() { _compilation = CreateCompilationWithMscorlibAndDocumentationComments(@"enum Color { Red, Blue, Green } namespace Acme { interface IProcess {...} struct ValueType {...} class Widget: IProcess { /// <summary> /// Hello! Nested Class. /// </summary> public class NestedClass {...} public interface IMenuItem {...} public delegate void Del(int i); public enum Direction { North, South, East, West } } class MyList<T> { class Helper<U,V> {...} } }"); _acmeNamespace = (NamespaceSymbol)_compilation.GlobalNamespace.GetMembers("Acme").Single(); _widgetClass = _acmeNamespace.GetTypeMembers("Widget").Single(); }
public SynthesizedImplementationMethod( MethodSymbol interfaceMethod, NamedTypeSymbol implementingType, string name = null, bool debuggerHidden = false, PropertySymbol associatedProperty = null, MethodSymbol asyncKickoffMethod = null) { //it does not make sense to add methods to substituted types Debug.Assert(implementingType.IsDefinition); this.name = name ?? ExplicitInterfaceHelpers.GetMemberName(interfaceMethod.Name, interfaceMethod.ContainingType, aliasQualifierOpt: null); this.interfaceMethod = interfaceMethod; this.implementingType = implementingType; this.debuggerHidden = debuggerHidden; this.associatedProperty = associatedProperty; this.explicitInterfaceImplementations = ImmutableArray.Create<MethodSymbol>(interfaceMethod); this.asyncKickoffMethod = asyncKickoffMethod; // alpha-rename to get the implementation's type parameters var typeMap = interfaceMethod.ContainingType.TypeSubstitution ?? TypeMap.Empty; typeMap.WithAlphaRename(interfaceMethod, this, out this.typeParameters); var substitutedInterfaceMethod = interfaceMethod.ConstructIfGeneric(this.typeParameters.Cast<TypeParameterSymbol, TypeSymbol>()); this.returnType = substitutedInterfaceMethod.ReturnType; this.parameters = SynthesizedParameterSymbol.DeriveParameters(substitutedInterfaceMethod, this); }
internal AnonymousTypeEqualsMethodSymbol(NamedTypeSymbol container) : base(container, WellKnownMemberNames.ObjectEquals) { _parameters = ImmutableArray.Create<ParameterSymbol>( SynthesizedParameterSymbol.Create(this, this.Manager.System_Object, 0, RefKind.None, "value") ); }
public SpecializedGenericNestedTypeInstanceReference(NamedTypeSymbol underlyingNamedType) : base(underlyingNamedType) { Debug.Assert(underlyingNamedType.IsDefinition); // Definition doesn't have custom modifiers on type arguments Debug.Assert(!underlyingNamedType.HasTypeArgumentsCustomModifiers); }
/// <summary> /// Register declaration of predefined CorLib type in this Assembly. /// </summary> /// <param name="corType"></param> internal override sealed void RegisterDeclaredSpecialType(NamedTypeSymbol corType) { SpecialType typeId = corType.SpecialType; Debug.Assert(typeId != SpecialType.None); Debug.Assert(ReferenceEquals(corType.ContainingAssembly, this)); Debug.Assert(corType.ContainingModule.Ordinal == 0); Debug.Assert(ReferenceEquals(this.CorLibrary, this)); if (_lazySpecialTypes == null) { Interlocked.CompareExchange(ref _lazySpecialTypes, new NamedTypeSymbol[(int)SpecialType.Count + 1], null); } if ((object)Interlocked.CompareExchange(ref _lazySpecialTypes[(int)typeId], corType, null) != null) { Debug.Assert(ReferenceEquals(corType, _lazySpecialTypes[(int)typeId]) || (corType.Kind == SymbolKind.ErrorType && _lazySpecialTypes[(int)typeId].Kind == SymbolKind.ErrorType)); } else { Interlocked.Increment(ref _cachedSpecialTypes); Debug.Assert(_cachedSpecialTypes > 0 && _cachedSpecialTypes <= (int)SpecialType.Count); } }
public SynthesizedImplementationMethod( MethodSymbol interfaceMethod, NamedTypeSymbol implementingType, string name = null, bool generateDebugInfo = true, PropertySymbol associatedProperty = null) { //it does not make sense to add methods to substituted types Debug.Assert(implementingType.IsDefinition); _name = name ?? ExplicitInterfaceHelpers.GetMemberName(interfaceMethod.Name, interfaceMethod.ContainingType, aliasQualifierOpt: null); _interfaceMethod = interfaceMethod; _implementingType = implementingType; _generateDebugInfo = generateDebugInfo; _associatedProperty = associatedProperty; _explicitInterfaceImplementations = ImmutableArray.Create<MethodSymbol>(interfaceMethod); // alpha-rename to get the implementation's type parameters var typeMap = interfaceMethod.ContainingType.TypeSubstitution ?? TypeMap.Empty; typeMap.WithAlphaRename(interfaceMethod, this, out _typeParameters); var substitutedInterfaceMethod = interfaceMethod.ConstructIfGeneric(_typeParameters.Cast<TypeParameterSymbol, TypeSymbol>()); _returnType = substitutedInterfaceMethod.ReturnType; _parameters = SynthesizedParameterSymbol.DeriveParameters(substitutedInterfaceMethod, this); }
internal CSharpAttributeData GetAttribute(AttributeSyntax node, NamedTypeSymbol boundAttributeType, out bool generatedDiagnostics) { var dummyDiagnosticBag = DiagnosticBag.GetInstance(); var boundAttribute = base.GetAttribute(node, boundAttributeType, dummyDiagnosticBag); generatedDiagnostics = !dummyDiagnosticBag.IsEmptyWithoutResolution; dummyDiagnosticBag.Free(); return boundAttribute; }
/// <summary> /// Given an anonymous type and new field types construct a new anonymous type symbol; /// a new type symbol will reuse type descriptor from the constructed type with new type arguments. /// </summary> public static NamedTypeSymbol ConstructAnonymousTypeSymbol(NamedTypeSymbol type, ImmutableArray<TypeSymbol> newFieldTypes) { Debug.Assert(!newFieldTypes.IsDefault); Debug.Assert(type.IsAnonymousType); var anonymous = (AnonymousTypePublicSymbol)type; return anonymous.Manager.ConstructAnonymousTypeSymbol(anonymous.TypeDescriptor.WithNewFieldsTypes(newFieldTypes)); }
public SynthesizedSubmissionFields(CSharpCompilation compilation, NamedTypeSymbol submissionClass) { Debug.Assert(compilation != null); Debug.Assert(submissionClass.IsSubmissionClass); _declaringSubmissionClass = submissionClass; _compilation = compilation; }
private SynthesizedEntryPointSymbol(NamedTypeSymbol containingType, TypeSymbol returnType) { Debug.Assert((object)containingType != null); Debug.Assert((object)returnType != null); _containingType = containingType; _returnType = returnType; }
private ExpressionLambdaRewriter(TypeCompilationState compilationState, CSharpSyntaxNode node, DiagnosticBag diagnostics) { Bound = new SyntheticBoundNodeFactory((NamedTypeSymbol)null, node, compilationState, diagnostics); Int32Type = Bound.SpecialType(SpecialType.System_Int32); ObjectType = Bound.SpecialType(SpecialType.System_Object); NullableType = Bound.SpecialType(SpecialType.System_Nullable_T); IEnumerableType = Bound.SpecialType(SpecialType.System_Collections_Generic_IEnumerable_T); }
/// <summary> /// Get a symbol of constructed anonymous type property by property index /// </summary> internal static PropertySymbol GetAnonymousTypeProperty(NamedTypeSymbol type, int index) { Debug.Assert((object)type != null); Debug.Assert(type.IsAnonymousType); var anonymous = (AnonymousTypePublicSymbol)type; return anonymous.Properties[index]; }
/// <summary> /// Creates a speculative AttributeSemanticModel that allows asking semantic questions about an attribute node that did not appear in the original source code. /// </summary> public static AttributeSemanticModel CreateSpeculative(SyntaxTreeSemanticModel parentSemanticModel, AttributeSyntax syntax, NamedTypeSymbol attributeType, AliasSymbol aliasOpt, Binder rootBinder, int position) { Debug.Assert(parentSemanticModel != null); Debug.Assert(rootBinder != null); Debug.Assert(rootBinder.IsSemanticModelBinder); return new AttributeSemanticModel(parentSemanticModel.Compilation, syntax, attributeType, aliasOpt, rootBinder, parentSemanticModel, position); }
private DiagnosticInfo _lazyUseSiteDiagnostic = CSDiagnosticInfo.EmptyErrorInfo; // Indicates unknown state. public RetargetingNamedTypeSymbol(RetargetingModuleSymbol retargetingModule, NamedTypeSymbol underlyingType) : base(underlyingType) { Debug.Assert((object)retargetingModule != null); Debug.Assert(!(underlyingType is RetargetingNamedTypeSymbol)); _retargetingModule = retargetingModule; }
public SynthesizedLambdaCacheFieldSymbol(NamedTypeSymbol containingType, TypeSymbol type, string name, MethodSymbol topLevelMethod, bool isReadOnly, bool isStatic) : base(containingType, name, isPublic: true, isReadOnly: isReadOnly, isStatic: isStatic) { Debug.Assert((object)type != null); Debug.Assert((object)topLevelMethod != null); _type = type; _topLevelMethod = topLevelMethod; }
private Tuple <NamedTypeSymbol, ImmutableArray <NamedTypeSymbol> > MakeDeclaredBases(ConsList <TypeSymbol> basesBeingResolved, BindingDiagnosticBag diagnostics) { if (this.TypeKind == TypeKind.Enum) { // Handled by GetEnumUnderlyingType(). return(new Tuple <NamedTypeSymbol, ImmutableArray <NamedTypeSymbol> >(null, ImmutableArray <NamedTypeSymbol> .Empty)); } var reportedPartialConflict = false; Debug.Assert(basesBeingResolved == null || !basesBeingResolved.ContainsReference(this.OriginalDefinition)); var newBasesBeingResolved = basesBeingResolved.Prepend(this.OriginalDefinition); var baseInterfaces = ArrayBuilder <NamedTypeSymbol> .GetInstance(); NamedTypeSymbol baseType = null; SourceLocation baseTypeLocation = null; var interfaceLocations = SpecializedSymbolCollections.GetPooledSymbolDictionaryInstance <NamedTypeSymbol, SourceLocation>(); foreach (var decl in this.declaration.Declarations) { Tuple <NamedTypeSymbol, ImmutableArray <NamedTypeSymbol> > one = MakeOneDeclaredBases(newBasesBeingResolved, decl, diagnostics); if ((object)one == null) { continue; } var partBase = one.Item1; var partInterfaces = one.Item2; if (!reportedPartialConflict) { if ((object)baseType == null) { baseType = partBase; baseTypeLocation = decl.NameLocation; } else if (baseType.TypeKind == TypeKind.Error && (object)partBase != null) { // if the old base was an error symbol, copy it to the interfaces list so it doesn't get lost partInterfaces = partInterfaces.Add(baseType); baseType = partBase; baseTypeLocation = decl.NameLocation; } else if ((object)partBase != null && !TypeSymbol.Equals(partBase, baseType, TypeCompareKind.ConsiderEverything) && partBase.TypeKind != TypeKind.Error) { // the parts do not agree if (partBase.Equals(baseType, TypeCompareKind.ObliviousNullableModifierMatchesAny)) { if (containsOnlyOblivious(baseType)) { baseType = partBase; baseTypeLocation = decl.NameLocation; continue; } else if (containsOnlyOblivious(partBase)) { continue; } } var info = diagnostics.Add(ErrorCode.ERR_PartialMultipleBases, Locations[0], this); baseType = new ExtendedErrorTypeSymbol(baseType, LookupResultKind.Ambiguous, info); baseTypeLocation = decl.NameLocation; reportedPartialConflict = true;
internal override void GenerateMethodBody(TypeCompilationState compilationState, DiagnosticBag diagnostics) { AnonymousTypeManager manager = ((AnonymousTypeTemplateSymbol)this.ContainingType).Manager; SyntheticBoundNodeFactory F = this.CreateBoundNodeFactory(compilationState, diagnostics); // Method body: // // { // $anonymous$ local = value as $anonymous$; // return local != null // && System.Collections.Generic.EqualityComparer<T_1>.Default.Equals(this.backingFld_1, local.backingFld_1) // ... // && System.Collections.Generic.EqualityComparer<T_N>.Default.Equals(this.backingFld_N, local.backingFld_N); // } // Type and type expression AnonymousTypeTemplateSymbol anonymousType = (AnonymousTypeTemplateSymbol)this.ContainingType; // local BoundAssignmentOperator assignmentToTemp; BoundLocal boundLocal = F.StoreToTemp(F.As(F.Parameter(_parameters[0]), anonymousType), out assignmentToTemp); // Generate: statement <= 'local = value as $anonymous$' BoundStatement assignment = F.ExpressionStatement(assignmentToTemp); // Generate expression for return statement // retExpression <= 'local != null' BoundExpression retExpression = F.Binary(BinaryOperatorKind.ObjectNotEqual, manager.System_Boolean, F.Convert(manager.System_Object, boundLocal), F.Null(manager.System_Object)); // prepare symbols MethodSymbol equalityComparer_Equals = manager.System_Collections_Generic_EqualityComparer_T__Equals; MethodSymbol equalityComparer_get_Default = manager.System_Collections_Generic_EqualityComparer_T__get_Default; NamedTypeSymbol equalityComparerType = equalityComparer_Equals.ContainingType; // Compare fields for (int index = 0; index < anonymousType.Properties.Length; index++) { // Prepare constructed symbols TypeParameterSymbol typeParameter = anonymousType.TypeParameters[index]; FieldSymbol fieldSymbol = anonymousType.Properties[index].BackingField; NamedTypeSymbol constructedEqualityComparer = equalityComparerType.Construct(typeParameter); // Generate 'retExpression' = 'retExpression && System.Collections.Generic.EqualityComparer<T_index>. // Default.Equals(this.backingFld_index, local.backingFld_index)' retExpression = F.LogicalAnd(retExpression, F.Call(F.StaticCall(constructedEqualityComparer, equalityComparer_get_Default.AsMember(constructedEqualityComparer)), equalityComparer_Equals.AsMember(constructedEqualityComparer), F.Field(F.This(), fieldSymbol), F.Field(boundLocal, fieldSymbol))); } // Final return statement BoundStatement retStatement = F.Return(retExpression); // Create a bound block F.CloseMethod(F.Block(ImmutableArray.Create <LocalSymbol>(boundLocal.LocalSymbol), assignment, retStatement)); }
protected SourceMemberMethodSymbol(NamedTypeSymbol containingType, SyntaxReference syntaxReferenceOpt, Location location, bool isIterator) : this(containingType, syntaxReferenceOpt, ImmutableArray.Create(location), isIterator) { }
protected sealed override void LazyAsyncMethodChecks(CancellationToken cancellationToken) { Debug.Assert(this.IsPartial == state.HasComplete(CompletionPart.FinishMethodChecks), "Partial methods complete method checks during construction. " + "Other methods can't complete method checks before executing this method."); if (!this.IsAsync) { if (state.NotePartComplete(CompletionPart.StartAsyncMethodChecks)) { if (IsPartialDefinition && (object)PartialImplementationPart == null) { DeclaringCompilation.SymbolDeclaredEvent(this); } state.NotePartComplete(CompletionPart.FinishAsyncMethodChecks); } else { state.SpinWaitComplete(CompletionPart.FinishAsyncMethodChecks, cancellationToken); } return; } DiagnosticBag diagnostics = DiagnosticBag.GetInstance(); Location errorLocation = this.Locations[0]; if (!this.IsGenericTaskReturningAsync(this.DeclaringCompilation) && !this.IsTaskReturningAsync(this.DeclaringCompilation) && !this.IsVoidReturningAsync()) { // The return type of an async method must be void, Task or Task<T> diagnostics.Add(ErrorCode.ERR_BadAsyncReturn, errorLocation); } for (NamedTypeSymbol curr = this.ContainingType; (object)curr != null; curr = curr.ContainingType) { var sourceNamedTypeSymbol = curr as SourceNamedTypeSymbol; if ((object)sourceNamedTypeSymbol != null && sourceNamedTypeSymbol.HasSecurityCriticalAttributes) { diagnostics.Add(ErrorCode.ERR_SecurityCriticalOrSecuritySafeCriticalOnAsyncInClassOrStruct, errorLocation); break; } } if ((this.ImplementationAttributes & System.Reflection.MethodImplAttributes.Synchronized) != 0) { diagnostics.Add(ErrorCode.ERR_SynchronizedAsyncMethod, errorLocation); } if (diagnostics.IsEmptyWithoutResolution) { ReportAsyncParameterErrors(this, diagnostics, errorLocation); } if (state.NotePartComplete(CompletionPart.StartAsyncMethodChecks)) { AddDeclarationDiagnostics(diagnostics); if (IsPartialDefinition) { DeclaringCompilation.SymbolDeclaredEvent(this); } state.NotePartComplete(CompletionPart.FinishAsyncMethodChecks); } else { state.SpinWaitComplete(CompletionPart.FinishAsyncMethodChecks, cancellationToken); } diagnostics.Free(); }
// Subclasses override this method to fetch a frame pointer. protected abstract BoundExpression FramePointer(CSharpSyntaxNode syntax, NamedTypeSymbol frameClass);
private static bool IsAsRestrictive(NamedTypeSymbol s1, Symbol sym2, ref HashSet <DiagnosticInfo> useSiteDiagnostics) { Accessibility acc1 = s1.DeclaredAccessibility; if (acc1 == Accessibility.Public) { return(true); } for (Symbol s2 = sym2; s2.Kind != SymbolKind.Namespace; s2 = s2.ContainingSymbol) { Accessibility acc2 = s2.DeclaredAccessibility; switch (acc1) { case Accessibility.Internal: { // If s2 is private or internal, and within the same assembly as s1, // then this is at least as restrictive as s1's internal. if ((acc2 == Accessibility.Private || acc2 == Accessibility.Internal) && s2.ContainingAssembly.HasInternalAccessTo(s1.ContainingAssembly)) { return(true); } break; } case Accessibility.Protected: { var parent1 = s1.ContainingType; if ((object)parent1 == null) { // not helpful } else if (acc2 == Accessibility.Private) { // if s2 is private and within s1's parent or within a subclass of s1's parent, // then this is at least as restrictive as s1's protected. for (var parent2 = s2.ContainingType; (object)parent2 != null; parent2 = parent2.ContainingType) { if (parent1.IsAccessibleViaInheritance(parent2, ref useSiteDiagnostics)) { return(true); } } } else if (acc2 == Accessibility.Protected) { // if s2 is protected, and it's parent is a subclass (or the same as) s1's parent // then this is at least as restrictive as s1's protected var parent2 = s2.ContainingType; if ((object)parent2 != null && parent1.IsAccessibleViaInheritance(parent2, ref useSiteDiagnostics)) { return(true); } } break; } case Accessibility.ProtectedOrInternal: { var parent1 = s1.ContainingType; if ((object)parent1 == null) { break; } switch (acc2) { case Accessibility.Private: // if s2 is private and within a subclass of s1's parent, // or within the same assembly as s1 // then this is at least as restrictive as s1's internal protected. if (s2.ContainingAssembly.HasInternalAccessTo(s1.ContainingAssembly)) { return(true); } for (var parent2 = s2.ContainingType; (object)parent2 != null; parent2 = parent2.ContainingType) { if (parent1.IsAccessibleViaInheritance(parent2, ref useSiteDiagnostics)) { return(true); } } break; case Accessibility.Internal: // If s2 is in the same assembly as s1, then this is more restrictive // than s1's internal protected. if (s2.ContainingAssembly.HasInternalAccessTo(s1.ContainingAssembly)) { return(true); } break; case Accessibility.Protected: // if s2 is protected, and it's parent is a subclass (or the same as) s1's parent // then this is at least as restrictive as s1's internal protected if (parent1.IsAccessibleViaInheritance(s2.ContainingType, ref useSiteDiagnostics)) { return(true); } break; case Accessibility.ProtectedOrInternal: // if s2 is internal protected, and it's parent is a subclass (or the same as) s1's parent // and its in the same assembly as s1, then this is at least as restrictive as s1's protected if (s2.ContainingAssembly.HasInternalAccessTo(s1.ContainingAssembly) && parent1.IsAccessibleViaInheritance(s2.ContainingType, ref useSiteDiagnostics)) { return(true); } break; } break; } case Accessibility.Private: if (acc2 == Accessibility.Private) { // if s2 is private, and it is within s1's parent, then this is at // least as restrictive as s1's private. NamedTypeSymbol parent1 = s1.ContainingType; if ((object)parent1 == null) { break; } var parent1OriginalDefinition = parent1.OriginalDefinition; for (var parent2 = s2.ContainingType; (object)parent2 != null; parent2 = parent2.ContainingType) { if (ReferenceEquals(parent2.OriginalDefinition, parent1OriginalDefinition) || parent1OriginalDefinition.TypeKind == TypeKind.Submission && parent2.TypeKind == TypeKind.Submission) { return(true); } } } break; default: throw ExceptionUtilities.UnexpectedValue(acc1); } } return(false); }
private SynthesizedEntryPointSymbol(NamedTypeSymbol containingType) { Debug.Assert((object)containingType != null); _containingType = containingType; }
internal EventSymbol AsMember(NamedTypeSymbol newOwner) { Debug.Assert(this.IsDefinition); Debug.Assert(ReferenceEquals(newOwner.OriginalDefinition, this.ContainingSymbol.OriginalDefinition)); return newOwner.IsDefinition ? this : new SubstitutedEventSymbol(newOwner as SubstitutedNamedTypeSymbol, this); }
public static bool IsTopLevelType(this NamedTypeSymbol type) { return((object)type.ContainingType == null); }
public SynthesizedEmbeddedAttributeConstructorSymbol(NamedTypeSymbol containingType) : base(containingType) { }
public SynthesizedMethodBase(NamedTypeSymbol containigType, string name) { _containigType = containigType; _name = name; }
private SourceMemberMethodSymbol( NamedTypeSymbol containingType, TypeSymbol explicitInterfaceType, string name, Location location, MethodDeclarationSyntax syntax, MethodKind methodKind, DiagnosticBag diagnostics) : base(containingType, syntax.GetReference(), // Prefer a block body if both exist syntax.Body?.GetReference() ?? syntax.ExpressionBody?.GetReference(), location) { _name = name; _explicitInterfaceType = explicitInterfaceType; SyntaxTokenList modifiers = syntax.Modifiers; // The following two values are used to compute and store the initial value of the flags // However, these two components are placeholders; the correct value will be // computed lazily later and then the flags will be fixed up. const bool returnsVoid = false; var firstParam = syntax.ParameterList.Parameters.FirstOrDefault(); bool isExtensionMethod = firstParam != null && !firstParam.IsArgList && firstParam.Modifiers.Any(SyntaxKind.ThisKeyword); bool modifierErrors; var declarationModifiers = this.MakeModifiers(modifiers, methodKind, location, diagnostics, out modifierErrors); var isMetadataVirtualIgnoringModifiers = (object)explicitInterfaceType != null; //explicit impls must be marked metadata virtual this.MakeFlags(methodKind, declarationModifiers, returnsVoid, isExtensionMethod, isMetadataVirtualIgnoringModifiers); if (syntax.Arity == 0) { _typeParameters = ImmutableArray <TypeParameterSymbol> .Empty; ReportErrorIfHasConstraints(syntax.ConstraintClauses, diagnostics); } else { _typeParameters = MakeTypeParameters(syntax, diagnostics); } bool hasBlockBody = syntax.Body != null; _isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null; syntax.ReturnType.SkipRef(out _refKind); if (hasBlockBody || _isExpressionBodied) { CheckModifiersForBody(location, diagnostics); } var info = ModifierUtils.CheckAccessibility(this.DeclarationModifiers); if (info != null) { diagnostics.Add(info, location); } // When a generic method overrides a generic method declared in a base class, or is an // explicit interface member implementation of a method in a base interface, the method // shall not specify any type-parameter-constraints-clauses. In these cases, the type // parameters of the method inherit constraints from the method being overridden or // implemented if (syntax.ConstraintClauses.Count > 0) { if (syntax.ExplicitInterfaceSpecifier != null || syntax.Modifiers.Any(SyntaxKind.OverrideKeyword)) { diagnostics.Add( ErrorCode.ERR_OverrideWithConstraints, syntax.ConstraintClauses[0].WhereKeyword.GetLocation()); } } CheckForBlockAndExpressionBody( syntax.Body, syntax.ExpressionBody, syntax, diagnostics); }
internal virtual NamedTypeSymbol GetNativeIntegerType(NamedTypeSymbol underlyingType) { throw ExceptionUtilities.Unreachable; }
internal AnonymousTypeGetHashCodeMethodSymbol(NamedTypeSymbol container) : base(container, WellKnownMemberNames.ObjectGetHashCode) { }
internal virtual void RegisterDeclaredSpecialType(NamedTypeSymbol corType) { throw ExceptionUtilities.Unreachable; }
internal override void GenerateMethodBody(TypeCompilationState compilationState, DiagnosticBag diagnostics) { AnonymousTypeManager manager = ((AnonymousTypeTemplateSymbol)this.ContainingType).Manager; SyntheticBoundNodeFactory F = this.CreateBoundNodeFactory(compilationState, diagnostics); // Method body: // // HASH_FACTOR = 0xa5555529; // INIT_HASH = (...((0 * HASH_FACTOR) + backingFld_1.Name.GetHashCode()) * HASH_FACTOR // + backingFld_2.Name.GetHashCode()) * HASH_FACTOR // + ... // + backingFld_N.Name.GetHashCode() // // { // return (...((INITIAL_HASH * HASH_FACTOR) + EqualityComparer<T_1>.Default.GetHashCode(this.backingFld_1)) * HASH_FACTOR // + EqualityComparer<T_2>.Default.GetHashCode(this.backingFld_2)) * HASH_FACTOR // ... // + EqualityComparer<T_N>.Default.GetHashCode(this.backingFld_N) // } const int HASH_FACTOR = -1521134295; // (int)0xa5555529 // Type expression AnonymousTypeTemplateSymbol anonymousType = (AnonymousTypeTemplateSymbol)this.ContainingType; // INIT_HASH int initHash = 0; foreach (var property in anonymousType.Properties) { initHash = unchecked (initHash * HASH_FACTOR + property.BackingField.Name.GetHashCode()); } // Generate expression for return statement // retExpression <= 'INITIAL_HASH' BoundExpression retExpression = F.Literal(initHash); // prepare symbols MethodSymbol equalityComparer_GetHashCode = manager.System_Collections_Generic_EqualityComparer_T__GetHashCode; MethodSymbol equalityComparer_get_Default = manager.System_Collections_Generic_EqualityComparer_T__get_Default; NamedTypeSymbol equalityComparerType = equalityComparer_GetHashCode.ContainingType; // bound HASH_FACTOR BoundLiteral boundHashFactor = F.Literal(HASH_FACTOR); // Process fields for (int index = 0; index < anonymousType.Properties.Length; index++) { // Prepare constructed symbols TypeParameterSymbol typeParameter = anonymousType.TypeParameters[index]; NamedTypeSymbol constructedEqualityComparer = equalityComparerType.Construct(typeParameter); // Generate 'retExpression' <= 'retExpression * HASH_FACTOR retExpression = F.Binary(BinaryOperatorKind.IntMultiplication, manager.System_Int32, retExpression, boundHashFactor); // Generate 'retExpression' <= 'retExpression + EqualityComparer<T_index>.Default.GetHashCode(this.backingFld_index)' retExpression = F.Binary(BinaryOperatorKind.IntAddition, manager.System_Int32, retExpression, F.Call( F.StaticCall(constructedEqualityComparer, equalityComparer_get_Default.AsMember(constructedEqualityComparer)), equalityComparer_GetHashCode.AsMember(constructedEqualityComparer), F.Field(F.This(), anonymousType.Properties[index].BackingField))); } // Create a bound block F.CloseMethod(F.Block(F.Return(retExpression))); }
internal static DeclarationModifiers MakeModifiers(NamedTypeSymbol containingType, SyntaxToken firstIdentifier, SyntaxTokenList modifiers, DiagnosticBag diagnostics, out bool modifierErrors) { DeclarationModifiers defaultAccess = (containingType.IsInterface) ? DeclarationModifiers.Public : DeclarationModifiers.Private; DeclarationModifiers allowedModifiers = DeclarationModifiers.AccessibilityMask | DeclarationModifiers.Const | DeclarationModifiers.New | DeclarationModifiers.ReadOnly | DeclarationModifiers.Static | DeclarationModifiers.Volatile | DeclarationModifiers.Fixed | DeclarationModifiers.Unsafe | DeclarationModifiers.Abstract; // filtered out later var errorLocation = new SourceLocation(firstIdentifier); DeclarationModifiers result = ModifierUtils.MakeAndCheckNontypeMemberModifiers( modifiers, defaultAccess, allowedModifiers, errorLocation, diagnostics, out modifierErrors); if ((result & DeclarationModifiers.Abstract) != 0) { diagnostics.Add(ErrorCode.ERR_AbstractField, errorLocation); result &= ~DeclarationModifiers.Abstract; } if ((result & DeclarationModifiers.Fixed) != 0) { if ((result & DeclarationModifiers.Static) != 0) { // The modifier 'static' is not valid for this item diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.StaticKeyword)); } if ((result & DeclarationModifiers.ReadOnly) != 0) { // The modifier 'readonly' is not valid for this item diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.ReadOnlyKeyword)); } if ((result & DeclarationModifiers.Const) != 0) { // The modifier 'const' is not valid for this item diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.ConstKeyword)); } if ((result & DeclarationModifiers.Volatile) != 0) { // The modifier 'volatile' is not valid for this item diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.VolatileKeyword)); } result &= ~(DeclarationModifiers.Static | DeclarationModifiers.ReadOnly | DeclarationModifiers.Const | DeclarationModifiers.Volatile); Debug.Assert((result & ~(DeclarationModifiers.AccessibilityMask | DeclarationModifiers.Fixed | DeclarationModifiers.Unsafe | DeclarationModifiers.New)) == 0); } if ((result & DeclarationModifiers.Const) != 0) { if ((result & DeclarationModifiers.Static) != 0) { // The constant '{0}' cannot be marked static diagnostics.Add(ErrorCode.ERR_StaticConstant, errorLocation, firstIdentifier.ValueText); } if ((result & DeclarationModifiers.ReadOnly) != 0) { // The modifier 'readonly' is not valid for this item diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.ReadOnlyKeyword)); } if ((result & DeclarationModifiers.Volatile) != 0) { // The modifier 'volatile' is not valid for this item diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.VolatileKeyword)); } if ((result & DeclarationModifiers.Unsafe) != 0) { // The modifier 'unsafe' is not valid for this item diagnostics.Add(ErrorCode.ERR_BadMemberFlag, errorLocation, SyntaxFacts.GetText(SyntaxKind.UnsafeKeyword)); } result |= DeclarationModifiers.Static; // "constants are considered static members" } else { // NOTE: always cascading on a const, so suppress. // NOTE: we're being a bit sneaky here - we're using the containingType rather than this symbol // to determine whether or not unsafe is allowed. Since this symbol and the containing type are // in the same compilation, it won't make a difference. We do, however, have to pass the error // location explicitly. containingType.CheckUnsafeModifier(result, errorLocation, diagnostics); } return(result); }
internal static ArrayTypeSymbol CreateSZArray( TypeWithAnnotations elementTypeWithAnnotations, NamedTypeSymbol array) { return(new SZArray(elementTypeWithAnnotations, array, GetSZArrayInterfaces(elementTypeWithAnnotations, array.ContainingAssembly))); }
protected override Location GetCorrespondingBaseListLocation(NamedTypeSymbol @base) { return(NoLocation.Singleton); // No explicit base list }
/// <summary> /// Returns the original virtual or abstract method which a given method symbol overrides, /// ignoring any other overriding methods in base classes. /// Also, if the given method symbol is generic then the resulting virtual or abstract method is constructed with the /// same type arguments as the given method. /// </summary> internal MethodSymbol GetConstructedLeastOverriddenMethod(NamedTypeSymbol accessingTypeOpt) { var m = this.ConstructedFrom.GetLeastOverriddenMethod(accessingTypeOpt); return(m.IsGenericMethod ? m.Construct(this.TypeArgumentsWithAnnotations) : m); }
protected override void CheckInterfaces(BindingDiagnosticBag diagnostics) { // Check declared interfaces and all base interfaces. This is necessary // since references to all interfaces will be emitted to metadata // and it's possible to define derived interfaces with weaker // constraints than the base interfaces, at least in metadata. var interfaces = this.InterfacesAndTheirBaseInterfacesNoUseSiteDiagnostics; if (interfaces.IsEmpty) { // nothing to verify return; } // Check constraints on the first declaration with explicit bases. var singleDeclaration = this.FirstDeclarationWithExplicitBases(); if (singleDeclaration != null) { var corLibrary = this.ContainingAssembly.CorLibrary; var conversions = new TypeConversions(corLibrary); var location = singleDeclaration.NameLocation; foreach (var pair in interfaces) { MultiDictionary <NamedTypeSymbol, NamedTypeSymbol> .ValueSet set = pair.Value; foreach (var @interface in set) { @interface.CheckAllConstraints(DeclaringCompilation, conversions, location, diagnostics); } if (set.Count > 1) { NamedTypeSymbol other = pair.Key; foreach (var @interface in set) { if ((object)other == @interface) { continue; } // InterfacesAndTheirBaseInterfacesNoUseSiteDiagnostics populates the set with interfaces that match by CLR signature. Debug.Assert(!other.Equals(@interface, TypeCompareKind.ConsiderEverything)); Debug.Assert(other.Equals(@interface, TypeCompareKind.CLRSignatureCompareOptions)); if (other.Equals(@interface, TypeCompareKind.IgnoreNullableModifiersForReferenceTypes)) { if (!other.Equals(@interface, TypeCompareKind.ObliviousNullableModifierMatchesAny)) { diagnostics.Add(ErrorCode.WRN_DuplicateInterfaceWithNullabilityMismatchInBaseList, location, @interface, this); } } else if (other.Equals(@interface, TypeCompareKind.IgnoreTupleNames | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes)) { diagnostics.Add(ErrorCode.ERR_DuplicateInterfaceWithTupleNamesInBaseList, location, @interface, other, this); } else { diagnostics.Add(ErrorCode.ERR_DuplicateInterfaceWithDifferencesInBaseList, location, @interface, other, this); } } } } } }
internal SynthesizedInstanceConstructor(NamedTypeSymbol containingType) { Debug.Assert((object)containingType != null); _containingType = containingType; }
public SubstitutedNestedErrorTypeSymbol(NamedTypeSymbol containingSymbol, ErrorTypeSymbol originalDefinition) : base(originalDefinition) { _containingSymbol = containingSymbol; _map = containingSymbol.TypeSubstitution.WithAlphaRename(originalDefinition, this, out _typeParameters); }
/// <summary> /// SubstType, but for NamedTypeSymbols only. This is used for concrete types, so no alpha substitution appears in the result. /// </summary> internal NamedTypeSymbol SubstituteNamedType(NamedTypeSymbol previous) { if (ReferenceEquals(previous, null)) { return(null); } if (previous.IsUnboundGenericType) { return(previous); } if (previous.IsAnonymousType) { ImmutableArray <TypeSymbol> oldFieldTypes = AnonymousTypeManager.GetAnonymousTypePropertyTypes(previous); ImmutableArray <TypeSymbol> newFieldTypes = SubstituteTypesWithoutModifiers(oldFieldTypes); return((oldFieldTypes == newFieldTypes) ? previous : AnonymousTypeManager.ConstructAnonymousTypeSymbol(previous, newFieldTypes)); } if (previous.IsTupleType) { var previousTuple = (TupleTypeSymbol)previous; NamedTypeSymbol oldUnderlyingType = previousTuple.TupleUnderlyingType; NamedTypeSymbol newUnderlyingType = (NamedTypeSymbol)SubstituteType(oldUnderlyingType).Type; return(((object)newUnderlyingType == (object)oldUnderlyingType) ? previous : previousTuple.WithUnderlyingType(newUnderlyingType)); } // TODO: we could construct the result's ConstructedFrom lazily by using a "deep" // construct operation here (as VB does), thereby avoiding alpha renaming in most cases. // Aleksey has shown that would reduce GC pressure if substitutions of deeply nested generics are common. NamedTypeSymbol oldConstructedFrom = previous.ConstructedFrom; NamedTypeSymbol newConstructedFrom = SubstituteMemberType(oldConstructedFrom); ImmutableArray <TypeSymbol> oldTypeArguments = previous.TypeArgumentsNoUseSiteDiagnostics; bool changed = !ReferenceEquals(oldConstructedFrom, newConstructedFrom); ImmutableArray <ImmutableArray <CustomModifier> > modifiers = previous.HasTypeArgumentsCustomModifiers ? previous.TypeArgumentsCustomModifiers : default(ImmutableArray <ImmutableArray <CustomModifier> >); var newTypeArguments = ArrayBuilder <TypeWithModifiers> .GetInstance(oldTypeArguments.Length); for (int i = 0; i < oldTypeArguments.Length; i++) { var oldArgument = modifiers.IsDefault ? new TypeWithModifiers(oldTypeArguments[i]) : new TypeWithModifiers(oldTypeArguments[i], modifiers[i]); var newArgument = oldArgument.SubstituteTypeWithTupleUnification(this); if (!changed && oldArgument != newArgument) { changed = true; } newTypeArguments.Add(newArgument); } if (!changed) { newTypeArguments.Free(); return(previous); } return(newConstructedFrom.ConstructIfGeneric(newTypeArguments.ToImmutableAndFree())); }
internal override NamedTypeSymbol AsMember(NamedTypeSymbol newOwner) { Debug.Assert(this.IsDefinition); Debug.Assert(ReferenceEquals(newOwner.OriginalDefinition, this.ContainingSymbol?.OriginalDefinition)); return(newOwner.IsDefinition ? this : new SubstitutedNestedErrorTypeSymbol(newOwner, this)); }
internal SynthesizedStaticConstructor(NamedTypeSymbol containingType) { this.containingType = containingType; }
internal MethodSymbol AsMember(NamedTypeSymbol newOwner) { Debug.Assert(this.IsDefinition); Debug.Assert(ReferenceEquals(newOwner.OriginalDefinition, this.ContainingSymbol.OriginalDefinition)); return((newOwner == this.ContainingSymbol) ? this : new SubstitutedMethodSymbol(newOwner, this)); }
public SynthesizedDefaultShimMethod(MethodSymbol conceptMethod, NamedTypeSymbol defaultStruct, NamedTypeSymbol implementingType) : base(conceptMethod, implementingType) { _defaultStruct = defaultStruct; }
protected override Location GetCorrespondingBaseListLocation(NamedTypeSymbol @base) { // A script class may implement interfaces in hosted scenarios. // The interface definitions are specified via API, not in compilation source. return(NoLocation.Singleton); }