// Part of the Crubit project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#ifndef CRUBIT_RS_BINDINGS_FROM_CC_DECL_IMPORTER_H_
#define CRUBIT_RS_BINDINGS_FROM_CC_DECL_IMPORTER_H_

#include <memory>
#include <optional>
#include <set>
#include <string>
#include <vector>

#include "absl/container/flat_hash_map.h"
#include "absl/log/check.h"
#include "absl/status/statusor.h"
#include "absl/types/span.h"
#include "lifetime_annotations/lifetime_annotations.h"
#include "lifetime_annotations/type_lifetimes.h"
#include "rs_bindings_from_cc/bazel_types.h"
#include "rs_bindings_from_cc/ir.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/RawCommentList.h"
#include "clang/AST/Type.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Sema/Sema.h"

namespace crubit {

// Top-level parameters as well as return value of an importer invocation.
class Invocation {
 public:
  Invocation(BazelLabel target, absl::Span<const HeaderName> public_headers,
             const absl::flat_hash_map<HeaderName, BazelLabel>& header_targets)
      : target_(target),
        public_headers_(public_headers),
        lifetime_context_(std::make_shared<
                          clang::tidy::lifetimes::LifetimeAnnotationContext>()),
        header_targets_(header_targets) {
    // Caller should verify that the inputs are non-empty.
    CHECK(!public_headers_.empty());
    CHECK(!header_targets_.empty());

    ir_.public_headers.insert(ir_.public_headers.end(), public_headers_.begin(),
                              public_headers.end());
    ir_.current_target = target_;
  }

  // Returns the target of a header, if any.
  std::optional<BazelLabel> header_target(const HeaderName header) const {
    auto it = header_targets_.find(header);
    return (it != header_targets_.end()) ? std::optional(it->second)
                                         : std::nullopt;
  }

  // The main target from which we are importing.
  const BazelLabel target_;

  // The headers from which the import starts.  See the doc comment of
  // `IR::public_headers` and `HeaderName` for more details.
  const absl::Span<const HeaderName> public_headers_;

  const std::shared_ptr<clang::tidy::lifetimes::LifetimeAnnotationContext>
      lifetime_context_;

  // The main output of the import process
  IR ir_;

 private:
  const absl::flat_hash_map<HeaderName, BazelLabel>& header_targets_;
};

// Explicitly defined interface that defines how `DeclImporter`s are allowed to
// interface with the global state of the importer.
class ImportContext {
 public:
  ImportContext(Invocation& invocation, clang::ASTContext& ctx,
                clang::Sema& sema)
      : invocation_(invocation), ctx_(ctx), sema_(sema) {}
  virtual ~ImportContext() = default;

  // Imports all decls contained in a `DeclContext`.
  virtual void ImportDeclsFromDeclContext(
      const clang::DeclContext* decl_context) = 0;

  // Imports an unsupported item with a single error message.
  virtual IR::Item ImportUnsupportedItem(const clang::Decl* decl,
                                         std::string error) = 0;

  // Imports an unsupported item with multiple error messages.
  virtual IR::Item ImportUnsupportedItem(const clang::Decl* decl,
                                         std::set<std::string> errors) = 0;

  // Imports a decl and creates an IR item (or error messages). This allows
  // importers to recursively delegate to other importers.
  // Does not use or update the cache.
  virtual std::optional<IR::Item> ImportDecl(clang::Decl* decl) = 0;

  // Returns the Item of a Decl, importing it first if necessary.
  // Updates the cache.
  virtual std::optional<IR::Item> GetDeclItem(clang::Decl* decl) = 0;

  virtual std::optional<IR::Item> GetImportedItem(
      const clang::Decl* decl) const = 0;

  virtual ItemId GenerateItemId(const clang::Decl* decl) const = 0;
  virtual ItemId GenerateItemId(const clang::RawComment* comment) const = 0;
  // Returns the ID of the parent record or namespace, if it exists, and
  // `std::nullopt` for top level decls. We use this function to assign a parent
  // item to all the IR items.
  //
  // Imports the parent decl if it is not already imported, and returns a bad
  // status if the parent cannot be imported.
  virtual absl::StatusOr<std::optional<ItemId>> GetEnclosingItemId(
      clang::Decl* decl) = 0;

  // Imports children of `decl`.
  //
  // Returns item ids of the children that belong to the current target.  This
  // includes ids of comments within `decl`.  The returned ids are ordered by
  // their source order.
  virtual std::vector<ItemId> GetItemIdsInSourceOrder(clang::Decl* decl) = 0;

  // Mangles the name of a named decl.
  virtual std::string GetMangledName(
      const clang::NamedDecl* named_decl) const = 0;

