LCOV - code coverage report
Current view: top level - src/torque - declarable.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 22 52 42.3 %
Date: 2019-03-21 Functions: 6 11 54.5 %

          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 <fstream>
       6             : #include <iostream>
       7             : 
       8             : #include "src/torque/declarable.h"
       9             : #include "src/torque/global-context.h"
      10             : 
      11             : namespace v8 {
      12             : namespace internal {
      13             : namespace torque {
      14             : 
      15      126284 : DEFINE_CONTEXTUAL_VARIABLE(CurrentScope)
      16             : 
      17           0 : std::ostream& operator<<(std::ostream& os, const QualifiedName& name) {
      18           0 :   for (const std::string& qualifier : name.namespace_qualification) {
      19           0 :     os << qualifier << "::";
      20             :   }
      21           0 :   return os << name.name;
      22             : }
      23             : 
      24           0 : std::ostream& operator<<(std::ostream& os, const Callable& m) {
      25           0 :   os << "callable " << m.ReadableName() << "(";
      26           0 :   if (m.signature().implicit_count != 0) {
      27           0 :     os << "implicit ";
      28             :     TypeVector implicit_parameter_types(
      29             :         m.signature().parameter_types.types.begin(),
      30             :         m.signature().parameter_types.types.begin() +
      31           0 :             m.signature().implicit_count);
      32           0 :     os << implicit_parameter_types << ")(";
      33             :     TypeVector explicit_parameter_types(
      34             :         m.signature().parameter_types.types.begin() +
      35           0 :             m.signature().implicit_count,
      36             :         m.signature().parameter_types.types.end());
      37           0 :     os << explicit_parameter_types;
      38             :   } else {
      39           0 :     os << m.signature().parameter_types;
      40             :   }
      41           0 :   os << "): " << *m.signature().return_type;
      42           0 :   return os;
      43             : }
      44             : 
      45           0 : std::ostream& operator<<(std::ostream& os, const Builtin& b) {
      46           0 :   os << "builtin " << *b.signature().return_type << " " << b.ReadableName()
      47           0 :      << b.signature().parameter_types;
      48           0 :   return os;
      49             : }
      50             : 
      51           0 : std::ostream& operator<<(std::ostream& os, const RuntimeFunction& b) {
      52           0 :   os << "runtime function " << *b.signature().return_type << " "
      53           0 :      << b.ReadableName() << b.signature().parameter_types;
      54           0 :   return os;
      55             : }
      56             : 
      57           0 : std::ostream& operator<<(std::ostream& os, const Generic& g) {
      58           0 :   os << "generic " << g.name() << "<";
      59           0 :   PrintCommaSeparatedList(
      60             :       os, g.declaration()->generic_parameters,
      61           0 :       [](const Identifier* identifier) { return identifier->value; });
      62           0 :   os << ">";
      63             : 
      64           0 :   return os;
      65             : }
      66             : 
      67         486 : base::Optional<const Type*> Generic::InferTypeArgument(
      68             :     size_t i, const TypeVector& arguments) {
      69         486 :   const std::string type_name = declaration()->generic_parameters[i]->value;
      70             :   const std::vector<TypeExpression*>& parameters =
      71         486 :       declaration()->callable->signature->parameters.types;
      72         486 :   size_t j = declaration()->callable->signature->parameters.implicit_count;
      73        1164 :   for (size_t i = 0; i < arguments.size() && j < parameters.size(); ++i, ++j) {
      74             :     BasicTypeExpression* basic =
      75         550 :         BasicTypeExpression::DynamicCast(parameters[j]);
      76        1650 :     if (basic && basic->namespace_qualification.empty() &&
      77        1650 :         !basic->is_constexpr && basic->name == type_name) {
      78         486 :       return arguments[i];
      79             :     }
      80             :   }
      81           0 :   return base::nullopt;
      82             : }
      83             : 
      84        4818 : base::Optional<TypeVector> Generic::InferSpecializationTypes(
      85             :     const TypeVector& explicit_specialization_types,
      86             :     const TypeVector& arguments) {
      87        4818 :   TypeVector result = explicit_specialization_types;
      88             :   size_t type_parameter_count = declaration()->generic_parameters.size();
      89        4818 :   if (explicit_specialization_types.size() > type_parameter_count) {
      90             :     return base::nullopt;
      91             :   }
      92         486 :   for (size_t i = explicit_specialization_types.size();
      93        5304 :        i < type_parameter_count; ++i) {
      94         486 :     base::Optional<const Type*> inferred = InferTypeArgument(i, arguments);
      95         486 :     if (!inferred) return base::nullopt;
      96         486 :     result.push_back(*inferred);
      97             :   }
      98             :   return result;
      99             : }
     100             : 
     101       49504 : bool Namespace::IsDefaultNamespace() const {
     102       49504 :   return this == GlobalContext::GetDefaultNamespace();
     103             : }
     104             : 
     105         174 : bool Namespace::IsTestNamespace() const { return name() == kTestNamespaceName; }
     106             : 
     107             : }  // namespace torque
     108             : }  // namespace internal
     109        6150 : }  // namespace v8

Generated by: LCOV version 1.10