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

Side by Side Diff: src/preparse-data.h

Issue 939303002: Replace is_reference_error bool argument with ParseErrorType enum (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Marja comments addressed Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « src/parser.cc ('k') | src/preparse-data.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_PREPARSE_DATA_H_ 5 #ifndef V8_PREPARSE_DATA_H_
6 #define V8_PREPARSE_DATA_H_ 6 #define V8_PREPARSE_DATA_H_
7 7
8 #include "src/allocation.h" 8 #include "src/allocation.h"
9 #include "src/hashmap.h" 9 #include "src/hashmap.h"
10 #include "src/preparse-data-format.h" 10 #include "src/preparse-data-format.h"
(...skipping 12 matching lines...) Expand all
23 virtual ~ParserRecorder() { } 23 virtual ~ParserRecorder() { }
24 24
25 // Logs the scope and some details of a function literal in the source. 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, 26 virtual void LogFunction(int start, int end, int literals, int properties,
27 LanguageMode language_mode, 27 LanguageMode language_mode,
28 bool uses_super_property) = 0; 28 bool uses_super_property) = 0;
29 29
30 // Logs an error message and marks the log as containing an error. 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 31 // Further logging will be ignored, and ExtractData will return a vector
32 // representing the error only. 32 // representing the error only.
33 virtual void LogMessage(int start, 33 virtual void LogMessage(int start, int end, const char* message,
34 int end,
35 const char* message,
36 const char* argument_opt, 34 const char* argument_opt,
37 bool is_reference_error) = 0; 35 ParseErrorType error_type) = 0;
36
38 private: 37 private:
39 DISALLOW_COPY_AND_ASSIGN(ParserRecorder); 38 DISALLOW_COPY_AND_ASSIGN(ParserRecorder);
40 }; 39 };
41 40
42 41
43 class SingletonLogger : public ParserRecorder { 42 class SingletonLogger : public ParserRecorder {
44 public: 43 public:
45 SingletonLogger() 44 SingletonLogger()
46 : has_error_(false), start_(-1), end_(-1), is_reference_error_(false) {} 45 : has_error_(false), start_(-1), end_(-1), error_type_(kSyntaxError) {}
47 virtual ~SingletonLogger() {} 46 virtual ~SingletonLogger() {}
48 47
49 void Reset() { has_error_ = false; } 48 void Reset() { has_error_ = false; }
50 49
51 virtual void LogFunction(int start, int end, int literals, int properties, 50 virtual void LogFunction(int start, int end, int literals, int properties,
52 LanguageMode language_mode, 51 LanguageMode language_mode,
53 bool scope_uses_super_property) { 52 bool scope_uses_super_property) {
54 DCHECK(!has_error_); 53 DCHECK(!has_error_);
55 start_ = start; 54 start_ = start;
56 end_ = end; 55 end_ = end;
57 literals_ = literals; 56 literals_ = literals;
58 properties_ = properties; 57 properties_ = properties;
59 language_mode_ = language_mode; 58 language_mode_ = language_mode;
60 scope_uses_super_property_ = scope_uses_super_property; 59 scope_uses_super_property_ = scope_uses_super_property;
61 } 60 }
62 61
63 // Logs an error message and marks the log as containing an error. 62 // Logs an error message and marks the log as containing an error.
64 // Further logging will be ignored, and ExtractData will return a vector 63 // Further logging will be ignored, and ExtractData will return a vector
65 // representing the error only. 64 // representing the error only.
66 virtual void LogMessage(int start, 65 virtual void LogMessage(int start, int end, const char* message,
67 int end, 66 const char* argument_opt, ParseErrorType error_type) {
68 const char* message,
69 const char* argument_opt,
70 bool is_reference_error) {
71 if (has_error_) return; 67 if (has_error_) return;
72 has_error_ = true; 68 has_error_ = true;
73 start_ = start; 69 start_ = start;
74 end_ = end; 70 end_ = end;
75 message_ = message; 71 message_ = message;
76 argument_opt_ = argument_opt; 72 argument_opt_ = argument_opt;
77 is_reference_error_ = is_reference_error; 73 error_type_ = error_type;
78 } 74 }
79 75
80 bool has_error() const { return has_error_; } 76 bool has_error() const { return has_error_; }
81 77
82 int start() const { return start_; } 78 int start() const { return start_; }
83 int end() const { return end_; } 79 int end() const { return end_; }
84 int literals() const { 80 int literals() const {
85 DCHECK(!has_error_); 81 DCHECK(!has_error_);
86 return literals_; 82 return literals_;
87 } 83 }
88 int properties() const { 84 int properties() const {
89 DCHECK(!has_error_); 85 DCHECK(!has_error_);
90 return properties_; 86 return properties_;
91 } 87 }
92 LanguageMode language_mode() const { 88 LanguageMode language_mode() const {
93 DCHECK(!has_error_); 89 DCHECK(!has_error_);
94 return language_mode_; 90 return language_mode_;
95 } 91 }
96 bool scope_uses_super_property() const { 92 bool scope_uses_super_property() const {
97 DCHECK(!has_error_); 93 DCHECK(!has_error_);
98 return scope_uses_super_property_; 94 return scope_uses_super_property_;
99 } 95 }
100 int is_reference_error() const { return is_reference_error_; } 96 ParseErrorType error_type() const {
97 DCHECK(has_error_);
98 return error_type_;
99 }
101 const char* message() { 100 const char* message() {
102 DCHECK(has_error_); 101 DCHECK(has_error_);
103 return message_; 102 return message_;
104 } 103 }
105 const char* argument_opt() const { 104 const char* argument_opt() const {
106 DCHECK(has_error_); 105 DCHECK(has_error_);
107 return argument_opt_; 106 return argument_opt_;
108 } 107 }
109 108
110 private: 109 private:
111 bool has_error_; 110 bool has_error_;
112 int start_; 111 int start_;
113 int end_; 112 int end_;
114 // For function entries. 113 // For function entries.
115 int literals_; 114 int literals_;
116 int properties_; 115 int properties_;
117 LanguageMode language_mode_; 116 LanguageMode language_mode_;
118 bool scope_uses_super_property_; 117 bool scope_uses_super_property_;
119 // For error messages. 118 // For error messages.
120 const char* message_; 119 const char* message_;
121 const char* argument_opt_; 120 const char* argument_opt_;
122 bool is_reference_error_; 121 ParseErrorType error_type_;
123 }; 122 };
124 123
125 124
126 class CompleteParserRecorder : public ParserRecorder { 125 class CompleteParserRecorder : public ParserRecorder {
127 public: 126 public:
128 struct Key { 127 struct Key {
129 bool is_one_byte; 128 bool is_one_byte;
130 Vector<const byte> literal_bytes; 129 Vector<const byte> literal_bytes;
131 }; 130 };
132 131
133 CompleteParserRecorder(); 132 CompleteParserRecorder();
134 virtual ~CompleteParserRecorder() {} 133 virtual ~CompleteParserRecorder() {}
135 134
136 virtual void LogFunction(int start, int end, int literals, int properties, 135 virtual void LogFunction(int start, int end, int literals, int properties,
137 LanguageMode language_mode, 136 LanguageMode language_mode,
138 bool scope_uses_super_property) { 137 bool scope_uses_super_property) {
139 function_store_.Add(start); 138 function_store_.Add(start);
140 function_store_.Add(end); 139 function_store_.Add(end);
141 function_store_.Add(literals); 140 function_store_.Add(literals);
142 function_store_.Add(properties); 141 function_store_.Add(properties);
143 function_store_.Add(language_mode); 142 function_store_.Add(language_mode);
144 function_store_.Add(scope_uses_super_property); 143 function_store_.Add(scope_uses_super_property);
145 } 144 }
146 145
147 // Logs an error message and marks the log as containing an error. 146 // Logs an error message and marks the log as containing an error.
148 // Further logging will be ignored, and ExtractData will return a vector 147 // Further logging will be ignored, and ExtractData will return a vector
149 // representing the error only. 148 // representing the error only.
150 virtual void LogMessage(int start, 149 virtual void LogMessage(int start, int end, const char* message,
151 int end, 150 const char* argument_opt, ParseErrorType error_type);
152 const char* message,
153 const char* argument_opt,
154 bool is_reference_error_);
155 ScriptData* GetScriptData(); 151 ScriptData* GetScriptData();
156 152
157 bool HasError() { 153 bool HasError() {
158 return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]); 154 return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]);
159 } 155 }
160 Vector<unsigned> ErrorMessageData() { 156 Vector<unsigned> ErrorMessageData() {
161 DCHECK(HasError()); 157 DCHECK(HasError());
162 return function_store_.ToVector(); 158 return function_store_.ToVector();
163 } 159 }
164 160
165 private: 161 private:
166 void WriteString(Vector<const char> str); 162 void WriteString(Vector<const char> str);
167 163
168 // Write a non-negative number to the symbol store. 164 // Write a non-negative number to the symbol store.
169 void WriteNumber(int number); 165 void WriteNumber(int number);
170 166
171 Collector<unsigned> function_store_; 167 Collector<unsigned> function_store_;
172 unsigned preamble_[PreparseDataConstants::kHeaderSize]; 168 unsigned preamble_[PreparseDataConstants::kHeaderSize];
173 169
174 #ifdef DEBUG 170 #ifdef DEBUG
175 int prev_start_; 171 int prev_start_;
176 #endif 172 #endif
177 }; 173 };
178 174
179 175
180 } } // namespace v8::internal. 176 } } // namespace v8::internal.
181 177
182 #endif // V8_PREPARSE_DATA_H_ 178 #endif // V8_PREPARSE_DATA_H_
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/preparse-data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698