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,
30 StrictMode strict_mode) = 0;
32 // Logs an error message and marks the log as containing an error.
33 // Further logging will be ignored, and ExtractData will return a vector
34 // representing the error only.
35 virtual void LogMessage(int start,
38 const char* argument_opt,
39 bool is_reference_error) = 0;
41 DISALLOW_COPY_AND_ASSIGN(ParserRecorder);
45 class SingletonLogger : public ParserRecorder {
48 : has_error_(false), start_(-1), end_(-1), is_reference_error_(false) {}
49 virtual ~SingletonLogger() {}
51 void Reset() { has_error_ = false; }
53 virtual void LogFunction(int start,
57 StrictMode strict_mode) {
62 properties_ = properties;
63 strict_mode_ = strict_mode;
66 // Logs an error message and marks the log as containing an error.
67 // Further logging will be ignored, and ExtractData will return a vector
68 // representing the error only.
69 virtual void LogMessage(int start,
72 const char* argument_opt,
73 bool is_reference_error) {
74 if (has_error_) return;
79 argument_opt_ = argument_opt;
80 is_reference_error_ = is_reference_error;
83 bool has_error() const { return has_error_; }
85 int start() const { return start_; }
86 int end() const { return end_; }
87 int literals() const {
91 int properties() const {
95 StrictMode strict_mode() const {
99 int is_reference_error() const { return is_reference_error_; }
100 const char* message() {
104 const char* argument_opt() const {
106 return argument_opt_;
113 // For function entries.
116 StrictMode strict_mode_;
117 // For error messages.
118 const char* message_;
119 const char* argument_opt_;
120 bool is_reference_error_;
124 class CompleteParserRecorder : public ParserRecorder {
128 Vector<const byte> literal_bytes;
131 CompleteParserRecorder();
132 virtual ~CompleteParserRecorder() {}
134 virtual void LogFunction(int start,
138 StrictMode strict_mode) {
139 function_store_.Add(start);
140 function_store_.Add(end);
141 function_store_.Add(literals);
142 function_store_.Add(properties);
143 function_store_.Add(strict_mode);
146 // Logs an error message and marks the log as containing an error.
147 // Further logging will be ignored, and ExtractData will return a vector
148 // representing the error only.
149 virtual void LogMessage(int start,
152 const char* argument_opt,
153 bool is_reference_error_);
154 ScriptData* GetScriptData();
157 return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]);
159 Vector<unsigned> ErrorMessageData() {
161 return function_store_.ToVector();
165 void WriteString(Vector<const char> str);
167 // Write a non-negative number to the symbol store.
168 void WriteNumber(int number);
170 Collector<unsigned> function_store_;
171 unsigned preamble_[PreparseDataConstants::kHeaderSize];
179 } } // namespace v8::internal.
181 #endif // V8_PREPARSE_DATA_H_