Terminal.java revision 608:7e06bf1dcb09
123353Sdfr/* 223353Sdfr * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved. 323353Sdfr * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 423353Sdfr * 523353Sdfr * This code is free software; you can redistribute it and/or modify it 623353Sdfr * under the terms of the GNU General Public License version 2 only, as 723353Sdfr * published by the Free Software Foundation. Oracle designates this 823353Sdfr * particular file as subject to the "Classpath" exception as provided 923353Sdfr * by Oracle in the LICENSE file that accompanied this code. 1023353Sdfr * 1123353Sdfr * This code is distributed in the hope that it will be useful, but WITHOUT 1223353Sdfr * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1323353Sdfr * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1423353Sdfr * version 2 for more details (a copy is included in the LICENSE file that 1523353Sdfr * accompanied this code). 1623353Sdfr * 1723353Sdfr * You should have received a copy of the GNU General Public License version 1823353Sdfr * 2 along with this work; if not, write to the Free Software Foundation, 1923353Sdfr * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2023353Sdfr * 2123353Sdfr * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2223353Sdfr * or visit www.oracle.com if you need additional information or have any 2323353Sdfr * questions. 2423353Sdfr */ 2523353Sdfr/* 2623353Sdfr * COMPONENT_NAME: idl.parser 2723353Sdfr * 2823353Sdfr * ORIGINS: 27 2950476Speter * 3023353Sdfr * Licensed Materials - Property of IBM 31192691Stmclaugh * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999 32206622Suqs * RMI-IIOP v1.0 3323353Sdfr * 3423353Sdfr */ 3523353Sdfr 36107788Srupackage com.sun.tools.corba.se.idl.constExpr; 3723353Sdfr 3884306Sru// NOTES: 3984306Sru 4084306Sruimport com.sun.tools.corba.se.idl.ConstEntry; 4123353Sdfrimport java.math.BigInteger; 42192691Stmclaugh 4323353Sdfr/** 44139848Skeramida * This class contains values. Objects of this class are the terminal 45139848Skeramida * nodes of an expression tree. 46139848Skeramida * <b> 47139848Skeramida * Note that there is a constructor for Double values, but not Float. 4823353Sdfr * CORBA defines that all floating point expressions are evaluated as 49139848Skeramida * double, and that the result is coerced back to float if necessary. 5023353Sdfr * <b> 51115440Shmp * Note also that there is a constructor for long values, but not for 52107788Sru * int or short. CORBA defines that all integral expressions are evaluated 5323353Sdfr * as unsigned long. A CORBA long is a Java int. There is no unsigned int 5423353Sdfr * in Java, so the next larger type, long, is used. 55139848Skeramida **/ 56139848Skeramidapublic class Terminal extends Expression 57139848Skeramida{ 58121382Shmp protected Terminal (String representation, Character charValue, 59121382Shmp boolean isWide) 6023353Sdfr { 6123353Sdfr rep (representation); 6223353Sdfr value (charValue); 63107788Sru if (isWide) 6423353Sdfr type( "wchar" ) ; 65107788Sru else 6657731Ssheldonh type( "char" ) ; 6757731Ssheldonh } // ctor 6823353Sdfr 69107788Sru protected Terminal (String representation, Boolean booleanValue) 7023353Sdfr { 7123353Sdfr rep (representation); 7223353Sdfr value (booleanValue); 73121382Shmp } // ctor 74121382Shmp 7523353Sdfr // Support long long <daz> 76107788Sru protected Terminal (String representation, BigInteger bigIntegerValue) 7723353Sdfr { 7823353Sdfr rep (representation); 7923353Sdfr value (bigIntegerValue); 8029966Swosch } // ctor 8129966Swosch 8223353Sdfr protected Terminal (String representation, Long longValue) 83121414Shmp { 8434504Scharnier long lv = longValue.longValue (); 85 rep (representation); 86 if (lv > Integer.MAX_VALUE || lv < Integer.MIN_VALUE) 87 value (longValue); 88 else 89 value (new Integer (longValue.intValue ())); 90 } // ctor 91 92 protected Terminal (String representation, Double doubleValue) 93 { 94 rep (representation); 95 value (doubleValue); 96 } // ctor 97 98 protected Terminal (String stringValue, boolean isWide ) 99 { 100 rep (stringValue); 101 value (stringValue); 102 if (isWide) 103 type( "wstring" ) ; 104 else 105 type( "string" ) ; 106 } // ctor 107 108 protected Terminal (ConstEntry constReference) 109 { 110 rep (constReference.fullName ()); 111 value (constReference); 112 } // ctor 113 114 ///// INSTANCE METHODS 115 public Object evaluate () throws EvaluationException 116 { 117 if (value () instanceof ConstEntry) 118 return ((ConstEntry)value ()).value ().evaluate (); 119 else 120 return value (); 121 } // evaluate 122} // class Terminal 123