Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/make/src/classes/build/tools/jdwpgen/Parse.java
32287 views
/*1* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package build.tools.jdwpgen;2627import java.util.*;28import java.io.*;2930class Parse {3132final StreamTokenizer izer;33final Map<String, Node> kindMap = new HashMap<String, Node>();3435Parse(Reader reader) {36izer = new StreamTokenizer(new BufferedReader(reader));37izer.resetSyntax();38izer.slashStarComments(true);39izer.slashSlashComments(true);40izer.wordChars((int)'a', (int)'z');41izer.wordChars((int)'A', (int)'Z');42izer.wordChars((int)'0', (int)'9');43izer.wordChars((int)'_', (int)'_');44izer.wordChars((int)'-', (int)'-');45izer.wordChars((int)'.', (int)'.');46izer.whitespaceChars(0, 32);47izer.quoteChar('"');48izer.quoteChar('\'');4950kindMap.put("CommandSet", new CommandSetNode());51kindMap.put("Command", new CommandNode());52kindMap.put("Out", new OutNode());53kindMap.put("Reply", new ReplyNode());54kindMap.put("ErrorSet", new ErrorSetNode());55kindMap.put("Error", new ErrorNode());56kindMap.put("Event", new EventNode());57kindMap.put("Repeat", new RepeatNode());58kindMap.put("Group", new GroupNode());59kindMap.put("Select", new SelectNode());60kindMap.put("Alt", new AltNode());61kindMap.put("ConstantSet", new ConstantSetNode());62kindMap.put("Constant", new ConstantNode());63kindMap.put("int", new IntTypeNode());64kindMap.put("long", new LongTypeNode());65kindMap.put("boolean", new BooleanTypeNode());66kindMap.put("object", new ObjectTypeNode());67kindMap.put("threadObject", new ThreadObjectTypeNode());68kindMap.put("threadGroupObject", new ThreadGroupObjectTypeNode());69kindMap.put("arrayObject", new ArrayObjectTypeNode());70kindMap.put("stringObject", new StringObjectTypeNode());71kindMap.put("classLoaderObject", new ClassLoaderObjectTypeNode());72kindMap.put("classObject", new ClassObjectTypeNode());73kindMap.put("referenceType", new ReferenceTypeNode());74kindMap.put("referenceTypeID", new ReferenceIDTypeNode());75kindMap.put("classType", new ClassTypeNode());76kindMap.put("interfaceType", new InterfaceTypeNode());77kindMap.put("arrayType", new ArrayTypeNode());78kindMap.put("method", new MethodTypeNode());79kindMap.put("field", new FieldTypeNode());80kindMap.put("frame", new FrameTypeNode());81kindMap.put("string", new StringTypeNode());82kindMap.put("value", new ValueTypeNode());83kindMap.put("byte", new ByteTypeNode());84kindMap.put("location", new LocationTypeNode());85kindMap.put("tagged-object", new TaggedObjectTypeNode());86kindMap.put("referenceTypeID", new ReferenceIDTypeNode());87kindMap.put("typed-sequence", new ArrayRegionTypeNode());88kindMap.put("untagged-value", new UntaggedValueTypeNode());89}9091RootNode items() throws IOException {92List<Node> list = new ArrayList<Node>();9394while (izer.nextToken() != StreamTokenizer.TT_EOF) {95izer.pushBack();96list.add(item());97}98RootNode node = new RootNode();99node.set("Root", list, 1);100return node;101}102103Node item() throws IOException {104switch (izer.nextToken()) {105case StreamTokenizer.TT_EOF:106error("Unexpect end-of-file");107return null;108109case StreamTokenizer.TT_WORD: {110String name = izer.sval;111if (izer.nextToken() == '=') {112int ntok = izer.nextToken();113if (ntok == StreamTokenizer.TT_WORD) {114return new NameValueNode(name, izer.sval);115} else if (ntok == '\'') {116return new NameValueNode(name, izer.sval.charAt(0));117} else {118error("Expected value after: " + name + " =");119return null;120}121} else {122izer.pushBack();123return new NameNode(name);124}125}126127case '"':128return new CommentNode(izer.sval);129130case '(': {131if (izer.nextToken() == StreamTokenizer.TT_WORD) {132String kind = izer.sval;133List<Node> list = new ArrayList<Node>();134135while (izer.nextToken() != ')') {136izer.pushBack();137list.add(item());138}139Node proto = kindMap.get(kind);140if (proto == null) {141error("Invalid kind: " + kind);142return null;143} else {144try {145Node node = (Node)proto.getClass().newInstance();146node.set(kind, list, izer.lineno());147return node;148} catch (InstantiationException exc) {149error(exc.toString());150return null;151} catch (IllegalAccessException exc) {152error(exc.toString());153return null;154}155}156} else {157error("Expected kind identifier, got " + izer.ttype +158" : " + izer.sval);159return null;160}161}162163default:164error("Unexpected character: '" + (char)izer.ttype + "'");165return null;166}167}168169void error(String errmsg) {170System.err.println(Main.specSource + ":" + izer.lineno() +171": " + errmsg);172throw new RuntimeException("Error: " + errmsg);173}174}175176177