aboutsummaryrefslogtreecommitdiffstats
path: root/C2J/CFuncVariable.java
blob: a2e08f02b9b90e52144aa6b760cebb8be4b639b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/**
 * @(#) CFuncVariable.java
 */

import java.lang.String;

/**
 * The variable-declaration holder !
 *
 * @see CFuncDeclaration
 * @version 	1.00, 12. Novemeber 1999
 * @author      Sven Goethel
 * 
 */
public class CFuncVariable 
	implements Cloneable
{

	public boolean complete;

	public boolean isVoid;
	public boolean isConst;

	public int     arrayNumber;

	public boolean isGLUPtrObject;

	/**
	 * This Variable holds the base type
	 * of the original C type !
	 *
	 * E.g. "const int[][]" -> "int"
	 *      "const GLint *" -> "GLint"
	 * 
	 */
	public String typeC;

	/**
	 * This Variable holds the base type
	 * of the corresponding Java type !
	 *
	 * E.g. "const int[][]" -> "int"
	 *      "const GLint *" -> "int"
	 * 
	 */
	public String typeJava;

	/**
	 * This Variable holds the
	 * name of the variable !
	 *
	 * E.g. "const int[][] arg1;" -> "arg1"
	 * 
	 */
	public String identifier;

	public CFuncVariable()
	{
		complete=false;

		isVoid=false;
		isConst=false;
		isGLUPtrObject=false;

		arrayNumber=0;

		typeC	= null;
		typeJava	= null;
		identifier 	= null;
	}

	protected Object clone()
	                throws CloneNotSupportedException
	{
		CFuncVariable nobj=new CFuncVariable();
		nobj.typeC=new String(typeC);
		nobj.typeJava=new String(typeJava);
		nobj.identifier=new String(identifier);
		nobj.complete=complete;
		nobj.isVoid=isVoid;
		nobj.isConst=isConst;
		nobj.arrayNumber=arrayNumber;
		nobj.isGLUPtrObject=isGLUPtrObject;
		return nobj;
	}

	public String toString()
	{
		int i;
		String res = new String();
		if(isConst)
			res += "const ";
	        res += "("+typeC+"|"+typeJava+") ";
		for(i=0; i<arrayNumber; i++)
			res += "*";
		if(isGLUPtrObject)
			res += "*";
		res += " "+identifier;
		if(isVoid)
			res += " /* Void */";
		return res;
	}

	/**
	 * This Method extracts the 
	 * correct Type-Part for the JNI-Access Methods !
	 * This is needed for Array-Types !
	 * 
	 * E.g.: 
	 *      jintArray -> Int : (*env)->GetIntArrayElements(...)
	 */
	public String getJniCMethodBaseType()
	{
		if(typeJava!=null)
		{
		   return typeJava.substring(0, 1).toUpperCase() +
			  typeJava.substring(1, typeJava.length());   
	        }

		return null;
	}

	/**
	 * This Method returns the complete
	 * Java-Type-String for this variable.
	 * 
	 */
	public String getJavaTypeString()
	{
		int j;
		String res = new String();

		res+=typeJava;

		for(j=0; j<arrayNumber; j++)
			res+="[]";

		return res;
	}

	/**
	 * This Method returns the complete
	 * JNI-Type-String for this variable.
	 * 
	 */
	public String getJNITypeString()
	{
		int j;
		String res = new String();

		if(isVoid)
			res+=typeJava;
		else
			res+="j"+typeJava;

		if(arrayNumber>0)
			res+="Array";

		return res;
	}

	/**
	 * This Method returns the complete
	 * C-Type-String for this variable.
	 * 
	 */
	public String getCTypeString()
	{
		int j;
		String res = new String();

		if(isConst)
			res+="const ";

		res+=typeC;

		if(arrayNumber>0||isGLUPtrObject)
			res+=" ";
		for(j=0; j<arrayNumber; j++)
			res+="*";
		if(isGLUPtrObject)
			res+="*";
		return res;
	}
}