Line data Source code
1 : // Copyright 2018 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.
4 :
5 : #ifndef V8_AST_SOURCE_RANGE_AST_VISITOR_H_
6 : #define V8_AST_SOURCE_RANGE_AST_VISITOR_H_
7 :
8 : #include <unordered_set>
9 :
10 : #include "src/ast/ast-traversal-visitor.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 :
15 : class SourceRangeMap;
16 :
17 : // Post-processes generated source ranges while the AST structure still exists.
18 : //
19 : // In particular, SourceRangeAstVisitor
20 : //
21 : // 1. deduplicates continuation source ranges, only keeping the outermost one.
22 : // See also: https://crbug.com/v8/8539.
23 : //
24 : // 2. removes the source range associated with the final statement in a block
25 : // or function body if the parent itself has a source range associated with it.
26 : // See also: https://crbug.com/v8/8381.
27 676 : class SourceRangeAstVisitor final
28 : : public AstTraversalVisitor<SourceRangeAstVisitor> {
29 : public:
30 : SourceRangeAstVisitor(uintptr_t stack_limit, Expression* root,
31 : SourceRangeMap* source_range_map);
32 :
33 : private:
34 : friend class AstTraversalVisitor<SourceRangeAstVisitor>;
35 :
36 : void VisitBlock(Block* stmt);
37 : void VisitFunctionLiteral(FunctionLiteral* expr);
38 : bool VisitNode(AstNode* node);
39 :
40 : void MaybeRemoveLastContinuationRange(ZonePtrList<Statement>* stmts);
41 :
42 : SourceRangeMap* source_range_map_ = nullptr;
43 : std::unordered_set<int> continuation_positions_;
44 : };
45 :
46 : } // namespace internal
47 : } // namespace v8
48 :
49 : #endif // V8_AST_SOURCE_RANGE_AST_VISITOR_H_
|