template.incremental.ASTChange.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.incHookSetParent = [[
$if (IncrementalEnabled)
$if (IncrementalLevelParam)
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
getParent_handler.notifyDependencies();
}
$endif
$if (IncrementalLevelAttr)
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
getParent_handler.notifyDependencies();
}
$endif
$if (IncrementalLevelNode)
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
if (parent != null) {
parent.handler.flushRegion();
}
}
$endif
$if (IncrementalLevelRegion)
if (!state().IN_CONSTRUCTION && !(state().IN_COMPUTATION > 0)) {
if (parent != null) {
parent.handler().flushRegion();
}
}
$endif
/*
if (node != null) {
inc_changeState(node.inc_state);
} else {
inc_changeState(inc_GARBAGE);
}
*/
$endif
]]
ASTNode.incHookSetChild1 = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
if (children != null && i < children.length && children[i] != null) {
children[i].inc_notifyForRemove();
}
if (children == null) {
numChildren_handler.notifyDependencies();
} else if (i >= numChildren) {
numChildren_handler.notifyDependencies();
if (i > 0 && getChild_handler[i-1] != null) {
getChild_handler[i-1].notifyDependencies();
}
} else {
if (getChild_handler[i] != null) {
getChild_handler[i].notifyDependencies();
} else {
getChild_handler[i] = $DDGNodeName.createAttrHandler(this, "getChild", Integer.valueOf(i));
}
}
$endif
$if(IncrementalLevelAttr)
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
if (children != null && i < children.length && children[i] != null) {
children[i].inc_notifyForRemove();
}
getChild_handler.flushRegion();
$endif
$if(IncrementalLevelNode)
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
if (children != null && i < children.length && children[i] != null) {
children[i].inc_notifyForRemove();
}
if (children != null && i < children.length && children[i] != null) {
children[i].handler.notifyDependencies();
}
if (i == numChildren) {
handler.notifyDependencies();
}
$endif
$if(IncrementalLevelRegion)
if (!state().IN_CONSTRUCTION && !(state().IN_COMPUTATION > 0)) {
if (children != null && i < children.length && children[i] != null) {
children[i].inc_notifyForRemove();
}
$DDGNodeName h = (children != null && i < children.length && children[i] != null) ?
children[i].handler() : handler();
if (h != null) {
h.notifyDependencies();
}
if (i == numChildren && h != handler()) {
handler().notifyDependencies();
}
$endif
}
$endif
]]
ASTNode.incHookSetChild2 = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
getChild_handler = new $DDGNodeName[#initialChildArraySize];
$endif
$endif
]]
ASTNode.incHookSetChild3 = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
if (getChild_handler != null) {
$DDGNodeName h[] = new $DDGNodeName[i << 1];
System.arraycopy(getChild_handler, 0, h, 0, getChild_handler.length);
getChild_handler = h;
}
$endif
$endif
]]
ASTNode.incHookSetChild4 = [[
$if(IncrementalEnabled)
if (children[i] != null) {
children[i].inc_throwAway();
children[i].parent = null;
}
$endif
]]
ASTNode.incHookSetChild5 = [[
$if(IncrementalEnabled)
$endif
]]
ASTNode.incHookInsertChild1 = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
numChildren_handler.notifyDependencies();
if (children != null && i <= numChildren) {
for (int k = i; k < children.length; k++) {
if (getChild_handler[k] != null) {
getChild_handler[k].notifyDependencies();
}
}
}
$endif
$if(IncrementalLevelAttr)
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
numChildren_handler.notifyDependencies();
if (children != null && i <= numChildren) {
getChild_handler.flushRegion();
}
$endif
$if(IncrementalLevelNode)
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
for (int k = i; k < children.length; k++) {
$ASTNode child = children[i];
if (child != null) {
child.handler.flushRegion();
}
}
$endif
$if(IncrementalLevelRegion)
if (!state().IN_CONSTRUCTION && !(state().IN_COMPUTATION > 0)) {
for (int k = i; k < children.length; k++) {
$ASTNode child = children[i];
if (child != null) {
child.handler().flushRegion();
}
}
$endif
}
$endif
]]
ASTNode.incHookInsertChild2 = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
getChild_handler = new $DDGNodeName[#initialChildArraySize];
getChild_handler[i] = $DDGNodeName.createAttrHandler(this, "getChild", Integer.valueOf(i));
$endif
$endif
]]
ASTNode.incHookInsertChild3 = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
if (getChild_handler != null) {
$DDGNodeName h[] = new $DDGNodeName[getChild_handler.length + 1];
System.arraycopy(getChild_handler, 0, h, 0, getChild_handler.length);
getChild_handler = h;
}
$endif
$endif
]]
ASTNode.incHookRemoveChild1 = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
if (children[i] != null) {
children[i].inc_notifyForRemove();
}
numChildren_handler.notifyDependencies();
for (int k = i; k < children.length; k++) {
if (getChild_handler[k] != null) {
getChild_handler[k].notifyDependencies();
}
}
$endif
$if(IncrementalLevelAttr)
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
if (children[i] != null) {
children[i].inc_notifyForRemove();
}
getChild_handler.flushRegion();
$endif
$if(IncrementalLevelNode)
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
if (children[i] != null) {
children[i].inc_notifyForRemove();
}
handler.flushRegion();
for (int k = i; k < children.length; k++) {
$ASTNode child = children[i];
if (child != null) {
child.handler.flushRegion();
}
}
$endif
$if(IncrementalLevelRegion)
if (!state().IN_CONSTRUCTION && !(state().IN_COMPUTATION > 0)) {
if (children[i] != null) {
children[i].inc_notifyForRemove();
}
handler().flushRegion();
for (int k = i; k < children.length; k++) {
$ASTNode child = children[i];
if (child != null) {
child.handler().flushRegion();
}
}
$endif
}
$endif
]]
ASTNode.incHookRemoveChild2 = [[
$if(IncrementalEnabled)
// prevent recursive call during state handling where setParent calls removeChild
child.inc_throwAway();
$endif
]]
ASTNode.incHookRemoveChild3 = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
if (getChild_handler != null && this instanceof $List) {
getChild_handler[numChildren] = null;
}
$endif
$endif
]]
TokenComponent.incHookSetToken = [[
$if(IncrementalEnabled)
$if(IncrementalLevelParam)
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
$if(#isNTA)
if (get$(Id)_computed) {
get$(Id)_computed = false;
get$(Id)_handler.notifyDependencies();
}
$else
$if(IncrementalTrack)
get$(Id)_handler.trackChange();
$endif
get$(Id)_handler.notifyDependencies();
$endif
$endif
$if(IncrementalLevelAttr)
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
$if(#isNTA)
if (get$(Id)_computed) {
get$(Id)_computed = false;
get$(Id)_handler.notifyDependencies();
}
$else
$if(IncrementalTrack)
get$(Id)_handler.trackChange();
$endif
get$(Id)_handler.notifyDependencies();
$endif
$endif
$if(IncrementalLevelNode)
if (!state().IN_CONSTRUCTION && !state().IN_ATTR_STORE_EVAL) {
$if(#isNTA)
if (get$(Id)_computed) {
get$(Id)_computed = false;
handler.flushRegion();
}
$else
handler.flushRegion();
$if (!IsStringToken)
$if (!#isPrimitive)
if (token$(TypeInSignature)_$Id instanceof $ASTNode) {
token$(TypeInSignature)_$(Id).handler.flushRegion();
}
$endif
$endif
$endif
$endif
$if(IncrementalLevelRegion)
if (!state().IN_CONSTRUCTION && !(state().IN_COMPUTATION > 0)) {
$if(#isNTA)
if (get$(Id)_computed) {
get$(Id)_computed = false;
handler().flushRegion();
}
$else
handler().flushRegion();
$if (!IsStringToken)
$if (!#isPrimitive)
if (token$(TypeInSignature)_$Id instanceof $ASTNode && token$(TypeInSignature)_$(Id).isRegionRoot()) {
token$(TypeInSignature)_$(Id).handler().flushRegion();
}
$endif
$endif
$endif
$endif
}
$endif
]]