1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef V8_PREPARSE_DATA_H_
6 #define V8_PREPARSE_DATA_H_
8 #include "src/allocation.h"
9 #include "src/hashmap.h"
10 #include "src/preparse-data-format.h"
11 #include "src/utils-inl.h"
19 // Abstract interface for preparse data recorder.
20 class ParserRecorder {
23 virtual ~ParserRecorder() { }
25 // Logs the scope and some details of a function literal in the source.
26 virtual void LogFunction(int start, int end, int literals, int properties,
27 LanguageMode language_mode,
28 bool uses_super_property) = 0;
30 // Logs an error message and marks the log as containing an error.
31 // Further logging will be ignored, and ExtractData will return a vector
32 // representing the error only.
33 virtual void LogMessage(int start,
36 const char* argument_opt,
37 bool is_reference_error) = 0;
39 DISALLOW_COPY_AND_ASSIGN(ParserRecorder);
43 class SingletonLogger : public ParserRecorder {
46 : has_error_(false), start_(-1), end_(-1), is_reference_error_(false) {}
47 virtual ~SingletonLogger() {}
49 void Reset() { has_error_ = false; }
51 virtual void LogFunction(int start, int end, int literals, int properties,
52 LanguageMode language_mode,
53 bool scope_uses_super_property) {
58 properties_ = properties;
59 language_mode_ = language_mode;
60 scope_uses_super_property_ = scope_uses_super_property;
63 // Logs an error message and marks the log as containing an error.
64 // Further logging will be ignored, and ExtractData will return a vector
65 // representing the error only.
66 virtual void LogMessage(int start,
69 const char* argument_opt,
70 bool is_reference_error) {
71 if (has_error_) return;
76 argument_opt_ = argument_opt;
77 is_reference_error_ = is_reference_error;
80 bool has_error() const { return has_error_; }
82 int start() const { return start_; }
83 int end() const { return end_; }
84 int literals() const {
88 int properties() const {
92 LanguageMode language_mode() const {
94 return language_mode_;
96 bool scope_uses_super_property() const {
98 return scope_uses_super_property_;
100 int is_reference_error() const { return is_reference_error_; }
101 const char* message() {
105 const char* argument_opt() const {
107 return argument_opt_;
114 // For function entries.
117 LanguageMode language_mode_;
118 bool scope_uses_super_property_;
119 // For error messages.
120 const char* message_;
121 const char* argument_opt_;
122 bool is_reference_error_;
126 class CompleteParserRecorder : public ParserRecorder {
130 Vector<const byte> literal_bytes;
133 CompleteParserRecorder();
134 virtual ~CompleteParserRecorder() {}
136 virtual void LogFunction(int start, int end, int literals, int properties,
137 LanguageMode language_mode,
138 bool scope_uses_super_property) {
139 function_store_.Add(start);
140 function_store_.Add(end);
141 function_store_.Add(literals);
142 function_store_.Add(properties);
143 function_store_.Add(language_mode);
144 function_store_.Add(scope_uses_super_property);
147 // Logs an error message and marks the log as containing an error.
148 // Further logging will be ignored, and ExtractData will return a vector
149 // representing the error only.
150 virtual void LogMessage(int start,
153 const char* argument_opt,
154 bool is_reference_error_);
155 ScriptData* GetScriptData();
158 return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]);
160 Vector<unsigned> ErrorMessageData() {
162 return function_store_.ToVector();
166 void WriteString(Vector<const char> str);
168 // Write a non-negative number to the symbol store.
169 void WriteNumber(int number);
171 Collector<unsigned> function_store_;
172 unsigned preamble_[PreparseDataConstants::kHeaderSize];
180 } } // namespace v8::internal.
182 #endif // V8_PREPARSE_DATA_H_