1 /* src/vm/package.cpp - Java boot-package functions
3 Copyright (C) 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
30 #include "toolbox/list.h"
32 #include "mm/memory.h"
34 #include "native/jni.h"
36 #include "native/include/java_lang_String.h"
38 #include "vm/package.hpp"
39 #include "vm/string.hpp"
41 #include "vmcore/options.h"
42 #include "vmcore/utf8.h"
45 /* internal property structure ************************************************/
47 typedef struct list_package_entry_t list_package_entry_t;
49 struct list_package_entry_t {
50 /* java_string_t *packagename; */
56 /* global variables ***********************************************************/
58 static list_t *list_package = NULL;
62 * Initialize the package list.
64 void Package::initialize(void)
66 TRACESUBSYSTEMINITIALIZATION("package_init");
68 /* create the properties list */
70 list_package = list_create(OFFSET(list_package_entry_t, linkage));
75 * Add a package to the boot-package list.
77 * @param packagename Package name as Java string.
79 /* void package_add(java_handle_t *packagename) */
80 void Package::add(utf *packagename)
82 /* java_string_t *s; */
83 list_package_entry_t *lpe;
85 /* Intern the Java string to get a unique address. */
87 /* s = javastring_intern(packagename); */
89 /* Check if the package is already stored. */
91 if (Package::find(packagename) != NULL)
94 /* Add the package. */
97 if (opt_DebugPackage) {
99 log_print("[package_add: packagename=");
100 utf_display_printable_ascii(packagename);
106 lpe = NEW(list_package_entry_t);
108 lpe->packagename = packagename;
110 list_add_last(list_package, lpe);
115 * Find a package in the list.
117 * @param packagename Package name as Java string.
119 * @return Package name as Java string.
121 /* java_handle_t *package_find(java_handle_t *packagename) */
122 utf* Package::find(utf *packagename)
124 /* java_string_t *s; */
126 list_package_entry_t *lpe;
128 /* Intern the Java string to get a unique address. */
130 /* s = javastring_intern(packagename); */
132 /* For convenience. */
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;
146 /* Legacy C interface *********************************************************/
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); }
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 * ---------------------------------------------------------------------
164 * indent-tabs-mode: t
168 * vim:noexpandtab:sw=4:ts=4: