-
Notifications
You must be signed in to change notification settings - Fork 352
Introduce a fhirpath debug tracer #3210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
d24d890
Functions and child properties the name is an identifier, not a const…
brianpos 269c6e3
ChildExpression name is an identifier (derived from constant)
brianpos 4d45c55
Initial draft of injecting a debug tracer.
brianpos 21539a4
Merge branch 'develop' into feature/BP-fhirpath-debugger
mmsmits b05954f
Update src/Hl7.Fhir.Base/FhirPath/DebugTracer.cs
brianpos cf9458b
Complete the external surface for how to "inject" the tracing delegat…
brianpos 8cf189b
Include the position information for the standard extension/valueset …
brianpos bea44d0
Use an interface that has the function rather than a delegate.
brianpos ba521f3
rename debugtracer file
brianpos c0530a4
Include a unit test for the debug tracer
brianpos a84bc97
Tweak some other fhirpath unit tests to use the diagnostics tracer to…
brianpos bdfc37f
Merge remote-tracking branch 'hl7/develop' into feature/BP-fhirpath-d…
brianpos 7dd77e9
Change to a few overload to the function rather than adding an option…
brianpos e5754af
Update the unit test with assertions that match the test data
brianpos 28ecc36
Capture the focus used in the invokee to report to the debug tracer
brianpos 07c71d1
Minor tweaks to cleanup co-pilots review
brianpos 29f0eeb
Merge branch 'develop' into feature/BP-fhirpath-debugger
Kasdejong 81435f4
refactor if else into switches
brianpos 0b8aa99
Merge branch 'develop' into feature/BP-fhirpath-debugger
mmsmits 0ec42ca
Introduce a closure Id (tracked based on closures created within an e…
brianpos 7a18bd7
Partial commit issue - resolve compilation issue
brianpos 9bc7009
Unit test updated
brianpos 9a3744e
Since the tests process multiple expressions, dump the specific expre…
brianpos 1d2c6fc
Stash the focus into the context, and restore it after processing the…
brianpos 4b9e4c8
Additional unit testing
brianpos 31d12ea
Include assertions into the debug trace tests too.
brianpos 3489cfc
And remove the out parameter
brianpos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* | ||
* Copyright (c) 2015, Firely (info@fire.ly) and contributors | ||
* See the file CONTRIBUTORS for details. | ||
* | ||
* This file is licensed under the BSD 3-Clause license | ||
* available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE | ||
*/ | ||
|
||
#nullable enable | ||
|
||
using Hl7.Fhir.ElementModel; | ||
using Hl7.FhirPath.Expressions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
|
||
namespace Hl7.FhirPath | ||
{ | ||
|
||
public class DiagnosticsDebugTracer : IDebugTracer | ||
{ | ||
public void TraceCall( | ||
Expression expr, | ||
int contextId, | ||
IEnumerable<ITypedElement>? focus, | ||
IEnumerable<ITypedElement>? thisValue, | ||
ITypedElement? index, | ||
IEnumerable<ITypedElement> totalValue, | ||
IEnumerable<ITypedElement> result, | ||
IEnumerable<KeyValuePair<string, IEnumerable<ITypedElement>>> variables) | ||
{ | ||
DiagnosticsDebugTracer.DebugTraceCall(expr, contextId, focus, thisValue, index, totalValue, result, variables); | ||
} | ||
|
||
public static void DebugTraceCall( | ||
Expression expr, | ||
int contextId, | ||
IEnumerable<ITypedElement>? focus, | ||
IEnumerable<ITypedElement>? thisValue, | ||
ITypedElement? index, | ||
IEnumerable<ITypedElement> totalValue, | ||
IEnumerable<ITypedElement> result, | ||
IEnumerable<KeyValuePair<string, IEnumerable<ITypedElement>>> variables) | ||
{ | ||
string exprName; | ||
|
||
switch (expr) | ||
{ | ||
case IdentifierExpression _: | ||
return; | ||
|
||
case ConstantExpression ce: | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},constant (ctx.id: {contextId})"); | ||
exprName = "constant"; | ||
break; | ||
|
||
case ChildExpression child: | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},{child.ChildName} (ctx.id: {contextId})"); | ||
exprName = child.ChildName; | ||
break; | ||
|
||
case IndexerExpression _: | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},[] (ctx.id: {contextId})"); | ||
exprName = "[]"; | ||
break; | ||
|
||
case UnaryExpression ue: | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},{ue.Op} (ctx.id: {contextId})"); | ||
exprName = ue.Op; | ||
break; | ||
|
||
case BinaryExpression be: | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},{be.Op} (ctx.id: {contextId})"); | ||
exprName = be.Op; | ||
break; | ||
|
||
case FunctionCallExpression fe: | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},{fe.FunctionName} (ctx.id: {contextId})"); | ||
exprName = fe.FunctionName; | ||
break; | ||
|
||
case NewNodeListInitExpression _: | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},{{}} (empty) (ctx.id: {contextId})"); | ||
exprName = "{}"; | ||
break; | ||
|
||
case AxisExpression ae: | ||
if (ae.AxisName == "that") | ||
return; | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},${ae.AxisName} (ctx.id: {contextId})"); | ||
exprName = "$" + ae.AxisName; | ||
break; | ||
|
||
case VariableRefExpression ve: | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},%{ve.Name} (ctx.id: {contextId})"); | ||
exprName = "%" + ve.Name; | ||
break; | ||
|
||
default: | ||
exprName = expr.GetType().Name; | ||
#if DEBUG | ||
Debugger.Break(); | ||
#endif | ||
throw new Exception($"Unknown expression type: {expr.GetType().Name} (ctx.id: {contextId})"); | ||
// Trace.WriteLine($"Evaluated: {expr} results: {result.Count()}"); | ||
} | ||
|
||
if (result != null) | ||
{ | ||
foreach (var item in result) | ||
{ | ||
DebugTraceValue($"{exprName} »", item); | ||
} | ||
} | ||
|
||
if (focus != null) | ||
{ | ||
foreach (var item in focus) | ||
{ | ||
DebugTraceValue($"$focus", item); | ||
} | ||
} | ||
|
||
if (index != null) | ||
{ | ||
DebugTraceValue("$index", index); | ||
} | ||
|
||
if (thisValue != null) | ||
{ | ||
foreach (var item in thisValue) | ||
{ | ||
DebugTraceValue("$this", item); | ||
} | ||
} | ||
|
||
if (totalValue != null) | ||
{ | ||
foreach (var item in totalValue) | ||
{ | ||
DebugTraceValue($"{exprName} »", item); | ||
} | ||
} | ||
} | ||
|
||
private static void DebugTraceValue(string exprName, ITypedElement? item) | ||
{ | ||
if (item == null) | ||
return; // possible with a null focus to kick things off | ||
if (item.Location == "@primitivevalue@" || item.Location == "@QuantityAsPrimitiveValue@") | ||
Trace.WriteLine($" {exprName}:\t{item.Value}\t({item.InstanceType})"); | ||
else | ||
Trace.WriteLine($" {exprName}:\t{item.Value}\t({item.InstanceType})\t{item.Location}"); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.