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 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 VisitSwitchStatement(SwitchStatement* stmt); 38 void VisitFunctionLiteral(FunctionLiteral* expr); 39 bool VisitNode(AstNode* node); 40 void VisitTryCatchStatement(TryCatchStatement* stmt); 41 void VisitTryFinallyStatement(TryFinallyStatement* stmt); 42 43 void MaybeRemoveContinuationRange(Statement* last_statement); 44 void MaybeRemoveLastContinuationRange(ZonePtrList<Statement>* stmts); 45 void MaybeRemoveContinuationRangeOfAsyncReturn(TryCatchStatement* stmt); 46 47 SourceRangeMap* source_range_map_ = nullptr; 48 std::unordered_set<int> continuation_positions_; 49 }; 50 51 } // namespace internal 52 } // namespace v8 53 54 #endif // V8_AST_SOURCE_RANGE_AST_VISITOR_H_ 55