Refactor parser mode configuration for correctness
authormstarzinger@chromium.org <mstarzinger@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 5 Apr 2013 13:01:06 +0000 (13:01 +0000)
committermstarzinger@chromium.org <mstarzinger@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 5 Apr 2013 13:01:06 +0000 (13:01 +0000)
commitd71678676fe9aa94c51e1da3d0fb258f8d9d6435
tree8aa87d25f0b0875a4e958ecb5c82052cbf7bf990
parentc02bf4515c5a2ebcc1381f8d58a833c3498cfa88
Refactor parser mode configuration for correctness

This patch refactors the parser and preparser interface to be more
readable and type-safe.  It has no behavior changes.

Previously, parsers and preparsers were configured via bitfield called
parser_flags in the Parser constructor, and flags in
PreParser::PreParseProgram, ParserApi::Parse, and ParserApi::PreParse.
This was error-prone in practice: six call sites passed incorrectly
typed values to this interface (a boolean FLAG value, a boolean false
and a boolean true value).  None of these errors were caught by the
compiler because it's just an "int".

The parser flags interface was also awkward because it encoded a
language mode, but the language mode was only used to turn on harmony
scoping or not -- it wasn't used to actually set the parser's language
mode.

Fundamentally these errors came in because of the desire for a
procedural parser interface, in ParserApi.  Because we need to be able
to configure the parser in various ways, the flags argument got added;
but no one understood how to use the flags properly.  Also they were
only used by constructors: callers packed bits, and the constructors
unpacked them into booleans on the parser or preparser.

The solution is to allow parser construction, configuration, and
invocation to be separated.  This patch does that.

It passes the existing tests.

BUG=

Review URL: https://codereview.chromium.org/13450007
Patch from Andy Wingo <wingo@igalia.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14151 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
12 files changed:
src/api.cc
src/compiler.cc
src/hydrogen.cc
src/liveedit.cc
src/parser.cc
src/parser.h
src/preparser-api.cc
src/preparser.cc
src/preparser.h
src/runtime.cc
src/scanner.h
test/cctest/test-parsing.cc