  // Returs the label of the target that contains a decl.
  virtual BazelLabel GetOwningTarget(const clang::Decl* decl) const = 0;

  // Checks if the given decl belongs to the current target. Does not look into
  // other redeclarations of the decl.
  virtual bool IsFromCurrentTarget(const clang::Decl* decl) const = 0;

  // Gets an IR UnqualifiedIdentifier for the named decl.
  //
  // If the decl's name is an identifier, this returns that identifier as-is.
  //
  // If the decl is a special member function or operator overload, this returns
  // a SpecialName.
  //
  // If the name can't be translated (or is empty), this returns an error.
  virtual absl::StatusOr<UnqualifiedIdentifier> GetTranslatedName(
      const clang::NamedDecl* named_decl) const = 0;

  // GetTranslatedName, but only for identifier names. This is the common case.
  // If the name can't be translated (or is empty), this returns an error.
  virtual absl::StatusOr<Identifier> GetTranslatedIdentifier(
      const clang::NamedDecl* named_decl) const = 0;

  // Gets the doc comment of the declaration.
  virtual std::optional<std::string> GetComment(
      const clang::Decl* decl) const = 0;

  // Converts a Clang source location to IR.
  virtual std::string ConvertSourceLocation(
      clang::SourceLocation loc) const = 0;

  // Converts the Clang type `qual_type` into an equivalent `MappedType`.
  // Lifetimes for the type can optionally be specified using `lifetimes` (pass
  // null otherwise).
  // If `qual_type` is a pointer type, `nullable` specifies whether the
  // pointer can be null.
  // TODO(b/209390498): Currently, we're able to specify nullability only for
  // top-level pointers. Extend this so that we can specify nullability for
  // all pointers contained in `qual_type`, in the same way that `lifetimes`
  // specifies lifetimes for all these pointers. Once this is done, make sure
  // that all callers pass in the appropriate information, derived from
  // nullability annotations.
  virtual absl::StatusOr<MappedType> ConvertQualType(
      clang::QualType qual_type,
      const clang::tidy::lifetimes::ValueLifetimes* lifetimes,
      std::optional<clang::RefQualifierKind> ref_qualifier_kind,
      bool nullable = true) = 0;

  // Marks `decl` as successfully imported.  Other pieces of code can check
  // HasBeenAlreadySuccessfullyImported to avoid introducing dangling ItemIds
  // that refer to an unimportable `decl`.
  virtual void MarkAsSuccessfullyImported(const clang::NamedDecl* decl) = 0;

  // Returns whether the `decl` has been already successfully imported (maybe
  // partially - e.g. CXXRecordDeclImporter::Import marks the import as success
  // before importing the fields, because the latter cannot fail).  See also
  // MarkAsSuccessfullyImported.
  virtual bool HasBeenAlreadySuccessfullyImported(
      const clang::NamedDecl* decl) const = 0;

  // Returns whether the `decl` will be successfully imported. If it hasn't been
  // imported yet, attempts to import it now, calling
  // MarkAsSuccessfullyImported.
  virtual bool EnsureSuccessfullyImported(clang::NamedDecl* decl) = 0;

  Invocation& invocation_;
  clang::ASTContext& ctx_;
  clang::Sema& sema_;
};

// Interface for components that can import decls of a certain category.
class DeclImporter {
 public:
  explicit DeclImporter(ImportContext& ictx) : ictx_(ictx) {}
  virtual ~DeclImporter() = default;

  // Returns an IR item for a decl, or `std::nullopt` if it could not be
  // imported.
  // If it can't be imported, other DeclImporters may be attempted.
  // To indicate that an item can't be imported, and no other importers should
  // be attempted, return UnsupportedItem.
  virtual std::optional<IR::Item> ImportDecl(clang::Decl*) = 0;

 protected:
  ImportContext& ictx_;
};

// Common implementation for defining `DeclImporter`s that determine their
// applicability by the dynamic type of the decl.
template <typename D>
class DeclImporterBase : public DeclImporter {
 public:
  explicit DeclImporterBase(ImportContext& context) : DeclImporter(context) {}

 protected:
  std::optional<IR::Item> ImportDecl(clang::Decl* decl) override {
    auto* typed_decl = clang::dyn_cast<D>(decl);
    if (typed_decl == nullptr) return std::nullopt;
    return Import(typed_decl);
  }
  virtual std::optional<IR::Item> Import(D*) = 0;
};

}  // namespace crubit

#endif  // CRUBIT_RS_BINDINGS_FROM_CC_DECL_IMPORTER_H_
