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-01-20 Functions: 5 10 50.0 %

          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             : 
      10             : namespace v8 {
      11             : namespace internal {
      12             : namespace torque {
      13             : 
      14       86173 : DEFINE_CONTEXTUAL_VARIABLE(CurrentScope);
      15             : 
      16           0 : std::ostream& operator<<(std::ostream& os, const QualifiedName& name) {
      17           0 :   for (const std::string& qualifier : name.namespace_qualification) {
      18           0 :     os << qualifier << "::";
      19             :   }
      20           0 :   return os << name.name;
      21             : }
      22             : 
      23           0 : std::ostream& operator<<(std::ostream& os, const Callable& m) {
      24           0 :   os << "callable " << m.ReadableName() << "(";
      25           0 :   if (m.signature().implicit_count != 0) {
      26           0 :     os << "implicit ";
      27             :     TypeVector implicit_parameter_types(
      28             :         m.signature().parameter_types.types.begin(),
      29           0 :         m.signature().parameter_types.types.begin() +
      30           0 :             m.signature().implicit_count);
      31           0 :     os << implicit_parameter_types << ")(";
      32             :     TypeVector explicit_parameter_types(
      33           0 :         m.signature().parameter_types.types.begin() +
      34             :             m.signature().implicit_count,
      35           0 :         m.signature().parameter_types.types.end());
      36           0 :     os << explicit_parameter_types;
      37             :   } else {
      38           0 :     os << m.signature().parameter_types;
      39             :   }
      40           0 :   os << "): " << *m.signature().return_type;
      41           0 :   return os;
      42             : }
      43             : 
      44           0 : std::ostream& operator<<(std::ostream& os, const Builtin& b) {
      45           0 :   os << "builtin " << *b.signature().return_type << " " << b.ReadableName()
      46           0 :      << b.signature().parameter_types;
      47           0 :   return os;
      48             : }
      49             : 
      50           0 : std::ostream& operator<<(std::ostream& os, const RuntimeFunction& b) {
      51           0 :   os << "runtime function " << *b.signature().return_type << " "
      52           0 :      << b.ReadableName() << b.signature().parameter_types;
      53           0 :   return os;
      54             : }
      55             : 
      56           0 : std::ostream& operator<<(std::ostream& os, const Generic& g) {
      57           0 :   os << "generic " << g.name() << "<";
      58           0 :   PrintCommaSeparatedList(os, g.declaration()->generic_parameters);
      59           0 :   os << ">";
      60             : 
      61           0 :   return os;
      62             : }
      63             : 
      64         242 : base::Optional<const Type*> Generic::InferTypeArgument(
      65         762 :     size_t i, const TypeVector& arguments) {
      66         484 :   const std::string type_name = declaration()->generic_parameters[i];
      67         556 :   const std::vector<TypeExpression*>& parameters =
      68         242 :       declaration()->callable->signature->parameters.types;
      69         242 :   size_t j = declaration()->callable->signature->parameters.implicit_count;
      70         834 :   for (size_t i = 0; i < arguments.size() && j < parameters.size(); ++i, ++j) {
      71             :     BasicTypeExpression* basic =
      72         278 :         BasicTypeExpression::DynamicCast(parameters[j]);
      73         834 :     if (basic && basic->namespace_qualification.empty() &&
      74         834 :         !basic->is_constexpr && basic->name == type_name) {
      75             :       return arguments[i];
      76             :     }
      77             :   }
      78             :   return base::nullopt;
      79             : }
      80             : 
      81        3488 : base::Optional<TypeVector> Generic::InferSpecializationTypes(
      82        3488 :     const TypeVector& explicit_specialization_types,
      83        3488 :     const TypeVector& arguments) {
      84        3488 :   TypeVector result = explicit_specialization_types;
      85        3488 :   size_t type_parameter_count = declaration()->generic_parameters.size();
      86        3488 :   if (explicit_specialization_types.size() > type_parameter_count) {
      87             :     return base::nullopt;
      88             :   }
      89         242 :   for (size_t i = explicit_specialization_types.size();
      90             :        i < type_parameter_count; ++i) {
      91         242 :     base::Optional<const Type*> inferred = InferTypeArgument(i, arguments);
      92         242 :     if (!inferred) return base::nullopt;
      93         242 :     result.push_back(*inferred);
      94             :   }
      95             :   return result;
      96             : }
      97             : 
      98             : }  // namespace torque
      99             : }  // namespace internal
     100        9078 : }  // namespace v8

Generated by: LCOV version 1.10