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