* Moved all files from vmcore/ to vm/.
[cacao.git] / src / vm / assertion.c
1 /* src/vm/assertion.c - assertion options
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 #include <errno.h>
30
31 #include "mm/memory.h"
32
33 #include "toolbox/list.h"
34
35 #include "vm/assertion.h"
36 #include "vm/global.h"
37 #include "vm/os.hpp"
38 #include "vm/vm.hpp"
39
40
41 /* -ea/-da options ************************************************************/
42
43 list_t  *list_assertion_names     = (list_t *)NULL;
44 int32_t  assertion_class_count    = 0;
45 int32_t  assertion_package_count  = 0;
46 bool     assertion_user_enabled   = false;
47 bool     assertion_system_enabled = false;
48
49
50 /* assertion_ea_da *************************************************************
51
52    Handle -ea:/-enableassertions: and -da:/-disableassertions: options.
53
54 *******************************************************************************/
55
56 void assertion_ea_da(const char *name, bool enabled)
57 {
58         bool              package;
59         size_t            len;
60         char             *buf;
61         assertion_name_t *item;
62         int32_t           i;
63
64         if (name == NULL) {
65                 assertion_user_enabled = enabled;
66                 return;
67         }
68
69         package = false;
70         len     = os_strlen(name);
71
72         if (name[len - 1] == '/') {
73                 return;
74         }
75
76         buf = os_strdup(name);
77
78         if (buf == NULL) {
79                 vm_abort("assertion_ea_da: strdup failed: %s", strerror(errno));
80         }
81
82         if ((len > 2) && (strcmp(name + (len - 3), "...") == 0)) {
83                 package = true;
84                 assertion_package_count += 1;
85 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
86                 buf[len - 2] = '\0';
87                 buf[len - 3] = '/';
88 #else
89                 buf[len - 3] = '\0';
90 #endif
91         }
92         else {
93                 assertion_class_count += 1;
94         }
95
96         len = os_strlen(buf);
97
98         for (i = 0; i < len; i++) {
99 #if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
100                 if (buf[i] == '.') {
101                         buf[i] = '/';
102                 }
103 #else
104                 if (buf[i] == '/') {
105                         buf[i] = '.';
106                 }
107 #endif
108         }
109
110         item          = NEW(assertion_name_t);
111         item->name    = buf;
112         item->enabled = enabled;
113         item->package = package;
114
115         if (list_assertion_names == NULL) {
116                 list_assertion_names = list_create(OFFSET(assertion_name_t, linkage));
117         }
118
119         list_add_last(list_assertion_names, item);
120 }
121
122
123 /*
124  * These are local overrides for various environment variables in Emacs.
125  * Please do not remove this and leave it at the end of the file, where
126  * Emacs will automagically detect them.
127  * ---------------------------------------------------------------------
128  * Local variables:
129  * mode: c
130  * indent-tabs-mode: t
131  * c-basic-offset: 4
132  * tab-width: 4
133  * End:
134  * vim:noexpandtab:sw=4:ts=4:
135  */