001/* ASTPtFunctionApplicationNode represents function nodes or array references in the parse tree 002 003 Copyright (c) 1998-2014 The Regents of the University of California and 004 Research in Motion Limited. 005 All rights reserved. 006 Permission is hereby granted, without written agreement and without 007 license or royalty fees, to use, copy, modify, and distribute this 008 software and its documentation for any purpose, provided that the above 009 copyright notice and the following two paragraphs appear in all copies 010 of this software. 011 012 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA OR RESEARCH IN MOTION 013 LIMITED BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, 014 INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS 015 SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA 016 OR RESEARCH IN MOTION LIMITED HAVE BEEN ADVISED OF THE POSSIBILITY OF 017 SUCH DAMAGE. 018 019 THE UNIVERSITY OF CALIFORNIA AND RESEARCH IN MOTION LIMITED 020 SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 021 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 022 PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 023 BASIS, AND THE UNIVERSITY OF CALIFORNIA AND RESEARCH IN MOTION 024 LIMITED HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 025 ENHANCEMENTS, OR MODIFICATIONS. 026 027 @ProposedRating Green (neuendor) 028 @AcceptedRating Yellow (neuendor) 029 030 Created : May 1998 031 */ 032package ptolemy.data.expr; 033 034import ptolemy.kernel.util.IllegalActionException; 035 036/////////////////////////////////////////////////////////////////// 037//// ASTPtFunctionApplicationNode 038 039/** 040 This class represents an expression that is the application of a 041 function in the parse tree. The first child of this node is the child 042 node that represents the function. The function specification may any 043 node that evaluates to a FunctionToken, or a leaf node that refers to 044 the name of a function registered with the parser. The remaining 045 children are node representing the arguments of the function. For 046 information on the evaluation of functions, refer to {@link 047 ptolemy.data.expr.ParseTreeEvaluator#visitFunctionApplicationNode}. 048 049 @author Neil Smyth, Edward A. Lee, Steve Neuendorffer 050 @author Zoltan Kemenczy, Research in Motion Limited 051 @version $Id$ 052 @see ptolemy.data.expr.ASTPtRootNode 053 @see ptolemy.data.expr.PtParser 054 @see ptolemy.data.Token 055 @see ptolemy.data.expr.UtilityFunctions 056 @see java.lang.Math 057 */ 058public class ASTPtFunctionApplicationNode extends ASTPtRootNode { 059 public ASTPtFunctionApplicationNode(int id) { 060 super(id); 061 } 062 063 public ASTPtFunctionApplicationNode(PtParser p, int id) { 064 super(p, id); 065 } 066 067 /////////////////////////////////////////////////////////////////// 068 //// public methods //// 069 public String getFunctionName() { 070 Node n = jjtGetChild(0); 071 072 if (!(n instanceof ASTPtLeafNode)) { 073 return null; 074 } else { 075 ASTPtLeafNode leaf = (ASTPtLeafNode) n; 076 077 if (leaf.isIdentifier()) { 078 return leaf.getName(); 079 } else { 080 return null; 081 } 082 } 083 } 084 085 @Override 086 public void jjtClose() { 087 super.jjtClose(); 088 089 // We cannot assume that the result of a function call is 090 // constant, even when the arguments to the function are. 091 _isConstant = false; 092 } 093 094 /** Traverse this node with the given visitor. 095 */ 096 @Override 097 public void visit(ParseTreeVisitor visitor) throws IllegalActionException { 098 visitor.visitFunctionApplicationNode(this); 099 } 100}