template.concurrent.Flush.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-2017, 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.
# Used to refresh a cloned node to a fresh state.
# Note: atomic references need to be replaced since this is a fresh object,
# otherwise there would be cache sharing between separate nodes.
ASTDecl.makeFreshNode [[
/** @apilevel internal */
public void #name.makeFreshNode() {
$if(!#isASTNodeDecl)
super.makeFreshNode();
$endif
$MakeFreshNodeBody
}
]]
# Resets all caches for a collection attribute.
Collection.makeFresh [[
$if(#onePhase)
collect_contributors_#collectionId = false;
$else
contributorMap_#collectionId = null;
$if(Concurrent)
surveyLock_#collectionId = new Object();
$endif
$endif
]]
AttrDecl.resetMethod [[
$if(FlushAttr)
/** @apilevel internal */
private void #(signature)_reset() {
$include(AttrDecl.traceFlushAttr)
$if(Concurrent)
$include(AttrDecl.resetAttrCache:concurrent)
$include(AttrDecl.resetAttrVisit:concurrent)
$else
$include(AttrDecl.resetAttrCache)
$include(AttrDecl.resetAttrVisit)
$endif
}
$endif
]]
# There are some things that don't need to be reset when flushing
# a node to a non-fresh state:
# - NTA proxy objects
# - atomic references
# - id objects
# Note: circular attribute values can be reset instead of creating a new
# object but this not implemented yet.
AttrDecl.resetAttrCache:concurrent [[
$if(#isParameterized)
#(signature)_values.clear();
$else
$if(#isCircular)
#(signature)_value = new CircularAttributeValue();
$else
$if(#isIdentityComparable)
#(signature)_computed = false;
$if(#cacheInCycle)
#(signature)_id = new Object();
$endif
$else
#(signature)_value.set(AttributeValue.NONE);
$endif
$endif
$endif
]]
# TODO(joqvist): implement this!
AttrDecl.resetAttrVisit:concurrent [[
]]
# Reset all attribute caches.
# Fresh atomic references are needed to avoid aliasing.
AttrDecl.makeFresh [[
/** @apilevel internal */
private void #(signature)_fresh() {
$if(#isParameterized)
$if(#declaredNTA)
#(signature)_proxy = new AtomicReference<$ASTNode>(null);
$endif
$if(#isCircular)
#(signature)_values = new $ConcurrentMap