/
CType.h
186 lines (150 loc) · 5.25 KB
/
CType.h
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
/*
* This file is part of cxxwrap
* Copyright (c) 1998, 1999 David Deaven (deaven@deaven.net)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Author: deaven $
* $Id: CType.h,v 1.24 2006/12/17 04:08:11 deaven Exp $
*/
#ifndef __CType__
#define __CType__
#include "Token.h"
class Arg;
class CType : public Token {
public:
enum Modifier {
M_CONST = 1 << 0,
M_STATIC = 1 << 1,
M_REFERENCE = 1 << 2,
M_POINTER = 1 << 3,
M_ENUM = 1 << 4,
M_VIRTUAL = 1 << 5,
M_TEMPLATE = 1 << 6,
M_UNSIGNED = 1 << 7,
M_VOLATILE = 1 << 8,
M_REGISTER = 1 << 9,
M_CTOR = 1 << 10,
M_DTOR = 1 << 11,
M_PROTECTED = 1 << 12,
M_PRIVATE = 1 << 13,
M_VARARG = 1 << 14,
M_ATTRIBUTE = 1 << 15,
M_TYPEDEF = 1 << 16,
M_OPERATOR = 1 << 17,
M_PTR_CONST = 1 << 18
};
CType(const char* _comment, long mods = 0L) :
Token(_comment), modifiers(mods), indirection_count(0),
alias(NULL) { }
virtual CType* clone() { return new CType(*this); }
virtual ~CType() { }
virtual const char* classname() const { return "CType"; }
virtual int equals(CType* other);
// expand a templated type
virtual CType* expand(Arg* parameters, Arg* args);
/** The C type name of this data type.
*/
virtual const char* CTypeName();
/** The C type name used by JNI to represent this type.
*/
virtual const char* JNITypeName();
/** Return the JNI type used in the return value from JNI
* functions, e.g. Call<type>Method.
*/
virtual const char* JavaJNITypeName();
/** Return the java type name as used in the Call<type>Method JNI
* functions.
*/
virtual const char* JNIFunctionTypeName();
/** The Java type name used in the public interface.
*/
virtual const char* JavaTypeName();
/** The Java type name used in the private native interface.
*/
virtual const char* PrivateJavaTypeName();
/** The default Java value used in the private native interface.
*/
virtual const char* DefaultPrivateJavaValue();
/** Emit any C code needed to support JNI casts.
*/
virtual const char* JNIBegin(const char* expr);
virtual const char* JNIEnd(const char* expr);
virtual const char* JNIInvokeBegin(const char* expr);
virtual const char* JNIInvokeEnd(const char* expr);
/** Cast a C expression in JNI type to the proper C type.
*/
virtual const char* JNICast(const char* expr);
/** Cast a C expression in C to the JNI type.
*/
virtual const char* JNIUpCast(const char* expr);
/** Cast a C expression in C to the JNI type, without
a previous down-cast (for C++ invoking Java).
*/
virtual const char* JNIInvokeUpCast(const char* expr);
/** Cast a java expression into the private java interface type.
*/
virtual const char* JavaCast(const char* expr);
/** Cast a java expression from private interface type to public
* interface type.
*/
virtual const char* JavaUpCast(const char* expr);
/** The string to append to the method name if an operator
* is used for casting to this type
*/
virtual const char* OperatorSuffix();
/* Functions dealing with callbacks */
/** Return name of variable to use in argument list when calling
* the java callback method from native code.
*/
virtual const char* CBCast(const char* expr);
/** Return code for converting the return value from the Java
* method to a native type.
*/
virtual const char* CBUpCast(const char* expr);
/** Return code for converting from native to Java types before the
* call to the Java callback method.
*/
virtual const char* CBBegin(const char* expr);
/** Return code for cleaning up after the call to the Java
* callback method.
*/
virtual const char* CBEnd(const char* expr);
/** Return the java type id (used in forming a java method
* descriptor).
*/
virtual const char* JavaTypeID();
virtual int is_void();
virtual int is_object();
virtual const char* CTypeNamePrefix();
virtual const char* BareCTypeName();
virtual const char* CTypeNameSuffix();
long modifiers;
int indirection_count;
const char* alias; // hack for type defs
virtual void print();
virtual int writeTo(FILE* f);
static CType* readFrom(FILE* f);
protected:
CType(const CType& other) :
Token(other.comment), modifiers(other.modifiers),
indirection_count(other.indirection_count),
alias(other.alias) { }
CType(const Token& other) :
Token(other), modifiers(0L),
indirection_count(0),
alias(NULL) { }
};
#endif // __CType__