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

Generated by: LCOV version 1.10