file-visitor.h 2.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_TORQUE_FILE_VISITOR_H_
#define V8_TORQUE_FILE_VISITOR_H_

#include <string>

#include "src/torque/ast.h"
#include "src/torque/global-context.h"
#include "src/torque/types.h"
#include "src/torque/utils.h"

#include "src/torque/TorqueBaseVisitor.h"

namespace v8 {
namespace internal {
namespace torque {

class FileVisitor {
 public:
  explicit FileVisitor(GlobalContext& global_context)
      : global_context_(global_context),
25 26
        declarations_(global_context.declarations()),
        module_(global_context.GetDefaultModule()) {}
27

28 29
  TypeVector GetTypeVector(SourcePosition pos,
                           const std::vector<std::string>& v) {
30 31
    TypeVector result;
    for (const std::string& s : v) {
32
      result.push_back(declarations()->LookupType(pos, s));
33 34 35 36 37
    }
    return result;
  }

  Ast* ast() { return global_context_.ast(); }
38
  Declarations* declarations() { return global_context_.declarations(); }
39 40

 protected:
41 42 43 44 45 46
  static constexpr const char* kTrueLabelName = "_True";
  static constexpr const char* kFalseLabelName = "_False";
  static constexpr const char* kReturnValueVariable = "_return";
  static constexpr const char* kConditionValueVariable = "_condition";
  static constexpr const char* kDoneLabelName = "_done";
  static constexpr const char* kForIndexValueVariable = "_for_index";
47 48 49 50 51 52 53 54 55 56

  Module* CurrentModule() const { return module_; }

  TypeOracle& GetTypeOracle() { return global_context_.GetTypeOracle(); }

  std::string GetParameterVariableFromName(const std::string& name) {
    return std::string("p_") + name;
  }

  std::string PositionAsString(SourcePosition pos) {
57
    return global_context_.ast()->source_file_map()->PositionAsString(pos);
58 59
  }

60 61 62 63
  Callable* LookupCall(SourcePosition pos, const std::string& name,
                       const TypeVector& parameter_types);

  Signature MakeSignature(SourcePosition pos, const ParameterList& parameters,
64
                          const std::string& return_type,
65
                          const LabelAndTypesVector& labels);
66 67

  GlobalContext& global_context_;
68
  Declarations* declarations_;
69 70 71 72 73 74 75 76 77
  Callable* current_callable_;
  Module* module_;
};

}  // namespace torque
}  // namespace internal
}  // namespace v8

#endif  // V8_TORQUE_FILE_VISITOR_H_