11cb0ef41Sopenharmony_ci// Copyright 2018 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_AST_SOURCE_RANGE_AST_VISITOR_H_
61cb0ef41Sopenharmony_ci#define V8_AST_SOURCE_RANGE_AST_VISITOR_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include <unordered_set>
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci#include "src/ast/ast-traversal-visitor.h"
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cinamespace v8 {
131cb0ef41Sopenharmony_cinamespace internal {
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciclass SourceRangeMap;
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci// Post-processes generated source ranges while the AST structure still exists.
181cb0ef41Sopenharmony_ci//
191cb0ef41Sopenharmony_ci// In particular, SourceRangeAstVisitor
201cb0ef41Sopenharmony_ci//
211cb0ef41Sopenharmony_ci// 1. deduplicates continuation source ranges, only keeping the outermost one.
221cb0ef41Sopenharmony_ci// See also: https://crbug.com/v8/8539.
231cb0ef41Sopenharmony_ci//
241cb0ef41Sopenharmony_ci// 2. removes the source range associated with the final statement in a block
251cb0ef41Sopenharmony_ci// or function body if the parent itself has a source range associated with it.
261cb0ef41Sopenharmony_ci// See also: https://crbug.com/v8/8381.
271cb0ef41Sopenharmony_ciclass SourceRangeAstVisitor final
281cb0ef41Sopenharmony_ci    : public AstTraversalVisitor<SourceRangeAstVisitor> {
291cb0ef41Sopenharmony_ci public:
301cb0ef41Sopenharmony_ci  SourceRangeAstVisitor(uintptr_t stack_limit, Expression* root,
311cb0ef41Sopenharmony_ci                        SourceRangeMap* source_range_map);
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci private:
341cb0ef41Sopenharmony_ci  friend class AstTraversalVisitor<SourceRangeAstVisitor>;
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  void VisitBlock(Block* stmt);
371cb0ef41Sopenharmony_ci  void VisitSwitchStatement(SwitchStatement* stmt);
381cb0ef41Sopenharmony_ci  void VisitFunctionLiteral(FunctionLiteral* expr);
391cb0ef41Sopenharmony_ci  bool VisitNode(AstNode* node);
401cb0ef41Sopenharmony_ci  void VisitTryCatchStatement(TryCatchStatement* stmt);
411cb0ef41Sopenharmony_ci  void VisitTryFinallyStatement(TryFinallyStatement* stmt);
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci  void MaybeRemoveContinuationRange(Statement* last_statement);
441cb0ef41Sopenharmony_ci  void MaybeRemoveLastContinuationRange(ZonePtrList<Statement>* stmts);
451cb0ef41Sopenharmony_ci  void MaybeRemoveContinuationRangeOfAsyncReturn(TryCatchStatement* stmt);
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci  SourceRangeMap* source_range_map_ = nullptr;
481cb0ef41Sopenharmony_ci  std::unordered_set<int> continuation_positions_;
491cb0ef41Sopenharmony_ci};
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci}  // namespace internal
521cb0ef41Sopenharmony_ci}  // namespace v8
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci#endif  // V8_AST_SOURCE_RANGE_AST_VISITOR_H_
55