001/* ASTPtAssignmentNode represents assignment nodes in the parse tree 002 003 Copyright (c) 1998-2015 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 Yellow (nsmyth) 028 @AcceptedRating Red (cxh) 029 030 Created : May 1998 031 */ 032package ptolemy.data.expr; 033 034import ptolemy.kernel.util.IllegalActionException; 035 036/////////////////////////////////////////////////////////////////// 037//// ASTPtAssignmentNode 038 039/** 040 041 <p> 042 @author Steve Neuendorffer 043 @version $Id$ 044 @see ptolemy.data.expr.ASTPtRootNode 045 @see ptolemy.data.expr.PtParser 046 @see ptolemy.data.Token 047 @see ptolemy.data.expr.UtilityFunctions 048 @see java.lang.Math 049 */ 050public class ASTPtAssignmentNode extends ASTPtRootNode { 051 public ASTPtAssignmentNode(int id) { 052 super(id); 053 } 054 055 public ASTPtAssignmentNode(PtParser p, int id) { 056 super(p, id); 057 } 058 059 /////////////////////////////////////////////////////////////////// 060 //// public methods //// 061 public String getAssignment() { 062 ParseTreeWriter writer = new ParseTreeWriter(); 063 return getIdentifier() + "=" 064 + writer.printParseTree(getExpressionTree()); 065 } 066 067 public ASTPtRootNode getExpressionTree() { 068 Node n = jjtGetChild(1); 069 070 if (!(n instanceof ASTPtRootNode)) { 071 return null; 072 } else { 073 return (ASTPtRootNode) n; 074 } 075 } 076 077 public String getIdentifier() { 078 Node n = jjtGetChild(0); 079 080 if (!(n instanceof ASTPtLeafNode)) { 081 return null; 082 } else { 083 return ((ASTPtLeafNode) n).getName(); 084 } 085 } 086 087 @Override 088 public void jjtClose() { 089 super.jjtClose(); 090 091 // We cannot assume that the result of a function call is 092 // constant, even when the arguments to the function are. 093 _isConstant = false; 094 } 095 096 /** Traverse this node with the given visitor. 097 */ 098 @Override 099 public void visit(ParseTreeVisitor visitor) throws IllegalActionException { 100 visitor.visitAssignmentNode(this); 101 } 102}