jdk/make/src/classes/build/tools/jdwpgen/Parse.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 21805 c7d7946239de
child 36511 9d0388c6b336
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21805
diff changeset
     2
 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3635
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3635
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3635
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3635
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3635
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package build.tools.jdwpgen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
class Parse {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    final StreamTokenizer izer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    final Map<String, Node> kindMap = new HashMap<String, Node>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    Parse(Reader reader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        izer = new StreamTokenizer(new BufferedReader(reader));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        izer.resetSyntax();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        izer.slashStarComments(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        izer.slashSlashComments(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        izer.wordChars((int)'a', (int)'z');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        izer.wordChars((int)'A', (int)'Z');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        izer.wordChars((int)'0', (int)'9');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        izer.wordChars((int)'_', (int)'_');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        izer.wordChars((int)'-', (int)'-');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        izer.wordChars((int)'.', (int)'.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        izer.whitespaceChars(0, 32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        izer.quoteChar('"');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        izer.quoteChar('\'');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        kindMap.put("CommandSet", new CommandSetNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        kindMap.put("Command", new CommandNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        kindMap.put("Out", new OutNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        kindMap.put("Reply", new ReplyNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        kindMap.put("ErrorSet", new ErrorSetNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        kindMap.put("Error", new ErrorNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        kindMap.put("Event", new EventNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        kindMap.put("Repeat", new RepeatNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        kindMap.put("Group", new GroupNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        kindMap.put("Select", new SelectNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        kindMap.put("Alt", new AltNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        kindMap.put("ConstantSet", new ConstantSetNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        kindMap.put("Constant", new ConstantNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        kindMap.put("int", new IntTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        kindMap.put("long", new LongTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        kindMap.put("boolean", new BooleanTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        kindMap.put("object", new ObjectTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        kindMap.put("threadObject", new ThreadObjectTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        kindMap.put("threadGroupObject", new ThreadGroupObjectTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        kindMap.put("arrayObject", new ArrayObjectTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        kindMap.put("stringObject", new StringObjectTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        kindMap.put("classLoaderObject", new ClassLoaderObjectTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        kindMap.put("classObject", new ClassObjectTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        kindMap.put("referenceType", new ReferenceTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        kindMap.put("referenceTypeID", new ReferenceIDTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        kindMap.put("classType", new ClassTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        kindMap.put("interfaceType", new InterfaceTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        kindMap.put("arrayType", new ArrayTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        kindMap.put("method", new MethodTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        kindMap.put("field", new FieldTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        kindMap.put("frame", new FrameTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        kindMap.put("string", new StringTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        kindMap.put("value", new ValueTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        kindMap.put("byte", new ByteTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        kindMap.put("location", new LocationTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        kindMap.put("tagged-object", new TaggedObjectTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        kindMap.put("referenceTypeID", new ReferenceIDTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        kindMap.put("typed-sequence", new ArrayRegionTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        kindMap.put("untagged-value", new UntaggedValueTypeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    RootNode items() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        List<Node> list = new ArrayList<Node>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        while (izer.nextToken() != StreamTokenizer.TT_EOF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            izer.pushBack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            list.add(item());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        RootNode node =  new RootNode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        node.set("Root", list, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    Node item() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        switch (izer.nextToken()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            case StreamTokenizer.TT_EOF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                error("Unexpect end-of-file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            case StreamTokenizer.TT_WORD: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                String name = izer.sval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                if (izer.nextToken() == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    int ntok = izer.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    if (ntok == StreamTokenizer.TT_WORD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                        return new NameValueNode(name, izer.sval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    } else if (ntok == '\'') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                        return new NameValueNode(name, izer.sval.charAt(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                        error("Expected value after: " + name + " =");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    izer.pushBack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    return new NameNode(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            case '"':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                return new CommentNode(izer.sval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            case '(': {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                if (izer.nextToken() == StreamTokenizer.TT_WORD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    String kind = izer.sval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    List<Node> list = new ArrayList<Node>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    while (izer.nextToken() != ')') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                        izer.pushBack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                        list.add(item());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    Node proto = kindMap.get(kind);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    if (proto == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                        error("Invalid kind: " + kind);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                            Node node = (Node)proto.getClass().newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                            node.set(kind, list, izer.lineno());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                            return node;
3635
dfc746e20834 6853636: Fix warnings in jdwpgen, add jdwpgen NetBeans project
ohair
parents: 2
diff changeset
   149
                        } catch (InstantiationException exc) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                            error(exc.toString());
3635
dfc746e20834 6853636: Fix warnings in jdwpgen, add jdwpgen NetBeans project
ohair
parents: 2
diff changeset
   151
                            return null;
dfc746e20834 6853636: Fix warnings in jdwpgen, add jdwpgen NetBeans project
ohair
parents: 2
diff changeset
   152
                        } catch (IllegalAccessException exc) {
dfc746e20834 6853636: Fix warnings in jdwpgen, add jdwpgen NetBeans project
ohair
parents: 2
diff changeset
   153
                            error(exc.toString());
dfc746e20834 6853636: Fix warnings in jdwpgen, add jdwpgen NetBeans project
ohair
parents: 2
diff changeset
   154
                            return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    error("Expected kind identifier, got " + izer.ttype +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                          " : " + izer.sval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                error("Unexpected character: '" + (char)izer.ttype + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    void error(String errmsg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        System.err.println(Main.specSource + ":" + izer.lineno() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                           ": " + errmsg);
3635
dfc746e20834 6853636: Fix warnings in jdwpgen, add jdwpgen NetBeans project
ohair
parents: 2
diff changeset
   173
        throw new RuntimeException("Error: " + errmsg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
}