提交 65f24c70 编写于 作者: T TomasMatousek

In C# lowering of async method stored the state machine type on...

In C# lowering of async method stored the state machine type on SourceMethodSymbol so it can later be used when emitting synthesized attributes of the method. This may cause issues when emitting the same compilation twice with different options that affect the state machine type.
     Instead we should store the state machine type to the current PEModuleBuilder. Rather then actually storing it there and adding a dependency on PEModuleBuilder to the attribute generation this change introduces ModuleCompilationState (similar to TypeCompilationState) and threads that one.
     This type is designed to be mutable during compilation (lowering) and immutable during emit. The idea is that all data currently stored in PEModuleBuilder that are produced during compilation and only read in emit could be moved there. Only emit specific data would remain on PEModuleBuilder.

     Also refactors Compilation.Compile to remove some duplication and make it cleaner.
 (changeset 1249664)
上级 6f2e0b6d
......@@ -248,6 +248,7 @@
<Compile Include="Compiler\MethodCompiler.cs" />
<Compile Include="Compiler\MethodBodySynthesizer.cs" />
<Compile Include="Compiler\MethodBodySynthesizer.Lowered.cs" />
<Compile Include="Compiler\ModuleCompilationState.cs" />
<Compile Include="Compiler\NamespaceScopeBuilder.cs" />
<Compile Include="Compiler\SynthesizedMetadataCompiler.cs" />
<Compile Include="Compiler\TypeCompilationState.cs" />
......
......@@ -53,11 +53,11 @@ protected override bool ReturnValueIsModified
}
}
protected override ImmutableArray<Cci.ICustomModifier> ReturnValueCustomModifiers
protected override IEnumerable<Cci.ICustomModifier> ReturnValueCustomModifiers
{
get
{
return UnderlyingProperty.TypeCustomModifiers.As<Cci.ICustomModifier>();
return UnderlyingProperty.TypeCustomModifiers;
}
}
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -65,8 +65,7 @@ public TypeSymbol Type
/// <summary>
/// If this field serves as a backing variable for an automatically generated
/// property or a field-like event or a Primary Constructor Parameter, returns that
/// property/event/parameter. Otherwise returns null.
/// property or a field-like event, returns that property/event. Otherwise returns null.
/// Note, the set of possible associated symbols might be expanded in the future to
/// reflect changes in the languages.
/// </summary>
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
......@@ -581,14 +581,6 @@ public override ImmutableArray<SyntaxReference> DeclaringSyntaxReferences
}
}
internal override FieldSymbol PrimaryConstructorParameterBackingField
{
get
{
return null;
}
}
public override ImmutableArray<CSharpAttributeData> GetAttributes()
{
if (this.lazyCustomAttributes.IsDefault)
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -236,20 +236,6 @@ internal sealed override bool HasByRefBeforeCustomModifiers
get { return underlyingParameter.HasByRefBeforeCustomModifiers; }
}
internal sealed override FieldSymbol PrimaryConstructorParameterBackingField
{
get
{
FieldSymbol backingField = underlyingParameter.PrimaryConstructorParameterBackingField;
if ((object)backingField != null)
{
return this.RetargetingModule.RetargetingTranslator.Retarget(backingField);
}
return null;
}
}
#endregion
}
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.CSharp.Symbols;
......@@ -17,7 +17,7 @@ internal sealed class SourceEventFieldSymbol : SourceMemberFieldSymbol
private readonly SourceEventSymbol associatedEvent;
internal SourceEventFieldSymbol(SourceEventSymbol associatedEvent, VariableDeclaratorSyntax declaratorSyntax, DiagnosticBag discardedDiagnostics)
: base(associatedEvent.containingType, declaratorSyntax, (associatedEvent.Modifiers & (~DeclarationModifiers.AccessibilityMask)) | DeclarationModifiers.Private, modifierErrors: true, diagnostics: discardedDiagnostics)
: base(associatedEvent.containingType, declaratorSyntax, associatedEvent.Modifiers, modifierErrors: true, diagnostics: discardedDiagnostics)
{
this.associatedEvent = associatedEvent;
}
......@@ -46,6 +46,14 @@ public override Symbol AssociatedSymbol
}
}
public override Accessibility DeclaredAccessibility
{
get
{
return Accessibility.Private;
}
}
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes)
{
base.AddSynthesizedAttributes(compilationState, ref attributes);
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
......@@ -21,13 +21,27 @@ internal abstract class SourceFieldSymbol : FieldSymbol, IAttributeTargetSymbol
{
protected SymbolCompletionState state;
protected readonly SourceMemberContainerTypeSymbol containingType;
private readonly string name;
private readonly Location location;
private readonly SyntaxReference syntaxReference;
private string lazyDocComment;
private CustomAttributesBag<CSharpAttributeData> lazyCustomAttributesBag;
protected SourceFieldSymbol(SourceMemberContainerTypeSymbol containingType)
private ConstantValue lazyConstantEarlyDecodingValue = Microsoft.CodeAnalysis.ConstantValue.Unset;
private ConstantValue lazyConstantValue = Microsoft.CodeAnalysis.ConstantValue.Unset;
protected SourceFieldSymbol(SourceMemberContainerTypeSymbol containingType, string name, SyntaxReference syntax, Location location)
{
Debug.Assert((object)containingType != null);
Debug.Assert(name != null);
Debug.Assert(syntax != null);
Debug.Assert(location != null);
this.containingType = containingType;
this.name = name;
this.syntaxReference = syntax;
this.location = location;
}
internal sealed override bool RequiresCompletion
......@@ -45,129 +59,80 @@ internal override void ForceComplete(SourceLocation locationOpt, CancellationTok
state.DefaultForceComplete(this);
}
public abstract override string Name { get; }
protected abstract DeclarationModifiers Modifiers { get; }
public sealed override bool IsStatic
public SyntaxTree SyntaxTree
{
get
{
return (Modifiers & DeclarationModifiers.Static) != 0;
return this.syntaxReference.SyntaxTree;
}
}
public sealed override bool IsReadOnly
public CSharpSyntaxNode SyntaxNode
{
get
{
return (Modifiers & DeclarationModifiers.ReadOnly) != 0;
return (CSharpSyntaxNode)this.syntaxReference.GetSyntax();
}
}
public sealed override bool IsConst
public sealed override string Name
{
get
{
return (Modifiers & DeclarationModifiers.Const) != 0;
return name;
}
}
public sealed override bool IsVolatile
public sealed override Symbol ContainingSymbol
{
get
{
return (Modifiers & DeclarationModifiers.Volatile) != 0;
return containingType;
}
}
public sealed override bool IsFixed
public override NamedTypeSymbol ContainingType
{
get
{
return (Modifiers & DeclarationModifiers.Fixed) != 0;
return this.containingType;
}
}
internal bool IsNew
internal override LexicalSortKey GetLexicalSortKey()
{
get
{
return (Modifiers & DeclarationModifiers.New) != 0;
}
return new LexicalSortKey(location, this.DeclaringCompilation);
}
public sealed override Accessibility DeclaredAccessibility
public sealed override ImmutableArray<Location> Locations
{
get
{
return ModifierUtils.EffectiveAccessibility(Modifiers);
}
}
protected void CheckAccessibility(DiagnosticBag diagnostics)
{
var info = ModifierUtils.CheckAccessibility(Modifiers);
if (info != null)
{
diagnostics.Add(new CSDiagnostic(info, this.ErrorLocation));
}
}
protected void ReportModifiersDiagnostics(DiagnosticBag diagnostics)
{
if (containingType.IsSealed && (DeclaredAccessibility == Accessibility.Protected || DeclaredAccessibility == Accessibility.ProtectedOrInternal))
{
diagnostics.Add(AccessCheck.GetProtectedMemberInSealedTypeError(containingType), ErrorLocation, this);
}
else if (IsVolatile && IsReadOnly)
{
diagnostics.Add(ErrorCode.ERR_VolatileAndReadonly, ErrorLocation, this);
}
else if (containingType.IsStatic && !IsStatic)
{
diagnostics.Add(ErrorCode.ERR_InstanceMemberInStaticClass, ErrorLocation, this);
return ImmutableArray.Create(location);
}
// TODO: Consider checking presence of core type System.Runtime.CompilerServices.IsVolatile
// if there is a volatile modifier. Perhaps an appropriate error should be reported if the
// type isn't available.
}
public override ImmutableArray<CustomModifier> CustomModifiers
internal Location Location
{
get
{
if (!IsVolatile)
{
return ImmutableArray<CustomModifier>.Empty;
}
else
{
return ImmutableArray.Create<CustomModifier>(
CSharpCustomModifier.CreateRequired(this.ContainingAssembly.GetSpecialType(SpecialType.System_Runtime_CompilerServices_IsVolatile)));
}
return location;
}
}
public sealed override Symbol ContainingSymbol
public sealed override ImmutableArray<SyntaxReference> DeclaringSyntaxReferences
{
get
{
return containingType;
return ImmutableArray.Create<SyntaxReference>(syntaxReference);
}
}
public override NamedTypeSymbol ContainingType
public sealed override string GetDocumentationCommentXml(CultureInfo preferredCulture = null, bool expandIncludes = false, CancellationToken cancellationToken = default(CancellationToken))
{
get
{
return this.containingType;
}
return SourceDocumentationCommentUtils.GetAndCacheDocumentationComment(this, expandIncludes, ref lazyDocComment);
}
internal abstract Location ErrorLocation { get; }
/// <summary>
/// Gets the syntax list of custom attributes applied on the symbol.
/// </summary>
......@@ -274,7 +239,7 @@ internal sealed override CSharpAttributeData EarlyDecodeWellKnownAttribute(ref E
if (obsoleteData != null)
{
arguments.GetOrCreateData<CommonFieldEarlyWellKnownAttributeData>().ObsoleteAttributeData = obsoleteData;
}
}
return boundAttribute;
}
......@@ -449,7 +414,7 @@ internal override void PostDecodeWellKnownAttributes(ImmutableArray<CSharpAttrib
if (this.ContainingType.Layout.Kind == LayoutKind.Explicit)
{
// error CS0625: '<field>': instance field types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute
diagnostics.Add(ErrorCode.ERR_MissingStructOffset, this.ErrorLocation, this);
diagnostics.Add(ErrorCode.ERR_MissingStructOffset, this.Location, this);
}
}
......@@ -516,89 +481,6 @@ internal sealed override MarshalPseudoCustomAttributeData MarshallingInformation
}
}
}
internal abstract class SourceFieldSymbolWithSyntaxReference : SourceFieldSymbol
{
private readonly string name;
private readonly Location location;
private readonly SyntaxReference syntaxReference;
private string lazyDocComment;
private ConstantValue lazyConstantEarlyDecodingValue = Microsoft.CodeAnalysis.ConstantValue.Unset;
private ConstantValue lazyConstantValue = Microsoft.CodeAnalysis.ConstantValue.Unset;
protected SourceFieldSymbolWithSyntaxReference(SourceMemberContainerTypeSymbol containingType, string name, SyntaxReference syntax, Location location)
: base(containingType)
{
Debug.Assert(name != null);
Debug.Assert(syntax != null);
Debug.Assert(location != null);
this.name = name;
this.syntaxReference = syntax;
this.location = location;
}
public SyntaxTree SyntaxTree
{
get
{
return this.syntaxReference.SyntaxTree;
}
}
public CSharpSyntaxNode SyntaxNode
{
get
{
return (CSharpSyntaxNode)this.syntaxReference.GetSyntax();
}
}
public sealed override string Name
{
get
{
return name;
}
}
internal override LexicalSortKey GetLexicalSortKey()
{
return new LexicalSortKey(location, this.DeclaringCompilation);
}
public sealed override ImmutableArray<Location> Locations
{
get
{
return ImmutableArray.Create(location);
}
}
internal sealed override Location ErrorLocation
{
get
{
return location;
}
}
public sealed override ImmutableArray<SyntaxReference> DeclaringSyntaxReferences
{
get
{
return ImmutableArray.Create<SyntaxReference>(syntaxReference);
}
}
public sealed override string GetDocumentationCommentXml(CultureInfo preferredCulture = null, bool expandIncludes = false, CancellationToken cancellationToken = default(CancellationToken))
{
return SourceDocumentationCommentUtils.GetAndCacheDocumentationComment(this, expandIncludes, ref lazyDocComment);
}
internal sealed override ConstantValue GetConstantValue(ConstantFieldsInProgress inProgress, bool earlyDecodingWellKnownAttributes)
{
var value = this.GetLazyConstantValue(earlyDecodingWellKnownAttributes);
......@@ -608,7 +490,7 @@ internal sealed override ConstantValue GetConstantValue(ConstantFieldsInProgress
}
if (!inProgress.IsEmpty)
{
{
// Add this field as a dependency of the original field, and
// return Unset. The outer GetConstantValue caller will call
// this method again after evaluating any dependencies.
......@@ -642,7 +524,7 @@ internal sealed override ConstantValue GetConstantValue(ConstantFieldsInProgress
/// constant value if there were no dependencies. (If there are dependencies,
/// the constant value will be re-evaluated after evaluating dependencies.)
/// </summary>
internal ImmutableHashSet<SourceFieldSymbolWithSyntaxReference> GetConstantValueDependencies(bool earlyDecodingWellKnownAttributes)
internal ImmutableHashSet<SourceFieldSymbol> GetConstantValueDependencies(bool earlyDecodingWellKnownAttributes)
{
var value = this.GetLazyConstantValue(earlyDecodingWellKnownAttributes);
if (value != Microsoft.CodeAnalysis.ConstantValue.Unset)
......@@ -650,12 +532,12 @@ internal ImmutableHashSet<SourceFieldSymbolWithSyntaxReference> GetConstantValue
// Constant value already determined. No need to
// compute dependencies since the constant values
// of all dependencies should be evaluated as well.
return ImmutableHashSet<SourceFieldSymbolWithSyntaxReference>.Empty;
return ImmutableHashSet<SourceFieldSymbol>.Empty;
}
ImmutableHashSet<SourceFieldSymbolWithSyntaxReference> dependencies;
var builder = PooledHashSet<SourceFieldSymbolWithSyntaxReference>.GetInstance();
var diagnostics = DiagnosticBag.GetInstance();
ImmutableHashSet<SourceFieldSymbol> dependencies;
var builder = PooledHashSet<SourceFieldSymbol>.GetInstance();
var diagnostics = DiagnosticBag.GetInstance();
value = MakeConstantValue(builder, earlyDecodingWellKnownAttributes, diagnostics);
// Only persist if there are no dependencies and the calculation
......@@ -672,14 +554,14 @@ internal ImmutableHashSet<SourceFieldSymbolWithSyntaxReference> GetConstantValue
earlyDecodingWellKnownAttributes,
diagnostics,
startsCycle: false);
dependencies = ImmutableHashSet<SourceFieldSymbolWithSyntaxReference>.Empty;
dependencies = ImmutableHashSet<SourceFieldSymbol>.Empty;
}
else
{
dependencies = ImmutableHashSet<SourceFieldSymbolWithSyntaxReference>.Empty.Union(builder);
dependencies = ImmutableHashSet<SourceFieldSymbol>.Empty.Union(builder);
}
diagnostics.Free();
diagnostics.Free();
builder.Free();
return dependencies;
}
......@@ -689,14 +571,14 @@ private void BindConstantValueIfNecessary(bool earlyDecodingWellKnownAttributes,
if (this.GetLazyConstantValue(earlyDecodingWellKnownAttributes) != Microsoft.CodeAnalysis.ConstantValue.Unset)
{
return;
}
}
var builder = PooledHashSet<SourceFieldSymbolWithSyntaxReference>.GetInstance();
var builder = PooledHashSet<SourceFieldSymbol>.GetInstance();
var diagnostics = DiagnosticBag.GetInstance();
if (startsCycle)
{
{
diagnostics.Add(ErrorCode.ERR_CircConstValue, this.location, this);
}
}
var value = MakeConstantValue(builder, earlyDecodingWellKnownAttributes, diagnostics);
this.SetLazyConstantValue(
......@@ -704,14 +586,14 @@ private void BindConstantValueIfNecessary(bool earlyDecodingWellKnownAttributes,
earlyDecodingWellKnownAttributes,
diagnostics,
startsCycle);
diagnostics.Free();
diagnostics.Free();
builder.Free();
}
private ConstantValue GetLazyConstantValue(bool earlyDecodingWellKnownAttributes)
{
return earlyDecodingWellKnownAttributes ? this.lazyConstantEarlyDecodingValue : this.lazyConstantValue;
}
}
private void SetLazyConstantValue(
ConstantValue value,
......@@ -740,6 +622,6 @@ private ConstantValue GetLazyConstantValue(bool earlyDecodingWellKnownAttributes
}
}
protected abstract ConstantValue MakeConstantValue(HashSet<SourceFieldSymbolWithSyntaxReference> dependencies, bool earlyDecodingWellKnownAttributes, DiagnosticBag diagnostics);
protected abstract ConstantValue MakeConstantValue(HashSet<SourceFieldSymbol> dependencies, bool earlyDecodingWellKnownAttributes, DiagnosticBag diagnostics);
}
}
......@@ -3,7 +3,6 @@
using Microsoft.CodeAnalysis.CSharp.Emit;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Roslyn.Utilities;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
......@@ -12,7 +11,7 @@
namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
internal class SourceMemberFieldSymbol : SourceFieldSymbolWithSyntaxReference
internal class SourceMemberFieldSymbol : SourceFieldSymbol
{
private readonly DeclarationModifiers modifiers;
......@@ -36,18 +35,27 @@ internal class SourceMemberFieldSymbol : SourceFieldSymbolWithSyntaxReference
this.CheckAccessibility(diagnostics);
if (!modifierErrors)
var location = Location;
if (modifierErrors)
{
this.ReportModifiersDiagnostics(diagnostics);
// skip the following checks
}
else if (containingType.IsSealed && (DeclaredAccessibility == Accessibility.Protected || DeclaredAccessibility == Accessibility.ProtectedOrInternal))
{
diagnostics.Add(AccessCheck.GetProtectedMemberInSealedTypeError(containingType), location, this);
}
protected sealed override DeclarationModifiers Modifiers
else if (IsVolatile && IsReadOnly)
{
get
diagnostics.Add(ErrorCode.ERR_VolatileAndReadonly, location, this);
}
else if (containingType.IsStatic && !IsStatic)
{
return modifiers;
diagnostics.Add(ErrorCode.ERR_InstanceMemberInStaticClass, location, this);
}
// TODO: Consider checking presence of core type System.Runtime.CompilerServices.IsVolatile
// if there is a volatile modifier. Perhaps an appropriate error should be reported if the
// type isn’t available.
}
private void TypeChecks(TypeSymbol type, BaseFieldDeclarationSyntax fieldSyntax, VariableDeclaratorSyntax declarator, DiagnosticBag diagnostics)
......@@ -55,7 +63,7 @@ private void TypeChecks(TypeSymbol type, BaseFieldDeclarationSyntax fieldSyntax,
if (type.IsStatic)
{
// Cannot declare a variable of static type '{0}'
diagnostics.Add(ErrorCode.ERR_VarDeclIsStaticClass, this.ErrorLocation, type);
diagnostics.Add(ErrorCode.ERR_VarDeclIsStaticClass, this.Location, type);
}
else if (type.SpecialType == SpecialType.System_Void)
{
......@@ -88,14 +96,14 @@ private void TypeChecks(TypeSymbol type, BaseFieldDeclarationSyntax fieldSyntax,
if (initializerOpt != null)
{
// '{0}': cannot have instance field initializers in structs
diagnostics.Add(ErrorCode.ERR_FieldInitializerInStruct, this.ErrorLocation, this);
diagnostics.Add(ErrorCode.ERR_FieldInitializerInStruct, this.Location, this);
}
}
if (IsVolatile && !type.IsValidVolatileFieldType())
{
// '{0}': a volatile field cannot be of the type '{1}'
diagnostics.Add(ErrorCode.ERR_VolatileStruct, this.ErrorLocation, this, type);
diagnostics.Add(ErrorCode.ERR_VolatileStruct, this.Location, this, type);
}
}
......@@ -103,10 +111,10 @@ private void TypeChecks(TypeSymbol type, BaseFieldDeclarationSyntax fieldSyntax,
if (!this.IsNoMoreVisibleThan(type, ref useSiteDiagnostics))
{
// Inconsistent accessibility: field type '{1}' is less accessible than field '{0}'
diagnostics.Add(ErrorCode.ERR_BadVisFieldType, this.ErrorLocation, this, type);
diagnostics.Add(ErrorCode.ERR_BadVisFieldType, this.Location, this, type);
}
diagnostics.Add(this.ErrorLocation, useSiteDiagnostics);
diagnostics.Add(this.Location, useSiteDiagnostics);
}
public VariableDeclaratorSyntax VariableDeclaratorNode
......@@ -124,7 +132,7 @@ private static BaseFieldDeclarationSyntax GetFieldDeclaration(CSharpSyntaxNode d
protected override SyntaxList<AttributeListSyntax> AttributeDeclarationSyntaxList
{
get
get
{
if (this.containingType.AnyMemberHasAttributes)
{
......@@ -201,7 +209,7 @@ internal sealed override TypeSymbol GetFieldType(ConsList<FieldSymbol> fieldsBei
if (@event.IsWindowsRuntimeEvent)
{
NamedTypeSymbol tokenTableType = this.DeclaringCompilation.GetWellKnownType(WellKnownType.System_Runtime_InteropServices_WindowsRuntime_EventRegistrationTokenTable_T);
Binder.ReportUseSiteDiagnostics(tokenTableType, diagnosticsForFirstDeclarator, this.ErrorLocation);
Binder.ReportUseSiteDiagnostics(tokenTableType, diagnosticsForFirstDeclarator, this.Location);
// CONSIDER: Do we want to guard against the possibility that someone has created their own EventRegistrationTokenTable<T>
// type that has additional generic constraints?
......@@ -242,7 +250,7 @@ internal sealed override TypeSymbol GetFieldType(ConsList<FieldSymbol> fieldsBei
if (fieldsBeingBound.ContainsReference(this))
{
diagnostics.Add(ErrorCode.ERR_RecursivelyTypedVariable, this.ErrorLocation, this);
diagnostics.Add(ErrorCode.ERR_RecursivelyTypedVariable, this.Location, this);
type = null;
}
else if (fieldSyntax.Declaration.Variables.Count > 1)
......@@ -278,17 +286,17 @@ internal sealed override TypeSymbol GetFieldType(ConsList<FieldSymbol> fieldsBei
{
if (ContainingType.TypeKind != TypeKind.Struct)
{
diagnostics.Add(ErrorCode.ERR_FixedNotInStruct, ErrorLocation);
diagnostics.Add(ErrorCode.ERR_FixedNotInStruct, Location);
}
if (IsStatic)
{
diagnostics.Add(ErrorCode.ERR_BadMemberFlag, ErrorLocation, SyntaxFacts.GetText(SyntaxKind.StaticKeyword));
diagnostics.Add(ErrorCode.ERR_BadMemberFlag, Location, SyntaxFacts.GetText(SyntaxKind.StaticKeyword));
}
if (IsVolatile)
{
diagnostics.Add(ErrorCode.ERR_BadMemberFlag, ErrorLocation, SyntaxFacts.GetText(SyntaxKind.VolatileKeyword));
diagnostics.Add(ErrorCode.ERR_BadMemberFlag, Location, SyntaxFacts.GetText(SyntaxKind.VolatileKeyword));
}
var elementType = ((PointerTypeSymbol)type).PointedAtType;
......@@ -312,7 +320,7 @@ internal sealed override TypeSymbol GetFieldType(ConsList<FieldSymbol> fieldsBei
TypeChecks(type, fieldSyntax, declarator, diagnostics);
// CONSIDER: SourceEventFieldSymbol would like to suppress these diagnostics.
compilation.SemanticDiagnostics.AddRange(diagnostics);
compilation.SemanticDiagnostics.AddRange(diagnostics);
bool isFirstDeclarator = fieldSyntax.Declaration.Variables[0] == declarator;
if (isFirstDeclarator)
......@@ -369,14 +377,54 @@ public override Symbol AssociatedSymbol
}
}
protected sealed override ConstantValue MakeConstantValue(HashSet<SourceFieldSymbolWithSyntaxReference> dependencies, bool earlyDecodingWellKnownAttributes, DiagnosticBag diagnostics)
public sealed override bool IsStatic
{
get
{
return (modifiers & DeclarationModifiers.Static) != 0;
}
}
public sealed override bool IsReadOnly
{
get
{
return (modifiers & DeclarationModifiers.ReadOnly) != 0;
}
}
public sealed override bool IsConst
{
get
{
return (modifiers & DeclarationModifiers.Const) != 0;
}
}
protected sealed override ConstantValue MakeConstantValue(HashSet<SourceFieldSymbol> dependencies, bool earlyDecodingWellKnownAttributes, DiagnosticBag diagnostics)
{
EqualsValueClauseSyntax initializer;
return !this.IsConst || ((initializer = VariableDeclaratorNode.Initializer) == null)
return !this.IsConst || ((initializer = VariableDeclaratorNode.Initializer) == null)
? null
: ConstantValueUtils.EvaluateFieldConstant(this, initializer, dependencies, earlyDecodingWellKnownAttributes, diagnostics);
}
public sealed override bool IsVolatile
{
get
{
return (modifiers & DeclarationModifiers.Volatile) != 0;
}
}
public sealed override bool IsFixed
{
get
{
return (modifiers & DeclarationModifiers.Fixed) != 0;
}
}
public override int FixedSize
{
get
......@@ -392,7 +440,32 @@ public override int FixedSize
}
}
internal static DeclarationModifiers MakeModifiers(NamedTypeSymbol containingType, SyntaxToken firstIdentifier, SyntaxTokenList modifiers, DiagnosticBag diagnostics, out bool modifierErrors, bool ignoreParameterModifiers = false)
internal bool IsNew
{
get
{
return (modifiers & DeclarationModifiers.New) != 0;
}
}
public override Accessibility DeclaredAccessibility
{
get
{
return ModifierUtils.EffectiveAccessibility(this.modifiers);
}
}
private void CheckAccessibility(DiagnosticBag diagnostics)
{
var info = ModifierUtils.CheckAccessibility(modifiers);
if (info != null)
{
diagnostics.Add(new CSDiagnostic(info, this.Location));
}
}
internal static DeclarationModifiers MakeModifiers(NamedTypeSymbol containingType, BaseFieldDeclarationSyntax fieldSyntax, DiagnosticBag diagnostics, out bool modifierErrors)
{
DeclarationModifiers defaultAccess =
(containingType.IsInterface) ? DeclarationModifiers.Public : DeclarationModifiers.Private;
......@@ -408,9 +481,10 @@ internal static DeclarationModifiers MakeModifiers(NamedTypeSymbol containingTyp
DeclarationModifiers.Unsafe |
DeclarationModifiers.Abstract; // filtered out later
var firstIdentifier = fieldSyntax.Declaration.Variables[0].Identifier;
var errorLocation = new SourceLocation(firstIdentifier);
DeclarationModifiers result = ModifierUtils.MakeAndCheckNontypeMemberModifiers(
modifiers, defaultAccess, allowedModifiers, errorLocation, diagnostics, out modifierErrors, ignoreParameterModifiers);
fieldSyntax.Modifiers, defaultAccess, allowedModifiers, errorLocation, diagnostics, out modifierErrors);
if ((result & DeclarationModifiers.Abstract) != 0)
{
......@@ -465,7 +539,17 @@ public sealed override ImmutableArray<CustomModifier> CustomModifiers
{
if (lazyCustomModifiers.IsDefault)
{
ImmutableInterlocked.InterlockedCompareExchange(ref lazyCustomModifiers, base.CustomModifiers, default(ImmutableArray<CustomModifier>));
if (!IsVolatile)
{
lazyCustomModifiers = ImmutableArray<CustomModifier>.Empty;
}
else
{
ImmutableInterlocked.InterlockedCompareExchange(ref lazyCustomModifiers,
ImmutableArray.Create<CustomModifier>(
CSharpCustomModifier.CreateRequired(this.ContainingAssembly.GetSpecialType(SpecialType.System_Runtime_CompilerServices_IsVolatile))),
default(ImmutableArray<CustomModifier>));
}
}
return lazyCustomModifiers;
......@@ -531,4 +615,4 @@ internal override bool IsDefinedInSourceTree(SyntaxTree tree, TextSpan? definedW
return false;
}
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Diagnostics;
......@@ -561,7 +561,7 @@ internal override int ParameterCount
{
return !this.lazyParameters.IsDefault
? this.lazyParameters.Length
: ((MethodDeclarationSyntax)syntaxReference.GetSyntax()).ParameterList.ParameterCount;
: ((MethodDeclarationSyntax)syntaxReference.GetSyntax()).ParameterCount;
}
}
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Roslyn.Utilities;
......@@ -168,7 +168,6 @@ private static bool ModifiersRequireMetadataVirtual(DeclarationModifiers modifie
bool isExtensionMethod,
bool isMetadataVirtualIgnoringModifiers = false)
{
Debug.Assert((declarationModifiers & DeclarationModifiers.PrimaryCtor) == 0 || methodKind == MethodKind.Constructor);
bool isMetadataVirtual = isMetadataVirtualIgnoringModifiers || ModifiersRequireMetadataVirtual(declarationModifiers);
int methodKindInt = ((int)methodKind << MethodKindOffset) & MethodKindMask;
......@@ -403,22 +402,6 @@ public sealed override bool IsExtern
}
}
/// <summary>
/// Is this a declaration of a Primary constructor?
/// Note, more than one constructor in a type can return true for this property.
/// This happens for an error situation when more than one partial declaration declares Primary
/// Constructor. We will create a constructor symbol for each of them and all of them will have
/// IsPrimaryCtor == true. However, The first one that we create will be the "main" Primary Constructor,
/// SourceMemberContainerTypeSymbol.PrimaryCtor property returns it.
/// </summary>
public bool IsPrimaryCtor
{
get
{
return (this.DeclarationModifiers & DeclarationModifiers.PrimaryCtor) != 0;
}
}
public sealed override bool IsSealed
{
get
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -372,17 +372,9 @@ AttributeLocation IAttributeTargetSymbol.AllowedAttributeLocations
return AttributeLocation.Type | AttributeLocation.Return;
case TypeKind.Enum:
case TypeKind.Interface:
return AttributeLocation.Type;
case TypeKind.Struct:
case TypeKind.Interface:
case TypeKind.Class:
if ((object)this.PrimaryCtor != null)
{
// Primary Constructor attributes go on the type.
return AttributeLocation.Type | AttributeLocation.Method;
}
return AttributeLocation.Type;
default:
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Diagnostics;
......@@ -96,7 +96,7 @@ internal sealed class SourcePropertyAccessorSymbol : SourceMethodSymbol
// Private accessors cannot be virtual.
propertyModifiers &= ~DeclarationModifiers.Virtual;
}
declarationModifiers |= propertyModifiers & ~DeclarationModifiers.Indexer;
declarationModifiers |= propertyModifiers;
// ReturnsVoid property is overridden in this class so
// returnsVoid argument to MakeFlags is ignored.
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
......@@ -973,7 +973,7 @@ public void OptionalParameters()
void M(C c)
{
int x;
x = this[]; //CS0443 - can't omit all
x = c[]; //CS0443 - can't omit all
x = c[x: 0];
x = c[y: ""hello""];
x = c[z:'a'];
......@@ -984,7 +984,7 @@ void M(C c)
}
}";
CreateCompilationWithMscorlib(source).VerifyDiagnostics(
// (8,18): error CS0443: Syntax error; value expected
// (8,15): error CS0443: Syntax error; value expected
Diagnostic(ErrorCode.ERR_ValueExpected, "]"));
}
......@@ -1000,7 +1000,7 @@ public void ParameterArray()
void M(C c)
{
int x;
x = this[]; //CS0443 - can't omit all
x = c[]; //CS0443 - can't omit all
x = c[0];
x = c[0, 1];
......@@ -1019,7 +1019,7 @@ void M(C c)
}
}";
CreateCompilationWithMscorlib(source).VerifyDiagnostics(
// (9,18): error CS0443: Syntax error; value expected
// (9,15): error CS0443: Syntax error; value expected
Diagnostic(ErrorCode.ERR_ValueExpected, "]"));
}
......
......@@ -187,6 +187,7 @@
<Compile Include="DocumentationMode.cs" />
<Compile Include="Emit\AnonymousTypeKey.cs" />
<Compile Include="Emit\AnonymousTypeValue.cs" />
<Compile Include="Compilation\CommonModuleCompilationState.cs" />
<Compile Include="Emit\Context.cs" />
<Compile Include="Emit\EditAndContinue\DefinitionMap.cs" />
<Compile Include="Emit\EditAndContinue\DeltaPeWriter.cs" />
......@@ -209,7 +210,7 @@
<Compile Include="Emit\NoPia\CommonEmbeddedTypeParameter.cs" />
<Compile Include="Emit\NoPia\EmbeddedTypesManager.cs" />
<Compile Include="Emit\NoPia\VtblGap.cs" />
<Compile Include="Emit\PEModuleBuilder.cs" />
<Compile Include="Emit\CommonPEModuleBuilder.cs" />
<Compile Include="Emit\SemanticEdit.cs" />
<Compile Include="Emit\TypeExport.cs" />
<Compile Include="EnumConstantHelper.cs" />
......@@ -451,6 +452,7 @@
<Compile Include="SymbolDisplay\SymbolDisplayPropertyStyle.cs" />
<Compile Include="SymbolDisplay\SymbolDisplayTypeQualificationStyle.cs" />
<Compile Include="Symbols\Accessibility.cs" />
<Compile Include="Symbols\AnonymousTypes\CommonAnonymousTypeManager.cs" />
<Compile Include="Symbols\Attributes\AttributeDescription.cs" />
<Compile Include="Symbols\Attributes\AttributeUsageInfo.cs" />
<Compile Include="Symbols\Attributes\CommonAssemblyWellKnownAttributeData.cs" />
......
......@@ -687,36 +687,35 @@ IEnumerable<Cci.ICustomAttribute> Cci.IModule.ModuleAttributes
get { return GetSourceModuleAttributes(); }
}
ImmutableArray<Cci.ExternNamespace> Cci.IModule.GetExternNamespaces()
IEnumerable<Cci.IExternNamespace> Cci.IModule.ExternNamespaces
{
var result = ArrayBuilder<Cci.ExternNamespace>.GetInstance(compilation.ExternalReferences.Length);
var referenceManager = this.compilation.GetBoundReferenceManager();
// Enumerate external references (#r's don't define aliases) to preserve the order.
foreach (MetadataReference reference in compilation.ExternalReferences)
get
{
// duplicate references might have been skipped by the assembly binder:
var referenceManager = this.compilation.GetBoundReferenceManager();
IAssemblySymbol symbol;
ImmutableArray<string> aliases;
if (referenceManager.TryGetReferencedAssemblySymbol(reference, out symbol, out aliases))
// Enumerate external references (#r's don't define aliases) to preserve the order.
foreach (MetadataReference reference in compilation.ExternalReferences)
{
var displayName = symbol.Identity.GetDisplayName();
for (int i = 0; i < aliases.Length; i++)
{
string alias = aliases[i];
// duplicate references might have been skipped by the assembly binder:
// filter out duplicates and global aliases:
if (alias != MetadataReferenceProperties.GlobalAlias && aliases.IndexOf(alias, 0, i) < 0)
IAssemblySymbol symbol;
ImmutableArray<string> aliases;
if (referenceManager.TryGetReferencedAssemblySymbol(reference, out symbol, out aliases))
{
var displayName = symbol.Identity.GetDisplayName();
for (int i = 0; i < aliases.Length; i++)
{
result.Add(new Cci.ExternNamespace(alias, displayName));
string alias = aliases[i];
// filter out duplicates and global aliases:
if (alias != MetadataReferenceProperties.GlobalAlias && aliases.IndexOf(alias, 0, i) < 0)
{
yield return new ExternNamespace(alias, displayName);
}
}
}
}
}
return result.ToImmutableAndFree();
}
// PE entry point, only available for console and windows apps:
......
......@@ -184,19 +184,19 @@ Cci.AsyncMethodBodyDebugInfo Cci.IMethodBody.AsyncMethodDebugInfo
get { return null; }
}
ImmutableArray<Cci.LocalScope> Cci.IMethodBody.LocalScopes
ImmutableArray<Cci.ILocalScope> Cci.IMethodBody.LocalScopes
{
get { return ImmutableArray<Cci.LocalScope>.Empty; }
get { return ImmutableArray<Cci.ILocalScope>.Empty; }
}
ImmutableArray<Cci.NamespaceScope> Cci.IMethodBody.NamespaceScopes
ImmutableArray<Cci.INamespaceScope> Cci.IMethodBody.NamespaceScopes
{
get { return ImmutableArray<Cci.NamespaceScope>.Empty; }
get { return ImmutableArray<Cci.INamespaceScope>.Empty; }
}
ImmutableArray<Cci.LocalScope> Cci.IMethodBody.IteratorScopes
ImmutableArray<Cci.ILocalScope> Cci.IMethodBody.IteratorScopes
{
get { return ImmutableArray<Cci.LocalScope>.Empty; }
get { return ImmutableArray<Cci.ILocalScope>.Empty; }
}
string Cci.IMethodBody.IteratorClassName
......@@ -498,7 +498,7 @@ ImmutableArray<Cci.IParameterTypeInformation> Cci.ISignature.GetParameters(EmitC
return StaticCast<Cci.IParameterTypeInformation>.From(parameters);
}
ImmutableArray<Cci.ICustomModifier> Cci.ISignature.ReturnValueCustomModifiers
IEnumerable<Cci.ICustomModifier> Cci.ISignature.ReturnValueCustomModifiers
{
get
{
......@@ -514,6 +514,14 @@ bool Cci.ISignature.ReturnValueIsByRef
}
}
bool Cci.ISignature.ReturnValueIsModified
{
get
{
return UnderlyingMethodSignature.ReturnValueIsModified;
}
}
Cci.ITypeReference Cci.ISignature.GetType(EmitContext context)
{
return UnderlyingMethodSignature.GetType(context);
......
......@@ -216,7 +216,7 @@ string Cci.INamedEntity.Name
get { return Name; }
}
ImmutableArray<Cci.ICustomModifier> Cci.IParameterTypeInformation.CustomModifiers
IEnumerable<Cci.ICustomModifier> Cci.IParameterTypeInformation.CustomModifiers
{
get
{
......@@ -232,6 +232,14 @@ bool Cci.IParameterTypeInformation.IsByReference
}
}
bool Cci.IParameterTypeInformation.IsModified
{
get
{
return UnderlyingParameterTypeInformation.IsModified;
}
}
bool Cci.IParameterTypeInformation.HasByRefBeforeCustomModifiers
{
get
......
......@@ -59,7 +59,7 @@ internal override TEmbeddedTypesManager TypeManager
protected abstract bool IsSpecialName { get; }
protected abstract Cci.CallingConvention CallingConvention { get; }
protected abstract bool ReturnValueIsModified { get; }
protected abstract ImmutableArray<Cci.ICustomModifier> ReturnValueCustomModifiers { get; }
protected abstract IEnumerable<Cci.ICustomModifier> ReturnValueCustomModifiers { get; }
protected abstract bool ReturnValueIsByRef { get; }
protected abstract Cci.ITypeReference GetType(TPEModuleBuilder moduleBuilder, TSyntaxNode syntaxNodeOpt, DiagnosticBag diagnostics);
protected abstract TEmbeddedType ContainingType { get; }
......@@ -146,7 +146,15 @@ ImmutableArray<Cci.IParameterTypeInformation> Cci.ISignature.GetParameters(EmitC
return StaticCast<Cci.IParameterTypeInformation>.From(parameters);
}
ImmutableArray<Cci.ICustomModifier> Cci.ISignature.ReturnValueCustomModifiers
bool Cci.ISignature.ReturnValueIsModified
{
get
{
return ReturnValueIsModified;
}
}
IEnumerable<Cci.ICustomModifier> Cci.ISignature.ReturnValueCustomModifiers
{
get
{
......
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
......@@ -32,6 +32,12 @@ internal static BoundStatement ParseAndBindMethodBody(string program, bool lower
var diagnostics = DiagnosticBag.GetInstance();
try
{
var block = MethodCompiler.BindMethodBody(method, diagnostics);
if ((block == null) || !lower)
{
return block;
}
// Provide an Emit.Module so that the lowering passes will be run
var module = new PEAssemblyBuilder(
(SourceAssemblySymbol)compilation.Assembly,
......@@ -43,12 +49,6 @@ internal static BoundStatement ParseAndBindMethodBody(string program, bool lower
TypeCompilationState compilationState = new TypeCompilationState(method.ContainingType, compilation, module);
var block = MethodCompiler.BindMethodBody(method, compilationState, diagnostics);
if ((block == null) || !lower)
{
return block;
}
NamedTypeSymbol stateMachineType;
var body = MethodCompiler.LowerBodyOrInitializer(
generateDebugInfo: true,
......
......@@ -929,6 +929,7 @@
<Compile Include="Symbols\SymbolVisitor`1.vb" />
<Compile Include="Syntax\InternalSyntax\ChildSyntaxList.Enumerator.vb" />
<Compile Include="Syntax\InternalSyntax\ChildSyntaxList.vb" />
<Compile Include="Compilation\ModuleCompilationState.vb" />
<Content Include="Symbols\SymbolsAndNoPia.docx" />
<Content Include="UseSiteDiagnosticsCheckEnforcer\BaseLine.txt" />
<Content Include="UseSiteDiagnosticsCheckEnforcer\Run.bat" />
......
......@@ -45,9 +45,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit.NoPia
End Get
End Property
Protected Overrides ReadOnly Property ReturnValueCustomModifiers As ImmutableArray(Of Cci.ICustomModifier)
Protected Overrides ReadOnly Property ReturnValueCustomModifiers As IEnumerable(Of Cci.ICustomModifier)
Get
Return UnderlyingProperty.TypeCustomModifiers.As(Of Cci.ICustomModifier)
Return UnderlyingProperty.TypeCustomModifiers
End Get
End Property
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册