1
/*
2
 * $Id$
3
 *
4
 * Copyright (C) 2003-2009 JNode.org
5
 *
6
 * This library is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation; either version 2.1 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful, but 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
14
 * License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this library; If not, write to the Free Software Foundation, Inc., 
18
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
 */
20
 
21
package org.jnode.vm;
22
23
import java.util.StringTokenizer;
24
25
public abstract class VmSystemObject implements BootableObject {
26
    /**
27
     * Mangle an identifier into a ASCII C name
28
     *
29
     * @param s
30
     * @return String
31
     */
32
    public static String mangle(String s) {
33
        final char[] src = s.toCharArray();
34
        final int cnt = s.length();
35
        final StringBuilder res = new StringBuilder(cnt);
36
        for (int i = 0; i < cnt; i++) {
37
            final char ch = src[i];
38
            if (((ch >= 'a') && (ch <= 'z'))
39
                || ((ch >= 'A') && (ch <= 'Z'))
40
                || ((ch >= '0') && (ch <= '9'))) {
41
                res.append(ch);
42
            } else {
43
                res.append(Integer.toHexString(ch));
44
            }
45
        }
46
        return InternString.internString(res.toString());
47
    }
48
49
    /**
50
     * Mangle a classname into a ASCII C name
51
     *
52
     * @param s
53
     * @return String
54
     */
55
    public static String mangleClassName(String s) {
56
        s = s.replace('/', '.');
57
        final StringTokenizer tok = new StringTokenizer(s, ".");
58
        final StringBuilder res = new StringBuilder(32);
59
        int q = tok.countTokens();
60
        res.append('Q');
61
        res.append(q);
62
        while (tok.hasMoreTokens()) {
63
            String v = tok.nextToken();
64
            res.append(v.length());
65
            res.append(v);
66
        }
67
        return InternString.internString(res.toString());
68
    }
69
70
    /**
71
     * Verify this object, just before it is written to the boot image during
72
     * the build process.
73
     */
74
    public void verifyBeforeEmit() {
75
    }
76
77
    /**
78
     * This method is called in the build process to get extra information
79
     * on this object. This extra information is added to the listing file.
80
     *
81
     * @return String
82
     */
83
    public String getExtraInfo() {
84
        return null;
85
    }
86
}