-
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
Open
mmsmits
wants to merge
18
commits into
develop
Choose a base branch
from
feature/BP-fhirpath-debugger
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 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 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,144 @@ | ||
/* | ||
* 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, | ||
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"); | ||
exprName = "constant"; | ||
break; | ||
|
||
case ChildExpression child: | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},{child.ChildName}"); | ||
exprName = child.ChildName; | ||
break; | ||
|
||
case IndexerExpression _: | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},[]"); | ||
exprName = "[]"; | ||
break; | ||
|
||
case UnaryExpression ue: | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},{ue.Op}"); | ||
exprName = ue.Op; | ||
break; | ||
|
||
case BinaryExpression be: | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},{be.Op}"); | ||
exprName = be.Op; | ||
break; | ||
|
||
case FunctionCallExpression fe: | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},{fe.FunctionName}"); | ||
exprName = fe.FunctionName; | ||
break; | ||
|
||
case NewNodeListInitExpression _: | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},{{}} (empty)"); | ||
exprName = "{}"; | ||
break; | ||
|
||
case AxisExpression ae: | ||
if (ae.AxisName == "that") | ||
return; | ||
Trace.WriteLine($"Evaluated: {ae.AxisName} results: {result.Count()}"); | ||
exprName = "$" + ae.AxisName; | ||
break; | ||
|
||
case VariableRefExpression ve: | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},%{ve.Name}"); | ||
exprName = "%" + ve.Name; | ||
break; | ||
|
||
default: | ||
exprName = expr.GetType().Name; | ||
#if DEBUG | ||
Debugger.Break(); | ||
#endif | ||
throw new Exception($"Unknown expression type: {expr.GetType().Name}"); | ||
// Trace.WriteLine($"Evaluated: {expr} results: {result.Count()}"); | ||
} | ||
|
||
if (focus != null) | ||
{ | ||
foreach (var item in focus) | ||
{ | ||
DebugTraceValue($"$focus", item); | ||
} | ||
} | ||
|
||
if (thisValue != null) | ||
{ | ||
foreach (var item in thisValue) | ||
{ | ||
DebugTraceValue("$this", item); | ||
} | ||
} | ||
|
||
if (index != null) | ||
{ | ||
DebugTraceValue("$index", index); | ||
} | ||
|
||
if (totalValue != null) | ||
{ | ||
foreach (var item in totalValue) | ||
{ | ||
DebugTraceValue($"{exprName} »", item); | ||
} | ||
} | ||
|
||
if (result != null) | ||
{ | ||
foreach (var item in result) | ||
{ | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We aim to have nullability annotations for any new classes. If those could be added, that would be great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added nullability.