001/* A visitor for parse trees of the expression language. 002 003 Copyright (c) 1998-2014 The Regents of the University of California 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA OR RESEARCH IN MOTION 012 LIMITED BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, 013 INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS 014 SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA 015 OR RESEARCH IN MOTION LIMITED HAVE BEEN ADVISED OF THE POSSIBILITY OF 016 SUCH DAMAGE. 017 018 THE UNIVERSITY OF CALIFORNIA AND RESEARCH IN MOTION LIMITED 019 SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 020 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 021 PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 022 BASIS, AND THE UNIVERSITY OF CALIFORNIA AND RESEARCH IN MOTION 023 LIMITED HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 024 ENHANCEMENTS, OR MODIFICATIONS. 025 026 027 */ 028package ptolemy.data.expr; 029 030import ptolemy.kernel.util.IllegalActionException; 031 032/////////////////////////////////////////////////////////////////// 033//// AbstractParseTreeVisitor 034 035/** 036 This class implements a base class visitor for parse trees in the 037 expression language. Primarily this class exists to give nice error 038 messages for visitors that are partly implemented, and to allow us to 039 extend the expression language without completely breaking existing 040 code. 041 042 @author Steve Neuendorffer 043 @version $Id$ 044 @since Ptolemy II 2.1 045 @Pt.ProposedRating Red (neuendor) 046 @Pt.AcceptedRating Red (cxh) 047 @see ptolemy.data.expr.ASTPtRootNode 048 */ 049public class AbstractParseTreeVisitor implements ParseTreeVisitor { 050 /////////////////////////////////////////////////////////////////// 051 //// public methods //// 052 @Override 053 public void visitArrayConstructNode(ASTPtArrayConstructNode node) 054 throws IllegalActionException { 055 throw _unsupportedVisitException("ASTPtArrayConstructNode"); 056 } 057 058 @Override 059 public void visitAssignmentNode(ASTPtAssignmentNode node) 060 throws IllegalActionException { 061 throw _unsupportedVisitException("ASTPtAssignmentNode"); 062 } 063 064 @Override 065 public void visitBitwiseNode(ASTPtBitwiseNode node) 066 throws IllegalActionException { 067 throw _unsupportedVisitException("ASTPtBitwiseNode"); 068 } 069 070 @Override 071 public void visitFunctionApplicationNode(ASTPtFunctionApplicationNode node) 072 throws IllegalActionException { 073 throw _unsupportedVisitException("ASTPtFunctionApplicationNode"); 074 } 075 076 @Override 077 public void visitFunctionDefinitionNode(ASTPtFunctionDefinitionNode node) 078 throws IllegalActionException { 079 throw _unsupportedVisitException("ASTPtFunctionDefinitionNode"); 080 } 081 082 @Override 083 public void visitFunctionalIfNode(ASTPtFunctionalIfNode node) 084 throws IllegalActionException { 085 throw _unsupportedVisitException("ASTPtFunctionalIfNode"); 086 } 087 088 @Override 089 public void visitLeafNode(ASTPtLeafNode node) 090 throws IllegalActionException { 091 throw _unsupportedVisitException("ASTPtLeafNode"); 092 } 093 094 @Override 095 public void visitLogicalNode(ASTPtLogicalNode node) 096 throws IllegalActionException { 097 throw _unsupportedVisitException("ASTPtLogicalNode"); 098 } 099 100 @Override 101 public void visitMatrixConstructNode(ASTPtMatrixConstructNode node) 102 throws IllegalActionException { 103 throw _unsupportedVisitException("ASTPtMatrixConstructNode"); 104 } 105 106 @Override 107 public void visitMethodCallNode(ASTPtMethodCallNode node) 108 throws IllegalActionException { 109 throw _unsupportedVisitException("ASTPtMethodCallNode"); 110 } 111 112 @Override 113 public void visitPowerNode(ASTPtPowerNode node) 114 throws IllegalActionException { 115 throw _unsupportedVisitException("ASTPtPowerNode"); 116 } 117 118 @Override 119 public void visitProductNode(ASTPtProductNode node) 120 throws IllegalActionException { 121 throw _unsupportedVisitException("ASTPtProductNode"); 122 } 123 124 @Override 125 public void visitRecordConstructNode(ASTPtRecordConstructNode node) 126 throws IllegalActionException { 127 throw _unsupportedVisitException("ASTPtRecordConstructNode"); 128 } 129 130 @Override 131 public void visitRelationalNode(ASTPtRelationalNode node) 132 throws IllegalActionException { 133 throw _unsupportedVisitException("ASTPtRelationalNode"); 134 } 135 136 @Override 137 public void visitShiftNode(ASTPtShiftNode node) 138 throws IllegalActionException { 139 throw _unsupportedVisitException("ASTPtShiftNode"); 140 } 141 142 @Override 143 public void visitSumNode(ASTPtSumNode node) throws IllegalActionException { 144 throw _unsupportedVisitException("ASTPtSumNode"); 145 } 146 147 @Override 148 public void visitUnaryNode(ASTPtUnaryNode node) 149 throws IllegalActionException { 150 throw _unsupportedVisitException("ASTPtUnaryNode"); 151 } 152 153 @Override 154 public void visitUnionConstructNode(ASTPtUnionConstructNode node) 155 throws IllegalActionException { 156 throw _unsupportedVisitException("ASTPtUnionConstructNode"); 157 } 158 159 /** Return an exception that describes an unsupported node type. 160 * @param name The name of the node type. 161 * @return An exception that describes an unsupported node type. 162 */ 163 protected IllegalActionException _unsupportedVisitException(String name) { 164 new Exception("Unsuppported...").printStackTrace(); 165 return new IllegalActionException("Nodes of type " + name 166 + " cannot be visited by a " + getClass().getName() + "."); 167 } 168 169 /** Loop through all of the children of this node, 170 * visiting each one of them, which will cause their token 171 * value to be determined. 172 * @param node The node whose children are to be looped through. 173 * @exception IllegalActionException If thrown while visiting a child 174 * node. 175 */ 176 protected void _visitAllChildren(ASTPtRootNode node) 177 throws IllegalActionException { 178 int numChildren = node.jjtGetNumChildren(); 179 180 for (int i = 0; i < numChildren; i++) { 181 _visitChild(node, i); 182 } 183 } 184 185 /** Visit the child with the given index of the given node. 186 * This is usually called while visiting the given node. 187 * @param node The node. 188 * @param i The index of the child to be visited. 189 * @exception IllegalActionException If thrown while visiting a child 190 * node. 191 */ 192 protected void _visitChild(ASTPtRootNode node, int i) 193 throws IllegalActionException { 194 ASTPtRootNode child = (ASTPtRootNode) node.jjtGetChild(i); 195 child.visit(this); 196 } 197}