template.ast.Circular.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.
AttrDecl.cycleDeclaration [[
$if(!#isParameterized)
/** @apilevel internal */
protected $StateClass.Cycle #(signature)_cycle = null;
$endif
]]
AttrDecl.circularEquation:unparameterized [[
#annotations
$include(AttrDecl.generatedAnnotations)
public #getType #name() {
$include(AttrDecl.cacheCheck)
$StateClass state = state();
if (!#(signature)_initialized) {
$if(#isCollection)
$ASTNode _node = this;
while (_node != null && !(_node instanceof #rootType)) {
_node = _node.getParent();
}
$include(CollDecl.collDebugCheck)
#rootType root = (#rootType) _node;
if (root.collecting_contributors_#collectionId) {
throw new RuntimeException("Circularity during survey phase");
}
root.survey_#collectionId();
$endif
#(signature)_initialized = true;
#(signature)_value = $BottomValue;
$if(#getNTA)
if (#(signature)_value != null) {
#(signature)_value.setParent(#ntaParent);
}
$endif
}
if (!state.inCircle() || state.calledByLazyAttribute()) {
$include(AttrDecl.traceCircularEnterCase1)
state.enterCircle();
#tracePrintCycleBeginString
$if(LegacyRewrite)
$include(AttrDecl.cacheInitRewrite)
$endif
do {
#(signature)_cycle = state.nextCycle();
#tracePrintBeginComputingValue
$include(AttrDecl.incHookAttrCompStartCircular)
$include(AttrDecl.traceComputeBegin)
#getType new_#(signature)_value = $CircularComputeRhs;
$include(AttrDecl.traceComputeEnd)
$include(AttrDecl.incHookAttrCompEndCircular)
if ($ChangeCondition) {
state.setChangeInCycle();
$include(AttrDecl.traceCircularCase1Change)
}
#(signature)_value = new_#(signature)_value;
$if(#getNTA)
if (#(signature)_value != null) {
#(signature)_value.setParent(#ntaParent);
}
$endif
#tracePrintStartingCycle
#cycleLimitCheck
} while (state.testAndClearChangeInCycle());
$if(LegacyRewrite)
if (#cacheStoreCondition) {
#(signature)_computed = true;
$include(AttrDecl.cacheCycleInit)
$include(AttrDecl.traceCacheStore)
} else {
state.startResetCycle();
#getType $$tmp = $CircularComputeRhs;
#(signature)_computed = false;
#(signature)_initialized = false;
$include(AttrDecl.traceCacheAbort)
}
$else
#(signature)_computed = true;
$include(AttrDecl.cacheCycleInit)
$include(AttrDecl.traceCacheStore)
$endif
state.leaveCircle();
$TracePrintReturnNewValue
#tracePrintCycleEndString
$include(AttrDecl.traceCircularExitCase1)
} else if (#(signature)_cycle != state.cycle()) {
$include(AttrDecl.traceCircularEnterCase2)
#(signature)_cycle = state.cycle();
$include(AttrDecl.cacheCycleCheck)
$if(LegacyRewrite)
$include(AttrDecl.resetCycleCheck)
$endif
#tracePrintBeginComputingValue
$include(AttrDecl.incHookAttrCompStartCircular)
$include(AttrDecl.traceComputeBegin)
#getType new_#(signature)_value = $CircularComputeRhs;
$include(AttrDecl.traceComputeEnd)
$include(AttrDecl.incHookAttrCompEndCircular)
if ($ChangeCondition) {
state.setChangeInCycle();
$include(AttrDecl.traceCircularCase2Change)
}
#(signature)_value = new_#(signature)_value;
$if(#getNTA)
if (#(signature)_value != null) {
#(signature)_value.setParent(#ntaParent);
}
$endif
$TracePrintReturnNewValue
$include(AttrDecl.traceCircularExitCase2)
} else {
$TracePrintReturnPreviousValue
$include(AttrDecl.traceCircularExitCase3)
}
$include(AttrDecl.returnStmt)
}
]]
AttrDecl.circularEquation:parameterized [[
#annotations
$include(AttrDecl.generatedAnnotations)
public #getType #name($ParamDecl) {
#parameterStructure
#initLazyMaps
$StateClass.CircularValue _value;
if (#(signature)_values.containsKey(_parameters)) {
Object _cache = #(signature)_values.get(_parameters);
if (!(_cache instanceof $StateClass.CircularValue)) {
$include(AttrDecl.traceCacheRead)
return (#boxedType) _cache;
} else {
_value = ($StateClass.CircularValue) _cache;
}
} else {
_value = new $StateClass.CircularValue();
#(signature)_values.put(_parameters, _value);
_value.value = $BottomValue;
$if(#getNTA)
if (_value.value != null) {
if (#(signature)_proxy == null) {
#(signature)_proxy = new $ASTNode();
#(signature)_proxy.setParent(#ntaParent);
}
(($ASTNode) _value.value).setParent(#(signature)_proxy);
}
$endif
}
$StateClass state = state();
if (!state.inCircle() || state.calledByLazyAttribute()) {
$include(AttrDecl.traceCircularEnterCase1)
state.enterCircle();
#tracePrintCycleBeginString
$if(LegacyRewrite)
$include(AttrDecl.cacheInitRewrite)
$endif
#getType new_#(signature)_value;
do {
_value.cycle = state.nextCycle();
#tracePrintBeginComputingValue
$include(AttrDecl.incHookAttrCompStartCircular)
$include(AttrDecl.traceComputeBegin)
new_#(signature)_value = $CircularComputeRhs;
$include(AttrDecl.traceComputeEnd)
$include(AttrDecl.incHookAttrCompEndCircular)
if ($ChangeCondition) {
state.setChangeInCycle();
$include(AttrDecl.traceCircularCase1Change)
_value.value = new_#(signature)_value;
$if(#getNTA)
if (_value.value != null) {
if (#(signature)_proxy == null) {
#(signature)_proxy = new $ASTNode();
#(signature)_proxy.setParent(#ntaParent);
}
(($ASTNode) _value.value).setParent(#(signature)_proxy);
}
$endif
}
#tracePrintStartingCycle
#cycleLimitCheck
} while (state.testAndClearChangeInCycle());
$if(LegacyRewrite)
if (#cacheStoreCondition) {
#(signature)_values.put(_parameters, new_#(signature)_value);
$include(AttrDecl.cacheCycleInit)
$include(AttrDecl.traceCacheStore)
} else {
#(signature)_values.remove(_parameters);
state.startResetCycle();
#getType $$tmp = $CircularComputeRhs;
$include(AttrDecl.traceCacheAbort)
}
$else
#(signature)_values.put(_parameters, new_#(signature)_value);
$include(AttrDecl.cacheCycleInit)
$include(AttrDecl.traceCacheStore)
$endif
state.leaveCircle();
$TracePrintReturnNewValue
#tracePrintCycleEndString
$include(AttrDecl.traceCircularExitCase1)
return new_#(signature)_value;
} else if (_value.cycle != state.cycle()) {
_value.cycle = state.cycle();
$include(AttrDecl.traceCircularEnterCase2)
#tracePrintBeginComputingValue
$include(AttrDecl.incHookAttrCompStartCircular)
$include(AttrDecl.traceComputeBegin)
#getType new_#(signature)_value = $CircularComputeRhs;
$include(AttrDecl.traceComputeEnd)
$include(AttrDecl.incHookAttrCompEndCircular)
$include(AttrDecl.cacheCycleCheck)
$if(LegacyRewrite)
$include(AttrDecl.resetCycleCheck)
else if ($ChangeCondition) {
$else
if ($ChangeCondition) {
$endif
state.setChangeInCycle();
$include(AttrDecl.traceCircularCase2Change)
_value.value = new_#(signature)_value;
$if(#getNTA)
if (_value.value != null) {
if (#(signature)_proxy == null) {
#(signature)_proxy = new $ASTNode();
#(signature)_proxy.setParent(#ntaParent);
}
(($ASTNode) _value.value).setParent(#(signature)_proxy);
}
$endif
}
$TracePrintReturnNewValue
$include(AttrDecl.traceCircularExitCase2)
return new_#(signature)_value;
} else {
$TracePrintReturnPreviousValue
$include(AttrDecl.traceCircularExitCase3)
return (#boxedType) _value.value;
}
}
]]
AttrDecl.cacheCycleInit [[
$if(CacheCycle)
state.startLastCycle();
#getType $$tmp = $CircularComputeRhs;
$endif
]]
AttrDecl.cacheCycleCheck [[
$if(CacheCycle)
if (state.lastCycle()) {
$if(#isParameterized)
#(signature)_values.put(_parameters, new_#(signature)_value);
$else
#(signature)_computed = true;
$include(AttrDecl.incHookAttrCompStartCircular)
#getType new_#(signature)_value = $CircularComputeRhs;
$include(AttrDecl.incHookAttrCompEndCircular)
return new_#(signature)_value;
$endif
}
$endif
]]
# Only used for legacy rewrites.
AttrDecl.resetCycleCheck [[
if (state.resetCycle()) {
$if(#isParameterized)
#(signature)_values.remove(_parameters);
$else
#(signature)_computed = false;
#(signature)_initialized = false;
#(signature)_cycle = null;
$include(AttrDecl.returnStmt)
$endif
}
]]