template.incremental.Tracking.tt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jastadd Show documentation
Show all versions of jastadd Show documentation
A metacompilation framework for Java using attribute grammars.
# 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.
ASTNode.incHookGetParent = [[
$if (IncrementalEnabled)
$if (IncrementalLevelParam)
state().addHandlerDepTo(getParent_handler);
$endif
$if (IncrementalLevelAttr)
state().addHandlerDepTo(getParent_handler);
$endif
$if (IncrementalLevelNode)
if (parent != null) {
state().addHandlerDepTo((($ASTNode) parent).handler);
}
$endif
$if (IncrementalLevelRegion)
$if (#isRegionRoot)
if (state().IN_COMPUTATION > 0 && parent != null) {
parent.handler().addListener(handler);
}
$endif
$endif
$endif
]]
ASTNode.incHookAddChild = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
int i = getNumChildNoTransform() - 1;
if (getChild_handler[i] == null) {
$if(IncrementalPropLimit)
getChild_handler[i] = $DDGNodeName.createAttrHandler(this, "getChild", Integer.valueOf(i), !node.mayHaveRewrite());
$else
getChild_handler[i] = $DDGNodeName.createAttrHandler(this, "getChild", Integer.valueOf(i));
$endif
}
state().addHandlerDepTo(getChild_handler[i]);
$if(LegacyRewrite)
if (state().IN_ATTR_STORE_EVAL && !node.mayHaveRewrite()) {
node.is$$Final(is$$Final());
}
$endif
$endif
$if(IncrementalLevelAttr)
state().addHandlerDepTo(getChild_handler);
$if(LegacyRewrite)
if (state().IN_ATTR_STORE_EVAL && !node.mayHaveRewrite()) {
node.is$$Final(is$$Final());
}
$endif
$endif
$if(IncrementalLevelNode)
if (node != null) {
state().addHandlerDepTo(node.handler);
$if(LegacyRewrite)
if (state().IN_ATTR_STORE_EVAL && !node.mayHaveRewrite()) {
node.is$$Final(is$$Final());
}
$endif
}
$endif
$if(IncrementalLevelRegion)
if (node != null && node.isRegionRoot()) {
state().addHandlerDepTo(node.handler());
$if(LegacyRewrite)
if (state().IN_ATTR_STORE_EVAL && !node.mayHaveRewrite()) {
node.is$$Final(is$$Final());
}
$endif
}
$endif
$endif
]]
ASTNode.incHookNumChildren = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
state().addHandlerDepTo(numChildren_handler);
$endif
$if(IncrementalLevelAttr)
state().addHandlerDepTo(numChildren_handler);
$endif
$endif
]]
ASTNode.incHookGetChild1 = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
this.state().enterRewriteEval(this.getChild_handler[i]);
$endif
$if(IncrementalLevelAttr)
this.state().enterRewriteEval(this.getChild_handler);
$endif
$endif
]]
ASTNode.incHookGetChild2 = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
this.state().exitRewriteEval(this.getChild_handler[i]);
$endif
$if(IncrementalLevelAttr)
this.state().exitRewriteEval(this.getChild_handler);
$endif
$endif
]]
ASTNode.incHookGetChild3 = [[
$if(IncrementalEnabled)
$endif
]]
ASTNode.incHookGetChild4 = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
if (this.getChild_handler[i] == null) {
$if(IncrementalPropLimit)
this.getChild_handler[i] = $DDGNodeName.createAttrHandler(this, "getChild", Integer.valueOf(i), !node.mayHaveRewrite());
$else
this.getChild_handler[i] = $DDGNodeName.createAttrHandler(this, "getChild", Integer.valueOf(i));
$endif
}
this.state().addHandlerDepTo(this.getChild_handler[i]);
$endif
$if(IncrementalLevelAttr)
this.state().addHandlerDepTo(this.getChild_handler);
$endif
$if(IncrementalLevelNode)
if (node != null) {
this.state().addHandlerDepTo(node.handler);
}
$endif
$endif
]]
ASTNode.incHookGetChild5 = [[
$if(IncrementalEnabled)
$if(IncrementalLevelNode)
this.state().enterRewriteEval(node.handler);
$endif
$if(IncrementalLevelRegion)
this.state().IN_COMPUTATION++;
$endif
$endif
]]
ASTNode.incHookGetChild6 = [[
$if(IncrementalEnabled)
$if(IncrementalLevelNode)
this.state().exitRewriteEval(oldNode.handler);
$endif
$if(IncrementalLevelRegion)
this.state().IN_COMPUTATION--;
$endif
$endif
]]
ASTNode.incHookGetChild7 = [[
$if(IncrementalEnabled)
//$ASTNode initial = this.init_children[i];
$endif
]]
ASTNode.incHookGetChild8 = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
oldNode.inc_flush_subtree(this.getChild_handler[i]);
//this.init_children[i] = initial;
$endif
$if(IncrementalLevelAttr)
oldNode.inc_flush_subtree(this.getChild_handler);
//this.init_children[i] = initial;
$endif
$if(IncrementalLevelNode)
oldNode.inc_flush_subtree(node.handler());
//this.init_children[i] = initial;
$endif
$if(IncrementalLevelRegion)
if (node.isRegionRoot()) {
oldNode.inc_flush_subtree(node.handler());
}
//this.init_children[i] = initial;
$endif
$endif
]]
ASTNode.incHookGetChild11 = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
if (this.getChild_handler[i] == null) {
$if(IncrementalPropLimit)
this.getChild_handler[i] = $DDGNodeName.createAttrHandler(this, "getChild", Integer.valueOf(i), !node.mayHaveRewrite());
$else
this.getChild_handler[i] = $DDGNodeName.createAttrHandler(this, "getChild", Integer.valueOf(i));
$endif
}
this.state().addHandlerDepTo(this.getChild_handler[i]);
$endif
$if(IncrementalLevelAttr)
this.state().addHandlerDepTo(this.getChild_handler);
$endif
$if(IncrementalLevelNode)
if (node != null) {
this.state().addHandlerDepTo(node.handler);
this.handler.addListener(node.handler);
}
$endif
$if(IncrementalLevelRegion)
if (node != null && node.isRegionRoot()) {
this.handler().addListener(node.handler());
node.handler().addListener(this.handler());
}
$endif
$endif
]]
ASTNode.incHookGetChild12 = [[
$if(IncrementalEnabled)
$if(IncrementalLevelRegion)
$if(#isRegionRoot)
if (state().IN_COMPUTATION > 0) {
node.handler().addListener(handler);
}
$endif
$endif
$endif
]]
ASTNode.incHookGetChildNT = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
if (getChild_handler[i] == null) {
$if(IncrementalPropLimit)
getChild_handler[i] = $DDGNodeName.createAttrHandler(this, "getChild", Integer.valueOf(i), !child.mayHaveRewrite());
$else
getChild_handler[i] = $DDGNodeName.createAttrHandler(this, "getChild", Integer.valueOf(i));
$endif
}
state().addHandlerDepTo(getChild_handler[i]);
$endif
$if(IncrementalLevelAttr)
state().addHandlerDepTo(getChild_handler);
$endif
$if(IncrementalLevelNode)
if (child != null) {
state().addHandlerDepTo(child.handler);
}
$endif
$if(IncrementalLevelRegion)
$if(#isRegionRoot)
if (state().IN_COMPUTATION > 0 && node != null) {
node.handler().addListener(handler);
}
$endif
$endif
$endif
]]
ASTNode.incHookGetChild = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
if (getChild_handler[i] == null) {
$if(IncrementalPropLimit)
getChild_handler[i] = $DDGNodeName.createAttrHandler(this, "getChild", Integer.valueOf(i), !child.mayHaveRewrite());
$else
getChild_handler[i] = $DDGNodeName.createAttrHandler(this, "getChild", Integer.valueOf(i));
$endif
}
state().addHandlerDepTo(getChild_handler[i]);
$endif
$if(IncrementalLevelAttr)
state().addHandlerDepTo(getChild_handler);
$endif
$if(IncrementalLevelNode)
if (child != null) {
state().addHandlerDepTo(child.handler);
}
$endif
$if(IncrementalLevelRegion)
$if(#isRegionRoot)
if (state().IN_COMPUTATION > 0 && node != null) {
node.handler().addListener(handler);
}
$endif
$endif
$endif
]]
ASTNode.incHookGetChildEnterEval = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
state().enterAttrStoreEval(getChild_handler[i]);
$endif
$if(IncrementalLevelRegion)
state().enterAttrStoreEval(handler());
$endif
$endif
]]
ASTNode.incHookGetChildExitEval = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
state().exitAttrStoreEval(getChild_handler[i]);
$endif
$if(IncrementalLevelRegion)
state().exitAttrStoreEval(handler());
$endif
$endif
]]
TokenComponent.incHookGetToken = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
state().addHandlerDepTo(get$(Id)_handler);
$endif
$if(IncrementalLevelAttr)
state().addHandlerDepTo(get$(Id)_handler);
$endif
$if(IncrementalLevelNode)
$if(!IsStringToken)
$if(!#isPrimitive)
if (token$(TypeInSignature)_$(Id) instanceof $ASTNode) {
state().addHandlerDepTo((($ASTNode) token$(TypeInSignature)_$(Id)).handler);
}
$endif
$endif
$endif
$if(IncrementalLevelRegion)
$if(!IsStringToken)
$if(!#isPrimitive)
if (token$(TypeInSignature)_$(Id) instanceof $ASTNode && token$(TypeInSignature)_$(Id).isRegionRoot()) {
(($ASTNode) token$(TypeInSignature)_$(Id)).handler().addListener(handler());
}
$endif
$endif
$endif
$endif
]]
AttrDecl.incHookAttrRead = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
$if(#isParameterized)
if (!#(signature)_handler.containsKey(_parameters)) {
#(signature)_handler.put(_parameters, new $DDGNodeName(this, "#(signature)", _parameters, $ASTNode.inc_EMPTY) {
@Override public void reactToDependencyChange() {
$include(AttrDecl.reactToDepChange)
}
});
}
state().addHandlerDepTo(($DDGNodeName)#(signature)_handler.get(_parameters));
$else
if (#(signature)_handler == null) {
#(signature)_handler = new $DDGNodeName(this, "#(signature)", null, $ASTNode.inc_EMPTY) {
@Override public void reactToDependencyChange() {
$include(AttrDecl.reactToDepChange)
}
};
}
state().addHandlerDepTo(#(signature)_handler);
$endif
$endif
$if(IncrementalLevelAttr)
if (#(signature)_handler == null) {
#(signature)_handler = new $DDGNodeName(this, "#(signature)", null, $ASTNode.inc_EMPTY) {
@Override public void reactToDependencyChange() {
$include(AttrDecl.reactToDepChange)
}
};
}
state().addHandlerDepTo(#(signature)_handler);
$endif
$if(IncrementalLevelNode)
$if(#getNTA)
$if(!#isParameterized)
if (#(signature)_computed) {
state().addHandlerDepTo(#(signature)_value.handler());
}
$else
if (#(signature)_values.containsKey(_parameters)) {
state().addHandlerDepTo((($ASTNode) #(signature)_values.get(_parameters)).handler());
}
$endif
$endif
$endif
$if(IncrementalLevelRegion)
$if(#getNTA)
$if(!#isParameterized)
if (#(signature)_computed && #(signature)_value.isRegionRoot()) {
state().addHandlerDepTo(#(signature)_value.handler());
}
$else
$ASTNode node$$Value = ($ASTNode) #(signature)_values.get(_parameters);
if (node$$Value != null && node$$Value.isRegionRoot()) {
state().addHandlerDepTo(node$$Value.handler());
}
$endif
$endif
$endif
$endif
]]
AttrDecl.incHookAttrCompStart = [[
$if(IncrementalEnabled)
$if(#isMemoized)
$if(IncrementalLevelParam)
//$DDGNodeName tmpHandler = $DDGNodeName.createAttrHandler(this, "", null);
//state().enterAttrStoreEval(tmpHandler);
$if(!#isParameterized)
state().enterAttrStoreEval(#(signature)_handler);
$else
state().enterAttrStoreEval(($DDGNodeName)#(signature)_handler.get(_parameters));
$endif
$endif
$if(IncrementalLevelAttr)
$DDGNodeName tmpHandler = new $DDGNodeName(this, "");
state().enterAttrStoreEval(tmpHandler);
$endif
$if(IncrementalLevelNode)
$if(#getNTA)
// Creating a dummy handler to collect dependencies
$DDGNodeName newHandler = new $DDGNodeName(this);
// Adding dependency to this region because it may be read during the computation
handler.addListener(newHandler);
state().enterAttrStoreEval(newHandler);
$else
$DDGNodeName tmpHandler = new $DDGNodeName(this);
state().enterAttrStoreEval(tmpHandler);
$endif
$endif
$if(IncrementalLevelRegion)
state().IN_COMPUTATION++;
$endif
$endif
$endif
]]
AttrDecl.incHookAttrCompStartCircular = [[
$if(IncrementalEnabled)
$if(#isMemoized)
$if(IncrementalLevelParam)
$if(!#isParameterized)
state().enterAttrStoreEval(#(signature)_handler);
$else
state().enterAttrStoreEval(($DDGNodeName)#(signature)_handler.get(_parameters));
$endif
$endif
$if(IncrementalLevelAttr)
state().enterAttrStoreEval(#(signature)_handler);
$endif
$if(IncrementalLevelNode)
$if(#getNTA)
// Creating a dummy handler to collect dependencies
$DDGNodeName newHandler = new $DDGNodeName(this);
// Adding dep. to this region because it may be read during the computation
handler.addListener(newHandler);
state().enterAttrStoreEval(newHandler);
$else
state().enterAttrStoreEval(handler);
$endif
$endif
$if(IncrementalLevelRegion)
state().IN_COMPUTATION++;
$endif
$endif
$endif
]]
AttrDecl.incHookAttrCompEnd = [[
$if(IncrementalEnabled)
$if(#isMemoized)
$if(IncrementalLevelParam)
//state().exitAttrStoreEval(tmpHandler);
$if(!#isParameterized)
state().exitAttrStoreEval(#(signature)_handler);
$else
state().exitAttrStoreEval(($DDGNodeName)#(signature)_handler.get(_parameters));
$endif
$endif
$if(IncrementalLevelAttr)
state().exitAttrStoreEval(tmpHandler);
$endif
$if(IncrementalLevelNode)
$if(#getNTA)
#(signature)_value.handler = newHandler;
#(signature)_value.handler.fNode = #(signature)_value;
state().exitAttrStoreEval(#(signature)_value.handler);
state().addHandlerDepTo(#(signature)_value.handler);
$else
state().exitAttrStoreEval(tmpHandler);
$endif
$endif
$if(IncrementalLevelRegion)
state().IN_COMPUTATION--;
handler().setComputed();
$if(#getNTA)
if (#(signature)_value != null && #(signature)_value.isRegionRoot()) {
$DDGNodeName nodeHandler = handler();
nodeHandler.addListener(#(signature)_value.handler());
#(signature)_value.handler().addListener(nodeHandler);
}
$endif
$endif
$endif
$endif
]]
AttrDecl.incHookAttrCompEndCircular = [[
$if(IncrementalEnabled)
$if(#isMemoized)
$if(IncrementalLevelParam)
$if(!#isParameterized)
state().exitAttrStoreEval(#(signature)_handler);
$else
state().exitAttrStoreEval(($DDGNodeName)#(signature)_handler.get(_parameters));
$endif
$endif
$if(IncrementalLevelAttr)
state().exitAttrStoreEval(#(signature)_handler);
$endif
$if(IncrementalLevelNode)
$if(#getNTA)
#(signature)_value.handler = newHandler;
#(signature)_value.handler.fNode = #(signature)_value;
state().exitAttrStoreEval(#(signature)_value.handler);
state().addHandlerDepTo(#(signature)_value.handler);
$else
state().exitAttrStoreEval(handler);
$endif
$endif
$if(IncrementalLevelRegion)
state().IN_COMPUTATION--;
$if(#getNTA)
if (#(signature)_value.isRegionRoot()) {
$DDGNodeName nodeHandler = handler();
nodeHandler.addListener(#(signature)_value.handler());
#(signature)_value.handler().addListener(nodeHandler);
}
$endif
$endif
$endif
$endif
]]
AttrDecl.incHookAttrCompBeforeStore = [[
$if(IncrementalEnabled)
$if(#isMemoized)
$if(IncrementalLevelParam)
$if(!#isParameterized)
//#(signature)_handler.transferDependenciesFrom(tmpHandler);
$else
//(($DDGNodeName)#(signature)_handler.get(_parameters)).transferDependenciesFrom(tmpHandler);
$endif
$endif
$if (IncrementalLevelAttr)
#(signature)_handler.transferDependenciesFrom(tmpHandler);
$endif
$if(IncrementalLevelNode)
$if(!#getNTA)
handler.transferDependenciesFrom(tmpHandler);
$endif
$endif
$endif
$endif
]]
AttrDecl.incHookAttrCompAfterStore = [[
$if(IncrementalEnabled)
$if(#isMemoized)
$if(IncrementalLevelParam)
tmpHandler.clearDependencies();
$endif
$if(IncrementalLevelAttr)
tmpHandler.clearDependencies();
$endif
$if(IncrementalLevelNode)
$if(!#getNTA)
tmpHandler.clearDependencies();
$endif
$endif
$endif
$endif
]]