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