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

template.incremental.Rewrites.tt Maven / Gradle / Ivy

There is a newer version: 2.3.6
Show newest version
# Copyright (c) 2013, 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.incFlushRewritesLocateEnclosingRewriteMethod = [[
$if(IncrementalEnabled)
$if(#isASTNodeDecl)
$if(IncrementalLevelParam)
  /** @apilevel internal */
   protected $ASTNode $ASTNode.inc_locateEnclosingRewrittenNode() {
     $ASTNode child = this;
     $ASTNode parent = this.parent;
     while (parent != null) {
       if (child.mayHaveRewrite()) {
         return parent;
       }
       child = parent;
       parent = parent.parent;
     }
     return null;
  }
$endif
$if(IncrementalLevelAttr)
  /** @apilevel internal */
   protected $ASTNode $ASTNode.inc_locateEnclosingRewrittenNode() {
     $ASTNode child = this;
     $ASTNode parent = this.parent;
     while (parent != null) {
       if (child.mayHaveRewrite()) {
         return parent;
       }
       child = parent;
       parent = parent.parent;
     }
     return null;
  }
$endif
$if(IncrementalLevelNode)
  /** @apilevel internal */
  protected $ASTNode $ASTNode.inc_locateEnclosingRewrittenNode() {
    $ASTNode node = parent;
    while (node != null) {
      if (node.mayHaveRewrite()) {
        return node;
      }
      node = node.parent;
    }
    return null;
  }
$endif
$if(IncrementalLevelRegion)
  /** @apilevel internal */
  protected $ASTNode $ASTNode.inc_locateEnclosingRewrittenNode() {
    $ASTNode node = parent;
    while (node != null) {
      if (node.mayHaveRewrite()) {
        return node;
      }
      node = node.parent;
    }
    return null;
  }
$endif
$endif
$endif
]]

ASTNode.incResetRewritesMethod = [[
$if(IncrementalEnabled)
$if(#isASTNodeDecl)
  /** @apilevel internal */
  protected void $ASTNode.inc_resetRewrites() {
    for (int i = 0; i < numChildren; i++) {
      if (children_computed != null && i < children_computed.length) {
        children_computed[i] = false;
        if (init_children[i] != null) {
          init_children[i].inc_throwAway();
          init_children[i] = null;
        }
      }
      if (children[i] != null) {
        children[i].inc_resetRewrites();
      }
    }
  }
$endif
$endif
]]

ASTNode.incRestoreEnclosingRewriteMethod = [[
$if(IncrementalEnabled)
$if(#isASTNodeDecl)
$if(IncrementalLevelParam)
  /** @apilevel internal */
  protected void $ASTNode.inc_restoreEnclosingRewrite() {
    $ASTNode child = this;
    $ASTNode parent = this.parent;
    while (parent != null) {
      int index = -1;
      for (int i = 0; i < parent.children.length; i++) {
        if (parent.children[i] == child) {
          index = i;
        }
      }
      if (child.mayHaveRewrite() && parent.inc_restoreInitialForIndex(index, parent.getChild_handler[index])) {
        parent.getChild_handler[index].notifyDependencies();
        break;
      }
      child = parent;
      parent = parent.getParent();
    }
  }
$endif
$endif
$endif
]]

ASTNode.incRestoreInitialForIndexMethod = [[
$if(IncrementalEnabled)
$if(#isASTNodeDecl)
$if(IncrementalLevelParam)
  /** @apilevel internal */
  protected boolean $ASTNode.inc_restoreInitialForIndex(int index, $DDGNodeName h) {
    if (init_children != null && index < init_children.length && init_children[index] != null) {
      $ASTNode oldNode = children[index];
      state().enterConstruction();
      setChild(init_children[index], index);
      state().exitConstruction();
      oldNode.inc_flush_subtree(h);
      init_children[index] = null;
      children_computed[index] = false;
      return true;
    }
    return false;
  }
$endif
$if(IncrementalLevelAttr)
  /** @apilevel internal */
  protected boolean $ASTNode.inc_restoreInitialForIndex(int index, $DDGNodeName h) {
    if (init_children != null && index < init_children.length && init_children[index] != null) {
      $ASTNode oldNode = children[index];
      state().enterConstruction();
      setChild(init_children[index], index);
      state().exitConstruction();
      oldNode.inc_flush_subtree(h);
      init_children[index] = null;
      children_computed[index] = false;
      return true;
    }
    return false;
  }
$endif
$if(IncrementalLevelNode)
  /** @apilevel internal */
  protected boolean $ASTNode.inc_restoreInitialForIndex(int index, $DDGNodeName h) {
    if (init_children != null && index < init_children.length && init_children[index] != null) {
      $ASTNode oldNode = children[index];
      state().enterConstruction();
      setChild(init_children[index], index);
      state().exitConstruction();
      oldNode.inc_flush_subtree(h);
      init_children[index] = null;
      return true;
    }
    return false;
  }
$endif
$if(IncrementalLevelRegion)
  /** @apilevel internal */
  protected boolean $ASTNode.inc_restoreInitialForIndex(int index, $DDGNodeName h) {
    if (init_children != null && index < init_children.length && init_children[index] != null) {
      $ASTNode oldNode = children[index];
      state().enterConstruction();
      setChild(init_children[index], index);
      state().exitConstruction();
      oldNode.inc_flush_subtree(h);
      init_children[index] = null;
      return true;
    }
    return false;
  }
$endif
$endif
$endif
]]

ASTNode.incLocateInitialCopyMethod = [[
$if(IncrementalEnabled)
$if(#isASTNodeDecl)
  /** @apilevel internal */
  protected $ASTNode $ASTNode.inc_locateInitialCopy() {
    //TODO(emso): fix this method to work with CNTAs.
    if (true) return null;
    // locate enclosing rewrite
    $ASTNode child = this;
    $ASTNode parent = getParent();
    java.util.LinkedList indexList = new java.util.LinkedList();
    while (parent != null) {
      int index = child.childIndex;
      indexList.addFirst(Integer.valueOf(index));
      //if (parent.init_children != null && index >= 0 && index < parent.init_children.length && parent.init_children[index] != null) {
      //  break;
      //}
      child = parent;
      parent = child.getParent();
    }
    // root reached -- no enclosing rewrite
    if (parent == null) {
      return null;
    }
    // root not reached -- enclosing rewrite found
    boolean first = true;
    for (java.util.Iterator itr = indexList.iterator(); itr.hasNext();) {
      int index = ((Integer)itr.next()).intValue();
      if (first) {
        first = false;
           //child = parent.init_children[index];
        parent = child;
      } else if (index < parent.getNumChildNoTransform()) {
        child = parent.getChildNoTransform(index);
        parent = child;
      } else {
        return null;
      }
    }
    // initial change point found
    return child;
  }
$endif
$endif
]]




© 2015 - 2024 Weber Informatics LLC | Privacy Policy