Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
e5a1101f
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,发现更多精彩内容 >>
提交
e5a1101f
编写于
4月 19, 2015
作者:
V
VSadov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added couple tests for ?. operator for cases missed in optimizations.
The tests arep assing, but codegen is not great.
上级
f7917f79
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
238 addition
and
0 deletion
+238
-0
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs
...arp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs
+238
-0
未找到文件。
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenShortCircuitOperatorTests.cs
浏览文件 @
e5a1101f
...
...
@@ -6654,6 +6654,244 @@ .maxstack 2
IL_000d: call ""void System.Console.WriteLine(int)""
IL_0012: ret
}
"
);
}
[
Fact
]
public
void
ConditionalBoolExpr02ba
()
{
var
source
=
@"
class C
{
public static void Main()
{
System.Console.Write(NotHasLength(null, 0));
System.Console.Write(NotHasLength(null, 3));
System.Console.Write(NotHasLength(1, 2));
}
static bool NotHasLength(int? s, int len)
{
return s?.GetHashCode() + 1 != len;
}
}
"
;
var
verifier
=
CompileAndVerify
(
source
,
expectedOutput
:
@"TrueTrueFalse"
);
verifier
.
VerifyIL
(
"C.NotHasLength"
,
@"
{
// Code size 106 (0x6a)
.maxstack 2
.locals init (int? V_0,
int V_1,
int? V_2,
int V_3,
int? V_4,
int V_5)
IL_0000: ldarga.s V_0
IL_0002: call ""bool int?.HasValue.get""
IL_0007: brtrue.s IL_0015
IL_0009: ldloca.s V_4
IL_000b: initobj ""int?""
IL_0011: ldloc.s V_4
IL_0013: br.s IL_002a
IL_0015: ldarga.s V_0
IL_0017: call ""int int?.GetValueOrDefault()""
IL_001c: stloc.s V_5
IL_001e: ldloca.s V_5
IL_0020: call ""int int.GetHashCode()""
IL_0025: newobj ""int?..ctor(int)""
IL_002a: stloc.2
IL_002b: ldc.i4.1
IL_002c: stloc.3
IL_002d: ldloca.s V_2
IL_002f: call ""bool int?.HasValue.get""
IL_0034: brtrue.s IL_0042
IL_0036: ldloca.s V_4
IL_0038: initobj ""int?""
IL_003e: ldloc.s V_4
IL_0040: br.s IL_0050
IL_0042: ldloca.s V_2
IL_0044: call ""int int?.GetValueOrDefault()""
IL_0049: ldloc.3
IL_004a: add
IL_004b: newobj ""int?..ctor(int)""
IL_0050: stloc.0
IL_0051: ldarg.1
IL_0052: stloc.1
IL_0053: ldloca.s V_0
IL_0055: call ""int int?.GetValueOrDefault()""
IL_005a: ldloc.1
IL_005b: beq.s IL_005f
IL_005d: ldc.i4.1
IL_005e: ret
IL_005f: ldloca.s V_0
IL_0061: call ""bool int?.HasValue.get""
IL_0066: ldc.i4.0
IL_0067: ceq
IL_0069: ret
}
"
);
}
[
Fact
]
public
void
ConditionalBoolExpr02bb
()
{
var
source
=
@"
class C
{
public static void Main()
{
System.Console.Write(NotHasLength(null, 0));
System.Console.Write(NotHasLength(null, 3));
System.Console.Write(NotHasLength(1, 2));
System.Console.Write(NotHasLength(null, null));
}
static bool NotHasLength(int? s, int? len)
{
return s?.GetHashCode() + 1 != len;
}
}
"
;
var
verifier
=
CompileAndVerify
(
source
,
expectedOutput
:
@"TrueTrueFalseFalse"
);
verifier
.
VerifyIL
(
"C.NotHasLength"
,
@"
{
// Code size 121 (0x79)
.maxstack 2
.locals init (int? V_0,
int? V_1,
int? V_2,
int V_3,
int? V_4,
int V_5)
IL_0000: ldarga.s V_0
IL_0002: call ""bool int?.HasValue.get""
IL_0007: brtrue.s IL_0015
IL_0009: ldloca.s V_4
IL_000b: initobj ""int?""
IL_0011: ldloc.s V_4
IL_0013: br.s IL_002a
IL_0015: ldarga.s V_0
IL_0017: call ""int int?.GetValueOrDefault()""
IL_001c: stloc.s V_5
IL_001e: ldloca.s V_5
IL_0020: call ""int int.GetHashCode()""
IL_0025: newobj ""int?..ctor(int)""
IL_002a: stloc.2
IL_002b: ldc.i4.1
IL_002c: stloc.3
IL_002d: ldloca.s V_2
IL_002f: call ""bool int?.HasValue.get""
IL_0034: brtrue.s IL_0042
IL_0036: ldloca.s V_4
IL_0038: initobj ""int?""
IL_003e: ldloc.s V_4
IL_0040: br.s IL_0050
IL_0042: ldloca.s V_2
IL_0044: call ""int int?.GetValueOrDefault()""
IL_0049: ldloc.3
IL_004a: add
IL_004b: newobj ""int?..ctor(int)""
IL_0050: stloc.0
IL_0051: ldarg.1
IL_0052: stloc.1
IL_0053: ldloca.s V_0
IL_0055: call ""int int?.GetValueOrDefault()""
IL_005a: ldloca.s V_1
IL_005c: call ""int int?.GetValueOrDefault()""
IL_0061: beq.s IL_0065
IL_0063: ldc.i4.1
IL_0064: ret
IL_0065: ldloca.s V_0
IL_0067: call ""bool int?.HasValue.get""
IL_006c: ldloca.s V_1
IL_006e: call ""bool int?.HasValue.get""
IL_0073: ceq
IL_0075: ldc.i4.0
IL_0076: ceq
IL_0078: ret
}
"
);
}
[
Fact
]
public
void
ConditionalUnary
()
{
var
source
=
@"
class C
{
public static void Main()
{
var x = - - -((string)null)?.Length ?? - - -string.Empty?.Length;
System.Console.WriteLine(x);
}
}
"
;
var
verifier
=
CompileAndVerify
(
source
,
expectedOutput
:
@"0"
);
verifier
.
VerifyIL
(
"C.Main"
,
@"
{
// Code size 135 (0x87)
.maxstack 2
.locals init (int? V_0,
int? V_1,
int? V_2)
IL_0000: ldloca.s V_2
IL_0002: initobj ""int?""
IL_0008: ldloc.2
IL_0009: stloc.1
IL_000a: ldloca.s V_1
IL_000c: call ""bool int?.HasValue.get""
IL_0011: brtrue.s IL_001e
IL_0013: ldloca.s V_2
IL_0015: initobj ""int?""
IL_001b: ldloc.2
IL_001c: br.s IL_002d
IL_001e: ldloca.s V_1
IL_0020: call ""int int?.GetValueOrDefault()""
IL_0025: neg
IL_0026: neg
IL_0027: neg
IL_0028: newobj ""int?..ctor(int)""
IL_002d: stloc.0
IL_002e: ldloca.s V_0
IL_0030: call ""bool int?.HasValue.get""
IL_0035: brtrue.s IL_007b
IL_0037: ldsfld ""string string.Empty""
IL_003c: dup
IL_003d: brtrue.s IL_004b
IL_003f: pop
IL_0040: ldloca.s V_2
IL_0042: initobj ""int?""
IL_0048: ldloc.2
IL_0049: br.s IL_0055
IL_004b: call ""int string.Length.get""
IL_0050: newobj ""int?..ctor(int)""
IL_0055: stloc.1
IL_0056: ldloca.s V_1
IL_0058: call ""bool int?.HasValue.get""
IL_005d: brtrue.s IL_006a
IL_005f: ldloca.s V_2
IL_0061: initobj ""int?""
IL_0067: ldloc.2
IL_0068: br.s IL_007c
IL_006a: ldloca.s V_1
IL_006c: call ""int int?.GetValueOrDefault()""
IL_0071: neg
IL_0072: neg
IL_0073: neg
IL_0074: newobj ""int?..ctor(int)""
IL_0079: br.s IL_007c
IL_007b: ldloc.0
IL_007c: box ""int?""
IL_0081: call ""void System.Console.WriteLine(object)""
IL_0086: ret
}
"
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录