OSDN Git Service

* config/i386/i386.md (*sinxf2): Rename to *sinxf2_i387.
[pf3gnuchains/gcc-fork.git] / libjava / classpath / tools / gnu / classpath / tools / giop / grmic / GiopIo.java
1 /* GiopIo.java -- Generates GIOP input/output statements.
2    Copyright (C) 2006 Free Software Foundation
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
20 */
21
22 package gnu.classpath.tools.giop.grmic;
23
24 import java.rmi.Remote;
25
26 import org.omg.CORBA.portable.ObjectImpl;
27
28 /**
29  * Generates the code for reading and writing data over GIOP stream.
30  * 
31  * @author Audrius Meskauskas, Lithuania (audriusa@Bioinformatics.org)
32  */
33 public class GiopIo
34 {
35   /**
36    * Get the statement for writing the variable of the given type to the GIOP ({@link org.omg.CORBA_2_3.portable.OutputStream) stream. The
37    * stream is always named "out".
38    * 
39    * @param c
40    *          the class of the object being written
41    * @param variable
42    *          the variable, where the object value is stored
43    * @param r
44    *          the parent generator, used to name the class
45    * @return the write statement.
46    */
47   public static String getWriteStatement(Class c, String variable, GiopRmicCompiler r)
48   {
49     if (c.equals(boolean.class))
50       return "out.write_boolean(" + variable + ");";
51     if (c.equals(byte.class))
52       return "out.write_octet(" + variable + ");";
53     else if (c.equals(short.class))
54       return "out.write_int(" + variable + ");";
55     else if (c.equals(int.class))
56       return "out.write_long(" + variable + ");";
57     else if (c.equals(long.class))
58       return "out.write_long_long(" + variable + ");";
59     else if (c.equals(double.class))
60       return "out.write_double(" + variable + ");";
61     else if (c.equals(float.class))
62       return "out.write_float(" + variable + ");";
63     else if (c.equals(char.class))
64       return "out.write_char(" + variable + ");";
65     else if (Remote.class.isAssignableFrom(c))
66       return "Util.writeRemoteObject(out, " + variable + ");";
67     else if (ObjectImpl.class.isAssignableFrom(c))
68       return "out.write_Object(" + variable + ");";
69     else
70       return "out.write_value(" + variable + ", " + r.name(c) + ".class);";
71   }
72
73   /**
74    * Get the statement for reading the value of the given type from to the GIOP ({@link org.omg.CORBA_2_3.portable.InputStream) stream. The
75    * stream is always named "in".
76    * 
77    * @param c
78    *          the class of the object being written
79    * @param r
80    *          the parent generator, used to name the class
81    * @return the right side of the read statement.
82    */
83   public static String getReadStatement(Class c, GiopRmicCompiler r)
84   {
85     if (c.equals(boolean.class))
86       return "in.read_boolean();";
87     else if (c.equals(byte.class))
88       return "in.read_octet();";
89     else if (c.equals(short.class))
90       return "in.read_int();";
91     else if (c.equals(int.class))
92       return "in.read_long();";
93     else if (c.equals(long.class))
94       return "in.read_long_long();";
95     else if (c.equals(double.class))
96       return "in.read_double();";
97     else if (c.equals(float.class))
98       return "in.read_float();";
99     else if (c.equals(char.class))
100       return "in.read_char();";
101     else if (Remote.class.isAssignableFrom(c))
102       return "(" + r.name(c)
103              + ") PortableRemoteObject.narrow(in.read_Object()," + r.name(c)
104              + ".class);";
105     else if (ObjectImpl.class.isAssignableFrom(c))
106       return "in.read_Object();";
107     else
108       return "(" + r.name(c)
109              + ") in.read_value(" + r.name(c) + ".class);";
110   }
111
112 }