From 474ca36ee1c463c495c9dace94d90dd4ac52d8c6 Mon Sep 17 00:00:00 2001 From: nosami Date: Mon, 24 Oct 2022 12:11:56 +0100 Subject: Generic and type resolver fixes --- .../Mono.Debugging.Client/DebuggerSession.cs | 6 ++-- .../LambdaBodyOutputVisitor.cs | 2 +- .../NRefactoryExpressionEvaluatorVisitor.cs | 41 ++++++---------------- .../NRefactoryExpressionResolverVisitor.cs | 21 +++++++---- 4 files changed, 29 insertions(+), 41 deletions(-) diff --git a/Mono.Debugging/Mono.Debugging.Client/DebuggerSession.cs b/Mono.Debugging/Mono.Debugging.Client/DebuggerSession.cs index 64a1f58..bcc2253 100644 --- a/Mono.Debugging/Mono.Debugging.Client/DebuggerSession.cs +++ b/Mono.Debugging/Mono.Debugging.Client/DebuggerSession.cs @@ -1009,8 +1009,8 @@ namespace Mono.Debugging.Client public virtual string ResolveExpression (string expression, SourceLocation location) { var key = expression + " " + location; - - if (!resolvedExpressionCache.TryGetValue (key, out var resolved)) { + string resolved = null; + //if (!resolvedExpressionCache.TryGetValue (key, out var resolved)) { try { resolved = OnResolveExpression (expression, location); } catch (Exception ex) { @@ -1018,7 +1018,7 @@ namespace Mono.Debugging.Client OnDebuggerOutput (true, "Error while resolving expression: " + ex.Message); } resolvedExpressionCache [key] = resolved; - } + //} return resolved ?? expression; } diff --git a/Mono.Debugging/Mono.Debugging.Evaluation/LambdaBodyOutputVisitor.cs b/Mono.Debugging/Mono.Debugging.Evaluation/LambdaBodyOutputVisitor.cs index 527416c..8c27de3 100644 --- a/Mono.Debugging/Mono.Debugging.Evaluation/LambdaBodyOutputVisitor.cs +++ b/Mono.Debugging/Mono.Debugging.Evaluation/LambdaBodyOutputVisitor.cs @@ -211,7 +211,7 @@ namespace Mono.Debugging.Evaluation { var invocationTarget = node.Expression; if (!(invocationTarget is IdentifierNameSyntax method)) { - base.VisitInvocationExpression (node); + Visit(invocationTarget); return; } diff --git a/Mono.Debugging/Mono.Debugging.Evaluation/NRefactoryExpressionEvaluatorVisitor.cs b/Mono.Debugging/Mono.Debugging.Evaluation/NRefactoryExpressionEvaluatorVisitor.cs index e0387b1..ef69199 100644 --- a/Mono.Debugging/Mono.Debugging.Evaluation/NRefactoryExpressionEvaluatorVisitor.cs +++ b/Mono.Debugging/Mono.Debugging.Evaluation/NRefactoryExpressionEvaluatorVisitor.cs @@ -1021,7 +1021,7 @@ namespace Mono.Debugging.Evaluation public override ValueReference VisitSimpleLambdaExpression (SimpleLambdaExpressionSyntax node) { - if (node.AsyncKeyword != null) + if (node.AsyncKeyword != default) throw NotSupported (); var parent = node.Parent; @@ -1301,47 +1301,22 @@ namespace Mono.Debugging.Evaluation string typeName = node.Identifier.ValueText; - typeName = MakeGenericTypeName (node, typeName); + typeName = MakeGenericTypeName(node, typeName);// $"{typeName}`{node.TypeArgumentList.Arguments.Count}"; + var type1 = ctx.Adapter.GetType (ctx, typeName, typeArgs); return new TypeValueReference (ctx, type1); - - //node. - //object[] typeArgs; - // if (node.Arity > 0) { - // var args = new List (); - - // foreach (var arg in node.TypeArgumentList.Arguments) { - // var type = Visit(arg); - // args.Add (type.Type); - // } - - // typeArgs = args.ToArray (); - //} else { - // typeArgs = null; - // } - ////var type = Visit(node.Type) as TypeValueReference; - ////var args = new List(); - - ////foreach (var arg in node.ArgumentList.Arguments) - ////{ - //// var val = Visit(arg); - //// args.Add(val != null ? val.Value : null); - ////} - //var val = ctx.Adapter.CreateValue( ) - //return LiteralValueReference.CreateTargetObjectLiteral(ctx, expression, ctx.Adapter.CreateValue(ctx, type.Type, args.ToArray())); - } - private static string MakeGenericTypeName (GenericNameSyntax node, string typeName) - { + static string MakeGenericTypeName(GenericNameSyntax node, string typeName) + { if (node.Parent is QualifiedNameSyntax qns && qns.Left is IdentifierNameSyntax ins) return $"{ins.Identifier.Value}.{typeName}`{node.TypeArgumentList.Arguments.Count}"; if (node.Parent is QualifiedNameSyntax qns2 && qns2.Left is QualifiedNameSyntax left) return $"{left}.{typeName}`{node.TypeArgumentList.Arguments.Count}"; return typeName; - } + } public override ValueReference VisitQualifiedName(QualifiedNameSyntax node) { @@ -1358,6 +1333,10 @@ namespace Mono.Debugging.Evaluation { return LiteralValueReference.CreateObjectLiteral(ctx, expression, syntax.Token.Value); } + //if (node is RangeExpressionSyntax res) + //{ + + // } throw NotSupported(); } #endregion diff --git a/Mono.Debugging/Mono.Debugging.Evaluation/NRefactoryExpressionResolverVisitor.cs b/Mono.Debugging/Mono.Debugging.Evaluation/NRefactoryExpressionResolverVisitor.cs index db83347..88868e5 100644 --- a/Mono.Debugging/Mono.Debugging.Evaluation/NRefactoryExpressionResolverVisitor.cs +++ b/Mono.Debugging/Mono.Debugging.Evaluation/NRefactoryExpressionResolverVisitor.cs @@ -111,8 +111,16 @@ namespace Mono.Debugging.Evaluation } parentType = type + GenerateGenericArgs (genericArgs); - var replacement = new Replacement { Offset = offset, Length = length, NewText = type }; - replacements.Add (replacement); + + if (type != name) { + var lengthDelta = type.Length - name.Length; + var start = offset - lengthDelta; + if (start >= 0 && expression.Substring(offset - lengthDelta, type.Length) == type) + return; + + var replacement = new Replacement { Offset = offset, Length = length, NewText = type }; + replacements.Add(replacement); + } } } @@ -126,9 +134,10 @@ namespace Mono.Debugging.Evaluation public override void VisitIdentifierName (IdentifierNameSyntax node) { - base.VisitIdentifierName (node); - int length = node.Span.Length; - int offset = node.Span.Start; + //base.VisitIdentifierName (node); + var loc = node.Identifier.GetLocation(); + int length = loc.SourceSpan.Length; + int offset = loc.SourceSpan.Start; ReplaceType (node.Identifier.ValueText, node.Arity, offset, length); } @@ -149,7 +158,7 @@ namespace Mono.Debugging.Evaluation int length = loc.SourceSpan.Length; int offset = loc.SourceSpan.Start; - ReplaceType(node.Identifier.Text, node.TypeArgumentList.Arguments.Count, offset, length); + ReplaceType(node.Identifier.ValueText, node.TypeArgumentList.Arguments.Count, offset, length); } } } \ No newline at end of file -- cgit v1.2.3