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

Side by Side Diff: src/parsing/expression-classifier.h

Issue 2255353002: [parser] Allow duplicate __proto__ keys in patterns (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: review comments Created 4 years, 4 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 | « no previous file | src/parsing/parser-base.h » ('j') | src/parsing/parser-base.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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_PARSING_EXPRESSION_CLASSIFIER_H 5 #ifndef V8_PARSING_EXPRESSION_CLASSIFIER_H
6 #define V8_PARSING_EXPRESSION_CLASSIFIER_H 6 #define V8_PARSING_EXPRESSION_CLASSIFIER_H
7 7
8 #include "src/messages.h" 8 #include "src/messages.h"
9 #include "src/parsing/scanner.h" 9 #include "src/parsing/scanner.h"
10 #include "src/parsing/token.h" 10 #include "src/parsing/token.h"
11 11
12 namespace v8 { 12 namespace v8 {
13 namespace internal { 13 namespace internal {
14 14
15 15
16 #define ERROR_CODES(T) \ 16 #define ERROR_CODES(T) \
17 T(ExpressionProduction, 0) \ 17 T(ExpressionProduction, 0) \
18 T(FormalParameterInitializerProduction, 1) \ 18 T(FormalParameterInitializerProduction, 1) \
19 T(BindingPatternProduction, 2) \ 19 T(BindingPatternProduction, 2) \
20 T(AssignmentPatternProduction, 3) \ 20 T(AssignmentPatternProduction, 3) \
21 T(DistinctFormalParametersProduction, 4) \ 21 T(DistinctFormalParametersProduction, 4) \
22 T(StrictModeFormalParametersProduction, 5) \ 22 T(StrictModeFormalParametersProduction, 5) \
23 T(ArrowFormalParametersProduction, 6) \ 23 T(ArrowFormalParametersProduction, 6) \
24 T(LetPatternProduction, 7) \ 24 T(LetPatternProduction, 7) \
25 T(CoverInitializedNameProduction, 8) \ 25 T(CoverInitializedNameProduction, 8) \
26 T(TailCallExpressionProduction, 9) \ 26 T(TailCallExpressionProduction, 9) \
27 T(AsyncArrowFormalParametersProduction, 10) \ 27 T(AsyncArrowFormalParametersProduction, 10) \
28 T(AsyncBindingPatternProduction, 11) 28 T(AsyncBindingPatternProduction, 11) \
29 T(AnnexBDuplicateProtoProduction, 12)
adamk 2016/08/19 20:17:07 Let's just call this DuplicateProtoProduction.
gsathya 2016/08/19 23:22:57 Changed to ObjectLiteralProduction as discussed of
29 30
30 31
31 template <typename Traits> 32 template <typename Traits>
32 class ExpressionClassifier { 33 class ExpressionClassifier {
33 public: 34 public:
34 enum ErrorKind : unsigned { 35 enum ErrorKind : unsigned {
35 #define DEFINE_ERROR_KIND(NAME, CODE) k##NAME = CODE, 36 #define DEFINE_ERROR_KIND(NAME, CODE) k##NAME = CODE,
36 ERROR_CODES(DEFINE_ERROR_KIND) 37 ERROR_CODES(DEFINE_ERROR_KIND)
37 #undef DEFINE_ERROR_KIND 38 #undef DEFINE_ERROR_KIND
38 kUnusedError = 15 // Larger than error codes; should fit in 4 bits 39 kUnusedError = 15 // Larger than error codes; should fit in 4 bits
(...skipping 28 matching lines...) Expand all
67 (ExpressionProduction | FormalParameterInitializerProduction | 68 (ExpressionProduction | FormalParameterInitializerProduction |
68 TailCallExpressionProduction), 69 TailCallExpressionProduction),
69 PatternProductions = 70 PatternProductions =
70 (BindingPatternProduction | AssignmentPatternProduction | 71 (BindingPatternProduction | AssignmentPatternProduction |
71 LetPatternProduction | AsyncBindingPatternProduction), 72 LetPatternProduction | AsyncBindingPatternProduction),
72 FormalParametersProductions = (DistinctFormalParametersProduction | 73 FormalParametersProductions = (DistinctFormalParametersProduction |
73 StrictModeFormalParametersProduction), 74 StrictModeFormalParametersProduction),
74 AllProductions = 75 AllProductions =
75 (ExpressionProductions | PatternProductions | 76 (ExpressionProductions | PatternProductions |
76 FormalParametersProductions | ArrowFormalParametersProduction | 77 FormalParametersProductions | ArrowFormalParametersProduction |
77 CoverInitializedNameProduction | AsyncArrowFormalParametersProduction) 78 CoverInitializedNameProduction | AsyncArrowFormalParametersProduction |
79 AnnexBDuplicateProtoProduction)
78 }; 80 };
79 81
80 enum FunctionProperties : unsigned { 82 enum FunctionProperties : unsigned {
81 NonSimpleParameter = 1 << 0 83 NonSimpleParameter = 1 << 0
82 }; 84 };
83 85
84 explicit ExpressionClassifier(const Traits* t) 86 explicit ExpressionClassifier(const Traits* t)
85 : zone_(t->zone()), 87 : zone_(t->zone()),
86 non_patterns_to_rewrite_(t->GetNonPatternList()), 88 non_patterns_to_rewrite_(t->GetNonPatternList()),
87 reported_errors_(t->GetReportedErrorList()), 89 reported_errors_(t->GetReportedErrorList()),
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 V8_INLINE const Error& cover_initialized_name_error() const { 196 V8_INLINE const Error& cover_initialized_name_error() const {
195 return reported_error(kCoverInitializedNameProduction); 197 return reported_error(kCoverInitializedNameProduction);
196 } 198 }
197 199
198 V8_INLINE bool has_tail_call_expression() const { 200 V8_INLINE bool has_tail_call_expression() const {
199 return !is_valid(TailCallExpressionProduction); 201 return !is_valid(TailCallExpressionProduction);
200 } 202 }
201 V8_INLINE const Error& tail_call_expression_error() const { 203 V8_INLINE const Error& tail_call_expression_error() const {
202 return reported_error(kTailCallExpressionProduction); 204 return reported_error(kTailCallExpressionProduction);
203 } 205 }
206
207 V8_INLINE bool has_annexb_duplicate_proto() const {
208 return !is_valid(AnnexBDuplicateProtoProduction);
209 }
210
211 V8_INLINE const Error& annexb_duplicate_proto_error() const {
212 return reported_error(kAnnexBDuplicateProtoProduction);
213 }
214
204 V8_INLINE const Error& async_arrow_formal_parameters_error() const { 215 V8_INLINE const Error& async_arrow_formal_parameters_error() const {
205 return reported_error(kAsyncArrowFormalParametersProduction); 216 return reported_error(kAsyncArrowFormalParametersProduction);
206 } 217 }
207 218
208 V8_INLINE const Error& async_binding_pattern_error() const { 219 V8_INLINE const Error& async_binding_pattern_error() const {
209 return reported_error(kAsyncBindingPatternProduction); 220 return reported_error(kAsyncBindingPatternProduction);
210 } 221 }
211 222
212 V8_INLINE bool is_simple_parameter_list() const { 223 V8_INLINE bool is_simple_parameter_list() const {
213 return !(function_properties_ & NonSimpleParameter); 224 return !(function_properties_ & NonSimpleParameter);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 } 334 }
324 335
325 void RecordTailCallExpressionError(const Scanner::Location& loc, 336 void RecordTailCallExpressionError(const Scanner::Location& loc,
326 MessageTemplate::Template message, 337 MessageTemplate::Template message,
327 const char* arg = nullptr) { 338 const char* arg = nullptr) {
328 if (has_tail_call_expression()) return; 339 if (has_tail_call_expression()) return;
329 invalid_productions_ |= TailCallExpressionProduction; 340 invalid_productions_ |= TailCallExpressionProduction;
330 Add(Error(loc, message, kTailCallExpressionProduction, arg)); 341 Add(Error(loc, message, kTailCallExpressionProduction, arg));
331 } 342 }
332 343
344 void RecordAnnexBDuplicateProtoError(const Scanner::Location& loc,
345 MessageTemplate::Template message,
346 const char* arg = nullptr) {
347 if (has_annexb_duplicate_proto()) return;
348 invalid_productions_ |= AnnexBDuplicateProtoProduction;
349 Add(Error(loc, message, kAnnexBDuplicateProtoProduction, arg));
350 }
351
333 void ForgiveCoverInitializedNameError() { 352 void ForgiveCoverInitializedNameError() {
334 if (!(invalid_productions_ & CoverInitializedNameProduction)) return; 353 if (!(invalid_productions_ & CoverInitializedNameProduction)) return;
335 Error& e = reported_error(kCoverInitializedNameProduction); 354 Error& e = reported_error(kCoverInitializedNameProduction);
336 e.kind = kUnusedError; 355 e.kind = kUnusedError;
337 invalid_productions_ &= ~CoverInitializedNameProduction; 356 invalid_productions_ &= ~CoverInitializedNameProduction;
338 } 357 }
339 358
340 void ForgiveAssignmentPatternError() { 359 void ForgiveAssignmentPatternError() {
341 if (!(invalid_productions_ & AssignmentPatternProduction)) return; 360 if (!(invalid_productions_ & AssignmentPatternProduction)) return;
342 Error& e = reported_error(kAssignmentPatternProduction); 361 Error& e = reported_error(kAssignmentPatternProduction);
343 e.kind = kUnusedError; 362 e.kind = kUnusedError;
344 invalid_productions_ &= ~AssignmentPatternProduction; 363 invalid_productions_ &= ~AssignmentPatternProduction;
345 } 364 }
346 365
366 void ForgiveAnnexBDuplicateProtoError() {
367 if (!(invalid_productions_ & AnnexBDuplicateProtoProduction)) return;
368 Error& e = reported_error(kAnnexBDuplicateProtoProduction);
369 e.kind = kUnusedError;
370 invalid_productions_ &= ~AnnexBDuplicateProtoProduction;
371 }
372
347 void Accumulate(ExpressionClassifier* inner, unsigned productions, 373 void Accumulate(ExpressionClassifier* inner, unsigned productions,
348 bool merge_non_patterns = true) { 374 bool merge_non_patterns = true) {
349 DCHECK_EQ(inner->reported_errors_, reported_errors_); 375 DCHECK_EQ(inner->reported_errors_, reported_errors_);
350 DCHECK_EQ(inner->reported_errors_begin_, reported_errors_end_); 376 DCHECK_EQ(inner->reported_errors_begin_, reported_errors_end_);
351 DCHECK_EQ(inner->reported_errors_end_, reported_errors_->length()); 377 DCHECK_EQ(inner->reported_errors_end_, reported_errors_->length());
352 if (merge_non_patterns) MergeNonPatterns(inner); 378 if (merge_non_patterns) MergeNonPatterns(inner);
353 // Propagate errors from inner, but don't overwrite already recorded 379 // Propagate errors from inner, but don't overwrite already recorded
354 // errors. 380 // errors.
355 unsigned non_arrow_inner_invalid_productions = 381 unsigned non_arrow_inner_invalid_productions =
356 inner->invalid_productions_ & ~ArrowFormalParametersProduction; 382 inner->invalid_productions_ & ~ArrowFormalParametersProduction;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 }; 518 };
493 519
494 520
495 #undef ERROR_CODES 521 #undef ERROR_CODES
496 522
497 523
498 } // namespace internal 524 } // namespace internal
499 } // namespace v8 525 } // namespace v8
500 526
501 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H 527 #endif // V8_PARSING_EXPRESSION_CLASSIFIER_H
OLDNEW
« no previous file with comments | « no previous file | src/parsing/parser-base.h » ('j') | src/parsing/parser-base.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698