Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ internal LookupResultKind ResultKind
return LookupResultKind.OverloadResolutionFailure;
}
default:
Debug.Assert(false, "Unknown UserDefinedConversionResultKind " + this.conversionResult.Kind);
Debug.Assert(false, $"Unknown UserDefinedConversionResultKind {this.conversionResult.Kind}");
return LookupResultKind.OverloadResolutionFailure;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public string Dump()
{
var sb = new System.Text.StringBuilder();
sb.AppendLine("User defined conversion analysis results:");
sb.AppendFormat("Summary: {0}\n", Kind);
sb.AppendLine($"Summary: {Kind}");
for (int i = 0; i < Results.Length; ++i)
{
sb.AppendFormat("{0} Conversion: {1} Result: {2}\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static BinaryOperatorKind WithType(this BinaryOperatorKind kind, SpecialT
case SpecialType.System_UInt64:
return kind | BinaryOperatorKind.ULong;
default:
Debug.Assert(false, "Unexpected binary operator type.");
Debug.Assert(false, _Unexpected);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous error said it was a binary operator while this error states that it is a unary operator.

return kind;
}
}
Expand All @@ -171,10 +171,11 @@ public static UnaryOperatorKind WithType(this UnaryOperatorKind kind, SpecialTyp
case SpecialType.System_UInt64:
return kind | UnaryOperatorKind.ULong;
default:
Debug.Assert(false, "Unexpected unary operator type.");
Debug.Assert(false, _Unexpected);
return kind;
}
}


public static BinaryOperatorKind WithType(this BinaryOperatorKind kind, BinaryOperatorKind type)
{
Expand Down Expand Up @@ -398,9 +399,9 @@ public static ExpressionType ToExpressionType(this UnaryOperatorKind kind)
public static string Dump(this BinaryOperatorKind kind)
{
var b = new StringBuilder();
if ((kind & BinaryOperatorKind.Lifted) != 0) b.Append("Lifted");
if ((kind & BinaryOperatorKind.Logical) != 0) b.Append("Logical");
if ((kind & BinaryOperatorKind.Checked) != 0) b.Append("Checked");
if ((kind & BinaryOperatorKind.Lifted) != 0) b.Append(_Lifted);
if ((kind & BinaryOperatorKind.Logical) != 0) b.Append(_Logical);
if ((kind & BinaryOperatorKind.Checked) != 0) b.Append(_Checked);
var type = kind & BinaryOperatorKind.TypeMask;
if (type != 0) b.Append(type.ToString());
var op = kind & BinaryOperatorKind.OpMask;
Expand All @@ -411,14 +412,18 @@ public static string Dump(this BinaryOperatorKind kind)
public static string Dump(this UnaryOperatorKind kind)
{
var b = new StringBuilder();
if ((kind & UnaryOperatorKind.Lifted) != 0) b.Append("Lifted");
if ((kind & UnaryOperatorKind.Checked) != 0) b.Append("Checked");
if ((kind & UnaryOperatorKind.Lifted) != 0) b.Append(_Lifted);
if ((kind & UnaryOperatorKind.Checked) != 0) b.Append(_Checked);
var type = kind & UnaryOperatorKind.TypeMask;
if (type != 0) b.Append(type.ToString());
var op = kind & UnaryOperatorKind.OpMask;
if (op != 0) b.Append(op.ToString());
return b.ToString();
}
const string _Lifted = "Lifted";
const string _Checked = "Checked";
const string _Logical = "Logical";
const string _Unexpected = "Unexpected unary operator type.";
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,35 @@ public UnaryOperatorAnalysisResult Best
}
}


