提交 7260514a 编写于 作者: J jmarolf

We don't use the ISyntaxVersionLanguageService for anything, removing.

     (Bug #774305) (changeset 1310427)
上级 86e1b1c2
......@@ -7,6 +7,7 @@
</ImportGroup>
<PropertyGroup>
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
<OutDir>..\..\..\Binaries\$(Configuration)\</OutDir>
<Platform Condition="'$(Platform)' == ''">AnyCPU</Platform>
<ProjectGuid>{21B239D0-D144-430F-A394-C066D58EE267}</ProjectGuid>
<OutputType>Library</OutputType>
......@@ -15,7 +16,6 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SolutionDir Condition="'$(SolutionDir)' == '' OR '$(SolutionDir)' == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<OutDir>..\..\..\Binaries\$(Configuration)\</OutDir>
</PropertyGroup>
<ItemGroup Label="File References">
<Reference Include="System.Collections.Immutable">
......@@ -205,7 +205,6 @@
<Compile Include="LanguageServices\CSharpSyntaxTreeFactoryService.NullSyntaxReference.cs" />
<Compile Include="LanguageServices\CSharpSyntaxTreeFactoryService.PositionalSyntaxReference.cs" />
<Compile Include="LanguageServices\CSharpSyntaxTreeFactoryService.RecoverableSyntaxTree.cs" />
<Compile Include="LanguageServices\CSharpSyntaxVersionService.cs" />
<Compile Include="LanguageServices\CSharpTypeInferenceService.cs" />
<Compile Include="LanguageServices\CSharpTypeInferenceService.TypeInferrer.cs" />
<Compile Include="LinkedFiles\CSharpLinkedFileMergeConflictCommentAdditionService.cs" />
......
// 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.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServices;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp
{
[ExportLanguageService(typeof(ISyntaxVersionLanguageService), LanguageNames.CSharp)]
internal partial class CSharpSyntaxVersionService : ISyntaxVersionLanguageService
{
public int ComputePublicHash(SyntaxNode root, CancellationToken cancellationToken)
{
var computer = SharedPools.Default<PublicHashComputer>().Allocate();
try
{
return computer.ComputeHash(root, cancellationToken);
}
finally
{
SharedPools.Default<PublicHashComputer>().Free(computer);
}
}
private class PublicHashComputer : CSharpSyntaxWalker
{
private int hash;
private CancellationToken cancellationToken;
public PublicHashComputer()
: base(SyntaxWalkerDepth.Token)
{
}
public int ComputeHash(SyntaxNode root, CancellationToken cancellationToken)
{
this.hash = 0;
this.cancellationToken = cancellationToken;
this.Visit(root);
return this.hash;
}
public override void VisitBlock(BlockSyntax node)
{
// interior contents of blocks are not considered (nor are the braces)
return;
}
public override void Visit(SyntaxNode node)
{
cancellationToken.ThrowIfCancellationRequested();
// non-const field initializers are not considered
if (node.Parent != null
&& node.Parent.CSharpKind() == SyntaxKind.EqualsValueClause
&& node.Parent.Parent.CSharpKind() == SyntaxKind.VariableDeclarator
&& node.Parent.Parent.Parent.CSharpKind() == SyntaxKind.VariableDeclaration
&& node.Parent.Parent.Parent.Parent.CSharpKind() == SyntaxKind.FieldDeclaration)
{
var fd = (FieldDeclarationSyntax)node.Parent.Parent.Parent.Parent;
if (!fd.Modifiers.Any(SyntaxKind.ConstKeyword))
{
return;
}
}
base.Visit(node);
}
public override void VisitToken(SyntaxToken token)
{
// trivia is not considered, only the raw form of the token
this.hash = Hash.Combine((int)token.CSharpKind(), this.hash);
switch (token.CSharpKind())
{
case SyntaxKind.IdentifierToken:
this.hash = Hash.Combine(token.ValueText.GetHashCode(), this.hash);
break;
case SyntaxKind.NumericLiteralToken:
case SyntaxKind.CharacterLiteralToken:
case SyntaxKind.StringLiteralToken:
this.hash = Hash.Combine(token.ToString().GetHashCode(), this.hash);
break;
}
}
}
}
}
\ 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.
using System.Threading;
using Microsoft.CodeAnalysis.Host;
namespace Microsoft.CodeAnalysis.LanguageServices
{
/// <summary>
/// A service that computes the syntactic version of a syntax tree
/// </summary>
internal interface ISyntaxVersionLanguageService : ILanguageService
{
/// <summary>
/// Computes a hash corresponding to the public declarations in the syntax tree.
/// Interior regions like method bodies, or trivia are not included.
/// </summary>
int ComputePublicHash(SyntaxNode root, CancellationToken cancellationToken);
}
}
\ No newline at end of file
......@@ -514,7 +514,6 @@
<Compile Include="Workspace\Host\Mef\ILanguageMetadata.cs" />
<Compile Include="Workspace\Host\ILanguageService.cs" />
<Compile Include="Workspace\Host\Mef\ILanguageServiceFactory.cs" />
<Compile Include="LanguageServices\ISyntaxVersionLanguageService.cs" />
<Compile Include="Workspace\Host\Mef\LanguageMetadata.cs" />
<Compile Include="Workspace\Host\Mef\LanguageServiceMetadata.cs" />
<Compile Include="Workspace\Host\Mef\OrderableLanguageMetadata.cs" />
......
......@@ -7,13 +7,13 @@
</ImportGroup>
<PropertyGroup>
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
<OutDir>..\..\..\Binaries\$(Configuration)\</OutDir>
<Platform Condition="'$(Platform)' == ''">AnyCPU</Platform>
<ProjectGuid>{57CA988D-F010-4BF2-9A2E-07D6DCD2FF2C}</ProjectGuid>
<OutputType>Library</OutputType>
<AssemblyName>Microsoft.CodeAnalysis.VisualBasic.Workspaces</AssemblyName>
<SolutionDir Condition="'$(SolutionDir)' == '' OR '$(SolutionDir)' == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<OutDir>..\..\..\Binaries\$(Configuration)\</OutDir>
</PropertyGroup>
<ItemGroup Label="File References">
<Reference Include="System.Collections.Immutable">
......@@ -202,7 +202,6 @@
<Compile Include="LanguageServices\VisualBasicSyntaxTreeFactoryService.PositionalSyntaxReference.vb" />
<Compile Include="LanguageServices\VisualBasicSyntaxTreeFactoryService.RecoverableSyntaxTree.vb" />
<Compile Include="LanguageServices\VisualBasicSyntaxTreeFactoryService.vb" />
<Compile Include="LanguageServices\VisualBasicSyntaxVersionService.vb" />
<Compile Include="LanguageServices\VisualBasicTypeInferenceService.TypeInferrer.vb" />
<Compile Include="LanguageServices\VisualBasicTypeInferenceService.vb" />
<Compile Include="LinkedFiles\BasicLinkedFileMergeConflictCommentAdditionService.vb" />
......
' 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.
Imports System.Threading
Imports Microsoft.CodeAnalysis.Host
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.LanguageServices
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.VisualBasic
<ExportLanguageService(GetType(ISyntaxVersionLanguageService), LanguageNames.VisualBasic)>
Friend Class VisualBasicSyntaxVersionLanguageService
Implements ISyntaxVersionLanguageService
Public Function ComputePublicHash(root As SyntaxNode, cancellationToken As CancellationToken) As Integer Implements ISyntaxVersionLanguageService.ComputePublicHash
Dim result As Integer
Dim computer = SharedPools.Default(Of PublicHashComputer)().Allocate()
Try
result = computer.ComputeHash(root, cancellationToken)
Finally
SharedPools.Default(Of PublicHashComputer)().Free(computer)
End Try
Return result
End Function
Private Class PublicHashComputer
Inherits VisualBasicSyntaxWalker
Private _hash As Integer
Private _cancellationToken As CancellationToken
Public Sub New()
MyBase.New(SyntaxWalkerDepth.Token)
End Sub
Public Function ComputeHash(node As SyntaxNode, cancellationToken As CancellationToken) As Integer
Me._hash = 0
Me._cancellationToken = cancellationToken
Visit(node)
Return Me._hash
End Function
Public Overrides Sub Visit(node As SyntaxNode)
Me._cancellationToken.ThrowIfCancellationRequested()
If node.Parent IsNot Nothing Then
' ignore statements of method bodies
Dim mb = TryCast(node, MethodBlockBaseSyntax)
If mb IsNot Nothing Then
Me.Visit(mb.Begin)
Me.Visit(mb.End)
Return
End If
' non-const field initializers are not considered
If node.Parent.VisualBasicKind = SyntaxKind.EqualsValue AndAlso
node.Parent.Parent.VisualBasicKind = SyntaxKind.VariableDeclarator AndAlso
node.Parent.Parent.Parent.VisualBasicKind = SyntaxKind.FieldDeclaration Then
Dim fd = DirectCast(node.Parent.Parent.Parent, FieldDeclarationSyntax)
If Not fd.Modifiers.Any(SyntaxKind.ConstKeyword) Then
Return
End If
End If
End If
MyBase.Visit(node)
End Sub
Public Overrides Sub VisitToken(token As SyntaxToken)
' trivia is not considered, only the raw form of the token
Me._hash = Hash.Combine(CType(token.VisualBasicKind, Integer), Me._hash)
Select Case token.VisualBasicKind
Case SyntaxKind.IdentifierToken,
SyntaxKind.CharacterLiteralToken,
SyntaxKind.DateLiteralToken,
SyntaxKind.DecimalLiteralToken,
SyntaxKind.FloatingLiteralToken,
SyntaxKind.IntegerLiteralToken,
SyntaxKind.StringLiteralToken
Me._hash = Hash.Combine(token.ToString().GetHashCode(), Me._hash)
End Select
End Sub
End Class
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册