001: package org.jacorb.idl;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1997-2004 Gerald Brose.
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Library General Public License for more details.
017: *
018: * You should have received a copy of the GNU Library General Public
019: * License along with this library; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: */
022:
023: import java.io.PrintWriter;
024:
025: /**
026: * @author Gerald Brose
027: * @version $Id: PrimaryExpr.java,v 1.19 2006/06/19 10:34:57 alphonse.bendt Exp $
028: */
029:
030: public class PrimaryExpr extends IdlSymbol {
031: public IdlSymbol symbol;
032:
033: public PrimaryExpr(int num) {
034: super (num);
035: }
036:
037: public void print(PrintWriter ps) {
038: if (symbol instanceof ConstExpr) {
039: ps.print("(");
040: symbol.print(ps);
041: ps.print(")");
042: } else if (symbol instanceof ScopedName) {
043: ps.print(((ScopedName) symbol).resolvedName());
044: } else {
045: // Literal
046: symbol.print(ps);
047: }
048: }
049:
050: public void parse() {
051: symbol.parse();
052: }
053:
054: public void setDeclaration(ConstDecl declared_in) {
055: if (symbol instanceof Literal) {
056: ((Literal) symbol).setDeclaration(declared_in);
057: }
058: }
059:
060: public void setPackage(String s) {
061: s = parser.pack_replace(s);
062: if (pack_name.length() > 0) {
063: pack_name = s + "." + pack_name;
064: } else {
065: pack_name = s;
066: }
067:
068: symbol.setPackage(s);
069: }
070:
071: int pos_int_const() {
072: if (symbol instanceof ConstExpr) {
073: return ((ConstExpr) symbol).pos_int_const();
074: } else if (symbol instanceof ScopedName) {
075: ConstExprEvaluator eval = new ConstExprEvaluator(ConstDecl
076: .namedValue((ScopedName) symbol));
077: if (logger.isDebugEnabled()) {
078: logger.debug("PrimaryExpr: returning value "
079: + eval.getValue().intValue());
080: }
081:
082: return eval.getValue().intValue();
083: }
084: return Integer.parseInt(((Literal) symbol).toString());
085: }
086:
087: public String value() {
088: if (symbol instanceof ConstExpr) {
089: return "(" + ((ConstExpr) symbol).value() + ")";
090: } else if (symbol instanceof ScopedName) {
091: return ConstDecl.namedValue((ScopedName) symbol);
092: }
093: return ((Literal) symbol).toString();
094: }
095:
096: public String toString() {
097: if (symbol instanceof ConstExpr) {
098: return "(" + ((ConstExpr) symbol).toString() + ")";
099: } else if (symbol instanceof ScopedName) {
100: return ((ScopedName) symbol).resolvedName();
101: } else {
102: return ((Literal) symbol).toString();
103: }
104: }
105:
106: public str_token get_token() {
107: return symbol.get_token();
108: }
109: }
|