Compare commits
1 Commits
JS2_PROTOT
...
src
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
258dc9fead |
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
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 oqr
|
||||
implied. See the License for the specific language governing
|
||||
rights and limitations under the License.
|
||||
|
||||
The Original Code is the JavaScript 2 Prototype.
|
||||
|
||||
The Initial Developer of the Original Code is Netscape
|
||||
Communications Corporation. Portions created by Netscape are
|
||||
Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
Rights Reserved.
|
||||
|
||||
Alternatively, the contents of this file may be used under the
|
||||
terms of the GNU Public License (the "GPL"), in which case the
|
||||
provisions of the GPL are applicable instead of those above.
|
||||
If you wish to allow use of your version of this file only
|
||||
under the terms of the GPL and not to allow others to use your
|
||||
version of this file under the NPL, indicate your decision by
|
||||
deleting the provisions above and replace them with the notice
|
||||
and other provisions required by the GPL. If you do not delete
|
||||
the provisions above, a recipient may use your version of this
|
||||
file under either the NPL or the GPL.
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
2001-01-30 <rginda@netscape.com>
|
||||
|
||||
* broke apart some classes contained parser.* and utilities.* into
|
||||
seperate files.
|
||||
parser.* begat lexer.*, token.*, reader.*
|
||||
utilities.* begat mem.*, stlcfg.h, ds.h, strings.*, exception.*,
|
||||
formatter.*, and algo.h
|
||||
* parser reorg compile time data:
|
||||
|
||||
new layout: 0:48.01elapsed 86%CPU
|
||||
old layout: 0:55.85elapsed 57%CPU
|
||||
|
||||
(old layout includes only hash numerics utilities parser world object
|
||||
files)
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
|
||||
SUBDIRS = src tests
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
parse functions
|
||||
parseIdentifierQualifiers(ExprNode *e, bool &foundQualifiers,
|
||||
parseParenthesesAndIdentifierQualifiers(const Token &tParen,
|
||||
parseQualifiedIdentifier(const Token &t, bool preferRegExp)
|
||||
parseArrayLiteral(const Token &initialToken)
|
||||
parseObjectLiteral(const Token &initialToken)
|
||||
parsePrimaryExpression()
|
||||
parseMember(ExprNode *target, const Token &tOperator,
|
||||
parseInvoke(ExprNode *target, uint32 pos,
|
||||
parsePostfixExpression(bool newExpression)
|
||||
parseUnaryExpression()
|
||||
parseExpression(bool noIn, bool noAssignment, bool noComma)
|
||||
parseParenthesizedExpression()
|
||||
parseTypeExpression(bool noIn)
|
||||
parseTypedIdentifier(ExprNode *&type)
|
||||
parseTypeBinding(Token::Kind kind, bool noIn)
|
||||
parseTypeListBinding(Token::Kind kind)
|
||||
parseVariableBinding(bool noQualifiers, bool noIn)
|
||||
parseFunctionName(FunctionName &fn)
|
||||
parseFunctionSignature(FunctionDefinition &fd)
|
||||
parseBlock(bool inSwitch, bool noCloseBrace)
|
||||
parseBody(SemicolonState *semicolonState)
|
||||
parseAttributeStatement(uint32 pos, IdentifierList *attributes,
|
||||
parseAttributesAndStatement(const Token *t, AttributeStatement as,
|
||||
parseAnnotatedBlock()
|
||||
parseFor(uint32 pos, SemicolonState &semicolonState)
|
||||
parseTry(uint32 pos)
|
||||
parseStatement(bool /*topLevel*/, bool inSwitch,
|
||||
parseStatementAndSemicolon(SemicolonState &semicolonState)
|
||||
parseIdentifier()
|
||||
parseLiteralField()
|
||||
parseFieldName()
|
||||
parseArgumentList(NodeQueue<ExprPairList> &args)
|
||||
parseArgumentListPrime(NodeQueue<ExprPairList> &args)
|
||||
parseNamedArgumentListPrime(NodeQueue<ExprPairList> &args)
|
||||
parseAllParameters(FunctionDefinition &fd,
|
||||
parseOptionalNamedRestParameters (FunctionDefinition &fd,
|
||||
parseNamedRestParameters(FunctionDefinition &fd,
|
||||
parseNamedParameters(FunctionDefinition &fd,
|
||||
parseRestParameter()
|
||||
parseParameter()
|
||||
parseOptionalParameter()
|
||||
parseOptionalParameterPrime(VariableBinding *first)
|
||||
parseNamedParameter(NodeQueue<IdentifierList> &aliases)
|
||||
parseResultSignature()
|
||||
|
||||
|
||||
1/28/01
|
||||
|
||||
Files:
|
||||
|
||||
cpucfg.h
|
||||
|
||||
formatter.cpp formatter.h
|
||||
"Formatter" class, iostream like wrapper around stdio.
|
||||
|
||||
gc_allocator.h, gc_container.h
|
||||
boehm gc stuff.
|
||||
|
||||
hash.cpp hash.h
|
||||
a hash
|
||||
|
||||
lexer.cpp lexer.h
|
||||
main lexer.
|
||||
|
||||
mem.cpp mem.h
|
||||
zone, arena, and pool classes for memory management.
|
||||
|
||||
nodefactory.h
|
||||
parse node factory.
|
||||
|
||||
numerics.cpp numerics.h
|
||||
numbers and stuff.
|
||||
|
||||
parser.cpp parser.h
|
||||
main parser source.
|
||||
tables in parser.h:
|
||||
enum ExprNode::Kind; types of expressions
|
||||
enum StmtNode::Kind; types of statements
|
||||
|
||||
|
||||
reader.cpp reader.h
|
||||
"Reader" class, feeds source to the parser/lexer.
|
||||
|
||||
stlcfg.h
|
||||
stupid stl tricks
|
||||
.
|
||||
systemtypes.h
|
||||
basic typedefs.
|
||||
|
||||
token.cpp token.h
|
||||
token class.
|
||||
|
||||
utilities.cpp utilities.h
|
||||
random things.
|
||||
|
||||
world.cpp world.h
|
||||
the whole world.
|
||||
@@ -1,26 +0,0 @@
|
||||
redo parseAllPArameters code
|
||||
|
||||
|
||||
move js/js2 to js2/src
|
||||
move js/semantics to js2/semantics
|
||||
|
||||
compile on mac and windows
|
||||
|
||||
parser:
|
||||
|
||||
1. Parser is out of date (by 10%?)
|
||||
a. rework parser to reflect grammer productions.
|
||||
b. functional attrs.
|
||||
c. parser node struct changes.
|
||||
|
||||
2. Parser Restructuring (2 weeks.)
|
||||
|
||||
3. Common lisp generator running?
|
||||
|
||||
4. const-ness
|
||||
a. compile time detection.
|
||||
b. read before assign.
|
||||
c. runtime assignment prevention.
|
||||
d. class/ function/ const equivalence.
|
||||
|
||||
export, namespace, import, package ?
|
||||
140
mozilla/js2/aclocal.m4
vendored
140
mozilla/js2/aclocal.m4
vendored
@@ -1,140 +0,0 @@
|
||||
dnl aclocal.m4 generated automatically by aclocal 1.4
|
||||
|
||||
dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
|
||||
dnl This file is free software; the Free Software Foundation
|
||||
dnl gives unlimited permission to copy and/or distribute it,
|
||||
dnl with or without modifications, as long as this notice is preserved.
|
||||
|
||||
dnl This program is distributed in the hope that it will be useful,
|
||||
dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
dnl PARTICULAR PURPOSE.
|
||||
|
||||
# Do all the work for Automake. This macro actually does too much --
|
||||
# some checks are only needed if your package does certain things.
|
||||
# But this isn't really a big deal.
|
||||
|
||||
# serial 1
|
||||
|
||||
dnl Usage:
|
||||
dnl AM_INIT_AUTOMAKE(package,version, [no-define])
|
||||
|
||||
AC_DEFUN(AM_INIT_AUTOMAKE,
|
||||
[AC_REQUIRE([AC_PROG_INSTALL])
|
||||
PACKAGE=[$1]
|
||||
AC_SUBST(PACKAGE)
|
||||
VERSION=[$2]
|
||||
AC_SUBST(VERSION)
|
||||
dnl test to see if srcdir already configured
|
||||
if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then
|
||||
AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
|
||||
fi
|
||||
ifelse([$3],,
|
||||
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
|
||||
AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package]))
|
||||
AC_REQUIRE([AM_SANITY_CHECK])
|
||||
AC_REQUIRE([AC_ARG_PROGRAM])
|
||||
dnl FIXME This is truly gross.
|
||||
missing_dir=`cd $ac_aux_dir && pwd`
|
||||
AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
|
||||
AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
|
||||
AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
|
||||
AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
|
||||
AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
|
||||
AC_REQUIRE([AC_PROG_MAKE_SET])])
|
||||
|
||||
#
|
||||
# Check to make sure that the build environment is sane.
|
||||
#
|
||||
|
||||
AC_DEFUN(AM_SANITY_CHECK,
|
||||
[AC_MSG_CHECKING([whether build environment is sane])
|
||||
# Just in case
|
||||
sleep 1
|
||||
echo timestamp > conftestfile
|
||||
# Do `set' in a subshell so we don't clobber the current shell's
|
||||
# arguments. Must try -L first in case configure is actually a
|
||||
# symlink; some systems play weird games with the mod time of symlinks
|
||||
# (eg FreeBSD returns the mod time of the symlink's containing
|
||||
# directory).
|
||||
if (
|
||||
set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null`
|
||||
if test "[$]*" = "X"; then
|
||||
# -L didn't work.
|
||||
set X `ls -t $srcdir/configure conftestfile`
|
||||
fi
|
||||
if test "[$]*" != "X $srcdir/configure conftestfile" \
|
||||
&& test "[$]*" != "X conftestfile $srcdir/configure"; then
|
||||
|
||||
# If neither matched, then we have a broken ls. This can happen
|
||||
# if, for instance, CONFIG_SHELL is bash and it inherits a
|
||||
# broken ls alias from the environment. This has actually
|
||||
# happened. Such a system could not be considered "sane".
|
||||
AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken
|
||||
alias in your environment])
|
||||
fi
|
||||
|
||||
test "[$]2" = conftestfile
|
||||
)
|
||||
then
|
||||
# Ok.
|
||||
:
|
||||
else
|
||||
AC_MSG_ERROR([newly created file is older than distributed files!
|
||||
Check your system clock])
|
||||
fi
|
||||
rm -f conftest*
|
||||
AC_MSG_RESULT(yes)])
|
||||
|
||||
dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY)
|
||||
dnl The program must properly implement --version.
|
||||
AC_DEFUN(AM_MISSING_PROG,
|
||||
[AC_MSG_CHECKING(for working $2)
|
||||
# Run test in a subshell; some versions of sh will print an error if
|
||||
# an executable is not found, even if stderr is redirected.
|
||||
# Redirect stdin to placate older versions of autoconf. Sigh.
|
||||
if ($2 --version) < /dev/null > /dev/null 2>&1; then
|
||||
$1=$2
|
||||
AC_MSG_RESULT(found)
|
||||
else
|
||||
$1="$3/missing $2"
|
||||
AC_MSG_RESULT(missing)
|
||||
fi
|
||||
AC_SUBST($1)])
|
||||
|
||||
# Define a conditional.
|
||||
|
||||
AC_DEFUN(AM_CONDITIONAL,
|
||||
[AC_SUBST($1_TRUE)
|
||||
AC_SUBST($1_FALSE)
|
||||
if $2; then
|
||||
$1_TRUE=
|
||||
$1_FALSE='#'
|
||||
else
|
||||
$1_TRUE='#'
|
||||
$1_FALSE=
|
||||
fi])
|
||||
|
||||
# Like AC_CONFIG_HEADER, but automatically create stamp file.
|
||||
|
||||
AC_DEFUN(AM_CONFIG_HEADER,
|
||||
[AC_PREREQ([2.12])
|
||||
AC_CONFIG_HEADER([$1])
|
||||
dnl When config.status generates a header, we must update the stamp-h file.
|
||||
dnl This file resides in the same directory as the config header
|
||||
dnl that is generated. We must strip everything past the first ":",
|
||||
dnl and everything past the last "/".
|
||||
AC_OUTPUT_COMMANDS(changequote(<<,>>)dnl
|
||||
ifelse(patsubst(<<$1>>, <<[^ ]>>, <<>>), <<>>,
|
||||
<<test -z "<<$>>CONFIG_HEADERS" || echo timestamp > patsubst(<<$1>>, <<^\([^:]*/\)?.*>>, <<\1>>)stamp-h<<>>dnl>>,
|
||||
<<am_indx=1
|
||||
for am_file in <<$1>>; do
|
||||
case " <<$>>CONFIG_HEADERS " in
|
||||
*" <<$>>am_file "*<<)>>
|
||||
echo timestamp > `echo <<$>>am_file | sed -e 's%:.*%%' -e 's%[^/]*$%%'`stamp-h$am_indx
|
||||
;;
|
||||
esac
|
||||
am_indx=`expr "<<$>>am_indx" + 1`
|
||||
done<<>>dnl>>)
|
||||
changequote([,]))])
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
|
||||
BOEHM_DIR = $(top_srcdir)/../gc/boehm/
|
||||
LIBBOEHM = $(BOEHM_DIR)/gc.a
|
||||
|
||||
JS2_DIR = $(top_srcdir)/src/
|
||||
LIBJS2 = $(JS2_DIR)/libjs2.a
|
||||
|
||||
WFLAGS = -Wmissing-prototypes -Wstrict-prototypes -Wunused \
|
||||
-Wswitch
|
||||
|
||||
|
||||
if DEBUG
|
||||
CXXFLAGS = -DXP_UNIX -g -DDEBUG -DNEW_PARSER $(WFLAGS)
|
||||
else
|
||||
CXXFLAGS = -DXP_UNIX -O2 -DNEW_PARSER -Wuninitialized $(WFLAGS)
|
||||
endif
|
||||
@@ -1,42 +0,0 @@
|
||||
/* config.h.in. Generated automatically from configure.in by autoheader. */
|
||||
|
||||
/* Define if using alloca.c. */
|
||||
#undef C_ALLOCA
|
||||
|
||||
/* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems.
|
||||
This function is required for alloca.c support on those systems. */
|
||||
#undef CRAY_STACKSEG_END
|
||||
|
||||
/* Define if you have alloca, as a function or macro. */
|
||||
#undef HAVE_ALLOCA
|
||||
|
||||
/* Define if you have <alloca.h> and it should be used (not on Ultrix). */
|
||||
#undef HAVE_ALLOCA_H
|
||||
|
||||
/* Define if you have a working `mmap' system call. */
|
||||
#undef HAVE_MMAP
|
||||
|
||||
/* If using the C implementation of alloca, define if you know the
|
||||
direction of stack growth for your system; otherwise it will be
|
||||
automatically deduced at run-time.
|
||||
STACK_DIRECTION > 0 => grows toward higher addresses
|
||||
STACK_DIRECTION < 0 => grows toward lower addresses
|
||||
STACK_DIRECTION = 0 => direction of growth unknown
|
||||
*/
|
||||
#undef STACK_DIRECTION
|
||||
|
||||
/* Define if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Define if you have the getpagesize function. */
|
||||
#undef HAVE_GETPAGESIZE
|
||||
|
||||
/* Define if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Name of package */
|
||||
#undef PACKAGE
|
||||
|
||||
/* Version number of package */
|
||||
#undef VERSION
|
||||
|
||||
2407
mozilla/js2/configure
vendored
2407
mozilla/js2/configure
vendored
File diff suppressed because it is too large
Load Diff
@@ -1,57 +0,0 @@
|
||||
dnl Process this file with autoconf to produce a configure script.
|
||||
|
||||
PACKAGE=JavaScript2
|
||||
VERSION=0.1
|
||||
AC_INIT(src/parser.h)
|
||||
AM_INIT_AUTOMAKE(JavaScript2, 0.1)
|
||||
|
||||
AC_ARG_ENABLE(debug,
|
||||
[ --enable-debug Turn on debugging],
|
||||
[case "${enableval}" in
|
||||
yes) debug=true ;;
|
||||
no) debug=false ;;
|
||||
*) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;;
|
||||
esac],[debug=false])
|
||||
AM_CONDITIONAL(DEBUG, test x$debug = xtrue)
|
||||
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
dnl Checks for programs.
|
||||
AC_PROG_CXX
|
||||
AC_PROG_AWK
|
||||
AC_PROG_CC
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_LN_S
|
||||
AC_PROG_MAKE_SET
|
||||
AC_PROG_RANLIB
|
||||
dnl AM_PATH_GTK(1.2.0, ,
|
||||
dnl AC_MSG_ERROR(Cannot find GTK: Is gtk-config in path?))
|
||||
|
||||
dnl Checks for libraries.
|
||||
dnl Replace `main' with a function in -ldl:
|
||||
dnl AC_CHECK_LIB(dl, main)
|
||||
dnl Replace `main' with a function in -lgdk:
|
||||
dnl AC_CHECK_LIB(gdk, main)
|
||||
dnl Replace `main' with a function in -lglib:
|
||||
dnl AC_CHECK_LIB(glib, main)
|
||||
dnl Replace `main' with a function in -lgmodule:
|
||||
dnl AC_CHECK_LIB(gmodule, main)
|
||||
dnl Replace `main' with a function in -lgtk:
|
||||
dnl AC_CHECK_LIB(gtk, main)
|
||||
dnl Replace `main' with a function in -lm:
|
||||
dnl AC_CHECK_LIB(m, main)
|
||||
|
||||
dnl Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
dnl AC_CHECK_HEADERS(fcntl.h limits.h malloc.h strings.h unistd.h)
|
||||
|
||||
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||
dnl AC_C_CONST
|
||||
dnl AC_C_INLINE
|
||||
dnl AC_TYPE_SIZE_T
|
||||
|
||||
dnl Checks for library functions.
|
||||
AC_FUNC_ALLOCA
|
||||
AC_FUNC_MMAP
|
||||
dnl AC_CHECK_FUNCS(getcwd getwd putenv strdup strerror tcgetattr)
|
||||
|
||||
AC_OUTPUT(./Makefile src/Makefile tests/Makefile tests/cpp/Makefile tests/js/Makefile)
|
||||
@@ -1,251 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# install - install a program, script, or datafile
|
||||
# This comes from X11R5 (mit/util/scripts/install.sh).
|
||||
#
|
||||
# Copyright 1991 by the Massachusetts Institute of Technology
|
||||
#
|
||||
# Permission to use, copy, modify, distribute, and sell this software and its
|
||||
# documentation for any purpose is hereby granted without fee, provided that
|
||||
# the above copyright notice appear in all copies and that both that
|
||||
# copyright notice and this permission notice appear in supporting
|
||||
# documentation, and that the name of M.I.T. not be used in advertising or
|
||||
# publicity pertaining to distribution of the software without specific,
|
||||
# written prior permission. M.I.T. makes no representations about the
|
||||
# suitability of this software for any purpose. It is provided "as is"
|
||||
# without express or implied warranty.
|
||||
#
|
||||
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||
# `make' implicit rules from creating a file called install from it
|
||||
# when there is no Makefile.
|
||||
#
|
||||
# This script is compatible with the BSD install script, but was written
|
||||
# from scratch. It can only install one file at a time, a restriction
|
||||
# shared with many OS's install programs.
|
||||
|
||||
|
||||
# set DOITPROG to echo to test this script
|
||||
|
||||
# Don't use :- since 4.3BSD and earlier shells don't like it.
|
||||
doit="${DOITPROG-}"
|
||||
|
||||
|
||||
# put in absolute paths if you don't have them in your path; or use env. vars.
|
||||
|
||||
mvprog="${MVPROG-mv}"
|
||||
cpprog="${CPPROG-cp}"
|
||||
chmodprog="${CHMODPROG-chmod}"
|
||||
chownprog="${CHOWNPROG-chown}"
|
||||
chgrpprog="${CHGRPPROG-chgrp}"
|
||||
stripprog="${STRIPPROG-strip}"
|
||||
rmprog="${RMPROG-rm}"
|
||||
mkdirprog="${MKDIRPROG-mkdir}"
|
||||
|
||||
transformbasename=""
|
||||
transform_arg=""
|
||||
instcmd="$mvprog"
|
||||
chmodcmd="$chmodprog 0755"
|
||||
chowncmd=""
|
||||
chgrpcmd=""
|
||||
stripcmd=""
|
||||
rmcmd="$rmprog -f"
|
||||
mvcmd="$mvprog"
|
||||
src=""
|
||||
dst=""
|
||||
dir_arg=""
|
||||
|
||||
while [ x"$1" != x ]; do
|
||||
case $1 in
|
||||
-c) instcmd="$cpprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-d) dir_arg=true
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-m) chmodcmd="$chmodprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-o) chowncmd="$chownprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-g) chgrpcmd="$chgrpprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-s) stripcmd="$stripprog"
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
*) if [ x"$src" = x ]
|
||||
then
|
||||
src=$1
|
||||
else
|
||||
# this colon is to work around a 386BSD /bin/sh bug
|
||||
:
|
||||
dst=$1
|
||||
fi
|
||||
shift
|
||||
continue;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ x"$src" = x ]
|
||||
then
|
||||
echo "install: no input file specified"
|
||||
exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]; then
|
||||
dst=$src
|
||||
src=""
|
||||
|
||||
if [ -d $dst ]; then
|
||||
instcmd=:
|
||||
chmodcmd=""
|
||||
else
|
||||
instcmd=mkdir
|
||||
fi
|
||||
else
|
||||
|
||||
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
|
||||
# might cause directories to be created, which would be especially bad
|
||||
# if $src (and thus $dsttmp) contains '*'.
|
||||
|
||||
if [ -f $src -o -d $src ]
|
||||
then
|
||||
true
|
||||
else
|
||||
echo "install: $src does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ x"$dst" = x ]
|
||||
then
|
||||
echo "install: no destination specified"
|
||||
exit 1
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
# If destination is a directory, append the input filename; if your system
|
||||
# does not like double slashes in filenames, you may need to add some logic
|
||||
|
||||
if [ -d $dst ]
|
||||
then
|
||||
dst="$dst"/`basename $src`
|
||||
else
|
||||
true
|
||||
fi
|
||||
fi
|
||||
|
||||
## this sed command emulates the dirname command
|
||||
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
|
||||
|
||||
# Make sure that the destination directory exists.
|
||||
# this part is taken from Noah Friedman's mkinstalldirs script
|
||||
|
||||
# Skip lots of stat calls in the usual case.
|
||||
if [ ! -d "$dstdir" ]; then
|
||||
defaultIFS='
|
||||
'
|
||||
IFS="${IFS-${defaultIFS}}"
|
||||
|
||||
oIFS="${IFS}"
|
||||
# Some sh's can't handle IFS=/ for some reason.
|
||||
IFS='%'
|
||||
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
|
||||
IFS="${oIFS}"
|
||||
|
||||
pathcomp=''
|
||||
|
||||
while [ $# -ne 0 ] ; do
|
||||
pathcomp="${pathcomp}${1}"
|
||||
shift
|
||||
|
||||
if [ ! -d "${pathcomp}" ] ;
|
||||
then
|
||||
$mkdirprog "${pathcomp}"
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
pathcomp="${pathcomp}/"
|
||||
done
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]
|
||||
then
|
||||
$doit $instcmd $dst &&
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
|
||||
else
|
||||
|
||||
# If we're going to rename the final executable, determine the name now.
|
||||
|
||||
if [ x"$transformarg" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
dstfile=`basename $dst $transformbasename |
|
||||
sed $transformarg`$transformbasename
|
||||
fi
|
||||
|
||||
# don't allow the sed command to completely eliminate the filename
|
||||
|
||||
if [ x"$dstfile" = x ]
|
||||
then
|
||||
dstfile=`basename $dst`
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
# Make a temp file name in the proper directory.
|
||||
|
||||
dsttmp=$dstdir/#inst.$$#
|
||||
|
||||
# Move or copy the file name to the temp name
|
||||
|
||||
$doit $instcmd $src $dsttmp &&
|
||||
|
||||
trap "rm -f ${dsttmp}" 0 &&
|
||||
|
||||
# and set any options; do chmod last to preserve setuid bits
|
||||
|
||||
# If any of these fail, we abort the whole thing. If we want to
|
||||
# ignore errors from any of these, just make sure not to ignore
|
||||
# errors from the above "$doit $instcmd $src $dsttmp" command.
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
|
||||
|
||||
# Now rename the file to the real destination.
|
||||
|
||||
$doit $rmcmd -f $dstdir/$dstfile &&
|
||||
$doit $mvcmd $dsttmp $dstdir/$dstfile
|
||||
|
||||
fi &&
|
||||
|
||||
|
||||
exit 0
|
||||
@@ -1,65 +0,0 @@
|
||||
# Makefile for ESC 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: util input lexer parser semantics generator runtime main sanity
|
||||
|
||||
main:
|
||||
javac -d Debug -classpath Debug ../../src/java/main/*.java
|
||||
|
||||
util:
|
||||
javac -d Debug -classpath Debug ../../src/java/util/*.java
|
||||
|
||||
input:
|
||||
javac -d Debug -classpath Debug ../../src/java/input/*.java
|
||||
|
||||
lexer:
|
||||
javac -d Debug -classpath Debug ../../src/java/lexer/*.java
|
||||
|
||||
parser:
|
||||
javac -d Debug -classpath Debug ../../src/java/parser/*.java
|
||||
|
||||
semantics:
|
||||
javac -d Debug -classpath Debug ../../src/java/semantics/*.java ../../src/java/semantics/values/*.java ../../src/java/semantics/types/*.java
|
||||
|
||||
generator:
|
||||
javac -d Debug -classpath Debug ../../src/java/generator/*.java
|
||||
|
||||
runtime:
|
||||
javac -d Debug -classpath Debug ../../src/java/runtime/*.java
|
||||
|
||||
testcase:
|
||||
javac -d Debug -classpath Debug Script1.java
|
||||
java -classpath Debug Test1 Script1
|
||||
|
||||
sanity:
|
||||
java -classpath Debug Main ../../test/sanity.js
|
||||
|
||||
test:
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/02.expressions/primary.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/02.expressions/prefixunary.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/02.expressions/postfixunary.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/02.expressions/binary.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/03.statements/break.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/03.statements/continue.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/03.statements/do.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/03.statements/for.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/03.statements/forin.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/03.statements/if.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/03.statements/labeled.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/03.statements/return.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/03.statements/switch.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/03.statements/throw.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/03.statements/try.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/03.statements/while.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/03.statements/with.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/04.definitions/definition.1.js
|
||||
java -classpath Debug Main -d ../../test/ecma-e4/04.definitions/definition.2.js
|
||||
|
||||
test_functions:
|
||||
java -classpath Debug Main -debug ../../test/ecma-e4/06.functions/function.1.js
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -1,321 +0,0 @@
|
||||
/*
|
||||
* Defines token classes and their print names.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The base Node class.
|
||||
*/
|
||||
|
||||
#ifndef Tokens_h
|
||||
#define Tokens_h
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
class Tokens {
|
||||
|
||||
#if 0
|
||||
|
||||
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>"
|
||||
};
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // Tokens_h
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Activation interface. An activation provides slot storage.
|
||||
*/
|
||||
|
||||
#ifndef Builder_h
|
||||
#define Builder_h
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
class ObjectValue;
|
||||
|
||||
class Builder {
|
||||
public:
|
||||
virtual void build(Context& cx, ObjectValue* ob) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // Builder_h
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Execution context.
|
||||
*/
|
||||
|
||||
#ifndef Context_h
|
||||
#define Context_h
|
||||
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
class Value;
|
||||
class ObjectValue;
|
||||
|
||||
class Context {
|
||||
|
||||
ObjectValue* global;
|
||||
std::stack<ObjectValue*> scopes;
|
||||
|
||||
public:
|
||||
Context() {
|
||||
}
|
||||
|
||||
void pushScope(ObjectValue* scope) {
|
||||
if(scopes.empty()) {
|
||||
global = scope;
|
||||
}
|
||||
|
||||
scopes.push(scope);
|
||||
}
|
||||
|
||||
void popScope() {
|
||||
scopes.pop();
|
||||
}
|
||||
|
||||
std::stack<ObjectValue*> getScopes() {
|
||||
return scopes;
|
||||
}
|
||||
|
||||
ObjectValue* scope() {
|
||||
return scopes.top();
|
||||
}
|
||||
|
||||
ObjectValue* globalScope() {
|
||||
return global;
|
||||
}
|
||||
|
||||
std::vector<Value*> used_namespaces;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // Context_h
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,345 +0,0 @@
|
||||
/**
|
||||
* The base visitor object extended by semantic evaluators.
|
||||
*
|
||||
* 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.)
|
||||
*/
|
||||
|
||||
#ifndef Evaluator_h
|
||||
#define Evaluator_h
|
||||
|
||||
#include "Value.h"
|
||||
#include "Context.h"
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
struct Node;
|
||||
struct IdentifierNode;
|
||||
struct ThisExpressionNode;
|
||||
struct SuperExpressionNode;
|
||||
struct QualifiedIdentifierNode;
|
||||
struct LiteralNullNode;
|
||||
struct LiteralBooleanNode;
|
||||
struct LiteralNumberNode;
|
||||
struct LiteralStringNode;
|
||||
struct LiteralUndefinedNode;
|
||||
struct LiteralRegExpNode;
|
||||
struct UnitExpressionNode;
|
||||
struct FunctionExpressionNode;
|
||||
struct ParenthesizedExpressionNode;
|
||||
struct ParenthesizedListExpressionNode;
|
||||
struct LiteralObjectNode;
|
||||
struct LiteralFieldNode;
|
||||
struct LiteralArrayNode;
|
||||
struct PostfixExpressionNode;
|
||||
struct NewExpressionNode;
|
||||
struct IndexedMemberExpressionNode;
|
||||
struct ClassofExpressionNode;
|
||||
struct MemberExpressionNode;
|
||||
struct CoersionExpressionNode;
|
||||
struct CallExpressionNode;
|
||||
struct GetExpressionNode;
|
||||
struct SetExpressionNode;
|
||||
struct UnaryExpressionNode;
|
||||
struct BinaryExpressionNode;
|
||||
struct ConditionalExpressionNode;
|
||||
struct AssignmentExpressionNode;
|
||||
struct ListNode;
|
||||
struct StatementListNode;
|
||||
struct EmptyStatementNode;
|
||||
struct ExpressionStatementNode;
|
||||
struct AnnotatedBlockNode;
|
||||
struct LabeledStatementNode;
|
||||
struct IfStatementNode;
|
||||
struct SwitchStatementNode;
|
||||
struct CaseLabelNode;
|
||||
struct DoStatementNode;
|
||||
struct WhileStatementNode;
|
||||
struct ForInStatementNode;
|
||||
struct ForStatementNode;
|
||||
struct WithStatementNode;
|
||||
struct ContinueStatementNode;
|
||||
struct BreakStatementNode;
|
||||
struct ReturnStatementNode;
|
||||
struct ThrowStatementNode;
|
||||
struct TryStatementNode;
|
||||
struct CatchClauseNode;
|
||||
struct FinallyClauseNode;
|
||||
struct UseStatementNode;
|
||||
struct IncludeStatementNode;
|
||||
struct ImportDefinitionNode;
|
||||
struct ImportBindingNode;
|
||||
struct AnnotatedDefinitionNode;
|
||||
struct AttributeListNode;
|
||||
struct ExportDefinitionNode;
|
||||
struct ExportBindingNode;
|
||||
struct VariableDefinitionNode;
|
||||
struct VariableBindingNode;
|
||||
struct TypedVariableNode;
|
||||
struct FunctionDefinitionNode;
|
||||
struct FunctionDeclarationNode;
|
||||
struct FunctionNameNode;
|
||||
struct FunctionSignatureNode;
|
||||
struct ParameterNode;
|
||||
struct OptionalParameterNode;
|
||||
struct RestParameterNode;
|
||||
struct NamedParameterNode;
|
||||
struct ClassDefinitionNode;
|
||||
struct ClassDeclarationNode;
|
||||
struct InheritanceNode;
|
||||
struct NamespaceDefinitionNode;
|
||||
struct PackageDefinitionNode;
|
||||
struct LanguageDeclarationNode;
|
||||
struct ProgramNode;
|
||||
|
||||
class Evaluator {
|
||||
|
||||
public:
|
||||
|
||||
// Base node
|
||||
|
||||
virtual Value* evaluate( Context& cx, Node* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
// Expression evaluators
|
||||
|
||||
virtual Value* evaluate( Context& cx, IdentifierNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
// Expression evaluators
|
||||
|
||||
virtual Value* evaluate( Context& cx, ThisExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, QualifiedIdentifierNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, LiteralBooleanNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
virtual Value* evaluate( Context& cx, LiteralNumberNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, LiteralStringNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, LiteralUndefinedNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, LiteralRegExpNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, UnitExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, FunctionExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ParenthesizedExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ParenthesizedListExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, LiteralObjectNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, LiteralFieldNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, LiteralArrayNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, PostfixExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, NewExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, IndexedMemberExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ClassofExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, MemberExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, CoersionExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, CallExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, GetExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, SetExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, UnaryExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, BinaryExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ConditionalExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, AssignmentExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ListNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
// Statements
|
||||
|
||||
virtual Value* evaluate( Context& cx, StatementListNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, EmptyStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ExpressionStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, AnnotatedBlockNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, LabeledStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, IfStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, SwitchStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, CaseLabelNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, DoStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, WhileStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ForInStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ForStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, WithStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ContinueStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, BreakStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ReturnStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ThrowStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, TryStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, CatchClauseNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, FinallyClauseNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, UseStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, IncludeStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
// Definitions
|
||||
|
||||
virtual Value* evaluate( Context& cx, ImportDefinitionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ImportBindingNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, AnnotatedDefinitionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, AttributeListNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ExportDefinitionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ExportBindingNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, VariableDefinitionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, VariableBindingNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, TypedVariableNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, FunctionDefinitionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, FunctionDeclarationNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, FunctionNameNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, FunctionSignatureNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ParameterNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, OptionalParameterNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ClassDefinitionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ClassDeclarationNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, InheritanceNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, NamespaceDefinitionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, PackageDefinitionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
virtual Value* evaluate( Context& cx, ProgramNode* node ) {
|
||||
throw;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // Evaluator_h
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,88 +0,0 @@
|
||||
/**
|
||||
* The base Node class.
|
||||
*/
|
||||
|
||||
#ifndef Node_h
|
||||
#define Node_h
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
class Evaluator;
|
||||
class Value;
|
||||
class Context;
|
||||
|
||||
struct Node {
|
||||
|
||||
int position;
|
||||
char local_var_index;
|
||||
|
||||
Node() {
|
||||
}
|
||||
|
||||
Node( int position ) {
|
||||
this->position = position;
|
||||
}
|
||||
|
||||
virtual Value* evaluate( Context& cx, Evaluator* evaluator ) {
|
||||
return (Value*) 0;
|
||||
}
|
||||
|
||||
Node* first() {
|
||||
return this;
|
||||
}
|
||||
|
||||
Node* last() {
|
||||
return this;
|
||||
}
|
||||
|
||||
Node* pos(int p) {
|
||||
position = p;
|
||||
return this;
|
||||
}
|
||||
|
||||
int pos() {
|
||||
return position;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
Block block;
|
||||
Store store;
|
||||
|
||||
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 String toString() {
|
||||
return isLeader ? "*"+block+":" : ""+block+":";
|
||||
}
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // Node_h
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* The value class from which all other values derive.
|
||||
*/
|
||||
|
||||
#include "NodeFactory.h"
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
std::vector<Node*>* NodeFactory::roots;
|
||||
|
||||
int NodeFactory::main(int argc, char* argv[]) {
|
||||
|
||||
NodeFactory::init();
|
||||
|
||||
NodeFactory::Identifier("a");
|
||||
NodeFactory::QualifiedIdentifier(
|
||||
NodeFactory::Identifier("public"),
|
||||
NodeFactory::Identifier("b"));
|
||||
NodeFactory::LiteralNull();
|
||||
NodeFactory::LiteralBoolean((bool)1);
|
||||
NodeFactory::LiteralArray(
|
||||
NodeFactory::List(
|
||||
NULL,
|
||||
NodeFactory::LiteralNumber("one")));
|
||||
NodeFactory::LiteralField(
|
||||
NodeFactory::Identifier("a"),
|
||||
NodeFactory::LiteralBoolean((bool)1));
|
||||
NodeFactory::LiteralNumber("3.1415");
|
||||
NodeFactory::LiteralObject(
|
||||
NodeFactory::List(
|
||||
NULL,
|
||||
NodeFactory::LiteralField(
|
||||
NodeFactory::Identifier("a"),
|
||||
NodeFactory::LiteralBoolean((bool)1))));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,445 +0,0 @@
|
||||
/*
|
||||
* Creates parse tree nodes.
|
||||
*/
|
||||
|
||||
#ifndef NodeFactory_h
|
||||
#define NodeFactory_h
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Node.h"
|
||||
#include "Nodes.h"
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
struct NodeFactory {
|
||||
|
||||
/*
|
||||
* Test driver
|
||||
*/
|
||||
|
||||
static int main(int argc, char* argv[]);
|
||||
|
||||
/*
|
||||
* roots is a vector of references to all the nodes allocated
|
||||
* since the last call to clear().
|
||||
*/
|
||||
|
||||
static std::vector<Node*>* roots;
|
||||
static void init() {
|
||||
NodeFactory::roots = new std::vector<Node*>();
|
||||
}
|
||||
|
||||
static void clear_root(Node* root) {
|
||||
delete root;
|
||||
}
|
||||
|
||||
static void clear() {
|
||||
std::for_each(roots->begin(),roots->end(),clear_root);
|
||||
roots->clear();
|
||||
delete roots;
|
||||
}
|
||||
|
||||
|
||||
// Nodes
|
||||
|
||||
static IdentifierNode* Identifier( std::string name ) {
|
||||
IdentifierNode* node = new IdentifierNode(name,0/*in->positionOfMark()*/);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static QualifiedIdentifierNode* QualifiedIdentifier( Node* qualifier, IdentifierNode* identifier ) {
|
||||
QualifiedIdentifierNode* node = new QualifiedIdentifierNode(qualifier,identifier,identifier->pos());
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static LiteralNullNode* LiteralNull() {
|
||||
LiteralNullNode* node = new LiteralNullNode();
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static LiteralBooleanNode* LiteralBoolean(bool value) {
|
||||
LiteralBooleanNode* node = new LiteralBooleanNode(value);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static LiteralArrayNode* LiteralArray( Node* elementlist ) {
|
||||
LiteralArrayNode* node = new LiteralArrayNode(elementlist);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static LiteralFieldNode* LiteralField( Node* name, Node* value ) {
|
||||
LiteralFieldNode* node = new LiteralFieldNode(name,value);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static LiteralNumberNode* LiteralNumber( std::string value ) {
|
||||
LiteralNumberNode* node = new LiteralNumberNode(value);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static LiteralObjectNode* LiteralObject( Node* fieldlist ) {
|
||||
LiteralObjectNode* node = new LiteralObjectNode(fieldlist);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static LiteralRegExpNode* LiteralRegExp( std::string value ) {
|
||||
LiteralRegExpNode* node = new LiteralRegExpNode(value);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static LiteralStringNode* LiteralString( std::string value ) {
|
||||
LiteralStringNode* node = new LiteralStringNode(value);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
#if 0
|
||||
static LiteralTypeNode* LiteralType( Type* type ) {
|
||||
LiteralTypeNode* node = new LiteralTypeNode(type);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
#endif
|
||||
static LiteralUndefinedNode* LiteralUndefined() {
|
||||
LiteralUndefinedNode* node = new LiteralUndefinedNode();
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ParenthesizedExpressionNode* ParenthesizedExpression( Node* expr ) {
|
||||
ParenthesizedExpressionNode* node = new ParenthesizedExpressionNode(expr,0/*in->positionOfMark()*/);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ParenthesizedListExpressionNode* ParenthesizedListExpression( Node* expr ) {
|
||||
ParenthesizedListExpressionNode* node = new ParenthesizedListExpressionNode(expr);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static FunctionExpressionNode* FunctionExpression( Node* name, Node* signature, Node* body ) {
|
||||
FunctionExpressionNode* node = new FunctionExpressionNode(name,signature,body);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static AnnotatedDefinitionNode* AnnotatedDefinition( Node* attributes, Node* definition ) {
|
||||
AnnotatedDefinitionNode* node = new AnnotatedDefinitionNode(attributes,definition);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static AttributeListNode* AttributeList( Node* item, Node* list ) {
|
||||
AttributeListNode* node = new AttributeListNode(item,list);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static UnitExpressionNode* UnitExpression( Node* value, Node* type ) {
|
||||
UnitExpressionNode* node = new UnitExpressionNode(value,type);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ThisExpressionNode* ThisExpression() {
|
||||
ThisExpressionNode* node = new ThisExpressionNode();
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static SuperExpressionNode* SuperExpression() {
|
||||
SuperExpressionNode* node = new SuperExpressionNode();
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ListNode* List( ListNode* list, Node* item ) {
|
||||
ListNode* node = new ListNode(list,item,item->pos());
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static PostfixExpressionNode* PostfixExpression( int op, Node* expr ) {
|
||||
PostfixExpressionNode* node = new PostfixExpressionNode(op,expr);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static NewExpressionNode* NewExpression( Node* member ) {
|
||||
NewExpressionNode* node = new NewExpressionNode(member);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ClassofExpressionNode* ClassofExpression( Node* base ) {
|
||||
ClassofExpressionNode* node = new ClassofExpressionNode(base);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static CallExpressionNode* CallExpression( MemberExpressionNode* member, ListNode* args ) {
|
||||
CallExpressionNode* node = new CallExpressionNode(member,args);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static GetExpressionNode* GetExpression( MemberExpressionNode* member ) {
|
||||
GetExpressionNode* node = new GetExpressionNode(member);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static SetExpressionNode* SetExpression( Node* member, Node* args ) {
|
||||
SetExpressionNode* node = new SetExpressionNode(member,args);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static IndexedMemberExpressionNode* IndexedMemberExpression( Node* base, Node* member ) {
|
||||
IndexedMemberExpressionNode* node = new IndexedMemberExpressionNode(base,member,0/*in->positionOfMark()*/);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static MemberExpressionNode* MemberExpression( Node* base, Node* name ) {
|
||||
MemberExpressionNode* node = new MemberExpressionNode(base,name,0/*in->positionOfMark()*/);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static CoersionExpressionNode* CoersionExpression( Node* expr, Node* type ) {
|
||||
CoersionExpressionNode* node = new CoersionExpressionNode(expr,type,0/*in->positionOfMark()*/);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static UnaryExpressionNode* UnaryExpression( int op, Node* expr ) {
|
||||
UnaryExpressionNode* node = new UnaryExpressionNode(op,expr);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static BinaryExpressionNode* BinaryExpression( int op, Node* lhs, Node* rhs ) {
|
||||
BinaryExpressionNode* node = new BinaryExpressionNode(op,lhs,rhs);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ConditionalExpressionNode* ConditionalExpression( Node* cond, Node* thenexpr, Node* elseexpr ) {
|
||||
ConditionalExpressionNode* node = new ConditionalExpressionNode(cond,thenexpr,elseexpr);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static AssignmentExpressionNode* AssignmentExpression( Node* lhs, int op, Node* rhs ) {
|
||||
AssignmentExpressionNode* node = new AssignmentExpressionNode(lhs,op,rhs);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static StatementListNode* StatementList( StatementListNode* list, Node* item ) {
|
||||
StatementListNode* node = new StatementListNode(list,item);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static EmptyStatementNode* EmptyStatement() {
|
||||
EmptyStatementNode* node = new EmptyStatementNode();
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ExpressionStatementNode* ExpressionStatement( Node* expr ) {
|
||||
ExpressionStatementNode* node = new ExpressionStatementNode(expr);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static AnnotatedBlockNode* AnnotatedBlock( Node* attributes, Node* definition ) {
|
||||
AnnotatedBlockNode* node = new AnnotatedBlockNode(attributes,definition);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static LabeledStatementNode* LabeledStatement( Node* label, Node* statement ) {
|
||||
LabeledStatementNode* node = new LabeledStatementNode(label,statement);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static IfStatementNode* IfStatement( Node* test, Node* tblock, Node* eblock ) {
|
||||
IfStatementNode* node = new IfStatementNode(test,tblock,eblock);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static SwitchStatementNode* SwitchStatement( Node* expr, StatementListNode* statements ) {
|
||||
SwitchStatementNode* node = new SwitchStatementNode(expr,statements);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static CaseLabelNode* CaseLabel( Node* label ) {
|
||||
CaseLabelNode* node = new CaseLabelNode(label);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static DoStatementNode* DoStatement( Node* block, Node* expr ) {
|
||||
DoStatementNode* node = new DoStatementNode(block,expr);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static WhileStatementNode* WhileStatement( Node* expr, Node* statement ) {
|
||||
WhileStatementNode* node = new WhileStatementNode(expr,statement);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ForInStatementNode* ForInStatement( Node* expr1, Node* expr2, Node* statement ) {
|
||||
ForInStatementNode* node = new ForInStatementNode(expr1,expr2,statement);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ForStatementNode* ForStatement( Node* expr1, Node* expr2, Node* expr3, Node* statement ) {
|
||||
ForStatementNode* node = new ForStatementNode(expr1,expr2,expr3,statement);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static WithStatementNode* WithStatement( Node* expr, Node* statement ) {
|
||||
WithStatementNode* node = new WithStatementNode(expr,statement);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ContinueStatementNode* ContinueStatement(Node* expr) {
|
||||
ContinueStatementNode* node = new ContinueStatementNode(expr);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static BreakStatementNode* BreakStatement(Node* expr) {
|
||||
BreakStatementNode* node = new BreakStatementNode(expr);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ReturnStatementNode* ReturnStatement( Node* expr ) {
|
||||
ReturnStatementNode* node = new ReturnStatementNode(expr);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ThrowStatementNode* ThrowStatement(Node* list) {
|
||||
ThrowStatementNode* node = new ThrowStatementNode(list);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static TryStatementNode* TryStatement(Node* tryblock, StatementListNode* catchlist, Node* finallyblock) {
|
||||
TryStatementNode* node = new TryStatementNode(tryblock,catchlist,finallyblock);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static CatchClauseNode* CatchClause(Node* parameter, Node* block) {
|
||||
CatchClauseNode* node = new CatchClauseNode(parameter,block);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static FinallyClauseNode* FinallyClause( Node* block ) {
|
||||
FinallyClauseNode* node = new FinallyClauseNode(block);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static IncludeStatementNode* IncludeStatement( Node* list ) {
|
||||
IncludeStatementNode* node = new IncludeStatementNode(list);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static UseStatementNode* UseStatement( Node* expr ) {
|
||||
UseStatementNode* node = new UseStatementNode(expr);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ImportDefinitionNode* ImportDefinition( Node* item, Node* list ) {
|
||||
ImportDefinitionNode* node = new ImportDefinitionNode(item,list);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ImportBindingNode* ImportBinding( Node* identifer, Node* item ) {
|
||||
ImportBindingNode* node = new ImportBindingNode(identifer,item);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ExportDefinitionNode* ExportDefinition( Node* list ) {
|
||||
ExportDefinitionNode* node = new ExportDefinitionNode(list);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ExportBindingNode* ExportBinding( Node* name, Node* value ) {
|
||||
ExportBindingNode* node = new ExportBindingNode(name,value);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static VariableDefinitionNode* VariableDefinition( int kind, Node* list ) {
|
||||
VariableDefinitionNode* node = new VariableDefinitionNode(kind,list,list->pos());
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static VariableBindingNode* VariableBinding( Node* identifier, Node* initializer ) {
|
||||
VariableBindingNode* node = new VariableBindingNode(identifier,initializer);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static TypedVariableNode* TypedVariable( Node* identifier, Node* type ) {
|
||||
TypedVariableNode* node = new TypedVariableNode(identifier,type,type!=NULL?type->pos():identifier->pos());
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static FunctionDefinitionNode* FunctionDefinition( Node* decl, Node* body ) {
|
||||
FunctionDefinitionNode* node = new FunctionDefinitionNode(decl,body);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static FunctionDeclarationNode* FunctionDeclaration( Node* name, Node* signature ) {
|
||||
FunctionDeclarationNode* node = new FunctionDeclarationNode(name,signature);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static FunctionNameNode* FunctionName( int kind, Node* name ) {
|
||||
FunctionNameNode* node = new FunctionNameNode(kind,name);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static RestParameterNode* RestParameter( Node* expr ) {
|
||||
RestParameterNode* node = new RestParameterNode(expr);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ParameterNode* Parameter( Node* identifer, Node* type ) {
|
||||
ParameterNode* node = new ParameterNode(identifer,type);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static OptionalParameterNode* OptionalParameter( Node* identifer, Node* init ) {
|
||||
OptionalParameterNode* node = new OptionalParameterNode(identifer,init);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static NamedParameterNode* NamedParameter( Node* name, Node* parameter ) {
|
||||
NamedParameterNode* node = new NamedParameterNode(name,parameter);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ClassDeclarationNode* ClassDeclaration( Node* name ) {
|
||||
ClassDeclarationNode* node = new ClassDeclarationNode(name);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ClassDefinitionNode* ClassDefinition( Node* name, Node* interfaces, Node* statements ) {
|
||||
ClassDefinitionNode* node = new ClassDefinitionNode(name,interfaces,statements);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static InheritanceNode* Inheritance( Node* baseclass, Node* interfaces ) {
|
||||
InheritanceNode* node = new InheritanceNode(baseclass,interfaces);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static NamespaceDefinitionNode* NamespaceDefinition( Node* identifier, Node* list ) {
|
||||
NamespaceDefinitionNode* node = new NamespaceDefinitionNode(identifier,list);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static LanguageDeclarationNode* LanguageDeclaration( Node* list ) {
|
||||
LanguageDeclarationNode* node = new LanguageDeclarationNode(list);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static PackageDefinitionNode* PackageDefinition( Node* name, Node* block ) {
|
||||
PackageDefinitionNode* node = new PackageDefinitionNode(name,block);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
static ProgramNode* Program( Node* statements ) {
|
||||
ProgramNode* node = new ProgramNode(statements);
|
||||
roots->push_back(node);
|
||||
return node;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // NodeFactory_h
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,426 +0,0 @@
|
||||
/*
|
||||
* The value class from which all other values derive.
|
||||
*/
|
||||
|
||||
#pragma warning ( disable : 4786 )
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Context.h"
|
||||
#include "Value.h"
|
||||
#include "Type.h"
|
||||
#include "Slot.h"
|
||||
|
||||
#include "ObjectValue.h"
|
||||
#include "ReferenceValue.h"
|
||||
#include "TypeValue.h"
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
ObjectValue* ObjectValue::undefinedValue;
|
||||
ObjectValue* ObjectValue::nullValue;
|
||||
ObjectValue* ObjectValue::trueValue;
|
||||
ObjectValue* ObjectValue::falseValue;
|
||||
ObjectValue* ObjectValue::publicNamespace;
|
||||
ObjectValue* ObjectValue::objectPrototype;
|
||||
|
||||
Slot default_slot;
|
||||
|
||||
void ObjectValue::init() {
|
||||
ObjectValue::undefinedValue = new ObjectValue();
|
||||
ObjectValue::nullValue = new ObjectValue();
|
||||
ObjectValue::trueValue = new ObjectValue();
|
||||
ObjectValue::falseValue = new ObjectValue();
|
||||
ObjectValue::publicNamespace = new ObjectValue(TypeValue::namespaceType);
|
||||
ObjectValue::objectPrototype = new ObjectValue();
|
||||
}
|
||||
|
||||
void ObjectValue::fini() {
|
||||
}
|
||||
|
||||
ObjectValue::ObjectValue()
|
||||
: names(*new std::map<std::string,Qualifiers>()),
|
||||
slots(*new std::vector<Slot>(3,default_slot)),
|
||||
dyna_slots(*new std::vector<Slot>),
|
||||
frozen_flag(false),
|
||||
first_index(0) {
|
||||
|
||||
initInstance(0,0);
|
||||
}
|
||||
|
||||
ObjectValue::ObjectValue(Builder& builder)
|
||||
: names(*new std::map<std::string,Qualifiers>()),
|
||||
slots(*new std::vector<Slot>(3,default_slot)),
|
||||
dyna_slots(*new std::vector<Slot>),
|
||||
frozen_flag(false),
|
||||
first_index(0) {
|
||||
|
||||
initInstance(0,TypeValue::objectType);
|
||||
|
||||
Context cx;
|
||||
builder.build(cx,this);
|
||||
}
|
||||
|
||||
ObjectValue::ObjectValue(bool value)
|
||||
: names(*new std::map<std::string,Qualifiers>()),
|
||||
slots(*new std::vector<Slot>(3,default_slot)),
|
||||
dyna_slots(*new std::vector<Slot>),
|
||||
frozen_flag(false),
|
||||
first_index(0) {
|
||||
|
||||
initInstance(TypeValue::booleanType->prototype,TypeValue::booleanType);
|
||||
|
||||
Context& cx = *new Context();
|
||||
Slot* slot = getSlot(cx,first_index+SLOT_VALUE);
|
||||
slot->intValue = value;
|
||||
slot->type = TypeValue::booleanType;
|
||||
slot->attrs = 0;
|
||||
}
|
||||
|
||||
// Construct an object with a given prototype object.
|
||||
|
||||
ObjectValue::ObjectValue(ObjectValue* protoObject)
|
||||
: names(*new std::map<std::string,Qualifiers>()),
|
||||
slots(*new std::vector<Slot>(3,default_slot)),
|
||||
dyna_slots(*new std::vector<Slot>),
|
||||
frozen_flag(false),
|
||||
first_index(protoObject->getLastSlotIndex()) {
|
||||
|
||||
initInstance(protoObject,TypeValue::objectType);
|
||||
}
|
||||
|
||||
// Construct an object with a class defined.
|
||||
|
||||
ObjectValue::ObjectValue(TypeValue* classObject)
|
||||
: names(*new std::map<std::string,Qualifiers>()),
|
||||
slots(*new std::vector<Slot>(3,default_slot)),
|
||||
dyna_slots(*new std::vector<Slot>),
|
||||
frozen_flag(false),
|
||||
first_index(classObject->prototype->getLastSlotIndex()) {
|
||||
|
||||
initInstance(classObject->prototype,classObject);
|
||||
}
|
||||
|
||||
void ObjectValue::initInstance(ObjectValue* protoObject,TypeValue* classObject) {
|
||||
|
||||
Context& cx = *new Context();
|
||||
|
||||
Slot* slot;
|
||||
slot = getSlot(cx,first_index+SLOT_PROTO);
|
||||
slot->value = protoObject;
|
||||
slot->type = TypeValue::objectType;
|
||||
slot->attrs = 0;
|
||||
slot = getSlot(cx,first_index+SLOT_CLASS);
|
||||
slot->value = classObject;
|
||||
slot->type = TypeValue::typeType;
|
||||
slot->attrs = 0;
|
||||
|
||||
// Call the class object's builder method to initialize
|
||||
// this instance.
|
||||
|
||||
if( classObject ) {
|
||||
classObject->build(cx,this);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Scope methods
|
||||
*/
|
||||
|
||||
/*
|
||||
* Look for a property name in the object.
|
||||
*/
|
||||
|
||||
bool ObjectValue::hasName(Context& cx, std::string name, Value* qualifier) {
|
||||
|
||||
Names::iterator nameit = names.find(name);
|
||||
|
||||
if( nameit == names.end() ) {
|
||||
return (bool)0;
|
||||
}
|
||||
|
||||
Qualifiers& qual = (*nameit).second;
|
||||
|
||||
return qual.find(qualifier) != qual.end();
|
||||
}
|
||||
|
||||
Namespaces* ObjectValue::hasNames(Context& cx, std::string name, Namespaces* namespaces) {
|
||||
|
||||
Namespaces* hasNamespaces = new Namespaces();
|
||||
Names::iterator nameit = names.find(name);
|
||||
|
||||
if( nameit == names.end() ) {
|
||||
return (Namespaces*)0;
|
||||
}
|
||||
|
||||
Qualifiers* quals = &(*nameit).second;
|
||||
|
||||
// For each member of namespaces, see if there
|
||||
// is a matching qualifier.
|
||||
|
||||
for(int i = 0; i < namespaces->size(); i++ ) {
|
||||
Value* qual = namespaces->at(i);
|
||||
if( quals->find(qual) != quals->end() ) {
|
||||
hasNamespaces->push_back(qual);
|
||||
}
|
||||
}
|
||||
return hasNamespaces;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the slot for a property.
|
||||
*
|
||||
* WARNING:
|
||||
* Before calling this method you must call hasName to ensure that
|
||||
* the requested property exists.
|
||||
*/
|
||||
|
||||
Slot* ObjectValue::get(Context& cx, std::string name, Value* qualifier) {
|
||||
|
||||
std::map<Value*,int>& prop = names[name];
|
||||
int index = prop[qualifier];
|
||||
return getSlot(cx,index);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the value of a property.
|
||||
*/
|
||||
|
||||
int ObjectValue::define(Context& cx, std::string name, Value* qualifier, int index) {
|
||||
|
||||
// Get the property for name
|
||||
|
||||
std::map<std::string,Qualifiers>::iterator nameit = names.find(name);
|
||||
|
||||
// If there is one, then get the qualifier map for that name.
|
||||
// Otherwise, create a qualifier map and a new property.
|
||||
|
||||
if( nameit == names.end() ) {
|
||||
Qualifiers qualifiers;
|
||||
names[name] = qualifiers;
|
||||
}
|
||||
|
||||
// Add the qualifier to the qualifiers map, and set its value to index.
|
||||
|
||||
std::map<Value*,int>& prop = names[name];
|
||||
prop[qualifier] = index;
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Add a slot to this object. This object's fixed slots
|
||||
* (that is, all slots added before freezeSlots is called)
|
||||
* begin where the [[Prototype]] indexes end.
|
||||
*
|
||||
* If [[Prototype]] object has not been frozen or this
|
||||
* object has been frozen, then addSlot allocates the
|
||||
* slot in the dynamic slot space.
|
||||
*/
|
||||
|
||||
int ObjectValue::addSlot(Context& cx) {
|
||||
Slot slot;
|
||||
int index;
|
||||
if( proto(cx) && proto(cx)->isFixed() && !this->isFixed() ) {
|
||||
index = first_index + slots.size();
|
||||
slots.push_back(slot);
|
||||
} else if( !this->isFixed() ) {
|
||||
index = slots.size();
|
||||
slots.push_back(slot);
|
||||
} else {
|
||||
index = -dyna_slots.size();
|
||||
dyna_slots.push_back(slot);
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the slot for an index. If it is a fixed slot
|
||||
* it will have a positive value. dynamic slots have
|
||||
* negative values.
|
||||
*/
|
||||
|
||||
Slot* ObjectValue::getSlot(Context& cx, int index) {
|
||||
Slot* slot;
|
||||
if( ((unsigned)index) < first_index ) {
|
||||
slot = proto(cx)->getSlot(cx,index);
|
||||
} else if (index < 0) {
|
||||
slot = &dyna_slots[-index];
|
||||
} else {
|
||||
slot = &slots[index-first_index];
|
||||
}
|
||||
return slot;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the slot index of a named property.
|
||||
*
|
||||
* Before calling this method you must call hasName to ensure that
|
||||
* the requested property exists.
|
||||
*/
|
||||
|
||||
int ObjectValue::getSlotIndex(Context& cx, std::string name, Value* qualifier) {
|
||||
std::map<Value*,int>& prop = names[name];
|
||||
int size = prop.size();
|
||||
int index = prop[qualifier];
|
||||
return index;
|
||||
}
|
||||
|
||||
bool ObjectValue::isFixed() {
|
||||
return frozen_flag;
|
||||
}
|
||||
|
||||
int ObjectValue::getFirstSlotIndex() {
|
||||
return first_index;
|
||||
}
|
||||
|
||||
int ObjectValue::getLastSlotIndex() {
|
||||
frozen_flag = true;
|
||||
return first_index+slots.size()-1;
|
||||
}
|
||||
|
||||
ObjectValue* ObjectValue::proto(Context& cx) {
|
||||
return this->getSlot(cx,first_index+SLOT_PROTO)->objValue;
|
||||
}
|
||||
|
||||
TypeValue* ObjectValue::getType(Context& cx) {
|
||||
return reinterpret_cast<TypeValue*>(this->getSlot(cx,first_index+SLOT_CLASS)->objValue);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test driver
|
||||
*/
|
||||
|
||||
int ObjectValue::main(int argc, char* argv[]) {
|
||||
Context& cx = *new Context();
|
||||
ObjectValue ob;
|
||||
ObjectValue q1,q2,q3;
|
||||
|
||||
int i1,i2,i3;
|
||||
i1 = ob.addSlot(cx); // add a slot
|
||||
i1 = ob.define(cx,"a",&q1,i1); // define a property
|
||||
i2 = ob.addSlot(cx);
|
||||
i2 = ob.define(cx,"a",&q2,i2);
|
||||
i3 = ob.addSlot(cx);
|
||||
i3 = ob.define(cx,"a",&q3,i2);
|
||||
|
||||
|
||||
//ObjectValue v1,v2,v3;
|
||||
|
||||
ob.get(cx,"a",&q1)->intValue = 10;
|
||||
ob.get(cx,"a",&q2)->intValue = 20;
|
||||
int v3 = ob.get(cx,"a",&q3)->intValue;
|
||||
|
||||
Slot* s1 = ob.getSlot(cx,i1);
|
||||
Slot* s2 = ob.getSlot(cx,i2);
|
||||
Slot* s3 = ob.getSlot(cx,i3);
|
||||
|
||||
ObjectValue b((bool)1);
|
||||
|
||||
delete &cx;
|
||||
|
||||
testClass(argc,argv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Test the case:
|
||||
// class B { static var xg = 1; var xp = 2; }
|
||||
// var b = new B;
|
||||
// b.xi = 3;
|
||||
// b.class.xg;
|
||||
// b.xp;
|
||||
// b.xi;
|
||||
|
||||
int ObjectValue::testClass(int argc, char* argv[]) {
|
||||
|
||||
Context cx;;
|
||||
|
||||
// Allocate the parts
|
||||
|
||||
ObjectValue global;
|
||||
|
||||
ObjectValue default_ns;
|
||||
|
||||
// Wire them together
|
||||
|
||||
int slot_index;
|
||||
Slot* slot;
|
||||
|
||||
// Init the proto object
|
||||
|
||||
ObjectValue b_proto;
|
||||
slot_index = b_proto.addSlot(cx); // add a slot
|
||||
slot_index = b_proto.define(cx,"xp",&default_ns,slot_index); // define a property
|
||||
slot = b_proto.getSlot(cx,slot_index);
|
||||
slot->intValue = 10;
|
||||
|
||||
// Init the class object
|
||||
|
||||
TypeValue b_class;
|
||||
slot_index = b_class.addSlot(cx); // add a slot
|
||||
slot_index = b_class.define(cx,"xg",&default_ns,slot_index); // define a property
|
||||
slot = b_class.getSlot(cx,slot_index);
|
||||
slot->intValue = 30;
|
||||
|
||||
// Init the instance object
|
||||
|
||||
ObjectValue b_instance(b_proto);
|
||||
int first_index = b_instance.getFirstSlotIndex();
|
||||
slot = b_instance.getSlot(cx,first_index+SLOT_PROTO);
|
||||
slot->value = &b_proto;
|
||||
slot->type = TypeValue::objectType;
|
||||
slot->attrs = 0;
|
||||
|
||||
slot_index = b_instance.define(cx,"class",&default_ns,first_index+SLOT_CLASS); // define a property
|
||||
slot = b_instance.getSlot(cx,first_index+SLOT_CLASS);
|
||||
slot->value = &b_class;
|
||||
slot->type = TypeValue::typeType;
|
||||
slot->attrs = 0;
|
||||
|
||||
slot_index = b_instance.addSlot(cx); // add a slot
|
||||
slot_index = b_instance.define(cx,"xi",&default_ns,slot_index); // define a property
|
||||
slot = b_instance.getSlot(cx,slot_index);
|
||||
slot->intValue = 20;
|
||||
|
||||
slot_index = global.addSlot(cx); // add a slot
|
||||
slot_index = global.define(cx,"b",&default_ns,slot_index); // define a property
|
||||
slot = global.getSlot(cx,slot_index);
|
||||
slot->objValue = &b_instance;
|
||||
|
||||
// Make and evaluate some references
|
||||
|
||||
|
||||
// b.xp
|
||||
|
||||
ReferenceValue r1(&b_instance,"xp",&default_ns);
|
||||
Slot* sp;
|
||||
sp = r1.getSlot(cx);
|
||||
int sp_index = r1.getSlotIndex();
|
||||
sp = b_instance.getSlot(cx,sp_index);
|
||||
|
||||
// b.xi
|
||||
|
||||
ReferenceValue r2(&b_instance,"xi",&default_ns);
|
||||
Slot* si = r2.getSlot(cx);
|
||||
|
||||
// b.class.xg
|
||||
|
||||
ReferenceValue r3(&b_instance,"class",&default_ns);
|
||||
ObjectValue& vB = *((ObjectValue*)r3.getValue(cx));
|
||||
ReferenceValue r4(&vB,"xg",&default_ns);
|
||||
Slot* sg = r4.getSlot(cx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Written by Jeff Dyer
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,163 +0,0 @@
|
||||
/*
|
||||
* This class is the building block for all ECMA values. Object values
|
||||
* are a sequence of instances linked through the [[Prototype]] slot.
|
||||
* Classes are a sequence of instances of the sub-class TypeValue, also
|
||||
* linked through the [[Prototype]] slot. Lookup of class and instance
|
||||
* properties uses the same algorithm to find a name. Names are bound
|
||||
* to slots. Slots contain values that are methods for accessing or
|
||||
* computing program values (i.e running code.)
|
||||
*
|
||||
* An object consists of a table of names, and a vector of slots. The
|
||||
* slots hold methods for accessing and computing values. An object
|
||||
* also has a private data accessible to the methods and accessors of
|
||||
* the object.
|
||||
*
|
||||
* All symbolic references to the properties of an object are bound
|
||||
* to the method of a slot. Constant references to fixed, final prop-
|
||||
* erties can be compiled to direct access of the data value. This
|
||||
* is the case with access to private, final or global variables.
|
||||
*
|
||||
* The instance and class hierarchies built at compile-time can be
|
||||
* compressed into a single instance prototype and class object for
|
||||
* faster lookup and dispatch.
|
||||
*/
|
||||
|
||||
#ifndef ObjectValue_h
|
||||
#define ObjectValue_h
|
||||
|
||||
#pragma warning( disable : 4786 )
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "Value.h"
|
||||
#include "Type.h"
|
||||
#include "Slot.h"
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
class Context;
|
||||
class TypeValue;
|
||||
class Builder;
|
||||
|
||||
enum {
|
||||
SLOT_PROTO = 0,
|
||||
SLOT_CLASS,
|
||||
SLOT_VALUE,
|
||||
};
|
||||
|
||||
typedef std::map<Value*,int> Qualifiers;
|
||||
typedef std::map<std::string,Qualifiers> Names;
|
||||
typedef std::vector<Slot> Slots;
|
||||
typedef std::vector<Value*> Namespaces;
|
||||
|
||||
class ObjectValue : public Value {
|
||||
private:
|
||||
|
||||
Names names; // Names table
|
||||
Slots slots; // Slots table
|
||||
Slots dyna_slots; // Slots table
|
||||
bool frozen_flag;
|
||||
int first_index;
|
||||
|
||||
public:
|
||||
|
||||
static ObjectValue* undefinedValue;
|
||||
static ObjectValue* nullValue;
|
||||
static ObjectValue* trueValue;
|
||||
static ObjectValue* falseValue;
|
||||
static ObjectValue* publicNamespace;
|
||||
static ObjectValue* objectPrototype;
|
||||
|
||||
ObjectValue();
|
||||
ObjectValue(ObjectValue* protoObject);
|
||||
ObjectValue(TypeValue* classObject);
|
||||
ObjectValue(Builder& builder);
|
||||
ObjectValue(bool value);
|
||||
|
||||
void ObjectValue::initInstance(ObjectValue* protoObject,TypeValue* classObject);
|
||||
|
||||
virtual ~ObjectValue() {
|
||||
//names.clear();
|
||||
//slots.clear();
|
||||
//dyna_slots.clear();
|
||||
}
|
||||
|
||||
/* Initialize and finalize the class.
|
||||
*/
|
||||
static void init();
|
||||
static void fini();
|
||||
|
||||
/* Define a property and associate it with slot_index
|
||||
*/
|
||||
int define(Context& cx, std::string name, Value* qualifier, int slot_index);
|
||||
|
||||
/* Get the slot index of a property name
|
||||
*/
|
||||
int getSlotIndex(Context& cx, std::string name, Value* qualifier);
|
||||
|
||||
/* Get the slot of a property name
|
||||
*/
|
||||
Slot* get(Context& cx, std::string name, Value* qualifier);
|
||||
|
||||
/* Check for a property
|
||||
*/
|
||||
bool hasName(Context& cx, std::string name, Value* qualifier);
|
||||
|
||||
/* Check for names that consist of an id and one of multiple
|
||||
* namespaces. Return a vector of namespaces that match. This
|
||||
* method is used for lookup of unqualified names.
|
||||
*/
|
||||
Namespaces* hasNames(Context& cx, std::string name, Namespaces* namespaces);
|
||||
|
||||
/* Add a slot to this object.
|
||||
*/
|
||||
int addSlot(Context& cx);
|
||||
|
||||
/* Get a slot for a slot index
|
||||
*/
|
||||
Slot* getSlot(Context& cx, int index);
|
||||
|
||||
/* Check if the object is fixed yet.
|
||||
*/
|
||||
bool isFixed();
|
||||
|
||||
/* Get the start index for slots in this object. The indicies of
|
||||
* all the objects in a prototype chain are contiguous.
|
||||
*/
|
||||
int getFirstSlotIndex();
|
||||
|
||||
/* Get the last slot index allocated for this part of the
|
||||
* instance. Calling this method has the side-effect of
|
||||
* freezing the slot table. Thereafter, new slots are
|
||||
* allocated in the dynamic slots table.
|
||||
*/
|
||||
int getLastSlotIndex();
|
||||
|
||||
/* Get the [[Prototype]] object
|
||||
*/
|
||||
ObjectValue* proto(Context& cx);
|
||||
|
||||
/* Get the [[Type]] object
|
||||
*/
|
||||
virtual TypeValue* getType(Context& context);
|
||||
|
||||
// main
|
||||
|
||||
static int main(int argc, char* argv[]);
|
||||
static int testClass(int argc, char* argv[]);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ObjectValue_h
|
||||
|
||||
/*
|
||||
* Written by Jeff Dyer
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,38 +0,0 @@
|
||||
#ifndef Slot_h
|
||||
#define Slot_h
|
||||
|
||||
/*
|
||||
* A slot.
|
||||
*/
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
class Value;
|
||||
class ObjectValue;
|
||||
|
||||
struct Slot {
|
||||
int attrs;
|
||||
TypeValue* type;
|
||||
union {
|
||||
Value* value;
|
||||
ObjectValue* objValue; // (ReferenceValue, ListValue, ObjectValue)
|
||||
int intValue;
|
||||
char* strValue;
|
||||
};
|
||||
|
||||
Slot() : attrs(0), type(0), value(0) {
|
||||
}
|
||||
//Block block;
|
||||
//Store store;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // Slot_h
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,35 +0,0 @@
|
||||
#ifndef Type_h
|
||||
#define Type_h
|
||||
|
||||
/**
|
||||
* The interface for all types.
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
class Value;
|
||||
class Context;
|
||||
|
||||
class Type {
|
||||
// virtual std::vector<Value*> values() = 0;
|
||||
// virtual std::vector<Value*> converts() = 0;
|
||||
// virtual void addSub(Type& type) = 0;
|
||||
virtual bool includes(Context& cx, Value* value) = 0;
|
||||
// virtual void setSuper(Type& type) = 0;
|
||||
// virtual Type* getSuper() = 0;
|
||||
// virtual Value* convert(Context& cx, Value& value) = 0;
|
||||
// virtual Value* coerce(Context& cx, Value& value) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // Type_h
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* The value class from which all other values derive.
|
||||
*/
|
||||
|
||||
#include "Value.h"
|
||||
#include "Type.h"
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Written by Jeff Dyer
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,30 +0,0 @@
|
||||
#ifndef Value_h
|
||||
#define Value_h
|
||||
|
||||
/*
|
||||
* The value class from which all other values derive. Immediate
|
||||
* children are ObjectValue, ReferenceValue, ListValue, and
|
||||
* CompletionValue.
|
||||
*/
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
class Context;
|
||||
class TypeValue;
|
||||
|
||||
class Value {
|
||||
public:
|
||||
virtual Value* getValue(Context& context) { return this; }
|
||||
virtual TypeValue* getType(Context& context) { return (TypeValue*)0; }
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // Value_h
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Global object builder
|
||||
*/
|
||||
|
||||
#pragma warning ( disable : 4786 )
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Context.h"
|
||||
#include "Value.h"
|
||||
#include "Type.h"
|
||||
#include "Slot.h"
|
||||
#include "Builder.h"
|
||||
#include "GlobalObjectBuilder.h"
|
||||
|
||||
#include "TypeValue.h"
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
|
||||
void GlobalObjectBuilder::build(Context& cx, ObjectValue* ob) {
|
||||
|
||||
Slot* slot;
|
||||
int slot_index;
|
||||
|
||||
// Never type
|
||||
slot_index = ob->addSlot(cx);
|
||||
slot_index = ob->define(cx,"Never",ObjectValue::publicNamespace,slot_index);
|
||||
slot = ob->getSlot(cx,slot_index);
|
||||
slot->objValue = new TypeValue();
|
||||
|
||||
// Null type
|
||||
slot_index = ob->addSlot(cx);
|
||||
slot_index = ob->define(cx,"Null",ObjectValue::publicNamespace,slot_index);
|
||||
slot = ob->getSlot(cx,slot_index);
|
||||
slot->objValue = new TypeValue();
|
||||
|
||||
// Boolean type
|
||||
slot_index = ob->addSlot(cx);
|
||||
slot_index = ob->define(cx,"Boolean",ObjectValue::publicNamespace,slot_index);
|
||||
slot = ob->getSlot(cx,slot_index);
|
||||
slot->objValue = new TypeValue();
|
||||
|
||||
// Number type
|
||||
slot_index = ob->addSlot(cx);
|
||||
slot_index = ob->define(cx,"Number",ObjectValue::publicNamespace,slot_index);
|
||||
slot = ob->getSlot(cx,slot_index);
|
||||
slot->objValue = new TypeValue();
|
||||
|
||||
// String type
|
||||
slot_index = ob->addSlot(cx);
|
||||
slot_index = ob->define(cx,"String",ObjectValue::publicNamespace,slot_index);
|
||||
slot = ob->getSlot(cx,slot_index);
|
||||
slot->objValue = new TypeValue();
|
||||
|
||||
// Function type
|
||||
slot_index = ob->addSlot(cx);
|
||||
slot_index = ob->define(cx,"Function",ObjectValue::publicNamespace,slot_index);
|
||||
slot = ob->getSlot(cx,slot_index);
|
||||
slot->objValue = new TypeValue();
|
||||
|
||||
// Array type
|
||||
slot_index = ob->addSlot(cx);
|
||||
slot_index = ob->define(cx,"Boolean",ObjectValue::publicNamespace,slot_index);
|
||||
slot = ob->getSlot(cx,slot_index);
|
||||
slot->objValue = new TypeValue();
|
||||
|
||||
// Type type
|
||||
slot_index = ob->addSlot(cx);
|
||||
slot_index = ob->define(cx,"Array",ObjectValue::publicNamespace,slot_index);
|
||||
slot = ob->getSlot(cx,slot_index);
|
||||
slot->objValue = new TypeValue();
|
||||
|
||||
// Unit type
|
||||
slot_index = ob->addSlot(cx);
|
||||
slot_index = ob->define(cx,"Unit",ObjectValue::publicNamespace,slot_index);
|
||||
slot = ob->getSlot(cx,slot_index);
|
||||
slot->objValue = new TypeValue();
|
||||
|
||||
// public namespace
|
||||
slot_index = ob->addSlot(cx);
|
||||
slot_index = ob->define(cx,"public",ObjectValue::publicNamespace,slot_index);
|
||||
slot = ob->getSlot(cx,slot_index);
|
||||
slot->value = ObjectValue::publicNamespace;
|
||||
|
||||
// print - (built-in) function
|
||||
slot_index = ob->addSlot(cx);
|
||||
slot_index = ob->define(cx,"print",ObjectValue::publicNamespace,slot_index);
|
||||
slot = ob->getSlot(cx,slot_index);
|
||||
slot->value = new ObjectValue(); // function: print
|
||||
|
||||
// version - (built-in) field
|
||||
|
||||
slot_index = ob->addSlot(cx);
|
||||
slot_index = ob->define(cx,"get version",ObjectValue::publicNamespace,slot_index);
|
||||
slot = ob->getSlot(cx,slot_index);
|
||||
slot->intValue = 7; //value_count; // function: get version
|
||||
|
||||
slot_index = ob->addSlot(cx);
|
||||
slot_index = ob->define(cx,"set version",ObjectValue::publicNamespace,slot_index);
|
||||
slot = ob->getSlot(cx,slot_index);
|
||||
slot->intValue = 7; //value_count++; // function: set version
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Written by Jeff Dyer
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,35 +0,0 @@
|
||||
#ifndef GlobalObjectConstructor_h
|
||||
#define GlobalObjectConstructor_h
|
||||
|
||||
/*
|
||||
* Constructs global objects
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Builder.h"
|
||||
#include "ObjectValue.h"
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
class GlobalObjectBuilder : public Builder {
|
||||
public:
|
||||
GlobalObjectBuilder() {
|
||||
}
|
||||
|
||||
virtual void build(Context& cx, ObjectValue* ob);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // GlobalObjectConstructor_h
|
||||
|
||||
/*
|
||||
* Written by Jeff Dyer
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved
|
||||
*/
|
||||
@@ -1,515 +0,0 @@
|
||||
|
||||
#pragma warning ( disable : 4786 )
|
||||
|
||||
#include "Nodes.h"
|
||||
#include "ConstantEvaluator.h"
|
||||
#include "NodeFactory.h"
|
||||
#include "ReferenceValue.h"
|
||||
#include "TypeValue.h"
|
||||
#include "GlobalObjectBuilder.h"
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
// Base node
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, Node* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
/*
|
||||
* Unqualified identifier
|
||||
*
|
||||
* STATUS
|
||||
*
|
||||
* NOTES
|
||||
* An unqualified name can bind to a local variable, instance
|
||||
* property, or global property. A local will result in a
|
||||
* aload_n instruction. A instance property will result in a
|
||||
* get_property method call. A global property will result in a
|
||||
* get_property method call on the global object.
|
||||
*/
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, IdentifierNode* node ) {
|
||||
return new ReferenceValue((ObjectValue*)0,node->name,used_namespaces);
|
||||
}
|
||||
|
||||
/*
|
||||
* QualifiedIdentifierNode
|
||||
*
|
||||
* {qualifiers:QualifierListNode name:String}
|
||||
*
|
||||
* Semantics:
|
||||
* 1. Evaluate qualifier.
|
||||
* 2. Call GetValue(Result(1).
|
||||
* 3. If Result(2) is not a namespace, then throw a TypeError.
|
||||
* 4. Create a new Reference(null,Result2),name).
|
||||
* 5. Return Result(4).
|
||||
*/
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, QualifiedIdentifierNode* node ) {
|
||||
|
||||
Value* qualifier;
|
||||
if( node->qualifier != (Node*)0 ) {
|
||||
qualifier = node->qualifier->evaluate(cx,this);
|
||||
qualifier = qualifier->getValue(cx);
|
||||
}
|
||||
|
||||
if( qualifier == (Value*)0 ) {
|
||||
//error();
|
||||
throw;
|
||||
}
|
||||
else
|
||||
if(!(TypeValue::namespaceType->includes(cx,qualifier)) ) {
|
||||
//error();
|
||||
throw;
|
||||
}
|
||||
|
||||
return new ReferenceValue((ObjectValue*)0,node->name,qualifier);
|
||||
}
|
||||
|
||||
/*
|
||||
* CallExpression
|
||||
*
|
||||
* Semantics
|
||||
* ---------
|
||||
* 1 Evaluate MemberExpression.
|
||||
* 2 Evaluate Arguments, producing an internal list of argument
|
||||
* values (section 11.2.4).
|
||||
* 3 Call GetValue(Result(1)).
|
||||
* 4 If Type(Result(3)) is not Object, throw a TypeError exception.
|
||||
* 5 If Result(3) does not implement the internal [[Call]] method,
|
||||
* throw a TypeError exception.
|
||||
* 6 If Type(Result(1)) is Reference, Result(6) is GetBase(Result(1)).
|
||||
* Otherwise, Result(6) is null.
|
||||
* 7 If Result(6) is an activation object, Result(7) is null.
|
||||
* Otherwise, Result(7) is the same as Result(6).
|
||||
* 8 Call the [[Call]] method on Result(3), providing Result(7)
|
||||
* as the this value and providing the list Result(2) as the
|
||||
* argument values.
|
||||
* 9 Return Result(8).
|
||||
*
|
||||
*/
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, CallExpressionNode* node ) {
|
||||
|
||||
Value* val = node->member->evaluate(cx,this);
|
||||
ReferenceValue* ref = dynamic_cast<ReferenceValue*>(val); // Forces the use of RTTI.
|
||||
|
||||
if( node->args ) {
|
||||
node->args->evaluate(cx,this);
|
||||
}
|
||||
|
||||
// Do typechecking. It is quite possible that this function has not
|
||||
// yet been defined. In this case, all of the semantic actions must
|
||||
// be performed at runtime.
|
||||
|
||||
if( ref->lookup(cx) ) {
|
||||
|
||||
/* If the function was found: The slot index is in
|
||||
* ref->slot_index and the base object is presumed
|
||||
* to be the top value on the operand stack (if base
|
||||
* is set), otherwise it is the nth (ref->scope_index)
|
||||
* object from the bottom of the scope stack. (0 is
|
||||
* global.)
|
||||
*
|
||||
* Nothing to do here.
|
||||
*/
|
||||
}
|
||||
|
||||
node->ref = ref;
|
||||
|
||||
return ObjectValue::undefinedValue;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, GetExpressionNode* node ) {
|
||||
|
||||
Value* val = node->member->evaluate(cx,this);
|
||||
ReferenceValue* ref = dynamic_cast<ReferenceValue*>(val); // Forces the use of RTTI.
|
||||
ref->name.insert(0,"get "); // Tweak the name to make it a getter reference.
|
||||
|
||||
// Do typechecking. It is quite possible that this function has not
|
||||
// yet been defined. In this case, all of the semantic actions must
|
||||
// be performed at runtime.
|
||||
|
||||
if( ref->lookup(cx) ) {
|
||||
|
||||
/* If the function was found: The slot index is in
|
||||
* ref->slot_index and the base object is presumed
|
||||
* to be the top value on the operand stack (if base
|
||||
* is set), otherwise it is the nth (ref->scope_index)
|
||||
* object from the bottom of the scope stack. (0 is
|
||||
* global.)
|
||||
*
|
||||
* Nothing to do here.
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
return node->ref = ref;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, SetExpressionNode* node ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ThisExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, LiteralBooleanNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, LiteralNumberNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, LiteralStringNode* node ) {
|
||||
return ObjectValue::undefinedValue;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, LiteralUndefinedNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, LiteralRegExpNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, UnitExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, FunctionExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ParenthesizedExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ParenthesizedListExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, LiteralObjectNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, LiteralFieldNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, LiteralArrayNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, PostfixExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, NewExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, IndexedMemberExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ClassofExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, MemberExpressionNode* node ) {
|
||||
|
||||
/* If the member expression has a base, evaluate it and try to
|
||||
* bind it to its slot. If there it binds, then get the slot
|
||||
* type and then the prototype of that type. The prototype will
|
||||
* be the compile-time stand-in for the instance.
|
||||
*/
|
||||
ObjectValue* prototype = 0;
|
||||
if( node->base ) {
|
||||
Value* val = node->base->evaluate(cx,this);
|
||||
ReferenceValue* ref = dynamic_cast<ReferenceValue*>(val); // Forces the use of RTTI.
|
||||
Slot* slot = ref->getSlot(cx);
|
||||
TypeValue* type = slot->type;
|
||||
|
||||
prototype = type->prototype;
|
||||
}
|
||||
|
||||
ReferenceValue* ref = dynamic_cast<ReferenceValue*>(node->expr->evaluate(cx,this));
|
||||
|
||||
ref->setBase(prototype);
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, CoersionExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, UnaryExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, BinaryExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ConditionalExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, AssignmentExpressionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ListNode* node ) {
|
||||
if( node->list ) {
|
||||
node->list->evaluate(cx,this);
|
||||
}
|
||||
if( node->item ) {
|
||||
node->item->evaluate(cx,this);
|
||||
}
|
||||
return ObjectValue::undefinedValue;
|
||||
}
|
||||
|
||||
// Statements
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, StatementListNode* node ) {
|
||||
if( node->list ) {
|
||||
node->list->evaluate(cx,this);
|
||||
}
|
||||
if( node->item ) {
|
||||
node->item->evaluate(cx,this);
|
||||
}
|
||||
return ObjectValue::undefinedValue;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, EmptyStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ExpressionStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, AnnotatedBlockNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, LabeledStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, IfStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, SwitchStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, CaseLabelNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, DoStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, WhileStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ForInStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ForStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, WithStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ContinueStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, BreakStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ReturnStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ThrowStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, TryStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, CatchClauseNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, FinallyClauseNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, UseStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, IncludeStatementNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
// Definitions
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ImportDefinitionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ImportBindingNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, AnnotatedDefinitionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, AttributeListNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ExportDefinitionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ExportBindingNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, VariableDefinitionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, VariableBindingNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, TypedVariableNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, FunctionDefinitionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, FunctionDeclarationNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, FunctionNameNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, FunctionSignatureNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ParameterNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, OptionalParameterNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ClassDefinitionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ClassDeclarationNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, InheritanceNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, NamespaceDefinitionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, PackageDefinitionNode* node ) {
|
||||
throw;
|
||||
}
|
||||
|
||||
Value* ConstantEvaluator::evaluate( Context& cx, ProgramNode* node ) {
|
||||
if( node->statements != (ProgramNode*)0 ) {
|
||||
node->statements->evaluate(cx,this);
|
||||
}
|
||||
return (Value*)0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Test driver
|
||||
*/
|
||||
|
||||
int ConstantEvaluator::main(int argc, char* argv[]) {
|
||||
|
||||
Context cx;
|
||||
Evaluator* evaluator = new ConstantEvaluator();
|
||||
|
||||
Builder* globalObjectBuilder = new GlobalObjectBuilder();
|
||||
ObjectValue* globalPrototype = new ObjectValue(*globalObjectBuilder);
|
||||
ObjectValue global = ObjectValue(globalPrototype);
|
||||
|
||||
cx.pushScope(&global); // first scope is always considered the global scope.
|
||||
cx.used_namespaces.push_back(ObjectValue::publicNamespace);
|
||||
|
||||
Node* node;
|
||||
Value* val;
|
||||
|
||||
// public::print
|
||||
|
||||
node = NodeFactory::QualifiedIdentifier(
|
||||
NodeFactory::Identifier("public"),
|
||||
NodeFactory::Identifier("print"));
|
||||
val = node->evaluate(cx,evaluator);
|
||||
val = val->getValue(cx);
|
||||
|
||||
// get version
|
||||
|
||||
node = NodeFactory::GetExpression(
|
||||
NodeFactory::MemberExpression(0,
|
||||
NodeFactory::Identifier("version")));
|
||||
|
||||
val = node->evaluate(cx,evaluator);
|
||||
val = val->getValue(cx);
|
||||
|
||||
// print('hello')
|
||||
|
||||
node = NodeFactory::CallExpression(NodeFactory::MemberExpression(0,NodeFactory::Identifier("print")),0);
|
||||
val = node->evaluate(cx,evaluator);
|
||||
val = val->getValue(cx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Written by Jeff Dyer
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* ConstantEvaluator
|
||||
*/
|
||||
|
||||
#ifndef ConstantEvaluator_h
|
||||
#define ConstantEvaluator_h
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "Value.h"
|
||||
#include "Context.h"
|
||||
#include "Evaluator.h"
|
||||
#include "ObjectValue.h"
|
||||
|
||||
//#include "ByteCodeFactory.h"
|
||||
//#include "ClassFileConstants.h"
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
|
||||
class ConstantEvaluator : public Evaluator {
|
||||
|
||||
std::vector<Value*>* used_namespaces;
|
||||
|
||||
public:
|
||||
|
||||
/*
|
||||
* Test driver
|
||||
*/
|
||||
|
||||
static int main(int argc, char* argv[]);
|
||||
|
||||
// Base node
|
||||
|
||||
Value* evaluate( Context& cx, Node* node );
|
||||
|
||||
// 3rd Edition features
|
||||
|
||||
Value* evaluate( Context& cx, IdentifierNode* node );
|
||||
Value* evaluate( Context& cx, ThisExpressionNode* node );
|
||||
Value* evaluate( Context& cx, LiteralBooleanNode* node );
|
||||
Value* evaluate( Context& cx, LiteralNumberNode* node );
|
||||
Value* evaluate( Context& cx, LiteralStringNode* node );
|
||||
Value* evaluate( Context& cx, LiteralUndefinedNode* node );
|
||||
Value* evaluate( Context& cx, LiteralRegExpNode* node );
|
||||
Value* evaluate( Context& cx, FunctionExpressionNode* node );
|
||||
Value* evaluate( Context& cx, ParenthesizedExpressionNode* node );
|
||||
Value* evaluate( Context& cx, ParenthesizedListExpressionNode* node );
|
||||
Value* evaluate( Context& cx, LiteralObjectNode* node );
|
||||
Value* evaluate( Context& cx, LiteralFieldNode* node );
|
||||
Value* evaluate( Context& cx, LiteralArrayNode* node );
|
||||
Value* evaluate( Context& cx, PostfixExpressionNode* node );
|
||||
Value* evaluate( Context& cx, NewExpressionNode* node );
|
||||
Value* evaluate( Context& cx, IndexedMemberExpressionNode* node );
|
||||
Value* evaluate( Context& cx, MemberExpressionNode* node );
|
||||
Value* evaluate( Context& cx, CallExpressionNode* node );
|
||||
Value* evaluate( Context& cx, GetExpressionNode* node );
|
||||
Value* evaluate( Context& cx, SetExpressionNode* node );
|
||||
Value* evaluate( Context& cx, UnaryExpressionNode* node );
|
||||
Value* evaluate( Context& cx, BinaryExpressionNode* node );
|
||||
Value* evaluate( Context& cx, ConditionalExpressionNode* node );
|
||||
Value* evaluate( Context& cx, AssignmentExpressionNode* node );
|
||||
Value* evaluate( Context& cx, ListNode* node );
|
||||
Value* evaluate( Context& cx, StatementListNode* node );
|
||||
Value* evaluate( Context& cx, EmptyStatementNode* node );
|
||||
Value* evaluate( Context& cx, ExpressionStatementNode* node );
|
||||
Value* evaluate( Context& cx, AnnotatedBlockNode* node );
|
||||
Value* evaluate( Context& cx, LabeledStatementNode* node );
|
||||
Value* evaluate( Context& cx, IfStatementNode* node );
|
||||
Value* evaluate( Context& cx, SwitchStatementNode* node );
|
||||
Value* evaluate( Context& cx, CaseLabelNode* node );
|
||||
Value* evaluate( Context& cx, DoStatementNode* node );
|
||||
Value* evaluate( Context& cx, WhileStatementNode* node );
|
||||
Value* evaluate( Context& cx, ForInStatementNode* node );
|
||||
Value* evaluate( Context& cx, ForStatementNode* node );
|
||||
Value* evaluate( Context& cx, WithStatementNode* node );
|
||||
Value* evaluate( Context& cx, ContinueStatementNode* node );
|
||||
Value* evaluate( Context& cx, BreakStatementNode* node );
|
||||
Value* evaluate( Context& cx, ReturnStatementNode* node );
|
||||
Value* evaluate( Context& cx, ThrowStatementNode* node );
|
||||
Value* evaluate( Context& cx, TryStatementNode* node );
|
||||
Value* evaluate( Context& cx, CatchClauseNode* node );
|
||||
Value* evaluate( Context& cx, FinallyClauseNode* node );
|
||||
Value* evaluate( Context& cx, AnnotatedDefinitionNode* node );
|
||||
Value* evaluate( Context& cx, VariableDefinitionNode* node );
|
||||
Value* evaluate( Context& cx, VariableBindingNode* node );
|
||||
Value* evaluate( Context& cx, FunctionDefinitionNode* node );
|
||||
Value* evaluate( Context& cx, FunctionDeclarationNode* node );
|
||||
Value* evaluate( Context& cx, FunctionNameNode* node );
|
||||
Value* evaluate( Context& cx, FunctionSignatureNode* node );
|
||||
Value* evaluate( Context& cx, ParameterNode* node );
|
||||
Value* evaluate( Context& cx, ProgramNode* node );
|
||||
|
||||
// 4th Edition features
|
||||
|
||||
Value* evaluate( Context& cx, QualifiedIdentifierNode* node );
|
||||
Value* evaluate( Context& cx, UnitExpressionNode* node );
|
||||
Value* evaluate( Context& cx, ClassofExpressionNode* node );
|
||||
Value* evaluate( Context& cx, CoersionExpressionNode* node );
|
||||
Value* evaluate( Context& cx, UseStatementNode* node );
|
||||
Value* evaluate( Context& cx, IncludeStatementNode* node );
|
||||
Value* evaluate( Context& cx, ImportDefinitionNode* node );
|
||||
Value* evaluate( Context& cx, ImportBindingNode* node );
|
||||
Value* evaluate( Context& cx, AttributeListNode* node );
|
||||
Value* evaluate( Context& cx, ExportDefinitionNode* node );
|
||||
Value* evaluate( Context& cx, ExportBindingNode* node );
|
||||
Value* evaluate( Context& cx, TypedVariableNode* node );
|
||||
Value* evaluate( Context& cx, OptionalParameterNode* node );
|
||||
Value* evaluate( Context& cx, ClassDefinitionNode* node );
|
||||
Value* evaluate( Context& cx, ClassDeclarationNode* node );
|
||||
Value* evaluate( Context& cx, InheritanceNode* node );
|
||||
Value* evaluate( Context& cx, NamespaceDefinitionNode* node );
|
||||
Value* evaluate( Context& cx, PackageDefinitionNode* node );
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ConstantEvaluator_h
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,215 +0,0 @@
|
||||
/*
|
||||
* ReferenceValue
|
||||
*/
|
||||
|
||||
#pragma warning ( disable : 4786 )
|
||||
|
||||
#include <stack>
|
||||
|
||||
#include "ReferenceValue.h"
|
||||
#include "TypeValue.h"
|
||||
#include "ObjectValue.h"
|
||||
#include "Context.h"
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
ReferenceValue::ReferenceValue(ObjectValue* base, std::string name,
|
||||
Value* qualifier)
|
||||
: base(base), name(name), qualifier(qualifier),
|
||||
used_namespaces((std::vector<Value*>*)0), slot((Slot*)0),
|
||||
slot_index(0),scope_index(0) {
|
||||
}
|
||||
|
||||
ReferenceValue::ReferenceValue(ObjectValue* base, std::string name,
|
||||
std::vector<Value*>* used_namespaces)
|
||||
: base(base), name(name), qualifier((Value*)0),
|
||||
used_namespaces(used_namespaces), slot((Slot*)0),
|
||||
slot_index(0),scope_index(0) {
|
||||
}
|
||||
|
||||
Value* ReferenceValue::getValue(Context& cx) {
|
||||
|
||||
|
||||
Slot* s = this->getSlot(cx);
|
||||
|
||||
if( s ) {
|
||||
return s->value;
|
||||
} else {
|
||||
return (Value*)0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Slot* ReferenceValue::getSlot(Context& cx) {
|
||||
|
||||
if( slot ) {
|
||||
return slot;
|
||||
}
|
||||
|
||||
if( lookup(cx) ) {
|
||||
// lookup has the side-effect of binding
|
||||
// this reference to its defining slot. So
|
||||
// now just return it.
|
||||
return this->slot;
|
||||
} else {
|
||||
return (Slot*)0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Lookup qualified name in the given context.
|
||||
*/
|
||||
|
||||
bool ReferenceValue::lookup(Context& cx) {
|
||||
|
||||
ObjectValue* obj;
|
||||
|
||||
if(!base) {
|
||||
|
||||
// If there is no base reference, search for the
|
||||
// binding from the inside to the outside of the
|
||||
// scope chain. Fix up this reference's base member
|
||||
// and recurse.
|
||||
|
||||
std::stack<ObjectValue*> scopes = cx.getScopes();
|
||||
int scope_index = 0;
|
||||
while( scopes.size() ) {
|
||||
this->base = scopes.top(); // Set the base value
|
||||
if( this->lookup(cx) ) {
|
||||
// Found one. Clear the temporary base value
|
||||
// and set the scope index.
|
||||
this->base = 0;
|
||||
this->scope_index = scope_index;
|
||||
break;
|
||||
}
|
||||
scopes.pop();
|
||||
++scope_index;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// If there is a base reference, search for the
|
||||
// binding in this object and then up the proto
|
||||
// chain.
|
||||
|
||||
if(!qualifier) {
|
||||
return this->lookupUnqualified(cx);
|
||||
}
|
||||
|
||||
obj = base;
|
||||
|
||||
while(obj && !obj->hasName(cx,name,qualifier)) {
|
||||
obj = obj->proto(cx);
|
||||
}
|
||||
|
||||
if( !obj ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Bind slot
|
||||
|
||||
this->slot_index = obj->getSlotIndex(cx,name,qualifier);
|
||||
this->slot = obj->getSlot(cx,this->slot_index);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lookup a name that has one of the used namespaces.
|
||||
*
|
||||
* 1 Traverse to root of proto chain, pushing all objects
|
||||
* onto a temporary stack.
|
||||
* 2 In lifo order, see if one or more of the qualified
|
||||
* names represented by the name and the used qualfiers
|
||||
* is in the top object on the stack. Repeat for all
|
||||
* objects on the stack until one object with at least
|
||||
* one match is found, or all objects have been searched.
|
||||
* 3 Create a new set of namespaces that inclues all
|
||||
* the qualifiers of all the names that matched in the
|
||||
* previous step.
|
||||
* 4 Starting with the most derived object, search to
|
||||
* proto chain for one or more of the qualified names
|
||||
* represented by the name and the new set of used
|
||||
* qualifiers.
|
||||
* 5 If the found set represents more than one slot, throw
|
||||
* and error exception. Otherwise, return true.
|
||||
* 6 If no matching names are found, return false.
|
||||
*/
|
||||
|
||||
bool ReferenceValue::lookupUnqualified(Context& cx) {
|
||||
|
||||
// Search this object and up the inheritance chain
|
||||
// to find the qualified name.
|
||||
|
||||
ObjectValue* obj = base;
|
||||
|
||||
// Push the protos onto a stack.
|
||||
|
||||
std::stack<ObjectValue*> protos;
|
||||
|
||||
while(obj) {
|
||||
protos.push(obj);
|
||||
obj = obj->proto(cx);
|
||||
}
|
||||
|
||||
// Search the protos top-down for matching names.
|
||||
|
||||
Namespaces* namespaces = 0;
|
||||
while(!protos.empty()) {
|
||||
ObjectValue* obj = protos.top();
|
||||
namespaces = obj->hasNames(cx,name,&cx.used_namespaces);
|
||||
if( namespaces ) {
|
||||
break;
|
||||
}
|
||||
protos.pop();
|
||||
}
|
||||
|
||||
// If no namespaces, then no matches. Return false.
|
||||
|
||||
if( !namespaces ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Search for the first object in the proto chain that
|
||||
// matches the name and namespaces.
|
||||
|
||||
obj = base?base:cx.scope();
|
||||
|
||||
while(obj && !(obj->hasNames(cx,name,namespaces))) {
|
||||
obj = obj->proto(cx);
|
||||
}
|
||||
|
||||
if( !obj ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify that all matched names point to a single slot.
|
||||
|
||||
int last_index = 0;
|
||||
for( int i = 0; i < namespaces->size(); i++ ) {
|
||||
Value* qualifier = namespaces->at(i);
|
||||
int index = obj->getSlotIndex(cx,name,qualifier);
|
||||
if( last_index!=0 && index!=last_index ) {
|
||||
throw;
|
||||
// error();
|
||||
}
|
||||
last_index = index;
|
||||
}
|
||||
|
||||
// Bind slot
|
||||
|
||||
this->slot_index = last_index;
|
||||
this->slot = obj->getSlot(cx,this->slot_index);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Written by Jeff Dyer
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* ReferenceValue
|
||||
*/
|
||||
|
||||
#ifndef ReferenceValue_h
|
||||
#define ReferenceValue_h
|
||||
|
||||
#pragma warning( disable : 4786 )
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Value.h"
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
struct Slot;
|
||||
class ObjectValue;
|
||||
class Context;
|
||||
|
||||
class ReferenceValue : public Value {
|
||||
|
||||
ObjectValue* base;
|
||||
Value* qualifier;
|
||||
std::vector<Value*>* used_namespaces;
|
||||
Slot* slot;
|
||||
int slot_index;
|
||||
int scope_index;
|
||||
|
||||
|
||||
public:
|
||||
std::string name;
|
||||
|
||||
ReferenceValue(ObjectValue* base, std::string name, Value* qualifier);
|
||||
ReferenceValue(ObjectValue* base, std::string name, std::vector<Value*>* used_namespaces);
|
||||
bool lookup(Context& cx);
|
||||
bool lookupUnqualified(Context& cx);
|
||||
Slot* getSlot(Context& cx);
|
||||
Value* getValue(Context& cx);
|
||||
int getSlotIndex() { return slot_index; }
|
||||
int getScopeIndex() { return scope_index; }
|
||||
ReferenceValue* setBase(ObjectValue* base) { this->base = base; return this; }
|
||||
|
||||
// main
|
||||
|
||||
static int main(int argc, char* argv[]);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ReferenceValue_h
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* The value class from which all other values derive.
|
||||
*/
|
||||
|
||||
#pragma warning ( disable : 4786 )
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Context.h"
|
||||
#include "Value.h"
|
||||
#include "Type.h"
|
||||
#include "Slot.h"
|
||||
#include "Builder.h"
|
||||
|
||||
#include "TypeValue.h"
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
|
||||
bool TypeValue::isInitialized = false;
|
||||
TypeValue* TypeValue::booleanType;
|
||||
TypeValue* TypeValue::namespaceType;
|
||||
TypeValue* TypeValue::objectType;
|
||||
TypeValue* TypeValue::typeType;
|
||||
|
||||
void TypeValue::init() {
|
||||
|
||||
if( isInitialized ) {
|
||||
return;
|
||||
}
|
||||
|
||||
isInitialized = true;
|
||||
booleanType = new TypeValue();
|
||||
namespaceType = new TypeValue();
|
||||
objectType = new TypeValue();
|
||||
typeType = new TypeValue();
|
||||
}
|
||||
|
||||
void TypeValue::fini() {
|
||||
|
||||
if( isInitialized ) {
|
||||
delete typeType;
|
||||
delete objectType;
|
||||
delete namespaceType;
|
||||
delete booleanType;
|
||||
isInitialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TypeValue::includes(Context& cx, Value* value) {
|
||||
|
||||
TypeValue* type = value->getType(cx);
|
||||
|
||||
while( type ) {
|
||||
if( type == this ) {
|
||||
return true;
|
||||
}
|
||||
type = type->super(cx);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void TypeValue::build(Context& cx, ObjectValue* ob) {
|
||||
}
|
||||
|
||||
TypeValue* TypeValue::super(Context& cx) {
|
||||
return reinterpret_cast<TypeValue*>(this->proto(cx));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Written by Jeff Dyer
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,58 +0,0 @@
|
||||
#ifndef TypeValue_h
|
||||
#define TypeValue_h
|
||||
|
||||
/**
|
||||
* The interface for all types.
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "Builder.h"
|
||||
#include "ObjectValue.h"
|
||||
|
||||
namespace esc {
|
||||
namespace v1 {
|
||||
|
||||
class TypeValue : public ObjectValue, public Type, public Builder {
|
||||
static bool isInitialized;
|
||||
public:
|
||||
|
||||
ObjectValue* prototype;
|
||||
|
||||
virtual bool includes(Context& cx, Value* value);
|
||||
virtual void build(Context& cx, ObjectValue* ob);
|
||||
TypeValue* super(Context& cx);
|
||||
|
||||
TypeValue() {
|
||||
this->prototype = new ObjectValue();
|
||||
}
|
||||
|
||||
static TypeValue* booleanType;
|
||||
static TypeValue* namespaceType;
|
||||
static TypeValue* objectType;
|
||||
static TypeValue* typeType;
|
||||
|
||||
#if 0
|
||||
virtual std::vector<Value*> values() {};
|
||||
virtual std::vector<Value*> converts() {};
|
||||
virtual void addSub(Type& type) {};
|
||||
virtual void setSuper(Type& type) {};
|
||||
virtual Type* getSuper(){};
|
||||
virtual Value* convert(Context& cx, Value& value) {};
|
||||
virtual Value* coerce(Context& cx, Value& value) {};
|
||||
#endif
|
||||
|
||||
static void init();
|
||||
static void fini();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // TypeValue_h
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998-2001 by Mountain View Compiler Company
|
||||
* All rights reserved.
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* 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.*;
|
||||
|
||||
/*
|
||||
* Debugging tool.
|
||||
*/
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,512 +0,0 @@
|
||||
/*
|
||||
* 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>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Filters and buffers characters from a input reader.
|
||||
*/
|
||||
|
||||
package com.compilercompany.es3c.v1;
|
||||
import java.io.*;
|
||||
|
||||
public class InputBuffer implements CharacterClasses {
|
||||
|
||||
private static final boolean debug = false;
|
||||
private static final boolean debug_nextchar = true;
|
||||
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.toString().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.
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,397 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/*
|
||||
* The states of the scanner.
|
||||
*/
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* Represents token instances: literals and identifiers.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,303 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/*
|
||||
* Defines token classes and their print names.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,194 +0,0 @@
|
||||
/*
|
||||
* 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 java.io.*;
|
||||
|
||||
/*
|
||||
* The main driver.
|
||||
*/
|
||||
|
||||
public class Main {
|
||||
|
||||
String[] classes;
|
||||
|
||||
/**
|
||||
* Entry point.
|
||||
*/
|
||||
|
||||
public static void main(String[] args) {
|
||||
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 doASM = false;
|
||||
private static boolean debug = false;
|
||||
|
||||
|
||||
public Main(String[] args) {
|
||||
if (args.length == 0) {
|
||||
System.out.println("Wrong args, read the 'readme' and try again");
|
||||
}
|
||||
|
||||
/* 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].equals("-a")||args[i].equals("-asm")) {
|
||||
doASM = true;
|
||||
} else if (args[i].charAt(0) == '-') {
|
||||
System.out.println("Unknown.option "+ args[i]);
|
||||
} else {
|
||||
break; /* The rest must be classes. */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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) {
|
||||
System.out.println("No script 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 = UndefinedValue.undefinedValue;
|
||||
|
||||
Class pc = Parser.class;
|
||||
Class[] args = new Class[0];
|
||||
|
||||
Parser parser;
|
||||
long t=0;
|
||||
|
||||
ObjectValue global = null;
|
||||
|
||||
int errorCount=0;
|
||||
|
||||
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();
|
||||
|
||||
t = System.currentTimeMillis();
|
||||
node = parser.parseProgram();
|
||||
errorCount = parser.errorCount();
|
||||
if( errorCount == 0 ) {
|
||||
|
||||
|
||||
if( traceParser ) {
|
||||
Debugger.trace("setting parser output to " + input[i]);
|
||||
JSILGenerator.setOut( input[i]+".par" );
|
||||
node.evaluate(context,new JSILGenerator(false));
|
||||
}
|
||||
|
||||
//Evaluator evaluator;
|
||||
|
||||
|
||||
context.setEvaluator(new BlockEvaluator());
|
||||
node.evaluate(context, context.getEvaluator());
|
||||
|
||||
//JSILGenerator.setOut( input[i]+".blocks" );
|
||||
//context.setEvaluator(new JSILGenerator(false));
|
||||
//node.evaluate(context, context.getEvaluator());
|
||||
|
||||
context.setEvaluator(new ConstantEvaluator());
|
||||
value = node.evaluate(context, context.getEvaluator());
|
||||
|
||||
context.setEvaluator(new JSILGenerator(doASM));
|
||||
JSILGenerator.setOut( input[i]+".jsil" );
|
||||
node.evaluate(context, context.getEvaluator());
|
||||
errorCount = context.errorCount();
|
||||
}
|
||||
|
||||
t = System.currentTimeMillis() - t;
|
||||
//Debugger.trace(""+global);
|
||||
System.out.println(input[i] + ": "+ errorCount +" errors [" + Long.toString(t) + " msec]");
|
||||
|
||||
} 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.
|
||||
*/
|
||||
@@ -1,15 +0,0 @@
|
||||
/*
|
||||
* Not used.
|
||||
*/
|
||||
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
interface Attributes {
|
||||
static final int ReadOnly = 0x00000001;
|
||||
static final int DontDelete = 0x00000002;
|
||||
static final int DontEnum = 0x00000004;
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* Represents a basic block for flow analysis.
|
||||
*/
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,214 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* Context used during semantic analysis.
|
||||
*/
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* Not used.
|
||||
**/
|
||||
|
||||
public interface Errors {
|
||||
|
||||
static final String syntaxPart1_error = "Error at: ";
|
||||
static final String syntaxPart2_error = " Expecting a ";
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
||||
@@ -1,243 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* The base visitor object extended by semantic evaluators.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* Interface that object initializers implement.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,64 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* The base Node class.
|
||||
*/
|
||||
|
||||
public class Node {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
Block block;
|
||||
int position;
|
||||
Store store;
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,273 +0,0 @@
|
||||
/*
|
||||
* Creates parse tree nodes.
|
||||
*/
|
||||
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
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,in.positionOfMark());
|
||||
}
|
||||
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 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,in.positionOfMark());
|
||||
}
|
||||
static MemberExpressionNode MemberExpression( Node base, Node name ) {
|
||||
return new MemberExpressionNode(base,name,in.positionOfMark());
|
||||
}
|
||||
static CoersionExpressionNode CoersionExpression( Node expr, Node type ) {
|
||||
return new CoersionExpressionNode(expr,type,in.positionOfMark());
|
||||
}
|
||||
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.
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,15 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* A scope, which contains slots.
|
||||
*/
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* A slot.
|
||||
*/
|
||||
|
||||
public class Slot {
|
||||
Value attrs;
|
||||
Value type;
|
||||
Value value;
|
||||
Block block;
|
||||
Store store;
|
||||
|
||||
public String toString() {
|
||||
return "{ "+attrs+", "+type+", "+value+", "+store+" }";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* Represents an abstract unit of storage.
|
||||
*/
|
||||
|
||||
public class Store {
|
||||
Scope scope;
|
||||
int index;
|
||||
|
||||
Store(Scope scope, int index) {
|
||||
this.scope = scope;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "store( " + index + " )";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* The interfaces for all types.
|
||||
*/
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,92 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
*/
|
||||
}
|
||||
|
||||
int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,962 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Delineates the program into its basic execution blocks.
|
||||
*
|
||||
* 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 );
|
||||
}
|
||||
|
||||
if( node.statements != null ) {
|
||||
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.
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,56 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
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.
|
||||
*/
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,53 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* class ClassType
|
||||
*/
|
||||
|
||||
public final class ClassType extends ObjectType implements Type {
|
||||
|
||||
private static final 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");
|
||||
ObjectType.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.
|
||||
*/
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,209 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* class ObjectType
|
||||
*/
|
||||
|
||||
public class ObjectType implements Type {
|
||||
|
||||
private static final boolean debug = true;
|
||||
|
||||
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) {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("ObjectType.includes() with this = " + this + ", value.type = " + value.type + ", values_ = " + values_);
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* A boolean value: true or false.
|
||||
*/
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* A character value.
|
||||
*/
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* A code value (intermediate).
|
||||
*
|
||||
* This value holds the intermediate code for an non-constant value.
|
||||
*/
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* A completion value (intermediate).
|
||||
*/
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,184 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* The global object initializer.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* A list value (intermediate).
|
||||
*/
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* The null value.
|
||||
*/
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* A number value.
|
||||
*/
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,201 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* An object value.
|
||||
*/
|
||||
|
||||
public class ObjectValue extends Value implements Attributes, Scope {
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
Hashtable slots = new Hashtable();
|
||||
String name;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public ObjectValue() {
|
||||
this.type = null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Slot slot;
|
||||
if( namespace == null ) {
|
||||
slot = (Slot) slots.get(name);
|
||||
} else {
|
||||
ObjectValue names = (ObjectValue)slots.get(namespace);
|
||||
if( names == null ) {
|
||||
slot = null;
|
||||
} else {
|
||||
slot = (Slot) names.slots.get(name);
|
||||
}
|
||||
}
|
||||
|
||||
return slot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a name to a namespace and return the resulting slot.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
int size() {
|
||||
return slots.size();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,185 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* A reference value.
|
||||
*/
|
||||
|
||||
public class ReferenceValue extends Value {
|
||||
|
||||
private static final boolean debug = true;
|
||||
|
||||
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 + " used_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( slot==null ) {
|
||||
slot = scope.get(qualifier/*=null*/,name);
|
||||
}
|
||||
}
|
||||
if( debug ) {
|
||||
Debugger.trace("leaving getSlotInScope() with slot="+slot);
|
||||
}
|
||||
return slot;
|
||||
}
|
||||
|
||||
public Slot getSlot(Context context) throws Exception {
|
||||
|
||||
if( debug ) {
|
||||
Debugger.trace("ReferenceValue.getSlot() with namespaces = " + namespaces + ", name = " + name );
|
||||
}
|
||||
|
||||
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("ReferenceValue.getValue() with namespaces = " + namespaces + ", name = " + name );
|
||||
}
|
||||
|
||||
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("ReferenceValue.getType() with namespaces = " + namespaces + ", name = " + name );
|
||||
}
|
||||
|
||||
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("ReferenceValue.getAttrs() with namespaces = " + namespaces + ", name = " + name );
|
||||
}
|
||||
|
||||
Value attrs = null;
|
||||
Slot slot = getSlot(context);
|
||||
|
||||
if( slot != null ) {
|
||||
attrs = slot.attrs;
|
||||
}
|
||||
|
||||
return attrs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* The end.
|
||||
*/
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* A string value.
|
||||
*/
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,170 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* A type value.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.compilercompany.es3c.v1;
|
||||
|
||||
/**
|
||||
* The undefined value.
|
||||
*/
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* 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-2001, Mountain View Compiler Company.
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Postfix Expressions
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "Postfix Expressions";
|
||||
}
|
||||
|
||||
class T {}
|
||||
class V {}
|
||||
|
||||
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));
|
||||
(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;}.class)::c[1,2].class--;
|
||||
(const new const function f(a,b){return a+b;}.class)::c[1,2].class@T;
|
||||
(const new const function f(a,b){return a+b;}.class)::c[1,2].class@(T);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000, Mountain View Compiler Company.
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* 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-2001, Mountain View Compiler Company.
|
||||
* All rights reserved.
|
||||
*/
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* The break Statement
|
||||
*/
|
||||
|
||||
function title() {
|
||||
return "The break Statement";
|
||||
}
|
||||
|
||||
function run() {
|
||||
break
|
||||
break id
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, Mountain View Compiler Company. All rights reserved.
|
||||
*/
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user