LCOV - code coverage report
Current view: top level - src/torque - global-context.h (source / functions) Hit Total Coverage
Test: app.info Lines: 24 25 96.0 %
Date: 2019-01-20 Functions: 22 22 100.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_GLOBAL_CONTEXT_H_
       6             : #define V8_TORQUE_GLOBAL_CONTEXT_H_
       7             : 
       8             : #include <map>
       9             : 
      10             : #include "src/torque/declarable.h"
      11             : #include "src/torque/declarations.h"
      12             : #include "src/torque/type-oracle.h"
      13             : 
      14             : namespace v8 {
      15             : namespace internal {
      16             : namespace torque {
      17             : 
      18           2 : class GlobalContext : public ContextualClass<GlobalContext> {
      19             :  public:
      20           1 :   explicit GlobalContext(Ast ast) : verbose_(false), ast_(std::move(ast)) {
      21           1 :     CurrentScope::Scope current_scope(nullptr);
      22             :     CurrentSourcePosition::Scope current_source_position(
      23           1 :         SourcePosition{CurrentSourceFile::Get(), -1, -1});
      24             :     default_namespace_ =
      25           2 :         RegisterDeclarable(base::make_unique<Namespace>("base"));
      26           1 :   }
      27       78962 :   static Namespace* GetDefaultNamespace() { return Get().default_namespace_; }
      28             :   template <class T>
      29        4900 :   T* RegisterDeclarable(std::unique_ptr<T> d) {
      30             :     T* ptr = d.get();
      31        9910 :     declarables_.push_back(std::move(d));
      32        4900 :     return ptr;
      33             :   }
      34             : 
      35             :   static const std::vector<std::unique_ptr<Declarable>>& AllDeclarables() {
      36             :     return Get().declarables_;
      37             :   }
      38             : 
      39          12 :   static const std::vector<Namespace*> GetNamespaces() {
      40             :     std::vector<Namespace*> result;
      41       19752 :     for (auto& declarable : AllDeclarables()) {
      42       19728 :       if (Namespace* n = Namespace::DynamicCast(declarable.get())) {
      43         120 :         result.push_back(n);
      44             :       }
      45             :     }
      46          12 :     return result;
      47             :   }
      48             : 
      49           7 :   static void RegisterClass(const std::string& name,
      50             :                             const ClassType* new_class) {
      51           7 :     Get().classes_[name] = new_class;
      52           7 :   }
      53             : 
      54             :   static const std::map<std::string, const ClassType*>& GetClasses() {
      55             :     return Get().classes_;
      56             :   }
      57             : 
      58          13 :   static void AddCppInclude(std::string include_path) {
      59          13 :     Get().cpp_includes_.push_back(std::move(include_path));
      60          13 :   }
      61             :   static const std::vector<std::string>& CppIncludes() {
      62             :     return Get().cpp_includes_;
      63             :   }
      64             : 
      65           0 :   static void SetVerbose() { Get().verbose_ = true; }
      66        5545 :   static bool verbose() { return Get().verbose_; }
      67             :   static Ast* ast() { return &Get().ast_; }
      68             : 
      69             :  private:
      70             :   bool verbose_;
      71             :   Namespace* default_namespace_;
      72             :   Ast ast_;
      73             :   std::vector<std::unique_ptr<Declarable>> declarables_;
      74             :   std::vector<std::string> cpp_includes_;
      75             :   std::map<std::string, const ClassType*> classes_;
      76             : };
      77             : 
      78             : template <class T>
      79        5009 : T* RegisterDeclarable(std::unique_ptr<T> d) {
      80        9908 :   return GlobalContext::Get().RegisterDeclarable(std::move(d));
      81             : }
      82             : 
      83             : }  // namespace torque
      84             : }  // namespace internal
      85             : }  // namespace v8
      86             : 
      87             : #endif  // V8_TORQUE_GLOBAL_CONTEXT_H_

Generated by: LCOV version 1.10