LCOV - code coverage report
Current view: top level - src/parsing - func-name-inferrer.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 36 36 100.0 %
Date: 2017-04-26 Functions: 7 7 100.0 %

          Line data    Source code
       1             : // Copyright 2011 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/parsing/func-name-inferrer.h"
       6             : 
       7             : #include "src/ast/ast-value-factory.h"
       8             : #include "src/ast/ast.h"
       9             : #include "src/list-inl.h"
      10             : #include "src/objects-inl.h"
      11             : 
      12             : namespace v8 {
      13             : namespace internal {
      14             : 
      15    11129750 : FuncNameInferrer::FuncNameInferrer(AstValueFactory* ast_value_factory,
      16             :                                    Zone* zone)
      17             :     : ast_value_factory_(ast_value_factory),
      18             :       entries_stack_(10, zone),
      19             :       names_stack_(5, zone),
      20             :       funcs_to_infer_(4, zone),
      21    11129750 :       zone_(zone) {
      22    11129744 : }
      23             : 
      24             : 
      25     4066396 : void FuncNameInferrer::PushEnclosingName(const AstRawString* name) {
      26             :   // Enclosing name is a name of a constructor function. To check
      27             :   // that it is really a constructor, we check that it is not empty
      28             :   // and starts with a capital letter.
      29     3128130 :   if (!name->IsEmpty() && unibrow::Uppercase::Is(name->FirstCharacter())) {
      30      938266 :     names_stack_.Add(Name(name, kEnclosingConstructorName), zone());
      31             :   }
      32     3128130 : }
      33             : 
      34             : 
      35    78555437 : void FuncNameInferrer::PushLiteralName(const AstRawString* name) {
      36    80477700 :   if (IsOpen() && name != ast_value_factory_->prototype_string()) {
      37    38316560 :     names_stack_.Add(Name(name, kLiteralName), zone());
      38             :   }
      39    40238879 : }
      40             : 
      41             : 
      42   188453481 : void FuncNameInferrer::PushVariableName(const AstRawString* name) {
      43   188453478 :   if (IsOpen() && name != ast_value_factory_->dot_result_string()) {
      44    93421567 :     names_stack_.Add(Name(name, kVariableName), zone());
      45             :   }
      46    95031900 : }
      47             : 
      48        4670 : void FuncNameInferrer::RemoveAsyncKeywordFromEnd() {
      49        4670 :   if (IsOpen()) {
      50        4655 :     CHECK(names_stack_.length() > 0);
      51        4655 :     CHECK(names_stack_.last().name->IsOneByteEqualTo("async"));
      52        4655 :     names_stack_.RemoveLast();
      53             :   }
      54        4670 : }
      55             : 
      56    11660567 : const AstConsString* FuncNameInferrer::MakeNameFromStack() {
      57    11660567 :   AstConsString* result = ast_value_factory_->NewConsString();
      58    16595696 :   for (int pos = 0; pos < names_stack_.length(); pos++) {
      59             :     // Skip consecutive variable declarations.
      60    43248508 :     if (pos + 1 < names_stack_.length() &&
      61    26178363 :         names_stack_.at(pos).type == kVariableName &&
      62     7430071 :         names_stack_.at(pos + 1).type == kVariableName) {
      63             :       continue;
      64             :     }
      65             :     // Add name. Separate names with ".".
      66     5809192 :     if (!result->IsEmpty()) {
      67     5908634 :       result->AddString(zone(), ast_value_factory_->dot_string());
      68             :     }
      69     5809192 :     result->AddString(zone(), names_stack_.at(pos).name);
      70             :   }
      71     2897058 :   return result;
      72             : }
      73             : 
      74     2897058 : void FuncNameInferrer::InferFunctionsNames() {
      75     2897058 :   const AstConsString* func_name = MakeNameFromStack();
      76    11599934 :   for (int i = 0; i < funcs_to_infer_.length(); ++i) {
      77    11605785 :     funcs_to_infer_[i]->set_raw_inferred_name(func_name);
      78             :   }
      79             :   funcs_to_infer_.Rewind(0);
      80     2897058 : }
      81             : 
      82             : 
      83             : }  // namespace internal
      84             : }  // namespace v8

Generated by: LCOV version 1.10