1 /*
2  * Copyright (c) 1994, 2003, 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 package sun.tools.tree;
27 
28 import sun.tools.java.*;
29 import sun.tools.asm.Assembler;
30 import java.util.Hashtable;
31 
32 /**
33  * WARNING: The contents of this source file are not part of any
34  * supported API.  Code that depends on them does so at its own risk:
35  * they are subject to change or removal without notice.
36  */
37 public
38 class CommaExpression extends BinaryExpression {
39     /**
40      * constructor
41      */
CommaExpression(long where, Expression left, Expression right)42     public CommaExpression(long where, Expression left, Expression right) {
43         super(COMMA, where, (right != null) ? right.type : Type.tVoid, left, right);
44     }
45 
46     /**
47      * Check void expression
48      */
check(Environment env, Context ctx, Vset vset, Hashtable<Object, Object> exp)49     public Vset check(Environment env, Context ctx, Vset vset, Hashtable<Object, Object> exp) {
50         vset = left.check(env, ctx, vset, exp);
51         vset = right.check(env, ctx, vset, exp);
52         return vset;
53     }
54 
55     /**
56      * Select the type
57      */
selectType(Environment env, Context ctx, int tm)58     void selectType(Environment env, Context ctx, int tm) {
59         type = right.type;
60     }
61 
62     /**
63      * Simplify
64      */
simplify()65     Expression simplify() {
66         if (left == null) {
67             return right;
68         }
69         if (right == null) {
70             return left;
71         }
72         return this;
73     }
74 
75     /**
76      * Inline
77      */
inline(Environment env, Context ctx)78     public Expression inline(Environment env, Context ctx) {
79         if (left != null) {
80             left = left.inline(env, ctx);
81         }
82         if (right != null) {
83             right = right.inline(env, ctx);
84         }
85         return simplify();
86     }
inlineValue(Environment env, Context ctx)87     public Expression inlineValue(Environment env, Context ctx) {
88         if (left != null) {
89             left = left.inline(env, ctx);
90         }
91         if (right != null) {
92             right = right.inlineValue(env, ctx);
93         }
94         return simplify();
95     }
96 
97     /**
98      * Code
99      */
codeLValue(Environment env, Context ctx, Assembler asm)100     int codeLValue(Environment env, Context ctx, Assembler asm) {
101         if (right == null) {
102             // throw an appropriate error
103             return super.codeLValue(env, ctx, asm);
104         } else {
105             // Fully code the left-hand side.  Do the LValue part of the
106             // right-hand side now.  The remainder will be done by codeLoad or
107             // codeStore
108             if (left != null) {
109                 left.code(env, ctx, asm);
110             }
111             return right.codeLValue(env, ctx, asm);
112         }
113     }
114 
codeLoad(Environment env, Context ctx, Assembler asm)115     void codeLoad(Environment env, Context ctx, Assembler asm) {
116         // The left-hand part has already been handled by codeLValue.
117 
118         if (right == null) {
119             // throw an appropriate error
120             super.codeLoad(env, ctx, asm);
121         } else {
122             right.codeLoad(env, ctx, asm);
123         }
124     }
125 
codeStore(Environment env, Context ctx, Assembler asm)126     void codeStore(Environment env, Context ctx, Assembler asm) {
127         // The left-hand part has already been handled by codeLValue.
128         if (right == null) {
129             // throw an appropriate error
130             super.codeStore(env, ctx, asm);
131         } else {
132             right.codeStore(env, ctx, asm);
133         }
134     }
135 
codeValue(Environment env, Context ctx, Assembler asm)136     public void codeValue(Environment env, Context ctx, Assembler asm) {
137         if (left != null) {
138             left.code(env, ctx, asm);
139         }
140         right.codeValue(env, ctx, asm);
141     }
code(Environment env, Context ctx, Assembler asm)142     public void code(Environment env, Context ctx, Assembler asm) {
143         if (left != null) {
144             left.code(env, ctx, asm);
145         }
146         if (right != null) {
147             right.code(env, ctx, asm);
148         }
149     }
150 }
151