LCOV - code coverage report
Current view: top level - src/torque - declarations.h (source / functions) Hit Total Coverage
Test: app.info Lines: 20 21 95.2 %
Date: 2019-02-19 Functions: 19 20 95.0 %

          Line data    Source code
       1             : // Copyright 2017 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             : #ifndef V8_TORQUE_DECLARATIONS_H_
       6             : #define V8_TORQUE_DECLARATIONS_H_
       7             : 
       8             : #include <string>
       9             : 
      10             : #include "src/torque/declarable.h"
      11             : #include "src/torque/utils.h"
      12             : 
      13             : namespace v8 {
      14             : namespace internal {
      15             : namespace torque {
      16             : 
      17             : static constexpr const char* const kFromConstexprMacroName = "FromConstexpr";
      18             : static constexpr const char* kTrueLabelName = "_True";
      19             : static constexpr const char* kFalseLabelName = "_False";
      20             : 
      21             : template <class T>
      22      139702 : std::vector<T*> FilterDeclarables(const std::vector<Declarable*> list) {
      23             :   std::vector<T*> result;
      24      414151 :   for (Declarable* declarable : list) {
      25      134747 :     if (T* t = T::DynamicCast(declarable)) {
      26      133292 :       result.push_back(t);
      27             :     }
      28             :   }
      29      139702 :   return result;
      30             : }
      31             : 
      32             : class Declarations {
      33             :  public:
      34       38772 :   static std::vector<Declarable*> TryLookup(const QualifiedName& name) {
      35       38772 :     return CurrentScope::Get()->Lookup(name);
      36             :   }
      37             : 
      38        5101 :   static std::vector<Declarable*> TryLookupShallow(const QualifiedName& name) {
      39        5101 :     return CurrentScope::Get()->LookupShallow(name);
      40             :   }
      41             : 
      42             :   template <class T>
      43        1946 :   static std::vector<T*> TryLookup(const QualifiedName& name) {
      44        3892 :     return FilterDeclarables<T>(TryLookup(name));
      45             :   }
      46             : 
      47       36826 :   static std::vector<Declarable*> Lookup(const QualifiedName& name) {
      48       36826 :     std::vector<Declarable*> d = TryLookup(name);
      49       36826 :     if (d.empty()) {
      50           0 :       ReportError("cannot find \"", name, "\"");
      51             :     }
      52       36826 :     return d;
      53             :   }
      54             : 
      55             :   static std::vector<Declarable*> LookupGlobalScope(const std::string& name);
      56             : 
      57             :   static const Type* LookupType(const QualifiedName& name);
      58             :   static const Type* LookupType(std::string name);
      59             :   static const Type* LookupGlobalType(const std::string& name);
      60             :   static const Type* GetType(TypeExpression* type_expression);
      61             : 
      62             :   static Builtin* FindSomeInternalBuiltinWithType(
      63             :       const BuiltinPointerType* type);
      64             : 
      65             :   static Value* LookupValue(const QualifiedName& name);
      66             : 
      67             :   static Macro* TryLookupMacro(const std::string& name,
      68             :                                const TypeVector& types);
      69             :   static base::Optional<Builtin*> TryLookupBuiltin(const QualifiedName& name);
      70             : 
      71             :   static std::vector<Generic*> LookupGeneric(const std::string& name);
      72             :   static Generic* LookupUniqueGeneric(const QualifiedName& name);
      73             : 
      74             :   static Namespace* DeclareNamespace(const std::string& name);
      75             : 
      76             :   static const AbstractType* DeclareAbstractType(
      77             :       const std::string& name, bool transient, const std::string& generated,
      78             :       base::Optional<const AbstractType*> non_constexpr_version,
      79             :       const base::Optional<std::string>& parent = {});
      80             : 
      81             :   static void DeclareType(const std::string& name, const Type* type,
      82             :                           bool redeclaration);
      83             : 
      84             :   static StructType* DeclareStruct(const std::string& name);
      85             : 
      86             :   static ClassType* DeclareClass(const Type* super, const std::string& name,
      87             :                                  bool is_extern, bool transient,
      88             :                                  const std::string& generates);
      89             : 
      90             :   static Macro* CreateMacro(std::string external_name,
      91             :                             std::string readable_name,
      92             :                             base::Optional<std::string> external_assembler_name,
      93             :                             Signature signature, bool transitioning,
      94             :                             base::Optional<Statement*> body);
      95             :   static Macro* DeclareMacro(
      96             :       const std::string& name,
      97             :       base::Optional<std::string> external_assembler_name,
      98             :       const Signature& signature, bool transitioning,
      99             :       base::Optional<Statement*> body, base::Optional<std::string> op = {});
     100             : 
     101             :   static Method* CreateMethod(AggregateType* class_type,
     102             :                               const std::string& name, Signature signature,
     103             :                               bool transitioning, Statement* body);
     104             : 
     105             :   static Intrinsic* CreateIntrinsic(const std::string& name,
     106             :                                     const Signature& signature);
     107             : 
     108             :   static Intrinsic* DeclareIntrinsic(const std::string& name,
     109             :                                      const Signature& signature);
     110             : 
     111             :   static Builtin* CreateBuiltin(std::string external_name,
     112             :                                 std::string readable_name, Builtin::Kind kind,
     113             :                                 Signature signature, bool transitioning,
     114             :                                 base::Optional<Statement*> body);
     115             :   static Builtin* DeclareBuiltin(const std::string& name, Builtin::Kind kind,
     116             :                                  const Signature& signature, bool transitioning,
     117             :                                  base::Optional<Statement*> body);
     118             : 
     119             :   static RuntimeFunction* DeclareRuntimeFunction(const std::string& name,
     120             :                                                  const Signature& signature,
     121             :                                                  bool transitioning);
     122             : 
     123             :   static void DeclareExternConstant(const std::string& name, const Type* type,
     124             :                                     std::string value);
     125             :   static NamespaceConstant* DeclareNamespaceConstant(const std::string& name,
     126             :                                                      const Type* type,
     127             :                                                      Expression* body);
     128             : 
     129             :   static Generic* DeclareGeneric(const std::string& name,
     130             :                                  GenericDeclaration* generic);
     131             : 
     132             :   template <class T>
     133         821 :   static T* Declare(const std::string& name, T* d) {
     134         821 :     CurrentScope::Get()->AddDeclarable(name, d);
     135         821 :     return d;
     136             :   }
     137             :   template <class T>
     138        5010 :   static T* Declare(const std::string& name, std::unique_ptr<T> d) {
     139             :     return CurrentScope::Get()->AddDeclarable(name,
     140       15030 :                                               RegisterDeclarable(std::move(d)));
     141             :   }
     142             :   static Macro* DeclareOperator(const std::string& name, Macro* m);
     143             : 
     144             :   static std::string GetGeneratedCallableName(
     145             :       const std::string& name, const TypeVector& specialized_types);
     146             : };
     147             : 
     148             : }  // namespace torque
     149             : }  // namespace internal
     150             : }  // namespace v8
     151             : 
     152             : #endif  // V8_TORQUE_DECLARATIONS_H_

Generated by: LCOV version 1.10