State of the art:
- Chromium doesn't do a separate preparsing phase any more.
- We start parsing with Parser, and when it sees a lazy function, it falls back
to PreParser for that function.
- The symbol data should contain symbols which are *outside* lazy functions.
- So Parser should always produce symbol data, and PreParser should never.
- Because it's this simple now, we don't need to keep track of "should
produce symbol data" (i.e., whether we're inside a lazy func or not).
R=ulan@chromium.org
BUG=
Review URL: https://codereview.chromium.org/
222123003
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20707
ce2b1a6d-e550-0410-aec6-
3dcde31c8c00
return parser_->LookupCachedSymbol(symbol_id);
}
} else if (parser_->cached_data_mode() == PRODUCE_CACHED_DATA) {
- if (parser_->log_->ShouldLogSymbols()) {
- parser_->scanner()->LogSymbol(parser_->log_, parser_->position());
- }
+ // Parser is never used inside lazy functions (it falls back to PreParser
+ // instead), so we can produce the symbol data unconditionally.
+ parser_->scanner()->LogSymbol(parser_->log_, parser_->position());
}
Handle<String> result =
parser_->scanner()->AllocateInternalizedString(parser_->isolate());
// With no cached data, we partially parse the function, without
// building an AST. This gathers the data needed to build a lazy
// function.
- // FIXME(marja): Now the PreParser doesn't need to log functions /
- // symbols; only errors -> clean that up.
SingletonLogger logger;
PreParser::PreParseResult result = LazyParseFunctionLiteral(&logger);
if (result == PreParser::kPreParseStackOverflow) {
#ifdef DEBUG
prev_start_ = -1;
#endif
- should_log_symbols_ = true;
}
STATIC_ASSERT(PreparseDataConstants::kMessageTextPos == 4);
WriteString(CStrVector(message));
if (arg_opt != NULL) WriteString(CStrVector(arg_opt));
- should_log_symbols_ = false;
}
void CompleteParserRecorder::LogOneByteSymbol(int start,
Vector<const uint8_t> literal) {
- ASSERT(should_log_symbols_);
int hash = vector_hash(literal);
LogSymbol(start, hash, true, literal);
}
void CompleteParserRecorder::LogTwoByteSymbol(int start,
Vector<const uint16_t> literal) {
- ASSERT(should_log_symbols_);
int hash = vector_hash(literal);
LogSymbol(start, hash, false, Vector<const byte>::cast(literal));
}
// Abstract interface for preparse data recorder.
class ParserRecorder {
public:
- ParserRecorder() : should_log_symbols_(false) { }
+ ParserRecorder() { }
virtual ~ParserRecorder() { }
// Logs the scope and some details of a function literal in the source.
const char* argument_opt,
bool is_reference_error) = 0;
- // Logs a symbol creation of a literal or identifier.
- bool ShouldLogSymbols() { return should_log_symbols_; }
// The following functions are only callable on CompleteParserRecorder
// and are guarded by calls to ShouldLogSymbols.
virtual void LogOneByteSymbol(int start, Vector<const uint8_t> literal) {
virtual void LogTwoByteSymbol(int start, Vector<const uint16_t> literal) {
UNREACHABLE();
}
- virtual void PauseRecording() { UNREACHABLE(); }
- virtual void ResumeRecording() { UNREACHABLE(); }
-
- protected:
- bool should_log_symbols_;
private:
DISALLOW_COPY_AND_ASSIGN(ParserRecorder);
const char* argument_opt,
bool is_reference_error_);
- virtual void PauseRecording() {
- ASSERT(should_log_symbols_);
- should_log_symbols_ = false;
- }
-
- virtual void ResumeRecording() {
- ASSERT(!should_log_symbols_);
- should_log_symbols_ = !has_error();
- }
-
virtual void LogOneByteSymbol(int start, Vector<const uint8_t> literal);
virtual void LogTwoByteSymbol(int start, Vector<const uint16_t> literal);
Vector<unsigned> ExtractData();
PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) {
- pre_parser_->LogSymbol();
if (scanner->current_token() == Token::FUTURE_RESERVED_WORD) {
return PreParserIdentifier::FutureReserved();
} else if (scanner->current_token() ==
PreParserExpression PreParserTraits::ExpressionFromString(
int pos, Scanner* scanner, PreParserFactory* factory) {
- pre_parser_->LogSymbol();
if (scanner->UnescapedLiteralMatches("use strict", 10)) {
return PreParserExpression::UseStrictStringLiteral();
}
void PreParser::ParseLazyFunctionLiteralBody(bool* ok) {
int body_start = position();
- bool is_logging = log_->ShouldLogSymbols();
- if (is_logging) log_->PauseRecording();
ParseSourceElements(Token::RBRACE, ok);
- if (is_logging) log_->ResumeRecording();
if (!*ok) return;
// Position right after terminal '}'.
#undef CHECK_OK
-void PreParser::LogSymbol() {
- if (log_->ShouldLogSymbols()) {
- scanner()->LogSymbol(log_, position());
- }
-}
-
-
} } // v8::internal
bool* ok);
void ParseLazyFunctionLiteralBody(bool* ok);
- // Logs the currently parsed literal as a symbol in the preparser data.
- void LogSymbol();
- // Log the currently parsed string literal.
- Expression GetStringSymbol();
-
bool CheckInOrOf(bool accept_OF);
};