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

template.ast.JJTree.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.

JJTree.jjtAddChild = [[
  public void #name.jjtAddChild(Node n, int i) {
    checkChild(n, i);
$if(#isASTNodeDecl)
    if (i >= numChildren) {
      numChildren = i+1;
    }
$endif
    super.jjtAddChild(n, i);
  }
]]

JJTree.dumpTree = [[
  public void #name.dumpTree(String indent, java.io.PrintStream out) {
    out.print(indent + "#name");
    #jjtGenPrintChildren
    String childIndent = indent + "  ";
    for (int i = 0; i < getNumChild(); i++) {
      getChild(i).dumpTree(childIndent, out);
    }
  }
]]

JJTree.jjtAccept = [[
  public Object #name.jjtAccept($(ParserName)Visitor visitor, Object data) {
    return visitor.visit(this, data);
  }
]]

JJTree.checkChild = [[
  public void #name.checkChild(Node n, int i) {
$if(#isOptDecl)
    if (i > 0) {
      throw new Error("Optional nodes can only have one child");
    }
    if (!(n instanceof $ASTNode)) {
      throw new Error("Node type must be an instance of $ASTNode");
    }
$else$if(#isListDecl)
    if (!(n instanceof $ASTNode)) {
      throw new Error("The node type of child " + i + " must be an instance of $ASTNode");
    }
$else
    #checkRegularNodeStructure
$endif$endif
  }
]]

ListComponent.checkComponentStructure = [[
  if (i == $ChildIndex) {
    if (!(n instanceof $List)) {
      throw new Error("Child number $ChildIndex of $HostClassName has the type " +
        n.getClass().getName() + " which is not an instance of $List");
    }
    for (int k = 0; k < (($List) n).getNumChildNoTransform(); k++) {
      if (!((($List) n).getChildNoTransform(k) instanceof #type)) {
        throw new Error("Child number " + k + " in #(name)List has the type " +
          (($List) n).getChildNoTransform(k).getClass().getName() + " which is not an instance of #type");
      }
    }
  }
]]

OptionalComponent.checkComponentStructure = [[
if (i == $ChildIndex) {
  if (!(n instanceof $Opt)) {
    throw new Error("Child number $ChildIndex of $HostClassName has the type " +
        n.getClass().getName() + " which is not an instance of $Opt");
  }
  if ((($Opt) n).getNumChildNoTransform() != 0 && !((($Opt) n).getChildNoTransform(0) instanceof #type)) {
    throw new Error("Optional name() has the type " +
        (($Opt) n).getChildNoTransform(0).getClass().getName() +
        " which is not an instance of #type");
  }
}
]]

AggregateComponent.checkComponentStructure = [[
if (i == $ChildIndex && !(n instanceof #type)) {
 throw new Error("Child number $ChildIndex of $HostClassName has the type " +
   n.getClass().getName() + " which is not an instance of #type");
}
]]




© 2015 - 2024 Weber Informatics LLC | Privacy Policy