const string _OverFail = "Overload resolution failed because";
const string _OverSucc = "Overload resolution succeeded";
#if DEBUG
public string Dump()
{
if (Results.Count == 0)
{
return "Overload resolution failed because there were no candidate operators.";
return $"{_OverFail} there were no candidate operators.";
}

var sb = new StringBuilder();
if (this.Best.HasValue)
{
sb.AppendLine("Overload resolution succeeded and chose " + this.Best.Signature.ToString());
sb.AppendLine($"{_OverSucc} and chose {this.Best.Signature.ToString()}");
}
else if (CountKind(OperatorAnalysisResultKind.Applicable) > 1)
{
sb.AppendLine("Overload resolution failed because of ambiguous possible best operators.");
sb.AppendLine($"{_OverFail} of ambiguous possible best operators.");
}
else
{
sb.AppendLine("Overload resolution failed because no operator was applicable.");
sb.AppendLine($"{_OverFail} no operator was applicable.");
}

sb.AppendLine("Detailed results:");
foreach (var result in Results)
{
sb.AppendFormat("operator: {0} reason: {1}\n", result.Signature.ToString(), result.Kind.ToString());
sb.AppendLine($"operator: {result.Signature.ToString()} reason: {result.Kind.ToString()}");
}

return sb.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,24 @@ private string Dump()
s += "Valid in expanded form.";
break;
case ArgumentAnalysisResultKind.NameUsedForPositional:
s += "Invalid because argument " + ArgumentPosition + " had a name.";
s += $"Invalid because argument {ArgumentPosition} had a name.";
break;
case ArgumentAnalysisResultKind.NoCorrespondingParameter:
s += "Invalid because argument " + ArgumentPosition + " has no corresponding parameter.";
s += $"Invalid because argument {ArgumentPosition} has no corresponding parameter.";
break;
case ArgumentAnalysisResultKind.NoCorrespondingNamedParameter:
s += "Invalid because named argument " + ArgumentPosition + " has no corresponding parameter.";
s += $"Invalid because named argument {ArgumentPosition} has no corresponding parameter.";
break;
case ArgumentAnalysisResultKind.RequiredParameterMissing:
s += "Invalid because parameter " + ParameterPosition + " has no corresponding argument.";
s += $"Invalid because parameter {ParameterPosition} has no corresponding argument.";
break;
}

