2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2020-03-23 10:26:13 +01:00
|
|
|
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
2010-05-25 15:58:33 -07:00
|
|
|
* published by the Free Software Foundation. Oracle designates this
|
2007-12-01 00:00:00 +00:00
|
|
|
* particular file as subject to the "Classpath" exception as provided
|
2010-05-25 15:58:33 -07:00
|
|
|
* by Oracle in the LICENSE file that accompanied this code.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-25 15:58:33 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package build.tools.jdwpgen;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
import java.io.*;
|
2020-03-23 10:26:13 +01:00
|
|
|
import java.lang.reflect.InvocationTargetException;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
class Parse {
|
|
|
|
|
|
|
|
final StreamTokenizer izer;
|
|
|
|
final Map<String, Node> kindMap = new HashMap<String, Node>();
|
|
|
|
|
|
|
|
Parse(Reader reader) {
|
|
|
|
izer = new StreamTokenizer(new BufferedReader(reader));
|
|
|
|
izer.resetSyntax();
|
|
|
|
izer.slashStarComments(true);
|
|
|
|
izer.slashSlashComments(true);
|
|
|
|
izer.wordChars((int)'a', (int)'z');
|
|
|
|
izer.wordChars((int)'A', (int)'Z');
|
|
|
|
izer.wordChars((int)'0', (int)'9');
|
|
|
|
izer.wordChars((int)'_', (int)'_');
|
|
|
|
izer.wordChars((int)'-', (int)'-');
|
|
|
|
izer.wordChars((int)'.', (int)'.');
|
|
|
|
izer.whitespaceChars(0, 32);
|
|
|
|
izer.quoteChar('"');
|
|
|
|
izer.quoteChar('\'');
|
|
|
|
|
|
|
|
kindMap.put("CommandSet", new CommandSetNode());
|
|
|
|
kindMap.put("Command", new CommandNode());
|
|
|
|
kindMap.put("Out", new OutNode());
|
|
|
|
kindMap.put("Reply", new ReplyNode());
|
|
|
|
kindMap.put("ErrorSet", new ErrorSetNode());
|
|
|
|
kindMap.put("Error", new ErrorNode());
|
|
|
|
kindMap.put("Event", new EventNode());
|
|
|
|
kindMap.put("Repeat", new RepeatNode());
|
|
|
|
kindMap.put("Group", new GroupNode());
|
|
|
|
kindMap.put("Select", new SelectNode());
|
|
|
|
kindMap.put("Alt", new AltNode());
|
|
|
|
kindMap.put("ConstantSet", new ConstantSetNode());
|
|
|
|
kindMap.put("Constant", new ConstantNode());
|
|
|
|
kindMap.put("int", new IntTypeNode());
|
|
|
|
kindMap.put("long", new LongTypeNode());
|
|
|
|
kindMap.put("boolean", new BooleanTypeNode());
|
|
|
|
kindMap.put("object", new ObjectTypeNode());
|
|
|
|
kindMap.put("threadObject", new ThreadObjectTypeNode());
|
|
|
|
kindMap.put("threadGroupObject", new ThreadGroupObjectTypeNode());
|
|
|
|
kindMap.put("arrayObject", new ArrayObjectTypeNode());
|
|
|
|
kindMap.put("stringObject", new StringObjectTypeNode());
|
|
|
|
kindMap.put("classLoaderObject", new ClassLoaderObjectTypeNode());
|
|
|
|
kindMap.put("classObject", new ClassObjectTypeNode());
|
|
|
|
kindMap.put("referenceType", new ReferenceTypeNode());
|
|
|
|
kindMap.put("referenceTypeID", new ReferenceIDTypeNode());
|
|
|
|
kindMap.put("classType", new ClassTypeNode());
|
|
|
|
kindMap.put("interfaceType", new InterfaceTypeNode());
|
|
|
|
kindMap.put("arrayType", new ArrayTypeNode());
|
|
|
|
kindMap.put("method", new MethodTypeNode());
|
|
|
|
kindMap.put("field", new FieldTypeNode());
|
|
|
|
kindMap.put("frame", new FrameTypeNode());
|
|
|
|
kindMap.put("string", new StringTypeNode());
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Co-authored-by: Alexandr Scherbatiy <alexandr.scherbatiy@oracle.com>
Co-authored-by: Amy Lu <amy.lu@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Daniel Fuchs <daniel.fuchs@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Jaroslav Bachorik <jaroslav.bachorik@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Miroslav Kos <miroslav.kos@oracle.com>
Co-authored-by: Huaming Li <huaming.li@oracle.com>
Co-authored-by: Sean Mullan <sean.mullan@oracle.com>
Co-authored-by: Naoto Sato <naoto.sato@oracle.com>
Co-authored-by: Masayoshi Okutsu <masayoshi.okutsu@oracle.com>
Co-authored-by: Peter Levart <peter.levart@gmail.com>
Co-authored-by: Philip Race <philip.race@oracle.com>
Co-authored-by: Claes Redestad <claes.redestad@oracle.com>
Co-authored-by: Sergey Bylokhov <sergey.bylokhov@oracle.com>
Co-authored-by: Alexandre Iline <alexandre.iline@oracle.com>
Co-authored-by: Volker Simonis <volker.simonis@gmail.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Stuart Marks <stuart.marks@oracle.com>
Co-authored-by: Semyon Sadetsky <semyon.sadetsky@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Co-authored-by: Valerie Peng <valerie.peng@oracle.com>
Co-authored-by: Vincent Ryan <vincent.x.ryan@oracle.com>
Co-authored-by: Weijun Wang <weijun.wang@oracle.com>
Co-authored-by: Yuri Nesterenko <yuri.nesterenko@oracle.com>
Co-authored-by: Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
Co-authored-by: Alexander Kulyakthin <alexander.kulyakhtin@oracle.com>
Co-authored-by: Felix Yang <felix.yang@oracle.com>
Co-authored-by: Andrei Eremeev <andrei.eremeev@oracle.com>
Co-authored-by: Frank Yuan <frank.yuan@oracle.com>
Co-authored-by: Sergei Pikalev <sergei.pikalev@oracle.com>
Co-authored-by: Sibabrata Sahoo <sibabrata.sahoo@oracle.com>
Co-authored-by: Tiantian Du <tiantian.du@oracle.com>
Co-authored-by: Sha Jiang <sha.jiang@oracle.com>
Reviewed-by: alanb, mchung, naoto, rriggs, psandoz, plevart, mullan, ascarpino, vinnie, prr, sherman, dfuchs, mhaupt
2016-03-17 19:04:16 +00:00
|
|
|
kindMap.put("moduleID", new ModuleTypeNode());
|
2007-12-01 00:00:00 +00:00
|
|
|
kindMap.put("value", new ValueTypeNode());
|
|
|
|
kindMap.put("byte", new ByteTypeNode());
|
|
|
|
kindMap.put("location", new LocationTypeNode());
|
|
|
|
kindMap.put("tagged-object", new TaggedObjectTypeNode());
|
|
|
|
kindMap.put("referenceTypeID", new ReferenceIDTypeNode());
|
|
|
|
kindMap.put("typed-sequence", new ArrayRegionTypeNode());
|
|
|
|
kindMap.put("untagged-value", new UntaggedValueTypeNode());
|
|
|
|
}
|
|
|
|
|
|
|
|
RootNode items() throws IOException {
|
|
|
|
List<Node> list = new ArrayList<Node>();
|
|
|
|
|
|
|
|
while (izer.nextToken() != StreamTokenizer.TT_EOF) {
|
|
|
|
izer.pushBack();
|
|
|
|
list.add(item());
|
|
|
|
}
|
|
|
|
RootNode node = new RootNode();
|
|
|
|
node.set("Root", list, 1);
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node item() throws IOException {
|
|
|
|
switch (izer.nextToken()) {
|
|
|
|
case StreamTokenizer.TT_EOF:
|
2022-04-14 19:33:28 +00:00
|
|
|
error("Unexpected end-of-file");
|
2007-12-01 00:00:00 +00:00
|
|
|
return null;
|
|
|
|
|
|
|
|
case StreamTokenizer.TT_WORD: {
|
|
|
|
String name = izer.sval;
|
|
|
|
if (izer.nextToken() == '=') {
|
|
|
|
int ntok = izer.nextToken();
|
|
|
|
if (ntok == StreamTokenizer.TT_WORD) {
|
|
|
|
return new NameValueNode(name, izer.sval);
|
|
|
|
} else if (ntok == '\'') {
|
|
|
|
return new NameValueNode(name, izer.sval.charAt(0));
|
|
|
|
} else {
|
|
|
|
error("Expected value after: " + name + " =");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
izer.pushBack();
|
|
|
|
return new NameNode(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case '"':
|
|
|
|
return new CommentNode(izer.sval);
|
|
|
|
|
|
|
|
case '(': {
|
|
|
|
if (izer.nextToken() == StreamTokenizer.TT_WORD) {
|
|
|
|
String kind = izer.sval;
|
|
|
|
List<Node> list = new ArrayList<Node>();
|
|
|
|
|
|
|
|
while (izer.nextToken() != ')') {
|
|
|
|
izer.pushBack();
|
|
|
|
list.add(item());
|
|
|
|
}
|
|
|
|
Node proto = kindMap.get(kind);
|
|
|
|
if (proto == null) {
|
|
|
|
error("Invalid kind: " + kind);
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
try {
|
2020-03-23 10:26:13 +01:00
|
|
|
Node node = (Node)proto.getClass().getDeclaredConstructor().newInstance();
|
2007-12-01 00:00:00 +00:00
|
|
|
node.set(kind, list, izer.lineno());
|
|
|
|
return node;
|
2009-08-24 09:57:30 -07:00
|
|
|
} catch (InstantiationException exc) {
|
2007-12-01 00:00:00 +00:00
|
|
|
error(exc.toString());
|
2009-08-24 09:57:30 -07:00
|
|
|
return null;
|
2020-03-23 10:26:13 +01:00
|
|
|
} catch (NoSuchMethodException exc) {
|
|
|
|
error(exc.toString());
|
|
|
|
return null;
|
|
|
|
} catch (InvocationTargetException exc) {
|
|
|
|
error(exc.toString());
|
|
|
|
return null;
|
2009-08-24 09:57:30 -07:00
|
|
|
} catch (IllegalAccessException exc) {
|
|
|
|
error(exc.toString());
|
|
|
|
return null;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error("Expected kind identifier, got " + izer.ttype +
|
|
|
|
" : " + izer.sval);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
error("Unexpected character: '" + (char)izer.ttype + "'");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void error(String errmsg) {
|
|
|
|
System.err.println(Main.specSource + ":" + izer.lineno() +
|
|
|
|
": " + errmsg);
|
2009-08-24 09:57:30 -07:00
|
|
|
throw new RuntimeException("Error: " + errmsg);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|