* src/cacaoh/dummy.c (package_add): New function.
[cacao.git] / src / vm / package.c
1 /* src/vm/package.c - Java boot-package functions
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 #include "config.h"
29
30 #include <stdint.h>
31
32 #include "toolbox/list.h"
33
34 #include "mm/memory.h"
35
36 #include "native/jni.h"
37
38 #include "native/include/java_lang_String.h"
39
40 #include "vm/package.h"
41 #include "vm/stringlocal.h"
42
43 #include "vmcore/options.h"
44 #include "vmcore/utf8.h"
45
46
47 /* internal property structure ************************************************/
48
49 typedef struct list_package_entry_t list_package_entry_t;
50
51 struct list_package_entry_t {
52 /*      java_string_t *packagename; */
53         utf           *packagename;
54         listnode_t     linkage;
55 };
56
57
58 /* global variables ***********************************************************/
59
60 static list_t *list_package = NULL;
61
62
63 /* package_init ****************************************************************
64
65    Initialize the package list.
66
67 *******************************************************************************/
68
69 void package_init(void)
70 {
71         /* create the properties list */
72
73         list_package = list_create(OFFSET(list_package_entry_t, linkage));
74 }
75
76
77 /* package_add *****************************************************************
78
79    Add a package to the boot-package list.
80
81    IN:
82        packagename....package name as Java string
83
84 *******************************************************************************/
85
86 /* void package_add(java_handle_t *packagename) */
87 void package_add(utf *packagename)
88 {
89 /*      java_string_t        *s; */
90         list_package_entry_t *lpe;
91
92         /* Intern the Java string to get a unique address. */
93
94 /*      s = javastring_intern(packagename); */
95
96         /* Check if the package is already stored. */
97
98         if (package_find(packagename) != NULL)
99                 return;
100
101         /* Add the package. */
102
103 #if !defined(NDEBUG)
104         if (opt_DebugPackage) {
105                 log_start();
106                 log_print("[package_add: packagename=");
107                 utf_display_printable_ascii(packagename);
108                 log_print("]");
109                 log_finish();
110         }
111 #endif
112
113         lpe = NEW(list_package_entry_t);
114
115         lpe->packagename = packagename;
116
117         list_add_last(list_package, lpe);
118 }
119
120
121 /* package_find ****************************************************************
122
123    Find a package in the list.
124
125    IN:
126        packagename....package name as Java string
127
128    OUT:
129        package name as Java string
130
131 *******************************************************************************/
132
133 /* java_handle_t *package_find(java_handle_t *packagename) */
134 utf *package_find(utf *packagename)
135 {
136 /*      java_string_t        *s; */
137         list_t               *l;
138         list_package_entry_t *lpe;
139
140         /* Intern the Java string to get a unique address. */
141
142 /*      s = javastring_intern(packagename); */
143
144         /* For convenience. */
145
146         l = list_package;
147
148         for (lpe = list_first(l); lpe != NULL; lpe = list_next(l, lpe)) {
149 /*              if (lpe->packagename == s) */
150                 if (lpe->packagename == packagename)
151                         return lpe->packagename;
152         }
153
154         return NULL;
155 }
156
157
158 /*
159  * These are local overrides for various environment variables in Emacs.
160  * Please do not remove this and leave it at the end of the file, where
161  * Emacs will automagically detect them.
162  * ---------------------------------------------------------------------
163  * Local variables:
164  * mode: c
165  * indent-tabs-mode: t
166  * c-basic-offset: 4
167  * tab-width: 4
168  * End:
169  * vim:noexpandtab:sw=4:ts=4:
170  */