Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
c4292e69
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,发现更多精彩内容 >>
未验证
提交
c4292e69
编写于
11月 29, 2017
作者:
D
Dustin Campbell
提交者:
GitHub
11月 29, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #23435 from DustinCampbell/script-cmd-line-parser-api
Make C# and VB CommandLineParser.Script public
上级
9746c895
08d4f343
变更
13
显示空白变更内容
内联
并排
Showing
13 changed file
with
67 addition
and
70 deletion
+67
-70
src/Compilers/CSharp/Portable/CommandLine/CSharpCommandLineParser.cs
...rs/CSharp/Portable/CommandLine/CSharpCommandLineParser.cs
+15
-16
src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt
src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt
+1
-0
src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
+23
-23
src/Compilers/Core/Portable/CommandLine/CommonCommandLineParser.cs
...lers/Core/Portable/CommandLine/CommonCommandLineParser.cs
+6
-7
src/Compilers/Test/Utilities/VisualBasic/MockVbi.vb
src/Compilers/Test/Utilities/VisualBasic/MockVbi.vb
+1
-1
src/Compilers/VisualBasic/Portable/CommandLine/VisualBasicCommandLineParser.vb
...asic/Portable/CommandLine/VisualBasicCommandLineParser.vb
+14
-16
src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb
...ompilers/VisualBasic/Test/CommandLine/CommandLineTests.vb
+1
-1
src/Interactive/EditorFeatures/CSharp/Interactive/CSharpInteractiveEvaluator.cs
...Features/CSharp/Interactive/CSharpInteractiveEvaluator.cs
+1
-1
src/Interactive/EditorFeatures/CSharp/Interactive/CSharpReplServiceProvider.cs
...rFeatures/CSharp/Interactive/CSharpReplServiceProvider.cs
+1
-1
src/Interactive/EditorFeatures/VisualBasic/Interactive/VisualBasicInteractiveEvaluator.vb
...isualBasic/Interactive/VisualBasicInteractiveEvaluator.vb
+1
-1
src/Interactive/EditorFeatures/VisualBasic/Interactive/VisualBasicReplServiceProvider.vb
...VisualBasic/Interactive/VisualBasicReplServiceProvider.vb
+1
-1
src/Scripting/CSharp/Hosting/CommandLine/Csi.cs
src/Scripting/CSharp/Hosting/CommandLine/Csi.cs
+1
-1
src/Scripting/VisualBasic/Hosting/CommandLine/Vbi.vb
src/Scripting/VisualBasic/Hosting/CommandLine/Vbi.vb
+1
-1
未找到文件。
src/Compilers/CSharp/Portable/CommandLine/CSharpCommandLineParser.cs
浏览文件 @
c4292e69
...
...
@@ -8,7 +8,6 @@
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
Microsoft.CodeAnalysis.Collections
;
using
Microsoft.CodeAnalysis.Emit
;
using
Microsoft.CodeAnalysis.PooledObjects
;
using
Microsoft.CodeAnalysis.Text
;
...
...
@@ -19,12 +18,12 @@ namespace Microsoft.CodeAnalysis.CSharp
public
class
CSharpCommandLineParser
:
CommandLineParser
{
public
static
CSharpCommandLineParser
Default
{
get
;
}
=
new
CSharpCommandLineParser
();
public
static
CSharpCommandLineParser
Script
{
get
;
}
=
new
CSharpCommandLineParser
(
isScriptCommandLineParser
:
true
);
internal
static
CSharpCommandLineParser
ScriptRunner
{
get
;
}
=
new
CSharpCommandLineParser
(
isScriptRunner
:
true
);
private
readonly
static
char
[]
s_quoteOrEquals
=
new
[]
{
'"'
,
'='
};
internal
CSharpCommandLineParser
(
bool
isScript
Runn
er
=
false
)
:
base
(
CSharp
.
MessageProvider
.
Instance
,
isScript
Runn
er
)
internal
CSharpCommandLineParser
(
bool
isScript
CommandLinePars
er
=
false
)
:
base
(
CSharp
.
MessageProvider
.
Instance
,
isScript
CommandLinePars
er
)
{
}
...
...
@@ -48,8 +47,8 @@ public new CSharpCommandLineArguments Parse(IEnumerable<string> args, string bas
{
List
<
Diagnostic
>
diagnostics
=
new
List
<
Diagnostic
>();
List
<
string
>
flattenedArgs
=
new
List
<
string
>();
List
<
string
>
scriptArgs
=
IsScript
Runn
er
?
new
List
<
string
>()
:
null
;
List
<
string
>
responsePaths
=
IsScript
Runn
er
?
new
List
<
string
>()
:
null
;
List
<
string
>
scriptArgs
=
IsScript
CommandLinePars
er
?
new
List
<
string
>()
:
null
;
List
<
string
>
responsePaths
=
IsScript
CommandLinePars
er
?
new
List
<
string
>()
:
null
;
FlattenArgs
(
args
,
diagnostics
,
flattenedArgs
,
scriptArgs
,
baseDirectory
,
responsePaths
);
string
appConfigPath
=
null
;
...
...
@@ -66,7 +65,7 @@ public new CSharpCommandLineArguments Parse(IEnumerable<string> args, string bas
DebugInformationFormat
debugInformationFormat
=
PathUtilities
.
IsUnixLikePlatform
?
DebugInformationFormat
.
PortablePdb
:
DebugInformationFormat
.
Pdb
;
bool
debugPlus
=
false
;
string
pdbPath
=
null
;
bool
noStdLib
=
IsScript
Runn
er
;
// don't add mscorlib from sdk dir when running scripts
bool
noStdLib
=
IsScript
CommandLinePars
er
;
// don't add mscorlib from sdk dir when running scripts
string
outputDirectory
=
baseDirectory
;
ImmutableArray
<
KeyValuePair
<
string
,
string
>>
pathMap
=
ImmutableArray
<
KeyValuePair
<
string
,
string
>>.
Empty
;
string
outputFileName
=
null
;
...
...
@@ -130,7 +129,7 @@ public new CSharpCommandLineArguments Parse(IEnumerable<string> args, string bas
// Process ruleset files first so that diagnostic severity settings specified on the command line via
// /nowarn and /warnaserror can override diagnostic severity settings specified in the ruleset file.
if
(!
IsScript
Runn
er
)
if
(!
IsScript
CommandLinePars
er
)
{
foreach
(
string
arg
in
flattenedArgs
)
{
...
...
@@ -208,7 +207,7 @@ public new CSharpCommandLineArguments Parse(IEnumerable<string> args, string bas
#endif
}
if
(
IsScript
Runn
er
)
if
(
IsScript
CommandLinePars
er
)
{
switch
(
name
)
{
...
...
@@ -1194,7 +1193,7 @@ public new CSharpCommandLineArguments Parse(IEnumerable<string> args, string bas
AddDiagnostic
(
diagnostics
,
diagnosticOptions
,
ErrorCode
.
ERR_NoNetModuleOutputWhenRefOutOrRefOnly
);
}
if
(!
IsScript
Runn
er
&&
!
sourceFilesSpecified
&&
(
outputKind
.
IsNetModule
()
||
!
resourcesOrModulesSpecified
))
if
(!
IsScript
CommandLinePars
er
&&
!
sourceFilesSpecified
&&
(
outputKind
.
IsNetModule
()
||
!
resourcesOrModulesSpecified
))
{
AddDiagnostic
(
diagnostics
,
diagnosticOptions
,
ErrorCode
.
WRN_NoSources
);
}
...
...
@@ -1262,7 +1261,7 @@ public new CSharpCommandLineArguments Parse(IEnumerable<string> args, string bas
languageVersion
:
languageVersion
,
preprocessorSymbols
:
defines
.
ToImmutableAndFree
(),
documentationMode
:
parseDocumentationComments
?
DocumentationMode
.
Diagnose
:
DocumentationMode
.
None
,
kind
:
IsScript
Runn
er
?
SourceCodeKind
.
Script
:
SourceCodeKind
.
Regular
,
kind
:
IsScript
CommandLinePars
er
?
SourceCodeKind
.
Script
:
SourceCodeKind
.
Regular
,
features
:
parsedFeatures
);
...
...
@@ -1319,8 +1318,8 @@ public new CSharpCommandLineArguments Parse(IEnumerable<string> args, string bas
return
new
CSharpCommandLineArguments
{
IsScriptRunner
=
IsScript
Runn
er
,
InteractiveMode
=
interactiveMode
||
IsScript
Runn
er
&&
sourceFiles
.
Count
==
0
,
IsScriptRunner
=
IsScript
CommandLinePars
er
,
InteractiveMode
=
interactiveMode
||
IsScript
CommandLinePars
er
&&
sourceFiles
.
Count
==
0
,
BaseDirectory
=
baseDirectory
,
PathMap
=
pathMap
,
Errors
=
diagnostics
.
AsImmutable
(),
...
...
@@ -1433,7 +1432,7 @@ private static string GetWin32Setting(string arg, string value, List<Diagnostic>
// names from the files containing their entrypoints and libraries derive their names from
// their first input files.
if
(!
IsScript
Runn
er
&&
!
sourceFilesSpecified
)
if
(!
IsScript
CommandLinePars
er
&&
!
sourceFilesSpecified
)
{
AddDiagnostic
(
diagnostics
,
ErrorCode
.
ERR_OutputNeedsName
);
simpleName
=
null
;
...
...
@@ -1467,7 +1466,7 @@ private static string GetWin32Setting(string arg, string value, List<Diagnostic>
if
(
outputKind
.
IsNetModule
())
{
Debug
.
Assert
(!
IsScript
Runn
er
);
Debug
.
Assert
(!
IsScript
CommandLinePars
er
);
compilationName
=
moduleAssemblyName
;
}
...
...
@@ -1509,7 +1508,7 @@ private ImmutableArray<string> BuildSearchPaths(string sdkDirectoryOpt, List<str
// with references relative to csi.exe (e.g. System.ValueTuple.dll).
if
(
responsePathsOpt
!=
null
)
{
Debug
.
Assert
(
IsScript
Runn
er
);
Debug
.
Assert
(
IsScript
CommandLinePars
er
);
builder
.
AddRange
(
responsePathsOpt
);
}
...
...
src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt
浏览文件 @
c4292e69
...
...
@@ -14,6 +14,7 @@ Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax.WithRefKindKeyword(Microsoft
Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax.ReadOnlyKeyword.get -> Microsoft.CodeAnalysis.SyntaxToken
Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax.Update(Microsoft.CodeAnalysis.SyntaxToken refKeyword, Microsoft.CodeAnalysis.SyntaxToken readOnlyKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax type) -> Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax
Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax.WithReadOnlyKeyword(Microsoft.CodeAnalysis.SyntaxToken readOnlyKeyword) -> Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax
static Microsoft.CodeAnalysis.CSharp.CSharpCommandLineParser.Script.get -> Microsoft.CodeAnalysis.CSharp.CSharpCommandLineParser
static Microsoft.CodeAnalysis.CSharp.CSharpExtensions.GetConversion(this Microsoft.CodeAnalysis.Operations.IConversionOperation conversionExpression) -> Microsoft.CodeAnalysis.CSharp.Conversion
static Microsoft.CodeAnalysis.CSharp.CSharpExtensions.GetDeconstructionInfo(this Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.CSharp.Syntax.AssignmentExpressionSyntax assignment) -> Microsoft.CodeAnalysis.CSharp.DeconstructionInfo
static Microsoft.CodeAnalysis.CSharp.CSharpExtensions.GetDeconstructionInfo(this Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.CSharp.Syntax.ForEachVariableStatementSyntax foreach) -> Microsoft.CodeAnalysis.CSharp.DeconstructionInfo
...
...
src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
浏览文件 @
c4292e69
...
...
@@ -89,7 +89,7 @@ private static CSharpCommandLineArguments DefaultParse(IEnumerable<string> args,
private
static
CSharpCommandLineArguments
ScriptParse
(
IEnumerable
<
string
>
args
,
string
baseDirectory
)
{
return
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
args
,
baseDirectory
,
s_defaultSdkDirectory
);
return
CSharpCommandLineParser
.
Script
.
Parse
(
args
,
baseDirectory
,
s_defaultSdkDirectory
);
}
private
static
CSharpCommandLineArguments
FullParse
(
string
commandLine
,
string
baseDirectory
,
string
sdkDirectory
=
null
,
string
additionalReferenceDirectories
=
null
)
...
...
@@ -1092,53 +1092,53 @@ public void ModuleManifest()
[
Fact
]
public
void
ArgumentParsing
()
{
var
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"a + b"
},
_baseDirectory
,
s_defaultSdkDirectory
);
var
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"a + b"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
Assert
.
False
(
parsedArgs
.
DisplayHelp
);
Assert
.
True
(
parsedArgs
.
SourceFiles
.
Any
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"a + b; c"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"a + b; c"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
Assert
.
False
(
parsedArgs
.
DisplayHelp
);
Assert
.
True
(
parsedArgs
.
SourceFiles
.
Any
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"/help"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"/help"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
Assert
.
True
(
parsedArgs
.
DisplayHelp
);
Assert
.
False
(
parsedArgs
.
SourceFiles
.
Any
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"/version"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"/version"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
Assert
.
True
(
parsedArgs
.
DisplayVersion
);
Assert
.
False
(
parsedArgs
.
SourceFiles
.
Any
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"/langversion:?"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"/langversion:?"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
(
// error CS2007: Unrecognized option: '/langversion:?'
Diagnostic
(
ErrorCode
.
ERR_BadSwitch
).
WithArguments
(
"/langversion:?"
).
WithLocation
(
1
,
1
)
);
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"/version"
,
"c.csx"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"/version"
,
"c.csx"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
Assert
.
True
(
parsedArgs
.
DisplayVersion
);
Assert
.
True
(
parsedArgs
.
SourceFiles
.
Any
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"/version:something"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"/version:something"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
Assert
.
True
(
parsedArgs
.
DisplayVersion
);
Assert
.
False
(
parsedArgs
.
SourceFiles
.
Any
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"/?"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"/?"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
Assert
.
True
(
parsedArgs
.
DisplayHelp
);
Assert
.
False
(
parsedArgs
.
SourceFiles
.
Any
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"c.csx /langversion:6"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"c.csx /langversion:6"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
Assert
.
False
(
parsedArgs
.
DisplayHelp
);
Assert
.
True
(
parsedArgs
.
SourceFiles
.
Any
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"/langversion:-1"
,
"c.csx"
,
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"/langversion:-1"
,
"c.csx"
,
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
(
// error CS2007: Unrecognized option: '/langversion:-1'
Diagnostic
(
ErrorCode
.
ERR_BadSwitch
).
WithArguments
(
"/langversion:-1"
));
...
...
@@ -1146,12 +1146,12 @@ public void ArgumentParsing()
Assert
.
False
(
parsedArgs
.
DisplayHelp
);
Assert
.
Equal
(
1
,
parsedArgs
.
SourceFiles
.
Length
);
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"c.csx /r:s=d /r:d.dll"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"c.csx /r:s=d /r:d.dll"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
Assert
.
False
(
parsedArgs
.
DisplayHelp
);
Assert
.
True
(
parsedArgs
.
SourceFiles
.
Any
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"@roslyn_test_non_existing_file"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"@roslyn_test_non_existing_file"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
(
// error CS2011: Error opening response file 'D:\R0\Main\Binaries\Debug\dd'
Diagnostic
(
ErrorCode
.
ERR_OpenResponseFile
).
WithArguments
(
Path
.
Combine
(
_baseDirectory
,
@"roslyn_test_non_existing_file"
)));
...
...
@@ -1159,34 +1159,34 @@ public void ArgumentParsing()
Assert
.
False
(
parsedArgs
.
DisplayHelp
);
Assert
.
False
(
parsedArgs
.
SourceFiles
.
Any
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"c /define:DEBUG"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"c /define:DEBUG"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
Assert
.
False
(
parsedArgs
.
DisplayHelp
);
Assert
.
True
(
parsedArgs
.
SourceFiles
.
Any
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"\\"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"\\"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
Assert
.
False
(
parsedArgs
.
DisplayHelp
);
Assert
.
True
(
parsedArgs
.
SourceFiles
.
Any
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"/r:d.dll"
,
"c.csx"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"/r:d.dll"
,
"c.csx"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
Assert
.
False
(
parsedArgs
.
DisplayHelp
);
Assert
.
True
(
parsedArgs
.
SourceFiles
.
Any
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"/define:goo"
,
"c.csx"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"/define:goo"
,
"c.csx"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
(
// error CS2007: Unrecognized option: '/define:goo'
Diagnostic
(
ErrorCode
.
ERR_BadSwitch
).
WithArguments
(
"/define:goo"
));
Assert
.
False
(
parsedArgs
.
DisplayHelp
);
Assert
.
True
(
parsedArgs
.
SourceFiles
.
Any
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"\"/r d.dll\""
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"\"/r d.dll\""
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
Assert
.
False
(
parsedArgs
.
DisplayHelp
);
Assert
.
True
(
parsedArgs
.
SourceFiles
.
Any
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
[]
{
"/r: d.dll"
,
"a.cs"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
[]
{
"/r: d.dll"
,
"a.cs"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
Assert
.
False
(
parsedArgs
.
DisplayHelp
);
Assert
.
True
(
parsedArgs
.
SourceFiles
.
Any
());
...
...
@@ -4041,19 +4041,19 @@ public void Usings()
{
CSharpCommandLineArguments
parsedArgs
;
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
string
[]
{
"/u:Goo.Bar"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
string
[]
{
"/u:Goo.Bar"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
AssertEx
.
Equal
(
new
[]
{
"Goo.Bar"
},
parsedArgs
.
CompilationOptions
.
Usings
.
AsEnumerable
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
string
[]
{
"/u:Goo.Bar;Baz"
,
"/using:System.Core;System"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
string
[]
{
"/u:Goo.Bar;Baz"
,
"/using:System.Core;System"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
AssertEx
.
Equal
(
new
[]
{
"Goo.Bar"
,
"Baz"
,
"System.Core"
,
"System"
},
parsedArgs
.
CompilationOptions
.
Usings
.
AsEnumerable
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
string
[]
{
"/u:Goo;;Bar"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
string
[]
{
"/u:Goo;;Bar"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
();
AssertEx
.
Equal
(
new
[]
{
"Goo"
,
"Bar"
},
parsedArgs
.
CompilationOptions
.
Usings
.
AsEnumerable
());
parsedArgs
=
CSharpCommandLineParser
.
Script
Runner
.
Parse
(
new
string
[]
{
"/u:"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
=
CSharpCommandLineParser
.
Script
.
Parse
(
new
string
[]
{
"/u:"
},
_baseDirectory
,
s_defaultSdkDirectory
);
parsedArgs
.
Errors
.
Verify
(
// error CS2006: Command-line syntax error: Missing '<namespace>' for '/u:' option
Diagnostic
(
ErrorCode
.
ERR_SwitchNeedsString
).
WithArguments
(
"<namespace>"
,
"/u:"
));
...
...
src/Compilers/Core/Portable/CommandLine/CommonCommandLineParser.cs
浏览文件 @
c4292e69
...
...
@@ -2,30 +2,29 @@
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
using
System.Diagnostics
;
using
System.Globalization
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
Microsoft.CodeAnalysis.Collections
;
using
Microsoft.CodeAnalysis.PooledObjects
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
using
System.Collections.Immutable
;
namespace
Microsoft.CodeAnalysis
{
public
abstract
class
CommandLineParser
{
private
readonly
CommonMessageProvider
_messageProvider
;
internal
readonly
bool
IsScript
Runn
er
;
internal
readonly
bool
IsScript
CommandLinePars
er
;
private
static
readonly
char
[]
s_searchPatternTrimChars
=
new
char
[]
{
'\t'
,
'\n'
,
'\v'
,
'\f'
,
'\r'
,
' '
,
'\
x0085
'
,
'\
x00a0
'
};
internal
CommandLineParser
(
CommonMessageProvider
messageProvider
,
bool
isScript
Runn
er
)
internal
CommandLineParser
(
CommonMessageProvider
messageProvider
,
bool
isScript
CommandLinePars
er
)
{
Debug
.
Assert
(
messageProvider
!=
null
);
_messageProvider
=
messageProvider
;
IsScript
Runner
=
isScriptRunn
er
;
IsScript
CommandLineParser
=
isScriptCommandLinePars
er
;
}
internal
CommonMessageProvider
MessageProvider
...
...
@@ -794,7 +793,7 @@ private CommandLineSourceFile ToCommandLineSourceFile(string resolvedPath)
string
extension
=
PathUtilities
.
GetExtension
(
resolvedPath
);
bool
isScriptFile
;
if
(
IsScript
Runn
er
)
if
(
IsScript
CommandLinePars
er
)
{
isScriptFile
=
!
string
.
Equals
(
extension
,
RegularFileExtension
,
StringComparison
.
OrdinalIgnoreCase
);
}
...
...
@@ -810,7 +809,7 @@ private CommandLineSourceFile ToCommandLineSourceFile(string resolvedPath)
internal
IEnumerable
<
CommandLineSourceFile
>
ParseFileArgument
(
string
arg
,
string
baseDirectory
,
IList
<
Diagnostic
>
errors
)
{
Debug
.
Assert
(
IsScript
Runn
er
||
!
arg
.
StartsWith
(
"-"
,
StringComparison
.
Ordinal
)
&&
!
arg
.
StartsWith
(
"@"
,
StringComparison
.
Ordinal
));
Debug
.
Assert
(
IsScript
CommandLinePars
er
||
!
arg
.
StartsWith
(
"-"
,
StringComparison
.
Ordinal
)
&&
!
arg
.
StartsWith
(
"@"
,
StringComparison
.
Ordinal
));
// We remove all doubles quotes from a file name. So that, for example:
// "Path With Spaces"\goo.cs
...
...
src/Compilers/Test/Utilities/VisualBasic/MockVbi.vb
浏览文件 @
c4292e69
...
...
@@ -9,7 +9,7 @@ Friend Class MockVbi
Inherits
VisualBasicCompiler
Public
Sub
New
(
responseFile
As
String
,
workingDirectory
As
String
,
args
As
String
())
MyBase
.
New
(
VisualBasicCommandLineParser
.
Script
Runner
,
responseFile
,
args
,
CreateBuildPaths
(
workingDirectory
),
Nothing
,
New
DesktopAnalyzerAssemblyLoader
())
MyBase
.
New
(
VisualBasicCommandLineParser
.
Script
,
responseFile
,
args
,
CreateBuildPaths
(
workingDirectory
),
Nothing
,
New
DesktopAnalyzerAssemblyLoader
())
End
Sub
Private
Shared
Function
CreateBuildPaths
(
workingDirectory
As
String
)
As
BuildPaths
...
...
src/Compilers/VisualBasic/Portable/CommandLine/VisualBasicCommandLineParser.vb
浏览文件 @
c4292e69
...
...
@@ -5,13 +5,11 @@ Imports System.Globalization
Imports
System.IO
Imports
System.Runtime.InteropServices
Imports
System.Text
Imports
Microsoft.CodeAnalysis.Collections
Imports
Microsoft.CodeAnalysis.Emit
Imports
Microsoft.CodeAnalysis.PooledObjects
Imports
Microsoft.CodeAnalysis.Text
Imports
Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports
Microsoft.CodeAnalysis.VisualBasic.SyntaxFacts
Imports
Roslyn.Utilities
Namespace
Microsoft.CodeAnalysis.VisualBasic
''' <summary>
...
...
@@ -22,19 +20,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
''' <summary>
''' Gets the current command line parser.
''' </summary>
Public
Shared
ReadOnly
Property
[
Default
]
As
VisualBasicCommandLineParser
=
New
VisualBasicCommandLineParser
()
Public
Shared
ReadOnly
Property
[
Default
]
As
New
VisualBasicCommandLineParser
()
''' <summary>
''' Gets the current interactive command line parser.
''' </summary>
Friend
Shared
ReadOnly
Property
ScriptRunner
As
VisualBasicCommandLineParser
=
New
VisualBasicCommandLineParser
(
isScriptRunn
er
:
=
True
)
Public
Shared
ReadOnly
Property
Script
As
New
VisualBasicCommandLineParser
(
isScriptCommandLinePars
er
:
=
True
)
''' <summary>
''' Creates a new command line parser.
''' </summary>
''' <param name="isScript
Runn
er">An optional parameter indicating whether to create a interactive command line parser.</param>
Friend
Sub
New
(
Optional
isScript
Runn
er
As
Boolean
=
False
)
MyBase
.
New
(
VisualBasic
.
MessageProvider
.
Instance
,
isScript
Runn
er
)
''' <param name="isScript
CommandLinePars
er">An optional parameter indicating whether to create a interactive command line parser.</param>
Friend
Sub
New
(
Optional
isScript
CommandLinePars
er
As
Boolean
=
False
)
MyBase
.
New
(
VisualBasic
.
MessageProvider
.
Instance
,
isScript
CommandLinePars
er
)
End
Sub
Private
Const
s_win32Manifest
As
String
=
"win32manifest"
...
...
@@ -78,7 +76,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim
diagnostics
As
List
(
Of
Diagnostic
)
=
New
List
(
Of
Diagnostic
)()
Dim
flattenedArgs
As
List
(
Of
String
)
=
New
List
(
Of
String
)()
Dim
scriptArgs
As
List
(
Of
String
)
=
If
(
IsScript
Runn
er
,
New
List
(
Of
String
)(),
Nothing
)
Dim
scriptArgs
As
List
(
Of
String
)
=
If
(
IsScript
CommandLinePars
er
,
New
List
(
Of
String
)(),
Nothing
)
' normalized paths to directories containing response files:
Dim
responsePaths
As
New
List
(
Of
String
)
...
...
@@ -165,7 +163,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
' Process ruleset files first so that diagnostic severity settings specified on the command line via
' /nowarn and /warnaserror can override diagnostic severity settings specified in the ruleset file.
If
Not
IsScript
Runn
er
Then
If
Not
IsScript
CommandLinePars
er
Then
For
Each
arg
In
flattenedArgs
Dim
name
As
String
=
Nothing
Dim
value
As
String
=
Nothing
...
...
@@ -420,7 +418,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
#End If
End
Select
If
IsScript
Runn
er
Then
If
IsScript
CommandLinePars
er
Then
Select
Case
name
Case
"i"
,
"i+"
If
value
IsNot
Nothing
Then
...
...
@@ -1207,7 +1205,7 @@ lVbRuntimePlus:
AddDiagnostic
(
diagnostics
,
ERRID
.
ERR_NoNetModuleOutputWhenRefOutOrRefOnly
)
End
If
If
Not
IsScript
Runn
er
AndAlso
Not
hasSourceFiles
AndAlso
managedResources
.
IsEmpty
()
Then
If
Not
IsScript
CommandLinePars
er
AndAlso
Not
hasSourceFiles
AndAlso
managedResources
.
IsEmpty
()
Then
' VB displays help when there is nothing specified on the command line
If
flattenedArgs
.
Any
Then
AddDiagnostic
(
diagnostics
,
ERRID
.
ERR_NoSources
)
...
...
@@ -1302,7 +1300,7 @@ lVbRuntimePlus:
Dim
compilationName
As
String
=
Nothing
GetCompilationAndModuleNames
(
diagnostics
,
outputKind
,
sourceFiles
,
moduleAssemblyName
,
outputFileName
,
moduleName
,
compilationName
)
If
Not
IsScript
Runn
er
AndAlso
If
Not
IsScript
CommandLinePars
er
AndAlso
Not
hasSourceFiles
AndAlso
Not
managedResources
.
IsEmpty
()
AndAlso
outputFileName
=
Nothing
AndAlso
...
...
@@ -1314,7 +1312,7 @@ lVbRuntimePlus:
Dim
parseOptions
=
New
VisualBasicParseOptions
(
languageVersion
:
=
languageVersion
,
documentationMode
:
=
If
(
parseDocumentationComments
,
DocumentationMode
.
Diagnose
,
DocumentationMode
.
None
),
kind
:
=
If
(
IsScript
Runn
er
,
SourceCodeKind
.
Script
,
SourceCodeKind
.
Regular
),
kind
:
=
If
(
IsScript
CommandLinePars
er
,
SourceCodeKind
.
Script
,
SourceCodeKind
.
Regular
),
preprocessorSymbols
:
=
AddPredefinedPreprocessorSymbols
(
outputKind
,
defines
.
AsImmutableOrEmpty
()),
features
:
=
parsedFeatures
)
...
...
@@ -1371,11 +1369,11 @@ lVbRuntimePlus:
' Enable interactive mode if either `\i` option is passed in or no arguments are specified (`vbi`, `vbi script.vbx \i`).
' If the script is passed without the `\i` option simply execute the script (`vbi script.vbx`).
interactiveMode
=
interactiveMode
Or
(
IsScript
Runn
er
AndAlso
sourceFiles
.
Count
=
0
)
interactiveMode
=
interactiveMode
Or
(
IsScript
CommandLinePars
er
AndAlso
sourceFiles
.
Count
=
0
)
Return
New
VisualBasicCommandLineArguments
With
{
.
IsScriptRunner
=
IsScript
Runn
er
,
.
IsScriptRunner
=
IsScript
CommandLinePars
er
,
.
InteractiveMode
=
interactiveMode
,
.
BaseDirectory
=
baseDirectory
,
.
Errors
=
diagnostics
.
AsImmutable
(),
...
...
@@ -2242,7 +2240,7 @@ lVbRuntimePlus:
End
If
If
kind
.
IsNetModule
()
Then
Debug
.
Assert
(
Not
IsScript
Runn
er
)
Debug
.
Assert
(
Not
IsScript
CommandLinePars
er
)
compilationName
=
moduleAssemblyName
Else
...
...
src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb
浏览文件 @
c4292e69
...
...
@@ -49,7 +49,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CommandLine.UnitTests
Private
Shared
Function
InteractiveParse
(
args
As
IEnumerable
(
Of
String
),
baseDirectory
As
String
,
Optional
sdkDirectory
As
String
=
Nothing
,
Optional
additionalReferenceDirectories
As
String
=
Nothing
)
As
VisualBasicCommandLineArguments
sdkDirectory
=
If
(
sdkDirectory
,
s_defaultSdkDirectory
)
Return
VisualBasicCommandLineParser
.
Script
Runner
.
Parse
(
args
,
baseDirectory
,
sdkDirectory
,
additionalReferenceDirectories
)
Return
VisualBasicCommandLineParser
.
Script
.
Parse
(
args
,
baseDirectory
,
sdkDirectory
,
additionalReferenceDirectories
)
End
Function
<
Fact
>
...
...
src/Interactive/EditorFeatures/CSharp/Interactive/CSharpInteractiveEvaluator.cs
浏览文件 @
c4292e69
...
...
@@ -76,7 +76,7 @@ public override bool CanExecuteCode(string text)
protected
override
CommandLineParser
CommandLineParser
{
get
{
return
CSharpCommandLineParser
.
Script
Runner
;
}
get
{
return
CSharpCommandLineParser
.
Script
;
}
}
}
}
src/Interactive/EditorFeatures/CSharp/Interactive/CSharpReplServiceProvider.cs
浏览文件 @
c4292e69
...
...
@@ -18,7 +18,7 @@ public CSharpReplServiceProvider()
}
public
override
ObjectFormatter
ObjectFormatter
{
get
;
}
=
CSharpObjectFormatter
.
Instance
;
public
override
CommandLineParser
CommandLineParser
=>
CSharpCommandLineParser
.
Script
Runner
;
public
override
CommandLineParser
CommandLineParser
=>
CSharpCommandLineParser
.
Script
;
public
override
DiagnosticFormatter
DiagnosticFormatter
=>
CSharpDiagnosticFormatter
.
Instance
;
public
override
string
Logo
...
...
src/Interactive/EditorFeatures/VisualBasic/Interactive/VisualBasicInteractiveEvaluator.vb
浏览文件 @
c4292e69
...
...
@@ -51,7 +51,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Interactive
Protected
Overrides
ReadOnly
Property
CommandLineParser
As
CommandLineParser
Get
Return
VisualBasicCommandLineParser
.
Script
Runner
Return
VisualBasicCommandLineParser
.
Script
End
Get
End
Property
...
...
src/Interactive/EditorFeatures/VisualBasic/Interactive/VisualBasicReplServiceProvider.vb
浏览文件 @
c4292e69
...
...
@@ -16,7 +16,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.Interactive
Public
Overrides
ReadOnly
Property
CommandLineParser
As
CommandLineParser
Get
Return
VisualBasicCommandLineParser
.
Script
Runner
Return
VisualBasicCommandLineParser
.
Script
End
Get
End
Property
...
...
src/Scripting/CSharp/Hosting/CommandLine/Csi.cs
浏览文件 @
c4292e69
...
...
@@ -14,7 +14,7 @@ internal sealed class CSharpInteractiveCompiler : CSharpCompiler
{
internal
CSharpInteractiveCompiler
(
string
responseFile
,
BuildPaths
buildPaths
,
string
[]
args
,
IAnalyzerAssemblyLoader
analyzerLoader
)
// Unlike C# compiler we do not use LIB environment variable. It's only supported for historical reasons.
:
base
(
CSharpCommandLineParser
.
Script
Runner
,
responseFile
,
args
,
buildPaths
,
null
,
analyzerLoader
)
:
base
(
CSharpCommandLineParser
.
Script
,
responseFile
,
args
,
buildPaths
,
null
,
analyzerLoader
)
{
}
...
...
src/Scripting/VisualBasic/Hosting/CommandLine/Vbi.vb
浏览文件 @
c4292e69
...
...
@@ -12,7 +12,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Scripting.Hosting
Inherits
VisualBasicCompiler
Friend
Sub
New
(
responseFile
As
String
,
buildPaths
As
BuildPaths
,
args
As
String
(),
analyzerLoader
As
IAnalyzerAssemblyLoader
)
MyBase
.
New
(
VisualBasicCommandLineParser
.
Script
Runner
,
responseFile
,
args
,
buildPaths
,
Nothing
,
analyzerLoader
)
MyBase
.
New
(
VisualBasicCommandLineParser
.
Script
,
responseFile
,
args
,
buildPaths
,
Nothing
,
analyzerLoader
)
End
Sub
Friend
Overrides
Function
GetCommandLineMetadataReferenceResolver
(
loggerOpt
As
TouchedFileLogger
)
As
MetadataReferenceResolver
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录