Chromium Code Reviews| Index: src/parser.h |
| diff --git a/src/parser.h b/src/parser.h |
| index ac276645a1dce197b1c7470d1535a726c01b97a8..4fabd0f57444280cf1f1d0e458e5f7dce41ff63d 100644 |
| --- a/src/parser.h |
| +++ b/src/parser.h |
| @@ -59,73 +59,41 @@ class FunctionEntry BASE_EMBEDDED { |
| }; |
| -class ScriptData { |
| +// Wrapper around ScriptData to provide parser-specific functionality. |
| +class ParseData { |
| public: |
| - explicit ScriptData(Vector<unsigned> store) |
| - : store_(store), |
| - owns_store_(true) { } |
| - |
| - ScriptData(Vector<unsigned> store, bool owns_store) |
| - : store_(store), |
| - owns_store_(owns_store) { } |
| - |
| - // The created ScriptData won't take ownership of the data. If the alignment |
| - // is not correct, this will copy the data (and the created ScriptData will |
| - // take ownership of the copy). |
| - static ScriptData* New(const char* data, int length, bool owns_store = false); |
| - |
| - virtual ~ScriptData(); |
| - virtual int Length(); |
| - virtual const char* Data(); |
| - virtual bool HasError(); |
| - |
| + explicit ParseData(ScriptData* script_data) : script_data_(script_data) { |
| + CHECK(IsAligned(script_data->length(), sizeof(unsigned))); |
| + CHECK(IsSane()); |
| + } |
| void Initialize(); |
| - void ReadNextSymbolPosition(); |
| - |
| FunctionEntry GetFunctionEntry(int start); |
| - int GetSymbolIdentifier(); |
| - bool SanityCheck(); |
| - |
| - Scanner::Location MessageLocation() const; |
| - bool IsReferenceError() const; |
| - const char* BuildMessage() const; |
| - const char* BuildArg() const; |
| - |
| - int function_count() { |
| - int functions_size = |
| - static_cast<int>(store_[PreparseDataConstants::kFunctionsSizeOffset]); |
| - if (functions_size < 0) return 0; |
| - if (functions_size % FunctionEntry::kSize != 0) return 0; |
| - return functions_size / FunctionEntry::kSize; |
| + int FunctionCount(); |
| + |
| + bool HasError() const; |
| + |
| + unsigned* Data() { // Writable data as unsigned int array. |
| + return reinterpret_cast<unsigned*>(const_cast<byte*>(script_data_->data())); |
| } |
| - // The following functions should only be called if SanityCheck has |
| - // returned true. |
| - bool has_error() { return store_[PreparseDataConstants::kHasErrorOffset]; } |
| - unsigned magic() { return store_[PreparseDataConstants::kMagicOffset]; } |
| - unsigned version() { return store_[PreparseDataConstants::kVersionOffset]; } |
| private: |
| - // Disable copying and assigning; because of owns_store they won't be correct. |
| - ScriptData(const ScriptData&); |
| - ScriptData& operator=(const ScriptData&); |
| - |
| - friend class v8::ScriptCompiler; |
| - Vector<unsigned> store_; |
| - unsigned char* symbol_data_; |
| - unsigned char* symbol_data_end_; |
| - int function_index_; |
| - bool owns_store_; |
| + bool IsSane(); |
| + unsigned Magic() const; |
| + unsigned Version() const; |
| + int FunctionsSize() const; |
| + int Length() const { |
| + // Script data length is already checked to be a multiple of unsigned size. |
| + return script_data_->length() / sizeof(unsigned); |
| + } |
| - unsigned Read(int position) const; |
| - unsigned* ReadAddress(int position) const; |
| - // Reads a number from the current symbols |
| - int ReadNumber(byte** source); |
| + ScriptData* script_data_; |
| + byte* symbol_data_; |
|
marja
2014/07/10 08:48:10
symbol_data_ and symbol_data_end_ are now unnecess
Yang
2014/07/10 10:27:58
Done.
|
| + byte* symbol_data_end_; |
| + int function_index_; |
| - // Read strings written by ParserRecorder::WriteString. |
| - static const char* ReadString(unsigned* start, int* chars); |
| + DISALLOW_COPY_AND_ASSIGN(ParseData); |
| }; |
| - |
| // ---------------------------------------------------------------------------- |
| // REGEXP PARSING |
| @@ -646,23 +614,10 @@ class Parser : public ParserBase<ParserTraits> { |
| FunctionLiteral* DoParseProgram(CompilationInfo* info, |
| Handle<String> source); |
| - // Report syntax error |
| - void ReportInvalidCachedData(const AstRawString* name, bool* ok); |
| - |
| - void SetCachedData(ScriptData** data, |
| - CachedDataMode cached_data_mode) { |
| - cached_data_mode_ = cached_data_mode; |
| - if (cached_data_mode == NO_CACHED_DATA) { |
| - cached_data_ = NULL; |
| - } else { |
| - ASSERT(data != NULL); |
| - cached_data_ = data; |
| - } |
| - } |
| + void SetCachedData(); |
| bool inside_with() const { return scope_->inside_with(); } |
| - ScriptData** cached_data() const { return cached_data_; } |
| - CachedDataMode cached_data_mode() const { return cached_data_mode_; } |
| + CachedDataMode cached_data_mode() const { return info_->cached_data_mode(); } |
| Scope* DeclarationScope(VariableMode mode) { |
| return IsLexicalVariableMode(mode) |
| ? scope_ : scope_->DeclarationScope(); |
| @@ -809,7 +764,7 @@ class Parser : public ParserBase<ParserTraits> { |
| PreParser* reusable_preparser_; |
| Scope* original_scope_; // for ES5 function declarations in sloppy eval |
| Target* target_stack_; // for break, continue statements |
| - ScriptData** cached_data_; |
| + ParseData* cached_parse_data_; |
| CachedDataMode cached_data_mode_; |
| AstValueFactory* ast_value_factory_; |