зеркало из https://github.com/mozilla/gecko-dev.git
Import of Initial Source from MVCC
This commit is contained in:
Родитель
a722f4ea85
Коммит
8d92d194b7
|
@ -0,0 +1,51 @@
|
|||
# Makefile for JSC in Java
|
||||
# Targets:
|
||||
# all -- to build all parts.
|
||||
# input, lexer, parser, semantics, generator -- to build a specfic part.
|
||||
# sanity -- to run the compiler against a simple script. If things are
|
||||
# working the compiler will return the value: completion( 0, okay, null )
|
||||
|
||||
|
||||
all: input lexer parser semantics generator main sanity
|
||||
|
||||
main:
|
||||
javac -d classes -classpath classes ../../src/java/main/*.java
|
||||
|
||||
input:
|
||||
javac -d classes -classpath classes ../../src/java/input/*.java
|
||||
|
||||
lexer:
|
||||
javac -d classes -classpath classes ../../src/java/lexer/*.java
|
||||
|
||||
parser:
|
||||
javac -d classes -classpath classes ../../src/java/parser/*.java
|
||||
|
||||
semantics:
|
||||
javac -d classes -classpath classes ../../src/java/semantics/*.java ../../src/java/semantics/values/*.java ../../src/java/semantics/types/*.java
|
||||
|
||||
generator:
|
||||
javac -d classes -classpath classes ../../src/java/generator/*.java
|
||||
|
||||
sanity:
|
||||
java -classpath classes Main -d ../../test/sanity.js
|
||||
|
||||
test:
|
||||
java -classpath classes Main -d ../../test/ecma-e4/02.expressions/primary.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/02.expressions/prefixunary.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/02.expressions/postfixunary.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/02.expressions/binary.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/break.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/continue.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/do.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/for.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/forin.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/if.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/labeled.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/return.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/switch.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/throw.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/try.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/while.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/with.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/04.definitions/definition.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/04.definitions/definition.2.js
|
|
@ -0,0 +1 @@
|
|||
ÐÏࡱ
|
|
@ -0,0 +1 @@
|
|||
ÐÏࡱ
|
|
@ -0,0 +1,71 @@
|
|||
J S C R E A D M E F I L E
|
||||
Jeff Dyer, Nov-30-2000
|
||||
|
||||
OVERVIEW
|
||||
|
||||
JSC (JavaScript Compiler) is a stand-alone front-end implementation
|
||||
of the JS2 language specification. Its purpose is to demonstrate how
|
||||
JS2 programs are statically prepared for execution by a JS2 interpreter.
|
||||
Its output is a psuedo intermediate language suitable for reading by
|
||||
human beings.
|
||||
|
||||
RUNNING JSC
|
||||
|
||||
With a Java Runtime Environment installed, go to the directory ./bin
|
||||
and issue the command:
|
||||
|
||||
java -classpath jsc.jar Main program.js
|
||||
|
||||
program.js is the name of the file to compile. JSC will
|
||||
produce a new file given the name of the original source file
|
||||
with the suffix .jsil appended to it. Errors are written to a
|
||||
file with the suffix .err appended to it.
|
||||
|
||||
BUILDING JSC
|
||||
|
||||
Go to the directory ./build/java, and run your favorite make
|
||||
utility. Such as with the command:
|
||||
|
||||
nmake
|
||||
|
||||
If all goes well, the file ./bin/jsc.jar will be updated.
|
||||
|
||||
|
||||
STATUS OF JSC
|
||||
|
||||
Input Buffer
|
||||
Lexer
|
||||
Parser
|
||||
Block Evaluator
|
||||
Flow Analyzer
|
||||
Type System
|
||||
Expressions
|
||||
Statements
|
||||
Definitions
|
||||
Variables
|
||||
Functions
|
||||
Classes
|
||||
Namespaces
|
||||
Packages
|
||||
Language Declarations
|
||||
Unit Parser
|
||||
Operator Overloading
|
||||
Errors
|
||||
|
||||
ISSUES
|
||||
|
||||
* Intermediate form of references, classes, and interfaces.
|
||||
|
||||
CHANGES
|
||||
|
||||
Nov-30-2000
|
||||
-----------
|
||||
* Folded definition evaluation into constant evaluation since annotated
|
||||
definitions cannot be evaluated until the constant attribute values
|
||||
have been computed. Now there is a BlockEvaluator and a ConstantEvaluator.
|
||||
* Added an error handler to the constant evaluator.
|
||||
* Simplified the type system.
|
||||
|
||||
Nov-16-2000
|
||||
-----------
|
||||
* Original release.
|
|
@ -0,0 +1,947 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* JSILGenerator
|
||||
*/
|
||||
|
||||
public class JSILGenerator extends Evaluator implements Tokens {
|
||||
|
||||
public static boolean debug = false;
|
||||
|
||||
private static PrintStream out;
|
||||
public static void setOut(String filename) throws Exception {
|
||||
out = new PrintStream( new FileOutputStream(filename) );
|
||||
}
|
||||
|
||||
private static void emit(String str) {
|
||||
if( debug ) {
|
||||
Debugger.trace("emit " + str);
|
||||
}
|
||||
|
||||
if( out!=null ) {
|
||||
out.println(str);
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
|
||||
Value evaluate( Context context, Node node ) throws Exception {
|
||||
String tag = "missing evaluator for " + node.getClass(); emit(context.getIndent()+tag); return null;
|
||||
}
|
||||
|
||||
// Expression evaluators
|
||||
|
||||
|
||||
Value evaluate( Context context, ThisExpressionNode node ) throws Exception {
|
||||
String tag = "ThisExpression ";
|
||||
emit(context.getIndent()+tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, IdentifierNode node ) throws Exception {
|
||||
String tag = "Identifier ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
emit(context.getIndent()+node.name);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, QualifiedIdentifierNode node ) throws Exception {
|
||||
String tag = "QualifiedIdentifier ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.qualifier != null ) {
|
||||
node.qualifier.evaluate(context,this);
|
||||
}
|
||||
if( node.name != null ) {
|
||||
emit(context.getIndent()+node.name);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralBooleanNode node ) throws Exception {
|
||||
String tag = "LiteralBoolean: " + node.value;
|
||||
emit(context.getIndent()+tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralNullNode node ) throws Exception {
|
||||
String tag = "LiteralNull ";
|
||||
emit(context.getIndent()+tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralNumberNode node ) throws Exception {
|
||||
String tag = "LiteralNumber: " + node.value;
|
||||
emit(context.getIndent()+tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralStringNode node ) throws Exception {
|
||||
String tag = "LiteralString: " + node.value;
|
||||
emit(context.getIndent()+tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralUndefinedNode node ) throws Exception {
|
||||
String tag = "LiteralUndefined ";
|
||||
emit(context.getIndent()+tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralRegExpNode node ) throws Exception {
|
||||
String tag = "LiteralRegExp: " + node.value;
|
||||
emit(context.getIndent()+tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, UnitExpressionNode node ) throws Exception {
|
||||
String tag = "UnitExpression ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.value != null ) {
|
||||
node.value.evaluate(context,this);
|
||||
}
|
||||
if( node.type != null ) {
|
||||
node.type.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ParenthesizedExpressionNode node ) throws Exception {
|
||||
String tag = "ParenthesizedExpression ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ParenthesizedListExpressionNode node ) throws Exception {
|
||||
String tag = "ParenthesizedListExpression ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, FunctionExpressionNode node ) throws Exception {
|
||||
String tag = "FunctionExpression ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
if( node.signature != null ) {
|
||||
node.signature.evaluate(context,this);
|
||||
}
|
||||
if( node.body != null ) {
|
||||
node.body.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralObjectNode node ) throws Exception {
|
||||
String tag = "LiteralObject ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.fieldlist != null ) {
|
||||
node.fieldlist.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralFieldNode node ) throws Exception {
|
||||
String tag = "LiteralField ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
if( node.value != null ) {
|
||||
node.value.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralArrayNode node ) throws Exception {
|
||||
String tag = "LiteralArray ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.elementlist != null ) {
|
||||
node.elementlist.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, PostfixExpressionNode node ) throws Exception {
|
||||
String tag = "PostfixExpression: " + Token.getTokenClassName(node.op);
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, NewExpressionNode node ) throws Exception {
|
||||
String tag = "NewExpression";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, IndexedMemberExpressionNode node ) throws Exception {
|
||||
String tag = "IndexedMemberExpression";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.base != null ) {
|
||||
node.base.evaluate(context,this);
|
||||
}
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, MemberExpressionNode node ) throws Exception {
|
||||
String tag = "MemberExpression";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.base != null ) {
|
||||
node.base.evaluate(context,this);
|
||||
}
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ClassofExpressionNode node ) throws Exception {
|
||||
String tag = "ClassofExpression";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.base != null ) {
|
||||
node.base.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, CoersionExpressionNode node ) throws Exception {
|
||||
String tag = "CoersionExpression";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
if( node.type != null ) {
|
||||
node.type.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, CallExpressionNode node ) throws Exception {
|
||||
String tag = "CallExpression";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.member != null ) {
|
||||
node.member.evaluate(context,this);
|
||||
}
|
||||
if( node.args != null ) {
|
||||
node.args.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, UnaryExpressionNode node ) throws Exception {
|
||||
String tag = "UnaryExpression: " + Token.getTokenClassName(node.op);
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, BinaryExpressionNode node ) throws Exception {
|
||||
String tag = "BinaryExpression: " + Token.getTokenClassName(node.op);
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.lhs != null ) {
|
||||
node.lhs.evaluate(context,this);
|
||||
}
|
||||
if( node.rhs != null ) {
|
||||
node.rhs.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ConditionalExpressionNode node ) throws Exception {
|
||||
String tag = "ConditionalExpression";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.condition != null ) {
|
||||
node.condition.evaluate(context,this);
|
||||
}
|
||||
if( node.thenexpr != null ) {
|
||||
node.thenexpr.evaluate(context,this);
|
||||
}
|
||||
if( node.elseexpr != null ) {
|
||||
node.elseexpr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, AssignmentExpressionNode node ) throws Exception {
|
||||
String tag = "AssignmentExpression: " + ((node.op==empty_token)?"":Token.getTokenClassName(node.op));
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.lhs != null ) {
|
||||
node.lhs.evaluate(context,this);
|
||||
}
|
||||
if( node.rhs != null ) {
|
||||
node.rhs.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ListNode node ) throws Exception {
|
||||
String tag = "List";
|
||||
//emit(context.getIndent()+tag);
|
||||
if( node.list != null ) {
|
||||
node.list.evaluate(context,this);
|
||||
}
|
||||
if( node.item != null ) {
|
||||
node.item.evaluate(context,this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Statements
|
||||
|
||||
Value evaluate( Context context, StatementListNode node ) throws Exception {
|
||||
String tag = "StatementList";
|
||||
//emit(context.getIndent()+tag);
|
||||
if( node.list != null ) {
|
||||
node.list.evaluate(context,this);
|
||||
}
|
||||
if( node.item != null ) {
|
||||
node.item.evaluate(context,this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, EmptyStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"EmptyStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ExpressionStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"ExpressionStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, AnnotatedBlockNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"AnnotatedBlock";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.attributes != null ) {
|
||||
node.attributes.evaluate(context,this);
|
||||
}
|
||||
if( node.statements != null ) {
|
||||
node.statements.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LabeledStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"LabeledStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.label != null ) {
|
||||
node.label.evaluate(context,this);
|
||||
}
|
||||
if( node.statement != null ) {
|
||||
node.statement.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, IfStatementNode node ) throws Exception {
|
||||
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"IfStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.condition != null ) {
|
||||
node.condition.evaluate(context,this);
|
||||
}
|
||||
if( node.thenactions != null ) {
|
||||
node.thenactions.evaluate(context,this);
|
||||
}
|
||||
if( node.elseactions != null ) {
|
||||
node.elseactions.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, SwitchStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"SwitchStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
if( node.statements != null ) {
|
||||
node.statements.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, CaseLabelNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"CaseLabel";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.label != null ) {
|
||||
node.label.evaluate(context,this);
|
||||
} else {
|
||||
emit(context.getIndent()+"default");
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, DoStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"DoStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.statements != null ) {
|
||||
node.statements.evaluate(context,this);
|
||||
}
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, WhileStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"WhileStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
if( node.statement != null ) {
|
||||
node.statement.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ForStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"ForStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.initialize != null ) {
|
||||
node.initialize.evaluate(context,this);
|
||||
}
|
||||
if( node.test != null ) {
|
||||
node.test.evaluate(context,this);
|
||||
}
|
||||
if( node.increment != null ) {
|
||||
node.increment.evaluate(context,this);
|
||||
}
|
||||
if( node.statement != null ) {
|
||||
node.statement.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ForInStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"ForInStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.property != null ) {
|
||||
node.property.evaluate(context,this);
|
||||
}
|
||||
if( node.object != null ) {
|
||||
node.object.evaluate(context,this);
|
||||
}
|
||||
if( node.statement != null ) {
|
||||
node.statement.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, WithStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"WithStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
if( node.statement != null ) {
|
||||
node.statement.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ContinueStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"ContinueStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, BreakStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"BreakStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ReturnStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"ReturnStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ThrowStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"ThrowStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, TryStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"TryStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.tryblock != null ) {
|
||||
node.tryblock.evaluate(context,this);
|
||||
}
|
||||
if( node.catchlist != null ) {
|
||||
node.catchlist.evaluate(context,this);
|
||||
}
|
||||
if( node.finallyblock != null ) {
|
||||
node.finallyblock.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, CatchClauseNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"CatchClause";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.parameter != null ) {
|
||||
node.parameter.evaluate(context,this);
|
||||
}
|
||||
if( node.statements != null ) {
|
||||
node.statements.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, FinallyClauseNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"FinallyClause";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.statements != null ) {
|
||||
node.statements.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, UseStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"UseStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, IncludeStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"IncludeStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.item != null ) {
|
||||
node.item.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Definitions
|
||||
|
||||
Value evaluate( Context context, ImportDefinitionNode node ) throws Exception {
|
||||
String tag = "ImportDefinition";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.item != null ) {
|
||||
node.item.evaluate(context,this);
|
||||
}
|
||||
if( node.list != null ) {
|
||||
node.list.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ImportBindingNode node ) throws Exception {
|
||||
String tag = "ImportBinding";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.identifier != null ) {
|
||||
node.identifier.evaluate(context,this);
|
||||
}
|
||||
if( node.item != null ) {
|
||||
node.item.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, AnnotatedDefinitionNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"AnnotatedDefinition";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.attributes != null ) {
|
||||
node.attributes.evaluate(context,this);
|
||||
}
|
||||
if( node.definition != null ) {
|
||||
node.definition.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, AttributeListNode node ) throws Exception {
|
||||
String tag = "AttributeList";
|
||||
//emit(context.getIndent()+tag);
|
||||
//context.indent++;
|
||||
if( node.item != null ) {
|
||||
node.item.evaluate(context,this);
|
||||
}
|
||||
if( node.list != null ) {
|
||||
node.list.evaluate(context,this);
|
||||
}
|
||||
//context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ExportDefinitionNode node ) throws Exception {
|
||||
String tag = "ExportDefinition";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.list != null ) {
|
||||
node.list.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ExportBindingNode node ) throws Exception {
|
||||
String tag = "ExportBinding";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
if( node.value != null ) {
|
||||
node.value.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, VariableDefinitionNode node ) throws Exception {
|
||||
String tag = "VariableDefinition: " + Token.getTokenClassName(node.kind);
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.list != null ) {
|
||||
node.list.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, VariableBindingNode node ) throws Exception {
|
||||
String tag = "VariableBinding";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.variable != null ) {
|
||||
node.variable.evaluate(context,this);
|
||||
}
|
||||
if( node.initializer != null ) {
|
||||
node.initializer.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, TypedVariableNode node ) throws Exception {
|
||||
String tag = "TypedVariable";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.identifier != null ) {
|
||||
node.identifier.evaluate(context,this);
|
||||
}
|
||||
if( node.type != null ) {
|
||||
node.type.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, FunctionDefinitionNode node ) throws Exception {
|
||||
String tag = "FunctionDefinition";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.decl != null ) {
|
||||
node.decl.evaluate(context,this);
|
||||
}
|
||||
if( node.body != null ) {
|
||||
node.body.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, FunctionDeclarationNode node ) throws Exception {
|
||||
String tag = "FunctionDeclaration";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
if( node.signature != null ) {
|
||||
node.signature.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, FunctionSignatureNode node ) throws Exception {
|
||||
String tag = "FunctionSignature";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.parameter != null ) {
|
||||
node.parameter.evaluate(context,this);
|
||||
}
|
||||
if( node.result != null ) {
|
||||
node.result.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, FunctionNameNode node ) throws Exception {
|
||||
String tag = "FunctionName: " + ((node.kind==empty_token)?"":Token.getTokenClassName(node.kind));
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ParameterNode node ) throws Exception {
|
||||
String tag = "Parameter";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.identifier != null ) {
|
||||
node.identifier.evaluate(context,this);
|
||||
}
|
||||
if( node.type != null ) {
|
||||
node.type.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, OptionalParameterNode node ) throws Exception {
|
||||
String tag = "OptionalParameter";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.parameter != null ) {
|
||||
node.parameter.evaluate(context,this);
|
||||
}
|
||||
if( node.initializer != null ) {
|
||||
node.initializer.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ClassDefinitionNode node ) throws Exception {
|
||||
String tag = "ClassDefinition";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
if( node.inheritance != null ) {
|
||||
node.inheritance.evaluate(context,this);
|
||||
}
|
||||
if( node.statements != null ) {
|
||||
node.statements.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, InheritanceNode node ) throws Exception {
|
||||
String tag = "Inheritance";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.baseclass != null ) {
|
||||
node.baseclass.evaluate(context,this);
|
||||
}
|
||||
if( node.interfaces != null ) {
|
||||
node.interfaces.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ClassDeclarationNode node ) throws Exception {
|
||||
String tag = "ClassDeclaration";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, NamespaceDefinitionNode node ) throws Exception {
|
||||
String tag = "NamespaceDefinition";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
if( node.extendslist != null ) {
|
||||
node.extendslist.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, PackageDefinitionNode node ) throws Exception {
|
||||
String tag = "PackageDefinition";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
if( node.statements != null ) {
|
||||
node.statements.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ProgramNode node ) throws Exception {
|
||||
String tag = "Program";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
node.statements.evaluate(context,this);
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* class Debugger
|
||||
*
|
||||
**/
|
||||
|
||||
public final class Debugger {
|
||||
|
||||
public static PrintStream dbg = null;
|
||||
private static boolean useSystemOut = false;
|
||||
|
||||
public static void setOutFile(String filename) {
|
||||
try {
|
||||
PrintStream out = new PrintStream( new FileOutputStream( filename ) );
|
||||
System.setOut( out );
|
||||
//System.setErr( outfile );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setErrFile(String filename) {
|
||||
try {
|
||||
PrintStream err = new PrintStream( new FileOutputStream( filename ) );
|
||||
//System.setOut( out );
|
||||
System.setErr( err );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setDbgFile(String filename) {
|
||||
try {
|
||||
if( dbg!=null) {
|
||||
dbg.close();
|
||||
}
|
||||
dbg = new PrintStream( new FileOutputStream( filename ) );
|
||||
//System.setOut( outfile );
|
||||
//System.setErr( outfile );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void trace( String str ) {
|
||||
try {
|
||||
if( useSystemOut )
|
||||
System.out.println( str );
|
||||
else {
|
||||
if( dbg == null ) {
|
||||
dbg = new PrintStream( new FileOutputStream( "debug.out" ) );
|
||||
//System.setOut( outfile );
|
||||
//System.setErr( outfile );
|
||||
}
|
||||
dbg.println( str );
|
||||
}
|
||||
}
|
||||
catch( SecurityException e ) {
|
||||
useSystemOut = true;
|
||||
System.out.println( str );
|
||||
}
|
||||
catch( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,514 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
/**
|
||||
* InputBuffer.java
|
||||
*
|
||||
* Filters and buffers characters from a Reader.
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.io.*;
|
||||
|
||||
public class InputBuffer implements CharacterClasses {
|
||||
|
||||
private static final boolean debug = false;
|
||||
private static final boolean debug_nextchar = false;
|
||||
private static final boolean debug_retract = false;
|
||||
|
||||
StringBuffer lineA = new StringBuffer();
|
||||
StringBuffer lineB = new StringBuffer();
|
||||
StringBuffer curr_line,prev_line;
|
||||
int curr_line_offset,prev_line_offset;
|
||||
int lineA_offset, lineB_offset;
|
||||
|
||||
private StringBuffer text;
|
||||
private int[] line_breaks = new int[1000];
|
||||
|
||||
Reader in;
|
||||
PrintStream err;
|
||||
String origin;
|
||||
|
||||
int pos;
|
||||
int colPos, lnNum=-1; // <0,0> is the position of the first character.
|
||||
|
||||
public static PrintStream out;
|
||||
public static void setOut(String filename) throws Exception {
|
||||
out = new PrintStream( new FileOutputStream(filename) );
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
test_retract();
|
||||
test_markandcopy();
|
||||
test_getLineText();
|
||||
}
|
||||
|
||||
public InputBuffer( Reader in, PrintStream err, String origin ) {
|
||||
this(in,err,origin,0);
|
||||
}
|
||||
|
||||
public InputBuffer( Reader in, PrintStream err, String origin, int pos ) {
|
||||
this.in = in;
|
||||
this.err = err;
|
||||
this.origin = origin;
|
||||
this.pos = pos;
|
||||
this.text = new StringBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* read()
|
||||
*
|
||||
* Read the next character from the input reader and store it in a buffer
|
||||
* of the full text.
|
||||
*/
|
||||
|
||||
private int read() throws Exception {
|
||||
int c = in.read();
|
||||
text.append((char)c);
|
||||
pos++;
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* text()
|
||||
*/
|
||||
|
||||
public String source() {
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* nextchar() --
|
||||
*
|
||||
* The basic function of nextchar() is to fetch the next character,
|
||||
* in the input array, increment next and return the fetched character.
|
||||
*
|
||||
* To simplify the Scanner, this method also does the following:
|
||||
* 1. normalizes certain special characters to a common character.
|
||||
* 2. skips unicode format control characters (category Cf).
|
||||
* 3. keeps track of line breaks, line position and line number.
|
||||
* 4. treats <cr>+<lf> as a single line terminator.
|
||||
* 5. returns 0 when the end of input is reached.
|
||||
*/
|
||||
|
||||
public final int nextchar() throws Exception {
|
||||
|
||||
int c = -1;
|
||||
|
||||
// If the last character was at the end of a line,
|
||||
// then swap buffers and fill the new one with characters
|
||||
// from the input reader.
|
||||
|
||||
if( curr_line==null || colPos==curr_line.length() ) {
|
||||
|
||||
lnNum++;
|
||||
colPos=0;
|
||||
|
||||
// If the current character is a newline, then read
|
||||
// the next line of input into the other input buffer.
|
||||
|
||||
if( curr_line == lineA ) {
|
||||
if( lineB == null ) {
|
||||
lineB = new StringBuffer();
|
||||
lineB_offset = pos;
|
||||
}
|
||||
curr_line = lineB; curr_line_offset = lineB_offset;
|
||||
prev_line = lineA; prev_line_offset = lineA_offset;
|
||||
lineA = null;
|
||||
} else {
|
||||
if( lineA == null ) {
|
||||
lineA = new StringBuffer();
|
||||
lineA_offset = pos;
|
||||
}
|
||||
curr_line = lineA; curr_line_offset = lineA_offset;
|
||||
prev_line = lineB; prev_line_offset = lineB_offset;
|
||||
lineB = null;
|
||||
}
|
||||
|
||||
while(c != '\n' && c != 0) {
|
||||
|
||||
c = read();
|
||||
|
||||
if( false ) {
|
||||
Debugger.trace( "c = " + c );
|
||||
}
|
||||
|
||||
// Skip Unicode 3.0 format-control (general category Cf in
|
||||
// Unicode Character Database) characters.
|
||||
|
||||
while(true) {
|
||||
|
||||
switch(c) {
|
||||
case 0x070f: // SYRIAC ABBREVIATION MARK
|
||||
case 0x180b: // MONGOLIAN FREE VARIATION SELECTOR ONE
|
||||
case 0x180c: // MONGOLIAN FREE VARIATION SELECTOR TWO
|
||||
case 0x180d: // MONGOLIAN FREE VARIATION SELECTOR THREE
|
||||
case 0x180e: // MONGOLIAN VOWEL SEPARATOR
|
||||
case 0x200c: // ZERO WIDTH NON-JOINER
|
||||
case 0x200d: // ZERO WIDTH JOINER
|
||||
case 0x200e: // LEFT-TO-RIGHT MARK
|
||||
case 0x200f: // RIGHT-TO-LEFT MARK
|
||||
case 0x202a: // LEFT-TO-RIGHT EMBEDDING
|
||||
case 0x202b: // RIGHT-TO-LEFT EMBEDDING
|
||||
case 0x202c: // POP DIRECTIONAL FORMATTING
|
||||
case 0x202d: // LEFT-TO-RIGHT OVERRIDE
|
||||
case 0x202e: // RIGHT-TO-LEFT OVERRIDE
|
||||
case 0x206a: // INHIBIT SYMMETRIC SWAPPING
|
||||
case 0x206b: // ACTIVATE SYMMETRIC SWAPPING
|
||||
case 0x206c: // INHIBIT ARABIC FORM SHAPING
|
||||
case 0x206d: // ACTIVATE ARABIC FORM SHAPING
|
||||
case 0x206e: // NATIONAL DIGIT SHAPES
|
||||
case 0x206f: // NOMINAL DIGIT SHAPES
|
||||
case 0xfeff: // ZERO WIDTH NO-BREAK SPACE
|
||||
case 0xfff9: // INTERLINEAR ANNOTATION ANCHOR
|
||||
case 0xfffa: // INTERLINEAR ANNOTATION SEPARATOR
|
||||
case 0xfffb: // INTERLINEAR ANNOTATION TERMINATOR
|
||||
c = read();
|
||||
continue; // skip it.
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break; // out of while loop.
|
||||
}
|
||||
|
||||
|
||||
if( c == 0x000a && prev_line.length()!=0 && prev_line.charAt(prev_line.length()-1) == 0x000d ) {
|
||||
|
||||
// If this is one of those funny double line terminators,
|
||||
// Then ignore the second character by reading on.
|
||||
|
||||
line_breaks[lnNum] = pos; // adjust if forward.
|
||||
c = read();
|
||||
}
|
||||
|
||||
// Line terminators.
|
||||
|
||||
if( c == 0x000a ||
|
||||
c == 0x000d ||
|
||||
c == 0x2028 ||
|
||||
c == 0x2029 ) {
|
||||
|
||||
curr_line.append((char)c);
|
||||
c = '\n';
|
||||
line_breaks[lnNum+1] = pos;
|
||||
|
||||
// White space
|
||||
|
||||
} else if( c == 0x0009 ||
|
||||
c == 0x000b ||
|
||||
c == 0x000c ||
|
||||
c == 0x0020 ||
|
||||
c == 0x00a0 ||
|
||||
false /* other cat Zs' */ ) {
|
||||
|
||||
c = ' ';
|
||||
curr_line.append((char)c);
|
||||
|
||||
// End of line
|
||||
|
||||
} else if( c == -1 ) {
|
||||
|
||||
c = 0;
|
||||
curr_line.append((char)c);
|
||||
|
||||
// All other characters.
|
||||
|
||||
} else {
|
||||
|
||||
// Use c as is.
|
||||
curr_line.append((char)c);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the next character.
|
||||
|
||||
int ln = lnNum;
|
||||
int col = colPos;
|
||||
|
||||
if( curr_line.length() != 0 && curr_line.charAt(colPos) == 0 ) {
|
||||
c = 0;
|
||||
colPos++;
|
||||
} else if( colPos == curr_line.length()-1 ) {
|
||||
c = '\n';
|
||||
colPos++;
|
||||
} else {
|
||||
c = curr_line.charAt(colPos++);
|
||||
}
|
||||
|
||||
if( out != null ) {
|
||||
out.println("Ln " + ln + ", Col " + col + ": nextchar " + Integer.toHexString(c) + " = " + (char)c + " @ " + positionOfNext());
|
||||
}
|
||||
if( debug || debug_nextchar ) {
|
||||
Debugger.trace("Ln " + ln + ", Col " + col + ": nextchar " + Integer.toHexString(c) + " = " + (char)c + " @ " + positionOfNext());
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* test_nextchar() --
|
||||
* Return an indication of how nextchar() performs
|
||||
* in various situations, relative to expectations.
|
||||
*/
|
||||
|
||||
boolean test_nextchar() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* time_nextchar() --
|
||||
* Return the milliseconds taken to do various ordinary
|
||||
* tasks with nextchar().
|
||||
*/
|
||||
|
||||
int time_nextchar() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* retract
|
||||
*
|
||||
* Backup one character position in the input. If at the beginning
|
||||
* of the line, then swap buffers and point to the last character
|
||||
* in the other buffer.
|
||||
*/
|
||||
|
||||
public final void retract() throws Exception {
|
||||
colPos--;
|
||||
if( colPos<0 ) {
|
||||
if( curr_line == prev_line ) {
|
||||
// Can only retract over one line.
|
||||
throw new Exception("Can only retract past one line at a time.");
|
||||
} else if( curr_line == lineA ) {
|
||||
curr_line = lineB = prev_line;
|
||||
} else {
|
||||
curr_line = lineA = prev_line;
|
||||
}
|
||||
lnNum--;
|
||||
colPos = curr_line.length()-1;
|
||||
curr_line_offset = prev_line_offset;
|
||||
}
|
||||
if( debug || debug_retract ) {
|
||||
Debugger.trace("Ln " + lnNum + ", Col " + colPos + ": retract");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static boolean test_retract() {
|
||||
Debugger.trace("test_retract");
|
||||
Reader reader = new StringReader("abc\ndef\nghi");
|
||||
try {
|
||||
InputBuffer inbuf = new InputBuffer(reader,System.err,"test");
|
||||
int c=-1;
|
||||
for(int i=0;i<9;i++) {
|
||||
c = inbuf.nextchar();
|
||||
}
|
||||
for(int i=0;i<3;i++) {
|
||||
inbuf.retract();
|
||||
c = inbuf.nextchar();
|
||||
inbuf.retract();
|
||||
}
|
||||
while(c!=0) {
|
||||
c = inbuf.nextchar();
|
||||
}
|
||||
} catch (Exception x) {
|
||||
x.printStackTrace();
|
||||
System.out.println(x);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* classOfNext
|
||||
*/
|
||||
|
||||
public byte classOfNext() {
|
||||
|
||||
// return the Unicode character class of the current
|
||||
// character, which is pointed to by 'next-1'.
|
||||
|
||||
return CharacterClasses.data[curr_line.charAt(colPos-1)];
|
||||
}
|
||||
|
||||
/**
|
||||
* positionOfNext
|
||||
*/
|
||||
|
||||
public int positionOfNext() {
|
||||
return curr_line_offset+colPos-1;
|
||||
}
|
||||
|
||||
/**
|
||||
* positionOfMark
|
||||
*/
|
||||
|
||||
public int positionOfMark() {
|
||||
return line_breaks[markLn]+markCol-1;
|
||||
}
|
||||
|
||||
/**
|
||||
* mark
|
||||
*/
|
||||
|
||||
int markCol;
|
||||
int markLn;
|
||||
|
||||
public int mark() {
|
||||
markLn = (lnNum==-1)?0:lnNum; // In case nextchar hasn't been called yet.
|
||||
markCol = colPos;
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("Ln " + markLn + ", Col " + markCol + ": mark");
|
||||
}
|
||||
|
||||
return markCol;
|
||||
}
|
||||
|
||||
/**
|
||||
* copy
|
||||
*/
|
||||
|
||||
public String copy() throws Exception {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("Ln " + lnNum + ", Col " + colPos + ": copy " + buf);
|
||||
}
|
||||
|
||||
if(markLn!=lnNum || markCol>colPos) {
|
||||
throw new Exception("Internal error: InputBuffer.copy() markLn = " + markLn + ", lnNum = " + lnNum + ", markCol = " +
|
||||
markCol + ", colPos = " + colPos );
|
||||
}
|
||||
|
||||
for (int i = markCol-1; i < colPos; i++) {
|
||||
buf.append(curr_line.charAt(i));
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
static boolean test_markandcopy() {
|
||||
Debugger.trace("test_copy");
|
||||
Reader reader = new StringReader("abc\ndef\nghijklmnopqrst\nuvwxyz");
|
||||
String s;
|
||||
try {
|
||||
InputBuffer inbuf = new InputBuffer(reader,System.err,"test");
|
||||
int c=-1;
|
||||
int i;
|
||||
for(i=0;i<10;i++) {
|
||||
c = inbuf.nextchar();
|
||||
}
|
||||
inbuf.mark();
|
||||
for(;i<13;i++) {
|
||||
c = inbuf.nextchar();
|
||||
}
|
||||
s = inbuf.copy();
|
||||
if(s.equals("ijk")) {
|
||||
Debugger.trace("1: passed: " + s);
|
||||
} else {
|
||||
Debugger.trace("1: failed: " + s);
|
||||
}
|
||||
while(c!=0) {
|
||||
c = inbuf.nextchar();
|
||||
}
|
||||
s = inbuf.copy();
|
||||
} catch (Exception x) {
|
||||
s = x.getMessage();
|
||||
//x.printStackTrace();
|
||||
}
|
||||
if(s.equals("Internal error: InputBuffer.copy() markLn = 2, lnNum = 3, markCol = 2, colPos = 6")) {
|
||||
Debugger.trace("2: passed: " + s);
|
||||
} else {
|
||||
Debugger.trace("2: failed: " + s);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getLineText(int pos) {
|
||||
int i,len;
|
||||
for(i = 0; line_breaks[i] <= pos && i <= lnNum; i++)
|
||||
;
|
||||
|
||||
int offset = line_breaks[i-1];
|
||||
|
||||
for(len = offset ; (text.charAt(len)!=(char)-1 &&
|
||||
text.charAt(len)!=0x0a &&
|
||||
text.charAt(len)!=0x0d &&
|
||||
text.charAt(len)!=0x2028 &&
|
||||
text.charAt(len)!=0x2029) ; len++) {
|
||||
}
|
||||
|
||||
return text.substring(offset,len);
|
||||
}
|
||||
|
||||
static boolean test_getLineText() {
|
||||
Debugger.trace("test_getLineText");
|
||||
Reader reader = new StringReader("abc\ndef\nghi");
|
||||
try {
|
||||
InputBuffer inbuf = new InputBuffer(reader,System.err,"test");
|
||||
int c=-1;
|
||||
for(int i=0;i<9;i++) {
|
||||
c = inbuf.nextchar();
|
||||
}
|
||||
for(int i=0;i<3;i++) {
|
||||
inbuf.retract();
|
||||
c = inbuf.nextchar();
|
||||
inbuf.retract();
|
||||
}
|
||||
while(c!=0) {
|
||||
c = inbuf.nextchar();
|
||||
}
|
||||
for(int i=0;i<inbuf.text.length()-1;i++) {
|
||||
Debugger.trace("text @ " + i + " " + inbuf.getLineText(i));
|
||||
}
|
||||
} catch (Exception x) {
|
||||
x.printStackTrace();
|
||||
System.out.println(x);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getColPos(int pos) {
|
||||
Debugger.trace("pos " + pos);
|
||||
int i,len;
|
||||
for(i = 0; line_breaks[i] <= pos && i <= lnNum; i++)
|
||||
;
|
||||
|
||||
int offset = line_breaks[i-1];
|
||||
Debugger.trace("offset " + offset);
|
||||
|
||||
return pos-offset;
|
||||
}
|
||||
|
||||
public int getLnNum(int pos) {
|
||||
int i;
|
||||
for(i = 0; line_breaks[i] <= pos && i <= lnNum; i++)
|
||||
;
|
||||
return i-1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.lang.reflect.*;
|
||||
import sun.tools.javac.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* class Shell
|
||||
*/
|
||||
|
||||
public final class Shell {
|
||||
private static boolean debug = true;
|
||||
static int failureCount = 0;
|
||||
|
||||
public static void main( String[] args ) {
|
||||
|
||||
try {
|
||||
|
||||
int count = args.length;
|
||||
String encoding = "UTF-8"; // Alternatives include: "UTF-16", "US-ASCII" (7-bit)
|
||||
|
||||
if( args[0].equals("-l") ) {
|
||||
/* run the input text through the scanner */
|
||||
|
||||
try {
|
||||
Debugger.trace("start "+args[count-1]);
|
||||
FileInputStream in = new FileInputStream( args[count-1] );
|
||||
InputStreamReader reader = new InputStreamReader( in, "UTF-8" );
|
||||
FileOutputStream tokfile = new FileOutputStream( args[count-1] + ".inp" );
|
||||
PrintWriter tokwriter = new PrintWriter( tokfile);
|
||||
FileOutputStream errfile = new FileOutputStream( args[count-1] + ".err" );
|
||||
PrintStream errwriter = new PrintStream( errfile );
|
||||
//char[] temp = new char[0xffff];
|
||||
//int len = reader.read( temp, 0, temp.length );
|
||||
//char[] src = new char[len+1];
|
||||
//System.arraycopy(temp, 0, src, 0, len);
|
||||
|
||||
InputBuffer inp = new InputBuffer( reader, errwriter, args[count-1] );
|
||||
int result;
|
||||
String follows;
|
||||
for( int i = 0; (result = inp.nextchar()) != 0; i++ ) {
|
||||
tokwriter.println( "" + Integer.toHexString(result) + " " + (char)result );
|
||||
}
|
||||
tokwriter.close();
|
||||
Debugger.trace("finish "+args[count-1]);
|
||||
}
|
||||
catch( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/*
|
||||
if( args[0].equals("-g") ) {
|
||||
|
||||
try {
|
||||
FileInputStream srcfile = new FileInputStream( args[count-1] );
|
||||
InputStreamReader reader = new InputStreamReader( srcfile );
|
||||
FileOutputStream errfile = new FileOutputStream( args[count-1] + ".err" );
|
||||
PrintStream errwriter = new PrintStream( errfile );
|
||||
char[] temp = new char[0x7ffff];
|
||||
int len = reader.read( temp, 0, temp.length );
|
||||
char[] src = new char[len+1];
|
||||
System.arraycopy(temp, 0, src, 0, len);
|
||||
|
||||
UnicodeNormalizationFormCReader ucreader = new UnicodeNormalizationFormCReader( src, errwriter, args[count-1] );
|
||||
UnicodeNormalizationFormCReader.generateCharacterClassesArray(ucreader);
|
||||
}
|
||||
catch( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
catch( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
**/
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.lang.reflect.*;
|
||||
import sun.tools.javac.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* class Shell
|
||||
*/
|
||||
|
||||
public final class Shell implements Tokens {
|
||||
private static boolean debug = false;
|
||||
static int failureCount = 0;
|
||||
|
||||
public static void main( String[] args ) {
|
||||
|
||||
try {
|
||||
|
||||
int count = args.length;
|
||||
|
||||
if( args[0].equals("-l") ) {
|
||||
/* run the input text through the scanner */
|
||||
|
||||
try {
|
||||
FileInputStream srcfile = new FileInputStream( args[count-1] );
|
||||
InputStreamReader reader = new InputStreamReader( srcfile );
|
||||
FileOutputStream tokfile = new FileOutputStream( args[count-1] + ".tok" );
|
||||
PrintWriter tokwriter = new PrintWriter( tokfile);
|
||||
FileOutputStream errfile = new FileOutputStream( args[count-1] + ".err" );
|
||||
PrintStream errwriter = new PrintStream( errfile );
|
||||
Scanner scanner = new Scanner( reader, errwriter, args[count-1] );
|
||||
int result;
|
||||
String follows;
|
||||
for( int i = 0; (result = scanner.nexttoken()) != eos_token; i++ ) {
|
||||
follows = scanner.followsLineTerminator() ? "*" : "";
|
||||
tokwriter.print( scanner.getPersistentTokenText(result) + follows + " " );
|
||||
}
|
||||
tokwriter.close();
|
||||
|
||||
/*
|
||||
for( int i = 0; (result = scanner.nexttoken()) != eos_token; i++ ) {
|
||||
System.out.println( scanner.lexeme() + "\t\t\t"
|
||||
+ Token.getTokenClassName(scanner.getTokenClass(result))
|
||||
+ " (" + result + ")"
|
||||
+ ": " + scanner.lexeme() );
|
||||
}
|
||||
*/
|
||||
}
|
||||
catch( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
**/
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,418 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
**/
|
||||
|
||||
interface States {
|
||||
|
||||
/**
|
||||
**/
|
||||
|
||||
public static final int start_state = 0;
|
||||
public static final int error_state = start_state-1;
|
||||
|
||||
public static final int minusminus_state = start_state+1;
|
||||
public static final int minusequal_state = minusminus_state +1;
|
||||
public static final int minus_state = minusequal_state +1;
|
||||
public static final int notequal_state = minus_state +1;
|
||||
public static final int not_state = notequal_state +1;
|
||||
public static final int remainderequal_state = not_state +1;
|
||||
public static final int remainder_state = remainderequal_state +1;
|
||||
public static final int logicaland_state = remainder_state +1;
|
||||
public static final int logicalandassign_state = logicaland_state +1;
|
||||
public static final int andequal_state = logicalandassign_state +1;
|
||||
public static final int and_state = andequal_state +1;
|
||||
public static final int leftparen_state = and_state +1;
|
||||
public static final int rightparen_state = leftparen_state +1;
|
||||
public static final int starequal_state = rightparen_state +1;
|
||||
public static final int star_state = starequal_state +1;
|
||||
public static final int comma_state = star_state +1;
|
||||
public static final int dot_state = comma_state +1;
|
||||
public static final int doubledot_state = dot_state +1;
|
||||
public static final int tripledot_state = doubledot_state +1;
|
||||
public static final int slashequal_state = tripledot_state +1;
|
||||
public static final int slash_state = slashequal_state +1;
|
||||
public static final int colon_state = slash_state +1;
|
||||
public static final int doublecolon_state = colon_state+1;
|
||||
public static final int semicolon_state = doublecolon_state+1;
|
||||
public static final int questionmark_state = semicolon_state +1;
|
||||
public static final int leftbracket_state = questionmark_state +1;
|
||||
public static final int rightbracket_state = leftbracket_state +1;
|
||||
public static final int bitwisexorassign_state = rightbracket_state +1;
|
||||
public static final int bitwisexor_state = bitwisexorassign_state+1;
|
||||
public static final int logicalxor_state = bitwisexor_state+1;
|
||||
public static final int logicalxorassign_state = logicalxor_state+1;
|
||||
public static final int leftbrace_state = logicalxorassign_state+1;
|
||||
public static final int logicalor_state = leftbrace_state+1;
|
||||
public static final int logicalorassign_state = logicalor_state+1;
|
||||
public static final int orequal_state = logicalorassign_state +1;
|
||||
public static final int or_state = orequal_state +1;
|
||||
public static final int rightbrace_state = or_state +1;
|
||||
public static final int squiggle_state = rightbrace_state +1;
|
||||
public static final int plusplus_state = squiggle_state +1;
|
||||
public static final int plusequal_state = plusplus_state +1;
|
||||
public static final int plus_state = plusequal_state +1;
|
||||
public static final int leftshiftequal_state = plus_state +1;
|
||||
public static final int leftshift_state = leftshiftequal_state +1;
|
||||
public static final int lessthanorequal_state = leftshift_state +1;
|
||||
public static final int lessthan_state = lessthanorequal_state +1;
|
||||
public static final int equal_state = lessthan_state +1;
|
||||
public static final int equalequal_state = equal_state +1;
|
||||
public static final int greaterthanorequal_state = equalequal_state +1;
|
||||
public static final int rightshiftequal_state = greaterthanorequal_state +1;
|
||||
public static final int unsignedrightshift_state = rightshiftequal_state +1;
|
||||
public static final int unsignedrightshiftequal_state = unsignedrightshift_state +1;
|
||||
public static final int rightshift_state = unsignedrightshiftequal_state+1;
|
||||
public static final int greaterthan_state = rightshift_state +1;
|
||||
public static final int A_state = greaterthan_state +1;
|
||||
public static final int N_state = A_state +1;
|
||||
public static final int AA_state = N_state +1;
|
||||
public static final int AN_state = AA_state +1;
|
||||
public static final int singlequote_state = AN_state +1;
|
||||
public static final int doublequote_state = singlequote_state +1;
|
||||
public static final int zero_state = doublequote_state +1;
|
||||
public static final int decimalinteger_state = zero_state +1;
|
||||
public static final int decimal_state = decimalinteger_state +1;
|
||||
public static final int exponent_state = decimal_state +1;
|
||||
public static final int hexinteger_state = exponent_state +1;
|
||||
public static final int octalinteger_state = hexinteger_state +1;
|
||||
public static final int slashregexp_state = octalinteger_state +1;
|
||||
public static final int slashdiv_state = slashregexp_state +1;
|
||||
public static final int regexp_state = slashdiv_state +1;
|
||||
public static final int regexpg_state = regexp_state +1;
|
||||
public static final int regexpi_state = regexpg_state +1;
|
||||
public static final int regexpm_state = regexpi_state +1;
|
||||
public static final int regexpgi_state = regexpm_state +1;
|
||||
public static final int regexpgm_state = regexpgi_state +1;
|
||||
public static final int regexpim_state = regexpgm_state +1;
|
||||
public static final int regexpgim_state = regexpim_state +1;
|
||||
public static final int pound_state = regexpgim_state +1;
|
||||
public static final int ampersand_state = pound_state +1;
|
||||
public static final int arrow_state = ampersand_state +1;
|
||||
|
||||
public static final int a_state = arrow_state+1;
|
||||
public static final int ab_state = a_state+1;
|
||||
public static final int abs_state = ab_state+1;
|
||||
public static final int abst_state = abs_state+1;
|
||||
public static final int abstr_state = abst_state+1;
|
||||
public static final int abstra_state = abstr_state+1;
|
||||
public static final int abstrac_state = abstra_state+1;
|
||||
public static final int abstract_state = abstrac_state+1;
|
||||
public static final int at_state = abstract_state +1;
|
||||
public static final int att_state = at_state+1;
|
||||
public static final int attr_state = att_state+1;
|
||||
public static final int attri_state = attr_state+1;
|
||||
public static final int attrib_state = attri_state+1;
|
||||
public static final int attribu_state = attrib_state+1;
|
||||
public static final int attribut_state = attribu_state+1;
|
||||
public static final int attribute_state = attribut_state+1;
|
||||
public static final int b_state = attribute_state+1;
|
||||
public static final int bo_state = b_state+1;
|
||||
public static final int boo_state = bo_state+1;
|
||||
public static final int bool_state = boo_state+1;
|
||||
public static final int boole_state = bool_state+1;
|
||||
public static final int boolea_state = boole_state+1;
|
||||
public static final int boolean_state = boolea_state+1;
|
||||
public static final int br_state = boolean_state+1;
|
||||
public static final int bre_state = br_state+1;
|
||||
public static final int brea_state = bre_state+1;
|
||||
public static final int break_state = brea_state+1;
|
||||
public static final int by_state = break_state+1;
|
||||
public static final int byt_state = by_state+1;
|
||||
public static final int byte_state = byt_state+1;
|
||||
public static final int c_state = byte_state+1;
|
||||
public static final int ca_state = c_state+1;
|
||||
public static final int cas_state = ca_state+1;
|
||||
public static final int case_state = cas_state+1;
|
||||
public static final int cat_state = case_state+1;
|
||||
public static final int catc_state = cat_state+1;
|
||||
public static final int catch_state = catc_state+1;
|
||||
public static final int ch_state = catch_state+1;
|
||||
public static final int cha_state = ch_state+1;
|
||||
public static final int char_state = cha_state+1;
|
||||
public static final int cl_state = char_state+1;
|
||||
public static final int cla_state = cl_state+1;
|
||||
public static final int clas_state = cla_state+1;
|
||||
public static final int class_state = clas_state+1;
|
||||
public static final int co_state = class_state+1;
|
||||
public static final int con_state = co_state+1;
|
||||
public static final int cont_state = con_state+1;
|
||||
public static final int conti_state = cont_state+1;
|
||||
public static final int contin_state = conti_state+1;
|
||||
public static final int continu_state = contin_state+1;
|
||||
public static final int continue_state = continu_state+1;
|
||||
public static final int cons_state = continue_state+1;
|
||||
public static final int const_state = cons_state+1;
|
||||
public static final int constr_state = const_state+1;
|
||||
public static final int constru_state = constr_state+1;
|
||||
public static final int construc_state = constru_state+1;
|
||||
public static final int construct_state = construc_state+1;
|
||||
public static final int constructo_state = construct_state+1;
|
||||
public static final int constructor_state = constructo_state+1;
|
||||
public static final int d_state = constructor_state+1;
|
||||
public static final int de_state = d_state+1;
|
||||
public static final int deb_state = de_state+1;
|
||||
public static final int debu_state = deb_state+1;
|
||||
public static final int debug_state = debu_state+1;
|
||||
public static final int debugg_state = debug_state+1;
|
||||
public static final int debugge_state = debugg_state+1;
|
||||
public static final int debugger_state = debugge_state+1;
|
||||
public static final int def_state = debugger_state+1;
|
||||
public static final int defa_state = def_state+1;
|
||||
public static final int defau_state = defa_state+1;
|
||||
public static final int defaul_state = defau_state+1;
|
||||
public static final int default_state = defaul_state+1;
|
||||
public static final int del_state = default_state+1;
|
||||
public static final int dele_state = del_state+1;
|
||||
public static final int delet_state = dele_state+1;
|
||||
public static final int delete_state = delet_state+1;
|
||||
public static final int do_state = delete_state+1;
|
||||
public static final int dou_state = do_state+1;
|
||||
public static final int doub_state = dou_state+1;
|
||||
public static final int doubl_state = doub_state+1;
|
||||
public static final int double_state = doubl_state+1;
|
||||
public static final int e_state = double_state+1;
|
||||
public static final int el_state = e_state+1;
|
||||
public static final int els_state = el_state+1;
|
||||
public static final int else_state = els_state+1;
|
||||
public static final int en_state = else_state+1;
|
||||
public static final int enu_state = en_state+1;
|
||||
public static final int enum_state = enu_state+1;
|
||||
public static final int ev_state = enum_state+1;
|
||||
public static final int eva_state = ev_state+1;
|
||||
public static final int eval_state = eva_state+1;
|
||||
public static final int ex_state = eval_state+1;
|
||||
public static final int exp_state = ex_state+1;
|
||||
public static final int expo_state = exp_state+1;
|
||||
public static final int expor_state = expo_state+1;
|
||||
public static final int export_state = expor_state+1;
|
||||
public static final int ext_state = export_state+1;
|
||||
public static final int exte_state = ext_state+1;
|
||||
public static final int exten_state = exte_state+1;
|
||||
public static final int extend_state = exten_state+1;
|
||||
public static final int extends_state = extend_state+1;
|
||||
public static final int f_state = extends_state+1;
|
||||
public static final int fa_state = f_state+1;
|
||||
public static final int fal_state = fa_state+1;
|
||||
public static final int fals_state = fal_state+1;
|
||||
public static final int false_state = fals_state+1;
|
||||
public static final int fi_state = false_state+1;
|
||||
public static final int fin_state = fi_state+1;
|
||||
public static final int fina_state = fin_state+1;
|
||||
public static final int final_state = fina_state+1;
|
||||
public static final int finall_state = final_state+1;
|
||||
public static final int finally_state = finall_state+1;
|
||||
public static final int fl_state = finally_state+1;
|
||||
public static final int flo_state = fl_state+1;
|
||||
public static final int floa_state = flo_state+1;
|
||||
public static final int float_state = floa_state+1;
|
||||
public static final int fo_state = float_state+1;
|
||||
public static final int for_state = fo_state+1;
|
||||
public static final int fu_state = for_state+1;
|
||||
public static final int fun_state = fu_state+1;
|
||||
public static final int func_state = fun_state+1;
|
||||
public static final int funct_state = func_state+1;
|
||||
public static final int functi_state = funct_state+1;
|
||||
public static final int functio_state = functi_state+1;
|
||||
public static final int function_state = functio_state+1;
|
||||
public static final int g_state = function_state+1;
|
||||
public static final int go_state = g_state+1;
|
||||
public static final int got_state = go_state+1;
|
||||
public static final int goto_state = got_state+1;
|
||||
public static final int i_state = goto_state+1;
|
||||
public static final int if_state = i_state+1;
|
||||
public static final int im_state = if_state+1;
|
||||
public static final int imp_state = im_state+1;
|
||||
public static final int impl_state = imp_state+1;
|
||||
public static final int imple_state = impl_state+1;
|
||||
public static final int implem_state = imple_state+1;
|
||||
public static final int impleme_state = implem_state+1;
|
||||
public static final int implemen_state = impleme_state+1;
|
||||
public static final int implement_state = implemen_state+1;
|
||||
public static final int implements_state = implement_state+1;
|
||||
public static final int impo_state = implements_state+1;
|
||||
public static final int impor_state = impo_state+1;
|
||||
public static final int import_state = impor_state+1;
|
||||
public static final int in_state = import_state+1;
|
||||
public static final int inc_state = in_state+1;
|
||||
public static final int incl_state = inc_state+1;
|
||||
public static final int inclu_state = incl_state+1;
|
||||
public static final int includ_state = inclu_state+1;
|
||||
public static final int include_state = includ_state+1;
|
||||
public static final int ins_state = include_state+1;
|
||||
public static final int inst_state = ins_state+1;
|
||||
public static final int insta_state = inst_state+1;
|
||||
public static final int instan_state = insta_state+1;
|
||||
public static final int instanc_state = instan_state+1;
|
||||
public static final int instance_state = instanc_state+1;
|
||||
public static final int instanceo_state = instance_state+1;
|
||||
public static final int instanceof_state = instanceo_state+1;
|
||||
public static final int int_state = instanceof_state+1;
|
||||
public static final int inte_state = int_state+1;
|
||||
public static final int inter_state = inte_state+1;
|
||||
public static final int interf_state = inter_state+1;
|
||||
public static final int interfa_state = interf_state+1;
|
||||
public static final int interfac_state = interfa_state+1;
|
||||
public static final int interface_state = interfac_state+1;
|
||||
public static final int l_state = interface_state+1;
|
||||
public static final int lo_state = l_state+1;
|
||||
public static final int lon_state = lo_state+1;
|
||||
public static final int long_state = lon_state+1;
|
||||
public static final int n_state = long_state+1;
|
||||
public static final int na_state = n_state+1;
|
||||
public static final int nam_state = na_state+1;
|
||||
public static final int name_state = nam_state+1;
|
||||
public static final int names_state = name_state+1;
|
||||
public static final int namesp_state = names_state+1;
|
||||
public static final int namespa_state = namesp_state+1;
|
||||
public static final int namespac_state = namespa_state+1;
|
||||
public static final int namespace_state = namespac_state+1;
|
||||
public static final int nat_state = namespace_state+1;
|
||||
public static final int nati_state = nat_state+1;
|
||||
public static final int nativ_state = nati_state+1;
|
||||
public static final int native_state = nativ_state+1;
|
||||
public static final int ne_state = native_state+1;
|
||||
public static final int new_state = ne_state+1;
|
||||
public static final int nu_state = new_state+1;
|
||||
public static final int nul_state = nu_state+1;
|
||||
public static final int null_state = nul_state+1;
|
||||
public static final int r_state = null_state+1;
|
||||
public static final int re_state = r_state+1;
|
||||
public static final int ret_state = re_state+1;
|
||||
public static final int retu_state = ret_state+1;
|
||||
public static final int retur_state = retu_state+1;
|
||||
public static final int return_state = retur_state +1;
|
||||
public static final int p_state = return_state +1;
|
||||
public static final int pa_state = p_state +1;
|
||||
public static final int pac_state = pa_state +1;
|
||||
public static final int pack_state = pac_state +1;
|
||||
public static final int packa_state = pack_state +1;
|
||||
public static final int packag_state = packa_state +1;
|
||||
public static final int package_state = packag_state +1;
|
||||
public static final int pr_state = package_state +1;
|
||||
public static final int pri_state = pr_state +1;
|
||||
public static final int priv_state = pri_state +1;
|
||||
public static final int priva_state = priv_state +1;
|
||||
public static final int privat_state = priva_state +1;
|
||||
public static final int private_state = privat_state +1;
|
||||
public static final int pro_state = private_state +1;
|
||||
public static final int prot_state = pro_state +1;
|
||||
public static final int prote_state = prot_state +1;
|
||||
public static final int protec_state = prote_state +1;
|
||||
public static final int protect_state = protec_state +1;
|
||||
public static final int protecte_state = protect_state +1;
|
||||
public static final int protected_state = protecte_state +1;
|
||||
public static final int pu_state = protected_state +1;
|
||||
public static final int pub_state = pu_state +1;
|
||||
public static final int publ_state = pub_state +1;
|
||||
public static final int publi_state = publ_state +1;
|
||||
public static final int public_state = publi_state +1;
|
||||
public static final int s_state = public_state +1;
|
||||
public static final int sh_state = s_state +1;
|
||||
public static final int sho_state = sh_state +1;
|
||||
public static final int shor_state = sho_state +1;
|
||||
public static final int short_state = shor_state +1;
|
||||
public static final int st_state = short_state +1;
|
||||
public static final int sta_state = st_state +1;
|
||||
public static final int stat_state = sta_state +1;
|
||||
public static final int stati_state = stat_state +1;
|
||||
public static final int static_state = stati_state +1;
|
||||
public static final int su_state = static_state +1;
|
||||
public static final int sup_state = su_state +1;
|
||||
public static final int supe_state = sup_state +1;
|
||||
public static final int super_state = supe_state +1;
|
||||
public static final int sw_state = super_state +1;
|
||||
public static final int swi_state = sw_state +1;
|
||||
public static final int swit_state = swi_state +1;
|
||||
public static final int switc_state = swit_state +1;
|
||||
public static final int switch_state = switc_state +1;
|
||||
public static final int sy_state = switch_state +1;
|
||||
public static final int syn_state = sy_state +1;
|
||||
public static final int sync_state = syn_state +1;
|
||||
public static final int synch_state = sync_state +1;
|
||||
public static final int synchr_state = synch_state +1;
|
||||
public static final int synchro_state = synchr_state +1;
|
||||
public static final int synchron_state = synchro_state +1;
|
||||
public static final int synchroni_state = synchron_state +1;
|
||||
public static final int synchroniz_state = synchroni_state +1;
|
||||
public static final int synchronize_state = synchroniz_state +1;
|
||||
public static final int synchronized_state = synchronize_state +1;
|
||||
public static final int t_state = synchronized_state+1;
|
||||
public static final int th_state = t_state +1;
|
||||
public static final int thi_state = th_state +1;
|
||||
public static final int this_state = thi_state +1;
|
||||
public static final int thr_state = this_state +1;
|
||||
public static final int thro_state = thr_state +1;
|
||||
public static final int throw_state = thro_state +1;
|
||||
public static final int throws_state = throw_state +1;
|
||||
public static final int tr_state = throws_state +1;
|
||||
public static final int tra_state = tr_state +1;
|
||||
public static final int tran_state = tra_state +1;
|
||||
public static final int trans_state = tran_state +1;
|
||||
public static final int transi_state = trans_state +1;
|
||||
public static final int transie_state = transi_state +1;
|
||||
public static final int transien_state = transie_state +1;
|
||||
public static final int transient_state = transien_state +1;
|
||||
public static final int tru_state = transient_state +1;
|
||||
public static final int true_state = tru_state +1;
|
||||
public static final int try_state = true_state +1;
|
||||
public static final int ty_state = try_state +1;
|
||||
public static final int typ_state = ty_state +1;
|
||||
public static final int type_state = typ_state +1;
|
||||
public static final int typeo_state = type_state +1;
|
||||
public static final int typeof_state = typeo_state +1;
|
||||
public static final int u_state = typeof_state +1;
|
||||
public static final int us_state = u_state+1;
|
||||
public static final int use_state = us_state+1;
|
||||
public static final int v_state = use_state+1;
|
||||
public static final int va_state = v_state +1;
|
||||
public static final int var_state = va_state +1;
|
||||
public static final int vo_state = var_state +1;
|
||||
public static final int vol_state = vo_state +1;
|
||||
public static final int vola_state = vol_state +1;
|
||||
public static final int volat_state = vola_state +1;
|
||||
public static final int volati_state = volat_state +1;
|
||||
public static final int volatil_state = volati_state +1;
|
||||
public static final int volatile_state = volatil_state +1;
|
||||
public static final int voi_state = volatile_state +1;
|
||||
public static final int void_state = voi_state +1;
|
||||
public static final int w_state = void_state +1;
|
||||
public static final int wh_state = w_state +1;
|
||||
public static final int whi_state = wh_state +1;
|
||||
public static final int whil_state = whi_state +1;
|
||||
public static final int while_state = whil_state +1;
|
||||
public static final int wi_state = while_state +1;
|
||||
public static final int wit_state = wi_state +1;
|
||||
public static final int with_state = wit_state +1;
|
||||
|
||||
public static final int blockcomment_state = with_state+1;
|
||||
public static final int blockcommentstar_state = blockcomment_state+1;
|
||||
public static final int linecomment_state = blockcommentstar_state+1;
|
||||
public static final int eol_state = linecomment_state+1;
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* Token.java
|
||||
*
|
||||
* This file implements the class Token that is used to carry
|
||||
* information from the Scanner to the Parser.
|
||||
*/
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public final class Token implements Tokens {
|
||||
|
||||
int tokenClass;
|
||||
String lexeme;
|
||||
|
||||
public Token( int tokenClass, String lexeme ) {
|
||||
this.tokenClass = tokenClass;
|
||||
this.lexeme = lexeme;
|
||||
}
|
||||
|
||||
public final int getTokenClass() {
|
||||
return tokenClass;
|
||||
}
|
||||
|
||||
public final String getTokenText() {
|
||||
if( tokenClass == stringliteral_token ) {
|
||||
// erase quotes.
|
||||
return lexeme.substring(1,lexeme.length()-1);
|
||||
}
|
||||
return lexeme;
|
||||
}
|
||||
|
||||
public final String getTokenSource() {
|
||||
return lexeme;
|
||||
}
|
||||
|
||||
public static String getTokenClassName( int token_class ) {
|
||||
return tokenClassNames[-1*token_class];
|
||||
}
|
||||
|
||||
/**
|
||||
* main()
|
||||
*
|
||||
* Unit test driver. Execute the command 'java Token' at the
|
||||
* shell to verify this class' basic functionality.
|
||||
*/
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Token begin");
|
||||
for(int i = 0; i>=stringliteral_token;i--) {
|
||||
System.out.println(tokenClassNames[-1*i]);
|
||||
}
|
||||
System.out.println("Token end");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,325 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* Tokens.java
|
||||
*
|
||||
* This interface defines values for each token class that occurs in
|
||||
* ECMAScript 4. All but numericliteral, stringliteral, regexpliteral, and
|
||||
* identifier are singleton and therefore a fully described by their
|
||||
* token class defined here. The other four however can have an infinite number
|
||||
* of instances each with a unique identifier and associated instance
|
||||
* data. We use positive identifiers to signify instances of these
|
||||
* token classes so that the instance data can be stored in an array,
|
||||
* or set of arrays with the token value specifying its index.
|
||||
*/
|
||||
|
||||
public interface Tokens {
|
||||
|
||||
/**
|
||||
* Token class values are negative, and token instances are positive so
|
||||
* that their values can point to their instance data in an array.
|
||||
*/
|
||||
|
||||
public static final int first_token = -1;
|
||||
public static final int eos_token = first_token-0;
|
||||
|
||||
public static final int minus_token = first_token - 1;
|
||||
public static final int minusminus_token = minus_token - 1;
|
||||
public static final int not_token = minusminus_token - 1;
|
||||
public static final int notequals_token = not_token - 1;
|
||||
public static final int strictnotequals_token = notequals_token - 1;
|
||||
public static final int pound_token = strictnotequals_token - 1;
|
||||
public static final int modulus_token = pound_token - 1;
|
||||
public static final int modulusassign_token = modulus_token - 1;
|
||||
public static final int bitwiseand_token = modulusassign_token - 1;
|
||||
public static final int logicaland_token = bitwiseand_token - 1;
|
||||
public static final int logicalandassign_token = logicaland_token - 1;
|
||||
public static final int bitwiseandassign_token = logicalandassign_token - 1;
|
||||
public static final int leftparen_token = bitwiseandassign_token - 1;
|
||||
public static final int rightparen_token = leftparen_token - 1;
|
||||
public static final int mult_token = rightparen_token - 1;
|
||||
public static final int multassign_token = mult_token - 1;
|
||||
public static final int comma_token = multassign_token - 1;
|
||||
public static final int dot_token = comma_token - 1;
|
||||
public static final int doubledot_token = dot_token - 1;
|
||||
public static final int tripledot_token = doubledot_token - 1;
|
||||
public static final int div_token = tripledot_token - 1;
|
||||
public static final int divassign_token = div_token - 1;
|
||||
public static final int colon_token = divassign_token - 1;
|
||||
public static final int doublecolon_token = colon_token - 1;
|
||||
public static final int semicolon_token = doublecolon_token - 1;
|
||||
public static final int questionmark_token = semicolon_token - 1;
|
||||
public static final int ampersand_token = questionmark_token - 1;
|
||||
public static final int leftbracket_token = ampersand_token - 1;
|
||||
public static final int rightbracket_token = leftbracket_token - 1 ;
|
||||
public static final int bitwisexor_token = rightbracket_token - 1;
|
||||
public static final int logicalxor_token = bitwisexor_token - 1;
|
||||
public static final int logicalxorassign_token = logicalxor_token - 1;
|
||||
public static final int bitwisexorassign_token = logicalxorassign_token - 1;
|
||||
public static final int leftbrace_token = bitwisexorassign_token - 1;
|
||||
public static final int bitwiseor_token = leftbrace_token - 1;
|
||||
public static final int logicalor_token = bitwiseor_token - 1;
|
||||
public static final int logicalorassign_token = logicalor_token - 1;
|
||||
public static final int bitwiseorassign_token = logicalorassign_token - 1;
|
||||
public static final int rightbrace_token = bitwiseorassign_token - 1;
|
||||
public static final int bitwisenot_token = rightbrace_token - 1;
|
||||
public static final int plus_token = bitwisenot_token - 1;
|
||||
public static final int plusplus_token = plus_token - 1;
|
||||
public static final int plusassign_token = plusplus_token - 1;
|
||||
public static final int lessthan_token = plusassign_token - 1;
|
||||
public static final int leftshift_token = lessthan_token - 1;
|
||||
public static final int leftshiftassign_token = leftshift_token - 1;
|
||||
public static final int lessthanorequals_token = leftshiftassign_token - 1;
|
||||
public static final int assign_token = lessthanorequals_token - 1;
|
||||
public static final int minusassign_token = assign_token - 1;
|
||||
public static final int equals_token = minusassign_token - 1;
|
||||
public static final int strictequals_token = equals_token - 1;
|
||||
public static final int greaterthan_token = strictequals_token - 1;
|
||||
public static final int arrow_token = greaterthan_token - 1;
|
||||
public static final int greaterthanorequals_token = arrow_token - 1;
|
||||
public static final int rightshift_token = greaterthanorequals_token - 1;
|
||||
public static final int rightshiftassign_token = rightshift_token - 1;
|
||||
public static final int unsignedrightshift_token = rightshiftassign_token - 1;
|
||||
public static final int unsignedrightshiftassign_token = unsignedrightshift_token - 1;
|
||||
public static final int abstract_token = unsignedrightshiftassign_token - 1;
|
||||
public static final int attribute_token = abstract_token - 1;
|
||||
public static final int boolean_token = attribute_token - 1;
|
||||
public static final int break_token = boolean_token - 1;
|
||||
public static final int byte_token = break_token - 1;
|
||||
public static final int case_token = byte_token - 1;
|
||||
public static final int catch_token = case_token - 1;
|
||||
public static final int char_token = catch_token - 1;
|
||||
public static final int class_token = char_token - 1;
|
||||
public static final int const_token = class_token - 1;
|
||||
public static final int constructor_token = const_token - 1;
|
||||
public static final int continue_token = constructor_token - 1;
|
||||
public static final int debugger_token = continue_token - 1;
|
||||
public static final int default_token = debugger_token - 1;
|
||||
public static final int delete_token = default_token - 1;
|
||||
public static final int do_token = delete_token - 1;
|
||||
public static final int double_token = do_token - 1;
|
||||
public static final int else_token = double_token - 1;
|
||||
public static final int enum_token = else_token - 1;
|
||||
public static final int eval_token = enum_token - 1;
|
||||
public static final int export_token = eval_token - 1;
|
||||
public static final int extends_token = export_token - 1;
|
||||
public static final int false_token = extends_token - 1;
|
||||
public static final int final_token = false_token - 1;
|
||||
public static final int finally_token = final_token - 1;
|
||||
public static final int float_token = finally_token - 1;
|
||||
public static final int for_token = float_token - 1;
|
||||
public static final int function_token = for_token - 1;
|
||||
public static final int get_token = function_token - 1;
|
||||
public static final int goto_token = get_token - 1;
|
||||
public static final int if_token = goto_token - 1;
|
||||
public static final int implements_token = if_token - 1;
|
||||
public static final int import_token = implements_token - 1;
|
||||
public static final int in_token = import_token - 1;
|
||||
public static final int include_token = in_token - 1;
|
||||
public static final int instanceof_token = include_token - 1;
|
||||
public static final int int_token = instanceof_token - 1;
|
||||
public static final int interface_token = int_token - 1;
|
||||
public static final int long_token = interface_token - 1;
|
||||
public static final int namespace_token = long_token - 1;
|
||||
public static final int native_token = namespace_token - 1;
|
||||
public static final int new_token = native_token - 1;
|
||||
public static final int null_token = new_token - 1;
|
||||
public static final int package_token = null_token - 1;
|
||||
public static final int private_token = package_token - 1;
|
||||
public static final int protected_token = private_token - 1;
|
||||
public static final int public_token = protected_token - 1;
|
||||
public static final int return_token = public_token - 1;
|
||||
public static final int set_token = return_token - 1;
|
||||
public static final int short_token = set_token - 1;
|
||||
public static final int static_token = short_token - 1;
|
||||
public static final int super_token = static_token - 1;
|
||||
public static final int switch_token = super_token - 1;
|
||||
public static final int synchronized_token = switch_token - 1;
|
||||
public static final int this_token = synchronized_token - 1;
|
||||
public static final int throw_token = this_token - 1;
|
||||
public static final int throws_token = throw_token - 1;
|
||||
public static final int transient_token = throws_token - 1;
|
||||
public static final int true_token = transient_token - 1;
|
||||
public static final int try_token = true_token - 1;
|
||||
public static final int typeof_token = try_token - 1;
|
||||
public static final int use_token = typeof_token - 1;
|
||||
public static final int var_token = use_token - 1;
|
||||
public static final int void_token = var_token - 1;
|
||||
public static final int volatile_token = void_token - 1;
|
||||
public static final int while_token = volatile_token - 1;
|
||||
public static final int with_token = while_token - 1;
|
||||
public static final int identifier_token = with_token - 1;
|
||||
public static final int numberliteral_token = identifier_token - 1;
|
||||
public static final int regexpliteral_token = numberliteral_token - 1;
|
||||
public static final int stringliteral_token = regexpliteral_token - 1;
|
||||
|
||||
public static final int eol_token = stringliteral_token - 1;
|
||||
|
||||
public static final int empty_token = eol_token - 1;
|
||||
public static final int error_token = empty_token - 1;
|
||||
public static final int last_token = empty_token - 1;
|
||||
|
||||
public static final String[] tokenClassNames = {
|
||||
"<unused index>",
|
||||
"<eos>",
|
||||
"minus_token",
|
||||
"minusminus_token",
|
||||
"not_token",
|
||||
"notequals_token",
|
||||
"strictnotequals_token",
|
||||
"pound_token",
|
||||
"modulus_token",
|
||||
"modulusassign_token",
|
||||
"bitwiseand_token",
|
||||
"logicaland_token",
|
||||
"logicalandassign_token",
|
||||
"bitwiseandassign_token",
|
||||
"leftparen_token",
|
||||
"rightparen_token",
|
||||
"mult_token",
|
||||
"multassign_token",
|
||||
"comma_token",
|
||||
"dot_token",
|
||||
"doubledot_token",
|
||||
"tripledot_token",
|
||||
"div_token",
|
||||
"divassign_token",
|
||||
"colon_token",
|
||||
"doublecolon_token",
|
||||
"semicolon_token",
|
||||
"questionmark_token",
|
||||
"ampersand_token",
|
||||
"leftbracket_token",
|
||||
"rightbracket_token",
|
||||
"bitwisexor_token",
|
||||
"logicalxor_token",
|
||||
"logicalxorassign_token",
|
||||
"bitwisexorassign_token",
|
||||
"leftbrace_token",
|
||||
"bitwiseor_token",
|
||||
"logicalor_token",
|
||||
"logicalorassign_token",
|
||||
"bitwiseorassign_token",
|
||||
"rightbrace_token",
|
||||
"bitwisenot_token",
|
||||
"plus_token",
|
||||
"plusplus_token",
|
||||
"plusassign_token",
|
||||
"lessthan_token",
|
||||
"leftshift_token",
|
||||
"leftshiftassign_token",
|
||||
"lessthanorequals_token",
|
||||
"assign_token",
|
||||
"minusassign_token",
|
||||
"equals_token",
|
||||
"strictequals_token",
|
||||
"greaterthan_token",
|
||||
"arrow_token",
|
||||
"greaterthanorequals_token",
|
||||
"rightshift_token",
|
||||
"rightshiftassign_token",
|
||||
"unsignedrightshift_token",
|
||||
"unsignedrightshiftassign_token",
|
||||
"abstract_token",
|
||||
"attribute_token",
|
||||
"boolean_token",
|
||||
"break_token",
|
||||
"byte_token",
|
||||
"case_token",
|
||||
"catch_token",
|
||||
"char_token",
|
||||
"class_token",
|
||||
"const_token",
|
||||
"constructor_token",
|
||||
"continue_token",
|
||||
"debugger_token",
|
||||
"default_token",
|
||||
"delete_token",
|
||||
"do_token",
|
||||
"double_token",
|
||||
"else_token",
|
||||
"enum_token",
|
||||
"eval_token",
|
||||
"export_token",
|
||||
"extends_token",
|
||||
"false_token",
|
||||
"final_token",
|
||||
"finally_token",
|
||||
"float_token",
|
||||
"for_token",
|
||||
"function_token",
|
||||
"get_token",
|
||||
"goto_token",
|
||||
"if_token",
|
||||
"implements_token",
|
||||
"import_token",
|
||||
"in_token",
|
||||
"include_token",
|
||||
"instanceof_token",
|
||||
"int_token",
|
||||
"interface_token",
|
||||
"long_token",
|
||||
"namespace_token",
|
||||
"native_token",
|
||||
"new_token",
|
||||
"null_token",
|
||||
"package_token",
|
||||
"private_token",
|
||||
"protected_token",
|
||||
"public_token",
|
||||
"return_token",
|
||||
"set_token",
|
||||
"short_token",
|
||||
"static_token",
|
||||
"super_token",
|
||||
"switch_token",
|
||||
"synchronized_token",
|
||||
"this_token",
|
||||
"throw_token",
|
||||
"throws_token",
|
||||
"transient_token",
|
||||
"true_token",
|
||||
"try_token",
|
||||
"typeof_token",
|
||||
"use_token",
|
||||
"var_token",
|
||||
"void_token",
|
||||
"volatile_token",
|
||||
"while_token",
|
||||
"with_token",
|
||||
"identifier_token",
|
||||
"numberliteral_token",
|
||||
"regexpliteral_token",
|
||||
"stringliteral_token",
|
||||
|
||||
"<eol>",
|
||||
"<empty>",
|
||||
"<error>"
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
import com.compilercompany.ecmascript.*;
|
||||
import sun.tools.util.CommandLine;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
String[] classes;
|
||||
|
||||
/**
|
||||
* Entry point.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
/* Preprocess @file arguments */
|
||||
try {
|
||||
args = CommandLine.parse(args);
|
||||
} catch (FileNotFoundException e) {
|
||||
Util.error("at.args.cant.read", e.getMessage());
|
||||
} catch (IOException e) {
|
||||
Util.error("at.args.io.exception", e.getMessage());
|
||||
}
|
||||
|
||||
new Main(args).run();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse options.
|
||||
*/
|
||||
|
||||
private static boolean traceInput = false;
|
||||
private static boolean traceLexer = false;
|
||||
private static boolean traceParser = false;
|
||||
private static boolean debug = false;
|
||||
|
||||
|
||||
public Main(String[] args) {
|
||||
if (args.length == 0) {
|
||||
Util.usage(1);
|
||||
}
|
||||
|
||||
/* Default values for options, overridden by user options. */
|
||||
|
||||
int i = 0;
|
||||
for (; i < args.length; i++) {
|
||||
if (args[i].equals("-i")||args[i].equals("-input")) {
|
||||
traceInput = true;
|
||||
} else if (args[i].equals("-l")||args[i].equals("-lexer")) {
|
||||
traceLexer = true;
|
||||
} else if (args[i].equals("-p")||args[i].equals("-parser")) {
|
||||
traceParser = true;
|
||||
} else if (args[i].equals("-d")||args[i].equals("-debug")) {
|
||||
debug = true;
|
||||
} else if (args[i].charAt(0) == '-') {
|
||||
Util.error("unknown.option", args[i], null, true);
|
||||
} else {
|
||||
break; /* The rest must be classes. */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Arrange for output destination.
|
||||
*/
|
||||
|
||||
/*
|
||||
if (odir != null && ofile != null)
|
||||
Util.error("dir.file.mixed");
|
||||
if (odir != null)
|
||||
; //setOutDir(odir);
|
||||
if (ofile != null)
|
||||
Debugger.setOutFile(ofile);
|
||||
*/
|
||||
|
||||
/*
|
||||
* Grab the rest of argv[] ... this must be the classes.
|
||||
*/
|
||||
classes = new String[args.length - i];
|
||||
System.arraycopy(args, i, classes, 0, args.length - i);
|
||||
|
||||
if (classes.length == 0) {
|
||||
Util.error("no.classes.specified");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
compile("",classes);
|
||||
} catch (Exception x) {
|
||||
x.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
static final void compile(String name, String[] input) throws Exception {
|
||||
|
||||
Debugger.trace( "begin testEvaluator: " + name );
|
||||
|
||||
String result;
|
||||
Node node;
|
||||
Value type;
|
||||
Evaluator evaluator;
|
||||
Value value;
|
||||
|
||||
Class pc = Parser.class;
|
||||
Class[] args = new Class[0];
|
||||
|
||||
Parser parser;
|
||||
long t=0;
|
||||
|
||||
ObjectValue global = null;
|
||||
|
||||
for( int i = 0; i < input.length; i++ ) {
|
||||
|
||||
try {
|
||||
|
||||
if( traceInput ) {
|
||||
InputBuffer.setOut(input[i]+".inp");
|
||||
} if( traceLexer ) {
|
||||
Scanner.setOut(input[i]+".lex");
|
||||
} if( debug ) {
|
||||
Debugger.setDbgFile( input[i]+".dbg" );
|
||||
}
|
||||
|
||||
Debugger.setErrFile( input[i]+".err" );
|
||||
|
||||
FileInputStream srcfile = new FileInputStream( input[i] );
|
||||
InputStreamReader reader = new InputStreamReader( srcfile );
|
||||
|
||||
Context context = new Context();
|
||||
global = new ObjectValue("__systemGlobal", new GlobalObject());
|
||||
context.pushScope(global);
|
||||
|
||||
parser = new Parser(reader);
|
||||
Evaluator cevaluator = new ConstantEvaluator();
|
||||
|
||||
System.gc();
|
||||
t = System.currentTimeMillis();
|
||||
node = parser.parseProgram();
|
||||
if( traceParser ) {
|
||||
Debugger.trace("setting parser output to " + input[i]);
|
||||
JSILGenerator.setOut( input[i]+".par" );
|
||||
node.evaluate(context,new JSILGenerator());
|
||||
}
|
||||
|
||||
//Evaluator evaluator;
|
||||
|
||||
|
||||
context.setEvaluator(new BlockEvaluator());
|
||||
node.evaluate(context, context.getEvaluator());
|
||||
|
||||
JSILGenerator.setOut( input[i]+".blocks" );
|
||||
context.setEvaluator(new JSILGenerator());
|
||||
node.evaluate(context, context.getEvaluator());
|
||||
|
||||
context.setEvaluator(new ConstantEvaluator());
|
||||
value = node.evaluate(context, context.getEvaluator());
|
||||
|
||||
context.setEvaluator(new JSILGenerator());
|
||||
JSILGenerator.setOut( input[i]+".jsil" );
|
||||
node.evaluate(context, context.getEvaluator());
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
//Debugger.trace(""+global);
|
||||
System.out.println(input[i] + ": "+context.errorCount()+" errors [" + Long.toString(t) + " msec] --> " + value.getValue(context) );
|
||||
|
||||
} catch( Exception x ) {
|
||||
x.printStackTrace();
|
||||
t = System.currentTimeMillis() - t;
|
||||
System.out.println(input[i] + ": internal error" );
|
||||
}
|
||||
//Debugger.trace( " " + i + " passed in " + Long.toString(t) +
|
||||
// " msec: [" + input[i] + "] = " + result );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,179 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
/**
|
||||
* Messages, verbose and error handling support.
|
||||
*
|
||||
* For errors, the failure modes are:
|
||||
* error -- User did something wrong
|
||||
* bug -- Bug has occurred in javah
|
||||
* fatal -- We can't even find resources, so bail fast, don't localize
|
||||
*
|
||||
* @version 1.6, 02/02/00
|
||||
*/
|
||||
public class Util {
|
||||
|
||||
/*
|
||||
* Help for verbosity.
|
||||
*/
|
||||
public static boolean verbose = false;
|
||||
|
||||
public static void log(String s) {
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Help for loading localized messages.
|
||||
*/
|
||||
private static ResourceBundle m;
|
||||
|
||||
private static void initMessages() {
|
||||
try {
|
||||
m=ResourceBundle.getBundle("com.sun.tools.javah.resources.l10n");
|
||||
} catch (MissingResourceException mre) {
|
||||
fatal("Error loading resources. Please file a bug report.", mre);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getText(String key) {
|
||||
return getText(key, null, null);
|
||||
}
|
||||
|
||||
private static String getText(String key, String a1, String a2){
|
||||
if (m == null)
|
||||
initMessages();
|
||||
try {
|
||||
return MessageFormat.format(m.getString(key),
|
||||
new String[] { a1, a2 });
|
||||
} catch (MissingResourceException e) {
|
||||
fatal("Key " + key + " not found in resources.", e);
|
||||
}
|
||||
return null; /* dead code */
|
||||
}
|
||||
|
||||
/*
|
||||
* Usage message.
|
||||
*/
|
||||
public static void usage(int exitValue) {
|
||||
if (exitValue == 0) {
|
||||
System.out.println(getText("usage"));
|
||||
} else {
|
||||
System.err.println(getText("usage"));
|
||||
}
|
||||
System.exit(exitValue);
|
||||
}
|
||||
|
||||
public static void version() {
|
||||
System.out.println(getText("javah.version",
|
||||
System.getProperty("java.version"), null));
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Failure modes.
|
||||
*/
|
||||
public static void bug(String key) {
|
||||
bug(key, null);
|
||||
}
|
||||
|
||||
public static void bug(String key, Exception e) {
|
||||
if (e != null)
|
||||
e.printStackTrace();
|
||||
System.err.println(getText(key));
|
||||
System.err.println(getText("bug.report"));
|
||||
System.exit(11);
|
||||
}
|
||||
|
||||
public static void error(String key) {
|
||||
error(key, null);
|
||||
}
|
||||
|
||||
public static void error(String key, String a1) {
|
||||
error(key, a1, null);
|
||||
}
|
||||
|
||||
public static void error(String key, String a1, String a2) {
|
||||
error(key, a1, a2, false);
|
||||
}
|
||||
|
||||
public static void error(String key, String a1, String a2,
|
||||
boolean showUsage) {
|
||||
System.err.println("Error: " + getText(key, a1, a2));
|
||||
if (showUsage)
|
||||
usage(15);
|
||||
System.exit(15);
|
||||
}
|
||||
|
||||
|
||||
private static void fatal(String msg) {
|
||||
fatal(msg, null);
|
||||
}
|
||||
|
||||
private static void fatal(String msg, Exception e) {
|
||||
if (e != null) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.err.println(msg);
|
||||
System.exit(10);
|
||||
}
|
||||
|
||||
/*
|
||||
* Support for platform specific things in javah, such as pragma
|
||||
* directives, exported symbols etc.
|
||||
*/
|
||||
static ResourceBundle platform = null;
|
||||
|
||||
static String getPlatformString(String key) {
|
||||
if (platform == null)
|
||||
initPlatform();
|
||||
try {
|
||||
return platform.getString(key);
|
||||
} catch (MissingResourceException mre) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void initPlatform() {
|
||||
String os = System.getProperty("os.name");
|
||||
if (os.startsWith("Windows"))
|
||||
os = "win32";
|
||||
String arch = System.getProperty("os.arch");
|
||||
String resname = "com.sun.tools.javah.resources." + os + "_" + arch;
|
||||
try {
|
||||
platform=ResourceBundle.getBundle(resname);
|
||||
} catch (MissingResourceException mre) {
|
||||
fatal("Error loading resources. Please file a bug report.", mre);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
interface Attributes {
|
||||
static final int ReadOnly = 0x00000001;
|
||||
static final int DontDelete = 0x00000002;
|
||||
static final int DontEnum = 0x00000004;
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class Block
|
||||
*/
|
||||
|
||||
public class Block {
|
||||
Node entry, exit;
|
||||
|
||||
int n;
|
||||
|
||||
Block(int n) {
|
||||
this.n = n;
|
||||
}
|
||||
|
||||
void setEntry( Node entry ) {
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
void setExit( Node exit ) {
|
||||
this.exit = exit;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "B"+n/*+"( " + entry + ", " + exit + " )"*/;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,236 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* Context
|
||||
*/
|
||||
|
||||
public class Context {
|
||||
|
||||
private static final boolean debug = true;
|
||||
|
||||
Evaluator evaluator;
|
||||
Stack scopeStack;
|
||||
Stack classStack;
|
||||
Scope global;
|
||||
Hashtable predecessors = new Hashtable();
|
||||
Hashtable D;
|
||||
|
||||
|
||||
|
||||
int indent = 0;
|
||||
int errors = 0;
|
||||
public int errorCount() {
|
||||
return errors;
|
||||
}
|
||||
|
||||
String getIndent() {
|
||||
StringBuffer str = new StringBuffer();
|
||||
for (int i = 0; i < indent; i++) {
|
||||
str.append('\t');
|
||||
}
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
static InputBuffer in;
|
||||
|
||||
public static InputBuffer getInput() {
|
||||
return in;
|
||||
}
|
||||
|
||||
public static void init(InputBuffer input) {
|
||||
in=input;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public Evaluator getEvaluator() {
|
||||
return evaluator;
|
||||
}
|
||||
|
||||
public void setEvaluator(Evaluator evaluator) {
|
||||
this.evaluator=evaluator;
|
||||
}
|
||||
|
||||
/**
|
||||
* The bottom of the stack.
|
||||
*/
|
||||
|
||||
Scope getGlobal() {
|
||||
return global;
|
||||
}
|
||||
|
||||
/**
|
||||
* The top of the scope stack.
|
||||
*/
|
||||
|
||||
Scope getLocal() {
|
||||
return (Scope) scopeStack.peek();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the given scope the new innermost scope.
|
||||
*/
|
||||
|
||||
public Scope pushScope(Scope scope) {
|
||||
if( scopeStack==null ) {
|
||||
scopeStack = new Stack();
|
||||
global = scope;
|
||||
}
|
||||
scopeStack.push(scope);
|
||||
return scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop the top scope off the stack.
|
||||
*/
|
||||
|
||||
public void popScope() {
|
||||
if( scopeStack==null ) {
|
||||
return;
|
||||
}
|
||||
scopeStack.pop();
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the given scope the new innermost scope.
|
||||
*/
|
||||
|
||||
void enterClass(Scope scope) {
|
||||
pushScope(scope);
|
||||
if( classStack==null ) {
|
||||
classStack = new Stack();
|
||||
}
|
||||
classStack.push(scope);
|
||||
return;
|
||||
}
|
||||
|
||||
void exitClass() {
|
||||
classStack.pop();
|
||||
popScope();
|
||||
return;
|
||||
}
|
||||
|
||||
Scope getThisClass() {
|
||||
if(classStack.size()==0) {
|
||||
return global;
|
||||
} else {
|
||||
return (Scope) classStack.peek();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The immediate outer.
|
||||
*/
|
||||
|
||||
Scope nextScope(Scope scope) {
|
||||
Scope next;
|
||||
int index = scopeStack.indexOf(scope);
|
||||
if(index==0) {
|
||||
next = null;
|
||||
} else {
|
||||
next = (Scope) scopeStack.elementAt(index-1);
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
private Block thisBlock;
|
||||
Vector blocks = new Vector();
|
||||
|
||||
int blockCount;
|
||||
void enterBlock(Node entry) throws Exception {
|
||||
if( debug ) {
|
||||
Debugger.trace("Context.enterBlock() with entry = " + entry );
|
||||
//Thread.dumpStack();
|
||||
//if(entry instanceof AnnotatedBlockNode) throw new Exception("blah");
|
||||
}
|
||||
if( thisBlock!=null ) {
|
||||
throw new Exception("Entering block before exiting previous block.");
|
||||
}
|
||||
thisBlock = new Block(blockCount++);
|
||||
thisBlock.setEntry(entry);
|
||||
blocks.addElement(thisBlock);
|
||||
}
|
||||
|
||||
Block getBlock() {
|
||||
return thisBlock;
|
||||
}
|
||||
|
||||
void setBlock(Block b) {
|
||||
thisBlock=b;
|
||||
}
|
||||
|
||||
void exitBlock(Node exit) {
|
||||
if( debug ) {
|
||||
Debugger.trace("Context.exitBlock() with exit = " + exit );
|
||||
}
|
||||
if(thisBlock!=null) {
|
||||
thisBlock.setExit(exit);
|
||||
thisBlock = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all basic blocks in the current program.
|
||||
*/
|
||||
|
||||
public Vector getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an edge.
|
||||
*/
|
||||
|
||||
void addEdge(Block b1, Block b2) {
|
||||
if( debug ) {
|
||||
Debugger.trace("Context.addEdge() with b1 = " + b1 + ", b2 = " + b2 );
|
||||
}
|
||||
Vector preds = (Vector) predecessors.get(b2);
|
||||
if( preds == null ) {
|
||||
preds = new Vector();
|
||||
preds.addElement(b1);
|
||||
predecessors.put(b2,preds);
|
||||
} else if( !preds.contains(b1) ) {
|
||||
preds.addElement(b1);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() { return "context( " + scopeStack + ", " + global + " )"; }
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* interface Errors
|
||||
**/
|
||||
|
||||
public interface Errors {
|
||||
|
||||
static final String syntaxPart1_error = "Error at: ";
|
||||
static final String syntaxPart2_error = " Expecting a ";
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,266 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
*
|
||||
* Evaluator
|
||||
*
|
||||
* This is a visitor that is used by the compiler for various forms for
|
||||
* evaluation of a parse tree (e.g. a type evaluator might compute the
|
||||
* static type of an expression.)
|
||||
*/
|
||||
|
||||
public class Evaluator {
|
||||
|
||||
Value evaluate( Context context, Node node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
|
||||
// Expression evaluators
|
||||
|
||||
|
||||
Value evaluate( Context context, ThisExpressionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, IdentifierNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, QualifiedIdentifierNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, LiteralBooleanNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, LiteralNullNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, LiteralNumberNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, LiteralStringNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, LiteralUndefinedNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, LiteralRegExpNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, UnitExpressionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, FunctionExpressionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ParenthesizedExpressionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ParenthesizedListExpressionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, LiteralObjectNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, LiteralFieldNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, LiteralArrayNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, PostfixExpressionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, NewExpressionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, IndexedMemberExpressionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ClassofExpressionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, MemberExpressionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, CoersionExpressionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, CallExpressionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, UnaryExpressionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, BinaryExpressionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ConditionalExpressionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, AssignmentExpressionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ListNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
|
||||
// Statements
|
||||
|
||||
Value evaluate( Context context, StatementListNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, EmptyStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ExpressionStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, AnnotatedBlockNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, LabeledStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, IfStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, SwitchStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, CaseLabelNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, DoStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, WhileStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ForInStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ForStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, WithStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ContinueStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, BreakStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ReturnStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ThrowStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, TryStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, CatchClauseNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, FinallyClauseNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, UseStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, IncludeStatementNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
|
||||
// Definitions
|
||||
|
||||
Value evaluate( Context context, ImportDefinitionNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ImportBindingNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, AnnotatedDefinitionNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, AttributeListNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ExportDefinitionNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ExportBindingNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, VariableDefinitionNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, VariableBindingNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, TypedVariableNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, FunctionDefinitionNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, FunctionDeclarationNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, FunctionNameNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, FunctionSignatureNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ParameterNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, OptionalParameterNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ClassDefinitionNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ClassDeclarationNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, InheritanceNode node ) throws Exception {
|
||||
throw new Exception( "synthesis unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, NamespaceDefinitionNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, PackageDefinitionNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
Value evaluate( Context context, ProgramNode node ) throws Exception {
|
||||
throw new Exception( "evaluation unspecified for node = " + node );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* interface Init
|
||||
*
|
||||
* This interface is implemented by objects that can build
|
||||
* instances of the Value class. For example, there is an
|
||||
* object class that implements this interface for the
|
||||
* system global object.
|
||||
*/
|
||||
|
||||
interface Init {
|
||||
void init( Value ob ) throws Exception;
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class Node
|
||||
*
|
||||
* To be a node you need to implement this interface.
|
||||
*/
|
||||
|
||||
public class Node {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
Block block;
|
||||
private int position;
|
||||
|
||||
public Node() {
|
||||
}
|
||||
|
||||
public Node( int position ) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public Value evaluate( Context context, Evaluator evaluator ) throws Exception {
|
||||
return null;
|
||||
}
|
||||
boolean isLeader;
|
||||
public void markLeader() throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace( "Node.markLeader() with this = " + this );
|
||||
//if(this instanceof AnnotatedBlockNode) throw new Exception("blah");
|
||||
}
|
||||
|
||||
isLeader=true;
|
||||
}
|
||||
public boolean isLeader() {
|
||||
return isLeader;
|
||||
}
|
||||
public boolean isBranch() {
|
||||
return false;
|
||||
}
|
||||
public Node[] getTargets() {
|
||||
return null;
|
||||
}
|
||||
public Node first() {
|
||||
return this;
|
||||
}
|
||||
public Node last() {
|
||||
return this;
|
||||
}
|
||||
public Node pos(int p) {
|
||||
position = p;
|
||||
return this;
|
||||
}
|
||||
public int pos() {
|
||||
return position;
|
||||
}
|
||||
public String toString() {
|
||||
return isLeader ? "*"+block+":" : ""+block+":";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,294 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
public final class NodeFactory {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
static private InputBuffer in;
|
||||
|
||||
static void init(InputBuffer input) {
|
||||
in = input;
|
||||
}
|
||||
|
||||
static IdentifierNode Identifier( String name ) {
|
||||
if( debug ) {
|
||||
Debugger.trace("" + in.positionOfMark() + ": Identifier " + name );
|
||||
}
|
||||
return new IdentifierNode(name,in.positionOfMark());
|
||||
}
|
||||
static QualifiedIdentifierNode QualifiedIdentifier( Node qualifier, IdentifierNode identifier ) {
|
||||
if( debug ) {
|
||||
Debugger.trace("" + in.positionOfMark() + ": QualifiedIdentifier " + identifier);
|
||||
}
|
||||
return new QualifiedIdentifierNode(qualifier,identifier,identifier.pos());
|
||||
}
|
||||
static LiteralNullNode LiteralNull() {
|
||||
return new LiteralNullNode();
|
||||
}
|
||||
static LiteralBooleanNode LiteralBoolean(boolean value) {
|
||||
return new LiteralBooleanNode(value);
|
||||
}
|
||||
static LiteralArrayNode LiteralArray( Node elementlist ) {
|
||||
return new LiteralArrayNode(elementlist);
|
||||
}
|
||||
static LiteralFieldNode LiteralField( Node name, Node value ) {
|
||||
return new LiteralFieldNode(name,value);
|
||||
}
|
||||
static LiteralNumberNode LiteralNumber( String value ) {
|
||||
return new LiteralNumberNode(value);
|
||||
}
|
||||
static LiteralObjectNode LiteralObject( Node fieldlist ) {
|
||||
return new LiteralObjectNode(fieldlist);
|
||||
}
|
||||
static LiteralRegExpNode LiteralRegExp( String value ) {
|
||||
return new LiteralRegExpNode(value);
|
||||
}
|
||||
static LiteralStringNode LiteralString( String value ) {
|
||||
return new LiteralStringNode(value);
|
||||
}
|
||||
static LiteralTypeNode LiteralType( Type type ) {
|
||||
return new LiteralTypeNode(type);
|
||||
}
|
||||
static LiteralUndefinedNode LiteralUndefined() {
|
||||
return new LiteralUndefinedNode();
|
||||
}
|
||||
static ParenthesizedExpressionNode ParenthesizedExpression( Node expr ) {
|
||||
return new ParenthesizedExpressionNode(expr);
|
||||
}
|
||||
static ParenthesizedListExpressionNode ParenthesizedListExpression( Node expr ) {
|
||||
return new ParenthesizedListExpressionNode(expr);
|
||||
}
|
||||
static FunctionExpressionNode FunctionExpression( Node name, Node signature, Node body ) {
|
||||
return new FunctionExpressionNode(name,signature,body);
|
||||
}
|
||||
static AnnotatedDefinitionNode AnnotatedDefinition( Node attributes, Node definition ) {
|
||||
return new AnnotatedDefinitionNode(attributes,definition);
|
||||
}
|
||||
static AttributeListNode AttributeList( Node item, Node list ) {
|
||||
return new AttributeListNode(item,list);
|
||||
}
|
||||
static UnitExpressionNode UnitExpression( Node value, Node type ) {
|
||||
return new UnitExpressionNode(value,type);
|
||||
}
|
||||
static ThisExpressionNode ThisExpression() {
|
||||
return new ThisExpressionNode();
|
||||
}
|
||||
static SuperExpressionNode SuperExpression() {
|
||||
return new SuperExpressionNode();
|
||||
}
|
||||
static EvalExpressionNode EvalExpression( Node expr ) {
|
||||
return new EvalExpressionNode(expr);
|
||||
}
|
||||
static ListNode List( Node list, Node item ) {
|
||||
return new ListNode(list,item,item.pos());
|
||||
}
|
||||
static PostfixExpressionNode PostfixExpression( int op, Node expr ) {
|
||||
return new PostfixExpressionNode(op,expr);
|
||||
}
|
||||
static NewExpressionNode NewExpression( Node member ) {
|
||||
return new NewExpressionNode(member);
|
||||
}
|
||||
static ClassofExpressionNode ClassofExpression( Node base ) {
|
||||
if( debug ) {
|
||||
Debugger.trace("base = " + base);
|
||||
}
|
||||
return new ClassofExpressionNode(base);
|
||||
}
|
||||
static CallExpressionNode CallExpression( Node member, Node args ) {
|
||||
return new CallExpressionNode(member,args);
|
||||
}
|
||||
static IndexedMemberExpressionNode IndexedMemberExpression( Node base, Node member ) {
|
||||
return new IndexedMemberExpressionNode(base,member);
|
||||
}
|
||||
static MemberExpressionNode MemberExpression( Node base, Node name ) {
|
||||
return new MemberExpressionNode(base,name);
|
||||
}
|
||||
static CoersionExpressionNode CoersionExpression( Node expr, Node type ) {
|
||||
return new CoersionExpressionNode(expr,type);
|
||||
}
|
||||
static UnaryExpressionNode UnaryExpression( int op, Node expr ) {
|
||||
return new UnaryExpressionNode(op,expr);
|
||||
}
|
||||
static BinaryExpressionNode BinaryExpression( int op, Node lhs, Node rhs ) {
|
||||
return new BinaryExpressionNode(op,lhs,rhs);
|
||||
}
|
||||
static ConditionalExpressionNode ConditionalExpression( Node cond, Node thenexpr, Node elseexpr ) {
|
||||
return new ConditionalExpressionNode(cond,thenexpr,elseexpr);
|
||||
}
|
||||
static AssignmentExpressionNode AssignmentExpression( Node lhs, int op, Node rhs ) {
|
||||
return new AssignmentExpressionNode(lhs,op,rhs);
|
||||
}
|
||||
static StatementListNode StatementList( StatementListNode list, Node item ) {
|
||||
return new StatementListNode(list,item);
|
||||
}
|
||||
|
||||
static EmptyStatementNode EmptyStatement() {
|
||||
return new EmptyStatementNode();
|
||||
}
|
||||
static ExpressionStatementNode ExpressionStatement( Node expr ) {
|
||||
return new ExpressionStatementNode(expr);
|
||||
}
|
||||
static AnnotatedBlockNode AnnotatedBlock( Node attributes, Node definition ) {
|
||||
return new AnnotatedBlockNode(attributes,definition);
|
||||
}
|
||||
static LabeledStatementNode LabeledStatement( Node label, Node statement ) {
|
||||
return new LabeledStatementNode(label,statement);
|
||||
}
|
||||
static IfStatementNode IfStatement( Node test, Node tblock, Node eblock ) {
|
||||
return new IfStatementNode(test,tblock,eblock);
|
||||
}
|
||||
static SwitchStatementNode SwitchStatement( Node expr, StatementListNode statements ) {
|
||||
return new SwitchStatementNode(expr,statements);
|
||||
}
|
||||
static CaseLabelNode CaseLabel( Node label ) {
|
||||
return new CaseLabelNode(label);
|
||||
}
|
||||
static DoStatementNode DoStatement( Node block, Node expr ) {
|
||||
return new DoStatementNode(block,expr);
|
||||
}
|
||||
static WhileStatementNode WhileStatement( Node expr, Node statement ) {
|
||||
return new WhileStatementNode(expr,statement);
|
||||
}
|
||||
static ForInStatementNode ForInStatement( Node expr1, Node expr2, Node statement ) {
|
||||
return new ForInStatementNode(expr1,expr2,statement);
|
||||
}
|
||||
static ForStatementNode ForStatement( Node expr1, Node expr2, Node expr3, Node statement ) {
|
||||
return new ForStatementNode(expr1,expr2,expr3,statement);
|
||||
}
|
||||
static WithStatementNode WithStatement( Node expr, Node statement ) {
|
||||
return new WithStatementNode(expr,statement);
|
||||
}
|
||||
static ContinueStatementNode ContinueStatement(Node expr) {
|
||||
return new ContinueStatementNode(expr);
|
||||
}
|
||||
static BreakStatementNode BreakStatement(Node expr) {
|
||||
return new BreakStatementNode(expr);
|
||||
}
|
||||
static ReturnStatementNode ReturnStatement( Node expr ) {
|
||||
return new ReturnStatementNode(expr);
|
||||
}
|
||||
static ThrowStatementNode ThrowStatement(Node list) {
|
||||
return new ThrowStatementNode(list);
|
||||
}
|
||||
static TryStatementNode TryStatement(Node tryblock, StatementListNode catchlist, Node finallyblock) {
|
||||
return new TryStatementNode(tryblock,catchlist,finallyblock);
|
||||
}
|
||||
static CatchClauseNode CatchClause(Node parameter, Node block) {
|
||||
return new CatchClauseNode(parameter,block);
|
||||
}
|
||||
static FinallyClauseNode FinallyClause( Node block ) {
|
||||
return new FinallyClauseNode(block);
|
||||
}
|
||||
static IncludeStatementNode IncludeStatement( Node list ) {
|
||||
return new IncludeStatementNode(list);
|
||||
}
|
||||
static UseStatementNode UseStatement( Node expr ) {
|
||||
return new UseStatementNode(expr);
|
||||
}
|
||||
|
||||
static ImportDefinitionNode ImportDefinition( Node item, Node list ) {
|
||||
return new ImportDefinitionNode(item,list);
|
||||
}
|
||||
static ImportBindingNode ImportBinding( Node identifer, Node item ) {
|
||||
return new ImportBindingNode(identifer,item);
|
||||
}
|
||||
static ExportDefinitionNode ExportDefinition( Node list ) {
|
||||
return new ExportDefinitionNode(list);
|
||||
}
|
||||
static ExportBindingNode ExportBinding( Node name, Node value ) {
|
||||
return new ExportBindingNode(name,value);
|
||||
}
|
||||
static VariableDefinitionNode VariableDefinition( int kind, Node list ) {
|
||||
return new VariableDefinitionNode(kind,list,list.pos());
|
||||
}
|
||||
static VariableBindingNode VariableBinding( Node identifier, Node initializer ) {
|
||||
return new VariableBindingNode(identifier,initializer);
|
||||
}
|
||||
static TypedVariableNode TypedVariable( Node identifier, Node type ) {
|
||||
if( debug ) {
|
||||
Debugger.trace("" + in.positionOfMark() + ": TypedVariable " + type );
|
||||
}
|
||||
return new TypedVariableNode(identifier,type,type!=null?type.pos():identifier.pos());
|
||||
}
|
||||
static FunctionDefinitionNode FunctionDefinition( Node decl, Node body ) {
|
||||
return new FunctionDefinitionNode(decl,body);
|
||||
}
|
||||
static FunctionDeclarationNode FunctionDeclaration( Node name, Node signature ) {
|
||||
return new FunctionDeclarationNode(name,signature);
|
||||
}
|
||||
static FunctionNameNode FunctionName( int kind, Node name ) {
|
||||
return new FunctionNameNode(kind,name);
|
||||
}
|
||||
static RestParameterNode RestParameter( Node expr ) {
|
||||
return new RestParameterNode(expr);
|
||||
}
|
||||
static ParameterNode Parameter( Node identifer, Node type ) {
|
||||
return new ParameterNode(identifer,type);
|
||||
}
|
||||
static OptionalParameterNode OptionalParameter( Node identifer, Node init ) {
|
||||
return new OptionalParameterNode(identifer,init);
|
||||
}
|
||||
static NamedParameterNode NamedParameter( Node name, Node parameter ) {
|
||||
return new NamedParameterNode(name,parameter);
|
||||
}
|
||||
static ClassDeclarationNode ClassDeclaration( Node name ) {
|
||||
return new ClassDeclarationNode(name);
|
||||
}
|
||||
static ClassDefinitionNode ClassDefinition( Node name, Node interfaces, Node statements ) {
|
||||
return new ClassDefinitionNode(name,interfaces,statements);
|
||||
}
|
||||
static InheritanceNode Inheritance( Node baseclass, Node interfaces ) {
|
||||
return new InheritanceNode(baseclass,interfaces);
|
||||
}
|
||||
static InterfaceDeclarationNode InterfaceDeclaration( Node name ) {
|
||||
return new InterfaceDeclarationNode(name);
|
||||
}
|
||||
static InterfaceDefinitionNode InterfaceDefinition( Node name, Node interfaces, Node statements ) {
|
||||
return new InterfaceDefinitionNode(name,interfaces,statements);
|
||||
}
|
||||
static NamespaceDefinitionNode NamespaceDefinition( Node identifier, Node list ) {
|
||||
return new NamespaceDefinitionNode(identifier,list);
|
||||
}
|
||||
static LanguageDeclarationNode LanguageDeclaration( Node list ) {
|
||||
return new LanguageDeclarationNode(list);
|
||||
}
|
||||
static PackageDefinitionNode PackageDefinition( Node name, Node block ) {
|
||||
return new PackageDefinitionNode(name,block);
|
||||
}
|
||||
static ProgramNode Program( Node statements ) {
|
||||
return new ProgramNode(statements);
|
||||
}
|
||||
|
||||
/*
|
||||
static Node () {
|
||||
return new Node();
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* Scope
|
||||
*/
|
||||
|
||||
public interface Scope {
|
||||
Slot get(Value namespace, String name) throws Exception;
|
||||
Slot add(Value namespace, String name ) throws Exception;
|
||||
boolean has(Value namespace, String name) throws Exception;
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* Slot
|
||||
*/
|
||||
|
||||
public class Slot {
|
||||
Value attrs;
|
||||
Value type;
|
||||
Value value;
|
||||
Block block;
|
||||
|
||||
public String toString() {
|
||||
return "{ "+attrs+", "+type+", "+value+" }";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public interface Type extends Init {
|
||||
Object[] values();
|
||||
Type[] converts();
|
||||
void addSub(Type type);
|
||||
boolean includes(Value value);
|
||||
void setSuper(Type type);
|
||||
Type getSuper();
|
||||
Value convert(Context context, Value value) throws Exception;
|
||||
Value coerce(Context context, Value value) throws Exception;
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Value
|
||||
*
|
||||
* This is the value class from which all other values derive.
|
||||
*/
|
||||
|
||||
abstract public class Value implements Scope {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
public Value type;
|
||||
public Value getValue(Context context) throws Exception { return this; }
|
||||
public Value getType(Context context) throws Exception { return type; }
|
||||
|
||||
/*
|
||||
Hashtable defaultNames = new Hashtable();
|
||||
Hashtable namespaces = new Hashtable();
|
||||
Hashtable attributes = new Hashtable();
|
||||
*/
|
||||
|
||||
public boolean has(Value namespace, String name) throws Exception {
|
||||
throw new Exception("Constructor object expected in new expression");
|
||||
/*
|
||||
Hashtable names;
|
||||
if( namespace == null ) {
|
||||
names = defaultNames;
|
||||
} else {
|
||||
names = (Hashtable) namespaces.get(namespace);
|
||||
}
|
||||
return names.containsKey(name);
|
||||
*/
|
||||
}
|
||||
|
||||
public Slot get(Value namespace, String name) throws Exception {
|
||||
throw new Exception("Constructor object expected in new expression");
|
||||
/*
|
||||
if(debug) {
|
||||
Debugger.trace("ObjectValue.get() with namespaces="+namespaces+", namespace="+namespace+", name="+name);
|
||||
}
|
||||
Hashtable names;
|
||||
if( namespace == null ) {
|
||||
names = defaultNames;
|
||||
} else {
|
||||
names = (Hashtable) namespaces.get(namespace);
|
||||
}
|
||||
return (Slot) names.get(name);
|
||||
*/
|
||||
}
|
||||
|
||||
public Slot add(Value namespace, String name) throws Exception {
|
||||
throw new Exception("Constructor object expected in new expression");
|
||||
/*
|
||||
if( debug ) {
|
||||
Debugger.trace("ObjectType.add() with this = " + this + " namespace = " + namespace + " name = " + name);
|
||||
}
|
||||
|
||||
Hashtable names;
|
||||
if( namespace == null ) {
|
||||
names = defaultNames;
|
||||
} else {
|
||||
names = (Hashtable) namespaces.get(namespace);
|
||||
if( names==null ) {
|
||||
names = new Hashtable();
|
||||
namespaces.put(namespace,names);
|
||||
}
|
||||
}
|
||||
|
||||
Slot slot = new Slot();
|
||||
names.put(name,slot);
|
||||
return slot;
|
||||
*/
|
||||
}
|
||||
|
||||
public Value construct(Context context, Value args) throws Exception {
|
||||
throw new Exception("Constructor object expected in new expression");
|
||||
}
|
||||
|
||||
public Value call(Context context, Value args) throws Exception {
|
||||
throw new Exception("Callable object expected in call expression");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,983 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* class BlockEvaluator
|
||||
*
|
||||
* The purpose of this pass is to delineate the basic
|
||||
* blocks of the program. It is necessary to know all
|
||||
* the blocks in the program before we can mark the
|
||||
* flow-control edges and compute the dominance relationship
|
||||
* between a reference and definition.
|
||||
*
|
||||
* The algorithm for partitioning the program into basic
|
||||
* blocks goes like this:
|
||||
* 1 Identify leaders.
|
||||
* 1.1 The first statement of a program.
|
||||
* 1.2 The target of a branch.
|
||||
* 1.3 Immediately follows a branch.
|
||||
* 1.2 Create a block with entry = leader, exit =
|
||||
* 2.Identify exits.
|
||||
* 3 Enter a new block at each leader.
|
||||
* 4 Exit the current block when an exit is encountered.
|
||||
*/
|
||||
|
||||
public class BlockEvaluator extends Evaluator {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
/**
|
||||
* ExpressionStatementNode
|
||||
*
|
||||
* Semantics:
|
||||
* 1. Tag node with current block label.
|
||||
* 2. Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, ExpressionStatementNode node ) throws Exception {
|
||||
if( debug ) {
|
||||
Debugger.trace("defining ExpressionStatementNode = " + node);
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* EmptyStatementNode
|
||||
*
|
||||
* Semantics:
|
||||
* 1. Tag node with current block label.
|
||||
* 2. Return undefined.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, EmptyStatementNode node ) throws Exception {
|
||||
if( debug ) {
|
||||
Debugger.trace("defining ExpressionStatementNode = " + node);
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* AnnotatedBlockNode
|
||||
*
|
||||
* Syntax:
|
||||
* { attributes:list statements:list }
|
||||
*
|
||||
* Semantics:
|
||||
* 1. Tag node with current block label.
|
||||
* 2. Exit current block.
|
||||
* 3. Mark first statement of block, a leader.
|
||||
* 4. Evaluate statements.
|
||||
* 5. Return.
|
||||
*
|
||||
* Notes:
|
||||
* The attributes reside in the preceding block. The first statement is
|
||||
* the leader of a new block since a boolean typed attribute affects
|
||||
* whether this statement list gets included in the control-flow of the
|
||||
* program. The next pass will determine if there is a false valued
|
||||
* attribute and exclude this block from the edges that lead from the
|
||||
* preceding block.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, AnnotatedBlockNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("evaluating AnnotatedBlockNode = " + node);
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
context.exitBlock(node);
|
||||
node.statements.first().markLeader();
|
||||
node.statements.evaluate(context,this);
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* StatementListNode
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, StatementListNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("defining StatementListNode = " + node);
|
||||
}
|
||||
|
||||
ListValue list;
|
||||
|
||||
if( node.list != null ) {
|
||||
if( node.list instanceof StatementListNode ) {
|
||||
list = (ListValue) node.list.evaluate(context,this);
|
||||
} else {
|
||||
list = new ListValue();
|
||||
list.push(node.list.evaluate(context,this));
|
||||
}
|
||||
} else {
|
||||
list = new ListValue();
|
||||
}
|
||||
|
||||
if( node.item != null ) {
|
||||
|
||||
Node item = node.item;
|
||||
StatementListNode prev = (StatementListNode)node.list;
|
||||
|
||||
// Mark leaders.
|
||||
|
||||
if( prev != null && prev.item.isBranch() ) {
|
||||
item.markLeader();
|
||||
}
|
||||
|
||||
if( item.isBranch() ) {
|
||||
Node[] targets = item.getTargets();
|
||||
if( targets!=null ) {
|
||||
for(int i=0;i<targets.length;i++) {
|
||||
Debugger.trace("targets[i]="+targets[i]);
|
||||
targets[i].markLeader();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( prev != null && item.isLeader() ) { // This should only happen with case labels.
|
||||
context.exitBlock(prev);
|
||||
}
|
||||
|
||||
if( item.isLeader() ) {
|
||||
context.enterBlock(item);
|
||||
}
|
||||
|
||||
item.evaluate(context,this);
|
||||
|
||||
}
|
||||
else {
|
||||
context.exitBlock(node.list.item);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
static final void testStatementList() throws Exception {
|
||||
|
||||
String[] input = {
|
||||
"x=1;y=2;z=3;",
|
||||
"if(x) {x=1;y=2;}",
|
||||
"class C {} a=0; if(x) {var x:C;y=2;} else { z=3; } var c:C; c;",
|
||||
"a=0; if(x) {x=1;y=2;} else { class C {} z=3; } d=4; var c:C; c;",
|
||||
};
|
||||
|
||||
String[] expected = {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
};
|
||||
|
||||
testEvaluator("AnnotatedDefinition",input,expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* LabeledStatementNode
|
||||
*
|
||||
* Semantics:
|
||||
* 1 Tag node with current block label.
|
||||
* 2 Evaluate statement.
|
||||
* 3 Exit the current block.
|
||||
* 4 Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, LabeledStatementNode node ) throws Exception {
|
||||
if( debug ) {
|
||||
Debugger.trace("defining LabeledStatementNode = " + node);
|
||||
}
|
||||
|
||||
// Point the current statement to its block.
|
||||
// This reference will be used to compute dominators.
|
||||
|
||||
node.block = context.getBlock();
|
||||
node.statement.evaluate(context,this);
|
||||
context.exitBlock(node.statement.last());
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* IfStatementNode
|
||||
*
|
||||
* Semantics:
|
||||
* 1. Tag node with current block label.
|
||||
* 2. Exit current block.
|
||||
* 3. Mark as leader the first statement of then block.
|
||||
* 4. Evaluate the then block statements.
|
||||
* 5. Exit the current block.
|
||||
* 6. Mark as leader the first statement of else block.
|
||||
* 7. Evaluate the else block statements.
|
||||
* 8. Exit the current block.
|
||||
* 9. Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, IfStatementNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("evaluating Node = " + node);
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
context.exitBlock(node.condition);
|
||||
node.thenactions.markLeader();
|
||||
context.enterBlock(node.thenactions);
|
||||
node.thenactions.block = context.getBlock();
|
||||
node.thenactions.evaluate(context,this);
|
||||
context.exitBlock(node.thenactions.last());
|
||||
if( node.elseactions!=null ) {
|
||||
node.elseactions.markLeader();
|
||||
context.enterBlock(node.elseactions);
|
||||
node.elseactions.block = context.getBlock();
|
||||
node.elseactions.evaluate(context,this);
|
||||
context.exitBlock(node.elseactions.last());
|
||||
}
|
||||
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* SwitchStatementNode
|
||||
*
|
||||
* { expr, statements }
|
||||
*
|
||||
* Semantics:
|
||||
* 1. Tag node with current block label.
|
||||
* 2. Exit current block.
|
||||
* 3. Mark as leader the first statement of statement list.
|
||||
* 4. Evaluate the statement list.
|
||||
* 5. Exit the current block.
|
||||
* 9. Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, SwitchStatementNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("evaluating Node = " + node);
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
context.exitBlock(node.expr);
|
||||
node.statements.evaluate(context,this);
|
||||
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* CaseLabelNode
|
||||
* { label }
|
||||
* if label is null, then its the default case.
|
||||
*
|
||||
* Semantics:
|
||||
* 1 Tag node with current block label.
|
||||
* 4 Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, CaseLabelNode node ) throws Exception {
|
||||
if( debug ) {
|
||||
Debugger.trace("defining CaseLabelNode = " + node);
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* DoStatementNode
|
||||
*
|
||||
* { statements, expr }
|
||||
*
|
||||
* Semantics:
|
||||
* 1 Tag node with current block label.
|
||||
* 2 Evaluate statements.
|
||||
* 3 Exit the current block.
|
||||
* 4 Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, DoStatementNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("evaluating DoStatementNode = " + node);
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
node.statements.evaluate(context,this);
|
||||
context.exitBlock(node.expr);
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* WhileStatementNode
|
||||
*
|
||||
* { expr, statement }
|
||||
*
|
||||
* Semantics:
|
||||
* 1 Tag node with current block label.
|
||||
* 2 Evaluate statements.
|
||||
* 3 Exit the current block.
|
||||
* 4 Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, WhileStatementNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("evaluating WhileStatementNode = " + node);
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
context.exitBlock(node);
|
||||
context.enterBlock(node.statement);
|
||||
node.statement.evaluate(context,this);
|
||||
context.exitBlock(node.statement.last());
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* ForStatementNode
|
||||
*
|
||||
* { initialize, test, increment, statement }
|
||||
*
|
||||
* Semantics:
|
||||
* 1 Tag node with current block label.
|
||||
* 2 Evaluate statements.
|
||||
* 3 Exit the current block.
|
||||
* 4 Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, ForStatementNode node ) throws Exception {
|
||||
|
||||
if( true || debug ) {
|
||||
Debugger.trace("evaluating ForStatementNode = " + node);
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
context.exitBlock(node);
|
||||
context.enterBlock(node.statement);
|
||||
node.statement.evaluate(context,this);
|
||||
context.exitBlock(node.statement.last());
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* ForInStatementNode
|
||||
*
|
||||
* { property, object, statement }
|
||||
*
|
||||
* Semantics:
|
||||
* 1 Tag node with current block label.
|
||||
* 2 Evaluate statements.
|
||||
* 3 Exit the current block.
|
||||
* 4 Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, ForInStatementNode node ) throws Exception {
|
||||
|
||||
if( true || debug ) {
|
||||
Debugger.trace("evaluating ForInStatementNode = " + node);
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
context.exitBlock(node);
|
||||
context.enterBlock(node.statement);
|
||||
node.statement.evaluate(context,this);
|
||||
context.exitBlock(node.statement.last());
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* WithStatementNode
|
||||
*
|
||||
* Syntax:
|
||||
* { expr, statement }
|
||||
*
|
||||
* Semantics:
|
||||
* 1. Tag node with current block label.
|
||||
* 4. Evaluate statement.
|
||||
* 5. Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, WithStatementNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("evaluating WithStatementNode = " + node);
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
node.statement.evaluate(context,this);
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* BreakStatementNode
|
||||
*
|
||||
* Semantics:
|
||||
* 1. Tag node with current block label.
|
||||
* 2. Exit the current block.
|
||||
* 3. Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, BreakStatementNode node ) throws Exception {
|
||||
if( debug ) {
|
||||
Debugger.trace("defining BreakStatementNode = " + node);
|
||||
}
|
||||
|
||||
// Point the current statement to its block.
|
||||
// This reference will be used to compute dominators.
|
||||
|
||||
node.block = context.getBlock();
|
||||
context.exitBlock(node);
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* ContinueStatementNode
|
||||
*
|
||||
* Semantics:
|
||||
* 1. Tag node with current block label.
|
||||
* 2. Exit the current block.
|
||||
* 3. Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, ContinueStatementNode node ) throws Exception {
|
||||
if( debug ) {
|
||||
Debugger.trace("defining ContinueStatementNode = " + node);
|
||||
}
|
||||
|
||||
// Point the current statement to its block.
|
||||
// This reference will be used to compute dominators.
|
||||
|
||||
node.block = context.getBlock();
|
||||
context.exitBlock(node);
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* ReturnStatementNode
|
||||
*
|
||||
* Semantics:
|
||||
* 1. Tag node with current block label.
|
||||
* 2. Exit the current block.
|
||||
* 3. Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, ReturnStatementNode node ) throws Exception {
|
||||
if( debug ) {
|
||||
Debugger.trace("defining ReturnStatementNode = " + node);
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
context.exitBlock(node);
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* ThrowStatementNode
|
||||
*
|
||||
* Semantics:
|
||||
* 1. Tag node with current block label.
|
||||
* 2. Exit the current block.
|
||||
* 3. Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, ThrowStatementNode node ) throws Exception {
|
||||
if( debug ) {
|
||||
Debugger.trace("defining ThrowStatementNode = " + node);
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
context.exitBlock(node);
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* TryStatementNode
|
||||
* { tryblock, catchlist, finallyblock }
|
||||
*
|
||||
* Semantics:
|
||||
* 1. Tag node with current block label.
|
||||
* 4. Evaluate the tryblock.
|
||||
* 5. Exit the current block.
|
||||
* 7. Evaluate the catchblock.
|
||||
* 8. Exit the current block.
|
||||
* 9. Evaluate the finally block.
|
||||
* 10. Exit the current block.
|
||||
* 11. Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, TryStatementNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("evaluating Node = " + node);
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
node.tryblock.evaluate(context,this);
|
||||
context.exitBlock(node.tryblock.last());
|
||||
if( node.catchlist!=null ) {
|
||||
node.catchlist.evaluate(context,this);
|
||||
context.exitBlock(node.catchlist.last());
|
||||
}
|
||||
if( node.finallyblock!=null ) {
|
||||
context.enterBlock(node.finallyblock);
|
||||
node.finallyblock.evaluate(context,this);
|
||||
context.exitBlock(node.finallyblock.last());
|
||||
}
|
||||
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* CatchClauseNode
|
||||
*
|
||||
* Syntax:
|
||||
* { parameter statements }
|
||||
*
|
||||
* Semantics:
|
||||
* 1. Tag node with current block label.
|
||||
* 2. Evaluate statements.
|
||||
* 3. Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, CatchClauseNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("evaluating CatchClauseNode = " + node);
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
node.statements.evaluate(context,this);
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* FinallyClauseNode
|
||||
*
|
||||
* Syntax:
|
||||
* { statements }
|
||||
*
|
||||
* Semantics:
|
||||
* 1. Tag node with current block label.
|
||||
* 2. Evaluate statements.
|
||||
* 3. Return.
|
||||
*/
|
||||
|
||||
Value evaluate( Context context, FinallyClauseNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("evaluating FinallyClauseNode = " + node);
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
node.statements.evaluate(context,this);
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
// Definitions
|
||||
|
||||
/**
|
||||
* namespaces is used to store namespace attributes for the
|
||||
* current definition being evaluated.
|
||||
*/
|
||||
|
||||
private Vector namespaces = new Vector();
|
||||
private Vector parameters = new Vector();
|
||||
|
||||
/**
|
||||
* AnnotatedDefinition
|
||||
*/
|
||||
|
||||
public Value evaluate( Context context, AnnotatedDefinitionNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace( "defining AnnotatedDefinitionNode: " + node );
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
Scope local = context.getLocal();
|
||||
|
||||
if( node.definition != null ) {
|
||||
node.definition.evaluate(context,this);
|
||||
}
|
||||
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
static final void testAnnotatedDefinition() throws Exception {
|
||||
|
||||
String[] input = {
|
||||
"",
|
||||
};
|
||||
|
||||
String[] expected = {
|
||||
"",
|
||||
};
|
||||
|
||||
testEvaluator("AnnotatedDefinition",input,expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* ExportDefinition
|
||||
*/
|
||||
|
||||
public Value evaluate( Context context, ExportDefinitionNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace( "defining ExportDefinitionNode: " + node );
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
static final void testExportDefinition() throws Exception {
|
||||
|
||||
String[] input = {
|
||||
"",
|
||||
};
|
||||
|
||||
String[] expected = {
|
||||
"",
|
||||
};
|
||||
|
||||
testEvaluator("ExportDefinition",input,expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* VariableDefinition
|
||||
*/
|
||||
|
||||
public Value evaluate( Context context, VariableDefinitionNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace( "defining VariableDefinitionNode: " + node );
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
static final void testVariableDefinition() throws Exception {
|
||||
|
||||
String[] input = {
|
||||
"var x; x;",
|
||||
"var y:T; y;",
|
||||
"class C; class C{}; var x, y:C; y;",
|
||||
"var x = 1; const y = 2; var z = n;",
|
||||
"var x = 1,y = 2,z = n;",
|
||||
"if(true) {const n = 1;} const z = n;",
|
||||
};
|
||||
|
||||
String[] expected = {
|
||||
"code(expressionstatement( identifier( x ) ))",
|
||||
"error(Type expression does not evaluate to a type: undefined)",
|
||||
"code(expressionstatement( identifier( y ) ))",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
};
|
||||
|
||||
testEvaluator("VariableDefinition",input,expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* FunctionDeclaration
|
||||
*/
|
||||
|
||||
public Value evaluate( Context context, FunctionDeclarationNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace( "defining FunctionDeclarationNode: " + node );
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
static final void testFunctionDeclaration() throws Exception {
|
||||
|
||||
String[] input = {
|
||||
"function f(); f;",
|
||||
"function f(x); f;",
|
||||
"function f(x:Integer,y:String); f;",
|
||||
};
|
||||
|
||||
String[] expected = {
|
||||
"completion( 0, object(function(f)){object(namespace(_parameters_)){}=object(namespace(object(namespace(_parameters_)){})){_result_={ 0, typevalue(any){}, undefined }}}, null )",
|
||||
"completion( 0, object(function(f)){object(namespace(_parameters_)){}=object(namespace(object(namespace(_parameters_)){})){x={ 0, typevalue(any){}, undefined }, _result_={ 0, typevalue(any){}, undefined }}}, null )",
|
||||
"completion( 0, object(function(f)){object(namespace(_parameters_)){}=object(namespace(object(namespace(_parameters_)){})){x={ 0, typevalue(integer){}, undefined }, _result_={ 0, typevalue(any){}, undefined }, y={ 0, typevalue(string){}, undefined }}}, null )",
|
||||
};
|
||||
|
||||
testEvaluator("FunctionDeclaration",input,expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* FunctionDefinition
|
||||
*/
|
||||
|
||||
public Value evaluate( Context context, FunctionDefinitionNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace( "defining FunctionDefinitionNode: " + node );
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
context.exitBlock(node.decl);
|
||||
if( node.body!=null) {
|
||||
node.body.first().markLeader();
|
||||
node.body.evaluate(context,this);
|
||||
context.exitBlock(node.body.last());
|
||||
}
|
||||
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
static final void testFunctionDefinition() throws Exception {
|
||||
|
||||
String[] input = {
|
||||
"function f(){}; f",
|
||||
"function f(x){var a;}; f",
|
||||
"namespace V; const v=namespace(V);v function f(x,y){var a; const b;}; v::f",
|
||||
};
|
||||
|
||||
String[] expected = {
|
||||
"completion( 0, object(function(f)){object(namespace(_parameters_)){}=object(namespace(object(namespace(_parameters_)){})){_result_={ 0, typevalue(any){}, undefined }}}, null )",
|
||||
"completion( 0, object(function(f)){a={ 0, typevalue(any){}, undefined }, object(namespace(_parameters_)){}=object(namespace(object(namespace(_parameters_)){})){x={ 0, typevalue(any){}, undefined }, _result_={ 0, typevalue(any){}, undefined }}, _code_={ 0, any, list([list([])]) }}, null )",
|
||||
"",
|
||||
};
|
||||
|
||||
testEvaluator("FunctionDefinition",input,expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* ClassDeclaration
|
||||
*/
|
||||
|
||||
public Value evaluate( Context context, ClassDeclarationNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace( "defining ClassDeclarationNode: " + node );
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
static final void testClassDeclaration() throws Exception {
|
||||
|
||||
String[] input = {
|
||||
"class C; C;"
|
||||
};
|
||||
|
||||
String[] expected = {
|
||||
"completion( 0, typevalue(class(C extends null)){}, null )"
|
||||
};
|
||||
|
||||
testEvaluator("ClassDeclaration",input,expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* ClassDefinition
|
||||
*
|
||||
* 1. Create a new class object.
|
||||
* 2. Add the classname and object to the global type database.
|
||||
* 3. Push the class object onto the scope stack.
|
||||
*/
|
||||
|
||||
public Value evaluate( Context context, ClassDefinitionNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace( "defining ClassDefinitionNode: " + node );
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
|
||||
if( node.statements!=null ) {
|
||||
node.statements.evaluate(context,this);
|
||||
}
|
||||
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
static final void testClassDefinition() throws Exception {
|
||||
|
||||
String[] input = {
|
||||
"class C {} C",
|
||||
};
|
||||
|
||||
String[] expected = {
|
||||
"completion( 0, typevalue(class(C extends null)){}, null )",
|
||||
};
|
||||
|
||||
testEvaluator("ClassDefinition",input,expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* NamespaceDefinition
|
||||
*/
|
||||
|
||||
public Value evaluate( Context context, NamespaceDefinitionNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace( "defining NamespaceDefinitionNode: " + node );
|
||||
}
|
||||
|
||||
node.block = context.getBlock();
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
static final void testNamespaceDefinition() throws Exception {
|
||||
|
||||
String[] input = {
|
||||
"namespace N; N;",
|
||||
"namespace N2 extends N1; N2;",
|
||||
};
|
||||
|
||||
String[] expected = {
|
||||
"completion( 0, object(namespace(N)){}, null )",
|
||||
"completion( 0, object(namespace(N2)){}, null )",
|
||||
};
|
||||
|
||||
testEvaluator("NamespaceDefinition",input,expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Program
|
||||
*/
|
||||
|
||||
public Value evaluate( Context context, ProgramNode node ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace( "defining ProgramNode: " + node );
|
||||
}
|
||||
|
||||
node.statements.first().markLeader();
|
||||
node.statements.evaluate(context,this);
|
||||
context.exitBlock(node.statements.last());
|
||||
return UndefinedValue.undefinedValue;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Main. Runs self diagnostics.
|
||||
*/
|
||||
|
||||
static int failureCount = 0;
|
||||
|
||||
public static void main( String[] args ) {
|
||||
PrintStream outfile = null;
|
||||
try {
|
||||
|
||||
outfile = new PrintStream( new FileOutputStream( "Parser.test" ) );
|
||||
System.setOut( outfile );
|
||||
|
||||
Debugger.trace( "Parser test begin" );
|
||||
|
||||
|
||||
if( failureCount != 0 )
|
||||
Debugger.trace( "DefinitionEvaluator test completed: " + failureCount + " tests failed" );
|
||||
else
|
||||
Debugger.trace( "DefinitionEvaluator test completed successfully" );
|
||||
}
|
||||
catch( Exception e ) {
|
||||
//Debugger.trace( "compile error: " + e );
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
outfile.close();
|
||||
System.setOut( null );
|
||||
}
|
||||
}
|
||||
|
||||
static final void testEvaluator(String name, String[] input, String[] expected) throws Exception {
|
||||
|
||||
Debugger.trace( "begin testEvaluator: " + name );
|
||||
|
||||
String result = "";
|
||||
|
||||
Node node;
|
||||
Value type;
|
||||
Evaluator evaluator;
|
||||
|
||||
Class pc = Parser.class;
|
||||
Class[] args = new Class[0];
|
||||
|
||||
Parser parser;
|
||||
long t=0;
|
||||
|
||||
ObjectValue global = null;
|
||||
|
||||
for( int i = 0; i < input.length; i++ ) {
|
||||
|
||||
Context context = new Context();
|
||||
|
||||
try {
|
||||
|
||||
global = new ObjectValue("__systemGlobal", new GlobalObject());
|
||||
context.enterClass(global);
|
||||
|
||||
parser = new Parser(new StringReader(input[i]));
|
||||
evaluator = new BlockEvaluator();
|
||||
|
||||
System.gc();
|
||||
t = System.currentTimeMillis();
|
||||
node = parser.parseProgram();
|
||||
Debugger.trace(" I: "+global);
|
||||
context.evaluator = evaluator;
|
||||
node.evaluate(context, evaluator);
|
||||
Debugger.trace(" D: "+global);
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
context.exitClass();
|
||||
|
||||
} catch( Exception x ) {
|
||||
x.printStackTrace();
|
||||
t = System.currentTimeMillis() - t;
|
||||
result = "error("+x.getMessage()+")";
|
||||
context.exitClass();
|
||||
}
|
||||
if( result.equals( expected[i] ) ) {
|
||||
Debugger.trace( " " + i + " passed in " + Long.toString(t) +
|
||||
" msec [" + input[i] + "] = " + result );
|
||||
} else {
|
||||
failureCount++;
|
||||
Debugger.trace( " " + i + " failed [" + input[i] + "] = " + result );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Debugger.trace( "finish testEvaluator: " + name );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* class ArrayType
|
||||
*/
|
||||
|
||||
public final class ArrayType extends ObjectType implements Type {
|
||||
|
||||
boolean debug = false;
|
||||
|
||||
public static final TypeValue type = new TypeValue(new ArrayType());
|
||||
|
||||
public String toString() {
|
||||
return "array";
|
||||
}
|
||||
|
||||
private ArrayType() {
|
||||
super("array");
|
||||
ObjectType.type.addSub(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Type methods
|
||||
*/
|
||||
|
||||
public Value convert(Context context, Value value) throws Exception {
|
||||
if( value instanceof ListValue ) {
|
||||
return this.convert(context,(ListValue)value);
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public Value convert(Context context, ListValue value) throws Exception {
|
||||
Value array = new ObjectValue(this);
|
||||
Enumeration e = value.elements();
|
||||
int i = 0;
|
||||
while(e.hasMoreElements()) {
|
||||
Slot slot;
|
||||
String name;
|
||||
Value elem;
|
||||
name = ""+i;
|
||||
slot = array.add(null,name);
|
||||
elem = (Value) e.nextElement();
|
||||
slot.value = elem.getValue(context);
|
||||
i++;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class BooleanType
|
||||
*/
|
||||
|
||||
public final class BooleanType extends ObjectType implements Type {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
public static final TypeValue type = new TypeValue(new BooleanType());
|
||||
|
||||
public String toString() {
|
||||
return "boolean";
|
||||
}
|
||||
|
||||
private BooleanType() {
|
||||
super("boolean");
|
||||
ObjectType.type.addSub(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class CharacterType
|
||||
*/
|
||||
|
||||
public final class CharacterType extends ObjectType implements Type {
|
||||
|
||||
boolean debug = false;
|
||||
|
||||
public static final TypeValue type = new TypeValue(new CharacterType());
|
||||
|
||||
public String toString() {
|
||||
return "character";
|
||||
}
|
||||
|
||||
private CharacterType() {
|
||||
super("character");
|
||||
ObjectType.type.addSub(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* class ClassType
|
||||
*/
|
||||
|
||||
public final class ClassType extends ObjectType implements Type {
|
||||
|
||||
boolean debug = false;
|
||||
|
||||
public static final TypeValue type = new TypeValue(new ClassType());
|
||||
|
||||
String name = "";
|
||||
|
||||
public String toString() {
|
||||
return "class("+name+" extends " + superType + ")";
|
||||
}
|
||||
|
||||
public ClassType(String name) {
|
||||
super("class#"+name);
|
||||
this.name = name;
|
||||
ClassType.type.addSub(this);
|
||||
}
|
||||
|
||||
private ClassType() {
|
||||
super("class");
|
||||
TypeType.type.addSub(this);
|
||||
}
|
||||
|
||||
private Type superType;
|
||||
|
||||
public void setSuper(Type type) {
|
||||
superType = type;
|
||||
superType.addSub(this);
|
||||
}
|
||||
|
||||
public Type getSuper() {
|
||||
return superType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init
|
||||
*/
|
||||
|
||||
public void init( Value ob ) {
|
||||
ob.type = TypeType.type;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class CompletionType
|
||||
*/
|
||||
|
||||
public final class CompletionType extends ObjectType {
|
||||
public static final int normalType = 0x00;
|
||||
public static final int breakType = 0x01;
|
||||
public static final int continueType = 0x02;
|
||||
public static final int returnType = 0x03;
|
||||
public static final int throwType = 0x04;
|
||||
|
||||
CompletionType() {
|
||||
super("completion");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class FunctionType
|
||||
*/
|
||||
|
||||
public final class FunctionType extends ObjectType implements Type {
|
||||
|
||||
boolean debug = false;
|
||||
|
||||
public static final TypeValue type = new TypeValue(new FunctionType());
|
||||
|
||||
String name;
|
||||
|
||||
public String toString() {
|
||||
return "function("+name+")";
|
||||
}
|
||||
|
||||
public FunctionType(String name) {
|
||||
super("function");
|
||||
this.name = name;
|
||||
FunctionType.type.addSub(this);
|
||||
}
|
||||
|
||||
private FunctionType() {
|
||||
super("function");
|
||||
ObjectType.type.addSub(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class IntegerType
|
||||
*/
|
||||
|
||||
public final class IntegerType extends ObjectType implements Type {
|
||||
|
||||
boolean debug = false;
|
||||
|
||||
public static final TypeValue type = new TypeValue(new IntegerType());
|
||||
|
||||
public String toString() {
|
||||
return "integer";
|
||||
}
|
||||
|
||||
private IntegerType() {
|
||||
super("integer");
|
||||
ObjectType.type.addSub(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class NamespaceType
|
||||
*/
|
||||
|
||||
public final class NamespaceType extends ObjectType implements Type {
|
||||
|
||||
boolean debug = false;
|
||||
|
||||
public static final TypeValue type = new TypeValue(new NamespaceType());
|
||||
|
||||
public String toString() {
|
||||
if( name == null ) {
|
||||
return "namespace";
|
||||
} else {
|
||||
return "namespace("+name+")";
|
||||
}
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
public NamespaceType(String name) {
|
||||
super("namespace");
|
||||
this.name = name;
|
||||
NamespaceType.type.addSub(this);
|
||||
}
|
||||
|
||||
private NamespaceType() {
|
||||
super("namespace");
|
||||
ObjectType.type.addSub(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class NoneType
|
||||
*/
|
||||
|
||||
public final class NoneType extends ObjectType implements Type {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
public static final TypeValue type = new TypeValue(new NoneType());
|
||||
|
||||
public String toString() {
|
||||
return "none";
|
||||
}
|
||||
|
||||
private NoneType() {
|
||||
super("none");
|
||||
ObjectType.type.addSub(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class NullType
|
||||
*/
|
||||
|
||||
public final class NullType extends ObjectType implements Type {
|
||||
|
||||
boolean debug = false;
|
||||
|
||||
public static final TypeValue type = new TypeValue(new NullType());
|
||||
|
||||
public String toString() {
|
||||
return "null";
|
||||
}
|
||||
|
||||
private NullType() {
|
||||
super("null");
|
||||
ObjectType.type.addSub(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class NumberType
|
||||
*/
|
||||
|
||||
public final class NumberType extends ObjectType implements Type {
|
||||
|
||||
boolean debug = false;
|
||||
|
||||
public static final TypeValue type = new TypeValue(new NumberType());
|
||||
|
||||
public String toString() {
|
||||
return "number";
|
||||
}
|
||||
|
||||
private NumberType() {
|
||||
super("number");
|
||||
ObjectType.type.addSub(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Type methods
|
||||
*/
|
||||
|
||||
public void init( Value ob ) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("NumberType.init() with ob = " + ob );
|
||||
}
|
||||
|
||||
Slot slot;
|
||||
slot = ob.add(null,"Number");
|
||||
slot.type = FunctionType.type;
|
||||
slot.value = new ObjectValue(new FunctionType("constructor"));
|
||||
slot.value.type = NumberType.type;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,233 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* class ObjectType
|
||||
*/
|
||||
|
||||
public class ObjectType implements Type {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
public static final TypeValue type = new TypeValue(new ObjectType());
|
||||
|
||||
String name = "object";
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ObjectType(String name) {
|
||||
this.name = name;
|
||||
ObjectType.type.addSub(this);
|
||||
}
|
||||
|
||||
private ObjectType() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Type methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Init
|
||||
*/
|
||||
|
||||
public void init( Value ob ) throws Exception {
|
||||
}
|
||||
|
||||
private Vector values_ = new Vector();
|
||||
private Type[] converts_ = null;
|
||||
|
||||
public Type[] converts() {
|
||||
if( converts_ == null) {
|
||||
converts_ = new Type[6];
|
||||
converts_[0] = UndefinedType.type;
|
||||
converts_[1] = NullType.type;
|
||||
converts_[2] = BooleanType.type;
|
||||
converts_[3] = NumberType.type;
|
||||
converts_[4] = StringType.type;
|
||||
converts_[5] = ObjectType.type;
|
||||
}
|
||||
return converts_;
|
||||
}
|
||||
|
||||
public void addSub(Type type) {
|
||||
if( debug ) {
|
||||
Debugger.trace("ObjectType.addSub() type = " + type + " to " + this);
|
||||
}
|
||||
values_.addElement(type);
|
||||
}
|
||||
|
||||
public Object[] values() {
|
||||
Object[] values = new Object[values_.size()];
|
||||
values_.copyInto(values);
|
||||
return values;
|
||||
}
|
||||
|
||||
public Value convert(Context context, Value value) throws Exception {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Value coerce(Context context, Value value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
private Type superType;
|
||||
|
||||
public void setSuper(Type type) {
|
||||
superType = type;
|
||||
}
|
||||
|
||||
public Type getSuper() {
|
||||
return superType;
|
||||
}
|
||||
|
||||
public boolean includes(Value value) {
|
||||
|
||||
// A type is always a member of itself.
|
||||
|
||||
if(value.type==ObjectType.type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return values_.contains(value.type);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* subset
|
||||
*
|
||||
* return t2 if t2 is a proper subset of t1, otherwise
|
||||
* return null.
|
||||
*/
|
||||
|
||||
public static Type subset(Type t1, Type t2) {
|
||||
|
||||
if(debug) {
|
||||
Debugger.trace("subset() with t1 = " + t1 + ", t2 = " + t2 );
|
||||
}
|
||||
|
||||
Object[] v1 = t1.values();
|
||||
Object[] v2 = t2.values();
|
||||
|
||||
int l1 = v1.length;
|
||||
int l2 = v2.length;
|
||||
|
||||
int i1;
|
||||
int i2;
|
||||
|
||||
for(i2 = 0; i2 < l2; i2++) {
|
||||
|
||||
// For each value in t2, check that it is also in t1.
|
||||
|
||||
for(i1 = 0; i1 < l1; i1++) {
|
||||
|
||||
if(debug) {
|
||||
Debugger.trace("subset() matching " + v2[i2] + " = " + v1[i1] );
|
||||
}
|
||||
|
||||
// If the match is found, then break out of this
|
||||
// inner loop and continue checking values.
|
||||
|
||||
if(v1[i1]==v2[i2]) {
|
||||
if(debug) {
|
||||
Debugger.trace("value found");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Not a subset if we got to the end of the t1 value array
|
||||
// without finding the current t2 value.
|
||||
|
||||
if(i1==l1) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// If we got to the end of the t2 values, then t2 is a subset
|
||||
// of t1. Return t2.
|
||||
|
||||
if(i2==l2) {
|
||||
return t2;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Type subset(Type[] at1, Type t2) {
|
||||
|
||||
if( at1 == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check that the values of t2 are a subset of values
|
||||
// of at least one of the types of the ta1 array.
|
||||
|
||||
int l = at1.length;
|
||||
int i;
|
||||
|
||||
for( i = 0; i < l; i++ ) {
|
||||
if( subset(at1[i],t2) != null ) {
|
||||
return at1[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* intersection
|
||||
*
|
||||
* return the aggregate type that represents the intersection
|
||||
* of t1 and t2. The empty set is expressed as null.
|
||||
*/
|
||||
|
||||
public static Type intersection(Type t1, Type t2) {
|
||||
|
||||
// Return a type that represents the intersection
|
||||
// of values in both t1 and t2.
|
||||
|
||||
/*
|
||||
for(;;) {
|
||||
for(;;) {
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Type intersection(Type[] ts1, Type t2) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class RegExpType
|
||||
*/
|
||||
|
||||
public final class RegExpType extends ObjectType implements Type {
|
||||
|
||||
boolean debug = false;
|
||||
|
||||
public static final RegExpType type = new RegExpType();
|
||||
|
||||
String expr;
|
||||
|
||||
public String toString() {
|
||||
return "regexp("+expr+")";
|
||||
}
|
||||
|
||||
private RegExpType() {
|
||||
super("regexp");
|
||||
ObjectType.type.addSub(this);
|
||||
}
|
||||
|
||||
public RegExpType(String expr) {
|
||||
super("regexp");
|
||||
this.expr = expr;
|
||||
|
||||
// Make this type a subtype of the base RegExpType.
|
||||
// This means that RegExpType.type.includes(this)
|
||||
// is true. Since values created by this type have
|
||||
// this type as their type, for any reg exp value
|
||||
// RegExpType.type.includes(value.type) is true.
|
||||
|
||||
RegExpType.type.addSub(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class StringType
|
||||
*/
|
||||
|
||||
public final class StringType extends ObjectType implements Type {
|
||||
|
||||
boolean debug = false;
|
||||
|
||||
public static final TypeValue type = new TypeValue(new StringType());
|
||||
|
||||
public String toString() {
|
||||
return "string";
|
||||
}
|
||||
|
||||
private StringType() {
|
||||
super("string");
|
||||
ObjectType.type.addSub(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class TypeType
|
||||
*/
|
||||
|
||||
public class TypeType extends ObjectType implements Type {
|
||||
|
||||
boolean debug = false;
|
||||
|
||||
public static TypeValue type = new TypeValue();
|
||||
|
||||
public String toString() {
|
||||
return "type";
|
||||
}
|
||||
|
||||
public TypeType() {
|
||||
super("type");
|
||||
ObjectType.type.addSub(this);
|
||||
}
|
||||
|
||||
public boolean includes(Value value) {
|
||||
|
||||
// A type is always a member of itself.
|
||||
|
||||
if(value.type==TypeType.type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check the store in the base object.
|
||||
|
||||
return super.includes(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class UndefinedType
|
||||
*/
|
||||
|
||||
public final class UndefinedType extends ObjectType implements Type {
|
||||
|
||||
boolean debug = false;
|
||||
|
||||
public static final TypeValue type = new TypeValue(new UndefinedType());
|
||||
|
||||
public String toString() {
|
||||
return "undefined";
|
||||
}
|
||||
|
||||
private UndefinedType() {
|
||||
super("undefined");
|
||||
ObjectType.type.addSub(this);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class BooleanValue
|
||||
*/
|
||||
|
||||
public class BooleanValue extends ObjectValue {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
public static final Value trueValue = new BooleanValue(true);
|
||||
public static final Value falseValue = new BooleanValue(false);
|
||||
|
||||
boolean value;
|
||||
|
||||
public String toString() {
|
||||
return "boolean("+value+")";
|
||||
}
|
||||
|
||||
BooleanValue(boolean value) {
|
||||
this.value = value;
|
||||
this.type = BooleanType.type;
|
||||
}
|
||||
|
||||
BooleanValue(boolean value, Value type) {
|
||||
this.value = value;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a value of the currently specified type.
|
||||
*/
|
||||
|
||||
public Value getValue(Context context) throws Exception {
|
||||
|
||||
Value value;
|
||||
|
||||
if(type == BooleanType.type) {
|
||||
value = this;
|
||||
} else {
|
||||
value = ((TypeValue)type).convert(context,this);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class CharacterValue
|
||||
*/
|
||||
|
||||
public class CharacterValue extends ObjectValue {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
public String toString() {
|
||||
return "character("+value+")";
|
||||
}
|
||||
|
||||
char value;
|
||||
|
||||
CharacterValue(char value) {
|
||||
this.type = CharacterType.type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
CharacterValue(char value, Value type) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Value getValue(Context context) throws Exception {
|
||||
|
||||
Value value;
|
||||
|
||||
if(type == CharacterType.type) {
|
||||
value = this;
|
||||
} else {
|
||||
throw new Exception("Unexpected type of character value.");
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* class CodeValue
|
||||
*
|
||||
* This value holds the compiled code for an unevaluated
|
||||
* expression.
|
||||
*/
|
||||
|
||||
public class CodeValue extends Value {
|
||||
|
||||
private static final boolean debug = false;
|
||||
private Node node;
|
||||
|
||||
public CodeValue( Node node ) {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "code("+node+")";
|
||||
}
|
||||
|
||||
/**
|
||||
* The result depends on during what phase this function
|
||||
* is called. At compile time it will either return itself,
|
||||
* or a compile-time constant value. At runtime it will
|
||||
* return a runtime value.
|
||||
*/
|
||||
|
||||
public Value getValue(Context context) throws Exception {
|
||||
|
||||
// ACTION: execute the code to get the value.
|
||||
|
||||
return node.evaluate(context,context.evaluator);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class CompletionValue
|
||||
*/
|
||||
|
||||
public class CompletionValue extends Value {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
int type;
|
||||
Value value;
|
||||
String target;
|
||||
|
||||
public CompletionValue(int type, Value value, String target) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public CompletionValue () {
|
||||
this(CompletionType.normalType,NullValue.nullValue,"");
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "completion( "+type+", "+value+", "+target+" )";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,206 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* GlobalObject
|
||||
*
|
||||
* An instance of this class is used to initialize a global
|
||||
* object.
|
||||
*/
|
||||
|
||||
public final class GlobalObject implements Init {
|
||||
|
||||
/**
|
||||
* Init
|
||||
*/
|
||||
|
||||
public void init( Value ob ) throws Exception {
|
||||
|
||||
// Add slots for pre-defined types. A note on values
|
||||
// and types: Each type contains a set of values. A
|
||||
// value is an instance of the value class. For example,
|
||||
// new BooleanValue(true) is the true value of the boolean
|
||||
// type. BooleanValue.type is the type of all boolean
|
||||
// values. Value classes implement the Value interface.
|
||||
|
||||
Slot slot;
|
||||
|
||||
// Types
|
||||
|
||||
slot = ob.add(null,"none");
|
||||
slot.type = TypeType.type;
|
||||
slot.value = NoneType.type;
|
||||
|
||||
slot = ob.add(null,"void");
|
||||
slot.type = TypeType.type;
|
||||
slot.value = UndefinedType.type;
|
||||
|
||||
slot = ob.add(null,"Null");
|
||||
slot.type = TypeType.type;
|
||||
slot.value = NullType.type;
|
||||
|
||||
slot = ob.add(null,"Boolean");
|
||||
slot.type = TypeType.type;
|
||||
slot.value = BooleanType.type;
|
||||
|
||||
slot = ob.add(null,"Integer");
|
||||
slot.type = TypeType.type;
|
||||
slot.value = IntegerType.type;
|
||||
|
||||
slot = ob.add(null,"Number");
|
||||
slot.type = TypeType.type;
|
||||
slot.value = NumberType.type;
|
||||
|
||||
slot = ob.add(null,"Character");
|
||||
slot.type = TypeType.type;
|
||||
slot.value = CharacterType.type;
|
||||
|
||||
slot = ob.add(null,"String");
|
||||
slot.type = TypeType.type;
|
||||
slot.value = StringType.type;
|
||||
|
||||
slot = ob.add(null,"Function");
|
||||
slot.type = TypeType.type;
|
||||
slot.value = FunctionType.type;
|
||||
|
||||
slot = ob.add(null,"Array");
|
||||
slot.type = TypeType.type;
|
||||
slot.value = ArrayType.type;
|
||||
|
||||
slot = ob.add(null,"Type");
|
||||
slot.type = TypeType.type;
|
||||
slot.value = TypeType.type;
|
||||
|
||||
slot = ob.add(null,"Unit");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
// Attributes
|
||||
|
||||
slot = ob.add(null,"local");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"regional");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"global");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"extend");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"unit");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"public");
|
||||
slot.type = NamespaceType.type;
|
||||
slot.value = new ObjectValue(new NamespaceType("public"));
|
||||
|
||||
slot = ob.add(null,"internal");
|
||||
slot.type = NamespaceType.type;
|
||||
slot.value = new ObjectValue(new NamespaceType("internal"));
|
||||
|
||||
slot = ob.add(null,"private");
|
||||
slot.type = NamespaceType.type;
|
||||
slot.value = new ObjectValue(new NamespaceType("private"));
|
||||
|
||||
slot = ob.add(null,"implicit");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"explicit");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"indexable");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"nonindexable");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"final");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"dynamic");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"fixed");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"static");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"constructor");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"abstract");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"virtual");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"final");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"override");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"mayOverride");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"prototype");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"weak");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
|
||||
slot = ob.add(null,"unused");
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = new ObjectValue();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* class ListValue
|
||||
*/
|
||||
|
||||
public class ListValue extends ObjectValue {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
Vector data = new Vector();
|
||||
|
||||
int size() {
|
||||
return data.size();
|
||||
}
|
||||
|
||||
Enumeration elements() {
|
||||
return data.elements();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "list(" + data + ")";
|
||||
}
|
||||
|
||||
public ListValue push(Object item) {
|
||||
data.addElement(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Value getValue(Context context) throws Exception {
|
||||
int size = data.size();
|
||||
if( size > 0 ) {
|
||||
return ((Value) data.elementAt(size-1)).getValue(context);
|
||||
}
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
public Value getValue(Context context, int n) throws Exception {
|
||||
int size = data.size();
|
||||
if( n >= 0 && n < size ) {
|
||||
return ((Value) data.elementAt(n)).getValue(context);
|
||||
}
|
||||
return UndefinedValue.undefinedValue;
|
||||
}
|
||||
|
||||
public void pop() {
|
||||
int size = data.size();
|
||||
if( size > 0 ) {
|
||||
data.setSize(size-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class NullValue
|
||||
*/
|
||||
|
||||
public class NullValue extends ObjectValue {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
public static final Value nullValue = new NullValue();
|
||||
|
||||
public String toString() {
|
||||
return "null";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class NumberValue
|
||||
*/
|
||||
|
||||
public final class NumberValue extends ObjectValue {
|
||||
|
||||
boolean debug = false;
|
||||
|
||||
String value;
|
||||
|
||||
public NumberValue(double value) {
|
||||
this.type = NumberType.type;
|
||||
this.value = null; // ACTION: value;
|
||||
}
|
||||
|
||||
public NumberValue(String value) throws Exception {
|
||||
this.type = NumberType.type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ""+value;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,207 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* ObjectValue
|
||||
*/
|
||||
|
||||
public class ObjectValue extends Value implements Attributes, Scope {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
Hashtable slots = new Hashtable();
|
||||
Hashtable attributes = new Hashtable();
|
||||
String name;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public ObjectValue() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public ObjectValue( TypeValue type ) throws Exception {
|
||||
if( debug ) {
|
||||
Debugger.trace("ObjectValue.ObjectValue() with type = " + type);
|
||||
}
|
||||
type.init(this);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public ObjectValue( String name, TypeValue type ) throws Exception {
|
||||
type.init(this);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public ObjectValue( Init initializer ) throws Exception {
|
||||
this.type = ObjectType.type;
|
||||
initializer.init(this);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public ObjectValue( String name, Init initializer ) throws Exception {
|
||||
this.name = name;
|
||||
this.type = ObjectType.type;
|
||||
initializer.init(this);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public String toString() {
|
||||
|
||||
if( name != null ) {
|
||||
return "object("+name+")"+slots;
|
||||
} else {
|
||||
return "object("+type+")"+slots;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public Value getValue(Context context) throws Exception {
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public boolean has(Value namespace, String name) {
|
||||
return get(namespace,name) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public Slot get(Value namespace, String name) {
|
||||
if( debug ) {
|
||||
Debugger.trace("ObjectValue.get() namespace="+namespace+", name="+name);
|
||||
}
|
||||
Hashtable names;
|
||||
if( namespace == null ) {
|
||||
names = slots;
|
||||
} else {
|
||||
names = (Hashtable) ((ObjectValue)slots.get(namespace)).slots;
|
||||
}
|
||||
return (Slot) names.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public Slot add(Value namespace, String name) throws Exception {
|
||||
if( debug ) {
|
||||
Debugger.trace("ObjectType.add() to " + this.name + " namespace = " + namespace + " name = " + name);
|
||||
}
|
||||
|
||||
Hashtable slots;
|
||||
ObjectValue names;
|
||||
|
||||
if( namespace == null ) {
|
||||
slots = this.slots;
|
||||
} else {
|
||||
names = (ObjectValue) this.slots.get(namespace);
|
||||
if( names==null ) {
|
||||
names = new ObjectValue(new NamespaceType(namespace.toString()));
|
||||
this.slots.put(namespace,names);
|
||||
slots = names.slots;
|
||||
} else {
|
||||
slots = names.slots;
|
||||
}
|
||||
}
|
||||
|
||||
Slot slot = new Slot();
|
||||
slot.type = ObjectType.type;
|
||||
slot.value = UndefinedValue.undefinedValue;
|
||||
|
||||
slots.put(name,slot);
|
||||
|
||||
return slot;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public Value construct(Context context, Value args) throws Exception {
|
||||
|
||||
Scope thisScope = context.getThisClass();
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("calling object constructor with this = " + thisScope + ", args = " + args);
|
||||
}
|
||||
|
||||
return (Value) thisScope;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public Value call(Context context, Value args) throws Exception {
|
||||
|
||||
Scope thisScope = context.getThisClass();
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("calling function with this = " + thisScope + ", args = " + args);
|
||||
}
|
||||
|
||||
Value value = UndefinedValue.undefinedValue;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* class ReferenceValue
|
||||
*/
|
||||
|
||||
public class ReferenceValue extends Value {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
Scope scope;
|
||||
Vector namespaces;
|
||||
Value qualifier;
|
||||
String name;
|
||||
|
||||
public String toString() {
|
||||
return "reference(scope=" + scope + ", namespace=" + namespaces + ", name=" + name + ")";
|
||||
}
|
||||
|
||||
public ReferenceValue( Scope scope, Vector namespaces, String name ) {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace( "creating reference scope = " + scope +
|
||||
" name = " + name + " namespaces = " + namespaces );
|
||||
}
|
||||
|
||||
this.scope = scope;
|
||||
this.namespaces = namespaces;
|
||||
this.qualifier = null;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ReferenceValue( Scope scope, Value qualifier, String name ) {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace( "creating reference scope = " + scope +
|
||||
" name = " + name + " namespaces = " + namespaces );
|
||||
}
|
||||
|
||||
this.scope = scope;
|
||||
this.namespaces = null;
|
||||
this.qualifier = qualifier;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
Slot getSlotInScope(Context context, Scope scope, String name) throws Exception {
|
||||
Slot slot = null;
|
||||
if( debug ) {
|
||||
Debugger.trace("entering getSlotInScope() with namespaces=" + namespaces +
|
||||
", name= " + name + ", slot=" + slot );
|
||||
}
|
||||
if( namespaces==null || namespaces.size()==0 ) {
|
||||
slot = scope.get(qualifier,name);
|
||||
} else {
|
||||
Enumeration e = namespaces.elements();
|
||||
while(e.hasMoreElements()) {
|
||||
Value namespace = (Value) e.nextElement();
|
||||
slot = scope.get(namespace,name);
|
||||
if( debug ) {
|
||||
Debugger.trace("looking for name = " + name + " in namespace=" + namespace + ", slot=" + slot );
|
||||
}
|
||||
if( slot!=null ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( debug ) {
|
||||
Debugger.trace("leaving getSlotInScope() with slot="+slot);
|
||||
}
|
||||
return slot;
|
||||
}
|
||||
|
||||
public Slot getSlot(Context context) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("ReferenceType.getSlot() with context = " + context );
|
||||
}
|
||||
|
||||
Slot slot = null;
|
||||
|
||||
// lookup the name in the specific scope.
|
||||
|
||||
|
||||
if( scope!=null ) {
|
||||
|
||||
slot = getSlotInScope(context,scope,name);
|
||||
|
||||
// ACTION: Look also in the prototype(s).
|
||||
|
||||
// ISSUE: What about reference to static vars though instances?
|
||||
|
||||
} else {
|
||||
|
||||
Scope scope = context.getLocal();
|
||||
|
||||
while(scope!=null) {
|
||||
slot = getSlotInScope(context,scope,name);
|
||||
|
||||
if(slot!=null) {
|
||||
break;
|
||||
}
|
||||
|
||||
// ACTION: Look also in the prototype(s).
|
||||
|
||||
scope = context.nextScope(scope);
|
||||
}
|
||||
}
|
||||
|
||||
return slot;
|
||||
}
|
||||
|
||||
public Value getValue(Context context) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("ReferenceType.getValue() with context = " + context );
|
||||
}
|
||||
|
||||
Value value = UndefinedValue.undefinedValue;
|
||||
Slot slot = getSlot(context);
|
||||
|
||||
if( slot != null ) {
|
||||
|
||||
Block d = slot.block;
|
||||
Block r = context.getBlock();
|
||||
|
||||
// d == null means that the definition is a native
|
||||
// an so dominates all user code.
|
||||
|
||||
if( d == null || Flow.dom(context,d,r) ) {
|
||||
value = slot.value;
|
||||
} else {
|
||||
// d does not dominate r, so we can't tell at compile-time
|
||||
// what the value of the current reference is.
|
||||
value = UndefinedValue.undefinedValue;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public Value getType(Context context) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("ReferenceType.getValue() with context = " + context );
|
||||
}
|
||||
|
||||
Value type = ObjectType.type;
|
||||
Slot slot = getSlot(context);
|
||||
if( slot != null ) {
|
||||
type = slot.type;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
Value getAttrs(Context context) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("ReferenceType.getAttrs() with context = " + context );
|
||||
}
|
||||
|
||||
Value attrs = null;
|
||||
Slot slot = getSlot(context);
|
||||
|
||||
if( slot != null ) {
|
||||
attrs = slot.attrs;
|
||||
}
|
||||
|
||||
return attrs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class StringValue
|
||||
*/
|
||||
|
||||
public final class StringValue extends ObjectValue {
|
||||
|
||||
boolean debug = false;
|
||||
|
||||
String value;
|
||||
|
||||
public StringValue(String value) {
|
||||
this.type = StringType.type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,192 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* class TypeValue
|
||||
*
|
||||
* TypeValues have an internal property valueType that is
|
||||
* the type that this value represents. The type of a TypeValue
|
||||
* is always ObjectType.type.
|
||||
*/
|
||||
|
||||
public class TypeValue extends ObjectValue implements Type {
|
||||
|
||||
private static final boolean debug = false;
|
||||
private String name;
|
||||
private Type impl; // This is the implementation of this value object.
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public TypeValue( Type impl ) {
|
||||
//super(valueType);
|
||||
//TypeType.type.addSub(valueType);
|
||||
this.impl = impl;
|
||||
this.type = TypeType.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* The root type value.
|
||||
*/
|
||||
|
||||
public TypeValue() {
|
||||
//super(impl);
|
||||
//TypeType.type.addSub(impl);
|
||||
this.impl = null;
|
||||
this.type = null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public String toString() {
|
||||
return "typevalue(" + impl + ")" + slots;
|
||||
}
|
||||
|
||||
// Type methods
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public Value convert(Context context, Value value) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public Value coerce(Context context, Value value) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public void addSub(Type type) {
|
||||
if( impl != null ) {
|
||||
impl.addSub(type);
|
||||
} else {
|
||||
// Otherwise, this is the root type so we already
|
||||
// know that this is a subtype, since all types are
|
||||
// subtypes.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public void setSuper(Type superClass) {
|
||||
impl.setSuper(superClass);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public Type getSuper() {
|
||||
return impl.getSuper();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
private Vector values_ = new Vector();
|
||||
private Type[] converts_ = null;
|
||||
|
||||
public Object[] values() {
|
||||
Object[] values = new Object[values_.size()];
|
||||
values_.copyInto(values);
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public Type[] converts() {
|
||||
return converts_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init
|
||||
*
|
||||
* Initialize a raw value. This is how class objects
|
||||
* construct instances. This is the second of three
|
||||
* steps taken to create a new object.
|
||||
*
|
||||
* 1 allocate raw value.
|
||||
* 2 call this method.
|
||||
* 3 call user constructor, if one exists.
|
||||
*
|
||||
* For each instance member in the type definition,
|
||||
* add a slot to the Value ob.
|
||||
*/
|
||||
|
||||
public void init( Value ob ) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public boolean includes(Value value) {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("includes() type = " + impl + ", value = "+value);
|
||||
}
|
||||
|
||||
boolean result;
|
||||
|
||||
if( this.impl==null ) {
|
||||
if( value.type == TypeType.type ) {
|
||||
result = true;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
} else {
|
||||
result = this.impl.includes(value);
|
||||
}
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace(">> result = " + result);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* class UndefinedValue
|
||||
*/
|
||||
|
||||
public class UndefinedValue extends ObjectValue {
|
||||
|
||||
private static final boolean debug = false;
|
||||
public static final Value undefinedValue = new UndefinedValue();
|
||||
|
||||
public UndefinedValue () {
|
||||
this.type = UndefinedType.type;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "undefined";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Prefix Unary Expressions
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "Prefix Unary Expressions";
|
||||
}
|
||||
|
||||
function run() {
|
||||
aa:b::c.d[e](f,g)[h].i++;
|
||||
ba:delete p;
|
||||
ca:void 0
|
||||
da:typeof ob;
|
||||
ea:++a.b--;
|
||||
fa:--a.b++;
|
||||
ga:+a;
|
||||
ha:-a;
|
||||
ia:!a;
|
||||
ja:a;
|
||||
ka:a*b;
|
||||
la:a/b;
|
||||
ma:a%b;
|
||||
na:a*b;
|
||||
oa:a*b+c;
|
||||
pa:a*b-c;
|
||||
qa:a*b-c;
|
||||
ra:a*b-c<<2;
|
||||
sa:a*b-c>>2;
|
||||
ta:a*b-c>>>2;
|
||||
ua:a*b-c>>>2;
|
||||
va:a*b-c>>>2<0;
|
||||
wa:a*b-c>>>2>0;
|
||||
xa:a*b-c>>>2<=0;
|
||||
ya:a*b-c>>>2>=0;
|
||||
za:a*b-c>>>2 instanceof int;
|
||||
ab:a*b-c>>>2 in ob;
|
||||
bb:a*b-c>>>2;
|
||||
cb:a*b-c>>>2<0;
|
||||
db:a*b-c>>>2>0;
|
||||
eb:a*b-c>>>2<=0;
|
||||
fb:a*b-c>>>2>=0;
|
||||
gb:a*b-c>>>2 instanceof int;
|
||||
hb:a*b-c>>>2<0;
|
||||
ib:a*b-c>>>2<0==a*b-c>>>2<0;
|
||||
jb:a*b-c>>>2<0!=a*b-c>>>2<0;
|
||||
kb:a*b-c>>>2<0===a*b-c>>>2<0;
|
||||
lb:a*b-c>>>2<0!=a*b-c>>>2<0;
|
||||
mb:a*b-c>>>2<0==a*b-c>>>2<0;
|
||||
nb:a*b-c>>>2<0==a*b-c>>>2<0&0xff;
|
||||
ob:a*b-c>>>2<0==a*b-c>>>2<0&0xff;
|
||||
pb:a*b-c>>>2<0==a*b-c>>>2<0&0xff^0x10;
|
||||
qb:a*b-c>>>2<0==a*b-c>>>2<0&0xff^0x10;
|
||||
rb:a*b-c>>>2<0==a*b-c>>>2<0&0xff^0x10|0x0f;
|
||||
sb:a*b-c>>>2<0==a*b-c>>>2<0&0xff^0x10|0x0f;
|
||||
tb:a*b-c>>>2<0==a*b-c>>>2<0&0xff^0x10|0x0f&&true;
|
||||
ub:a*b-c>>>2<0==a*b-c>>>2<0&0xff^0x10|0x0f&&true^^!true;
|
||||
vb:a*b-c>>>2<0==a*b-c>>>2<0&0xff^0x10|0x0f&&true^^!true;
|
||||
wb:a*b-c>>>2<0==a*b-c>>>2<0&0xff^0x10|0x0f&&true^^!true;
|
||||
xb:a*b-c>>>2<0==a*b-c>>>2<0&0xff^0x10|0x0f&&true^^!true||false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Postfix Expressions
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "Postfix Expressions";
|
||||
}
|
||||
|
||||
function run() {
|
||||
a.b::c.d[e](f,g)[h].i;
|
||||
(const new const function f(a,b){return a+b;}.(a<<b)::c[1,2].class@(T+V));
|
||||
(const new const function f(a,b){return a+b;}.(a<<b)::c[1,2].class);
|
||||
|
||||
a.b::c.d[e](f,g)[h].i;
|
||||
a.b::c.d[e](f,g)[h].i.j::k;
|
||||
a.b::c.d[e](f,g)[h].i[j,k];
|
||||
a.b::c.d[e](f,g)[h].i(j,k);
|
||||
|
||||
(function f(a,b){return a+b;});
|
||||
(a<<b)::c;
|
||||
new const function f(a,b){return a+b;}.(a<<b)::c(d,1,"z");
|
||||
new const function f(a,b){return a+b;}.(a<<b)::c(d,1,"z").e::f;
|
||||
new const function f(a,b){return a+b;}.(a<<b)::c(d,1,"z")[e,f];
|
||||
new const function f(a,b){return a+b;}.(a<<b)::c(d,1,"z")(e,f);
|
||||
(const new const (a,b,c,1+2+3) "miles".(a<<b)::c[1,2].class++);
|
||||
(const new const function f(a,b){return a+b;}.(a<<b)::c[1,2].class--);
|
||||
(const new const function f(a,b){return a+b;}.(a<<b)::c[1,2].class@T);
|
||||
(const new const function f(a,b){return a+b;}.(a<<b)::c[1,2].class@(T+V));
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Prefix Unary Expressions
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "Prefix Unary Expressions";
|
||||
}
|
||||
|
||||
function run() {
|
||||
a.b::c.d[e](f,g)[h].i++;
|
||||
delete p;
|
||||
void 0;
|
||||
typeof ob;
|
||||
++a.b--;
|
||||
--a.b++;
|
||||
+a;
|
||||
-a;
|
||||
!a;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Primary Expressions
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "Primary Expressions";
|
||||
}
|
||||
|
||||
function run() {
|
||||
null;
|
||||
true;
|
||||
false;
|
||||
//(public);
|
||||
1.23;
|
||||
'abc';
|
||||
this;
|
||||
//super;
|
||||
/abc/gim;
|
||||
[a,b,c];
|
||||
({x:a,y:b,z:c});
|
||||
(function (a:int) { print ('b'); });
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* The break Statement
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "The break Statement";
|
||||
}
|
||||
|
||||
function run() {
|
||||
break
|
||||
break id
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* The continue Statement
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "The continue Statement";
|
||||
}
|
||||
|
||||
function run() {
|
||||
continue
|
||||
continue id
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* The do Statement
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "The do Statement";
|
||||
}
|
||||
|
||||
function run() {
|
||||
|
||||
do print('a') while(true)
|
||||
|
||||
do print('a'); while(true)
|
||||
|
||||
do print('a')
|
||||
while(true)
|
||||
|
||||
do { print('a'); } while(true)
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* The for Statement
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "The for Statement";
|
||||
}
|
||||
|
||||
function run() {
|
||||
for(;;) print('a')
|
||||
for(;i<100;) print('a')
|
||||
for(;i<100;i++) print('a')
|
||||
for(var i:int=0;i<100;i++) print('a')
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* The do Statement
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "The do Statement";
|
||||
}
|
||||
|
||||
function run() {
|
||||
for(p in o) print('a')
|
||||
for(p in a,b,c) print('a')
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* The if Statement
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "The if Statement";
|
||||
}
|
||||
|
||||
function run() {
|
||||
|
||||
if( true ) {
|
||||
print("true");
|
||||
}
|
||||
|
||||
if( true ) {
|
||||
print("a");
|
||||
print("b");
|
||||
print("c");
|
||||
print("d");
|
||||
} else {
|
||||
print("e");
|
||||
print("f");
|
||||
print("g");
|
||||
}
|
||||
|
||||
if(true) print(true) else print(false)
|
||||
|
||||
|
||||
if(true) if(true) print('a') else print('b') else print('c')
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* The labeled Statement
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "The labeled Statement";
|
||||
}
|
||||
|
||||
function run() {
|
||||
a: print('a')
|
||||
b:
|
||||
print('b')
|
||||
c: {print('c')}
|
||||
d:;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* The break Statement
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "The return Statement";
|
||||
}
|
||||
|
||||
function run() {
|
||||
return
|
||||
return e1,e2,e3
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* The switch Statement
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "The switch Statement";
|
||||
}
|
||||
|
||||
function run() {
|
||||
switch(0) {
|
||||
case 1:
|
||||
case 2:
|
||||
print('a');
|
||||
break;
|
||||
case 3:
|
||||
print('b');
|
||||
break;
|
||||
default:
|
||||
print('c');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* The throw Statement
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "The throw Statement";
|
||||
}
|
||||
|
||||
function run() {
|
||||
throw e1,e2,e3;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* The try Statement
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "The try Statement";
|
||||
}
|
||||
|
||||
function run() {
|
||||
try {
|
||||
print('a');
|
||||
} catch ( e:Exception ) {
|
||||
print('b');
|
||||
} catch ( e ) {
|
||||
print('b');
|
||||
} finally {
|
||||
print('c');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* The do Statement
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "The do Statement";
|
||||
}
|
||||
|
||||
function run() {
|
||||
|
||||
while(true) print('a')
|
||||
while(true) print('a');
|
||||
while(true) { print('a') ;;; }
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* The with Statement
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "The with Statement";
|
||||
}
|
||||
|
||||
function run() {
|
||||
|
||||
with(o) print('a')
|
||||
with(o) print('a');
|
||||
with(o) { print('a') }
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Annotated Definitions
|
||||
*/
|
||||
|
||||
const showerrors = false;
|
||||
|
||||
|
||||
function title() {
|
||||
return "Annotated Definitions";
|
||||
}
|
||||
|
||||
class U { }
|
||||
class T { static var d:U; }
|
||||
|
||||
T::d = new U;
|
||||
|
||||
function run() {
|
||||
var x:T;
|
||||
global internal var y;
|
||||
}
|
||||
|
||||
extend(U) static var PI = 3.1415;
|
||||
showerrors extend(U) var RHO = 10;
|
||||
extend(U) const LAMBDA = 12;
|
||||
static var NOT = 0;
|
||||
|
||||
function makeLiter(x,y=0) {
|
||||
return Unit.dm.pow(3)(x,y);
|
||||
}
|
||||
|
||||
unit const liter = makeLiter;
|
||||
showerrors unit const liter = Unit.dm.pow(3);
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Annotated Definitions
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "Annotated Definitions";
|
||||
}
|
||||
|
||||
final aaa class T { a;b;c };
|
||||
|
||||
function run() {
|
||||
public var x:T;
|
||||
}
|
||||
|
||||
var y:Y;
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,25 @@
|
|||
class Spaceship extends Vehicle {
|
||||
var motor : Rocket;
|
||||
var velocity : int;
|
||||
var occupancy : int;
|
||||
const max_velocity: int = 186000 "miles/second";
|
||||
|
||||
constructor function Spaceship( motor:Rocket ) {
|
||||
this.motor = motor;
|
||||
}
|
||||
|
||||
function fly() {};
|
||||
}
|
||||
|
||||
class Vehicle {
|
||||
function travel() {};
|
||||
}
|
||||
|
||||
function run() {
|
||||
var vehicle : Vehicle;
|
||||
|
||||
vehicle = new Spaceship();
|
||||
|
||||
vehicle.travel();
|
||||
vehicle.fly();
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
package Mission {
|
||||
|
||||
class Spaceship extends Vehicle {
|
||||
var motor : Rocket;
|
||||
var velocity ; int;
|
||||
var occupancy : int;
|
||||
|
||||
constructor function Spaceship( motor:Rocket ) {
|
||||
this.motor = motor;
|
||||
}
|
||||
|
||||
function fly() {};
|
||||
}
|
||||
|
||||
class Vehicle {
|
||||
function travel() {};
|
||||
}
|
||||
|
||||
function run() {
|
||||
var vehicle : Vehicle;
|
||||
|
||||
vehicle = new Spaceship();
|
||||
|
||||
vehicle.travel();
|
||||
vehicle.fly();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* The if Statement
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "The if Statement";
|
||||
}
|
||||
|
||||
function run() {
|
||||
class T {}
|
||||
var x:T;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* error test
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "The this Keyword";
|
||||
}
|
||||
|
||||
function run() {
|
||||
x;
|
||||
y
|
||||
z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* The include Statement
|
||||
*/
|
||||
|
||||
include 'a'
|
||||
|
||||
function title() {
|
||||
return "The include Statement";
|
||||
}
|
||||
|
||||
function run() {
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Sanity test.
|
||||
*/
|
||||
|
||||
const result = 'okay';
|
||||
|
||||
function title() {
|
||||
return "sanity";
|
||||
}
|
||||
|
||||
|
||||
function run() {
|
||||
}
|
||||
|
||||
result;
|
||||
|
||||
/**
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
|
@ -0,0 +1,51 @@
|
|||
# Makefile for JSC in Java
|
||||
# Targets:
|
||||
# all -- to build all parts.
|
||||
# input, lexer, parser, semantics, generator -- to build a specfic part.
|
||||
# sanity -- to run the compiler against a simple script. If things are
|
||||
# working the compiler will return the value: completion( 0, okay, null )
|
||||
|
||||
|
||||
all: input lexer parser semantics generator main sanity
|
||||
|
||||
main:
|
||||
javac -d classes -classpath classes ../../src/java/main/*.java
|
||||
|
||||
input:
|
||||
javac -d classes -classpath classes ../../src/java/input/*.java
|
||||
|
||||
lexer:
|
||||
javac -d classes -classpath classes ../../src/java/lexer/*.java
|
||||
|
||||
parser:
|
||||
javac -d classes -classpath classes ../../src/java/parser/*.java
|
||||
|
||||
semantics:
|
||||
javac -d classes -classpath classes ../../src/java/semantics/*.java ../../src/java/semantics/values/*.java ../../src/java/semantics/types/*.java
|
||||
|
||||
generator:
|
||||
javac -d classes -classpath classes ../../src/java/generator/*.java
|
||||
|
||||
sanity:
|
||||
java -classpath classes Main -d ../../test/sanity.js
|
||||
|
||||
test:
|
||||
java -classpath classes Main -d ../../test/ecma-e4/02.expressions/primary.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/02.expressions/prefixunary.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/02.expressions/postfixunary.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/02.expressions/binary.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/break.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/continue.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/do.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/for.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/forin.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/if.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/labeled.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/return.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/switch.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/throw.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/try.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/while.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/03.statements/with.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/04.definitions/definition.1.js
|
||||
java -classpath classes Main -d ../../test/ecma-e4/04.definitions/definition.2.js
|
|
@ -0,0 +1 @@
|
|||
ÐÏࡱ
|
|
@ -0,0 +1 @@
|
|||
ÐÏࡱ
|
|
@ -0,0 +1,71 @@
|
|||
J S C R E A D M E F I L E
|
||||
Jeff Dyer, Nov-30-2000
|
||||
|
||||
OVERVIEW
|
||||
|
||||
JSC (JavaScript Compiler) is a stand-alone front-end implementation
|
||||
of the JS2 language specification. Its purpose is to demonstrate how
|
||||
JS2 programs are statically prepared for execution by a JS2 interpreter.
|
||||
Its output is a psuedo intermediate language suitable for reading by
|
||||
human beings.
|
||||
|
||||
RUNNING JSC
|
||||
|
||||
With a Java Runtime Environment installed, go to the directory ./bin
|
||||
and issue the command:
|
||||
|
||||
java -classpath jsc.jar Main program.js
|
||||
|
||||
program.js is the name of the file to compile. JSC will
|
||||
produce a new file given the name of the original source file
|
||||
with the suffix .jsil appended to it. Errors are written to a
|
||||
file with the suffix .err appended to it.
|
||||
|
||||
BUILDING JSC
|
||||
|
||||
Go to the directory ./build/java, and run your favorite make
|
||||
utility. Such as with the command:
|
||||
|
||||
nmake
|
||||
|
||||
If all goes well, the file ./bin/jsc.jar will be updated.
|
||||
|
||||
|
||||
STATUS OF JSC
|
||||
|
||||
Input Buffer
|
||||
Lexer
|
||||
Parser
|
||||
Block Evaluator
|
||||
Flow Analyzer
|
||||
Type System
|
||||
Expressions
|
||||
Statements
|
||||
Definitions
|
||||
Variables
|
||||
Functions
|
||||
Classes
|
||||
Namespaces
|
||||
Packages
|
||||
Language Declarations
|
||||
Unit Parser
|
||||
Operator Overloading
|
||||
Errors
|
||||
|
||||
ISSUES
|
||||
|
||||
* Intermediate form of references, classes, and interfaces.
|
||||
|
||||
CHANGES
|
||||
|
||||
Nov-30-2000
|
||||
-----------
|
||||
* Folded definition evaluation into constant evaluation since annotated
|
||||
definitions cannot be evaluated until the constant attribute values
|
||||
have been computed. Now there is a BlockEvaluator and a ConstantEvaluator.
|
||||
* Added an error handler to the constant evaluator.
|
||||
* Simplified the type system.
|
||||
|
||||
Nov-16-2000
|
||||
-----------
|
||||
* Original release.
|
|
@ -0,0 +1,947 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* JSILGenerator
|
||||
*/
|
||||
|
||||
public class JSILGenerator extends Evaluator implements Tokens {
|
||||
|
||||
public static boolean debug = false;
|
||||
|
||||
private static PrintStream out;
|
||||
public static void setOut(String filename) throws Exception {
|
||||
out = new PrintStream( new FileOutputStream(filename) );
|
||||
}
|
||||
|
||||
private static void emit(String str) {
|
||||
if( debug ) {
|
||||
Debugger.trace("emit " + str);
|
||||
}
|
||||
|
||||
if( out!=null ) {
|
||||
out.println(str);
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
|
||||
Value evaluate( Context context, Node node ) throws Exception {
|
||||
String tag = "missing evaluator for " + node.getClass(); emit(context.getIndent()+tag); return null;
|
||||
}
|
||||
|
||||
// Expression evaluators
|
||||
|
||||
|
||||
Value evaluate( Context context, ThisExpressionNode node ) throws Exception {
|
||||
String tag = "ThisExpression ";
|
||||
emit(context.getIndent()+tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, IdentifierNode node ) throws Exception {
|
||||
String tag = "Identifier ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
emit(context.getIndent()+node.name);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, QualifiedIdentifierNode node ) throws Exception {
|
||||
String tag = "QualifiedIdentifier ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.qualifier != null ) {
|
||||
node.qualifier.evaluate(context,this);
|
||||
}
|
||||
if( node.name != null ) {
|
||||
emit(context.getIndent()+node.name);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralBooleanNode node ) throws Exception {
|
||||
String tag = "LiteralBoolean: " + node.value;
|
||||
emit(context.getIndent()+tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralNullNode node ) throws Exception {
|
||||
String tag = "LiteralNull ";
|
||||
emit(context.getIndent()+tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralNumberNode node ) throws Exception {
|
||||
String tag = "LiteralNumber: " + node.value;
|
||||
emit(context.getIndent()+tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralStringNode node ) throws Exception {
|
||||
String tag = "LiteralString: " + node.value;
|
||||
emit(context.getIndent()+tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralUndefinedNode node ) throws Exception {
|
||||
String tag = "LiteralUndefined ";
|
||||
emit(context.getIndent()+tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralRegExpNode node ) throws Exception {
|
||||
String tag = "LiteralRegExp: " + node.value;
|
||||
emit(context.getIndent()+tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, UnitExpressionNode node ) throws Exception {
|
||||
String tag = "UnitExpression ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.value != null ) {
|
||||
node.value.evaluate(context,this);
|
||||
}
|
||||
if( node.type != null ) {
|
||||
node.type.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ParenthesizedExpressionNode node ) throws Exception {
|
||||
String tag = "ParenthesizedExpression ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ParenthesizedListExpressionNode node ) throws Exception {
|
||||
String tag = "ParenthesizedListExpression ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, FunctionExpressionNode node ) throws Exception {
|
||||
String tag = "FunctionExpression ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
if( node.signature != null ) {
|
||||
node.signature.evaluate(context,this);
|
||||
}
|
||||
if( node.body != null ) {
|
||||
node.body.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralObjectNode node ) throws Exception {
|
||||
String tag = "LiteralObject ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.fieldlist != null ) {
|
||||
node.fieldlist.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralFieldNode node ) throws Exception {
|
||||
String tag = "LiteralField ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
if( node.value != null ) {
|
||||
node.value.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LiteralArrayNode node ) throws Exception {
|
||||
String tag = "LiteralArray ";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.elementlist != null ) {
|
||||
node.elementlist.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, PostfixExpressionNode node ) throws Exception {
|
||||
String tag = "PostfixExpression: " + Token.getTokenClassName(node.op);
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, NewExpressionNode node ) throws Exception {
|
||||
String tag = "NewExpression";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, IndexedMemberExpressionNode node ) throws Exception {
|
||||
String tag = "IndexedMemberExpression";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.base != null ) {
|
||||
node.base.evaluate(context,this);
|
||||
}
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, MemberExpressionNode node ) throws Exception {
|
||||
String tag = "MemberExpression";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.base != null ) {
|
||||
node.base.evaluate(context,this);
|
||||
}
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ClassofExpressionNode node ) throws Exception {
|
||||
String tag = "ClassofExpression";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.base != null ) {
|
||||
node.base.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, CoersionExpressionNode node ) throws Exception {
|
||||
String tag = "CoersionExpression";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
if( node.type != null ) {
|
||||
node.type.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, CallExpressionNode node ) throws Exception {
|
||||
String tag = "CallExpression";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.member != null ) {
|
||||
node.member.evaluate(context,this);
|
||||
}
|
||||
if( node.args != null ) {
|
||||
node.args.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, UnaryExpressionNode node ) throws Exception {
|
||||
String tag = "UnaryExpression: " + Token.getTokenClassName(node.op);
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, BinaryExpressionNode node ) throws Exception {
|
||||
String tag = "BinaryExpression: " + Token.getTokenClassName(node.op);
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.lhs != null ) {
|
||||
node.lhs.evaluate(context,this);
|
||||
}
|
||||
if( node.rhs != null ) {
|
||||
node.rhs.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ConditionalExpressionNode node ) throws Exception {
|
||||
String tag = "ConditionalExpression";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.condition != null ) {
|
||||
node.condition.evaluate(context,this);
|
||||
}
|
||||
if( node.thenexpr != null ) {
|
||||
node.thenexpr.evaluate(context,this);
|
||||
}
|
||||
if( node.elseexpr != null ) {
|
||||
node.elseexpr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, AssignmentExpressionNode node ) throws Exception {
|
||||
String tag = "AssignmentExpression: " + ((node.op==empty_token)?"":Token.getTokenClassName(node.op));
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.lhs != null ) {
|
||||
node.lhs.evaluate(context,this);
|
||||
}
|
||||
if( node.rhs != null ) {
|
||||
node.rhs.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ListNode node ) throws Exception {
|
||||
String tag = "List";
|
||||
//emit(context.getIndent()+tag);
|
||||
if( node.list != null ) {
|
||||
node.list.evaluate(context,this);
|
||||
}
|
||||
if( node.item != null ) {
|
||||
node.item.evaluate(context,this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Statements
|
||||
|
||||
Value evaluate( Context context, StatementListNode node ) throws Exception {
|
||||
String tag = "StatementList";
|
||||
//emit(context.getIndent()+tag);
|
||||
if( node.list != null ) {
|
||||
node.list.evaluate(context,this);
|
||||
}
|
||||
if( node.item != null ) {
|
||||
node.item.evaluate(context,this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, EmptyStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"EmptyStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ExpressionStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"ExpressionStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, AnnotatedBlockNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"AnnotatedBlock";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.attributes != null ) {
|
||||
node.attributes.evaluate(context,this);
|
||||
}
|
||||
if( node.statements != null ) {
|
||||
node.statements.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, LabeledStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"LabeledStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.label != null ) {
|
||||
node.label.evaluate(context,this);
|
||||
}
|
||||
if( node.statement != null ) {
|
||||
node.statement.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, IfStatementNode node ) throws Exception {
|
||||
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"IfStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.condition != null ) {
|
||||
node.condition.evaluate(context,this);
|
||||
}
|
||||
if( node.thenactions != null ) {
|
||||
node.thenactions.evaluate(context,this);
|
||||
}
|
||||
if( node.elseactions != null ) {
|
||||
node.elseactions.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, SwitchStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"SwitchStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
if( node.statements != null ) {
|
||||
node.statements.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, CaseLabelNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"CaseLabel";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.label != null ) {
|
||||
node.label.evaluate(context,this);
|
||||
} else {
|
||||
emit(context.getIndent()+"default");
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, DoStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"DoStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.statements != null ) {
|
||||
node.statements.evaluate(context,this);
|
||||
}
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, WhileStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"WhileStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
if( node.statement != null ) {
|
||||
node.statement.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ForStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"ForStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.initialize != null ) {
|
||||
node.initialize.evaluate(context,this);
|
||||
}
|
||||
if( node.test != null ) {
|
||||
node.test.evaluate(context,this);
|
||||
}
|
||||
if( node.increment != null ) {
|
||||
node.increment.evaluate(context,this);
|
||||
}
|
||||
if( node.statement != null ) {
|
||||
node.statement.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ForInStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"ForInStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.property != null ) {
|
||||
node.property.evaluate(context,this);
|
||||
}
|
||||
if( node.object != null ) {
|
||||
node.object.evaluate(context,this);
|
||||
}
|
||||
if( node.statement != null ) {
|
||||
node.statement.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, WithStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"WithStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
if( node.statement != null ) {
|
||||
node.statement.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ContinueStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"ContinueStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, BreakStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"BreakStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ReturnStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"ReturnStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ThrowStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"ThrowStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, TryStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"TryStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.tryblock != null ) {
|
||||
node.tryblock.evaluate(context,this);
|
||||
}
|
||||
if( node.catchlist != null ) {
|
||||
node.catchlist.evaluate(context,this);
|
||||
}
|
||||
if( node.finallyblock != null ) {
|
||||
node.finallyblock.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, CatchClauseNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"CatchClause";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.parameter != null ) {
|
||||
node.parameter.evaluate(context,this);
|
||||
}
|
||||
if( node.statements != null ) {
|
||||
node.statements.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, FinallyClauseNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"FinallyClause";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.statements != null ) {
|
||||
node.statements.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, UseStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"UseStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.expr != null ) {
|
||||
node.expr.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, IncludeStatementNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"IncludeStatement";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.item != null ) {
|
||||
node.item.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Definitions
|
||||
|
||||
Value evaluate( Context context, ImportDefinitionNode node ) throws Exception {
|
||||
String tag = "ImportDefinition";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.item != null ) {
|
||||
node.item.evaluate(context,this);
|
||||
}
|
||||
if( node.list != null ) {
|
||||
node.list.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ImportBindingNode node ) throws Exception {
|
||||
String tag = "ImportBinding";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.identifier != null ) {
|
||||
node.identifier.evaluate(context,this);
|
||||
}
|
||||
if( node.item != null ) {
|
||||
node.item.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, AnnotatedDefinitionNode node ) throws Exception {
|
||||
String tag = (node.isLeader ? "*"+node.block+":" : ""+node.block+": ")+"AnnotatedDefinition";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.attributes != null ) {
|
||||
node.attributes.evaluate(context,this);
|
||||
}
|
||||
if( node.definition != null ) {
|
||||
node.definition.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, AttributeListNode node ) throws Exception {
|
||||
String tag = "AttributeList";
|
||||
//emit(context.getIndent()+tag);
|
||||
//context.indent++;
|
||||
if( node.item != null ) {
|
||||
node.item.evaluate(context,this);
|
||||
}
|
||||
if( node.list != null ) {
|
||||
node.list.evaluate(context,this);
|
||||
}
|
||||
//context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ExportDefinitionNode node ) throws Exception {
|
||||
String tag = "ExportDefinition";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.list != null ) {
|
||||
node.list.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ExportBindingNode node ) throws Exception {
|
||||
String tag = "ExportBinding";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
if( node.value != null ) {
|
||||
node.value.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, VariableDefinitionNode node ) throws Exception {
|
||||
String tag = "VariableDefinition: " + Token.getTokenClassName(node.kind);
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.list != null ) {
|
||||
node.list.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, VariableBindingNode node ) throws Exception {
|
||||
String tag = "VariableBinding";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.variable != null ) {
|
||||
node.variable.evaluate(context,this);
|
||||
}
|
||||
if( node.initializer != null ) {
|
||||
node.initializer.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, TypedVariableNode node ) throws Exception {
|
||||
String tag = "TypedVariable";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.identifier != null ) {
|
||||
node.identifier.evaluate(context,this);
|
||||
}
|
||||
if( node.type != null ) {
|
||||
node.type.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, FunctionDefinitionNode node ) throws Exception {
|
||||
String tag = "FunctionDefinition";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.decl != null ) {
|
||||
node.decl.evaluate(context,this);
|
||||
}
|
||||
if( node.body != null ) {
|
||||
node.body.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, FunctionDeclarationNode node ) throws Exception {
|
||||
String tag = "FunctionDeclaration";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
if( node.signature != null ) {
|
||||
node.signature.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, FunctionSignatureNode node ) throws Exception {
|
||||
String tag = "FunctionSignature";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.parameter != null ) {
|
||||
node.parameter.evaluate(context,this);
|
||||
}
|
||||
if( node.result != null ) {
|
||||
node.result.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, FunctionNameNode node ) throws Exception {
|
||||
String tag = "FunctionName: " + ((node.kind==empty_token)?"":Token.getTokenClassName(node.kind));
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ParameterNode node ) throws Exception {
|
||||
String tag = "Parameter";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.identifier != null ) {
|
||||
node.identifier.evaluate(context,this);
|
||||
}
|
||||
if( node.type != null ) {
|
||||
node.type.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, OptionalParameterNode node ) throws Exception {
|
||||
String tag = "OptionalParameter";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.parameter != null ) {
|
||||
node.parameter.evaluate(context,this);
|
||||
}
|
||||
if( node.initializer != null ) {
|
||||
node.initializer.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ClassDefinitionNode node ) throws Exception {
|
||||
String tag = "ClassDefinition";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
if( node.inheritance != null ) {
|
||||
node.inheritance.evaluate(context,this);
|
||||
}
|
||||
if( node.statements != null ) {
|
||||
node.statements.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, InheritanceNode node ) throws Exception {
|
||||
String tag = "Inheritance";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.baseclass != null ) {
|
||||
node.baseclass.evaluate(context,this);
|
||||
}
|
||||
if( node.interfaces != null ) {
|
||||
node.interfaces.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ClassDeclarationNode node ) throws Exception {
|
||||
String tag = "ClassDeclaration";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, NamespaceDefinitionNode node ) throws Exception {
|
||||
String tag = "NamespaceDefinition";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
if( node.extendslist != null ) {
|
||||
node.extendslist.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, PackageDefinitionNode node ) throws Exception {
|
||||
String tag = "PackageDefinition";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
if( node.name != null ) {
|
||||
node.name.evaluate(context,this);
|
||||
}
|
||||
if( node.statements != null ) {
|
||||
node.statements.evaluate(context,this);
|
||||
}
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
|
||||
Value evaluate( Context context, ProgramNode node ) throws Exception {
|
||||
String tag = "Program";
|
||||
emit(context.getIndent()+tag);
|
||||
context.indent++;
|
||||
node.statements.evaluate(context,this);
|
||||
context.indent--;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* class Debugger
|
||||
*
|
||||
**/
|
||||
|
||||
public final class Debugger {
|
||||
|
||||
public static PrintStream dbg = null;
|
||||
private static boolean useSystemOut = false;
|
||||
|
||||
public static void setOutFile(String filename) {
|
||||
try {
|
||||
PrintStream out = new PrintStream( new FileOutputStream( filename ) );
|
||||
System.setOut( out );
|
||||
//System.setErr( outfile );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setErrFile(String filename) {
|
||||
try {
|
||||
PrintStream err = new PrintStream( new FileOutputStream( filename ) );
|
||||
//System.setOut( out );
|
||||
System.setErr( err );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setDbgFile(String filename) {
|
||||
try {
|
||||
if( dbg!=null) {
|
||||
dbg.close();
|
||||
}
|
||||
dbg = new PrintStream( new FileOutputStream( filename ) );
|
||||
//System.setOut( outfile );
|
||||
//System.setErr( outfile );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void trace( String str ) {
|
||||
try {
|
||||
if( useSystemOut )
|
||||
System.out.println( str );
|
||||
else {
|
||||
if( dbg == null ) {
|
||||
dbg = new PrintStream( new FileOutputStream( "debug.out" ) );
|
||||
//System.setOut( outfile );
|
||||
//System.setErr( outfile );
|
||||
}
|
||||
dbg.println( str );
|
||||
}
|
||||
}
|
||||
catch( SecurityException e ) {
|
||||
useSystemOut = true;
|
||||
System.out.println( str );
|
||||
}
|
||||
catch( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,514 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
/**
|
||||
* InputBuffer.java
|
||||
*
|
||||
* Filters and buffers characters from a Reader.
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.io.*;
|
||||
|
||||
public class InputBuffer implements CharacterClasses {
|
||||
|
||||
private static final boolean debug = false;
|
||||
private static final boolean debug_nextchar = false;
|
||||
private static final boolean debug_retract = false;
|
||||
|
||||
StringBuffer lineA = new StringBuffer();
|
||||
StringBuffer lineB = new StringBuffer();
|
||||
StringBuffer curr_line,prev_line;
|
||||
int curr_line_offset,prev_line_offset;
|
||||
int lineA_offset, lineB_offset;
|
||||
|
||||
private StringBuffer text;
|
||||
private int[] line_breaks = new int[1000];
|
||||
|
||||
Reader in;
|
||||
PrintStream err;
|
||||
String origin;
|
||||
|
||||
int pos;
|
||||
int colPos, lnNum=-1; // <0,0> is the position of the first character.
|
||||
|
||||
public static PrintStream out;
|
||||
public static void setOut(String filename) throws Exception {
|
||||
out = new PrintStream( new FileOutputStream(filename) );
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
test_retract();
|
||||
test_markandcopy();
|
||||
test_getLineText();
|
||||
}
|
||||
|
||||
public InputBuffer( Reader in, PrintStream err, String origin ) {
|
||||
this(in,err,origin,0);
|
||||
}
|
||||
|
||||
public InputBuffer( Reader in, PrintStream err, String origin, int pos ) {
|
||||
this.in = in;
|
||||
this.err = err;
|
||||
this.origin = origin;
|
||||
this.pos = pos;
|
||||
this.text = new StringBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* read()
|
||||
*
|
||||
* Read the next character from the input reader and store it in a buffer
|
||||
* of the full text.
|
||||
*/
|
||||
|
||||
private int read() throws Exception {
|
||||
int c = in.read();
|
||||
text.append((char)c);
|
||||
pos++;
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* text()
|
||||
*/
|
||||
|
||||
public String source() {
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* nextchar() --
|
||||
*
|
||||
* The basic function of nextchar() is to fetch the next character,
|
||||
* in the input array, increment next and return the fetched character.
|
||||
*
|
||||
* To simplify the Scanner, this method also does the following:
|
||||
* 1. normalizes certain special characters to a common character.
|
||||
* 2. skips unicode format control characters (category Cf).
|
||||
* 3. keeps track of line breaks, line position and line number.
|
||||
* 4. treats <cr>+<lf> as a single line terminator.
|
||||
* 5. returns 0 when the end of input is reached.
|
||||
*/
|
||||
|
||||
public final int nextchar() throws Exception {
|
||||
|
||||
int c = -1;
|
||||
|
||||
// If the last character was at the end of a line,
|
||||
// then swap buffers and fill the new one with characters
|
||||
// from the input reader.
|
||||
|
||||
if( curr_line==null || colPos==curr_line.length() ) {
|
||||
|
||||
lnNum++;
|
||||
colPos=0;
|
||||
|
||||
// If the current character is a newline, then read
|
||||
// the next line of input into the other input buffer.
|
||||
|
||||
if( curr_line == lineA ) {
|
||||
if( lineB == null ) {
|
||||
lineB = new StringBuffer();
|
||||
lineB_offset = pos;
|
||||
}
|
||||
curr_line = lineB; curr_line_offset = lineB_offset;
|
||||
prev_line = lineA; prev_line_offset = lineA_offset;
|
||||
lineA = null;
|
||||
} else {
|
||||
if( lineA == null ) {
|
||||
lineA = new StringBuffer();
|
||||
lineA_offset = pos;
|
||||
}
|
||||
curr_line = lineA; curr_line_offset = lineA_offset;
|
||||
prev_line = lineB; prev_line_offset = lineB_offset;
|
||||
lineB = null;
|
||||
}
|
||||
|
||||
while(c != '\n' && c != 0) {
|
||||
|
||||
c = read();
|
||||
|
||||
if( false ) {
|
||||
Debugger.trace( "c = " + c );
|
||||
}
|
||||
|
||||
// Skip Unicode 3.0 format-control (general category Cf in
|
||||
// Unicode Character Database) characters.
|
||||
|
||||
while(true) {
|
||||
|
||||
switch(c) {
|
||||
case 0x070f: // SYRIAC ABBREVIATION MARK
|
||||
case 0x180b: // MONGOLIAN FREE VARIATION SELECTOR ONE
|
||||
case 0x180c: // MONGOLIAN FREE VARIATION SELECTOR TWO
|
||||
case 0x180d: // MONGOLIAN FREE VARIATION SELECTOR THREE
|
||||
case 0x180e: // MONGOLIAN VOWEL SEPARATOR
|
||||
case 0x200c: // ZERO WIDTH NON-JOINER
|
||||
case 0x200d: // ZERO WIDTH JOINER
|
||||
case 0x200e: // LEFT-TO-RIGHT MARK
|
||||
case 0x200f: // RIGHT-TO-LEFT MARK
|
||||
case 0x202a: // LEFT-TO-RIGHT EMBEDDING
|
||||
case 0x202b: // RIGHT-TO-LEFT EMBEDDING
|
||||
case 0x202c: // POP DIRECTIONAL FORMATTING
|
||||
case 0x202d: // LEFT-TO-RIGHT OVERRIDE
|
||||
case 0x202e: // RIGHT-TO-LEFT OVERRIDE
|
||||
case 0x206a: // INHIBIT SYMMETRIC SWAPPING
|
||||
case 0x206b: // ACTIVATE SYMMETRIC SWAPPING
|
||||
case 0x206c: // INHIBIT ARABIC FORM SHAPING
|
||||
case 0x206d: // ACTIVATE ARABIC FORM SHAPING
|
||||
case 0x206e: // NATIONAL DIGIT SHAPES
|
||||
case 0x206f: // NOMINAL DIGIT SHAPES
|
||||
case 0xfeff: // ZERO WIDTH NO-BREAK SPACE
|
||||
case 0xfff9: // INTERLINEAR ANNOTATION ANCHOR
|
||||
case 0xfffa: // INTERLINEAR ANNOTATION SEPARATOR
|
||||
case 0xfffb: // INTERLINEAR ANNOTATION TERMINATOR
|
||||
c = read();
|
||||
continue; // skip it.
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break; // out of while loop.
|
||||
}
|
||||
|
||||
|
||||
if( c == 0x000a && prev_line.length()!=0 && prev_line.charAt(prev_line.length()-1) == 0x000d ) {
|
||||
|
||||
// If this is one of those funny double line terminators,
|
||||
// Then ignore the second character by reading on.
|
||||
|
||||
line_breaks[lnNum] = pos; // adjust if forward.
|
||||
c = read();
|
||||
}
|
||||
|
||||
// Line terminators.
|
||||
|
||||
if( c == 0x000a ||
|
||||
c == 0x000d ||
|
||||
c == 0x2028 ||
|
||||
c == 0x2029 ) {
|
||||
|
||||
curr_line.append((char)c);
|
||||
c = '\n';
|
||||
line_breaks[lnNum+1] = pos;
|
||||
|
||||
// White space
|
||||
|
||||
} else if( c == 0x0009 ||
|
||||
c == 0x000b ||
|
||||
c == 0x000c ||
|
||||
c == 0x0020 ||
|
||||
c == 0x00a0 ||
|
||||
false /* other cat Zs' */ ) {
|
||||
|
||||
c = ' ';
|
||||
curr_line.append((char)c);
|
||||
|
||||
// End of line
|
||||
|
||||
} else if( c == -1 ) {
|
||||
|
||||
c = 0;
|
||||
curr_line.append((char)c);
|
||||
|
||||
// All other characters.
|
||||
|
||||
} else {
|
||||
|
||||
// Use c as is.
|
||||
curr_line.append((char)c);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the next character.
|
||||
|
||||
int ln = lnNum;
|
||||
int col = colPos;
|
||||
|
||||
if( curr_line.length() != 0 && curr_line.charAt(colPos) == 0 ) {
|
||||
c = 0;
|
||||
colPos++;
|
||||
} else if( colPos == curr_line.length()-1 ) {
|
||||
c = '\n';
|
||||
colPos++;
|
||||
} else {
|
||||
c = curr_line.charAt(colPos++);
|
||||
}
|
||||
|
||||
if( out != null ) {
|
||||
out.println("Ln " + ln + ", Col " + col + ": nextchar " + Integer.toHexString(c) + " = " + (char)c + " @ " + positionOfNext());
|
||||
}
|
||||
if( debug || debug_nextchar ) {
|
||||
Debugger.trace("Ln " + ln + ", Col " + col + ": nextchar " + Integer.toHexString(c) + " = " + (char)c + " @ " + positionOfNext());
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* test_nextchar() --
|
||||
* Return an indication of how nextchar() performs
|
||||
* in various situations, relative to expectations.
|
||||
*/
|
||||
|
||||
boolean test_nextchar() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* time_nextchar() --
|
||||
* Return the milliseconds taken to do various ordinary
|
||||
* tasks with nextchar().
|
||||
*/
|
||||
|
||||
int time_nextchar() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* retract
|
||||
*
|
||||
* Backup one character position in the input. If at the beginning
|
||||
* of the line, then swap buffers and point to the last character
|
||||
* in the other buffer.
|
||||
*/
|
||||
|
||||
public final void retract() throws Exception {
|
||||
colPos--;
|
||||
if( colPos<0 ) {
|
||||
if( curr_line == prev_line ) {
|
||||
// Can only retract over one line.
|
||||
throw new Exception("Can only retract past one line at a time.");
|
||||
} else if( curr_line == lineA ) {
|
||||
curr_line = lineB = prev_line;
|
||||
} else {
|
||||
curr_line = lineA = prev_line;
|
||||
}
|
||||
lnNum--;
|
||||
colPos = curr_line.length()-1;
|
||||
curr_line_offset = prev_line_offset;
|
||||
}
|
||||
if( debug || debug_retract ) {
|
||||
Debugger.trace("Ln " + lnNum + ", Col " + colPos + ": retract");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static boolean test_retract() {
|
||||
Debugger.trace("test_retract");
|
||||
Reader reader = new StringReader("abc\ndef\nghi");
|
||||
try {
|
||||
InputBuffer inbuf = new InputBuffer(reader,System.err,"test");
|
||||
int c=-1;
|
||||
for(int i=0;i<9;i++) {
|
||||
c = inbuf.nextchar();
|
||||
}
|
||||
for(int i=0;i<3;i++) {
|
||||
inbuf.retract();
|
||||
c = inbuf.nextchar();
|
||||
inbuf.retract();
|
||||
}
|
||||
while(c!=0) {
|
||||
c = inbuf.nextchar();
|
||||
}
|
||||
} catch (Exception x) {
|
||||
x.printStackTrace();
|
||||
System.out.println(x);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* classOfNext
|
||||
*/
|
||||
|
||||
public byte classOfNext() {
|
||||
|
||||
// return the Unicode character class of the current
|
||||
// character, which is pointed to by 'next-1'.
|
||||
|
||||
return CharacterClasses.data[curr_line.charAt(colPos-1)];
|
||||
}
|
||||
|
||||
/**
|
||||
* positionOfNext
|
||||
*/
|
||||
|
||||
public int positionOfNext() {
|
||||
return curr_line_offset+colPos-1;
|
||||
}
|
||||
|
||||
/**
|
||||
* positionOfMark
|
||||
*/
|
||||
|
||||
public int positionOfMark() {
|
||||
return line_breaks[markLn]+markCol-1;
|
||||
}
|
||||
|
||||
/**
|
||||
* mark
|
||||
*/
|
||||
|
||||
int markCol;
|
||||
int markLn;
|
||||
|
||||
public int mark() {
|
||||
markLn = (lnNum==-1)?0:lnNum; // In case nextchar hasn't been called yet.
|
||||
markCol = colPos;
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("Ln " + markLn + ", Col " + markCol + ": mark");
|
||||
}
|
||||
|
||||
return markCol;
|
||||
}
|
||||
|
||||
/**
|
||||
* copy
|
||||
*/
|
||||
|
||||
public String copy() throws Exception {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("Ln " + lnNum + ", Col " + colPos + ": copy " + buf);
|
||||
}
|
||||
|
||||
if(markLn!=lnNum || markCol>colPos) {
|
||||
throw new Exception("Internal error: InputBuffer.copy() markLn = " + markLn + ", lnNum = " + lnNum + ", markCol = " +
|
||||
markCol + ", colPos = " + colPos );
|
||||
}
|
||||
|
||||
for (int i = markCol-1; i < colPos; i++) {
|
||||
buf.append(curr_line.charAt(i));
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
static boolean test_markandcopy() {
|
||||
Debugger.trace("test_copy");
|
||||
Reader reader = new StringReader("abc\ndef\nghijklmnopqrst\nuvwxyz");
|
||||
String s;
|
||||
try {
|
||||
InputBuffer inbuf = new InputBuffer(reader,System.err,"test");
|
||||
int c=-1;
|
||||
int i;
|
||||
for(i=0;i<10;i++) {
|
||||
c = inbuf.nextchar();
|
||||
}
|
||||
inbuf.mark();
|
||||
for(;i<13;i++) {
|
||||
c = inbuf.nextchar();
|
||||
}
|
||||
s = inbuf.copy();
|
||||
if(s.equals("ijk")) {
|
||||
Debugger.trace("1: passed: " + s);
|
||||
} else {
|
||||
Debugger.trace("1: failed: " + s);
|
||||
}
|
||||
while(c!=0) {
|
||||
c = inbuf.nextchar();
|
||||
}
|
||||
s = inbuf.copy();
|
||||
} catch (Exception x) {
|
||||
s = x.getMessage();
|
||||
//x.printStackTrace();
|
||||
}
|
||||
if(s.equals("Internal error: InputBuffer.copy() markLn = 2, lnNum = 3, markCol = 2, colPos = 6")) {
|
||||
Debugger.trace("2: passed: " + s);
|
||||
} else {
|
||||
Debugger.trace("2: failed: " + s);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getLineText(int pos) {
|
||||
int i,len;
|
||||
for(i = 0; line_breaks[i] <= pos && i <= lnNum; i++)
|
||||
;
|
||||
|
||||
int offset = line_breaks[i-1];
|
||||
|
||||
for(len = offset ; (text.charAt(len)!=(char)-1 &&
|
||||
text.charAt(len)!=0x0a &&
|
||||
text.charAt(len)!=0x0d &&
|
||||
text.charAt(len)!=0x2028 &&
|
||||
text.charAt(len)!=0x2029) ; len++) {
|
||||
}
|
||||
|
||||
return text.substring(offset,len);
|
||||
}
|
||||
|
||||
static boolean test_getLineText() {
|
||||
Debugger.trace("test_getLineText");
|
||||
Reader reader = new StringReader("abc\ndef\nghi");
|
||||
try {
|
||||
InputBuffer inbuf = new InputBuffer(reader,System.err,"test");
|
||||
int c=-1;
|
||||
for(int i=0;i<9;i++) {
|
||||
c = inbuf.nextchar();
|
||||
}
|
||||
for(int i=0;i<3;i++) {
|
||||
inbuf.retract();
|
||||
c = inbuf.nextchar();
|
||||
inbuf.retract();
|
||||
}
|
||||
while(c!=0) {
|
||||
c = inbuf.nextchar();
|
||||
}
|
||||
for(int i=0;i<inbuf.text.length()-1;i++) {
|
||||
Debugger.trace("text @ " + i + " " + inbuf.getLineText(i));
|
||||
}
|
||||
} catch (Exception x) {
|
||||
x.printStackTrace();
|
||||
System.out.println(x);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getColPos(int pos) {
|
||||
Debugger.trace("pos " + pos);
|
||||
int i,len;
|
||||
for(i = 0; line_breaks[i] <= pos && i <= lnNum; i++)
|
||||
;
|
||||
|
||||
int offset = line_breaks[i-1];
|
||||
Debugger.trace("offset " + offset);
|
||||
|
||||
return pos-offset;
|
||||
}
|
||||
|
||||
public int getLnNum(int pos) {
|
||||
int i;
|
||||
for(i = 0; line_breaks[i] <= pos && i <= lnNum; i++)
|
||||
;
|
||||
return i-1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.lang.reflect.*;
|
||||
import sun.tools.javac.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* class Shell
|
||||
*/
|
||||
|
||||
public final class Shell {
|
||||
private static boolean debug = true;
|
||||
static int failureCount = 0;
|
||||
|
||||
public static void main( String[] args ) {
|
||||
|
||||
try {
|
||||
|
||||
int count = args.length;
|
||||
String encoding = "UTF-8"; // Alternatives include: "UTF-16", "US-ASCII" (7-bit)
|
||||
|
||||
if( args[0].equals("-l") ) {
|
||||
/* run the input text through the scanner */
|
||||
|
||||
try {
|
||||
Debugger.trace("start "+args[count-1]);
|
||||
FileInputStream in = new FileInputStream( args[count-1] );
|
||||
InputStreamReader reader = new InputStreamReader( in, "UTF-8" );
|
||||
FileOutputStream tokfile = new FileOutputStream( args[count-1] + ".inp" );
|
||||
PrintWriter tokwriter = new PrintWriter( tokfile);
|
||||
FileOutputStream errfile = new FileOutputStream( args[count-1] + ".err" );
|
||||
PrintStream errwriter = new PrintStream( errfile );
|
||||
//char[] temp = new char[0xffff];
|
||||
//int len = reader.read( temp, 0, temp.length );
|
||||
//char[] src = new char[len+1];
|
||||
//System.arraycopy(temp, 0, src, 0, len);
|
||||
|
||||
InputBuffer inp = new InputBuffer( reader, errwriter, args[count-1] );
|
||||
int result;
|
||||
String follows;
|
||||
for( int i = 0; (result = inp.nextchar()) != 0; i++ ) {
|
||||
tokwriter.println( "" + Integer.toHexString(result) + " " + (char)result );
|
||||
}
|
||||
tokwriter.close();
|
||||
Debugger.trace("finish "+args[count-1]);
|
||||
}
|
||||
catch( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/*
|
||||
if( args[0].equals("-g") ) {
|
||||
|
||||
try {
|
||||
FileInputStream srcfile = new FileInputStream( args[count-1] );
|
||||
InputStreamReader reader = new InputStreamReader( srcfile );
|
||||
FileOutputStream errfile = new FileOutputStream( args[count-1] + ".err" );
|
||||
PrintStream errwriter = new PrintStream( errfile );
|
||||
char[] temp = new char[0x7ffff];
|
||||
int len = reader.read( temp, 0, temp.length );
|
||||
char[] src = new char[len+1];
|
||||
System.arraycopy(temp, 0, src, 0, len);
|
||||
|
||||
UnicodeNormalizationFormCReader ucreader = new UnicodeNormalizationFormCReader( src, errwriter, args[count-1] );
|
||||
UnicodeNormalizationFormCReader.generateCharacterClassesArray(ucreader);
|
||||
}
|
||||
catch( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
catch( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
**/
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
import java.lang.reflect.*;
|
||||
import sun.tools.javac.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* class Shell
|
||||
*/
|
||||
|
||||
public final class Shell implements Tokens {
|
||||
private static boolean debug = false;
|
||||
static int failureCount = 0;
|
||||
|
||||
public static void main( String[] args ) {
|
||||
|
||||
try {
|
||||
|
||||
int count = args.length;
|
||||
|
||||
if( args[0].equals("-l") ) {
|
||||
/* run the input text through the scanner */
|
||||
|
||||
try {
|
||||
FileInputStream srcfile = new FileInputStream( args[count-1] );
|
||||
InputStreamReader reader = new InputStreamReader( srcfile );
|
||||
FileOutputStream tokfile = new FileOutputStream( args[count-1] + ".tok" );
|
||||
PrintWriter tokwriter = new PrintWriter( tokfile);
|
||||
FileOutputStream errfile = new FileOutputStream( args[count-1] + ".err" );
|
||||
PrintStream errwriter = new PrintStream( errfile );
|
||||
Scanner scanner = new Scanner( reader, errwriter, args[count-1] );
|
||||
int result;
|
||||
String follows;
|
||||
for( int i = 0; (result = scanner.nexttoken()) != eos_token; i++ ) {
|
||||
follows = scanner.followsLineTerminator() ? "*" : "";
|
||||
tokwriter.print( scanner.getPersistentTokenText(result) + follows + " " );
|
||||
}
|
||||
tokwriter.close();
|
||||
|
||||
/*
|
||||
for( int i = 0; (result = scanner.nexttoken()) != eos_token; i++ ) {
|
||||
System.out.println( scanner.lexeme() + "\t\t\t"
|
||||
+ Token.getTokenClassName(scanner.getTokenClass(result))
|
||||
+ " (" + result + ")"
|
||||
+ ": " + scanner.lexeme() );
|
||||
}
|
||||
*/
|
||||
}
|
||||
catch( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch( Exception e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
**/
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,418 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
**/
|
||||
|
||||
interface States {
|
||||
|
||||
/**
|
||||
**/
|
||||
|
||||
public static final int start_state = 0;
|
||||
public static final int error_state = start_state-1;
|
||||
|
||||
public static final int minusminus_state = start_state+1;
|
||||
public static final int minusequal_state = minusminus_state +1;
|
||||
public static final int minus_state = minusequal_state +1;
|
||||
public static final int notequal_state = minus_state +1;
|
||||
public static final int not_state = notequal_state +1;
|
||||
public static final int remainderequal_state = not_state +1;
|
||||
public static final int remainder_state = remainderequal_state +1;
|
||||
public static final int logicaland_state = remainder_state +1;
|
||||
public static final int logicalandassign_state = logicaland_state +1;
|
||||
public static final int andequal_state = logicalandassign_state +1;
|
||||
public static final int and_state = andequal_state +1;
|
||||
public static final int leftparen_state = and_state +1;
|
||||
public static final int rightparen_state = leftparen_state +1;
|
||||
public static final int starequal_state = rightparen_state +1;
|
||||
public static final int star_state = starequal_state +1;
|
||||
public static final int comma_state = star_state +1;
|
||||
public static final int dot_state = comma_state +1;
|
||||
public static final int doubledot_state = dot_state +1;
|
||||
public static final int tripledot_state = doubledot_state +1;
|
||||
public static final int slashequal_state = tripledot_state +1;
|
||||
public static final int slash_state = slashequal_state +1;
|
||||
public static final int colon_state = slash_state +1;
|
||||
public static final int doublecolon_state = colon_state+1;
|
||||
public static final int semicolon_state = doublecolon_state+1;
|
||||
public static final int questionmark_state = semicolon_state +1;
|
||||
public static final int leftbracket_state = questionmark_state +1;
|
||||
public static final int rightbracket_state = leftbracket_state +1;
|
||||
public static final int bitwisexorassign_state = rightbracket_state +1;
|
||||
public static final int bitwisexor_state = bitwisexorassign_state+1;
|
||||
public static final int logicalxor_state = bitwisexor_state+1;
|
||||
public static final int logicalxorassign_state = logicalxor_state+1;
|
||||
public static final int leftbrace_state = logicalxorassign_state+1;
|
||||
public static final int logicalor_state = leftbrace_state+1;
|
||||
public static final int logicalorassign_state = logicalor_state+1;
|
||||
public static final int orequal_state = logicalorassign_state +1;
|
||||
public static final int or_state = orequal_state +1;
|
||||
public static final int rightbrace_state = or_state +1;
|
||||
public static final int squiggle_state = rightbrace_state +1;
|
||||
public static final int plusplus_state = squiggle_state +1;
|
||||
public static final int plusequal_state = plusplus_state +1;
|
||||
public static final int plus_state = plusequal_state +1;
|
||||
public static final int leftshiftequal_state = plus_state +1;
|
||||
public static final int leftshift_state = leftshiftequal_state +1;
|
||||
public static final int lessthanorequal_state = leftshift_state +1;
|
||||
public static final int lessthan_state = lessthanorequal_state +1;
|
||||
public static final int equal_state = lessthan_state +1;
|
||||
public static final int equalequal_state = equal_state +1;
|
||||
public static final int greaterthanorequal_state = equalequal_state +1;
|
||||
public static final int rightshiftequal_state = greaterthanorequal_state +1;
|
||||
public static final int unsignedrightshift_state = rightshiftequal_state +1;
|
||||
public static final int unsignedrightshiftequal_state = unsignedrightshift_state +1;
|
||||
public static final int rightshift_state = unsignedrightshiftequal_state+1;
|
||||
public static final int greaterthan_state = rightshift_state +1;
|
||||
public static final int A_state = greaterthan_state +1;
|
||||
public static final int N_state = A_state +1;
|
||||
public static final int AA_state = N_state +1;
|
||||
public static final int AN_state = AA_state +1;
|
||||
public static final int singlequote_state = AN_state +1;
|
||||
public static final int doublequote_state = singlequote_state +1;
|
||||
public static final int zero_state = doublequote_state +1;
|
||||
public static final int decimalinteger_state = zero_state +1;
|
||||
public static final int decimal_state = decimalinteger_state +1;
|
||||
public static final int exponent_state = decimal_state +1;
|
||||
public static final int hexinteger_state = exponent_state +1;
|
||||
public static final int octalinteger_state = hexinteger_state +1;
|
||||
public static final int slashregexp_state = octalinteger_state +1;
|
||||
public static final int slashdiv_state = slashregexp_state +1;
|
||||
public static final int regexp_state = slashdiv_state +1;
|
||||
public static final int regexpg_state = regexp_state +1;
|
||||
public static final int regexpi_state = regexpg_state +1;
|
||||
public static final int regexpm_state = regexpi_state +1;
|
||||
public static final int regexpgi_state = regexpm_state +1;
|
||||
public static final int regexpgm_state = regexpgi_state +1;
|
||||
public static final int regexpim_state = regexpgm_state +1;
|
||||
public static final int regexpgim_state = regexpim_state +1;
|
||||
public static final int pound_state = regexpgim_state +1;
|
||||
public static final int ampersand_state = pound_state +1;
|
||||
public static final int arrow_state = ampersand_state +1;
|
||||
|
||||
public static final int a_state = arrow_state+1;
|
||||
public static final int ab_state = a_state+1;
|
||||
public static final int abs_state = ab_state+1;
|
||||
public static final int abst_state = abs_state+1;
|
||||
public static final int abstr_state = abst_state+1;
|
||||
public static final int abstra_state = abstr_state+1;
|
||||
public static final int abstrac_state = abstra_state+1;
|
||||
public static final int abstract_state = abstrac_state+1;
|
||||
public static final int at_state = abstract_state +1;
|
||||
public static final int att_state = at_state+1;
|
||||
public static final int attr_state = att_state+1;
|
||||
public static final int attri_state = attr_state+1;
|
||||
public static final int attrib_state = attri_state+1;
|
||||
public static final int attribu_state = attrib_state+1;
|
||||
public static final int attribut_state = attribu_state+1;
|
||||
public static final int attribute_state = attribut_state+1;
|
||||
public static final int b_state = attribute_state+1;
|
||||
public static final int bo_state = b_state+1;
|
||||
public static final int boo_state = bo_state+1;
|
||||
public static final int bool_state = boo_state+1;
|
||||
public static final int boole_state = bool_state+1;
|
||||
public static final int boolea_state = boole_state+1;
|
||||
public static final int boolean_state = boolea_state+1;
|
||||
public static final int br_state = boolean_state+1;
|
||||
public static final int bre_state = br_state+1;
|
||||
public static final int brea_state = bre_state+1;
|
||||
public static final int break_state = brea_state+1;
|
||||
public static final int by_state = break_state+1;
|
||||
public static final int byt_state = by_state+1;
|
||||
public static final int byte_state = byt_state+1;
|
||||
public static final int c_state = byte_state+1;
|
||||
public static final int ca_state = c_state+1;
|
||||
public static final int cas_state = ca_state+1;
|
||||
public static final int case_state = cas_state+1;
|
||||
public static final int cat_state = case_state+1;
|
||||
public static final int catc_state = cat_state+1;
|
||||
public static final int catch_state = catc_state+1;
|
||||
public static final int ch_state = catch_state+1;
|
||||
public static final int cha_state = ch_state+1;
|
||||
public static final int char_state = cha_state+1;
|
||||
public static final int cl_state = char_state+1;
|
||||
public static final int cla_state = cl_state+1;
|
||||
public static final int clas_state = cla_state+1;
|
||||
public static final int class_state = clas_state+1;
|
||||
public static final int co_state = class_state+1;
|
||||
public static final int con_state = co_state+1;
|
||||
public static final int cont_state = con_state+1;
|
||||
public static final int conti_state = cont_state+1;
|
||||
public static final int contin_state = conti_state+1;
|
||||
public static final int continu_state = contin_state+1;
|
||||
public static final int continue_state = continu_state+1;
|
||||
public static final int cons_state = continue_state+1;
|
||||
public static final int const_state = cons_state+1;
|
||||
public static final int constr_state = const_state+1;
|
||||
public static final int constru_state = constr_state+1;
|
||||
public static final int construc_state = constru_state+1;
|
||||
public static final int construct_state = construc_state+1;
|
||||
public static final int constructo_state = construct_state+1;
|
||||
public static final int constructor_state = constructo_state+1;
|
||||
public static final int d_state = constructor_state+1;
|
||||
public static final int de_state = d_state+1;
|
||||
public static final int deb_state = de_state+1;
|
||||
public static final int debu_state = deb_state+1;
|
||||
public static final int debug_state = debu_state+1;
|
||||
public static final int debugg_state = debug_state+1;
|
||||
public static final int debugge_state = debugg_state+1;
|
||||
public static final int debugger_state = debugge_state+1;
|
||||
public static final int def_state = debugger_state+1;
|
||||
public static final int defa_state = def_state+1;
|
||||
public static final int defau_state = defa_state+1;
|
||||
public static final int defaul_state = defau_state+1;
|
||||
public static final int default_state = defaul_state+1;
|
||||
public static final int del_state = default_state+1;
|
||||
public static final int dele_state = del_state+1;
|
||||
public static final int delet_state = dele_state+1;
|
||||
public static final int delete_state = delet_state+1;
|
||||
public static final int do_state = delete_state+1;
|
||||
public static final int dou_state = do_state+1;
|
||||
public static final int doub_state = dou_state+1;
|
||||
public static final int doubl_state = doub_state+1;
|
||||
public static final int double_state = doubl_state+1;
|
||||
public static final int e_state = double_state+1;
|
||||
public static final int el_state = e_state+1;
|
||||
public static final int els_state = el_state+1;
|
||||
public static final int else_state = els_state+1;
|
||||
public static final int en_state = else_state+1;
|
||||
public static final int enu_state = en_state+1;
|
||||
public static final int enum_state = enu_state+1;
|
||||
public static final int ev_state = enum_state+1;
|
||||
public static final int eva_state = ev_state+1;
|
||||
public static final int eval_state = eva_state+1;
|
||||
public static final int ex_state = eval_state+1;
|
||||
public static final int exp_state = ex_state+1;
|
||||
public static final int expo_state = exp_state+1;
|
||||
public static final int expor_state = expo_state+1;
|
||||
public static final int export_state = expor_state+1;
|
||||
public static final int ext_state = export_state+1;
|
||||
public static final int exte_state = ext_state+1;
|
||||
public static final int exten_state = exte_state+1;
|
||||
public static final int extend_state = exten_state+1;
|
||||
public static final int extends_state = extend_state+1;
|
||||
public static final int f_state = extends_state+1;
|
||||
public static final int fa_state = f_state+1;
|
||||
public static final int fal_state = fa_state+1;
|
||||
public static final int fals_state = fal_state+1;
|
||||
public static final int false_state = fals_state+1;
|
||||
public static final int fi_state = false_state+1;
|
||||
public static final int fin_state = fi_state+1;
|
||||
public static final int fina_state = fin_state+1;
|
||||
public static final int final_state = fina_state+1;
|
||||
public static final int finall_state = final_state+1;
|
||||
public static final int finally_state = finall_state+1;
|
||||
public static final int fl_state = finally_state+1;
|
||||
public static final int flo_state = fl_state+1;
|
||||
public static final int floa_state = flo_state+1;
|
||||
public static final int float_state = floa_state+1;
|
||||
public static final int fo_state = float_state+1;
|
||||
public static final int for_state = fo_state+1;
|
||||
public static final int fu_state = for_state+1;
|
||||
public static final int fun_state = fu_state+1;
|
||||
public static final int func_state = fun_state+1;
|
||||
public static final int funct_state = func_state+1;
|
||||
public static final int functi_state = funct_state+1;
|
||||
public static final int functio_state = functi_state+1;
|
||||
public static final int function_state = functio_state+1;
|
||||
public static final int g_state = function_state+1;
|
||||
public static final int go_state = g_state+1;
|
||||
public static final int got_state = go_state+1;
|
||||
public static final int goto_state = got_state+1;
|
||||
public static final int i_state = goto_state+1;
|
||||
public static final int if_state = i_state+1;
|
||||
public static final int im_state = if_state+1;
|
||||
public static final int imp_state = im_state+1;
|
||||
public static final int impl_state = imp_state+1;
|
||||
public static final int imple_state = impl_state+1;
|
||||
public static final int implem_state = imple_state+1;
|
||||
public static final int impleme_state = implem_state+1;
|
||||
public static final int implemen_state = impleme_state+1;
|
||||
public static final int implement_state = implemen_state+1;
|
||||
public static final int implements_state = implement_state+1;
|
||||
public static final int impo_state = implements_state+1;
|
||||
public static final int impor_state = impo_state+1;
|
||||
public static final int import_state = impor_state+1;
|
||||
public static final int in_state = import_state+1;
|
||||
public static final int inc_state = in_state+1;
|
||||
public static final int incl_state = inc_state+1;
|
||||
public static final int inclu_state = incl_state+1;
|
||||
public static final int includ_state = inclu_state+1;
|
||||
public static final int include_state = includ_state+1;
|
||||
public static final int ins_state = include_state+1;
|
||||
public static final int inst_state = ins_state+1;
|
||||
public static final int insta_state = inst_state+1;
|
||||
public static final int instan_state = insta_state+1;
|
||||
public static final int instanc_state = instan_state+1;
|
||||
public static final int instance_state = instanc_state+1;
|
||||
public static final int instanceo_state = instance_state+1;
|
||||
public static final int instanceof_state = instanceo_state+1;
|
||||
public static final int int_state = instanceof_state+1;
|
||||
public static final int inte_state = int_state+1;
|
||||
public static final int inter_state = inte_state+1;
|
||||
public static final int interf_state = inter_state+1;
|
||||
public static final int interfa_state = interf_state+1;
|
||||
public static final int interfac_state = interfa_state+1;
|
||||
public static final int interface_state = interfac_state+1;
|
||||
public static final int l_state = interface_state+1;
|
||||
public static final int lo_state = l_state+1;
|
||||
public static final int lon_state = lo_state+1;
|
||||
public static final int long_state = lon_state+1;
|
||||
public static final int n_state = long_state+1;
|
||||
public static final int na_state = n_state+1;
|
||||
public static final int nam_state = na_state+1;
|
||||
public static final int name_state = nam_state+1;
|
||||
public static final int names_state = name_state+1;
|
||||
public static final int namesp_state = names_state+1;
|
||||
public static final int namespa_state = namesp_state+1;
|
||||
public static final int namespac_state = namespa_state+1;
|
||||
public static final int namespace_state = namespac_state+1;
|
||||
public static final int nat_state = namespace_state+1;
|
||||
public static final int nati_state = nat_state+1;
|
||||
public static final int nativ_state = nati_state+1;
|
||||
public static final int native_state = nativ_state+1;
|
||||
public static final int ne_state = native_state+1;
|
||||
public static final int new_state = ne_state+1;
|
||||
public static final int nu_state = new_state+1;
|
||||
public static final int nul_state = nu_state+1;
|
||||
public static final int null_state = nul_state+1;
|
||||
public static final int r_state = null_state+1;
|
||||
public static final int re_state = r_state+1;
|
||||
public static final int ret_state = re_state+1;
|
||||
public static final int retu_state = ret_state+1;
|
||||
public static final int retur_state = retu_state+1;
|
||||
public static final int return_state = retur_state +1;
|
||||
public static final int p_state = return_state +1;
|
||||
public static final int pa_state = p_state +1;
|
||||
public static final int pac_state = pa_state +1;
|
||||
public static final int pack_state = pac_state +1;
|
||||
public static final int packa_state = pack_state +1;
|
||||
public static final int packag_state = packa_state +1;
|
||||
public static final int package_state = packag_state +1;
|
||||
public static final int pr_state = package_state +1;
|
||||
public static final int pri_state = pr_state +1;
|
||||
public static final int priv_state = pri_state +1;
|
||||
public static final int priva_state = priv_state +1;
|
||||
public static final int privat_state = priva_state +1;
|
||||
public static final int private_state = privat_state +1;
|
||||
public static final int pro_state = private_state +1;
|
||||
public static final int prot_state = pro_state +1;
|
||||
public static final int prote_state = prot_state +1;
|
||||
public static final int protec_state = prote_state +1;
|
||||
public static final int protect_state = protec_state +1;
|
||||
public static final int protecte_state = protect_state +1;
|
||||
public static final int protected_state = protecte_state +1;
|
||||
public static final int pu_state = protected_state +1;
|
||||
public static final int pub_state = pu_state +1;
|
||||
public static final int publ_state = pub_state +1;
|
||||
public static final int publi_state = publ_state +1;
|
||||
public static final int public_state = publi_state +1;
|
||||
public static final int s_state = public_state +1;
|
||||
public static final int sh_state = s_state +1;
|
||||
public static final int sho_state = sh_state +1;
|
||||
public static final int shor_state = sho_state +1;
|
||||
public static final int short_state = shor_state +1;
|
||||
public static final int st_state = short_state +1;
|
||||
public static final int sta_state = st_state +1;
|
||||
public static final int stat_state = sta_state +1;
|
||||
public static final int stati_state = stat_state +1;
|
||||
public static final int static_state = stati_state +1;
|
||||
public static final int su_state = static_state +1;
|
||||
public static final int sup_state = su_state +1;
|
||||
public static final int supe_state = sup_state +1;
|
||||
public static final int super_state = supe_state +1;
|
||||
public static final int sw_state = super_state +1;
|
||||
public static final int swi_state = sw_state +1;
|
||||
public static final int swit_state = swi_state +1;
|
||||
public static final int switc_state = swit_state +1;
|
||||
public static final int switch_state = switc_state +1;
|
||||
public static final int sy_state = switch_state +1;
|
||||
public static final int syn_state = sy_state +1;
|
||||
public static final int sync_state = syn_state +1;
|
||||
public static final int synch_state = sync_state +1;
|
||||
public static final int synchr_state = synch_state +1;
|
||||
public static final int synchro_state = synchr_state +1;
|
||||
public static final int synchron_state = synchro_state +1;
|
||||
public static final int synchroni_state = synchron_state +1;
|
||||
public static final int synchroniz_state = synchroni_state +1;
|
||||
public static final int synchronize_state = synchroniz_state +1;
|
||||
public static final int synchronized_state = synchronize_state +1;
|
||||
public static final int t_state = synchronized_state+1;
|
||||
public static final int th_state = t_state +1;
|
||||
public static final int thi_state = th_state +1;
|
||||
public static final int this_state = thi_state +1;
|
||||
public static final int thr_state = this_state +1;
|
||||
public static final int thro_state = thr_state +1;
|
||||
public static final int throw_state = thro_state +1;
|
||||
public static final int throws_state = throw_state +1;
|
||||
public static final int tr_state = throws_state +1;
|
||||
public static final int tra_state = tr_state +1;
|
||||
public static final int tran_state = tra_state +1;
|
||||
public static final int trans_state = tran_state +1;
|
||||
public static final int transi_state = trans_state +1;
|
||||
public static final int transie_state = transi_state +1;
|
||||
public static final int transien_state = transie_state +1;
|
||||
public static final int transient_state = transien_state +1;
|
||||
public static final int tru_state = transient_state +1;
|
||||
public static final int true_state = tru_state +1;
|
||||
public static final int try_state = true_state +1;
|
||||
public static final int ty_state = try_state +1;
|
||||
public static final int typ_state = ty_state +1;
|
||||
public static final int type_state = typ_state +1;
|
||||
public static final int typeo_state = type_state +1;
|
||||
public static final int typeof_state = typeo_state +1;
|
||||
public static final int u_state = typeof_state +1;
|
||||
public static final int us_state = u_state+1;
|
||||
public static final int use_state = us_state+1;
|
||||
public static final int v_state = use_state+1;
|
||||
public static final int va_state = v_state +1;
|
||||
public static final int var_state = va_state +1;
|
||||
public static final int vo_state = var_state +1;
|
||||
public static final int vol_state = vo_state +1;
|
||||
public static final int vola_state = vol_state +1;
|
||||
public static final int volat_state = vola_state +1;
|
||||
public static final int volati_state = volat_state +1;
|
||||
public static final int volatil_state = volati_state +1;
|
||||
public static final int volatile_state = volatil_state +1;
|
||||
public static final int voi_state = volatile_state +1;
|
||||
public static final int void_state = voi_state +1;
|
||||
public static final int w_state = void_state +1;
|
||||
public static final int wh_state = w_state +1;
|
||||
public static final int whi_state = wh_state +1;
|
||||
public static final int whil_state = whi_state +1;
|
||||
public static final int while_state = whil_state +1;
|
||||
public static final int wi_state = while_state +1;
|
||||
public static final int wit_state = wi_state +1;
|
||||
public static final int with_state = wit_state +1;
|
||||
|
||||
public static final int blockcomment_state = with_state+1;
|
||||
public static final int blockcommentstar_state = blockcomment_state+1;
|
||||
public static final int linecomment_state = blockcommentstar_state+1;
|
||||
public static final int eol_state = linecomment_state+1;
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* Token.java
|
||||
*
|
||||
* This file implements the class Token that is used to carry
|
||||
* information from the Scanner to the Parser.
|
||||
*/
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public final class Token implements Tokens {
|
||||
|
||||
int tokenClass;
|
||||
String lexeme;
|
||||
|
||||
public Token( int tokenClass, String lexeme ) {
|
||||
this.tokenClass = tokenClass;
|
||||
this.lexeme = lexeme;
|
||||
}
|
||||
|
||||
public final int getTokenClass() {
|
||||
return tokenClass;
|
||||
}
|
||||
|
||||
public final String getTokenText() {
|
||||
if( tokenClass == stringliteral_token ) {
|
||||
// erase quotes.
|
||||
return lexeme.substring(1,lexeme.length()-1);
|
||||
}
|
||||
return lexeme;
|
||||
}
|
||||
|
||||
public final String getTokenSource() {
|
||||
return lexeme;
|
||||
}
|
||||
|
||||
public static String getTokenClassName( int token_class ) {
|
||||
return tokenClassNames[-1*token_class];
|
||||
}
|
||||
|
||||
/**
|
||||
* main()
|
||||
*
|
||||
* Unit test driver. Execute the command 'java Token' at the
|
||||
* shell to verify this class' basic functionality.
|
||||
*/
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Token begin");
|
||||
for(int i = 0; i>=stringliteral_token;i--) {
|
||||
System.out.println(tokenClassNames[-1*i]);
|
||||
}
|
||||
System.out.println("Token end");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
|
@ -0,0 +1,325 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mountain View Compiler
|
||||
* Company. Portions created by Mountain View Compiler Company are
|
||||
* Copyright (C) 1998-2000 Mountain View Compiler Company. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jeff Dyer <jeff@compilercompany.com>
|
||||
*/
|
||||
|
||||
package com.compilercompany.ecmascript;
|
||||
|
||||
/**
|
||||
* Tokens.java
|
||||
*
|
||||
* This interface defines values for each token class that occurs in
|
||||
* ECMAScript 4. All but numericliteral, stringliteral, regexpliteral, and
|
||||
* identifier are singleton and therefore a fully described by their
|
||||
* token class defined here. The other four however can have an infinite number
|
||||
* of instances each with a unique identifier and associated instance
|
||||
* data. We use positive identifiers to signify instances of these
|
||||
* token classes so that the instance data can be stored in an array,
|
||||
* or set of arrays with the token value specifying its index.
|
||||
*/
|
||||
|
||||
public interface Tokens {
|
||||
|
||||
/**
|
||||
* Token class values are negative, and token instances are positive so
|
||||
* that their values can point to their instance data in an array.
|
||||
*/
|
||||
|
||||
public static final int first_token = -1;
|
||||
public static final int eos_token = first_token-0;
|
||||
|
||||
public static final int minus_token = first_token - 1;
|
||||
public static final int minusminus_token = minus_token - 1;
|
||||
public static final int not_token = minusminus_token - 1;
|
||||
public static final int notequals_token = not_token - 1;
|
||||
public static final int strictnotequals_token = notequals_token - 1;
|
||||
public static final int pound_token = strictnotequals_token - 1;
|
||||
public static final int modulus_token = pound_token - 1;
|
||||
public static final int modulusassign_token = modulus_token - 1;
|
||||
public static final int bitwiseand_token = modulusassign_token - 1;
|
||||
public static final int logicaland_token = bitwiseand_token - 1;
|
||||
public static final int logicalandassign_token = logicaland_token - 1;
|
||||
public static final int bitwiseandassign_token = logicalandassign_token - 1;
|
||||
public static final int leftparen_token = bitwiseandassign_token - 1;
|
||||
public static final int rightparen_token = leftparen_token - 1;
|
||||
public static final int mult_token = rightparen_token - 1;
|
||||
public static final int multassign_token = mult_token - 1;
|
||||
public static final int comma_token = multassign_token - 1;
|
||||
public static final int dot_token = comma_token - 1;
|
||||
public static final int doubledot_token = dot_token - 1;
|
||||
public static final int tripledot_token = doubledot_token - 1;
|
||||
public static final int div_token = tripledot_token - 1;
|
||||
public static final int divassign_token = div_token - 1;
|
||||
public static final int colon_token = divassign_token - 1;
|
||||
public static final int doublecolon_token = colon_token - 1;
|
||||
public static final int semicolon_token = doublecolon_token - 1;
|
||||
public static final int questionmark_token = semicolon_token - 1;
|
||||
public static final int ampersand_token = questionmark_token - 1;
|
||||
public static final int leftbracket_token = ampersand_token - 1;
|
||||
public static final int rightbracket_token = leftbracket_token - 1 ;
|
||||
public static final int bitwisexor_token = rightbracket_token - 1;
|
||||
public static final int logicalxor_token = bitwisexor_token - 1;
|
||||
public static final int logicalxorassign_token = logicalxor_token - 1;
|
||||
public static final int bitwisexorassign_token = logicalxorassign_token - 1;
|
||||
public static final int leftbrace_token = bitwisexorassign_token - 1;
|
||||
public static final int bitwiseor_token = leftbrace_token - 1;
|
||||
public static final int logicalor_token = bitwiseor_token - 1;
|
||||
public static final int logicalorassign_token = logicalor_token - 1;
|
||||
public static final int bitwiseorassign_token = logicalorassign_token - 1;
|
||||
public static final int rightbrace_token = bitwiseorassign_token - 1;
|
||||
public static final int bitwisenot_token = rightbrace_token - 1;
|
||||
public static final int plus_token = bitwisenot_token - 1;
|
||||
public static final int plusplus_token = plus_token - 1;
|
||||
public static final int plusassign_token = plusplus_token - 1;
|
||||
public static final int lessthan_token = plusassign_token - 1;
|
||||
public static final int leftshift_token = lessthan_token - 1;
|
||||
public static final int leftshiftassign_token = leftshift_token - 1;
|
||||
public static final int lessthanorequals_token = leftshiftassign_token - 1;
|
||||
public static final int assign_token = lessthanorequals_token - 1;
|
||||
public static final int minusassign_token = assign_token - 1;
|
||||
public static final int equals_token = minusassign_token - 1;
|
||||
public static final int strictequals_token = equals_token - 1;
|
||||
public static final int greaterthan_token = strictequals_token - 1;
|
||||
public static final int arrow_token = greaterthan_token - 1;
|
||||
public static final int greaterthanorequals_token = arrow_token - 1;
|
||||
public static final int rightshift_token = greaterthanorequals_token - 1;
|
||||
public static final int rightshiftassign_token = rightshift_token - 1;
|
||||
public static final int unsignedrightshift_token = rightshiftassign_token - 1;
|
||||
public static final int unsignedrightshiftassign_token = unsignedrightshift_token - 1;
|
||||
public static final int abstract_token = unsignedrightshiftassign_token - 1;
|
||||
public static final int attribute_token = abstract_token - 1;
|
||||
public static final int boolean_token = attribute_token - 1;
|
||||
public static final int break_token = boolean_token - 1;
|
||||
public static final int byte_token = break_token - 1;
|
||||
public static final int case_token = byte_token - 1;
|
||||
public static final int catch_token = case_token - 1;
|
||||
public static final int char_token = catch_token - 1;
|
||||
public static final int class_token = char_token - 1;
|
||||
public static final int const_token = class_token - 1;
|
||||
public static final int constructor_token = const_token - 1;
|
||||
public static final int continue_token = constructor_token - 1;
|
||||
public static final int debugger_token = continue_token - 1;
|
||||
public static final int default_token = debugger_token - 1;
|
||||
public static final int delete_token = default_token - 1;
|
||||
public static final int do_token = delete_token - 1;
|
||||
public static final int double_token = do_token - 1;
|
||||
public static final int else_token = double_token - 1;
|
||||
public static final int enum_token = else_token - 1;
|
||||
public static final int eval_token = enum_token - 1;
|
||||
public static final int export_token = eval_token - 1;
|
||||
public static final int extends_token = export_token - 1;
|
||||
public static final int false_token = extends_token - 1;
|
||||
public static final int final_token = false_token - 1;
|
||||
public static final int finally_token = final_token - 1;
|
||||
public static final int float_token = finally_token - 1;
|
||||
public static final int for_token = float_token - 1;
|
||||
public static final int function_token = for_token - 1;
|
||||
public static final int get_token = function_token - 1;
|
||||
public static final int goto_token = get_token - 1;
|
||||
public static final int if_token = goto_token - 1;
|
||||
public static final int implements_token = if_token - 1;
|
||||
public static final int import_token = implements_token - 1;
|
||||
public static final int in_token = import_token - 1;
|
||||
public static final int include_token = in_token - 1;
|
||||
public static final int instanceof_token = include_token - 1;
|
||||
public static final int int_token = instanceof_token - 1;
|
||||
public static final int interface_token = int_token - 1;
|
||||
public static final int long_token = interface_token - 1;
|
||||
public static final int namespace_token = long_token - 1;
|
||||
public static final int native_token = namespace_token - 1;
|
||||
public static final int new_token = native_token - 1;
|
||||
public static final int null_token = new_token - 1;
|
||||
public static final int package_token = null_token - 1;
|
||||
public static final int private_token = package_token - 1;
|
||||
public static final int protected_token = private_token - 1;
|
||||
public static final int public_token = protected_token - 1;
|
||||
public static final int return_token = public_token - 1;
|
||||
public static final int set_token = return_token - 1;
|
||||
public static final int short_token = set_token - 1;
|
||||
public static final int static_token = short_token - 1;
|
||||
public static final int super_token = static_token - 1;
|
||||
public static final int switch_token = super_token - 1;
|
||||
public static final int synchronized_token = switch_token - 1;
|
||||
public static final int this_token = synchronized_token - 1;
|
||||
public static final int throw_token = this_token - 1;
|
||||
public static final int throws_token = throw_token - 1;
|
||||
public static final int transient_token = throws_token - 1;
|
||||
public static final int true_token = transient_token - 1;
|
||||
public static final int try_token = true_token - 1;
|
||||
public static final int typeof_token = try_token - 1;
|
||||
public static final int use_token = typeof_token - 1;
|
||||
public static final int var_token = use_token - 1;
|
||||
public static final int void_token = var_token - 1;
|
||||
public static final int volatile_token = void_token - 1;
|
||||
public static final int while_token = volatile_token - 1;
|
||||
public static final int with_token = while_token - 1;
|
||||
public static final int identifier_token = with_token - 1;
|
||||
public static final int numberliteral_token = identifier_token - 1;
|
||||
public static final int regexpliteral_token = numberliteral_token - 1;
|
||||
public static final int stringliteral_token = regexpliteral_token - 1;
|
||||
|
||||
public static final int eol_token = stringliteral_token - 1;
|
||||
|
||||
public static final int empty_token = eol_token - 1;
|
||||
public static final int error_token = empty_token - 1;
|
||||
public static final int last_token = empty_token - 1;
|
||||
|
||||
public static final String[] tokenClassNames = {
|
||||
"<unused index>",
|
||||
"<eos>",
|
||||
"minus_token",
|
||||
"minusminus_token",
|
||||
"not_token",
|
||||
"notequals_token",
|
||||
"strictnotequals_token",
|
||||
"pound_token",
|
||||
"modulus_token",
|
||||
"modulusassign_token",
|
||||
"bitwiseand_token",
|
||||
"logicaland_token",
|
||||
"logicalandassign_token",
|
||||
"bitwiseandassign_token",
|
||||
"leftparen_token",
|
||||
"rightparen_token",
|
||||
"mult_token",
|
||||
"multassign_token",
|
||||
"comma_token",
|
||||
"dot_token",
|
||||
"doubledot_token",
|
||||
"tripledot_token",
|
||||
"div_token",
|
||||
"divassign_token",
|
||||
"colon_token",
|
||||
"doublecolon_token",
|
||||
"semicolon_token",
|
||||
"questionmark_token",
|
||||
"ampersand_token",
|
||||
"leftbracket_token",
|
||||
"rightbracket_token",
|
||||
"bitwisexor_token",
|
||||
"logicalxor_token",
|
||||
"logicalxorassign_token",
|
||||
"bitwisexorassign_token",
|
||||
"leftbrace_token",
|
||||
"bitwiseor_token",
|
||||
"logicalor_token",
|
||||
"logicalorassign_token",
|
||||
"bitwiseorassign_token",
|
||||
"rightbrace_token",
|
||||
"bitwisenot_token",
|
||||
"plus_token",
|
||||
"plusplus_token",
|
||||
"plusassign_token",
|
||||
"lessthan_token",
|
||||
"leftshift_token",
|
||||
"leftshiftassign_token",
|
||||
"lessthanorequals_token",
|
||||
"assign_token",
|
||||
"minusassign_token",
|
||||
"equals_token",
|
||||
"strictequals_token",
|
||||
"greaterthan_token",
|
||||
"arrow_token",
|
||||
"greaterthanorequals_token",
|
||||
"rightshift_token",
|
||||
"rightshiftassign_token",
|
||||
"unsignedrightshift_token",
|
||||
"unsignedrightshiftassign_token",
|
||||
"abstract_token",
|
||||
"attribute_token",
|
||||
"boolean_token",
|
||||
"break_token",
|
||||
"byte_token",
|
||||
"case_token",
|
||||
"catch_token",
|
||||
"char_token",
|
||||
"class_token",
|
||||
"const_token",
|
||||
"constructor_token",
|
||||
"continue_token",
|
||||
"debugger_token",
|
||||
"default_token",
|
||||
"delete_token",
|
||||
"do_token",
|
||||
"double_token",
|
||||
"else_token",
|
||||
"enum_token",
|
||||
"eval_token",
|
||||
"export_token",
|
||||
"extends_token",
|
||||
"false_token",
|
||||
"final_token",
|
||||
"finally_token",
|
||||
"float_token",
|
||||
"for_token",
|
||||
"function_token",
|
||||
"get_token",
|
||||
"goto_token",
|
||||
"if_token",
|
||||
"implements_token",
|
||||
"import_token",
|
||||
"in_token",
|
||||
"include_token",
|
||||
"instanceof_token",
|
||||
"int_token",
|
||||
"interface_token",
|
||||
"long_token",
|
||||
"namespace_token",
|
||||
"native_token",
|
||||
"new_token",
|
||||
"null_token",
|
||||
"package_token",
|
||||
"private_token",
|
||||
"protected_token",
|
||||
"public_token",
|
||||
"return_token",
|
||||
"set_token",
|
||||
"short_token",
|
||||
"static_token",
|
||||
"super_token",
|
||||
"switch_token",
|
||||
"synchronized_token",
|
||||
"this_token",
|
||||
"throw_token",
|
||||
"throws_token",
|
||||
"transient_token",
|
||||
"true_token",
|
||||
"try_token",
|
||||
"typeof_token",
|
||||
"use_token",
|
||||
"var_token",
|
||||
"void_token",
|
||||
"volatile_token",
|
||||
"while_token",
|
||||
"with_token",
|
||||
"identifier_token",
|
||||
"numberliteral_token",
|
||||
"regexpliteral_token",
|
||||
"stringliteral_token",
|
||||
|
||||
"<eol>",
|
||||
"<empty>",
|
||||
"<error>"
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче