* Removed all Id tags.
[cacao.git] / src / native / llni.h
1 /* src/native/llni.h - low level native interfarce (LLNI) macros
2
3    Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25 */
26
27
28 #ifndef _LLNI_H
29 #define _LLNI_H
30
31 #include "config.h"
32
33
34 /* LLNI macros *****************************************************************
35
36    The following macros should be used whenever a Java Object is
37    accessed in native code without the use of an JNI function.
38
39    LLNI_field_set_val, LLNI_field_get_val:
40      Deal with primitive values like integer and float values. Do
41      not use these macros to access pointers or references!
42
43    LLNI_field_set_ref, LLNI_field_get_ref:
44      Deal with references to other objects.
45
46    LLNI_field_set_cls, LLNI_field_get_cls:
47      Deal with references to Java Classes which are internally
48      represented by classinfo or java_lang_Class.
49
50 *******************************************************************************/
51
52 #define LLNI_field_set_val(obj, field, value) \
53         LLNI_field_direct(obj, field) = (value)
54
55 #define LLNI_field_set_ref(obj, field, reference) \
56         LLNI_field_set_val(obj, field, reference)
57
58 #define LLNI_field_set_cls(obj, field, value) \
59         LLNI_field_direct(obj, field) = (java_lang_Class *) (value)
60
61 #define LLNI_field_get_val(obj, field, variable) \
62         (variable) = LLNI_field_direct(obj, field)
63
64 #define LLNI_field_get_ref(obj, field, variable) \
65         LLNI_field_get_val(obj, field, variable)
66
67 #define LLNI_field_get_cls(obj, field, variable) \
68         (variable) = (classinfo *) LLNI_field_direct(obj, field)
69
70 #define LLNI_class_get(obj, variable) \
71         (variable) = LLNI_field_direct(obj, header.vftbl->class)
72
73
74 /* LLNI classinfo wrapping / unwrapping macros *********************************
75
76    The following macros are used to wrap or unwrap a classinfo from
77    or into a handle (typically java_lang_Class).
78
79 *******************************************************************************/
80
81 #define LLNI_classinfo_wrap(classinfo) \
82         ((java_lang_Class *) (classinfo))
83
84 #define LLNI_classinfo_unwrap(clazz) \
85         ((classinfo *) (clazz))
86
87
88 /* XXX the direct macros have to be used inside a critical section!!! */
89
90 #define LLNI_field_direct(obj, field) ((obj)->field) 
91
92 #define LLNI_vftbl_direct(obj) (((java_handle_t *) (obj))->vftbl)
93
94 #define LLNI_array_direct(arr, index) ((arr)->data[(index)])
95
96 #define LLNI_array_data(arr) ((arr)->data)
97
98 #define LLNI_array_size(arr) ((java_array_t *) (arr))->size
99
100 /* XXX document me */
101
102 #define LLNI_objectarray_element_set(arr, index, reference) \
103         LLNI_array_direct(arr, index) = reference
104
105 #define LLNI_objectarray_element_get(arr, index, variable) \
106         (variable) = (java_handle_t *) LLNI_array_direct(arr, index)
107
108
109
110 #endif /* _LLNI_H */
111
112
113 /*
114  * These are local overrides for various environment variables in Emacs.
115  * Please do not remove this and leave it at the end of the file, where
116  * Emacs will automagically detect them.
117  * ---------------------------------------------------------------------
118  * Local variables:
119  * mode: c
120  * indent-tabs-mode: t
121  * c-basic-offset: 4
122  * tab-width: 4
123  * End:
124  */