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: AddExpr.java,v 1.16 2006/06/19 10:34:57 alphonse.bendt Exp $
028: */
029:
030: public class AddExpr extends IdlSymbol {
031: public AddExpr add_expr = null;
032: public String operator;
033: public MultExpr mult_expr;
034:
035: public AddExpr(int num) {
036: super (num);
037: }
038:
039: public void print(PrintWriter ps) {
040: if (add_expr != null) {
041: add_expr.print(ps);
042: ps.print(operator);
043: }
044: mult_expr.print(ps);
045: }
046:
047: public void setDeclaration(ConstDecl declared_in) {
048: mult_expr.setDeclaration(declared_in);
049: }
050:
051: public void setPackage(String s) {
052: s = parser.pack_replace(s);
053: if (pack_name.length() > 0)
054: pack_name = s + "." + pack_name;
055: else
056: pack_name = s;
057: if (add_expr != null) {
058: add_expr.setPackage(s);
059: }
060: mult_expr.setPackage(s);
061: }
062:
063: public void parse() {
064: if (add_expr != null) {
065: add_expr.parse();
066: }
067: mult_expr.parse();
068: }
069:
070: int pos_int_const() {
071: int y = mult_expr.pos_int_const();
072: if (add_expr != null) {
073: int z = add_expr.pos_int_const();
074: if (operator.equals("-")) {
075: z *= -1;
076: }
077: return z + y;
078: }
079: return y;
080: }
081:
082: public String value() {
083: String x = "";
084: if (add_expr != null) {
085: x = add_expr.value() + operator;
086: }
087: return x + mult_expr.value();
088: }
089:
090: public String toString() {
091: String x = "";
092: if (add_expr != null) {
093: x = add_expr.toString() + ' ' + operator + ' ';
094: }
095: return x + mult_expr;
096: }
097:
098: public str_token get_token() {
099: return mult_expr.get_token();
100: }
101: }
|