1 /* 2 * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 /* 26 * COMPONENT_NAME: idl.parser 27 * 28 * ORIGINS: 27 29 * 30 * Licensed Materials - Property of IBM 31 * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999 32 * RMI-IIOP v1.0 33 * 34 */ 35 36 package com.sun.tools.corba.se.idl.constExpr; 37 38 // NOTES: 39 40 import com.sun.tools.corba.se.idl.ConstEntry; 41 import java.math.BigInteger; 42 43 /** 44 * This class contains values. Objects of this class are the terminal 45 * nodes of an expression tree. 46 * <b> 47 * Note that there is a constructor for Double values, but not Float. 48 * CORBA defines that all floating point expressions are evaluated as 49 * double, and that the result is coerced back to float if necessary. 50 * <b> 51 * Note also that there is a constructor for long values, but not for 52 * int or short. CORBA defines that all integral expressions are evaluated 53 * as unsigned long. A CORBA long is a Java int. There is no unsigned int 54 * in Java, so the next larger type, long, is used. 55 **/ 56 public class Terminal extends Expression 57 { 58 protected Terminal (String representation, Character charValue, 59 boolean isWide) 60 { 61 rep (representation); 62 value (charValue); 63 if (isWide) 64 type( "wchar" ) ; 65 else 66 type( "char" ) ; 67 } // ctor 68 69 protected Terminal (String representation, Boolean booleanValue) 70 { 71 rep (representation); 72 value (booleanValue); 73 } // ctor 74 75 // Support long long <daz> 76 protected Terminal (String representation, BigInteger bigIntegerValue) 77 { 78 rep (representation); 79 value (bigIntegerValue); 80 } // ctor 81 82 protected Terminal (String representation, Long longValue) 83 { 84 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