* src/vm/signal.c (signal_thread): Restart sigwait if it has been
[cacao.git] / src / vm / package.cpp
1 /* src/vm/package.cpp - Java boot-package functions
2
3    Copyright (C) 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <stdint.h>
29
30 #include "toolbox/list.h"
31
32 #include "mm/memory.h"
33
34 #include "native/jni.h"
35
36 #include "native/include/java_lang_String.h"
37
38 #include "vm/package.hpp"
39 #include "vm/string.hpp"
40
41 #include "vmcore/options.h"
42 #include "vmcore/utf8.h"
43
44
45 /* internal property structure ************************************************/
46
47 typedef struct list_package_entry_t list_package_entry_t;
48
49 struct list_package_entry_t {
50 /*      java_string_t *packagename; */
51         utf           *packagename;
52         listnode_t     linkage;
53 };
54
55
56 /* global variables ***********************************************************/
57
58 static list_t *list_package = NULL;
59
60
61 /**
62  * Initialize the package list.
63  */
64 void Package::initialize(void)
65 {
66         TRACESUBSYSTEMINITIALIZATION("package_init");
67
68         /* create the properties list */
69
70         list_package = list_create(OFFSET(list_package_entry_t, linkage));
71 }
72
73
74 /**
75  * Add a package to the boot-package list.
76  *
77  * @param packagename Package name as Java string.
78  */
79 /* void package_add(java_handle_t *packagename) */
80 void Package::add(utf *packagename)
81 {
82 /*      java_string_t        *s; */
83         list_package_entry_t *lpe;
84
85         /* Intern the Java string to get a unique address. */
86
87 /*      s = javastring_intern(packagename); */
88
89         /* Check if the package is already stored. */
90
91         if (Package::find(packagename) != NULL)
92                 return;
93
94         /* Add the package. */
95
96 #if !defined(NDEBUG)
97         if (opt_DebugPackage) {
98                 log_start();
99                 log_print("[package_add: packagename=");
100                 utf_display_printable_ascii(packagename);
101                 log_print("]");
102                 log_finish();
103         }
104 #endif
105
106         lpe = NEW(list_package_entry_t);
107
108         lpe->packagename = packagename;
109
110         list_add_last(list_package, lpe);
111 }
112
113
114 /**
115  * Find a package in the list.
116  *
117  * @param packagename Package name as Java string.
118  *
119  * @return Package name as Java string.
120  */
121 /* java_handle_t *package_find(java_handle_t *packagename) */
122 utf* Package::find(utf *packagename)
123 {
124 /*      java_string_t        *s; */
125         list_t               *l;
126         list_package_entry_t *lpe;
127
128         /* Intern the Java string to get a unique address. */
129
130 /*      s = javastring_intern(packagename); */
131
132         /* For convenience. */
133
134         l = list_package;
135
136         for (lpe = (list_package_entry_t*) list_first(l); lpe != NULL; lpe = (list_package_entry_t*) list_next(l, lpe)) {
137 /*              if (lpe->packagename == s) */
138                 if (lpe->packagename == packagename)
139                         return lpe->packagename;
140         }
141
142         return NULL;
143 }
144
145
146 /* Legacy C interface *********************************************************/
147
148 extern "C" {
149
150 void Package_initialize(void) { Package::initialize(); }
151 void Package_add(utf* packagename) { Package::add(packagename); }
152 utf* Package_find(utf *packagename) { return Package::find(packagename); }
153
154 }
155
156
157 /*
158  * These are local overrides for various environment variables in Emacs.
159  * Please do not remove this and leave it at the end of the file, where
160  * Emacs will automagically detect them.
161  * ---------------------------------------------------------------------
162  * Local variables:
163  * mode: c++
164  * indent-tabs-mode: t
165  * c-basic-offset: 4
166  * tab-width: 4
167  * End:
168  * vim:noexpandtab:sw=4:ts=4:
169  */