1 /*
2 * Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
265 Identifier exp[], Node val) {
266 throw new RuntimeException("defineField method is abstract");
267 }
268
269 /*
270 * A growable array of nodes. It is used as a growable
271 * buffer to hold argument lists and expression lists.
272 * I'm not using Vector to make it more efficient.
273 */
274 private Node args[] = new Node[32];
275 protected int argIndex = 0;
276
277 protected final void addArgument(Node n) {
278 if (argIndex == args.length) {
279 Node newArgs[] = new Node[args.length * 2];
280 System.arraycopy(args, 0, newArgs, 0, args.length);
281 args = newArgs;
282 }
283 args[argIndex++] = n;
284 }
285 protected final Expression exprArgs(int index)[] {
286 Expression e[] = new Expression[argIndex - index];
287 System.arraycopy(args, index, e, 0, argIndex - index);
288 argIndex = index;
289 return e;
290 }
291 protected final Statement statArgs(int index)[] {
292 Statement s[] = new Statement[argIndex - index];
293 System.arraycopy(args, index, s, 0, argIndex - index);
294 argIndex = index;
295 return s;
296 }
297
298 /**
299 * Expect a token, return its value, scan the next token or
300 * throw an exception.
301 */
302 protected void expect(int t) throws SyntaxError, IOException {
303 if (token != t) {
304 switch (t) {
305 case IDENT:
306 env.error(scanner.prevPos, "identifier.expected");
307 break;
308 default:
309 env.error(scanner.prevPos, "token.expected", opNames[t]);
310 break;
311 }
|
1 /*
2 * Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
265 Identifier exp[], Node val) {
266 throw new RuntimeException("defineField method is abstract");
267 }
268
269 /*
270 * A growable array of nodes. It is used as a growable
271 * buffer to hold argument lists and expression lists.
272 * I'm not using Vector to make it more efficient.
273 */
274 private Node args[] = new Node[32];
275 protected int argIndex = 0;
276
277 protected final void addArgument(Node n) {
278 if (argIndex == args.length) {
279 Node newArgs[] = new Node[args.length * 2];
280 System.arraycopy(args, 0, newArgs, 0, args.length);
281 args = newArgs;
282 }
283 args[argIndex++] = n;
284 }
285 protected final Expression[] exprArgs(int index) {
286 Expression e[] = new Expression[argIndex - index];
287 System.arraycopy(args, index, e, 0, argIndex - index);
288 argIndex = index;
289 return e;
290 }
291 protected final Statement[] statArgs(int index) {
292 Statement s[] = new Statement[argIndex - index];
293 System.arraycopy(args, index, s, 0, argIndex - index);
294 argIndex = index;
295 return s;
296 }
297
298 /**
299 * Expect a token, return its value, scan the next token or
300 * throw an exception.
301 */
302 protected void expect(int t) throws SyntaxError, IOException {
303 if (token != t) {
304 switch (t) {
305 case IDENT:
306 env.error(scanner.prevPos, "identifier.expected");
307 break;
308 default:
309 env.error(scanner.prevPos, "token.expected", opNames[t]);
310 break;
311 }
|