-
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
Draft
mmsmits
wants to merge
12
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.
Draft
Changes from all commits
Commits
Show all changes
12 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 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,139 @@ | ||
/* | ||
* 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://github.com/FirelyTeam/firely-net-sdk/master/LICENSE | ||
*/ | ||
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; | ||
if (expr is IdentifierExpression ie) | ||
return; | ||
|
||
if (expr is ConstantExpression ce) | ||
{ | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},constant"); | ||
exprName = "constant"; | ||
} | ||
else if (expr is ChildExpression child) | ||
{ | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},{child.ChildName}"); | ||
exprName = child.ChildName; | ||
} | ||
else if (expr is IndexerExpression indexer) | ||
{ | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},[]"); | ||
exprName = "[]"; | ||
} | ||
else if (expr is UnaryExpression ue) | ||
{ | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},{ue.Op}"); | ||
exprName = ue.Op; | ||
} | ||
else if (expr is BinaryExpression be) | ||
{ | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},{be.Op}"); | ||
exprName = be.Op; | ||
} | ||
else if (expr is FunctionCallExpression fe) | ||
{ | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},{fe.FunctionName}"); | ||
exprName = fe.FunctionName; | ||
} | ||
else if (expr is NewNodeListInitExpression) | ||
{ | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},{{}} (empty)"); | ||
exprName = "{}"; | ||
} | ||
else if (expr is AxisExpression ae) | ||
{ | ||
if (ae.AxisName == "that") | ||
return; | ||
Trace.WriteLine($"Evaluated: {ae.AxisName} results: {result.Count()}"); | ||
exprName = "$" + ae.AxisName; | ||
} | ||
else if (expr is VariableRefExpression ve) | ||
{ | ||
Trace.WriteLine($"{expr.Location.LineNumber},{expr.Location.LinePosition},%{ve.Name}"); | ||
exprName = "%" + ve.Name; | ||
} | ||
else | ||
{ | ||
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
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,27 @@ | ||
/* | ||
* 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://github.com/FirelyTeam/firely-net-sdk/master/LICENSE | ||
*/ | ||
using Hl7.Fhir.ElementModel; | ||
using Hl7.FhirPath.Expressions; | ||
using System.Collections.Generic; | ||
|
||
namespace Hl7.FhirPath | ||
{ | ||
/// <summary> | ||
/// An interface for tracing FHIRPath expression results during evaluation. | ||
/// </summary> | ||
public interface IDebugTracer | ||
{ | ||
void TraceCall(Expression expr, | ||
IEnumerable<ITypedElement> focus, | ||
IEnumerable<ITypedElement> thisValue, | ||
ITypedElement index, | ||
IEnumerable<ITypedElement> totalValue, | ||
IEnumerable<ITypedElement> result, | ||
IEnumerable<KeyValuePair<string, IEnumerable<ITypedElement>>> variables); | ||
} | ||
} |
Oops, something went wrong.
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.