All Downloads are FREE. Search and download functionalities are using the official Maven repository.

template.trace.Tracer.tt Maven / Gradle / Ivy

There is a newer version: 2.3.6
Show newest version
# Copyright (c) 2013-2016, The JastAdd Team
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#     * Redistributions of source code must retain the above copyright notice,
#       this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the name of the Lund University nor the names of its
#       contributors may be used to endorse or promote products derived from
#       this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

# Code for the class ASTNodeState.Trace.
TraceClass [[
$if(TracingEnabled)
public static class Trace {
  /**
   * Trace events corresponding to attribute evaluation events.
   *
   * 

These events can be filtered statically using the flag --tracing to * JastAdd2. For example, the flag {@code --tracing=compute,cache} will only trace * compute events and cache events. The flag --tracing will enable all events. * *

To access the trace events you will need to register an event receiver. * This can be done using the method setReceiver($StateClass.Trace.Receiver). */ public enum Event { // Flag: --tracing=compute COMPUTE_BEGIN, COMPUTE_END, // Flag: --tracing=cache CACHE_WRITE, CACHE_READ, CACHE_ABORT, // Flag: --tracing=rewrite REWRITE_CASE1_START, REWRITE_CASE1_CHANGE, REWRITE_CASE1_RETURN, REWRITE_CASE2_RETURN, REWRITE_CASE3_RETURN, // Flag: --tracing=circular CIRCULAR_NTA_CASE1_START, CIRCULAR_NTA_CASE1_CHANGE, CIRCULAR_NTA_CASE1_RETURN, CIRCULAR_NTA_CASE2_START, CIRCULAR_NTA_CASE2_CHANGE, CIRCULAR_NTA_CASE2_RETURN, CIRCULAR_NTA_CASE3_RETURN, CIRCULAR_CASE1_START, CIRCULAR_CASE1_CHANGE, CIRCULAR_CASE1_RETURN, CIRCULAR_CASE2_START, CIRCULAR_CASE2_CHANGE, CIRCULAR_CASE2_RETURN, CIRCULAR_CASE3_RETURN, // Flag: --tracing=copy COPY_NODE, // Flag: --tracing=flush FLUSH_ATTR, FLUSH_REWRITE, FLUSH_REWRITE_INIT; } /** * Functional interface for a trace event receiver. * This can be implemented by applications that want to trace attribute evaluation. */ public interface Receiver { void accept($StateClass.Trace.Event event, $ASTNode node, String attribute, Object params, Object value); } public Trace(Receiver receiver) { this.receiver = receiver; } public Trace() { } // The default event receiver does nothing. private Receiver receiver = new Receiver() { public void accept($StateClass.Trace.Event event, $ASTNode node, String attribute, Object params, Object value) { } }; /** * Registers an input filter to use during tracing. * @param filter The input filter to register. */ public void setReceiver($StateClass.Trace.Receiver receiver) { this.receiver = receiver; } public Receiver getReceiver() { return receiver; } /** * Trace that an attribute instance started its computation. * @param value The value of the attribute instance. */ public void computeBegin($ASTNode node, String attr, Object params, Object value) { receiver.accept(Event.COMPUTE_BEGIN, node, attr, params, value); } /** * Trace that an attribute instance ended its computation. * @param value The value of the attribute instance. */ public void computeEnd($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.COMPUTE_END, node, attr, params, value); } /** * Trace that the cache of an attribute instances was read. * @param value The value of the attribute instance. */ public void cacheRead($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CACHE_READ, node, attr, params, value); } /** * Trace that an attribute instance was cached. * @param value The value of the attribute instance. */ public void cacheWrite($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CACHE_WRITE, node, attr, params, value); } /** * Trace that the caching of an attribute instance was aborted. * @param value The value of the attribute instance. */ public void cacheAbort($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CACHE_ABORT, node, attr, params, value); } /** * Trace that a rewrite evaluation entered case 1. * @param value The value of the rewrite. */ public void enterRewriteCase1($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.REWRITE_CASE1_START, node, attr, params, value); } /** * Trace that a rewrite in evaluation case 1 changed value. * @param value The value of the rewrite before and after. */ public void rewriteChange($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.REWRITE_CASE1_CHANGE, node, attr, params, value); } /** * Trace that a rewrite returned from evaluation case 1. * @param value The value of the rewrite. */ public void exitRewriteCase1($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.REWRITE_CASE1_RETURN, node, attr, params, value); } /** * Trace that a rewrite returned from evaluation case 2. * @param value The value of the rewrite. */ public void exitRewriteCase2($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.REWRITE_CASE2_RETURN, node, attr, params, value); } /** * Trace that a rewrite returned from evaluation case 3. * @param value The value of the rewrite. */ public void exitRewriteCase3($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.REWRITE_CASE3_RETURN, node, attr, params, value); } /** * Trace that a circular attribute instance entered evaluation case 1. * @param value The value of the circular attribute instance. */ public void enterCircularCase1($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CIRCULAR_CASE1_START, node, attr, params, value); } /** * Trace that a circular attribute instance in evaluation case 1 changed value. * @param value The value of the circular attribute instance, before and after. */ public void circularCase1Change($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CIRCULAR_CASE1_CHANGE, node, attr, params, value); } /** * Trace that a circular attribute instance returned from evaluation case 1. * @param value The value of the circular attribute instance. */ public void exitCircularCase1($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CIRCULAR_CASE1_RETURN, node, attr, params, value); } /** * Trace that a circular attribute instance entered evaluation case 2. * @param value The value of the circular attribute instance. */ public void enterCircularCase2($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CIRCULAR_CASE2_START, node, attr, params, value); } /** * Trace that a circular attribute instance in evaluation case 2 changed value. * @param value The value of the circular attribute instance, before and after. */ public void circularCase2Change($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CIRCULAR_CASE2_CHANGE, node, attr, params, value); } /** * Trace that a circular attribute instance returned from evaluation case 2. * @param value The value of the circular attribute instance. */ public void exitCircularCase2($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CIRCULAR_CASE2_RETURN, node, attr, params, value); } /** * Trace that a circular attribute instance returned from evaluation case 2. * @param value The value of the circular attribute instance. */ public void exitCircularCase3($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CIRCULAR_CASE3_RETURN, node, attr, params, value); } /** * Trace that a circular NTA entered evaluation case 1. * @param value The value of the circular NTA. */ public void enterCircularNTACase1($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CIRCULAR_NTA_CASE1_START, node, attr, params, value); } /** * Trace that a circular NTA in evaluation case 1 changed value. * @param value The value of the circular NTA, before and after. */ public void circularNTACase1Change($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CIRCULAR_NTA_CASE1_CHANGE, node, attr, params, value); } /** * Trace that a circular NTA returned from evaluation case 1. * @param value The value of the circular NTA. */ public void exitCircularNTACase1($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CIRCULAR_NTA_CASE1_RETURN, node, attr, params, value); } /** * Trace that a circular NTA entered evaluation case 2. * @param value The value of the circular NTA. */ public void enterCircularNTACase2($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CIRCULAR_NTA_CASE2_START, node, attr, params, value); } /** * Trace that a circular NTA in evaluation case 2 changed value. * @param value The value of the circular NTA, before and after. */ public void circularNTACase2Change($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CIRCULAR_NTA_CASE2_CHANGE, node, attr, params, value); } /** * Trace that a circular NTA returned from evaluation case 2. * @param value The value of the circular NTA. */ public void exitCircularNTACase2($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CIRCULAR_NTA_CASE2_RETURN, node, attr, params, value); } /** * Trace that a circular NTA returned from evaluation case 2. * @param value The value of the circular NTA. */ public void exitCircularNTACase3($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.CIRCULAR_NTA_CASE3_RETURN, node, attr, params, value); } /** * Trace that an AST node was copied. * @param node The copied node. * @param value The value of the node. */ public void copyNode($ASTNode node, Object value) { receiver.accept($StateClass.Trace.Event.COPY_NODE, node, "ASTNode.copy", "", value); } /** * Trace that an attribute was flushed. * @param value The value of the attribute. */ public void flushAttr($ASTNode node, String attr, Object params, Object value) { receiver.accept($StateClass.Trace.Event.FLUSH_ATTR, node, attr, params, value); } } $endif ]]





© 2015 - 2024 Weber Informatics LLC | Privacy Policy