diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2011-06-29 17:26:51 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2011-06-29 17:26:51 +0200 |
commit | 33af2720f26c2b25bc7f75ce7eb454ff99db6d35 (patch) | |
tree | 9a38f0c96420edf503eebd6325dd8d2d8249f653 /deps/v8/src/parser.h | |
parent | 6afdca885adeeeed9eef8cbb01c3d97af0bc084d (diff) | |
download | node-new-33af2720f26c2b25bc7f75ce7eb454ff99db6d35.tar.gz |
Upgrade V8 to 3.4.8
Diffstat (limited to 'deps/v8/src/parser.h')
-rw-r--r-- | deps/v8/src/parser.h | 130 |
1 files changed, 42 insertions, 88 deletions
diff --git a/deps/v8/src/parser.h b/deps/v8/src/parser.h index bc7bc562ea..ea2e0d529f 100644 --- a/deps/v8/src/parser.h +++ b/deps/v8/src/parser.h @@ -1,4 +1,4 @@ -// Copyright 2010 the V8 project authors. All rights reserved. +// Copyright 2011 the V8 project authors. All rights reserved. // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: @@ -32,6 +32,7 @@ #include "ast.h" #include "scanner.h" #include "scopes.h" +#include "preparse-data-format.h" #include "preparse-data.h" namespace v8 { @@ -42,7 +43,7 @@ class FuncNameInferrer; class ParserLog; class PositionStack; class Target; -class TemporaryScope; +class LexicalScope; template <typename T> class ZoneListWrapper; @@ -71,22 +72,14 @@ class FunctionEntry BASE_EMBEDDED { FunctionEntry() : backing_(Vector<unsigned>::empty()) { } int start_pos() { return backing_[kStartPosOffset]; } - void set_start_pos(int value) { backing_[kStartPosOffset] = value; } - int end_pos() { return backing_[kEndPosOffset]; } - void set_end_pos(int value) { backing_[kEndPosOffset] = value; } - int literal_count() { return backing_[kLiteralCountOffset]; } - void set_literal_count(int value) { backing_[kLiteralCountOffset] = value; } - int property_count() { return backing_[kPropertyCountOffset]; } - void set_property_count(int value) { - backing_[kPropertyCountOffset] = value; - } + bool strict_mode() { return backing_[kStrictModeOffset] != 0; } bool is_valid() { return backing_.length() > 0; } - static const int kSize = 4; + static const int kSize = 5; private: Vector<unsigned> backing_; @@ -94,6 +87,7 @@ class FunctionEntry BASE_EMBEDDED { static const int kEndPosOffset = 1; static const int kLiteralCountOffset = 2; static const int kPropertyCountOffset = 3; + static const int kStrictModeOffset = 4; }; @@ -280,6 +274,9 @@ class RegExpBuilder: public ZoneObject { void FlushCharacters(); void FlushText(); void FlushTerms(); + Zone* zone() { return zone_; } + + Zone* zone_; bool pending_empty_; ZoneList<uc16>* characters_; BufferedZoneList<RegExpTree, 2> terms_; @@ -388,6 +385,9 @@ class RegExpParser { int disjunction_capture_index_; }; + Isolate* isolate() { return isolate_; } + Zone* zone() { return isolate_->zone(); } + uc32 current() { return current_; } bool has_more() { return has_more_; } bool has_next() { return next_pos_ < in()->length(); } @@ -395,6 +395,7 @@ class RegExpParser { FlatStringReader* in() { return in_; } void ScanForCaptures(); + Isolate* isolate_; Handle<String>* error_; ZoneList<RegExpCapture*>* captures_; FlatStringReader* in_; @@ -441,6 +442,7 @@ class Parser { // construct a hashable id, so if more than 2^17 are allowed, this // should be checked. static const int kMaxNumFunctionParameters = 32766; + static const int kMaxNumFunctionLocals = 32767; FunctionLiteral* ParseLazy(CompilationInfo* info, UC16CharacterStream* source, ZoneScope* zone_scope); @@ -449,6 +451,9 @@ class Parser { PARSE_EAGERLY }; + Isolate* isolate() { return isolate_; } + Zone* zone() { return isolate_->zone(); } + // Called by ParseProgram after setting up the scanner. FunctionLiteral* DoParseProgram(Handle<String> source, bool in_global_context, @@ -461,10 +466,13 @@ class Parser { void ReportMessage(const char* message, Vector<const char*> args); bool inside_with() const { return with_nesting_level_ > 0; } - V8JavaScriptScanner& scanner() { return scanner_; } + JavaScriptScanner& scanner() { return scanner_; } Mode mode() const { return mode_; } ScriptDataImpl* pre_data() const { return pre_data_; } + // Check if the given string is 'eval' or 'arguments'. + bool IsEvalOrArguments(Handle<String> string); + // All ParseXXX functions take as the last argument an *ok parameter // which is set to false if parsing failed; it is unchanged otherwise. // By making the 'exception handling' explicit, we are forced to check @@ -483,10 +491,7 @@ class Parser { Statement* ParseContinueStatement(bool* ok); Statement* ParseBreakStatement(ZoneStringList* labels, bool* ok); Statement* ParseReturnStatement(bool* ok); - Block* WithHelper(Expression* obj, - ZoneStringList* labels, - bool is_catch_block, - bool* ok); + Block* WithHelper(Expression* obj, ZoneStringList* labels, bool* ok); Statement* ParseWithStatement(ZoneStringList* labels, bool* ok); CaseClause* ParseCaseClause(bool* default_seen_ptr, bool* ok); SwitchStatement* ParseSwitchStatement(ZoneStringList* labels, bool* ok); @@ -574,7 +579,7 @@ class Parser { if (stack_overflow_) { return Token::ILLEGAL; } - if (StackLimitCheck().HasOverflowed()) { + if (StackLimitCheck(isolate()).HasOverflowed()) { // Any further calls to Next or peek will return the illegal token. // The current call must return the next token, which might already // have been peek'ed. @@ -592,21 +597,21 @@ class Parser { Handle<String> LiteralString(PretenureFlag tenured) { if (scanner().is_literal_ascii()) { - return Factory::NewStringFromAscii(scanner().literal_ascii_string(), - tenured); + return isolate_->factory()->NewStringFromAscii( + scanner().literal_ascii_string(), tenured); } else { - return Factory::NewStringFromTwoByte(scanner().literal_uc16_string(), - tenured); + return isolate_->factory()->NewStringFromTwoByte( + scanner().literal_uc16_string(), tenured); } } Handle<String> NextLiteralString(PretenureFlag tenured) { if (scanner().is_next_literal_ascii()) { - return Factory::NewStringFromAscii(scanner().next_literal_ascii_string(), - tenured); + return isolate_->factory()->NewStringFromAscii( + scanner().next_literal_ascii_string(), tenured); } else { - return Factory::NewStringFromTwoByte(scanner().next_literal_uc16_string(), - tenured); + return isolate_->factory()->NewStringFromTwoByte( + scanner().next_literal_uc16_string(), tenured); } } @@ -618,11 +623,12 @@ class Parser { Literal* GetLiteralNumber(double value); Handle<String> ParseIdentifier(bool* ok); - Handle<String> ParseIdentifierOrReservedWord(bool* is_reserved, bool* ok); + Handle<String> ParseIdentifierOrStrictReservedWord( + bool* is_strict_reserved, bool* ok); Handle<String> ParseIdentifierName(bool* ok); - Handle<String> ParseIdentifierOrGetOrSet(bool* is_get, - bool* is_set, - bool* ok); + Handle<String> ParseIdentifierNameOrGetOrSet(bool* is_get, + bool* is_set, + bool* ok); // Strict mode validation of LValue expressions void CheckStrictModeLValue(Expression* expression, @@ -642,7 +648,7 @@ class Parser { BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok); IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); - void RegisterTargetUse(BreakTarget* target, Target* stop); + void RegisterTargetUse(Label* target, Target* stop); // Factory methods. @@ -686,15 +692,16 @@ class Parser { Handle<String> type, Vector< Handle<Object> > arguments); + Isolate* isolate_; ZoneList<Handle<String> > symbol_cache_; Handle<Script> script_; - V8JavaScriptScanner scanner_; + JavaScriptScanner scanner_; Scope* top_scope_; int with_nesting_level_; - TemporaryScope* temp_scope_; + LexicalScope* lexical_scope_; Mode mode_; Target* target_stack_; // for break, continue statements @@ -709,6 +716,8 @@ class Parser { // Heuristically that means that the function will be called immediately, // so never lazily compile it. bool parenthesized_function_; + + friend class LexicalScope; }; @@ -742,61 +751,6 @@ class CompileTimeValue: public AllStatic { DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); }; - -// ---------------------------------------------------------------------------- -// JSON PARSING - -// JSON is a subset of JavaScript, as specified in, e.g., the ECMAScript 5 -// specification section 15.12.1 (and appendix A.8). -// The grammar is given section 15.12.1.2 (and appendix A.8.2). -class JsonParser BASE_EMBEDDED { - public: - // Parse JSON input as a single JSON value. - // Returns null handle and sets exception if parsing failed. - static Handle<Object> Parse(Handle<String> source) { - if (source->IsExternalTwoByteString()) { - ExternalTwoByteStringUC16CharacterStream stream( - Handle<ExternalTwoByteString>::cast(source), 0, source->length()); - return JsonParser().ParseJson(source, &stream); - } else { - GenericStringUC16CharacterStream stream(source, 0, source->length()); - return JsonParser().ParseJson(source, &stream); - } - } - - private: - JsonParser() { } - ~JsonParser() { } - - // Parse a string containing a single JSON value. - Handle<Object> ParseJson(Handle<String> script, UC16CharacterStream* source); - // Parse a single JSON value from input (grammar production JSONValue). - // A JSON value is either a (double-quoted) string literal, a number literal, - // one of "true", "false", or "null", or an object or array literal. - Handle<Object> ParseJsonValue(); - // Parse a JSON object literal (grammar production JSONObject). - // An object literal is a squiggly-braced and comma separated sequence - // (possibly empty) of key/value pairs, where the key is a JSON string - // literal, the value is a JSON value, and the two are separated by a colon. - // A JSON array dosn't allow numbers and identifiers as keys, like a - // JavaScript array. - Handle<Object> ParseJsonObject(); - // Parses a JSON array literal (grammar production JSONArray). An array - // literal is a square-bracketed and comma separated sequence (possibly empty) - // of JSON values. - // A JSON array doesn't allow leaving out values from the sequence, nor does - // it allow a terminal comma, like a JavaScript array does. - Handle<Object> ParseJsonArray(); - - // Mark that a parsing error has happened at the current token, and - // return a null handle. Primarily for readability. - Handle<Object> ReportUnexpectedToken() { return Handle<Object>::null(); } - // Converts the currently parsed literal to a JavaScript String. - Handle<String> GetString(); - - JsonScanner scanner_; - bool stack_overflow_; -}; } } // namespace v8::internal #endif // V8_PARSER_H_ |