8074671: Nashorn Parser API
Reviewed-by: darcy, forax, attila, hannesw
This commit is contained in:
parent
d6aef89288
commit
0ed9eb856c
@ -314,6 +314,15 @@ grant codeBase "file:/${basedir}/${nashorn.internal.tests.jar}" {
|
||||
permission java.security.AllPermission;
|
||||
};
|
||||
|
||||
grant codeBase "file:/${basedir}/${nashorn.api.tests.jar}" {
|
||||
permission java.util.PropertyPermission "parserapitest.*", "read";
|
||||
permission java.util.PropertyPermission "test.*", "read";
|
||||
permission java.util.PropertyPermission "test262.*", "read";
|
||||
permission java.io.FilePermission "${basedir}/test/-","read";
|
||||
permission java.io.FilePermission "$${user.dir}", "read";
|
||||
permission java.util.PropertyPermission "user.dir", "read";
|
||||
};
|
||||
|
||||
grant codeBase "file:/${basedir}/${file.reference.testng.jar}" {
|
||||
permission java.security.AllPermission;
|
||||
};
|
||||
@ -395,6 +404,7 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
|
||||
<fileset id="test.classes" dir="${build.test.classes.dir}">
|
||||
<include name="**/api/javaaccess/*Test.class"/>
|
||||
<include name="**/api/scripting/*Test.class"/>
|
||||
<include name="**/api/tree/*Test.class"/>
|
||||
<include name="**/codegen/*Test.class"/>
|
||||
<include name="**/parser/*Test.class"/>
|
||||
<include name="**/runtime/*Test.class"/>
|
||||
@ -440,7 +450,7 @@ grant codeBase "file:/${basedir}/test/script/markdown.js" {
|
||||
<delete dir="${build.dir}/nashorn_code_cache"/>
|
||||
<property name="debug.test.jvmargs" value=""/>
|
||||
<testng outputdir="${build.test.results.dir}/${testResultsSubDir}" classfilesetref="test.classes"
|
||||
verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
|
||||
verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
|
||||
<jvmarg line="${boot.class.path}"/>
|
||||
<jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
|
||||
<jvmarg line="${debug.test.jvmargs}"/>
|
||||
|
@ -155,7 +155,7 @@
|
||||
</view>
|
||||
<subprojects/>
|
||||
</general-data>
|
||||
<java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/3">
|
||||
<java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/4">
|
||||
<compilation-unit>
|
||||
<package-root>../test/src</package-root>
|
||||
<unit-tests/>
|
||||
|
@ -134,6 +134,10 @@ test-sys-prop.test.js.roots=${test.basic.dir} ${test.maptests.dir} ${test.error.
|
||||
test-sys-prop.test262.suite.dir=${test262.suite.dir}
|
||||
test-sys-prop.es5conform.testcases.dir=${test.external.dir}/ES5Conform/TestCases
|
||||
test-sys-prop.test.basic.dir=${test.basic.dir}
|
||||
test-sys-prop.test.external.dir=${test.external.dir}
|
||||
test-sys-prop.test.maptests.dir=${test.maptests.dir}
|
||||
test-sys-prop.test.sandbox.dir=${test.sandbox.dir}
|
||||
test-sys-prop.test.trusted.dir=${test.trusted.dir}
|
||||
|
||||
test-sys-prop-no-security.test.dir=${test.dir}
|
||||
test-sys-prop-no-security.test.js.roots=${test.nosecurity.dir}
|
||||
@ -147,9 +151,11 @@ test-sys-prop.parsertest.verbose=false
|
||||
|
||||
# turn on/off scripting mode for parser tests
|
||||
test-sys-prop.parsertest.scripting=true
|
||||
test-sys-prop.parserapitest.verbose=false
|
||||
|
||||
# turn on/off test262 scripts for parser tests
|
||||
test-sys-prop.parsertest.test262=false
|
||||
test-sys-prop.parserapitest.test262=false
|
||||
|
||||
# Control the verbosity of the CompilerTest
|
||||
test-sys-prop.compilertest.verbose=false
|
||||
|
58
nashorn/samples/evalcheck.js
Normal file
58
nashorn/samples/evalcheck.js
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
// Simple demo of Nashorn Parser API
|
||||
|
||||
var Parser = Java.type("jdk.nashorn.api.tree.Parser");
|
||||
var SimpleTreeVisitor = Java.type("jdk.nashorn.api.tree.SimpleTreeVisitorES5_1");
|
||||
var IdentifierTree = Java.type("jdk.nashorn.api.tree.IdentifierTree");
|
||||
|
||||
var parser = Parser.create();
|
||||
var ast = parser.parse("t", "eval('hello');\n eval(2 + 3)", print);
|
||||
// locate 'eval' calls in the script
|
||||
ast.accept(visitor = new (Java.extend(SimpleTreeVisitor)) {
|
||||
lineMap: null,
|
||||
visitCompilationUnit: function(node, extra) {
|
||||
this.lineMap = node.lineMap;
|
||||
Java.super(visitor).visitCompilationUnit(node, extra);
|
||||
},
|
||||
|
||||
visitFunctionCall: function(node, extra) {
|
||||
var func = node.functionSelect;
|
||||
if (func instanceof IdentifierTree && func.name == "eval") {
|
||||
var pos = node.startPosition;
|
||||
var line = this.lineMap.getLineNumber(pos);
|
||||
var column = this.lineMap.getColumnNumber(pos);
|
||||
print("eval call found @ " + line + ":" + column);
|
||||
}
|
||||
}
|
||||
}, null);
|
38
nashorn/samples/withcheck.js
Normal file
38
nashorn/samples/withcheck.js
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* - Neither the name of Oracle nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
// Simple demo of Nashorn Parser API
|
||||
|
||||
var Parser = Java.type("jdk.nashorn.api.tree.Parser");
|
||||
var parser = Parser.create("-strict");
|
||||
// you'll get diagnostic message for 'with'
|
||||
parser.parse("t", "with({}){}", print);
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for an array access expression.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>expression</em> [ <em>index</em> ]
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface ArrayAccessTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the array that is accessed.
|
||||
*
|
||||
* @return the array that is accessed
|
||||
*/
|
||||
ExpressionTree getExpression();
|
||||
|
||||
/**
|
||||
* Returns the index of the array element accessed.
|
||||
*
|
||||
* @return the index expression
|
||||
*/
|
||||
ExpressionTree getIndex();
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.Expression;
|
||||
|
||||
final class ArrayAccessTreeImpl extends ExpressionTreeImpl implements ArrayAccessTree {
|
||||
|
||||
private final ExpressionTree base, index;
|
||||
|
||||
ArrayAccessTreeImpl(final Expression node, final ExpressionTree base, final ExpressionTree index) {
|
||||
super(node);
|
||||
this.base = base;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree.Kind getKind() {
|
||||
return Tree.Kind.ARRAY_ACCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getExpression() {
|
||||
return base;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitArrayAccess(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents ECMAScript array literal expression.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface ArrayLiteralTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the list of Array element expressions.
|
||||
*
|
||||
* @return array element expressions
|
||||
*/
|
||||
public List<? extends ExpressionTree> getElements();
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import jdk.nashorn.internal.ir.LiteralNode;
|
||||
|
||||
final class ArrayLiteralTreeImpl extends ExpressionTreeImpl
|
||||
implements ArrayLiteralTree {
|
||||
private final List<? extends ExpressionTree> elements;
|
||||
ArrayLiteralTreeImpl(final LiteralNode<?> node, final List<? extends ExpressionTree> elements) {
|
||||
super(node);
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree.Kind getKind() {
|
||||
return Tree.Kind.ARRAY_LITERAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends ExpressionTree> getElements() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitArrayLiteral(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for an assignment expression.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>variable</em> = <em>expression</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface AssignmentTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the left hand side (LHS) of this assignment.
|
||||
*
|
||||
* @return left hand side (LHS) expression
|
||||
*/
|
||||
ExpressionTree getVariable();
|
||||
|
||||
/**
|
||||
* Returns the right hand side (RHS) of this assignment.
|
||||
*
|
||||
* @return right hand side (RHS) expression
|
||||
*/
|
||||
ExpressionTree getExpression();
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.BinaryNode;
|
||||
|
||||
final class AssignmentTreeImpl extends ExpressionTreeImpl implements AssignmentTree {
|
||||
private final Tree.Kind kind;
|
||||
private final ExpressionTree var, expr;
|
||||
|
||||
AssignmentTreeImpl(final BinaryNode node, final ExpressionTree left, final ExpressionTree right) {
|
||||
super(node);
|
||||
assert node.isAssignment() : "assignment node expected";
|
||||
this.var = left;
|
||||
this.expr = right;
|
||||
this.kind = getOperator(node.tokenType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree.Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getVariable() {
|
||||
return var;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getExpression() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitAssignment(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for a binary expression.
|
||||
* Use {@link #getKind getKind} to determine the kind of operator.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>leftOperand</em> <em>operator</em> <em>rightOperand</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface BinaryTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns left hand side (LHS) of this binary expression.
|
||||
*
|
||||
* @return left hand side (LHS) of this binary expression
|
||||
*/
|
||||
ExpressionTree getLeftOperand();
|
||||
|
||||
/**
|
||||
* Returns right hand side (RHS) of this binary expression.
|
||||
*
|
||||
* @return right hand side (RHS) of this binary expression
|
||||
*/
|
||||
ExpressionTree getRightOperand();
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.BinaryNode;
|
||||
|
||||
class BinaryTreeImpl extends ExpressionTreeImpl implements BinaryTree {
|
||||
private final Tree.Kind kind;
|
||||
private final ExpressionTree left, right;
|
||||
|
||||
BinaryTreeImpl(final BinaryNode node, final ExpressionTree left, final ExpressionTree right) {
|
||||
super(node);
|
||||
assert !node.isAssignment() : "assignment node";
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.kind = getOperator(node.tokenType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree.Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getLeftOperand() {
|
||||
return left;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getRightOperand() {
|
||||
return right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitBinary(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A tree node for a statement block.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* { }
|
||||
*
|
||||
* { <em>statements</em> }
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface BlockTree extends StatementTree {
|
||||
/**
|
||||
* Returns the list of statements in this block.
|
||||
*
|
||||
* @return the list of statements in this block
|
||||
*/
|
||||
List<? extends StatementTree> getStatements();
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import jdk.nashorn.internal.ir.Block;
|
||||
import jdk.nashorn.internal.ir.BlockStatement;
|
||||
|
||||
final class BlockTreeImpl extends StatementTreeImpl implements BlockTree {
|
||||
private final List<? extends StatementTree> statements;
|
||||
|
||||
BlockTreeImpl(final BlockStatement node, final List<? extends StatementTree> statements) {
|
||||
super(node);
|
||||
this.statements = statements;
|
||||
}
|
||||
|
||||
BlockTreeImpl(final Block node, final List<? extends StatementTree> statements) {
|
||||
super(node);
|
||||
this.statements = statements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends StatementTree> getStatements() {
|
||||
return statements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitBlock(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for a 'break' statement.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* break;
|
||||
*
|
||||
* break <em>label</em> ;
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface BreakTree extends GotoTree {
|
||||
/**
|
||||
* Label associated with this break statement. This is null
|
||||
* if there is no label associated with this break statement.
|
||||
*
|
||||
* @return label associated with this break statement.
|
||||
*/
|
||||
String getLabel();
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.BreakNode;
|
||||
import jdk.nashorn.internal.ir.IdentNode;
|
||||
|
||||
final class BreakTreeImpl extends StatementTreeImpl implements BreakTree {
|
||||
private final String label;
|
||||
|
||||
BreakTreeImpl(final BreakNode node) {
|
||||
super(node);
|
||||
this.label = node.getLabelName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree.Kind getKind() {
|
||||
return Tree.Kind.BREAK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitBreak(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A tree node for a 'case' in a 'switch' statement.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* case <em>expression</em> :
|
||||
* <em>statements</em>
|
||||
*
|
||||
* default :
|
||||
* <em>statements</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface CaseTree extends Tree {
|
||||
/**
|
||||
* Case expression of this 'case' statement.
|
||||
*
|
||||
* @return null if and only if this Case is {@code default:}
|
||||
*/
|
||||
ExpressionTree getExpression();
|
||||
|
||||
/**
|
||||
* Return the list of statements for this 'case'.
|
||||
*
|
||||
* @return list of statements for this 'case'
|
||||
*/
|
||||
List<? extends StatementTree> getStatements();
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import jdk.nashorn.internal.ir.CaseNode;
|
||||
|
||||
final class CaseTreeImpl extends TreeImpl implements CaseTree {
|
||||
private final ExpressionTree expression;
|
||||
private final List<? extends StatementTree> statements;
|
||||
|
||||
public CaseTreeImpl(final CaseNode node,
|
||||
final ExpressionTree expression,
|
||||
final List<? extends StatementTree> statements) {
|
||||
super(node);
|
||||
this.expression = expression;
|
||||
this.statements = statements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.CASE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends StatementTree> getStatements() {
|
||||
return statements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitCase(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for a 'catch' block in a 'try' statement.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* catch ( <em>parameter</em> )
|
||||
* <em>block</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface CatchTree extends Tree {
|
||||
/**
|
||||
* Returns the catch parameter identifier of the exception caught.
|
||||
*
|
||||
* @return the catch parameter identifier
|
||||
*/
|
||||
IdentifierTree getParameter();
|
||||
|
||||
/**
|
||||
* Returns the code block of this catch block.
|
||||
*
|
||||
* @return the code block
|
||||
*/
|
||||
BlockTree getBlock();
|
||||
|
||||
/**
|
||||
* Returns the optional catch condition expression. This is null
|
||||
* if this is an unconditional catch statement.
|
||||
*
|
||||
* @return the optional catch condition expression.
|
||||
*/
|
||||
ExpressionTree getCondition();
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.CatchNode;
|
||||
|
||||
final class CatchTreeImpl extends TreeImpl implements CatchTree {
|
||||
private final IdentifierTree param;
|
||||
private final BlockTree block;
|
||||
private final ExpressionTree condition;
|
||||
|
||||
CatchTreeImpl(final CatchNode node,
|
||||
final IdentifierTree param,
|
||||
final BlockTree block,
|
||||
final ExpressionTree condition) {
|
||||
super(node);
|
||||
this.param = param;
|
||||
this.block = block;
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.CATCH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierTree getParameter() {
|
||||
return param;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockTree getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitCatch(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the abstract syntax tree for compilation units (source
|
||||
* files)
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface CompilationUnitTree extends Tree {
|
||||
/**
|
||||
* Return the list of source elements in this compilation unit.
|
||||
*
|
||||
* @return the list of source elements in this compilation unit
|
||||
*/
|
||||
List<? extends Tree> getSourceElements();
|
||||
|
||||
/**
|
||||
* Return the source name of this script compilation unit.
|
||||
*
|
||||
* @return the source name of this script compilation unit
|
||||
*/
|
||||
String getSourceName();
|
||||
|
||||
/**
|
||||
* Returns if this is a ECMAScript "strict" compilation unit or not.
|
||||
*
|
||||
* @return true if this compilation unit is declared "strict"
|
||||
*/
|
||||
boolean isStrict();
|
||||
|
||||
/**
|
||||
* Returns the line map for this compilation unit, if available.
|
||||
* Returns null if the line map is not available.
|
||||
*
|
||||
* @return the line map for this compilation unit
|
||||
*/
|
||||
LineMap getLineMap();
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import jdk.nashorn.internal.ir.FunctionNode;
|
||||
|
||||
final class CompilationUnitTreeImpl extends TreeImpl
|
||||
implements CompilationUnitTree {
|
||||
private final FunctionNode funcNode;
|
||||
private final List<? extends Tree> elements;
|
||||
|
||||
CompilationUnitTreeImpl(final FunctionNode node,
|
||||
final List<? extends Tree> elements) {
|
||||
super(node);
|
||||
this.funcNode = node;
|
||||
assert funcNode.getKind() == FunctionNode.Kind.SCRIPT : "script function expected";
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree.Kind getKind() {
|
||||
return Tree.Kind.COMPILATION_UNIT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Tree> getSourceElements() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceName() {
|
||||
return funcNode.getSourceName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStrict() {
|
||||
return funcNode.isStrict();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LineMap getLineMap() {
|
||||
return new LineMapImpl(funcNode.getSource());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitCompilationUnit(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for compound assignment operator.
|
||||
* Use {@link #getKind getKind} to determine the kind of operator.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>variable</em> <em>operator</em> <em>expression</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface CompoundAssignmentTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the left hand side (LHS) of this assignment.
|
||||
*
|
||||
* @return left hand side (LHS) expression
|
||||
*/
|
||||
ExpressionTree getVariable();
|
||||
|
||||
/**
|
||||
* Returns the right hand side (RHS) of this assignment.
|
||||
*
|
||||
* @return right hand side (RHS) expression
|
||||
*/
|
||||
ExpressionTree getExpression();
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.BinaryNode;
|
||||
|
||||
final class CompoundAssignmentTreeImpl extends ExpressionTreeImpl implements CompoundAssignmentTree {
|
||||
|
||||
private final ExpressionTree var, expr;
|
||||
private final Kind kind;
|
||||
|
||||
CompoundAssignmentTreeImpl(final BinaryNode node, final ExpressionTree left, final ExpressionTree right) {
|
||||
super(node);
|
||||
assert node.isAssignment() : "not an assignment node";
|
||||
this.var = left;
|
||||
this.expr = right;
|
||||
this.kind = getOperator(node.tokenType());
|
||||
assert kind != Tree.Kind.ASSIGNMENT : "compound assignment expected";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getVariable() {
|
||||
return var;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getExpression() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitCompoundAssignment(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for the conditional operator ? :.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>condition</em> ? <em>trueExpression</em> : <em>falseExpression</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface ConditionalExpressionTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the condition expression of this ternary expression.
|
||||
*
|
||||
* @return the condition expression
|
||||
*/
|
||||
ExpressionTree getCondition();
|
||||
|
||||
/**
|
||||
* Returns the true part of this ternary expression.
|
||||
*
|
||||
* @return the 'true' part expression
|
||||
*/
|
||||
ExpressionTree getTrueExpression();
|
||||
|
||||
/**
|
||||
* Returns the false part of this ternary expression.
|
||||
*
|
||||
* @return the 'false' part expression
|
||||
*/
|
||||
ExpressionTree getFalseExpression();
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.TernaryNode;
|
||||
|
||||
final class ConditionalExpressionTreeImpl extends ExpressionTreeImpl implements ConditionalExpressionTree {
|
||||
private final ExpressionTree condExpr, trueExpr, falseExpr;
|
||||
|
||||
ConditionalExpressionTreeImpl(final TernaryNode node,
|
||||
final ExpressionTree condExpr, final ExpressionTree trueExpr,
|
||||
final ExpressionTree falseExpr) {
|
||||
super(node);
|
||||
this.condExpr = condExpr;
|
||||
this.trueExpr = trueExpr;
|
||||
this.falseExpr = falseExpr;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.CONDITIONAL_EXPRESSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getCondition() {
|
||||
return condExpr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getTrueExpression() {
|
||||
return trueExpr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getFalseExpression() {
|
||||
return falseExpr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitConditionalExpression(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A mixin for conditional "loop" statements.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface ConditionalLoopTree extends LoopTree {
|
||||
/**
|
||||
* Returns the condition expression of this 'loop' statement.
|
||||
*
|
||||
* @return the condition expression
|
||||
*/
|
||||
ExpressionTree getCondition();
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for a 'continue' statement.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* continue;
|
||||
* continue <em>label</em> ;
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface ContinueTree extends GotoTree {
|
||||
/**
|
||||
* Label associated with this continue statement. This is null
|
||||
* if there is no label associated with this continue statement.
|
||||
*
|
||||
* @return label associated with this continue statement.
|
||||
*/
|
||||
String getLabel();
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.ContinueNode;
|
||||
import jdk.nashorn.internal.ir.IdentNode;
|
||||
|
||||
final class ContinueTreeImpl extends StatementTreeImpl implements ContinueTree {
|
||||
private final String label;
|
||||
|
||||
ContinueTreeImpl(final ContinueNode node) {
|
||||
super(node);
|
||||
this.label = node.getLabelName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree.Kind getKind() {
|
||||
return Tree.Kind.CONTINUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitContinue(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for a 'debugger' statement.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>debugger;</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface DebuggerTree extends StatementTree {
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.DebuggerNode;
|
||||
|
||||
final class DebuggerTreeImpl extends StatementTreeImpl implements DebuggerTree {
|
||||
DebuggerTreeImpl(final DebuggerNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree.Kind getKind() {
|
||||
return Tree.Kind.DEBUGGER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitDebugger(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* Interface for diagnostics from tools. A diagnostic usually reports
|
||||
* a problem at a specific position in a source file. However, not
|
||||
* all diagnostics are associated with a position or a file.
|
||||
*
|
||||
* <p>A position is a zero-based character offset from the beginning of
|
||||
* a file. Negative values (except {@link #NOPOS}) are not valid
|
||||
* positions.
|
||||
*
|
||||
* <p>Line and column numbers begin at 1. Negative values (except
|
||||
* {@link #NOPOS}) and 0 are not valid line or column numbers.
|
||||
*
|
||||
* <p>Line terminator is as defined in ECMAScript specification which is one
|
||||
* of { \u000A, \u000B, \u2028, \u2029 }.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface Diagnostic {
|
||||
|
||||
/**
|
||||
* Kinds of diagnostics, for example, error or warning.
|
||||
*
|
||||
* The kind of a diagnostic can be used to determine how the
|
||||
* diagnostic should be presented to the user. For example,
|
||||
* errors might be colored red or prefixed with the word "Error",
|
||||
* while warnings might be colored yellow or prefixed with the
|
||||
* word "Warning". There is no requirement that the Kind
|
||||
* should imply any inherent semantic meaning to the message
|
||||
* of the diagnostic: for example, a tool might provide an
|
||||
* option to report all warnings as errors.
|
||||
*/
|
||||
enum Kind {
|
||||
/**
|
||||
* Problem which prevents the tool's normal completion.
|
||||
*/
|
||||
ERROR,
|
||||
/**
|
||||
* Problem which does not usually prevent the tool from
|
||||
* completing normally.
|
||||
*/
|
||||
WARNING,
|
||||
/**
|
||||
* Problem similar to a warning, but is mandated by the tool's
|
||||
* specification. For example, the Java™ Language
|
||||
* Specification mandates warnings on certain
|
||||
* unchecked operations and the use of deprecated methods.
|
||||
*/
|
||||
MANDATORY_WARNING,
|
||||
/**
|
||||
* Informative message from the tool.
|
||||
*/
|
||||
NOTE,
|
||||
/**
|
||||
* Diagnostic which does not fit within the other kinds.
|
||||
*/
|
||||
OTHER,
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to signal that no position is available.
|
||||
*/
|
||||
public final static long NOPOS = -1;
|
||||
|
||||
/**
|
||||
* Gets the kind of this diagnostic, for example, error or
|
||||
* warning.
|
||||
* @return the kind of this diagnostic
|
||||
*/
|
||||
Kind getKind();
|
||||
|
||||
/**
|
||||
* Gets a character offset from the beginning of the source object
|
||||
* associated with this diagnostic that indicates the location of
|
||||
* the problem. In addition, the following must be true:
|
||||
*
|
||||
* <p>{@code getStartPostion() <= getPosition()}
|
||||
* <p>{@code getPosition() <= getEndPosition()}
|
||||
*
|
||||
* @return character offset from beginning of source; {@link
|
||||
* #NOPOS} if no location is suitable
|
||||
*/
|
||||
long getPosition();
|
||||
|
||||
/**
|
||||
* Gets the source file name.
|
||||
*
|
||||
* @return the file name or null if not available
|
||||
*/
|
||||
String getFileName();
|
||||
|
||||
/**
|
||||
* Gets the line number of the character offset returned by
|
||||
* {@linkplain #getPosition()}.
|
||||
*
|
||||
* @return a line number or {@link #NOPOS} if and only if {@link
|
||||
* #getPosition()} returns {@link #NOPOS}
|
||||
*/
|
||||
long getLineNumber();
|
||||
|
||||
/**
|
||||
* Gets the column number of the character offset returned by
|
||||
* {@linkplain #getPosition()}.
|
||||
*
|
||||
* @return a column number or {@link #NOPOS} if and only if {@link
|
||||
* #getPosition()} returns {@link #NOPOS}
|
||||
*/
|
||||
long getColumnNumber();
|
||||
|
||||
/**
|
||||
* Gets a diagnostic code indicating the type of diagnostic. The
|
||||
* code is implementation-dependent and might be {@code null}.
|
||||
*
|
||||
* @return a diagnostic code
|
||||
*/
|
||||
String getCode();
|
||||
|
||||
/**
|
||||
* Gets a message for this diagnostic.
|
||||
*
|
||||
* @return a message
|
||||
*/
|
||||
String getMessage();
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.parser.Token;
|
||||
import jdk.nashorn.internal.runtime.ParserException;
|
||||
import jdk.nashorn.internal.runtime.Source;
|
||||
|
||||
final class DiagnosticImpl implements Diagnostic {
|
||||
private final ParserException exp;
|
||||
private final Kind kind;
|
||||
|
||||
DiagnosticImpl(final ParserException exp, final Kind kind) {
|
||||
this.exp = exp;
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPosition() {
|
||||
return exp.getPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileName() {
|
||||
return exp.getFileName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLineNumber() {
|
||||
return exp.getLineNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getColumnNumber() {
|
||||
return exp.getColumnNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
final long token = exp.getToken();
|
||||
return (token < 0)? null : Token.toString(null, token, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return exp.getMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getMessage();
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* Interface for receiving diagnostics from Nashorn parser.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
@FunctionalInterface
|
||||
public interface DiagnosticListener {
|
||||
/**
|
||||
* Invoked whenever a parsing problem is found.
|
||||
*
|
||||
* @param diagnostic additional information errors, warnings detected during parsing.
|
||||
*/
|
||||
void report(Diagnostic diagnostic);
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for a 'do' statement.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* do
|
||||
* <em>statement</em>
|
||||
* while ( <em>expression</em> );
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface DoWhileLoopTree extends ConditionalLoopTree {
|
||||
/**
|
||||
* Returns the condition expression of this do-while statement.
|
||||
*
|
||||
* @return the condition expression
|
||||
*/
|
||||
ExpressionTree getCondition();
|
||||
|
||||
/**
|
||||
* The statement contained within this do-while statement.
|
||||
*
|
||||
* @return the statement
|
||||
*/
|
||||
StatementTree getStatement();
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.WhileNode;
|
||||
|
||||
final class DoWhileLoopTreeImpl extends StatementTreeImpl implements DoWhileLoopTree {
|
||||
private final ExpressionTree cond;
|
||||
private final StatementTree stat;
|
||||
|
||||
DoWhileLoopTreeImpl(final WhileNode node, final ExpressionTree cond, final StatementTree stat) {
|
||||
super(node);
|
||||
assert node.isDoWhile() : "do while expected";
|
||||
this.cond = cond;
|
||||
this.stat = stat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.DO_WHILE_LOOP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getCondition() {
|
||||
return cond;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatementTree getStatement() {
|
||||
return stat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitDoWhileLoop(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for an empty (skip) statement.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* ;
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface EmptyStatementTree extends StatementTree {}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.EmptyNode;
|
||||
|
||||
final class EmptyStatementTreeImpl extends StatementTreeImpl implements EmptyStatementTree {
|
||||
EmptyStatementTreeImpl(final EmptyNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.EMPTY_STATEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitEmptyStatement(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node to stand in for a malformed expression.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface ErroneousTree extends ExpressionTree {
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.ErrorNode;
|
||||
|
||||
final class ErroneousTreeImpl extends ExpressionTreeImpl implements ErroneousTree {
|
||||
ErroneousTreeImpl(final ErrorNode errorNode) {
|
||||
super(errorNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.ERROR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitErroneous(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for an expression statement.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>expression</em> ;
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface ExpressionStatementTree extends StatementTree {
|
||||
/**
|
||||
* Returns the expression of this expression statement.
|
||||
*
|
||||
* @return the expression
|
||||
*/
|
||||
ExpressionTree getExpression();
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.ExpressionStatement;
|
||||
|
||||
final class ExpressionStatementTreeImpl extends StatementTreeImpl implements ExpressionStatementTree {
|
||||
private final ExpressionTree expr;
|
||||
|
||||
ExpressionStatementTreeImpl(final ExpressionStatement es, final ExpressionTree expr) {
|
||||
super(es);
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.EXPRESSION_STATEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getExpression() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitExpressionStatement(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node used as the base class for the different types of
|
||||
* expressions.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface ExpressionTree extends Tree {}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.Expression;
|
||||
|
||||
abstract class ExpressionTreeImpl extends TreeImpl implements ExpressionTree {
|
||||
ExpressionTreeImpl(final Expression expr) {
|
||||
super(expr);
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for for..in statement
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* for ( <em>variable</em> in <em>expression</em> )
|
||||
* <em>statement</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface ForInLoopTree extends LoopTree {
|
||||
/**
|
||||
* The for..in left hand side expression.
|
||||
*
|
||||
* @return the left hand side expression
|
||||
*/
|
||||
ExpressionTree getVariable();
|
||||
|
||||
/**
|
||||
* The object or array being whose properties are iterated.
|
||||
*
|
||||
* @return the object or array expression being iterated
|
||||
*/
|
||||
ExpressionTree getExpression();
|
||||
|
||||
/**
|
||||
* The statement contained in this for..in statement.
|
||||
*
|
||||
* @return the statement
|
||||
*/
|
||||
StatementTree getStatement();
|
||||
|
||||
/**
|
||||
* Returns if this is a for..each..in statement or not.
|
||||
*
|
||||
* @return true if this is a for..each..in statement
|
||||
*/
|
||||
boolean isForEach();
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.ForNode;
|
||||
|
||||
final class ForInLoopTreeImpl extends StatementTreeImpl implements ForInLoopTree {
|
||||
private final ExpressionTree lhsExpr;
|
||||
private final ExpressionTree expr;
|
||||
private final StatementTree stat;
|
||||
private final boolean forEach;
|
||||
|
||||
ForInLoopTreeImpl(final ForNode node,
|
||||
final ExpressionTree lhsExpr,
|
||||
final ExpressionTree expr,
|
||||
final StatementTree stat) {
|
||||
super(node);
|
||||
assert node.isForIn() : "for ..in expected";
|
||||
this.lhsExpr = lhsExpr;
|
||||
this.expr = expr;
|
||||
this.stat = stat;
|
||||
this.forEach = node.isForEach();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.FOR_IN_LOOP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getVariable() {
|
||||
return lhsExpr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getExpression() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatementTree getStatement() {
|
||||
return stat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isForEach() {
|
||||
return forEach;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitForInLoop(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for a basic 'for' loop statement.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* for ( <em>initializer</em> ; <em>condition</em> ; <em>update</em> )
|
||||
* <em>statement</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface ForLoopTree extends ConditionalLoopTree {
|
||||
/**
|
||||
* Returns the initializer expression of this 'for' statement.
|
||||
*
|
||||
* @return the initializer expression
|
||||
*/
|
||||
ExpressionTree getInitializer();
|
||||
|
||||
/**
|
||||
* Returns the condition expression of this 'for' statement.
|
||||
*
|
||||
* @return the condition expression
|
||||
*/
|
||||
ExpressionTree getCondition();
|
||||
|
||||
/**
|
||||
* Returns the update expression of this 'for' statement.
|
||||
*
|
||||
* @return the update expression
|
||||
*/
|
||||
ExpressionTree getUpdate();
|
||||
|
||||
/**
|
||||
* Returns the statement contained in this 'for' statement.
|
||||
*
|
||||
* @return the statement
|
||||
*/
|
||||
StatementTree getStatement();
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import jdk.nashorn.internal.ir.ForNode;
|
||||
|
||||
final class ForLoopTreeImpl extends StatementTreeImpl implements ForLoopTree {
|
||||
private final ExpressionTree init;
|
||||
private final ExpressionTree cond;
|
||||
private final ExpressionTree update;
|
||||
private final StatementTree stat;
|
||||
|
||||
ForLoopTreeImpl(final ForNode node,
|
||||
final ExpressionTree init,
|
||||
final ExpressionTree cond,
|
||||
final ExpressionTree update,
|
||||
final StatementTree stat) {
|
||||
super(node);
|
||||
assert !node.isForIn() : "for statement expected";
|
||||
this.init = init;
|
||||
this.cond = cond;
|
||||
this.update = update;
|
||||
this.stat = stat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.FOR_LOOP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getInitializer() {
|
||||
return init;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getCondition() {
|
||||
return cond;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getUpdate() {
|
||||
return update;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatementTree getStatement() {
|
||||
return stat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitForLoop(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A tree node for a function call expression.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>identifier</em> ( <em>arguments</em> )
|
||||
*
|
||||
* this . <em>identifier</em> ( <em>arguments</em> )
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface FunctionCallTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the function being called.
|
||||
*
|
||||
* @return the function being called
|
||||
*/
|
||||
ExpressionTree getFunctionSelect();
|
||||
|
||||
/**
|
||||
* Returns the list of arguments being passed to this function call.
|
||||
*
|
||||
* @return the list of argument expressions
|
||||
*/
|
||||
List<? extends ExpressionTree> getArguments();
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import jdk.nashorn.internal.ir.CallNode;
|
||||
|
||||
class FunctionCallTreeImpl extends ExpressionTreeImpl implements FunctionCallTree {
|
||||
private final List<? extends ExpressionTree> arguments;
|
||||
private final ExpressionTree function;
|
||||
FunctionCallTreeImpl(final CallNode node,
|
||||
final ExpressionTree function,
|
||||
final List<? extends ExpressionTree> arguments) {
|
||||
super(node);
|
||||
this.function = function;
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.FUNCTION_INVOCATION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getFunctionSelect() {
|
||||
return function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends ExpressionTree> getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitFunctionCall(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A tree node for a function declaration.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>function</em> <em>name</em>
|
||||
* ( <em>parameters</em> )
|
||||
* <em>body</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface FunctionDeclarationTree extends StatementTree {
|
||||
/**
|
||||
* Returns the name of the function being declared.
|
||||
*
|
||||
* @return name the function declared
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Returns the parameters of this function.
|
||||
*
|
||||
* @return the list of parameters
|
||||
*/
|
||||
List<? extends ExpressionTree> getParameters();
|
||||
|
||||
/**
|
||||
* Returns the body of code of this function.
|
||||
*
|
||||
* @return the body of code
|
||||
*/
|
||||
BlockTree getBody();
|
||||
|
||||
/**
|
||||
* Is this a strict function?
|
||||
*
|
||||
* @return true if this function is strict
|
||||
*/
|
||||
boolean isStrict();
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import jdk.nashorn.internal.ir.FunctionNode;
|
||||
import jdk.nashorn.internal.ir.VarNode;
|
||||
|
||||
final class FunctionDeclarationTreeImpl extends StatementTreeImpl
|
||||
implements FunctionDeclarationTree {
|
||||
private final FunctionNode funcNode;
|
||||
private final String funcName;
|
||||
private final List<? extends ExpressionTree> params;
|
||||
private final BlockTree body;
|
||||
|
||||
FunctionDeclarationTreeImpl(final VarNode node,
|
||||
final List<? extends ExpressionTree> params,
|
||||
final BlockTree body) {
|
||||
super(node);
|
||||
assert node.getInit() instanceof FunctionNode : "function expected";
|
||||
funcNode = (FunctionNode)node.getInit();
|
||||
assert funcNode.isDeclared() : "function declaration expected";
|
||||
funcName = node.getName().getName();
|
||||
this.params = params;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.FUNCTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return funcName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends ExpressionTree> getParameters() {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockTree getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStrict() {
|
||||
return funcNode.isStrict();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitFunctionDeclaration(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A tree node for a function expression.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>var</em> func = <em>function</em>
|
||||
* ( <em>parameters</em> )
|
||||
* <em>body</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface FunctionExpressionTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the name of the function being declared.
|
||||
*
|
||||
* @return name the function declared
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Returns the parameters of this function.
|
||||
*
|
||||
* @return the list of parameters
|
||||
*/
|
||||
List<? extends ExpressionTree> getParameters();
|
||||
|
||||
/**
|
||||
* Returns the body of code of this function.
|
||||
*
|
||||
* @return the body of code
|
||||
*/
|
||||
BlockTree getBody();
|
||||
|
||||
/**
|
||||
* Is this a strict function?
|
||||
*
|
||||
* @return true if this function is strict
|
||||
*/
|
||||
boolean isStrict();
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import jdk.nashorn.internal.ir.FunctionNode;
|
||||
|
||||
final class FunctionExpressionTreeImpl extends ExpressionTreeImpl
|
||||
implements FunctionExpressionTree {
|
||||
private final FunctionNode funcNode;
|
||||
private final String funcName;
|
||||
private final List<? extends ExpressionTree> params;
|
||||
private final BlockTree body;
|
||||
|
||||
FunctionExpressionTreeImpl(final FunctionNode node,
|
||||
final List<? extends ExpressionTree> params,
|
||||
final BlockTree body) {
|
||||
super(node);
|
||||
funcNode = node;
|
||||
assert !funcNode.isDeclared() : "function expression expected";
|
||||
|
||||
final FunctionNode.Kind kind = node.getKind();
|
||||
if (node.isAnonymous() || kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) {
|
||||
funcName = null;
|
||||
} else {
|
||||
funcName = node.getIdent().getName();
|
||||
}
|
||||
|
||||
this.params = params;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree.Kind getKind() {
|
||||
return Tree.Kind.FUNCTION_EXPRESSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return funcName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends ExpressionTree> getParameters() {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockTree getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStrict() {
|
||||
return funcNode.isStrict();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitFunctionExpression(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for a statement that jumps to a target. Note that
|
||||
* ECMAScript does not support a goto statement. But, this Tree
|
||||
* type serves as a super interface for {@link BreakTree} and
|
||||
* {@link ContinueTree}.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface GotoTree extends StatementTree {
|
||||
/**
|
||||
* Label associated with this goto statement. This is null
|
||||
* if there is no label associated with this goto statement.
|
||||
*
|
||||
* @return label associated with this goto statement.
|
||||
*/
|
||||
String getLabel();
|
||||
}
|
@ -0,0 +1,517 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import jdk.nashorn.internal.ir.AccessNode;
|
||||
import jdk.nashorn.internal.ir.BinaryNode;
|
||||
import jdk.nashorn.internal.ir.Block;
|
||||
import jdk.nashorn.internal.ir.BlockStatement;
|
||||
import jdk.nashorn.internal.ir.BreakNode;
|
||||
import jdk.nashorn.internal.ir.CallNode;
|
||||
import jdk.nashorn.internal.ir.CaseNode;
|
||||
import jdk.nashorn.internal.ir.CatchNode;
|
||||
import jdk.nashorn.internal.ir.ContinueNode;
|
||||
import jdk.nashorn.internal.ir.DebuggerNode;
|
||||
import jdk.nashorn.internal.ir.EmptyNode;
|
||||
import jdk.nashorn.internal.ir.ErrorNode;
|
||||
import jdk.nashorn.internal.ir.Expression;
|
||||
import jdk.nashorn.internal.ir.ExpressionStatement;
|
||||
import jdk.nashorn.internal.ir.ForNode;
|
||||
import jdk.nashorn.internal.ir.FunctionNode;
|
||||
import jdk.nashorn.internal.ir.IdentNode;
|
||||
import jdk.nashorn.internal.ir.IfNode;
|
||||
import jdk.nashorn.internal.ir.IndexNode;
|
||||
import jdk.nashorn.internal.ir.LabelNode;
|
||||
import jdk.nashorn.internal.ir.LexicalContext;
|
||||
import jdk.nashorn.internal.ir.LiteralNode;
|
||||
import jdk.nashorn.internal.ir.Node;
|
||||
import jdk.nashorn.internal.ir.ObjectNode;
|
||||
import jdk.nashorn.internal.ir.PropertyNode;
|
||||
import jdk.nashorn.internal.ir.ReturnNode;
|
||||
import jdk.nashorn.internal.ir.RuntimeNode;
|
||||
import jdk.nashorn.internal.ir.SplitNode;
|
||||
import jdk.nashorn.internal.ir.Statement;
|
||||
import jdk.nashorn.internal.ir.SwitchNode;
|
||||
import jdk.nashorn.internal.ir.TernaryNode;
|
||||
import jdk.nashorn.internal.ir.ThrowNode;
|
||||
import jdk.nashorn.internal.ir.TryNode;
|
||||
import jdk.nashorn.internal.ir.UnaryNode;
|
||||
import jdk.nashorn.internal.ir.VarNode;
|
||||
import jdk.nashorn.internal.ir.WhileNode;
|
||||
import jdk.nashorn.internal.ir.WithNode;
|
||||
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
||||
import jdk.nashorn.internal.parser.Lexer;
|
||||
import jdk.nashorn.internal.parser.TokenType;
|
||||
|
||||
/**
|
||||
* This class translates from nashorn IR Node objects
|
||||
* to nashorn parser API Tree objects.
|
||||
*/
|
||||
final class IRTranslator extends NodeVisitor<LexicalContext> {
|
||||
|
||||
public IRTranslator() {
|
||||
super(new LexicalContext());
|
||||
}
|
||||
|
||||
// currently translated Statement
|
||||
private StatementTreeImpl curStat;
|
||||
// currently translated Expression
|
||||
private ExpressionTreeImpl curExpr;
|
||||
|
||||
// entry point for translator
|
||||
CompilationUnitTree translate(final FunctionNode node) {
|
||||
if (node == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
assert (node.getKind() == FunctionNode.Kind.SCRIPT) : "script function expected";
|
||||
|
||||
final Block body = node.getBody();
|
||||
return new CompilationUnitTreeImpl(node,
|
||||
translateStats(body != null? body.getStatements() : null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterAccessNode(final AccessNode accessNode) {
|
||||
curExpr = new MemberSelectTreeImpl(accessNode, translateExpr(accessNode.getBase()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterBlock(final Block block) {
|
||||
// FIXME: revisit this!
|
||||
if (block.isSynthetic()) {
|
||||
final int statCount = block.getStatementCount();
|
||||
switch (statCount) {
|
||||
case 0: {
|
||||
final EmptyNode emptyNode = new EmptyNode(-1, block.getToken(), block.getFinish());
|
||||
curStat = new EmptyStatementTreeImpl(emptyNode);
|
||||
return false;
|
||||
}
|
||||
case 1: {
|
||||
curStat = translateStat(block.getStatements().get(0));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
curStat = new BlockTreeImpl(block,
|
||||
translateStats(block.getStatements()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterBinaryNode(final BinaryNode binaryNode) {
|
||||
if (binaryNode.isAssignment()) {
|
||||
final ExpressionTree srcTree = translateExpr(binaryNode.getAssignmentSource());
|
||||
final ExpressionTree destTree = translateExpr(binaryNode.getAssignmentDest());
|
||||
|
||||
if (binaryNode.tokenType() == TokenType.ASSIGN) {
|
||||
curExpr = new AssignmentTreeImpl(binaryNode, destTree, srcTree);
|
||||
} else {
|
||||
curExpr = new CompoundAssignmentTreeImpl(binaryNode, destTree, srcTree);
|
||||
}
|
||||
} else {
|
||||
final ExpressionTree leftTree = translateExpr(binaryNode.lhs());
|
||||
final ExpressionTree rightTree = translateExpr(binaryNode.rhs());
|
||||
|
||||
if (binaryNode.tokenType() == TokenType.INSTANCEOF) {
|
||||
curExpr = new InstanceOfTreeImpl(binaryNode, leftTree, rightTree);
|
||||
} else {
|
||||
curExpr = new BinaryTreeImpl(binaryNode, leftTree, rightTree);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterBreakNode(final BreakNode breakNode) {
|
||||
curStat = new BreakTreeImpl(breakNode);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterCallNode(final CallNode callNode) {
|
||||
curExpr = null;
|
||||
callNode.getFunction().accept(this);
|
||||
final ExpressionTree funcTree = curExpr;
|
||||
final List<? extends ExpressionTree> argTrees = translateExprs(callNode.getArgs());
|
||||
curExpr = new FunctionCallTreeImpl(callNode, funcTree, argTrees);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterCaseNode(final CaseNode caseNode) {
|
||||
assert false : "should not reach here!";
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterCatchNode(final CatchNode catchNode) {
|
||||
assert false : "should not reach here";
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterContinueNode(final ContinueNode continueNode) {
|
||||
curStat = new ContinueTreeImpl(continueNode);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterDebuggerNode(final DebuggerNode debuggerNode) {
|
||||
curStat = new DebuggerTreeImpl(debuggerNode);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterEmptyNode(final EmptyNode emptyNode) {
|
||||
curStat = new EmptyStatementTreeImpl(emptyNode);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterErrorNode(final ErrorNode errorNode) {
|
||||
curExpr = new ErroneousTreeImpl(errorNode);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterExpressionStatement(final ExpressionStatement expressionStatement) {
|
||||
curStat = new ExpressionStatementTreeImpl(expressionStatement,
|
||||
translateExpr(expressionStatement.getExpression()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterBlockStatement(final BlockStatement blockStatement) {
|
||||
final Block block = blockStatement.getBlock();
|
||||
if (blockStatement.isSynthetic()) {
|
||||
assert block != null && block.getStatements() != null && block.getStatements().size() == 1;
|
||||
curStat = translateStat(block.getStatements().get(0));
|
||||
} else {
|
||||
curStat = new BlockTreeImpl(blockStatement,
|
||||
translateStats(block != null? block.getStatements() : null));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterForNode(final ForNode forNode) {
|
||||
if (forNode.isForIn()) {
|
||||
curStat = new ForInLoopTreeImpl(forNode,
|
||||
translateExpr(forNode.getInit()),
|
||||
translateExpr(forNode.getModify()),
|
||||
translateBlock(forNode.getBody()));
|
||||
} else {
|
||||
curStat = new ForLoopTreeImpl(forNode,
|
||||
translateExpr(forNode.getInit()),
|
||||
translateExpr(forNode.getTest()),
|
||||
translateExpr(forNode.getModify()),
|
||||
translateBlock(forNode.getBody()));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterFunctionNode(final FunctionNode functionNode) {
|
||||
assert !functionNode.isDeclared() : "should not reach here for function declaration";
|
||||
|
||||
final List<? extends ExpressionTree> paramTrees
|
||||
= translateExprs(functionNode.getParameters());
|
||||
final BlockTree blockTree = (BlockTree) translateBlock(functionNode.getBody());
|
||||
curExpr = new FunctionExpressionTreeImpl(functionNode, paramTrees, blockTree);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterIdentNode(final IdentNode identNode) {
|
||||
curExpr = new IdentifierTreeImpl(identNode);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterIfNode(final IfNode ifNode) {
|
||||
curStat = new IfTreeImpl(ifNode,
|
||||
translateExpr(ifNode.getTest()),
|
||||
translateBlock(ifNode.getPass()),
|
||||
translateBlock(ifNode.getFail()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterIndexNode(final IndexNode indexNode) {
|
||||
curExpr = new ArrayAccessTreeImpl(indexNode,
|
||||
translateExpr(indexNode.getBase()),
|
||||
translateExpr(indexNode.getIndex()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterLabelNode(final LabelNode labelNode) {
|
||||
curStat = new LabeledStatementTreeImpl(labelNode,
|
||||
translateBlock(labelNode.getBody()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterLiteralNode(final LiteralNode<?> literalNode) {
|
||||
final Object value = literalNode.getValue();
|
||||
if (value instanceof Lexer.RegexToken) {
|
||||
curExpr = new RegExpLiteralTreeImpl(literalNode);
|
||||
} else if (literalNode.isArray()) {
|
||||
final List<Expression> exprNodes = literalNode.getElementExpressions();
|
||||
final List<ExpressionTreeImpl> exprTrees = new ArrayList<>(exprNodes.size());
|
||||
for (final Node node : exprNodes) {
|
||||
if (node == null) {
|
||||
exprTrees.add(null);
|
||||
} else {
|
||||
curExpr = null;
|
||||
node.accept(this);
|
||||
assert curExpr != null : "null for " + node;
|
||||
exprTrees.add(curExpr);
|
||||
}
|
||||
}
|
||||
curExpr = new ArrayLiteralTreeImpl(literalNode, exprTrees);
|
||||
} else {
|
||||
curExpr = new LiteralTreeImpl(literalNode);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterObjectNode(final ObjectNode objectNode) {
|
||||
final List<PropertyNode> propNodes = objectNode.getElements();
|
||||
final List<PropertyTreeImpl> propTrees = new ArrayList<>(propNodes.size());
|
||||
for (final PropertyNode propNode : propNodes) {
|
||||
propTrees.add(new PropertyTreeImpl(propNode,
|
||||
translateExpr(propNode.getKey()),
|
||||
translateExpr(propNode.getValue()),
|
||||
(FunctionExpressionTree) translateExpr(propNode.getGetter()),
|
||||
(FunctionExpressionTree) translateExpr(propNode.getSetter())));
|
||||
}
|
||||
curExpr = new ObjectLiteralTreeImpl(objectNode, propTrees);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterPropertyNode(final PropertyNode propertyNode) {
|
||||
assert false : "should not reach here!";
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterReturnNode(final ReturnNode returnNode) {
|
||||
curStat = new ReturnTreeImpl(returnNode,
|
||||
translateExpr(returnNode.getExpression()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterRuntimeNode(final RuntimeNode runtimeNode) {
|
||||
assert false : "should not reach here: RuntimeNode";
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterSplitNode(final SplitNode splitNode) {
|
||||
assert false : "should not reach here!";
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterSwitchNode(final SwitchNode switchNode) {
|
||||
final List<CaseNode> caseNodes = switchNode.getCases();
|
||||
final List<CaseTreeImpl> caseTrees = new ArrayList<>(caseNodes.size());
|
||||
for (final CaseNode caseNode : caseNodes) {
|
||||
final Block body = caseNode.getBody();
|
||||
caseTrees.add(
|
||||
new CaseTreeImpl(caseNode,
|
||||
translateExpr(caseNode.getTest()),
|
||||
translateStats(body != null? body.getStatements() : null)));
|
||||
}
|
||||
|
||||
curStat = new SwitchTreeImpl(switchNode,
|
||||
translateExpr(switchNode.getExpression()),
|
||||
caseTrees);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterTernaryNode(final TernaryNode ternaryNode) {
|
||||
curExpr = new ConditionalExpressionTreeImpl(ternaryNode,
|
||||
translateExpr(ternaryNode.getTest()),
|
||||
translateExpr(ternaryNode.getTrueExpression()),
|
||||
translateExpr(ternaryNode.getFalseExpression()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterThrowNode(final ThrowNode throwNode) {
|
||||
curStat = new ThrowTreeImpl(throwNode,
|
||||
translateExpr(throwNode.getExpression()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterTryNode(final TryNode tryNode) {
|
||||
final List<? extends CatchNode> catchNodes = tryNode.getCatches();
|
||||
final List<CatchTreeImpl> catchTrees = new ArrayList<>(catchNodes.size());
|
||||
for (final CatchNode catchNode : catchNodes) {
|
||||
catchTrees.add(new CatchTreeImpl(catchNode,
|
||||
translateIdent(catchNode.getException()),
|
||||
(BlockTree) translateBlock(catchNode.getBody()),
|
||||
translateExpr(catchNode.getExceptionCondition())));
|
||||
}
|
||||
|
||||
curStat = new TryTreeImpl(tryNode,
|
||||
(BlockTree) translateBlock(tryNode.getBody()),
|
||||
catchTrees,
|
||||
(BlockTree) translateBlock(tryNode.getFinallyBody()));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterUnaryNode(final UnaryNode unaryNode) {
|
||||
if (unaryNode.tokenType() == TokenType.NEW) {
|
||||
curExpr = new NewTreeImpl(unaryNode,
|
||||
translateExpr(unaryNode.getExpression()));
|
||||
} else {
|
||||
curExpr = new UnaryTreeImpl(unaryNode,
|
||||
translateExpr(unaryNode.getExpression()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterVarNode(final VarNode varNode) {
|
||||
final Expression initNode = varNode.getInit();
|
||||
if (initNode instanceof FunctionNode && ((FunctionNode)initNode).isDeclared()) {
|
||||
final FunctionNode funcNode = (FunctionNode) initNode;
|
||||
|
||||
final List<? extends ExpressionTree> paramTrees
|
||||
= translateExprs(funcNode.getParameters());
|
||||
final BlockTree blockTree = (BlockTree) translateBlock(funcNode.getBody());
|
||||
curStat = new FunctionDeclarationTreeImpl(varNode, paramTrees, blockTree);
|
||||
} else {
|
||||
curStat = new VariableTreeImpl(varNode, translateExpr(initNode));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterWhileNode(final WhileNode whileNode) {
|
||||
final ExpressionTree condTree = translateExpr(whileNode.getTest());
|
||||
final StatementTree statTree = translateBlock(whileNode.getBody());
|
||||
|
||||
if (whileNode.isDoWhile()) {
|
||||
curStat = new DoWhileLoopTreeImpl(whileNode, condTree, statTree);
|
||||
} else {
|
||||
curStat = new WhileLoopTreeImpl(whileNode, condTree, statTree);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enterWithNode(final WithNode withNode) {
|
||||
curStat = new WithTreeImpl(withNode,
|
||||
translateExpr(withNode.getExpression()),
|
||||
translateBlock(withNode.getBody()));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private StatementTree translateBlock(final Block blockNode) {
|
||||
if (blockNode == null) {
|
||||
return null;
|
||||
}
|
||||
curStat = null;
|
||||
blockNode.accept(this);
|
||||
return curStat;
|
||||
}
|
||||
|
||||
private List<? extends StatementTree> translateStats(final List<? extends Statement> stats) {
|
||||
if (stats == null) {
|
||||
return null;
|
||||
}
|
||||
final List<StatementTreeImpl> statTrees = new ArrayList<>(stats.size());
|
||||
for (final Statement stat : stats) {
|
||||
curStat = null;
|
||||
stat.accept(this);
|
||||
assert curStat != null;
|
||||
statTrees.add(curStat);
|
||||
}
|
||||
return statTrees;
|
||||
}
|
||||
|
||||
private List<? extends ExpressionTree> translateExprs(final List<? extends Expression> exprs) {
|
||||
if (exprs == null) {
|
||||
return null;
|
||||
}
|
||||
final List<ExpressionTreeImpl> exprTrees = new ArrayList<>(exprs.size());
|
||||
for (final Expression expr : exprs) {
|
||||
curExpr = null;
|
||||
expr.accept(this);
|
||||
assert curExpr != null;
|
||||
exprTrees.add(curExpr);
|
||||
}
|
||||
return exprTrees;
|
||||
}
|
||||
|
||||
private ExpressionTreeImpl translateExpr(final Expression expr) {
|
||||
if (expr == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
curExpr = null;
|
||||
expr.accept(this);
|
||||
assert curExpr != null : "null for " + expr;
|
||||
return curExpr;
|
||||
}
|
||||
|
||||
private StatementTreeImpl translateStat(final Statement stat) {
|
||||
if (stat == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
curStat = null;
|
||||
stat.accept(this);
|
||||
assert curStat != null : "null for " + stat;
|
||||
return curStat;
|
||||
}
|
||||
|
||||
private IdentifierTree translateIdent(final IdentNode ident) {
|
||||
return new IdentifierTreeImpl(ident);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for an identifier expression.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>name</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface IdentifierTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the name of this identifier.
|
||||
*
|
||||
* @return the name of this identifier
|
||||
*/
|
||||
String getName();
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.IdentNode;
|
||||
|
||||
final class IdentifierTreeImpl extends ExpressionTreeImpl implements IdentifierTree {
|
||||
private final String name;
|
||||
|
||||
IdentifierTreeImpl(final IdentNode node) {
|
||||
super(node);
|
||||
this.name = node.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.IDENTIFIER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitIdentifier(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for an 'if' statement.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* if ( <em>condition</em> )
|
||||
* <em>thenStatement</em>
|
||||
*
|
||||
* if ( <em>condition</em> )
|
||||
* <em>thenStatement</em>
|
||||
* else
|
||||
* <em>elseStatement</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface IfTree extends StatementTree {
|
||||
/**
|
||||
* Returns the condition expression of this 'if' statement.
|
||||
*
|
||||
* @return the condition expression
|
||||
*/
|
||||
ExpressionTree getCondition();
|
||||
|
||||
/**
|
||||
* Returns the 'then' statement of this 'if' statement.
|
||||
*
|
||||
* @return the 'then' statement
|
||||
*/
|
||||
StatementTree getThenStatement();
|
||||
|
||||
/**
|
||||
* Returns the then statement of this 'if' statement.
|
||||
* null if this if statement has no else branch.
|
||||
*
|
||||
* @return the 'else' statement
|
||||
*/
|
||||
StatementTree getElseStatement();
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.IfNode;
|
||||
|
||||
final class IfTreeImpl extends StatementTreeImpl implements IfTree {
|
||||
private final ExpressionTree cond;
|
||||
private final StatementTree thenStat;
|
||||
private final StatementTree elseStat;
|
||||
IfTreeImpl(final IfNode node, final ExpressionTree cond,
|
||||
final StatementTree thenStat, final StatementTree elseStat) {
|
||||
super(node);
|
||||
this.cond = cond;
|
||||
this.thenStat = thenStat;
|
||||
this.elseStat = elseStat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.IF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getCondition() {
|
||||
return cond;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatementTree getThenStatement() {
|
||||
return thenStat;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null if this if statement has no else branch.
|
||||
*/
|
||||
@Override
|
||||
public StatementTree getElseStatement() {
|
||||
return elseStat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitIf(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for an 'instanceof' expression.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>expression</em> instanceof <em>type</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface InstanceOfTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the expression whose type is being checked.
|
||||
*
|
||||
* @return the expression whose type is being checked
|
||||
*/
|
||||
ExpressionTree getExpression();
|
||||
|
||||
/**
|
||||
* Returns the type expression.
|
||||
*
|
||||
* @return the type expression
|
||||
*/
|
||||
Tree getType();
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.BinaryNode;
|
||||
import jdk.nashorn.internal.parser.TokenType;
|
||||
|
||||
final class InstanceOfTreeImpl extends BinaryTreeImpl implements InstanceOfTree {
|
||||
InstanceOfTreeImpl(final BinaryNode node,
|
||||
final ExpressionTree expr,
|
||||
final ExpressionTree type) {
|
||||
super(node, expr, type);
|
||||
assert node.tokenType() == TokenType.INSTANCEOF : "instanceof expected";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.INSTANCE_OF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getExpression() {
|
||||
return getLeftOperand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree getType() {
|
||||
return getRightOperand();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitInstanceOf(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for a labeled statement.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>label</em> : <em>statement</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface LabeledStatementTree extends StatementTree {
|
||||
/**
|
||||
* Returns the label associated with this statement.
|
||||
*
|
||||
* @return the label
|
||||
*/
|
||||
String getLabel();
|
||||
|
||||
/**
|
||||
* Returns the statement being labeled.
|
||||
*
|
||||
* @return the statement labeled
|
||||
*/
|
||||
StatementTree getStatement();
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.LabelNode;
|
||||
|
||||
final class LabeledStatementTreeImpl extends StatementTreeImpl
|
||||
implements LabeledStatementTree {
|
||||
private final String name;
|
||||
private final StatementTree stat;
|
||||
|
||||
LabeledStatementTreeImpl(final LabelNode node, final StatementTree stat) {
|
||||
super(node);
|
||||
this.name = node.getLabelName();
|
||||
this.stat = stat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.LABELED_STATEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatementTree getStatement() {
|
||||
return stat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitLabeledStatement(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* Provides methods to convert between character positions and line numbers
|
||||
* for a compilation unit.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface LineMap {
|
||||
/**
|
||||
* Find the line containing a position; a line termination
|
||||
* character is on the line it terminates.
|
||||
*
|
||||
* @param pos character offset of the position
|
||||
* @return the line number of pos (first line is 1)
|
||||
*/
|
||||
long getLineNumber(long pos);
|
||||
|
||||
/**
|
||||
* Find the column for a character position.
|
||||
* Tab characters preceding the position on the same line
|
||||
* will be expanded when calculating the column number.
|
||||
*
|
||||
* @param pos character offset of the position
|
||||
* @return the tab-expanded column number of pos (first column is 1)
|
||||
*/
|
||||
long getColumnNumber(long pos);
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.runtime.Source;
|
||||
|
||||
final class LineMapImpl implements LineMap {
|
||||
private final Source source;
|
||||
|
||||
LineMapImpl(final Source source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLineNumber(long pos) {
|
||||
return source.getLine((int)pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getColumnNumber(long pos) {
|
||||
return source.getColumn((int)pos);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for a literal expression.
|
||||
* Use {@link #getKind getKind} to determine the kind of literal.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>value</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface LiteralTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the value of this literal.
|
||||
*
|
||||
* @return the value of this literal
|
||||
*/
|
||||
Object getValue();
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.LiteralNode;
|
||||
|
||||
final class LiteralTreeImpl extends ExpressionTreeImpl implements LiteralTree {
|
||||
private final Object value;
|
||||
private final Kind kind;
|
||||
LiteralTreeImpl(final LiteralNode<?> node) {
|
||||
super(node);
|
||||
this.kind = literalKind(node);
|
||||
this.value = node.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
private static Kind literalKind(final LiteralNode<?> node) {
|
||||
if (node.isBoolean()) {
|
||||
return Kind.BOOLEAN_LITERAL;
|
||||
} else if (node.isNumeric()) {
|
||||
return Kind.NUMBER_LITERAL;
|
||||
} else if (node.isString()) {
|
||||
return Kind.STRING_LITERAL;
|
||||
} else if (node.isNull()) {
|
||||
return Kind.NULL_LITERAL;
|
||||
} else {
|
||||
throw new AssertionError("should not reach here: " + node.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitLiteral(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A mixin for "loop" statements.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface LoopTree extends StatementTree {
|
||||
/**
|
||||
* Returns the statement contained in this 'loop' statement.
|
||||
*
|
||||
* @return the statement
|
||||
*/
|
||||
StatementTree getStatement();
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for a member access expression.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>expression</em> . <em>identifier</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface MemberSelectTree extends ExpressionTree {
|
||||
/**
|
||||
* The object expression whose member is being selected.
|
||||
*
|
||||
* @return the object whose member is selected
|
||||
*/
|
||||
ExpressionTree getExpression();
|
||||
|
||||
/**
|
||||
* Returns the name of the property.
|
||||
*
|
||||
* @return the name of the property
|
||||
*/
|
||||
String getIdentifier();
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.AccessNode;
|
||||
|
||||
final class MemberSelectTreeImpl extends ExpressionTreeImpl
|
||||
implements MemberSelectTree {
|
||||
private final String ident;
|
||||
private final ExpressionTree expr;
|
||||
MemberSelectTreeImpl(final AccessNode node, final ExpressionTree expr) {
|
||||
super(node);
|
||||
this.ident = node.getProperty();
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.MEMBER_SELECT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getExpression() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return ident;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitMemberSelect(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A tree node to declare a new instance of a class.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* new <em>identifier</em> ( )
|
||||
*
|
||||
* new <em>identifier</em> ( <em>arguments</em> )
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface NewTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the constructor expression of this 'new' expression.
|
||||
*
|
||||
* @return the constructor expression of this 'new' expression
|
||||
*/
|
||||
ExpressionTree getConstructorExpression();
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.UnaryNode;
|
||||
import jdk.nashorn.internal.parser.TokenType;
|
||||
|
||||
final class NewTreeImpl extends ExpressionTreeImpl implements NewTree {
|
||||
private final ExpressionTree constrExpr;
|
||||
|
||||
NewTreeImpl(final UnaryNode node, final ExpressionTree constrExpr) {
|
||||
super(node);
|
||||
assert (node.tokenType() == TokenType.NEW) : "new expected";
|
||||
this.constrExpr = constrExpr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.NEW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getConstructorExpression() {
|
||||
return constrExpr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(TreeVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitNew(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents ECMAScript object literal expression.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface ObjectLiteralTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the list of properties of this object literal.
|
||||
*
|
||||
* @return the list of properties of this object literal
|
||||
*/
|
||||
public List<? extends PropertyTree> getProperties();
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import jdk.nashorn.internal.ir.ObjectNode;
|
||||
|
||||
final class ObjectLiteralTreeImpl extends ExpressionTreeImpl
|
||||
implements ObjectLiteralTree {
|
||||
private final List<? extends PropertyTree> props;
|
||||
ObjectLiteralTreeImpl(final ObjectNode node, final List<? extends PropertyTree> props) {
|
||||
super(node);
|
||||
this.props = props;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.OBJECT_LITERAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends PropertyTree> getProperties() {
|
||||
return props;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitObjectLiteral(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for a parenthesized expression. Note: parentheses
|
||||
* not be preserved by the parser.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* ( <em>expression</em> )
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface ParenthesizedTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the expression within the parenthesis.
|
||||
*
|
||||
* @return the expression within the parenthesis
|
||||
*/
|
||||
ExpressionTree getExpression();
|
||||
}
|
@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import jdk.nashorn.api.scripting.NashornException;
|
||||
import jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||
|
||||
/**
|
||||
* Represents nashorn ECMAScript parser instance.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface Parser {
|
||||
/**
|
||||
* Parses the source file and returns compilation unit tree
|
||||
*
|
||||
* @param file source file to parse
|
||||
* @param listener to receive diagnostic messages from the parser. This can be null.
|
||||
* if null is passed, a NashornException is thrown on the first parse error.
|
||||
* @return compilation unit tree
|
||||
* @throws NullPointerException if file is null
|
||||
* @throws IOException if parse source read fails
|
||||
* @throws NashornException is thrown if no listener is supplied and parser encounters error
|
||||
*/
|
||||
public CompilationUnitTree parse(final File file, final DiagnosticListener listener) throws IOException, NashornException;
|
||||
|
||||
/**
|
||||
* Parses the source Path and returns compilation unit tree
|
||||
*
|
||||
* @param path source Path to parse
|
||||
* @param listener to receive diagnostic messages from the parser. This can be null.
|
||||
* if null is passed, a NashornException is thrown on the first parse error.
|
||||
* @return compilation unit tree
|
||||
* @throws NullPointerException if path is null
|
||||
* @throws IOException if parse source read fails
|
||||
* @throws NashornException is thrown if no listener is supplied and parser encounters error
|
||||
*/
|
||||
public CompilationUnitTree parse(final Path path, final DiagnosticListener listener) throws IOException, NashornException;
|
||||
|
||||
/**
|
||||
* Parses the source url and returns compilation unit tree
|
||||
*
|
||||
* @param url source file to parse
|
||||
* @param listener to receive diagnostic messages from the parser. This can be null.
|
||||
* if null is passed, a NashornException is thrown on the first parse error.
|
||||
* @return compilation unit tree
|
||||
* @throws NullPointerException if url is null
|
||||
* @throws IOException if parse source read fails
|
||||
* @throws NashornException is thrown if no listener is supplied and parser encounters error
|
||||
*/
|
||||
public CompilationUnitTree parse(final URL url, final DiagnosticListener listener) throws IOException, NashornException;
|
||||
|
||||
/**
|
||||
* Parses the readerand returns compilation unit tree
|
||||
*
|
||||
* @param name name of the source file to parse
|
||||
* @param reader from which source is read
|
||||
* @param listener to receive diagnostic messages from the parser. This can be null.
|
||||
* if null is passed, a NashornException is thrown on the first parse error.
|
||||
* @return compilation unit tree
|
||||
* @throws NullPointerException if name or reader is null
|
||||
* @throws IOException if parse source read fails
|
||||
* @throws NashornException is thrown if no listener is supplied and parser encounters error
|
||||
*/
|
||||
public CompilationUnitTree parse(final String name, Reader reader, final DiagnosticListener listener) throws IOException, NashornException;
|
||||
|
||||
/**
|
||||
* Parses the string source and returns compilation unit tree
|
||||
*
|
||||
* @param name of the source
|
||||
* @param code string source
|
||||
* @param listener to receive diagnostic messages from the parser. This can be null.
|
||||
* if null is passed, a NashornException is thrown on the first parse error.
|
||||
* @return compilation unit tree
|
||||
* @throws NullPointerException if name or code is null
|
||||
* @throws NashornException is thrown if no listener is supplied and parser encounters error
|
||||
*/
|
||||
public CompilationUnitTree parse(final String name, String code, final DiagnosticListener listener) throws NashornException;
|
||||
|
||||
/**
|
||||
* Parses the source from script object and returns compilation unit tree
|
||||
*
|
||||
* @param scriptObj script object whose script and name properties are used for script source
|
||||
* @param listener to receive diagnostic messages from the parser. This can be null.
|
||||
* if null is passed, a NashornException is thrown on the first parse error.
|
||||
* @return compilation unit tree
|
||||
* @throws NullPointerException if scriptObj is null
|
||||
* @throws NashornException is thrown if no listener is supplied and parser encounters error
|
||||
*/
|
||||
public CompilationUnitTree parse(final ScriptObjectMirror scriptObj, final DiagnosticListener listener) throws NashornException;
|
||||
|
||||
/**
|
||||
* Factory method to create a new instance of Parser.
|
||||
*
|
||||
* @param options configuration options to initialize the Parser.
|
||||
* Currently the following options are supported:
|
||||
*
|
||||
* <dl>
|
||||
* <dt>"--const-as-var"</dt><dd>treat "const" declaration as "var"</dd>
|
||||
* <dt>"-dump-on-error" or "-doe"</dt><dd>dump stack trace on error</dd>
|
||||
* <dt>"--empty-statements"</dt><dd>include empty statement nodes</dd>
|
||||
* <dt>"--no-syntax-extensions" or "-nse"</dt><dd>disable ECMAScript syntax extensions</dd>
|
||||
* <dt>"-scripting"</dt><dd>enable scripting mode extensions</dd>
|
||||
* <dt>"-strict"</dt><dd>enable ECMAScript strict mode</dd>
|
||||
* </dl>
|
||||
*
|
||||
* @throws NullPointerException if options arrry or any of it's element is null
|
||||
* @throws IllegalArgumentException on unsupported option value.
|
||||
* @return a new Parser instance.
|
||||
*/
|
||||
public static Parser create(final String... options) throws IllegalArgumentException {
|
||||
options.getClass();
|
||||
for (String opt : options) {
|
||||
switch (opt) {
|
||||
case "--const-as-var":
|
||||
case "-dump-on-error":
|
||||
case "-doe":
|
||||
case "--empty-statements":
|
||||
case "--no-syntax-extensions":
|
||||
case "-nse":
|
||||
case "-scripting":
|
||||
case "-strict":
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException(opt);
|
||||
}
|
||||
}
|
||||
|
||||
return new ParserImpl(options);
|
||||
}
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import jdk.nashorn.api.scripting.NashornException;
|
||||
import jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||
import jdk.nashorn.internal.ir.FunctionNode;
|
||||
import jdk.nashorn.internal.runtime.Context;
|
||||
import jdk.nashorn.internal.runtime.ErrorManager;
|
||||
import jdk.nashorn.internal.runtime.JSType;
|
||||
import jdk.nashorn.internal.runtime.ParserException;
|
||||
import jdk.nashorn.internal.runtime.ScriptEnvironment;
|
||||
import jdk.nashorn.internal.runtime.Source;
|
||||
import jdk.nashorn.internal.runtime.options.Options;
|
||||
|
||||
final class ParserImpl implements Parser {
|
||||
|
||||
private final ScriptEnvironment env;
|
||||
|
||||
ParserImpl(final String... args) throws IllegalArgumentException {
|
||||
Objects.requireNonNull(args);
|
||||
Options options = new Options("nashorn");
|
||||
options.process(args);
|
||||
this.env = new ScriptEnvironment(options,
|
||||
new PrintWriter(System.out), new PrintWriter(System.err));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilationUnitTree parse(final File file, final DiagnosticListener listener) throws IOException, NashornException {
|
||||
Objects.requireNonNull(file);
|
||||
final Source src = Source.sourceFor(file.getName(), file);
|
||||
return translate(makeParser(src, listener).parse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilationUnitTree parse(final Path path, final DiagnosticListener listener) throws IOException, NashornException {
|
||||
Objects.requireNonNull(path);
|
||||
final Source src = Source.sourceFor(path.toString(), path);
|
||||
return translate(makeParser(src, listener).parse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilationUnitTree parse(final URL url, final DiagnosticListener listener) throws IOException, NashornException {
|
||||
final Source src = Source.sourceFor(url.toString(), url);
|
||||
return translate(makeParser(src, listener).parse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilationUnitTree parse(final String name, final Reader reader, final DiagnosticListener listener) throws IOException, NashornException {
|
||||
Objects.requireNonNull(name);
|
||||
Objects.requireNonNull(reader);
|
||||
final Source src = Source.sourceFor(name, reader);
|
||||
return translate(makeParser(src, listener).parse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilationUnitTree parse(final String name, final String code, final DiagnosticListener listener) throws NashornException {
|
||||
final Source src = Source.sourceFor(name, code);
|
||||
return translate(makeParser(src, listener).parse());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompilationUnitTree parse(final ScriptObjectMirror scriptObj, final DiagnosticListener listener) throws NashornException {
|
||||
Objects.requireNonNull(scriptObj);
|
||||
final Map<?,?> map = scriptObj;
|
||||
if (map.containsKey("script") && map.containsKey("name")) {
|
||||
final String script = JSType.toString(map.get("script"));
|
||||
final String name = JSType.toString(map.get("name"));
|
||||
final Source src = Source.sourceFor(name, script);
|
||||
return translate(makeParser(src, listener).parse());
|
||||
} else {
|
||||
throw new IllegalArgumentException("can't find 'script' and 'name' properties");
|
||||
}
|
||||
}
|
||||
|
||||
private jdk.nashorn.internal.parser.Parser makeParser(final Source source, final DiagnosticListener listener) {
|
||||
final ErrorManager errMgr = listener != null? new ListenerErrorManager(listener) : new Context.ThrowErrorManager();
|
||||
return new jdk.nashorn.internal.parser.Parser(env, source, errMgr);
|
||||
}
|
||||
|
||||
private static class ListenerErrorManager extends ErrorManager {
|
||||
private final DiagnosticListener listener;
|
||||
|
||||
ListenerErrorManager(final DiagnosticListener listener) {
|
||||
// null check
|
||||
listener.getClass();
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(final String msg) {
|
||||
error(new ParserException(msg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(final ParserException e) {
|
||||
listener.report(new DiagnosticImpl(e, Diagnostic.Kind.ERROR));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(final String msg) {
|
||||
warning(new ParserException(msg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(final ParserException e) {
|
||||
listener.report(new DiagnosticImpl(e, Diagnostic.Kind.WARNING));
|
||||
}
|
||||
}
|
||||
|
||||
private CompilationUnitTree translate(final FunctionNode node) {
|
||||
return new IRTranslator().translate(node);
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* To represent property setting in an object literal tree.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface PropertyTree extends Tree {
|
||||
/**
|
||||
* Returns the name of this property.
|
||||
*
|
||||
* @return the name of the property
|
||||
*/
|
||||
public ExpressionTree getKey();
|
||||
|
||||
/**
|
||||
* Returns the value of this property. This is null for accessor properties.
|
||||
*
|
||||
* @return the value of the property
|
||||
*/
|
||||
public ExpressionTree getValue();
|
||||
|
||||
/**
|
||||
* Returns the setter function of this property if this
|
||||
* is an accessor property. This is null for data properties.
|
||||
*
|
||||
* @return the setter function of the property
|
||||
*/
|
||||
public FunctionExpressionTree getGetter();
|
||||
|
||||
/**
|
||||
* Returns the getter function of this property if this
|
||||
* is an accessor property. This is null for data properties.
|
||||
*
|
||||
* @return the getter function of the property
|
||||
*/
|
||||
public FunctionExpressionTree getSetter();
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.PropertyNode;
|
||||
|
||||
final class PropertyTreeImpl extends TreeImpl implements PropertyTree {
|
||||
private final ExpressionTree key;
|
||||
private final ExpressionTree value;
|
||||
private final FunctionExpressionTree getter;
|
||||
private final FunctionExpressionTree setter;
|
||||
PropertyTreeImpl(final PropertyNode node,
|
||||
final ExpressionTree key,
|
||||
final ExpressionTree value,
|
||||
final FunctionExpressionTree getter,
|
||||
final FunctionExpressionTree setter) {
|
||||
super(node);
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.getter = getter;
|
||||
this.setter = setter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.PROPERTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunctionExpressionTree getGetter() {
|
||||
return getter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunctionExpressionTree getSetter() {
|
||||
return setter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitProperty(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* Represents regular expression literal in the source code.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface RegExpLiteralTree extends Tree {
|
||||
/**
|
||||
* Regular expression pattern to match.
|
||||
*
|
||||
* @return regular expression patten
|
||||
*/
|
||||
public String getPattern();
|
||||
|
||||
/**
|
||||
* Regular expression matching options.
|
||||
*
|
||||
* @return options like "i" for ignoreCase used
|
||||
*/
|
||||
public String getOptions();
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.LiteralNode;
|
||||
import jdk.nashorn.internal.parser.Lexer;
|
||||
|
||||
final class RegExpLiteralTreeImpl extends ExpressionTreeImpl
|
||||
implements RegExpLiteralTree {
|
||||
private final String pattern;
|
||||
private final String options;
|
||||
RegExpLiteralTreeImpl(final LiteralNode<?> node) {
|
||||
super(node);
|
||||
assert node.getValue() instanceof Lexer.RegexToken : "regexp expected";
|
||||
final Lexer.RegexToken regex = (Lexer.RegexToken) node.getValue();
|
||||
this.pattern = regex.getExpression();
|
||||
this.options = regex.getOptions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.REGEXP_LITERAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOptions() {
|
||||
return options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitRegExpLiteral(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for a 'return' statement.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* return;
|
||||
* return <em>expression</em>;
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface ReturnTree extends StatementTree {
|
||||
/**
|
||||
* Returns the expression being returned. This is null if no value
|
||||
* is being returned. i.e., empty return statement.
|
||||
*
|
||||
* @return the returned expression
|
||||
*/
|
||||
ExpressionTree getExpression();
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.ReturnNode;
|
||||
|
||||
final class ReturnTreeImpl extends StatementTreeImpl implements ReturnTree {
|
||||
private final ExpressionTree expr;
|
||||
|
||||
ReturnTreeImpl(final ReturnNode returnNode, final ExpressionTree expr) {
|
||||
super(returnNode);
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree.Kind getKind() {
|
||||
return Tree.Kind.RETURN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getExpression() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitReturn(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,390 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A simple implementation of the TreeVisitor for ECMAScript edition 5.1.
|
||||
*
|
||||
* <p>The visit methods corresponding to ES 5.1 language constructs walk the
|
||||
* "components" of the given tree by calling accept method passing the
|
||||
* current visitor and the additional parameter.
|
||||
*
|
||||
* <p>For constructs introduced in later versions, {@code visitUnknown}
|
||||
* is called instead which throws {@link UnknownTreeException}.
|
||||
*
|
||||
* <p> Methods in this class may be overridden subject to their
|
||||
* general contract. Note that annotating methods in concrete
|
||||
* subclasses with {@link java.lang.Override @Override} will help
|
||||
* ensure that methods are overridden as intended.
|
||||
*
|
||||
* @param <R> the return type of this visitor's methods. Use {@link
|
||||
* Void} for visitors that do not need to return results.
|
||||
* @param <P> the type of the additional parameter to this visitor's
|
||||
* methods. Use {@code Void} for visitors that do not need an
|
||||
* additional parameter.
|
||||
*/
|
||||
public class SimpleTreeVisitorES5_1<R, P> implements TreeVisitor<R, P> {
|
||||
@Override
|
||||
public R visitAssignment(AssignmentTree node, P r) {
|
||||
node.getVariable().accept(this, r);
|
||||
node.getExpression().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitCompoundAssignment(CompoundAssignmentTree node, P r) {
|
||||
node.getVariable().accept(this, r);
|
||||
node.getExpression().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitBinary(BinaryTree node, P r) {
|
||||
node.getLeftOperand().accept(this, r);
|
||||
node.getRightOperand().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitBlock(BlockTree node, P r) {
|
||||
node.getStatements().forEach((tree) -> {
|
||||
tree.accept(this, r);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitBreak(BreakTree node, P r) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitCase(CaseTree node, P r) {
|
||||
final Tree caseVal = node.getExpression();
|
||||
if (caseVal != null) {
|
||||
caseVal.accept(this, r);
|
||||
}
|
||||
|
||||
node.getStatements().forEach((tree) -> {
|
||||
tree.accept(this, r);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitCatch(CatchTree node, P r) {
|
||||
final Tree cond = node.getCondition();
|
||||
if (cond != null) {
|
||||
cond.accept(this, r);
|
||||
}
|
||||
node.getParameter().accept(this, r);
|
||||
node.getBlock().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitConditionalExpression(ConditionalExpressionTree node, P r) {
|
||||
node.getCondition().accept(this, r);
|
||||
node.getTrueExpression().accept(this, r);
|
||||
node.getFalseExpression().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitContinue(ContinueTree node, P r) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitDebugger(DebuggerTree node, P r) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitDoWhileLoop(DoWhileLoopTree node, P r) {
|
||||
node.getStatement().accept(this, r);
|
||||
node.getCondition().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitErroneous(ErroneousTree node, P r) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitExpressionStatement(ExpressionStatementTree node, P r) {
|
||||
node.getExpression().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitForLoop(ForLoopTree node, P r) {
|
||||
final Tree init = node.getInitializer();
|
||||
if (init != null) {
|
||||
init.accept(this, r);
|
||||
}
|
||||
|
||||
final Tree cond = node.getCondition();
|
||||
if (cond != null) {
|
||||
cond.accept(this, r);
|
||||
}
|
||||
|
||||
final Tree update = node.getUpdate();
|
||||
if (update != null) {
|
||||
update.accept(this, r);
|
||||
}
|
||||
|
||||
node.getStatement().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitForInLoop(ForInLoopTree node, P r) {
|
||||
node.getVariable().accept(this, r);
|
||||
node.getExpression().accept(this, r);
|
||||
final StatementTree stat = node.getStatement();
|
||||
if (stat != null) {
|
||||
stat.accept(this, r);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitFunctionCall(FunctionCallTree node, P r) {
|
||||
node.getFunctionSelect().accept(this, r);
|
||||
node.getArguments().forEach((tree) -> {
|
||||
tree.accept(this, r);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitFunctionDeclaration(FunctionDeclarationTree node, P r) {
|
||||
node.getParameters().forEach((tree) -> {
|
||||
tree.accept(this, r);
|
||||
});
|
||||
node.getBody().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitFunctionExpression(FunctionExpressionTree node, P r) {
|
||||
node.getParameters().forEach((tree) -> {
|
||||
tree.accept(this, r);
|
||||
});
|
||||
node.getBody().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitIdentifier(IdentifierTree node, P r) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitIf(IfTree node, P r) {
|
||||
node.getCondition().accept(this, r);
|
||||
node.getThenStatement().accept(this, r);
|
||||
final Tree elseStat = node.getElseStatement();
|
||||
if (elseStat != null) {
|
||||
elseStat.accept(this, r);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitArrayAccess(ArrayAccessTree node, P r) {
|
||||
node.getExpression().accept(this, r);
|
||||
node.getIndex().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitArrayLiteral(ArrayLiteralTree node, P r) {
|
||||
node.getElements().stream().filter((tree) -> (tree != null)).forEach((tree) -> {
|
||||
tree.accept(this, r);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitLabeledStatement(LabeledStatementTree node, P r) {
|
||||
node.getStatement().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitLiteral(LiteralTree node, P r) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitParenthesized(ParenthesizedTree node, P r) {
|
||||
node.getExpression().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitReturn(ReturnTree node, P r) {
|
||||
final Tree retExpr = node.getExpression();
|
||||
if (retExpr != null) {
|
||||
retExpr.accept(this, r);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitMemberSelect(MemberSelectTree node, P r) {
|
||||
node.getExpression().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitNew(NewTree node, P r) {
|
||||
node.getConstructorExpression().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitObjectLiteral(ObjectLiteralTree node, P r) {
|
||||
node.getProperties().forEach((tree) -> {
|
||||
tree.accept(this, r);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitProperty(PropertyTree node, P r) {
|
||||
FunctionExpressionTree getter = node.getGetter();
|
||||
if (getter != null) {
|
||||
getter.accept(this, r);
|
||||
}
|
||||
ExpressionTree key = node.getKey();
|
||||
if (key != null) {
|
||||
key.accept(this, r);
|
||||
}
|
||||
|
||||
FunctionExpressionTree setter = node.getSetter();
|
||||
if (setter != null) {
|
||||
setter.accept(this, r);
|
||||
}
|
||||
|
||||
ExpressionTree value = node.getValue();
|
||||
if (value != null) {
|
||||
value.accept(this, r);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitRegExpLiteral(RegExpLiteralTree node, P r) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitEmptyStatement(EmptyStatementTree node, P r) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitSwitch(SwitchTree node, P r) {
|
||||
node.getExpression().accept(this, r);
|
||||
node.getCases().forEach((tree) -> {
|
||||
tree.accept(this, r);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitThrow(ThrowTree node, P r) {
|
||||
node.getExpression().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitCompilationUnit(CompilationUnitTree node, P r) {
|
||||
node.getSourceElements().forEach((tree) -> {
|
||||
tree.accept(this, r);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitTry(TryTree node, P r) {
|
||||
node.getBlock().accept(this, r);
|
||||
node.getCatches().forEach((tree) -> {
|
||||
tree.accept(this, r);
|
||||
});
|
||||
|
||||
final Tree finallyBlock = node.getFinallyBlock();
|
||||
if (finallyBlock != null) {
|
||||
finallyBlock.accept(this, r);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitInstanceOf(InstanceOfTree node, P r) {
|
||||
node.getType().accept(this, r);
|
||||
node.getExpression().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitUnary(UnaryTree node, P r) {
|
||||
node.getExpression().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitVariable(VariableTree node, P r) {
|
||||
if (node.getInitializer() != null) {
|
||||
node.getInitializer().accept(this, r);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitWhileLoop(WhileLoopTree node, P r) {
|
||||
node.getCondition().accept(this, r);
|
||||
node.getStatement().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitWith(WithTree node, P r) {
|
||||
node.getScope().accept(this, r);
|
||||
node.getStatement().accept(this, r);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R visitUnknown(Tree node, P r) {
|
||||
// unknown in ECMAScript 5.1 edition
|
||||
throw new UnknownTreeException(node, r);
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node used as the base class for the different kinds of
|
||||
* statements.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface StatementTree extends Tree {
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.Block;
|
||||
import jdk.nashorn.internal.ir.Statement;
|
||||
|
||||
abstract class StatementTreeImpl extends TreeImpl implements StatementTree {
|
||||
StatementTreeImpl(final Statement stat) {
|
||||
super(stat);
|
||||
}
|
||||
|
||||
StatementTreeImpl(final Block stat) {
|
||||
super(stat);
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A tree node for a 'switch' statement.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* switch ( <em>expression</em> ) {
|
||||
* <em>cases</em>
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface SwitchTree extends StatementTree {
|
||||
/**
|
||||
* Returns the expression on which this statement switches.
|
||||
*
|
||||
* @return the switch expression
|
||||
*/
|
||||
ExpressionTree getExpression();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the list of 'case' statements.
|
||||
*
|
||||
* @return the 'case' statements
|
||||
*/
|
||||
List<? extends CaseTree> getCases();
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import jdk.nashorn.internal.ir.SwitchNode;
|
||||
|
||||
final class SwitchTreeImpl extends StatementTreeImpl implements SwitchTree {
|
||||
private final ExpressionTree expr;
|
||||
private final List<? extends CaseTree> cases;
|
||||
SwitchTreeImpl(final SwitchNode node,
|
||||
final ExpressionTree expr,
|
||||
List<? extends CaseTree> cases) {
|
||||
super(node);
|
||||
this.expr = expr;
|
||||
this.cases = cases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.SWITCH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getExpression() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends CaseTree> getCases() {
|
||||
return cases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitSwitch(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for a 'throw' statement.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* throw <em>expression</em>;
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface ThrowTree extends StatementTree {
|
||||
/**
|
||||
* Returns the expression being thrown.
|
||||
*
|
||||
* @return the expression being thrown.
|
||||
*/
|
||||
ExpressionTree getExpression();
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.ThrowNode;
|
||||
|
||||
final class ThrowTreeImpl extends StatementTreeImpl implements ThrowTree {
|
||||
private final ExpressionTree expr;
|
||||
ThrowTreeImpl(final ThrowNode node, final ExpressionTree expr) {
|
||||
super(node);
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.THROW;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getExpression() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitThrow(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,599 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* Common interface for all nodes in an abstract syntax tree.
|
||||
*
|
||||
* <p><b>WARNING:</b> This interface and its sub-interfaces are
|
||||
* subject to change as the ECMAScript programming language evolves.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface Tree {
|
||||
|
||||
/**
|
||||
* Enumerates all kinds of trees.
|
||||
*/
|
||||
@jdk.Exported
|
||||
public enum Kind {
|
||||
/**
|
||||
* Used for instances of {@link ArrayAccessTree}.
|
||||
*/
|
||||
ARRAY_ACCESS(ArrayAccessTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ArrayLiteralTree}.
|
||||
*/
|
||||
ARRAY_LITERAL(ArrayLiteralTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link AssignmentTree}.
|
||||
*/
|
||||
ASSIGNMENT(AssignmentTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BlockTree}.
|
||||
*/
|
||||
BLOCK(BlockTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BreakTree}.
|
||||
*/
|
||||
BREAK(BreakTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link CaseTree}.
|
||||
*/
|
||||
CASE(CaseTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link CatchTree}.
|
||||
*/
|
||||
CATCH(CatchTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link CompilationUnitTree}.
|
||||
*/
|
||||
COMPILATION_UNIT(CompilationUnitTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ConditionalExpressionTree}.
|
||||
*/
|
||||
CONDITIONAL_EXPRESSION(ConditionalExpressionTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ContinueTree}.
|
||||
*/
|
||||
CONTINUE(ContinueTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link DoWhileLoopTree}.
|
||||
*/
|
||||
DO_WHILE_LOOP(DoWhileLoopTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link DebuggerTree}.
|
||||
*/
|
||||
DEBUGGER(DebuggerTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ForInLoopTree}.
|
||||
*/
|
||||
FOR_IN_LOOP(ForInLoopTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link FunctionExpressionTree}.
|
||||
*/
|
||||
FUNCTION_EXPRESSION(FunctionExpressionTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ErroneousTree}.
|
||||
*/
|
||||
ERROR(ErroneousTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ExpressionStatementTree}.
|
||||
*/
|
||||
EXPRESSION_STATEMENT(ExpressionStatementTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link MemberSelectTree}.
|
||||
*/
|
||||
MEMBER_SELECT(MemberSelectTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ForLoopTree}.
|
||||
*/
|
||||
FOR_LOOP(ForLoopTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link IdentifierTree}.
|
||||
*/
|
||||
IDENTIFIER(IdentifierTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link IfTree}.
|
||||
*/
|
||||
IF(IfTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link InstanceOfTree}.
|
||||
*/
|
||||
INSTANCE_OF(InstanceOfTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link LabeledStatementTree}.
|
||||
*/
|
||||
LABELED_STATEMENT(LabeledStatementTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link FunctionDeclarationTree}.
|
||||
*/
|
||||
FUNCTION(FunctionDeclarationTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link FunctionCallTree}.
|
||||
*/
|
||||
FUNCTION_INVOCATION(FunctionCallTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link NewTree}.
|
||||
*/
|
||||
NEW(NewTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ObjectLiteralTree}.
|
||||
*/
|
||||
OBJECT_LITERAL(ObjectLiteralTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ParenthesizedTree}.
|
||||
*/
|
||||
PARENTHESIZED(ParenthesizedTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link PropertyTree}.
|
||||
*/
|
||||
PROPERTY(PropertyTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link RegExpLiteralTree}.
|
||||
*/
|
||||
REGEXP_LITERAL(RegExpLiteralTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ReturnTree}.
|
||||
*/
|
||||
RETURN(ReturnTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link EmptyStatementTree}.
|
||||
*/
|
||||
EMPTY_STATEMENT(EmptyStatementTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link SwitchTree}.
|
||||
*/
|
||||
SWITCH(SwitchTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link ThrowTree}.
|
||||
*/
|
||||
THROW(ThrowTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link TryTree}.
|
||||
*/
|
||||
TRY(TryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link VariableTree}.
|
||||
*/
|
||||
VARIABLE(VariableTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link WhileLoopTree}.
|
||||
*/
|
||||
WHILE_LOOP(WhileLoopTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link WithTree}.
|
||||
*/
|
||||
WITH(WithTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link UnaryTree} representing postfix
|
||||
* increment operator {@code ++}.
|
||||
*/
|
||||
POSTFIX_INCREMENT(UnaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link UnaryTree} representing postfix
|
||||
* decrement operator {@code --}.
|
||||
*/
|
||||
POSTFIX_DECREMENT(UnaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link UnaryTree} representing prefix
|
||||
* increment operator {@code ++}.
|
||||
*/
|
||||
PREFIX_INCREMENT(UnaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link UnaryTree} representing prefix
|
||||
* decrement operator {@code --}.
|
||||
*/
|
||||
PREFIX_DECREMENT(UnaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link UnaryTree} representing unary plus
|
||||
* operator {@code +}.
|
||||
*/
|
||||
UNARY_PLUS(UnaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link UnaryTree} representing unary minus
|
||||
* operator {@code -}.
|
||||
*/
|
||||
UNARY_MINUS(UnaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link UnaryTree} representing bitwise
|
||||
* complement operator {@code ~}.
|
||||
*/
|
||||
BITWISE_COMPLEMENT(UnaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link UnaryTree} representing logical
|
||||
* complement operator {@code !}.
|
||||
*/
|
||||
LOGICAL_COMPLEMENT(UnaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link UnaryTree} representing logical
|
||||
* delete operator {@code delete}.
|
||||
*/
|
||||
DELETE(UnaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link UnaryTree} representing logical
|
||||
* typeof operator {@code typeof}.
|
||||
*/
|
||||
TYPEOF(UnaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link UnaryTree} representing logical
|
||||
* void operator {@code typeof}.
|
||||
*/
|
||||
VOID(UnaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* comma {@code ,}.
|
||||
*/
|
||||
COMMA(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* multiplication {@code *}.
|
||||
*/
|
||||
MULTIPLY(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* division {@code /}.
|
||||
*/
|
||||
DIVIDE(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* remainder {@code %}.
|
||||
*/
|
||||
REMAINDER(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* addition or string concatenation {@code +}.
|
||||
*/
|
||||
PLUS(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* subtraction {@code -}.
|
||||
*/
|
||||
MINUS(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* left shift {@code <<}.
|
||||
*/
|
||||
LEFT_SHIFT(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* right shift {@code >>}.
|
||||
*/
|
||||
RIGHT_SHIFT(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* unsigned right shift {@code >>>}.
|
||||
*/
|
||||
UNSIGNED_RIGHT_SHIFT(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* less-than {@code <}.
|
||||
*/
|
||||
LESS_THAN(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* greater-than {@code >}.
|
||||
*/
|
||||
GREATER_THAN(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* less-than-equal {@code <=}.
|
||||
*/
|
||||
LESS_THAN_EQUAL(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* greater-than-equal {@code >=}.
|
||||
*/
|
||||
GREATER_THAN_EQUAL(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* in operator {@code in}.
|
||||
*/
|
||||
IN(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* equal-to {@code ==}.
|
||||
*/
|
||||
EQUAL_TO(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* not-equal-to {@code !=}.
|
||||
*/
|
||||
NOT_EQUAL_TO(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* equal-to {@code ===}.
|
||||
*/
|
||||
STRICT_EQUAL_TO(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* not-equal-to {@code !==}.
|
||||
*/
|
||||
STRICT_NOT_EQUAL_TO(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* bitwise and logical "and" {@code &}.
|
||||
*/
|
||||
AND(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* bitwise and logical "xor" {@code ^}.
|
||||
*/
|
||||
XOR(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* bitwise and logical "or" {@code |}.
|
||||
*/
|
||||
OR(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* conditional-and {@code &&}.
|
||||
*/
|
||||
CONDITIONAL_AND(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link BinaryTree} representing
|
||||
* conditional-or {@code ||}.
|
||||
*/
|
||||
CONDITIONAL_OR(BinaryTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link CompoundAssignmentTree} representing
|
||||
* multiplication assignment {@code *=}.
|
||||
*/
|
||||
MULTIPLY_ASSIGNMENT(CompoundAssignmentTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link CompoundAssignmentTree} representing
|
||||
* division assignment {@code /=}.
|
||||
*/
|
||||
DIVIDE_ASSIGNMENT(CompoundAssignmentTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link CompoundAssignmentTree} representing
|
||||
* remainder assignment {@code %=}.
|
||||
*/
|
||||
REMAINDER_ASSIGNMENT(CompoundAssignmentTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link CompoundAssignmentTree} representing
|
||||
* addition or string concatenation assignment {@code +=}.
|
||||
*/
|
||||
PLUS_ASSIGNMENT(CompoundAssignmentTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link CompoundAssignmentTree} representing
|
||||
* subtraction assignment {@code -=}.
|
||||
*/
|
||||
MINUS_ASSIGNMENT(CompoundAssignmentTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link CompoundAssignmentTree} representing
|
||||
* left shift assignment {@code <<=}.
|
||||
*/
|
||||
LEFT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link CompoundAssignmentTree} representing
|
||||
* right shift assignment {@code >>=}.
|
||||
*/
|
||||
RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link CompoundAssignmentTree} representing
|
||||
* unsigned right shift assignment {@code >>>=}.
|
||||
*/
|
||||
UNSIGNED_RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link CompoundAssignmentTree} representing
|
||||
* bitwise and logical "and" assignment {@code &=}.
|
||||
*/
|
||||
AND_ASSIGNMENT(CompoundAssignmentTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link CompoundAssignmentTree} representing
|
||||
* bitwise and logical "xor" assignment {@code ^=}.
|
||||
*/
|
||||
XOR_ASSIGNMENT(CompoundAssignmentTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link CompoundAssignmentTree} representing
|
||||
* bitwise and logical "or" assignment {@code |=}.
|
||||
*/
|
||||
OR_ASSIGNMENT(CompoundAssignmentTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link LiteralTree} representing
|
||||
* a number literal expression of type {@code double}.
|
||||
*/
|
||||
NUMBER_LITERAL(LiteralTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link LiteralTree} representing
|
||||
* a boolean literal expression of type {@code boolean}.
|
||||
*/
|
||||
BOOLEAN_LITERAL(LiteralTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link LiteralTree} representing
|
||||
* a string literal expression of type {@link String}.
|
||||
*/
|
||||
STRING_LITERAL(LiteralTree.class),
|
||||
|
||||
/**
|
||||
* Used for instances of {@link LiteralTree} representing
|
||||
* the use of {@code null}.
|
||||
*/
|
||||
NULL_LITERAL(LiteralTree.class),
|
||||
|
||||
/**
|
||||
* An implementation-reserved node. This is the not the node
|
||||
* you are looking for.
|
||||
*/
|
||||
OTHER(null);
|
||||
|
||||
Kind(Class<? extends Tree> intf) {
|
||||
associatedInterface = intf;
|
||||
}
|
||||
|
||||
public Class<? extends Tree> asInterface() {
|
||||
return associatedInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this is a literal tree kind or not.
|
||||
*
|
||||
* @return true if this is a literal tree kind, false otherwise
|
||||
*/
|
||||
public boolean isLiteral() {
|
||||
return associatedInterface == LiteralTree.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this is an expression tree kind or not.
|
||||
*
|
||||
* @return true if this is an expression tree kind, false otherwise
|
||||
*/
|
||||
public boolean isExpression() {
|
||||
return ExpressionTree.class.isAssignableFrom(associatedInterface);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this is a statement tree kind or not.
|
||||
*
|
||||
* @return true if this is a statement tree kind, false otherwise
|
||||
*/
|
||||
public boolean isStatement() {
|
||||
return StatementTree.class.isAssignableFrom(associatedInterface);
|
||||
}
|
||||
|
||||
private final Class<? extends Tree> associatedInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start character offset of this Tree within the source.
|
||||
*
|
||||
* @return the position
|
||||
*/
|
||||
long getStartPosition();
|
||||
|
||||
/**
|
||||
* End character offset of this Tree within the source.
|
||||
*
|
||||
* @return the position
|
||||
*/
|
||||
long getEndPosition();
|
||||
|
||||
/**
|
||||
* Gets the kind of this tree.
|
||||
*
|
||||
* @return the kind of this tree.
|
||||
*/
|
||||
Kind getKind();
|
||||
|
||||
/**
|
||||
* Accept method used to implement the visitor pattern. The
|
||||
* visitor pattern is used to implement operations on trees.
|
||||
*
|
||||
* @param <R> result type of this operation.
|
||||
* @param <D> type of additional data.
|
||||
* @param visitor tree visitor
|
||||
* @param data additional data passed to visitor methods
|
||||
* @return the value from visitor's visit methods
|
||||
*/
|
||||
<R,D> R accept(TreeVisitor<R,D> visitor, D data);
|
||||
}
|
@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.Node;
|
||||
|
||||
import jdk.nashorn.internal.parser.TokenType;
|
||||
|
||||
abstract class TreeImpl implements Tree {
|
||||
protected final Node node;
|
||||
|
||||
TreeImpl(final Node node) {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStartPosition() {
|
||||
return node.getStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEndPosition() {
|
||||
return node.getFinish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitUnknown(this, data);
|
||||
}
|
||||
|
||||
static Kind getOperator(final TokenType tt) {
|
||||
switch(tt) {
|
||||
case NEW:
|
||||
return Kind.NEW;
|
||||
case NOT:
|
||||
return Kind.LOGICAL_COMPLEMENT;
|
||||
case NE:
|
||||
return Kind.NOT_EQUAL_TO;
|
||||
case NE_STRICT:
|
||||
return Kind.STRICT_NOT_EQUAL_TO;
|
||||
case MOD:
|
||||
return Kind.REMAINDER;
|
||||
case ASSIGN_MOD:
|
||||
return Kind.REMAINDER_ASSIGNMENT;
|
||||
case BIT_AND:
|
||||
return Kind.AND;
|
||||
case AND:
|
||||
return Kind.CONDITIONAL_AND;
|
||||
case ASSIGN_BIT_AND:
|
||||
return Kind.AND_ASSIGNMENT;
|
||||
case MUL:
|
||||
return Kind.MULTIPLY;
|
||||
case ASSIGN_MUL:
|
||||
return Kind.MULTIPLY_ASSIGNMENT;
|
||||
case ADD:
|
||||
return Kind.PLUS;
|
||||
case INCPREFIX:
|
||||
return Kind.PREFIX_INCREMENT;
|
||||
case INCPOSTFIX:
|
||||
return Kind.POSTFIX_INCREMENT;
|
||||
case ASSIGN_ADD:
|
||||
return Kind.PLUS_ASSIGNMENT;
|
||||
case SUB:
|
||||
return Kind.MINUS;
|
||||
case DECPREFIX:
|
||||
return Kind.PREFIX_DECREMENT;
|
||||
case DECPOSTFIX:
|
||||
return Kind.POSTFIX_DECREMENT;
|
||||
case ASSIGN_SUB:
|
||||
return Kind.MINUS_ASSIGNMENT;
|
||||
case DIV:
|
||||
return Kind.DIVIDE;
|
||||
case ASSIGN_DIV:
|
||||
return Kind.DIVIDE_ASSIGNMENT;
|
||||
case LT:
|
||||
return Kind.LESS_THAN;
|
||||
case SHL:
|
||||
return Kind.LEFT_SHIFT;
|
||||
case ASSIGN_SHL:
|
||||
return Kind.LEFT_SHIFT_ASSIGNMENT;
|
||||
case LE:
|
||||
return Kind.LESS_THAN_EQUAL;
|
||||
case ASSIGN:
|
||||
return Kind.ASSIGNMENT;
|
||||
case EQ:
|
||||
return Kind.EQUAL_TO;
|
||||
case EQ_STRICT:
|
||||
return Kind.STRICT_EQUAL_TO;
|
||||
case GT:
|
||||
return Kind.GREATER_THAN;
|
||||
case GE:
|
||||
return Kind.GREATER_THAN_EQUAL;
|
||||
case SAR:
|
||||
return Kind.RIGHT_SHIFT;
|
||||
case ASSIGN_SAR:
|
||||
return Kind.RIGHT_SHIFT_ASSIGNMENT;
|
||||
case SHR:
|
||||
return Kind.UNSIGNED_RIGHT_SHIFT;
|
||||
case ASSIGN_SHR:
|
||||
return Kind.UNSIGNED_RIGHT_SHIFT_ASSIGNMENT;
|
||||
case TERNARY:
|
||||
return Kind.CONDITIONAL_EXPRESSION;
|
||||
case BIT_XOR:
|
||||
return Kind.XOR;
|
||||
case ASSIGN_BIT_XOR:
|
||||
return Kind.XOR_ASSIGNMENT;
|
||||
case BIT_OR:
|
||||
return Kind.OR;
|
||||
case ASSIGN_BIT_OR:
|
||||
return Kind.OR_ASSIGNMENT;
|
||||
case OR:
|
||||
return Kind.CONDITIONAL_OR;
|
||||
case BIT_NOT:
|
||||
return Kind.BITWISE_COMPLEMENT;
|
||||
case DELETE:
|
||||
return Kind.DELETE;
|
||||
case TYPEOF:
|
||||
return Kind.TYPEOF;
|
||||
case VOID:
|
||||
return Kind.VOID;
|
||||
case IN:
|
||||
return Kind.IN;
|
||||
case INSTANCEOF:
|
||||
return Kind.INSTANCE_OF;
|
||||
case COMMARIGHT:
|
||||
return Kind.COMMA;
|
||||
default:
|
||||
throw new AssertionError("should not reach here: " + tt);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,438 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A visitor of trees, in the style of the visitor design pattern.
|
||||
* Classes implementing this interface are used to operate
|
||||
* on a tree when the kind of tree is unknown at compile time.
|
||||
* When a visitor is passed to an tree's {@link Tree#accept
|
||||
* accept} method, the <tt>visit<i>XYZ</i></tt> method most applicable
|
||||
* to that tree is invoked.
|
||||
*
|
||||
* <p> Classes implementing this interface may or may not throw a
|
||||
* {@code NullPointerException} if the additional parameter {@code p}
|
||||
* is {@code null}; see documentation of the implementing class for
|
||||
* details.
|
||||
*
|
||||
* <p> <b>WARNING:</b> It is possible that methods will be added to
|
||||
this interface to accommodate new, currently unknown, language
|
||||
structures added to future versions of the ECMAScript programming
|
||||
language. When new visit methods are added for new Tree subtypes,
|
||||
default method bodies will be introduced which will call visitUnknown
|
||||
method as a fallback.
|
||||
*
|
||||
* @param <R> the return type of this visitor's methods. Use {@link
|
||||
* Void} for visitors that do not need to return results.
|
||||
* @param <P> the type of the additional parameter to this visitor's
|
||||
* methods. Use {@code Void} for visitors that do not need an
|
||||
* additional parameter.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface TreeVisitor<R,P> {
|
||||
/**
|
||||
* Visit assignment tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitAssignment(AssignmentTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit compound assignment tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitCompoundAssignment(CompoundAssignmentTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit binary expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitBinary(BinaryTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit block statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitBlock(BlockTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit break statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitBreak(BreakTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit case statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitCase(CaseTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit catch block statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitCatch(CatchTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit conditional expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitConditionalExpression(ConditionalExpressionTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit continue statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitContinue(ContinueTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit debugger statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitDebugger(DebuggerTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit do-while statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitDoWhileLoop(DoWhileLoopTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit error expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitErroneous(ErroneousTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit expression statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitExpressionStatement(ExpressionStatementTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit 'for' statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitForLoop(ForLoopTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit for..in statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitForInLoop(ForInLoopTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit function call expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitFunctionCall(FunctionCallTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit function declaration tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitFunctionDeclaration(FunctionDeclarationTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit function expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitFunctionExpression(FunctionExpressionTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit identifier tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitIdentifier(IdentifierTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit 'if' statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitIf(IfTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit array access expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitArrayAccess(ArrayAccessTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit array literal expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitArrayLiteral(ArrayLiteralTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit labeled statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitLabeledStatement(LabeledStatementTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit literal expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitLiteral(LiteralTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit parenthesized expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitParenthesized(ParenthesizedTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit return statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitReturn(ReturnTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit member select expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitMemberSelect(MemberSelectTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit 'new' expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitNew(NewTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit object literal tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitObjectLiteral(ObjectLiteralTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit a property of an object literal expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitProperty(PropertyTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit regular expression literal tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitRegExpLiteral(RegExpLiteralTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit an empty statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitEmptyStatement(EmptyStatementTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit 'switch' statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitSwitch(SwitchTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit 'throw' expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitThrow(ThrowTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit compilation unit tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitCompilationUnit(CompilationUnitTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit 'try' statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitTry(TryTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit 'instanceof' expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitInstanceOf(InstanceOfTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit unary expression tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitUnary(UnaryTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit variable declaration tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitVariable(VariableTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit 'while' statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitWhileLoop(WhileLoopTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit 'with' statement tree.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitWith(WithTree node, P p);
|
||||
|
||||
/**
|
||||
* Visit unknown expression/statement tree. This fallback will be
|
||||
* called if new Tree subtypes are introduced in future. A specific
|
||||
* implementation may throw {{@linkplain UnknownTreeException unknown tree exception}
|
||||
* if the visitor implementation was for an older language version.
|
||||
*
|
||||
* @param node node being visited
|
||||
* @param p extra parameter passed to the visitor
|
||||
* @return value from the visitor
|
||||
*/
|
||||
R visitUnknown(Tree node, P p);
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A tree node for a 'try' statement.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* try
|
||||
* <em>block</em>
|
||||
* <em>catches</em>
|
||||
* finally
|
||||
* <em>finallyBlock</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface TryTree extends StatementTree {
|
||||
/**
|
||||
* Returns the 'try' block of this 'try' statement.
|
||||
*
|
||||
* @return the 'try' block
|
||||
*/
|
||||
BlockTree getBlock();
|
||||
|
||||
/**
|
||||
* Returns the list of 'catch' statements associated with this 'try'.
|
||||
*
|
||||
* @return the list of 'catch' statements associated with this 'try'.
|
||||
*/
|
||||
List<? extends CatchTree> getCatches();
|
||||
|
||||
/**
|
||||
* Returns the 'finally' block associated with this 'try'. This is
|
||||
* null if there is no 'finally' block associated with this 'try'.
|
||||
*
|
||||
* @return the 'finally' block associated with this 'try'.
|
||||
*/
|
||||
BlockTree getFinallyBlock();
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import java.util.List;
|
||||
import jdk.nashorn.internal.ir.TryNode;
|
||||
|
||||
final class TryTreeImpl extends StatementTreeImpl implements TryTree {
|
||||
private final BlockTree block;
|
||||
private final List<? extends CatchTree> catches;
|
||||
private final BlockTree finallyBlock;
|
||||
TryTreeImpl(final TryNode node,
|
||||
final BlockTree block,
|
||||
final List<? extends CatchTree> catches,
|
||||
final BlockTree finallyBlock) {
|
||||
super(node);
|
||||
this.block = block;
|
||||
this.catches = catches;
|
||||
this.finallyBlock = finallyBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.TRY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockTree getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends CatchTree> getCatches() {
|
||||
return catches;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockTree getFinallyBlock() {
|
||||
return finallyBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitTry(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
/**
|
||||
* A tree node for postfix and unary expressions.
|
||||
* Use {@link #getKind getKind} to determine the kind of operator.
|
||||
*
|
||||
* For example:
|
||||
* <pre>
|
||||
* <em>operator</em> <em>expression</em>
|
||||
*
|
||||
* <em>expression</em> <em>operator</em>
|
||||
* </pre>
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface UnaryTree extends ExpressionTree {
|
||||
/**
|
||||
* Returns the expression operated by the unary operator.
|
||||
*
|
||||
* @return The expression operated by the unary operator.
|
||||
*/
|
||||
ExpressionTree getExpression();
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
import jdk.nashorn.internal.ir.UnaryNode;
|
||||
|
||||
class UnaryTreeImpl extends ExpressionTreeImpl implements UnaryTree {
|
||||
private final ExpressionTree expr;
|
||||
private final Kind kind;
|
||||
UnaryTreeImpl(final UnaryNode node, final ExpressionTree expr) {
|
||||
super(node);
|
||||
this.expr = expr;
|
||||
this.kind = getOperator(node.tokenType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionTree getExpression() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
|
||||
return visitor.visitUnary(this, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* 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
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package jdk.nashorn.api.tree;
|
||||
|
||||
|
||||
/**
|
||||
* Indicates that an unknown kind of Tree was encountered. This
|
||||
* can occur if the language evolves and new kinds of Trees are
|
||||
* added to the {@code Tree} hierarchy. May be thrown by a
|
||||
* {@linkplain TreeVisitor tree visitor} to indicate that the
|
||||
* visitor was created for a prior version of the language.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class UnknownTreeException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private transient final Tree tree;
|
||||
private transient final Object parameter;
|
||||
|
||||
/**
|
||||
* Creates a new {@code UnknownTreeException}. The {@code p}
|
||||
* parameter may be used to pass in an additional argument with
|
||||
* information about the context in which the unknown element was
|
||||
* encountered; for example, the visit methods of {@link
|
||||
* TreeVisitor} may pass in their additional parameter.
|
||||
*
|
||||
* @param t the unknown tree, may be {@code null}
|
||||
* @param p an additional parameter, may be {@code null}
|
||||
*/
|
||||
public UnknownTreeException(Tree t, Object p) {
|
||||
super("Unknown tree: " + t);
|
||||
this.tree = t;
|
||||
this.parameter = p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unknown tree.
|
||||
* The value may be unavailable if this exception has been
|
||||
* serialized and then read back in.
|
||||
*
|
||||
* @return the unknown element, or {@code null} if unavailable
|
||||
*/
|
||||
public Tree getUnknownTree() {
|
||||
return tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the additional argument.
|
||||
* The value may be unavailable if this exception has been
|
||||
* serialized and then read back in.
|
||||
*
|
||||
* @return the additional argument
|
||||
*/
|
||||
public Object getArgument() {
|
||||
return parameter;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user