提交 f88f4cde 编写于 作者: C CyrusNajmabadi

Store data in the decl-table so we don't have to go back to the source tree.

上级 886ece81
...@@ -279,6 +279,11 @@ private SingleNamespaceOrTypeDeclaration VisitTypeDeclaration(TypeDeclarationSyn ...@@ -279,6 +279,11 @@ private SingleNamespaceOrTypeDeclaration VisitTypeDeclaration(TypeDeclarationSyn
declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasBaseDeclarations; declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasBaseDeclarations;
} }
if (node.ConstraintClauses.Count > 0)
{
declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasConstraints;
}
var memberNames = GetNonTypeMemberNames(((Syntax.InternalSyntax.TypeDeclarationSyntax)(node.Green)).Members, var memberNames = GetNonTypeMemberNames(((Syntax.InternalSyntax.TypeDeclarationSyntax)(node.Green)).Members,
ref declFlags); ref declFlags);
...@@ -316,9 +321,14 @@ private ImmutableArray<SingleTypeDeclaration> VisitTypeChildren(TypeDeclarationS ...@@ -316,9 +321,14 @@ private ImmutableArray<SingleTypeDeclaration> VisitTypeChildren(TypeDeclarationS
public override SingleNamespaceOrTypeDeclaration VisitDelegateDeclaration(DelegateDeclarationSyntax node) public override SingleNamespaceOrTypeDeclaration VisitDelegateDeclaration(DelegateDeclarationSyntax node)
{ {
SingleTypeDeclaration.TypeDeclarationFlags declFlags = node.AttributeLists.Any() ? var declFlags = node.AttributeLists.Any()
SingleTypeDeclaration.TypeDeclarationFlags.HasAnyAttributes : ? SingleTypeDeclaration.TypeDeclarationFlags.HasAnyAttributes
SingleTypeDeclaration.TypeDeclarationFlags.None; : SingleTypeDeclaration.TypeDeclarationFlags.None;
if (node.ConstraintClauses.Count > 0)
{
declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasConstraints;
}
declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasAnyNontypeMembers; declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasAnyNontypeMembers;
......
...@@ -123,6 +123,22 @@ public bool AnyMemberHasAttributes ...@@ -123,6 +123,22 @@ public bool AnyMemberHasAttributes
} }
} }
public bool HasConstraints
{
get
{
foreach (var decl in this.Declarations)
{
if (decl.HasConstraints)
{
return true;
}
}
return false;
}
}
public LexicalSortKey GetLexicalSortKey(CSharpCompilation compilation) public LexicalSortKey GetLexicalSortKey(CSharpCompilation compilation)
{ {
LexicalSortKey sortKey = new LexicalSortKey(Declarations[0].NameLocation, compilation); LexicalSortKey sortKey = new LexicalSortKey(Declarations[0].NameLocation, compilation);
......
...@@ -26,6 +26,7 @@ internal enum TypeDeclarationFlags : byte ...@@ -26,6 +26,7 @@ internal enum TypeDeclarationFlags : byte
HasBaseDeclarations = 1 << 3, HasBaseDeclarations = 1 << 3,
AnyMemberHasAttributes = 1 << 4, AnyMemberHasAttributes = 1 << 4,
HasAnyNontypeMembers = 1 << 5, HasAnyNontypeMembers = 1 << 5,
HasConstraints = 1 << 6,
} }
internal SingleTypeDeclaration( internal SingleTypeDeclaration(
...@@ -124,6 +125,8 @@ public bool AnyMemberHasAttributes ...@@ -124,6 +125,8 @@ public bool AnyMemberHasAttributes
} }
} }
public bool HasConstraints => (_flags & TypeDeclarationFlags.HasConstraints) != 0;
public bool HasAnyNontypeMembers public bool HasAnyNontypeMembers
{ {
get get
......
...@@ -84,6 +84,15 @@ internal SourceNamedTypeSymbol(NamespaceOrTypeSymbol containingSymbol, MergedTyp ...@@ -84,6 +84,15 @@ internal SourceNamedTypeSymbol(NamespaceOrTypeSymbol containingSymbol, MergedTyp
// Nested types are never unified. // Nested types are never unified.
_lazyIsExplicitDefinitionOfNoPiaLocalType = ThreeState.False; _lazyIsExplicitDefinitionOfNoPiaLocalType = ThreeState.False;
} }
if (declaration.Arity == 0 && declaration.HasConstraints)
{
foreach (var syntaxRef in this.SyntaxReferences)
{
var constraintClauses = GetConstraintClauses((CSharpSyntaxNode)syntaxRef.GetSyntax());
ReportErrorIfHasConstraints(constraintClauses, diagnostics);
}
}
} }
#region Syntax #region Syntax
...@@ -118,15 +127,6 @@ private ImmutableArray<TypeParameterSymbol> MakeTypeParameters(DiagnosticBag dia ...@@ -118,15 +127,6 @@ private ImmutableArray<TypeParameterSymbol> MakeTypeParameters(DiagnosticBag dia
{ {
if (declaration.Arity == 0) if (declaration.Arity == 0)
{ {
if (declaration.Kind != DeclarationKind.Enum)
{
foreach (var syntaxRef in this.SyntaxReferences)
{
var constraintClauses = GetConstraintClauses((CSharpSyntaxNode)syntaxRef.GetSyntax());
ReportErrorIfHasConstraints(constraintClauses, diagnostics);
}
}
return ImmutableArray<TypeParameterSymbol>.Empty; return ImmutableArray<TypeParameterSymbol>.Empty;
} }
......
...@@ -304,15 +304,12 @@ public class B ...@@ -304,15 +304,12 @@ public class B
var method = (MethodSymbol)type.GetMembers().First(); var method = (MethodSymbol)type.GetMembers().First();
Assert.Equal(1, countedTree.AccessCount); Assert.Equal(1, countedTree.AccessCount);
// To get the return type, we need to get the type parameters of the containing type. // Once we have the method, we shouldn't need to go back to syntax again.
// That may cause us to go back to the syntax to check for Type-Parameter + Constraint
// issues.
var returnType = method.ReturnType; var returnType = method.ReturnType;
Assert.Equal(3, countedTree.AccessCount); Assert.Equal(1, countedTree.AccessCount);
// Once we have the method, we shouldn't need to go back to syntax again.
var parameterType = method.Parameters.Single(); var parameterType = method.Parameters.Single();
Assert.Equal(3, countedTree.AccessCount); Assert.Equal(1, countedTree.AccessCount);
} }
private class CountedSyntaxTree : CSharpSyntaxTree private class CountedSyntaxTree : CSharpSyntaxTree
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册