Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
57d43f27
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,发现更多精彩内容 >>
提交
57d43f27
编写于
10月 08, 2015
作者:
A
Andrew Casey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Stop exposing imports to #loaded files
Fixes #5423
上级
fc47157b
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
107 addition
and
25 deletion
+107
-25
src/Compilers/CSharp/Portable/Binder/Binder.cs
src/Compilers/CSharp/Portable/Binder/Binder.cs
+5
-0
src/Compilers/CSharp/Portable/Binder/BinderFactory.BinderFactoryVisitor.cs
...arp/Portable/Binder/BinderFactory.BinderFactoryVisitor.cs
+8
-1
src/Compilers/CSharp/Portable/Binder/BinderFlags.cs
src/Compilers/CSharp/Portable/Binder/BinderFlags.cs
+5
-0
src/Compilers/CSharp/Portable/Binder/Binder_Lookup.cs
src/Compilers/CSharp/Portable/Binder/Binder_Lookup.cs
+18
-1
src/Compilers/CSharp/Portable/Binder/BuckStopsHereBinder.cs
src/Compilers/CSharp/Portable/Binder/BuckStopsHereBinder.cs
+5
-0
src/Compilers/CSharp/Portable/Binder/InContainerBinder.cs
src/Compilers/CSharp/Portable/Binder/InContainerBinder.cs
+3
-8
src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs
...ompilers/CSharp/Portable/Compilation/CSharpCompilation.cs
+9
-2
src/Compilers/CSharp/Portable/Compilation/SyntaxTreeSemanticModel.cs
...rs/CSharp/Portable/Compilation/SyntaxTreeSemanticModel.cs
+2
-2
src/Compilers/CSharp/Test/Semantic/Semantics/ImportsTests.cs
src/Compilers/CSharp/Test/Semantic/Semantics/ImportsTests.cs
+2
-2
src/Compilers/CSharp/Test/Semantic/Semantics/InteractiveUsingTests.cs
...s/CSharp/Test/Semantic/Semantics/InteractiveUsingTests.cs
+50
-9
未找到文件。
src/Compilers/CSharp/Portable/Binder/Binder.cs
浏览文件 @
57d43f27
...
...
@@ -270,6 +270,11 @@ internal virtual ImportChain ImportChain
}
}
internal
virtual
Imports
GetImports
(
ConsList
<
Symbol
>
basesBeingResolved
)
{
return
_next
.
GetImports
(
basesBeingResolved
);
}
/// <summary>
/// The type containing the binding context
/// </summary>
...
...
src/Compilers/CSharp/Portable/Binder/BinderFactory.BinderFactoryVisitor.cs
浏览文件 @
57d43f27
...
...
@@ -801,6 +801,12 @@ internal InContainerBinder VisitCompilationUnit(CompilationUnitSyntax compilatio
// + script class members and using aliases
//
bool
isSubmissionTree
=
compilation
.
IsSubmissionSyntaxTree
(
compilationUnit
.
SyntaxTree
);
if
(!
isSubmissionTree
)
{
result
=
result
.
WithAdditionalFlags
(
BinderFlags
.
InLoadedSyntaxTree
);
}
// This is declared here so it can be captured. It's initialized below.
InContainerBinder
scriptClassBinder
=
null
;
...
...
@@ -814,7 +820,8 @@ internal InContainerBinder VisitCompilationUnit(CompilationUnitSyntax compilatio
// NB: This binder has a full Imports object, but only the non-alias imports are
// ever consumed. Aliases are actually checked in scriptClassBinder (below).
result
=
compilation
.
PreviousSubmission
==
null
// Note: #loaded trees don't consume previous submission imports.
result
=
compilation
.
PreviousSubmission
==
null
||
!
isSubmissionTree
?
new
InContainerBinder
(
result
,
basesBeingResolved
=>
scriptClassBinder
.
GetImports
(
basesBeingResolved
))
:
new
InContainerBinder
(
result
,
basesBeingResolved
=>
compilation
.
GetPreviousSubmissionImports
().
Concat
(
scriptClassBinder
.
GetImports
(
basesBeingResolved
)));
...
...
src/Compilers/CSharp/Portable/Binder/BinderFlags.cs
浏览文件 @
57d43f27
...
...
@@ -93,6 +93,11 @@ internal enum BinderFlags : uint
/// </summary>
InScriptUsing
=
1
<<
27
,
/// <summary>
/// In a file that has been included in the compilation via #load.
/// </summary>
InLoadedSyntaxTree
=
1
<<
28
,
// Groups
AllClearedAtExecutableCodeBoundary
=
InLockBody
|
InCatchBlock
|
InCatchFilter
|
InFinallyBlock
|
InTryBlockOfTryCatch
|
InNestedFinallyBlock
,
...
...
src/Compilers/CSharp/Portable/Binder/Binder_Lookup.cs
浏览文件 @
57d43f27
...
...
@@ -246,7 +246,24 @@ private void LookupMembersInSubmissions(LookupResult result, TypeSymbol submissi
var
isCurrentSubmission
=
submission
==
Compilation
;
var
considerUsings
=
!(
isCurrentSubmission
&&
this
.
Flags
.
Includes
(
BinderFlags
.
InScriptUsing
));
var
submissionImports
=
considerUsings
?
submission
.
GetSubmissionImports
()
:
Imports
.
Empty
;
Imports
submissionImports
;
if
(!
considerUsings
)
{
submissionImports
=
Imports
.
Empty
;
}
else
if
(!
this
.
Flags
.
Includes
(
BinderFlags
.
InLoadedSyntaxTree
))
{
submissionImports
=
submission
.
GetSubmissionImports
();
}
else
if
(
isCurrentSubmission
)
{
submissionImports
=
this
.
GetImports
(
basesBeingResolved
);
}
else
{
submissionImports
=
Imports
.
Empty
;
}
// If a viable using alias and a matching member are both defined in the submission an error is reported elsewhere.
// Ignore the member in such case.
...
...
src/Compilers/CSharp/Portable/Binder/BuckStopsHereBinder.cs
浏览文件 @
57d43f27
...
...
@@ -35,6 +35,11 @@ internal override ImportChain ImportChain
}
}
internal
override
Imports
GetImports
(
ConsList
<
Symbol
>
basesBeingResolved
)
{
return
Imports
.
Empty
;
}
protected
override
SourceLocalSymbol
LookupLocal
(
SyntaxToken
nameToken
)
{
return
null
;
...
...
src/Compilers/CSharp/Portable/Binder/InContainerBinder.cs
浏览文件 @
57d43f27
...
...
@@ -66,12 +66,7 @@ internal NamespaceOrTypeSymbol Container
}
}
internal
Imports
GetImports
()
{
return
GetImports
(
basesBeingResolved
:
null
);
}
internal
Imports
GetImports
(
ConsList
<
Symbol
>
basesBeingResolved
)
internal
override
Imports
GetImports
(
ConsList
<
Symbol
>
basesBeingResolved
)
{
Debug
.
Assert
(
_lazyImports
!=
null
||
_computeImports
!=
null
,
"Have neither imports nor a way to compute them."
);
...
...
@@ -92,7 +87,7 @@ internal override ImportChain ImportChain
ImportChain
importChain
=
this
.
Next
.
ImportChain
;
if
((
object
)
_container
==
null
||
_container
.
Kind
==
SymbolKind
.
Namespace
)
{
importChain
=
new
ImportChain
(
GetImports
(),
importChain
);
importChain
=
new
ImportChain
(
GetImports
(
basesBeingResolved
:
null
),
importChain
);
}
Interlocked
.
CompareExchange
(
ref
_lazyImportChain
,
importChain
,
null
);
...
...
@@ -146,7 +141,7 @@ internal override bool SupportsExtensionMethods
{
if
(
searchUsingsNotNamespace
)
{
this
.
GetImports
().
LookupExtensionMethodsInUsings
(
methods
,
name
,
arity
,
options
,
originalBinder
);
this
.
GetImports
(
basesBeingResolved
:
null
).
LookupExtensionMethodsInUsings
(
methods
,
name
,
arity
,
options
,
originalBinder
);
}
else
if
(
_container
?.
Kind
==
SymbolKind
.
Namespace
)
{
...
...
src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs
浏览文件 @
57d43f27
...
...
@@ -1200,6 +1200,13 @@ private ImplicitNamedTypeSymbol BindScriptClass()
return
namespaceOrType
as
ImplicitNamedTypeSymbol
;
}
internal
bool
IsSubmissionSyntaxTree
(
SyntaxTree
tree
)
{
Debug
.
Assert
(
tree
!=
null
);
Debug
.
Assert
(!
this
.
IsSubmission
||
_syntaxAndDeclarations
.
ExternalSyntaxTrees
.
Length
<=
1
);
return
this
.
IsSubmission
&&
tree
==
_syntaxAndDeclarations
.
ExternalSyntaxTrees
.
SingleOrDefault
();
}
/// <summary>
/// Global imports (including those from previous submissions, if there are any).
/// </summary>
...
...
@@ -1223,7 +1230,7 @@ internal Imports GetSubmissionImports()
}
var
binder
=
GetBinderFactory
(
tree
).
GetImportsBinder
((
CSharpSyntaxNode
)
tree
.
GetRoot
());
return
binder
.
GetImports
();
return
binder
.
GetImports
(
basesBeingResolved
:
null
);
}
/// <summary>
...
...
@@ -1691,7 +1698,7 @@ internal Binder GetBinder(CSharpSyntaxNode syntax)
/// </summary>
internal
Imports
GetImports
(
SingleNamespaceDeclaration
declaration
)
{
return
GetBinderFactory
(
declaration
.
SyntaxReference
.
SyntaxTree
).
GetImportsBinder
((
CSharpSyntaxNode
)
declaration
.
SyntaxReference
.
GetSyntax
()).
GetImports
();
return
GetBinderFactory
(
declaration
.
SyntaxReference
.
SyntaxTree
).
GetImportsBinder
((
CSharpSyntaxNode
)
declaration
.
SyntaxReference
.
GetSyntax
()).
GetImports
(
basesBeingResolved
:
null
);
}
private
AliasSymbol
CreateGlobalNamespaceAlias
()
...
...
src/Compilers/CSharp/Portable/Compilation/SyntaxTreeSemanticModel.cs
浏览文件 @
57d43f27
...
...
@@ -1635,7 +1635,7 @@ public override ILabelSymbol GetDeclaredSymbol(SwitchLabelSyntax declarationSynt
}
InContainerBinder
binder
=
_binderFactory
.
GetImportsBinder
(
declarationSyntax
.
Parent
);
var
imports
=
binder
.
GetImports
();
var
imports
=
binder
.
GetImports
(
basesBeingResolved
:
null
);
var
alias
=
imports
.
UsingAliases
[
declarationSyntax
.
Alias
.
Name
.
Identifier
.
ValueText
];
if
((
object
)
alias
.
Alias
==
null
)
...
...
@@ -1666,7 +1666,7 @@ public override IAliasSymbol GetDeclaredSymbol(ExternAliasDirectiveSyntax declar
CheckSyntaxNode
(
declarationSyntax
);
var
binder
=
_binderFactory
.
GetImportsBinder
(
declarationSyntax
.
Parent
);
var
imports
=
binder
.
GetImports
();
var
imports
=
binder
.
GetImports
(
basesBeingResolved
:
null
);
// TODO: If this becomes a bottleneck, put the extern aliases in a dictionary, as for using aliases.
foreach
(
var
alias
in
imports
.
ExternAliases
)
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/ImportsTests.cs
浏览文件 @
57d43f27
...
...
@@ -106,7 +106,7 @@ public void ConcatCollidingExternAliases()
var
tree
=
comp
.
SyntaxTrees
.
Single
();
var
binder
=
comp
.
GetBinderFactory
(
tree
).
GetImportsBinder
((
CSharpSyntaxNode
)
tree
.
GetRoot
(),
inUsing
:
false
);
var
scratchImports
=
binder
.
GetImports
();
var
scratchImports
=
binder
.
GetImports
(
basesBeingResolved
:
null
);
var
scratchExternAliases
=
scratchImports
.
ExternAliases
;
Assert
.
Equal
(
2
,
scratchExternAliases
.
Length
);
...
...
@@ -145,7 +145,7 @@ private static Imports[] GetImports(params string[] sources)
var
factories
=
trees
.
Select
(
tree
=>
comp
.
GetBinderFactory
(
tree
));
var
binders
=
factories
.
Select
(
factory
=>
factory
.
GetImportsBinder
((
CSharpSyntaxNode
)
factory
.
SyntaxTree
.
GetRoot
(),
inUsing
:
false
));
var
imports
=
binders
.
Select
(
binder
=>
binder
.
GetImports
());
var
imports
=
binders
.
Select
(
binder
=>
binder
.
GetImports
(
basesBeingResolved
:
null
));
Assert
.
DoesNotContain
(
Imports
.
Empty
,
imports
);
return
imports
.
ToArray
();
}
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/InteractiveUsingTests.cs
浏览文件 @
57d43f27
...
...
@@ -373,17 +373,43 @@ class C { }
}
[
WorkItem
(
5423
,
"https://github.com/dotnet/roslyn/issues/5423"
)]
[
Fact
(
Skip
=
"https://github.com/dotnet/roslyn/issues/5423"
)
]
[
Fact
]
void
UsingsToLoadedScript
()
{
const
string
scriptSource
=
@"
using System.Collections.Generic;
using AL = System.Collections.ArrayList;
using static System.Math;
class D { }
System.Type t;
// Previous submission
GetCommandLineArgs(); // using static not exposed
t = typeof(StringBuilder); // using not exposed
t = typeof(P); // using alias not exposed
t = typeof(B); // declaration exposed
// Current submission
GetTempPath(); // using static not exposed
t = typeof(File); // using not exposed
t = typeof(F); // using alias not exposed
t = typeof(C); // declaration exposed
// Current file - all available
Sin(1);
t = typeof(List<int>);
t = typeof(AL);
t = typeof(D);
"
;
const
string
previousSubmissionSource
=
@"
using static System.Environment;
using System.Text;
using P = System.IO.Path;
class B { }
"
;
const
string
submissionSource
=
@"
...
...
@@ -403,18 +429,33 @@ class C { }
var
compilation
=
CreateSubmission
(
submissionSource
,
options
:
TestOptions
.
DebugDll
.
WithSourceReferenceResolver
(
resolver
));
options
:
TestOptions
.
DebugDll
.
WithSourceReferenceResolver
(
resolver
),
previous
:
CreateSubmission
(
previousSubmissionSource
));
compilation
.
VerifyDiagnostics
(
// a.csx(4,1): error CS0103: The name 'GetTempPath' does not exist in the current context
// Previous submission
// a.csx(11,1): error CS0103: The name 'GetCommandLineArgs' does not exist in the current context
// GetCommandLineArgs(); // using static not exposed
Diagnostic
(
ErrorCode
.
ERR_NameNotInContext
,
"GetCommandLineArgs"
).
WithArguments
(
"GetCommandLineArgs"
).
WithLocation
(
11
,
1
),
// a.csx(12,12): error CS0246: The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)
// t = typeof(StringBuilder); // using not exposed
Diagnostic
(
ErrorCode
.
ERR_SingleTypeNameNotFound
,
"StringBuilder"
).
WithArguments
(
"StringBuilder"
).
WithLocation
(
12
,
12
),
// a.csx(13,12): error CS0246: The type or namespace name 'P' could not be found (are you missing a using directive or an assembly reference?)
// t = typeof(P); // using alias not exposed
Diagnostic
(
ErrorCode
.
ERR_SingleTypeNameNotFound
,
"P"
).
WithArguments
(
"P"
).
WithLocation
(
13
,
12
),
// Current submission
// a.csx(17,1): error CS0103: The name 'GetTempPath' does not exist in the current context
// GetTempPath(); // using static not exposed
Diagnostic
(
ErrorCode
.
ERR_NameNotInContext
,
"GetTempPath"
).
WithArguments
(
"GetTempPath"
).
WithLocation
(
4
,
1
),
// a.csx(
5
,12): error CS0246: The type or namespace name 'File' could not be found (are you missing a using directive or an assembly reference?)
Diagnostic
(
ErrorCode
.
ERR_NameNotInContext
,
"GetTempPath"
).
WithArguments
(
"GetTempPath"
).
WithLocation
(
17
,
1
),
// a.csx(
18
,12): error CS0246: The type or namespace name 'File' could not be found (are you missing a using directive or an assembly reference?)
// t = typeof(File); // using not exposed
Diagnostic
(
ErrorCode
.
ERR_SingleTypeNameNotFound
,
"File"
).
WithArguments
(
"File"
).
WithLocation
(
5
,
12
),
// a.csx(
6
,12): error CS0246: The type or namespace name 'F' could not be found (are you missing a using directive or an assembly reference?)
Diagnostic
(
ErrorCode
.
ERR_SingleTypeNameNotFound
,
"File"
).
WithArguments
(
"File"
).
WithLocation
(
18
,
12
),
// a.csx(
19
,12): error CS0246: The type or namespace name 'F' could not be found (are you missing a using directive or an assembly reference?)
// t = typeof(F); // using alias not exposed
Diagnostic
(
ErrorCode
.
ERR_SingleTypeNameNotFound
,
"F"
).
WithArguments
(
"F"
).
WithLocation
(
6
,
12
));
Diagnostic
(
ErrorCode
.
ERR_SingleTypeNameNotFound
,
"F"
).
WithArguments
(
"F"
).
WithLocation
(
19
,
12
));
}
[
Fact
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录