001: /*
002: * @(#)JVMDIParse.java 1.10 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.tools.jdwpgen;
028:
029: import java.util.*;
030: import java.io.*;
031:
032: class JVMDIParse {
033:
034: final StreamTokenizer izer;
035: static final int DEFINE_TOKEN = 101010;
036: static final int NAME_TOKEN = 101011;
037: int tok;
038: int prevTok = StreamTokenizer.TT_EOL;
039: String origName;
040: int value;
041:
042: JVMDIParse(Reader reader) throws IOException {
043: izer = new StreamTokenizer(new BufferedReader(reader));
044: izer.resetSyntax();
045: izer.slashStarComments(true);
046: izer.slashSlashComments(true);
047: izer.wordChars((int) 'a', (int) 'z');
048: izer.wordChars((int) 'A', (int) 'Z');
049: izer.wordChars((int) '0', (int) '9');
050: izer.wordChars((int) '_', (int) '_');
051: izer.whitespaceChars(0, 32);
052: izer.whitespaceChars((int) '(', (int) ')');
053: items();
054: }
055:
056: void items() throws IOException {
057:
058: while ((tok = izer.nextToken()) != StreamTokenizer.TT_EOF) {
059: prevTok = item();
060: }
061: if (Main.nameMap.size() == 0) {
062: error("Empty name map");
063: }
064: }
065:
066: int item() throws IOException {
067: switch (tok) {
068: case StreamTokenizer.TT_EOF:
069: error("Unexpected end-of-file");
070: return tok;
071:
072: case StreamTokenizer.TT_WORD: {
073: String word = izer.sval;
074: if (Character.isDigit(word.charAt(0))) {
075: if (prevTok != NAME_TOKEN) {
076: return tok;
077: }
078: int num;
079: try {
080: if (word.startsWith("0x")) {
081: num = Integer.parseInt(word.substring(2), 16);
082: } else {
083: num = Integer.parseInt(word);
084: }
085: } catch (NumberFormatException exc) {
086: return tok;
087: }
088: NameNode nn = new NameValueNode(origName, num);
089: Main.nameMap.put(origName, nn);
090: return tok;
091: }
092: switch (prevTok) {
093: case '#':
094: if (word.equals("define")) {
095: return DEFINE_TOKEN;
096: } else {
097: return tok;
098: }
099: case DEFINE_TOKEN: {
100: if (word.startsWith("JVMDI_")) {
101: origName = word;
102: return NAME_TOKEN;
103: }
104: return tok;
105: }
106: case NAME_TOKEN:
107: if (word.equals("jint") || word.equals("jvmdiError")) {
108: return prevTok; // ignore
109: } else {
110: return tok;
111: }
112: default:
113: return tok;
114: }
115: }
116:
117: default:
118: return tok;
119: }
120: }
121:
122: void error(String errmsg) {
123: System.err.println("JVMDI:" + izer.lineno()
124: + ": Internal Error - " + errmsg);
125: System.exit(1);
126: }
127: }
|