LCOV - code coverage report
Current view: top level - src/ast - source-range-ast-visitor.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 29 31 93.5 %
Date: 2019-01-20 Functions: 6 7 85.7 %

          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             : #include "src/ast/source-range-ast-visitor.h"
       6             : 
       7             : #include "src/ast/ast-source-ranges.h"
       8             : 
       9             : namespace v8 {
      10             : namespace internal {
      11             : 
      12         815 : SourceRangeAstVisitor::SourceRangeAstVisitor(uintptr_t stack_limit,
      13             :                                              Expression* root,
      14             :                                              SourceRangeMap* source_range_map)
      15             :     : AstTraversalVisitor(stack_limit, root),
      16        1630 :       source_range_map_(source_range_map) {}
      17             : 
      18        1565 : void SourceRangeAstVisitor::VisitBlock(Block* stmt) {
      19        1565 :   AstTraversalVisitor::VisitBlock(stmt);
      20        1565 :   ZonePtrList<Statement>* stmts = stmt->statements();
      21        1565 :   AstNodeSourceRanges* enclosingSourceRanges = source_range_map_->Find(stmt);
      22        1565 :   if (enclosingSourceRanges != nullptr) {
      23         725 :     CHECK(enclosingSourceRanges->HasRange(SourceRangeKind::kContinuation));
      24         725 :     MaybeRemoveLastContinuationRange(stmts);
      25             :   }
      26        1565 : }
      27             : 
      28           0 : void SourceRangeAstVisitor::VisitFunctionLiteral(FunctionLiteral* expr) {
      29        1470 :   AstTraversalVisitor::VisitFunctionLiteral(expr);
      30        1470 :   ZonePtrList<Statement>* stmts = expr->body();
      31        1470 :   MaybeRemoveLastContinuationRange(stmts);
      32           0 : }
      33             : 
      34       20660 : bool SourceRangeAstVisitor::VisitNode(AstNode* node) {
      35       20660 :   AstNodeSourceRanges* range = source_range_map_->Find(node);
      36             : 
      37       20660 :   if (range == nullptr) return true;
      38        3005 :   if (!range->HasRange(SourceRangeKind::kContinuation)) return true;
      39             : 
      40             :   // Called in pre-order. In case of conflicting continuation ranges, only the
      41             :   // outermost range may survive.
      42             : 
      43        2615 :   SourceRange continuation = range->GetRange(SourceRangeKind::kContinuation);
      44        2615 :   if (continuation_positions_.find(continuation.start) !=
      45             :       continuation_positions_.end()) {
      46         845 :     range->RemoveContinuationRange();
      47             :   } else {
      48             :     continuation_positions_.emplace(continuation.start);
      49             :   }
      50             : 
      51             :   return true;
      52             : }
      53             : 
      54        2195 : void SourceRangeAstVisitor::MaybeRemoveLastContinuationRange(
      55        2195 :     ZonePtrList<Statement>* statements) {
      56        2195 :   if (statements->is_empty()) return;
      57             : 
      58        1620 :   Statement* last_statement = statements->last();
      59        1620 :   AstNodeSourceRanges* last_range = source_range_map_->Find(last_statement);
      60        1620 :   if (last_range == nullptr) return;
      61             : 
      62         675 :   if (last_range->HasRange(SourceRangeKind::kContinuation)) {
      63         675 :     last_range->RemoveContinuationRange();
      64             :   }
      65             : }
      66             : 
      67             : }  // namespace internal
      68      183867 : }  // namespace v8

Generated by: LCOV version 1.10