001: /*
002: * Copyright 1999-2001 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: /*
026: * COMPONENT_NAME: idl.parser
027: *
028: * ORIGINS: 27
029: *
030: * Licensed Materials - Property of IBM
031: * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
032: * RMI-IIOP v1.0
033: *
034: * @(#)Terminal.java 1.21 07/05/05
035: */
036:
037: package com.sun.tools.corba.se.idl.constExpr;
038:
039: // NOTES:
040:
041: import com.sun.tools.corba.se.idl.ConstEntry;
042: import java.math.BigInteger;
043:
044: /**
045: * This class contains values. Objects of this class are the terminal
046: * nodes of an expression tree.
047: * <b>
048: * Note that there is a constructor for Double values, but not Float.
049: * CORBA defines that all floating point expressions are evaluated as
050: * double, and that the result is coerced back to float if necessary.
051: * <b>
052: * Note also that there is a constructor for long values, but not for
053: * int or short. CORBA defines that all integral expressions are evaluated
054: * as unsigned long. A CORBA long is a Java int. There is no unsigned int
055: * in Java, so the next larger type, long, is used.
056: **/
057: public class Terminal extends Expression {
058: protected Terminal(String representation, Character charValue,
059: boolean isWide) {
060: rep(representation);
061: value(charValue);
062: if (isWide)
063: type("wchar");
064: else
065: type("char");
066: } // ctor
067:
068: protected Terminal(String representation, Boolean booleanValue) {
069: rep(representation);
070: value(booleanValue);
071: } // ctor
072:
073: // Support long long <daz>
074: protected Terminal(String representation, BigInteger bigIntegerValue) {
075: rep(representation);
076: value(bigIntegerValue);
077: } // ctor
078:
079: protected Terminal(String representation, Long longValue) {
080: long lv = longValue.longValue();
081: rep(representation);
082: if (lv > Integer.MAX_VALUE || lv < Integer.MIN_VALUE)
083: value(longValue);
084: else
085: value(new Integer(longValue.intValue()));
086: } // ctor
087:
088: protected Terminal(String representation, Double doubleValue) {
089: rep(representation);
090: value(doubleValue);
091: } // ctor
092:
093: protected Terminal(String stringValue, boolean isWide) {
094: rep(stringValue);
095: value(stringValue);
096: if (isWide)
097: type("wstring");
098: else
099: type("string");
100: } // ctor
101:
102: protected Terminal(ConstEntry constReference) {
103: rep(constReference.fullName());
104: value(constReference);
105: } // ctor
106:
107: ///// INSTANCE METHODS
108: public Object evaluate() throws EvaluationException {
109: if (value() instanceof ConstEntry)
110: return ((ConstEntry) value()).value().evaluate();
111: else
112: return value();
113: } // evaluate
114: } // class Terminal
|