diff --git a/src/java/org/jastadd/Configuration.java b/src/java/org/jastadd/Configuration.java index 053492bc45faecec27cc80697f532ee245b7639c..e2e4147d735fb88fc129e0479fbfe466d0ea2031 100644 --- a/src/java/org/jastadd/Configuration.java +++ b/src/java/org/jastadd/Configuration.java @@ -249,6 +249,7 @@ public class Configuration { .addAcceptedValue("circularNTA", "trace circular attribute evaluation") .addAcceptedValue("copy", "trace node copy operations") .addAcceptedValue("flush", "trace flush operations") + .addAcceptedValue("coll", "trace collection attribute contributions") .additionalDescription("All events are collected by default.\n" + "Listen to events by calling ASTState.Trace.setReceiver()"); @@ -534,6 +535,7 @@ public class Configuration { tt.bind("TraceCircular", traceCircular()); tt.bind("TraceCopy", traceCopy()); tt.bind("TraceFlush", traceFlush()); + tt.bind("TraceColl", traceColl()); // Set template variables to accommodate deprecated options // (the deprecated options may alter the value of the template variable). @@ -822,6 +824,14 @@ public class Configuration { return traceAll() || tracingOption.hasValue("flush"); } +/** + * @return {@code true} if collection attributes should be traced + */ + public boolean traceColl() { + return traceAll() || tracingOption.hasValue("coll"); + } + + /** * @return ASTNode type name */ diff --git a/src/template/ast/Collections.tt b/src/template/ast/Collections.tt index e8e969ced57328451bfaa7dd2de81bae7c368357..dda5d29c0cb19d245d93f8c8c7b5064edd4fcfcb 100644 --- a/src/template/ast/Collections.tt +++ b/src/template/ast/Collections.tt @@ -234,6 +234,7 @@ $endif ]] CollEq.contributeStatement [[ +$include(CollEq.traceContributionBegin) $if(#hasCondition) if (#getCondition) { $include(CollEq.addValueToCollection) @@ -241,6 +242,7 @@ $if(#hasCondition) $else $include(CollEq.addValueToCollection) $endif +$include(CollEq.traceContributionEnd) ]] CollEq.addValueToCollection [[ diff --git a/src/template/trace/TraceHooks.tt b/src/template/trace/TraceHooks.tt index 88f2478ec04edfd57adbb351196c72414322d748..c47186137c87ad00867a2ae3962558a6b13db809 100644 --- a/src/template/trace/TraceHooks.tt +++ b/src/template/trace/TraceHooks.tt @@ -322,3 +322,15 @@ state().trace().flushAttr(this, "#hostClassName.#signatureJavaStyle", "", #(sign $endif $endif ]] + +CollEq.traceContributionBegin [[ +$if (TraceColl) +state().trace.contributionBegin(this, "#hostClassName.#signatureJavaStyle", "", ""); +$endif +]] + +CollEq.traceContributionEnd [[ +$if (TraceColl) +state().trace.contributionEnd(this, "#hostClassName.#signatureJavaStyle", "", ""); +$endif +]] diff --git a/src/template/trace/Tracer.tt b/src/template/trace/Tracer.tt index 0d19cde6937335562f2b73bf8474a4fd7ab82695..879f4f1c3d738315245d59d462f357565cce9661 100644 --- a/src/template/trace/Tracer.tt +++ b/src/template/trace/Tracer.tt @@ -80,6 +80,10 @@ public static class Trace { FLUSH_REWRITE, FLUSH_REWRITE_INIT, INC_FLUSH_ATTR; + + // Flag: --tracing=coll + CONTRIBUTION_BEGIN, + CONTRIBUTION_END, } /** @@ -332,6 +336,20 @@ public static class Trace { public void flushIncAttr($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.INC_FLUSH_ATTR, node, attr, params, value); } + + /** + * Trace that a contribution to a collection attribute begun. + */ + public void contributionBegin($ASTNode node, String attr) { + receiver.accept($StateClass.Trace.Event.CONTRIBUTION_BEGIN, node, attr, "", value); + } + + /** + * Trace that a contribution to a collection attribute ended. + */ + public void contributionEnd($ASTNode node, String attr) { + receiver.accept($StateClass.Trace.Event.CONTRIBUTION_END, node, attr, "", value); + } } $endif ]]