if (!ArgsToParamsOpt.IsDefault)
{
for (int i = 0; i < ArgsToParamsOpt.Length; ++i)
{
s += "\nArgument " + i + " corresponds to parameter " + ArgsToParamsOpt[i];
s += $"\nArgument {i} corresponds to parameter {ArgsToParamsOpt[i]}";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ internal string Dump()
sb.AppendLine("Detailed results:");
foreach (var result in ResultsBuilder)
{
sb.AppendFormat("method: {0} reason: {1}\n", result.Member.ToString(), result.Result.Kind.ToString());
sb.AppendLine($"method: {result.Member.ToString()} reason: {result.Result.Kind.ToString()}");
}

return sb.ToString();
Expand Down
5 changes: 4 additions & 1 deletion src/Compilers/CSharp/Portable/CSharpCodeAnalysis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<DefineConstants>TRACE;DEBUG</DefineConstants>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<CodeAnalysisRuleSet>..\CSharpCodeAnalysisRules.ruleset</CodeAnalysisRuleSet>
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<CodeAnalysisRuleSet>..\CSharpCodeAnalysisRules.ruleset</CodeAnalysisRuleSet>
Expand Down Expand Up @@ -345,6 +346,7 @@
<Compile Include="Errors\SyntaxDiagnosticInfo.cs" />
<Compile Include="Errors\XmlParseErrorCode.cs" />
<Compile Include="Errors\XmlSyntaxDiagnosticInfo.cs" />
<Compile Include="Utilities\GenericExtensions.cs" />
<Compile Include="FlowAnalysis\AbstractFlowPass.cs" />
<Compile Include="FlowAnalysis\AbstractRegionControlFlowPass.cs" />
<Compile Include="FlowAnalysis\AbstractRegionDataFlowPass.cs" />
Expand Down Expand Up @@ -886,11 +888,12 @@
<HintPath>..\..\..\..\packages\System.Reflection.Metadata.1.0.18-beta\lib\portable-net45+win8\System.Reflection.Metadata.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup />
<Import Project="..\CSharpAnalyzerDriver\CSharpAnalyzerDriver.projitems" Label="Shared" />
<ImportGroup Label="Targets">
<Import Project="..\..\..\Tools\Microsoft.CodeAnalysis.Toolset.Open\Targets\VSL.Imports.targets" />
<Import Project="..\..\..\..\build\VSL.Imports.Closed.targets" />
<Import Project="..\..\..\..\packages\StyleCop.MSBuild.4.7.48.2\build\StyleCop.MSBuild.Targets" Condition="Exists('..\..\..\..\packages\StyleCop.MSBuild.4.7.48.2\build\StyleCop.MSBuild.Targets')" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</ImportGroup>
</Project>
</Project>
10 changes: 9 additions & 1 deletion src/Compilers/CSharp/Portable/Errors/SyntaxDiagnosticInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ internal class SyntaxDiagnosticInfo : DiagnosticInfo
internal readonly int Offset;
internal readonly int Width;

internal SyntaxDiagnosticInfo(int offset, int width, ErrorCode code, params object[] args)

internal SyntaxDiagnosticInfo(int offset, int width, ErrorCode code, string arg)
: base(CSharp.MessageProvider.Instance, (int)code, arg)
{
Debug.Assert(width >= 0);
this.Offset = offset;
this.Width = width;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: blank line separator

internal SyntaxDiagnosticInfo(int offset, int width, ErrorCode code, params object[] args)
: base(CSharp.MessageProvider.Instance, (int)code, args)
{
Debug.Assert(width >= 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ namespace Microsoft.CodeAnalysis.CSharp
internal sealed class XmlSyntaxDiagnosticInfo : SyntaxDiagnosticInfo
{
private readonly XmlParseErrorCode xmlErrorCode;

internal XmlSyntaxDiagnosticInfo(XmlParseErrorCode code, params object[] args)
internal XmlSyntaxDiagnosticInfo(XmlParseErrorCode code, string arg)
: this(0, 0, code, arg)
{
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Need a blank line separator here

internal XmlSyntaxDiagnosticInfo(XmlParseErrorCode code, params object[] args)
: this(0, 0, code, args)
{
}
Expand Down
63 changes: 27 additions & 36 deletions src/Compilers/CSharp/Portable/Parser/AbstractLexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,38 +60,28 @@ protected SyntaxDiagnosticInfo[] GetErrors(int leadingTriviaWidth)
return null;
}
}
protected void AddError(int position, int width, ErrorCode code, string arg )
{
this.AddError(this.MakeError(position, width, code, arg));
}

protected void AddError(int position, int width, ErrorCode code)
{
this.AddError(this.MakeError(position, width, code));
}

protected void AddError(int position, int width, ErrorCode code, params object[] args)
protected void AddError(int position, int width, ErrorCode code, object[] args = null)
{
this.AddError(this.MakeError(position, width, code, args));
}

protected void AddError(int position, int width, XmlParseErrorCode code, params object[] args)
protected void AddError(int position, int width, XmlParseErrorCode code, object[] args = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What problem does this change solve?

{
this.AddError(this.MakeError(position, width, code, args));
}

protected void AddError(ErrorCode code)
{
this.AddError(MakeError(code));
}

protected void AddError(ErrorCode code, params object[] args)
{
this.AddError(MakeError(code, args));
}

protected void AddError(XmlParseErrorCode code)
{
this.AddError(MakeError(code));
}

protected void AddError(XmlParseErrorCode code, params object[] args)
protected void AddError(XmlParseErrorCode code, object[] args = null)
{
this.AddError(MakeError(code, args));
}
Expand All @@ -109,19 +99,21 @@ protected void AddError(SyntaxDiagnosticInfo error)
}
}

protected SyntaxDiagnosticInfo MakeError(int position, int width, ErrorCode code)
{
int offset = GetLexemeOffsetFromPosition(position);
return new SyntaxDiagnosticInfo(offset, width, code);
}

protected SyntaxDiagnosticInfo MakeError(int position, int width, ErrorCode code, params object[] args)
protected SyntaxDiagnosticInfo MakeError(int position, int width, ErrorCode code, string arg )
{
int offset = GetLexemeOffsetFromPosition(position);
return new SyntaxDiagnosticInfo(offset, width, code, arg);
}


protected SyntaxDiagnosticInfo MakeError(int position, int width, ErrorCode code, object[] args = null)
{
int offset = GetLexemeOffsetFromPosition(position);
return new SyntaxDiagnosticInfo(offset, width, code, args);
return new SyntaxDiagnosticInfo( offset, width, code, args);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: extra space


protected XmlSyntaxDiagnosticInfo MakeError(int position, int width, XmlParseErrorCode code, params object[] args)
protected XmlSyntaxDiagnosticInfo MakeError(int position, int width, XmlParseErrorCode code, object[] args = null)
{
int offset = GetLexemeOffsetFromPosition(position);
return new XmlSyntaxDiagnosticInfo(offset, width, code, args);
Expand All @@ -132,24 +124,23 @@ private int GetLexemeOffsetFromPosition(int position)
return position >= TextWindow.LexemeStartPosition ? position - TextWindow.LexemeStartPosition : position;
}

protected static SyntaxDiagnosticInfo MakeError(ErrorCode code)
{
return new SyntaxDiagnosticInfo(code);
}
protected static SyntaxDiagnosticInfo MakeError(ErrorCode code, string arg)
{
return new SyntaxDiagnosticInfo(code, arg);
}

protected static SyntaxDiagnosticInfo MakeError(ErrorCode code, params object[] args)
protected static SyntaxDiagnosticInfo MakeError(ErrorCode code, object[] args = null)
{
return new SyntaxDiagnosticInfo(code, args);
}

protected static XmlSyntaxDiagnosticInfo MakeError(XmlParseErrorCode code)
{
return new XmlSyntaxDiagnosticInfo(0, 0, code);
}

protected static XmlSyntaxDiagnosticInfo MakeError(XmlParseErrorCode code, params object[] args)
protected static XmlSyntaxDiagnosticInfo MakeError(XmlParseErrorCode code, object[] args = null)
{
return new XmlSyntaxDiagnosticInfo(0, 0, code, args);
}
protected static XmlSyntaxDiagnosticInfo MakeError(XmlParseErrorCode code, string arg)
{
return new XmlSyntaxDiagnosticInfo(0, 0, code, arg);
}
}
}
12 changes: 6 additions & 6 deletions src/Compilers/CSharp/Portable/Parser/CharacterInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ public static partial class SyntaxFacts
/// <returns>true if the character is a hexadecimal digit 0-9, A-F, a-f.</returns>
internal static bool IsHexDigit(char c)
{
return (c >= '0' && c <= '9') ||
(c >= 'A' && c <= 'F') ||
(c >= 'a' && c <= 'f');
return c.IsDecDigit() ||
c.IsBetween('A','F') ||
c.IsBetween('a','f');
}

/// <summary>
/// Returns true if the Unicode character is a decimal digit.
/// </summary>
/// <param name="c">The Unicode character.</param>
/// <returns>true if the Unicode character is a decimal digit.</returns>
internal static bool IsDecDigit(char c)
internal static bool IsDecDigit(this char c)
{
return c >= '0' && c <= '9';
return c.IsBetween('0','9');
}

/// <summary>
Expand All @@ -39,7 +39,7 @@ internal static bool IsDecDigit(char c)
internal static int HexValue(char c)
{
Debug.Assert(IsHexDigit(c));
return (c >= '0' && c <= '9') ? c - '0' : (c & 0xdf) - 'A' + 10;
return c.IsDecDigit() ? c - '0' : (c & 0xdf) - 'A' + 10;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Parser/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ private double GetValueDouble(string text)
if (!Double.TryParse(text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out result))
{
//we've already lexed the literal, so the error must be from overflow
this.AddError(MakeError(ErrorCode.ERR_FloatOverflow, "double"));
this.AddError(MakeError(ErrorCode.ERR_FloatOverflow, "double" ));
}

return result;
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ private void ScanInterpolatedStringLiteralContents(ArrayBuilder<Interpolation> i
char ch = lexer.ScanEscapeSequence(out c2);
if ((ch == '{' || ch == '}') && error == null)
{
error = lexer.MakeError(escapeStart, lexer.TextWindow.Position - escapeStart, ErrorCode.ERR_EscapedCurly, ch);
error = lexer.MakeError(escapeStart, lexer.TextWindow.Position - escapeStart, ErrorCode.ERR_EscapedCurly, ch.ToString());
}

continue;
Expand All @@ -450,7 +450,7 @@ private void ScanFormatSpecifier()
ch = lexer.ScanEscapeSequence(out c2);
if ((ch == '{' || ch == '}') && error == null)
{
error = lexer.MakeError(pos, 1, ErrorCode.ERR_EscapedCurly, ch);
error = lexer.MakeError(pos, 1, ErrorCode.ERR_EscapedCurly, ch.ToString());
}
}
else if (ch == '"')
Expand Down
Loading