Skip to content

Commit

Permalink
update roslyn & fix warnning
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghuan committed Dec 18, 2019
1 parent e3da7fc commit c96f909
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 66 deletions.
2 changes: 1 addition & 1 deletion CSharp.lua/CSharp.lua.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.3.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.4.0" />
</ItemGroup>

<ItemGroup>
Expand Down
22 changes: 11 additions & 11 deletions CSharp.lua/LuaSyntaxGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public int Indent {
private readonly Dictionary<INamedTypeSymbol, List<PartialTypeDeclaration>> partialTypes_ = new Dictionary<INamedTypeSymbol, List<PartialTypeDeclaration>>();
private readonly HashSet<string> monoBehaviourSpecialMethodNames_;
private IMethodSymbol mainEntryPoint_;
private List<LuaExpressionSyntax> assemblyAttributes_ = new List<LuaExpressionSyntax>();
private readonly List<LuaExpressionSyntax> assemblyAttributes_ = new List<LuaExpressionSyntax>();
public INamedTypeSymbol SystemExceptionTypeSymbol { get; }
private readonly INamedTypeSymbol monoBehaviourTypeSymbol_;

Expand Down Expand Up @@ -690,13 +690,13 @@ private LuaIdentifierNameSyntax InternalGetMemberName(ISymbol symbol) {
}

private static bool IsSameNameSymbol(ISymbol member, ISymbol symbol) {
if (member.Equals(symbol)) {
if (member.EQ(symbol)) {
return true;
}

if (symbol.Kind == SymbolKind.Method) {
var methodSymbol = (IMethodSymbol)symbol;
if (methodSymbol.PartialDefinitionPart != null && methodSymbol.PartialDefinitionPart.Equals(member)) {
if (methodSymbol.PartialDefinitionPart != null && methodSymbol.PartialDefinitionPart.EQ(member)) {
return true;
}
}
Expand Down Expand Up @@ -782,7 +782,7 @@ private LuaIdentifierNameSyntax GetStaticClassMemberName(ISymbol symbol) {
int index = 0;
foreach (ISymbol member in sameNameMembers) {
LuaIdentifierNameSyntax identifierName = GetMethodNameFromIndex(symbol, index);
if (member.Equals(symbol)) {
if (member.EQ(symbol)) {
symbolExpression = identifierName;
} else {
if (!memberNames_.ContainsKey(member)) {
Expand Down Expand Up @@ -843,7 +843,7 @@ private List<ISymbol> GetSameNameMembers(ISymbol symbol) {
var rootType = symbol.ContainingType;
var curTypeSymbol = rootType;
while (true) {
AddSimilarNameMembers(curTypeSymbol, names, members, !rootType.Equals(curTypeSymbol));
AddSimilarNameMembers(curTypeSymbol, names, members, !rootType.EQ(curTypeSymbol));
var baseTypeSymbol = curTypeSymbol.BaseType;
if (baseTypeSymbol != null) {
curTypeSymbol = baseTypeSymbol;
Expand Down Expand Up @@ -950,7 +950,7 @@ private int MemberSymbolComparison(ISymbol a, ISymbol b) {
if (countOfA == 1) {
var implementationOfA = a.InterfaceImplementations().First();
var implementationOfB = b.InterfaceImplementations().First();
if (implementationOfA.Equals(implementationOfB)) {
if (implementationOfA.EQ(implementationOfB)) {
throw new CompilationErrorException($"{a} is conflict with {b}");
}

Expand All @@ -976,7 +976,7 @@ private int MemberSymbolComparison(ISymbol a, ISymbol b) {
}

private int MemberSymbolCommonComparison(ISymbol a, ISymbol b) {
if (a.ContainingType.Equals(b.ContainingType)) {
if (a.ContainingType.EQ(b.ContainingType)) {
var type = a.ContainingType;
var names = GetSymbolNames(a);
List<ISymbol> members = new List<ISymbol>();
Expand Down Expand Up @@ -1306,7 +1306,7 @@ private void CheckImplicitInterfaceImplementation(INamedTypeSymbol type) {
}

var implementationType = implementationMember.ContainingType;
if (!implementationType.Equals(type)) {
if (!implementationType.EQ(type)) {
if (!implementationType.AllInterfaces.Contains(baseInterface)) {
generator_.AddImplicitInterfaceImplementation(implementationMember, interfaceMember);
generator_.TryAddExtend(baseInterface, implementationType);
Expand Down Expand Up @@ -1372,7 +1372,7 @@ private string GetTypeOrNamespaceNewName(IEnumerable<ISymbol> allSymbols, ISymbo
}

private static bool CheckTypeNameExists(IEnumerable<ISymbol> all, ISymbol type, string newName) {
return all.Where(i => i.ContainingNamespace.Equals(type.ContainingNamespace)).Any(i => i.Name == newName);
return all.Where(i => i.ContainingNamespace.EQ(type.ContainingNamespace)).Any(i => i.Name == newName);
}

private void CheckNamespace() {
Expand Down Expand Up @@ -1599,12 +1599,12 @@ public bool IsMoreThanLocalVariables(ISymbol symbol) {
int index = 0;
switch (symbol.Kind) {
case SymbolKind.Method: {
index = methods.FindIndex(i => i.Equals(symbol));
index = methods.FindIndex(i => i.EQ(symbol));
break;
}
case SymbolKind.Property:
case SymbolKind.Event: {
index = methods.FindIndex(i => i.Kind == SymbolKind.Method && symbol.Equals(((IMethodSymbol)i).AssociatedSymbol)) + 1;
index = methods.FindIndex(i => i.Kind == SymbolKind.Method && symbol.EQ(((IMethodSymbol)i).AssociatedSymbol)) + 1;
break;
}
}
Expand Down
31 changes: 12 additions & 19 deletions CSharp.lua/LuaSyntaxNodeTransform.Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ internal bool AddGenericImport(LuaInvocationExpressionSyntax invocationExpressio
}

internal void ImportGenericTypeName(ref LuaExpressionSyntax luaExpression, ITypeSymbol symbol) {
if (!IsNoImportTypeName && !CurTypeSymbol.Equals(symbol) && !IsCurMethodTypeArgument(symbol)) {
if (!IsNoImportTypeName && !CurTypeSymbol.EQ(symbol) && !IsCurMethodTypeArgument(symbol)) {
var invocationExpression = (LuaInvocationExpressionSyntax)luaExpression;
string newName = GetGenericTypeImportName(invocationExpression, out var argumentTypeNames);
if (!IsLocalVarExistsInCurMethod(newName)) {
Expand Down Expand Up @@ -1094,8 +1094,7 @@ private void CheckValueTypeClone(ITypeSymbol typeSymbol, IdentifierNameSyntax no
}
}

var symbol = semanticModel_.GetSymbolInfo(argument.Parent.Parent).Symbol as IMethodSymbol;
if (symbol != null) {
if (semanticModel_.GetSymbolInfo(argument.Parent.Parent).Symbol is IMethodSymbol symbol) {
if (symbol.IsFromAssembly() && !symbol.ContainingType.IsCollectionType()) {
break;
}
Expand Down Expand Up @@ -1266,7 +1265,7 @@ private void CheckConversion(ExpressionSyntax node, ref LuaExpressionSyntax expr

private LuaExpressionSyntax GetOperatorMemberAccessExpression(IMethodSymbol methodSymbol) {
var methodName = GetMemberName(methodSymbol);
if (CurTypeSymbol.Equals(methodSymbol.ContainingType)) {
if (CurTypeSymbol.EQ(methodSymbol.ContainingType)) {
return methodName;
}

Expand Down Expand Up @@ -1392,7 +1391,7 @@ public SymbolAssignmentSearcher(LuaSyntaxGenerator generator, ISymbol symbol) {
public override void VisitAssignmentExpression(AssignmentExpressionSyntax node) {
var semanticModel = generator_.GetSemanticModel(node.SyntaxTree);
var symbol = semanticModel.GetSymbolInfo(node.Left).Symbol;
if (symbol_.Equals(symbol)) {
if (symbol_.EQ(symbol)) {
Found();
}

Expand All @@ -1411,7 +1410,7 @@ public override void VisitInvocationExpression(InvocationExpressionSyntax node)
foreach (var argument in node.ArgumentList.Arguments) {
if (argument.RefKindKeyword.IsOutOrRef()) {
var symbol = semanticModel.GetSymbolInfo(argument.Expression).Symbol;
if (symbol.Equals(symbol_)) {
if (symbol.EQ(symbol_)) {
Found();
}
}
Expand Down Expand Up @@ -1751,7 +1750,7 @@ public override void VisitInvocationExpression(InvocationExpressionSyntax node)

var methodSymbol = (IMethodSymbol)semanticModel.GetSymbolInfo(node).Symbol;
if (methodSymbol != null) {
if (methodSymbol.Equals(symbol_)) {
if (methodSymbol.EQ(symbol_)) {
Found();
}
}
Expand All @@ -1776,8 +1775,7 @@ private bool InliningInvocationExpression(SyntaxNode root, IMethodSymbol symbol,
BlockSyntax bodyNode;
ArrowExpressionClauseSyntax expressionBodyNode;
if (symbol.MethodKind == MethodKind.PropertyGet) {
var propertyDeclaration = symbol.AssociatedSymbol.GetDeclaringSyntaxNode() as PropertyDeclarationSyntax;
if (propertyDeclaration == null) {
if (!(symbol.AssociatedSymbol.GetDeclaringSyntaxNode() is PropertyDeclarationSyntax propertyDeclaration)) {
goto Fail;
}

Expand All @@ -1787,8 +1785,7 @@ private bool InliningInvocationExpression(SyntaxNode root, IMethodSymbol symbol,
expressionBodyNode = accessor.ExpressionBody;
parameterList = null;
} else {
var methodDeclaration = symbol.GetDeclaringSyntaxNode() as MethodDeclarationSyntax;
if (methodDeclaration == null) {
if (!(symbol.GetDeclaringSyntaxNode() is MethodDeclarationSyntax methodDeclaration)) {
goto Fail;
}

Expand Down Expand Up @@ -1945,13 +1942,11 @@ private LuaExpressionSyntax CompressionInliningBlock(SyntaxNode root, LuaBlockSt
}
}

var expressionStatement = block.Statements.Last() as LuaExpressionStatementSyntax;
if (expressionStatement == null) {
if (!(block.Statements.Last() is LuaExpressionStatementSyntax expressionStatement)) {
return null;
}

var assignment = expressionStatement.Expression as LuaAssignmentExpressionSyntax;
if (assignment == null) {
if (!(expressionStatement.Expression is LuaAssignmentExpressionSyntax assignment)) {
return null;
}

Expand Down Expand Up @@ -2038,8 +2033,7 @@ private bool IsWantInline(IPropertySymbol symbol) {
return false;
}

var propertyDeclaration = symbol.GetDeclaringSyntaxNode() as PropertyDeclarationSyntax;
if (propertyDeclaration == null || propertyDeclaration.AccessorList == null) {
if (!(symbol.GetDeclaringSyntaxNode() is PropertyDeclarationSyntax propertyDeclaration) || propertyDeclaration.AccessorList == null) {
return false;
}

Expand All @@ -2050,8 +2044,7 @@ private bool IsWantInline(IPropertySymbol symbol) {
return false;
}

var returnStatement = accessor.Body.Statements.First() as ReturnStatementSyntax;
if (returnStatement == null) {
if (!(accessor.Body.Statements.First() is ReturnStatementSyntax returnStatement)) {
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions CSharp.lua/LuaSyntaxNodeTransform.Object.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ private LuaTryAdapterExpressionSyntax VisitTryCatchesExpress(SyntaxList<CatchCla
if (catchNode.Declaration != null) {
var typeName = catchNode.Declaration.Type.Accept<LuaIdentifierNameSyntax>(this);
var typeSymbol = semanticModel_.GetTypeInfo(catchNode.Declaration.Type).Type;
if (!typeSymbol.Equals(generator_.SystemExceptionTypeSymbol)) {
if (!typeSymbol.EQ(generator_.SystemExceptionTypeSymbol)) {
var mathcTypeInvocation = new LuaInvocationExpressionSyntax(LuaIdentifierNameSyntax.Is, temp, typeName);
if (ifCondition != null) {
ifCondition = ifCondition.And(mathcTypeInvocation);
Expand Down Expand Up @@ -781,7 +781,7 @@ private BaseVisitType CheckBaseVisitType<T>(T symbol, Func<T, ISymbol> overridde
if (generator_.IsSealed(curTypeSymbol)) {
bool exists = curTypeSymbol.GetMembers().OfType<T>().Any(i => {
var overriddenSymbol = overriddenFunc(i);
return overriddenSymbol != null && overriddenSymbol.OriginalDefinition.Equals(symbol.OriginalDefinition);
return overriddenSymbol != null && overriddenSymbol.OriginalDefinition.EQ(symbol.OriginalDefinition);
});
return exists ? BaseVisitType.UseBase : BaseVisitType.UseThis;
} else {
Expand Down Expand Up @@ -1191,7 +1191,7 @@ public override LuaSyntaxNode VisitArrowExpressionClause(ArrowExpressionClauseSy
}

public override LuaSyntaxNode VisitLocalFunctionStatement(LocalFunctionStatementSyntax node) {
var result = BuildMethodDeclaration(node, default, node.ParameterList, node.TypeParameterList, node.Body, node.ExpressionBody, node.ReturnType);
var result = BuildMethodDeclaration(node, default, node.ParameterList, node.TypeParameterList, node.Body, node.ExpressionBody);
if (node.Modifiers.IsStatic() && IsStaticLocalMethodEnableAddToType(result.Symbol)) {
CurTypeDeclaration.TypeDeclaration.AddMethod(result.Name, result.Function, true, result.Document);
return LuaStatementSyntax.Empty;
Expand Down
15 changes: 7 additions & 8 deletions CSharp.lua/LuaSyntaxNodeTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public TypeDeclarationInfo(INamedTypeSymbol typeSymbol, LuaTypeDeclarationSyntax
}

public bool CheckTypeName(INamedTypeSymbol getNameTypeSymbol, out LuaIdentifierNameSyntax name) {
if (getNameTypeSymbol.Equals(TypeSymbol)) {
if (getNameTypeSymbol.EQ(TypeSymbol)) {
TypeDeclaration.IsClassUsed = true;
name = LuaIdentifierNameSyntax.Class;
return true;
Expand Down Expand Up @@ -624,8 +624,7 @@ private MethodDeclarationResult BuildMethodDeclaration(
ParameterListSyntax parameterList,
TypeParameterListSyntax typeParameterList,
BlockSyntax body,
ArrowExpressionClauseSyntax expressionBody,
TypeSyntax returnType) {
ArrowExpressionClauseSyntax expressionBody) {
IMethodSymbol symbol = (IMethodSymbol)semanticModel_.GetDeclaredSymbol(node);
var refOrOutParameters = new List<LuaExpressionSyntax>();
MethodInfo methodInfo = new MethodInfo(symbol, refOrOutParameters);
Expand Down Expand Up @@ -720,7 +719,7 @@ private bool IsCurTypeSerializable {

public override LuaSyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax node) {
if ((node.Body != null || node.ExpressionBody != null) && !node.HasCSharpLuaAttribute(LuaDocumentStatement.AttributeFlags.Ignore)) {
var result = BuildMethodDeclaration(node, node.AttributeLists, node.ParameterList, node.TypeParameterList, node.Body, node.ExpressionBody, node.ReturnType);
var result = BuildMethodDeclaration(node, node.AttributeLists, node.ParameterList, node.TypeParameterList, node.Body, node.ExpressionBody);
bool isMoreThanLocalVariables = IsMoreThanLocalVariables(result.Symbol);
CurType.AddMethod(result.Name, result.Function, result.IsPrivate, result.Document, isMoreThanLocalVariables, result.Symbol.IsInterfaceDefaultMethod());
if (IsCurTypeExportMetadataAll || result.Attributes.Count > 0 || result.IsMetadata) {
Expand Down Expand Up @@ -1278,7 +1277,7 @@ public LuaSyntaxNode Visit(LuaSyntaxNodeTransform transfor) {
return new LuaShortCommentStatement(commentContent);
}
case SyntaxKind.MultiLineCommentTrivia: {
string commentContent = content.Substring(kCommentCharCount, content.Length - kCommentCharCount - kCommentCharCount);
string commentContent = content[kCommentCharCount..^kCommentCharCount];
commentContent = commentContent.ReplaceNewline();
if (CheckInsertLuaCodeTemplate(commentContent, out var codeStatement)) {
return codeStatement;
Expand Down Expand Up @@ -2864,7 +2863,7 @@ private void CheckDelegateBind(IMethodSymbol symbol, CSharpSyntaxNode node, ref
const int kReturnParameterIndex = int.MaxValue;
if (symbol.IsGenericMethod) {
var originalDefinition = symbol.OriginalDefinition;
if (!originalDefinition.Equals(symbol)) {
if (!originalDefinition.EQ(symbol)) {
var targetMethodSymbol = GetDelegateTargetMethodSymbol(node);
var targetTypeParameters = new List<TypeParameterPlaceholder>();
foreach (var typeArgument in targetMethodSymbol.ContainingType.TypeArguments) {
Expand Down Expand Up @@ -4339,7 +4338,7 @@ private void ChecktIncrementExpression(ExpressionSyntax operand, ref LuaExpressi
var symbol = semanticModel_.GetTypeInfo(operand).Type;
if (!symbol.IsNumberType()) {
var op_Implicits = symbol.GetMembers("op_Implicit").OfType<IMethodSymbol>();
var methodSymbol = op_Implicits.FirstOrDefault(i => isAddOrAssignment ? i.ReturnType.IsIntegerType() : i.ReturnType.Equals(symbol));
var methodSymbol = op_Implicits.FirstOrDefault(i => isAddOrAssignment ? i.ReturnType.IsIntegerType() : i.ReturnType.EQ(symbol));
if (methodSymbol != null) {
expression = BuildConversionExpression(methodSymbol, expression);
}
Expand Down Expand Up @@ -4615,7 +4614,7 @@ private void CheckForeachCast(LuaIdentifierNameSyntax identifier, ForEachStateme
bool hasCast = false;
var elementType = !isAsync ? sourceType.GetIEnumerableElementType() : sourceType.GetIAsyncEnumerableElementType();
if (elementType != null) {
if (!elementType.Equals(targetType) && !elementType.Is(targetType)) {
if (!elementType.EQ(targetType) && !elementType.Is(targetType)) {
hasCast = true;
}
} else {
Expand Down
Loading

0 comments on commit c96f909

Please sign in to comment.