Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
63e58ee6
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
63e58ee6
编写于
2月 23, 2015
作者:
M
Matt Warren
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #736 from mattwar/Bug605
Fix calculation for slot containing offset
上级
28ceb712
b106d3d4
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
105 addition
and
4 deletion
+105
-4
src/Compilers/CSharp/Portable/Syntax/InternalSyntax/SyntaxList.WithLotsOfChildren.cs
...le/Syntax/InternalSyntax/SyntaxList.WithLotsOfChildren.cs
+1
-2
src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNodeTests.cs
src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNodeTests.cs
+38
-0
src/Compilers/Core/Portable/InternalUtilities/ArrayExtensions.cs
...pilers/Core/Portable/InternalUtilities/ArrayExtensions.cs
+30
-0
src/Compilers/VisualBasic/Portable/Syntax/InternalSyntax/SyntaxList.vb
.../VisualBasic/Portable/Syntax/InternalSyntax/SyntaxList.vb
+1
-2
src/Compilers/VisualBasic/Test/Syntax/TestSyntaxNodes.vb
src/Compilers/VisualBasic/Test/Syntax/TestSyntaxNodes.vb
+35
-0
未找到文件。
src/Compilers/CSharp/Portable/Syntax/InternalSyntax/SyntaxList.WithLotsOfChildren.cs
浏览文件 @
63e58ee6
...
...
@@ -52,8 +52,7 @@ public override int GetSlotOffset(int index)
public
override
int
FindSlotIndexContainingOffset
(
int
offset
)
{
Debug
.
Assert
(
offset
>=
0
&&
offset
<
FullWidth
);
int
idx
=
_childOffsets
.
BinarySearch
(
offset
);
return
idx
>=
0
?
idx
:
(~
idx
-
1
);
return
_childOffsets
.
BinarySearchUpperBound
(
offset
)
-
1
;
}
private
static
int
[]
CalculateOffsets
(
ArrayElement
<
CSharpSyntaxNode
>[]
children
)
...
...
src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNodeTests.cs
浏览文件 @
63e58ee6
...
...
@@ -481,6 +481,44 @@ public void TestFindToken()
Assert
.
Equal
(
SyntaxKind
.
IfKeyword
,
token
.
Kind
());
}
[
Fact
]
public
void
TestFindTokenInLargeList
()
{
var
identifier
=
SyntaxFactory
.
Identifier
(
"x"
);
var
missingIdentifier
=
SyntaxFactory
.
MissingToken
(
SyntaxKind
.
IdentifierToken
);
var
name
=
SyntaxFactory
.
IdentifierName
(
identifier
);
var
missingName
=
SyntaxFactory
.
IdentifierName
(
missingIdentifier
);
var
comma
=
SyntaxFactory
.
Token
(
SyntaxKind
.
CommaToken
);
var
missingComma
=
SyntaxFactory
.
MissingToken
(
SyntaxKind
.
CommaToken
);
var
argument
=
SyntaxFactory
.
Argument
(
name
);
var
missingArgument
=
SyntaxFactory
.
Argument
(
missingName
);
// make a large list that has lots of zero-length nodes (that shouldn't be found)
var
nodesAndTokens
=
SyntaxFactory
.
NodeOrTokenList
(
missingArgument
,
missingComma
,
missingArgument
,
missingComma
,
missingArgument
,
missingComma
,
missingArgument
,
missingComma
,
missingArgument
,
missingComma
,
missingArgument
,
missingComma
,
missingArgument
,
missingComma
,
missingArgument
,
missingComma
,
argument
);
var
argumentList
=
SyntaxFactory
.
ArgumentList
(
SyntaxFactory
.
SeparatedList
<
ArgumentSyntax
>(
SyntaxFactory
.
NodeOrTokenList
(
nodesAndTokens
)));
var
invocation
=
SyntaxFactory
.
InvocationExpression
(
name
,
argumentList
);
CheckFindToken
(
invocation
);
}
private
void
CheckFindToken
(
SyntaxNode
node
)
{
for
(
int
i
=
0
;
i
<
node
.
FullSpan
.
End
;
i
++)
{
var
token
=
node
.
FindToken
(
i
);
Assert
.
Equal
(
true
,
token
.
FullSpan
.
Contains
(
i
));
}
}
[
WorkItem
(
755236
,
"DevDiv"
)]
[
Fact
]
public
void
TestFindNode
()
...
...
src/Compilers/Core/Portable/InternalUtilities/ArrayExtensions.cs
浏览文件 @
63e58ee6
...
...
@@ -173,5 +173,35 @@ internal static int BinarySearch(this int[] array, int value)
return
~
low
;
}
/// <summary>
/// Search a sorted integer array for the target value in O(log N) time.
/// </summary>
/// <param name="array">The array of integers which must be sorted in ascending order.</param>
/// <param name="value">The target value.</param>
/// <returns>An index in the array pointing to the position where <paramref name="value"/> should be
/// inserted in order to maintain the sorted order. All values to the right of this position will be
/// strictly greater than <paramref name="value"/>. Note that this may return a position off the end
/// of the array if all elements are less than or equal to <paramref name="value"/>.</returns>
internal
static
int
BinarySearchUpperBound
(
this
int
[]
array
,
int
value
)
{
int
low
=
0
;
int
high
=
array
.
Length
-
1
;
while
(
low
<=
high
)
{
int
middle
=
low
+
((
high
-
low
)
>>
1
);
if
(
array
[
middle
]
>
value
)
{
high
=
middle
-
1
;
}
else
{
low
=
middle
+
1
;
}
}
return
low
;
}
}
}
src/Compilers/VisualBasic/Portable/Syntax/InternalSyntax/SyntaxList.vb
浏览文件 @
63e58ee6
...
...
@@ -466,8 +466,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
''' </remarks>
Public
Overrides
Function
FindSlotIndexContainingOffset
(
offset
As
Integer
)
As
Integer
Debug
.
Assert
(
offset
>=
0
AndAlso
offset
<
FullWidth
)
Dim
idx
=
_childOffsets
.
BinarySearch
(
offset
)
Return
If
(
idx
>=
0
,
idx
,
(
Not
idx
)
-
1
)
Return
_childOffsets
.
BinarySearchUpperBound
(
offset
)
-
1
End
Function
Friend
Overrides
Function
SetDiagnostics
(
errors
()
As
DiagnosticInfo
)
As
GreenNode
...
...
src/Compilers/VisualBasic/Test/Syntax/TestSyntaxNodes.vb
浏览文件 @
63e58ee6
...
...
@@ -2114,6 +2114,41 @@ End Class]]>
Assert
.
Throws
(
Of
ArgumentOutOfRangeException
)(
Sub
()
classDecl
.
FindNode
(
root
.
FullSpan
))
End
Sub
<
Fact
>
Public
Sub
TestFindTokenInLargeList
()
Dim
identifier
=
SyntaxFactory
.
Identifier
(
"x"
)
Dim
missingIdentifier
=
SyntaxFactory
.
MissingToken
(
SyntaxKind
.
IdentifierToken
)
Dim
name
=
SyntaxFactory
.
IdentifierName
(
identifier
)
Dim
missingName
=
SyntaxFactory
.
IdentifierName
(
missingIdentifier
)
Dim
comma
=
SyntaxFactory
.
Token
(
SyntaxKind
.
CommaToken
)
Dim
missingComma
=
SyntaxFactory
.
MissingToken
(
SyntaxKind
.
CommaToken
)
Dim
argument
=
SyntaxFactory
.
SimpleArgument
(
name
)
Dim
missingArgument
=
SyntaxFactory
.
SimpleArgument
(
missingName
)
'' make a large list that has lots of zero-length nodes (that shouldn't be found)
Dim
nodesAndTokens
=
SyntaxFactory
.
NodeOrTokenList
(
missingArgument
,
missingComma
,
missingArgument
,
missingComma
,
missingArgument
,
missingComma
,
missingArgument
,
missingComma
,
missingArgument
,
missingComma
,
missingArgument
,
missingComma
,
missingArgument
,
missingComma
,
missingArgument
,
missingComma
,
argument
)
Dim
argumentList
=
SyntaxFactory
.
ArgumentList
(
SyntaxFactory
.
SeparatedList
(
Of
ArgumentSyntax
)(
SyntaxFactory
.
NodeOrTokenList
(
nodesAndTokens
)))
Dim
invocation
=
SyntaxFactory
.
InvocationExpression
(
name
,
argumentList
)
CheckFindToken
(
invocation
)
End
Sub
Private
Sub
CheckFindToken
(
node
As
SyntaxNode
)
For
i
As
Integer
=
1
To
node
.
FullSpan
.
End
-
1
Dim
token
=
node
.
FindToken
(
i
)
Assert
.
Equal
(
True
,
token
.
FullSpan
.
Contains
(
i
))
Next
End
Sub
<
WorkItem
(
539940
,
"DevDiv"
)
>
<
Fact
>
Public
Sub
TestFindTriviaNoTriviaExistsAtPosition
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录