Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(741)

Unified Diff: src/parser.h

Issue 376223002: Refactor ScriptData class for cached compile data. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/mksnapshot.cc ('k') | src/parser.cc » ('j') | src/preparse-data.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.h
diff --git a/src/parser.h b/src/parser.h
index ac276645a1dce197b1c7470d1535a726c01b97a8..1537e5d69dfa132e625ffdb070d40f81cd79560e 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -59,73 +59,39 @@ 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();
+
+ 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();
+ unsigned Version();
+ int FunctionsSize();
+ 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_;
+ 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 +612,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 +762,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_;
« no previous file with comments | « src/mksnapshot.cc ('k') | src/parser.cc » ('j') | src/preparse-data.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698