001: /*
002: * Copyright 1994-2003 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: package sun.tools.tree;
027:
028: import sun.tools.java.*;
029: import sun.tools.asm.Assembler;
030: import java.util.Hashtable;
031:
032: /**
033: * WARNING: The contents of this source file are not part of any
034: * supported API. Code that depends on them does so at its own risk:
035: * they are subject to change or removal without notice.
036: */
037: public class CommaExpression extends BinaryExpression {
038: /**
039: * constructor
040: */
041: public CommaExpression(long where, Expression left, Expression right) {
042: super (COMMA, where, (right != null) ? right.type : Type.tVoid,
043: left, right);
044: }
045:
046: /**
047: * Check void expression
048: */
049: public Vset check(Environment env, Context ctx, Vset vset,
050: Hashtable exp) {
051: vset = left.check(env, ctx, vset, exp);
052: vset = right.check(env, ctx, vset, exp);
053: return vset;
054: }
055:
056: /**
057: * Select the type
058: */
059: void selectType(Environment env, Context ctx, int tm) {
060: type = right.type;
061: }
062:
063: /**
064: * Simplify
065: */
066: Expression simplify() {
067: if (left == null) {
068: return right;
069: }
070: if (right == null) {
071: return left;
072: }
073: return this ;
074: }
075:
076: /**
077: * Inline
078: */
079: public Expression inline(Environment env, Context ctx) {
080: if (left != null) {
081: left = left.inline(env, ctx);
082: }
083: if (right != null) {
084: right = right.inline(env, ctx);
085: }
086: return simplify();
087: }
088:
089: public Expression inlineValue(Environment env, Context ctx) {
090: if (left != null) {
091: left = left.inline(env, ctx);
092: }
093: if (right != null) {
094: right = right.inlineValue(env, ctx);
095: }
096: return simplify();
097: }
098:
099: /**
100: * Code
101: */
102: int codeLValue(Environment env, Context ctx, Assembler asm) {
103: if (right == null) {
104: // throw an appropriate error
105: return super .codeLValue(env, ctx, asm);
106: } else {
107: // Fully code the left-hand side. Do the LValue part of the
108: // right-hand side now. The remainder will be done by codeLoad or
109: // codeStore
110: if (left != null) {
111: left.code(env, ctx, asm);
112: }
113: return right.codeLValue(env, ctx, asm);
114: }
115: }
116:
117: void codeLoad(Environment env, Context ctx, Assembler asm) {
118: // The left-hand part has already been handled by codeLValue.
119:
120: if (right == null) {
121: // throw an appropriate error
122: super .codeLoad(env, ctx, asm);
123: } else {
124: right.codeLoad(env, ctx, asm);
125: }
126: }
127:
128: void codeStore(Environment env, Context ctx, Assembler asm) {
129: // The left-hand part has already been handled by codeLValue.
130: if (right == null) {
131: // throw an appropriate error
132: super .codeStore(env, ctx, asm);
133: } else {
134: right.codeStore(env, ctx, asm);
135: }
136: }
137:
138: public void codeValue(Environment env, Context ctx, Assembler asm) {
139: if (left != null) {
140: left.code(env, ctx, asm);
141: }
142: right.codeValue(env, ctx, asm);
143: }
144:
145: public void code(Environment env, Context ctx, Assembler asm) {
146: if (left != null) {
147: left.code(env, ctx, asm);
148: }
149: if (right != null) {
150: right.code(env, ctx, asm);
151: }
152: }
153: }
|