reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
//===-- ClangExternalASTSourceCallbacks.h -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef liblldb_ClangExternalASTSourceCallbacks_h_
#define liblldb_ClangExternalASTSourceCallbacks_h_

#include <stdint.h>

#include "clang/AST/CharUnits.h"
#include "llvm/ADT/DenseMap.h"

#include "lldb/Core/ClangForward.h"
#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
#include "lldb/Symbol/CompilerType.h"
#include "lldb/lldb-enumerations.h"

namespace lldb_private {

class ClangExternalASTSourceCallbacks : public ClangExternalASTSourceCommon {
public:
  typedef void (*CompleteTagDeclCallback)(void *baton, clang::TagDecl *);
  typedef void (*CompleteObjCInterfaceDeclCallback)(void *baton,
                                                    clang::ObjCInterfaceDecl *);
  typedef void (*FindExternalVisibleDeclsByNameCallback)(
      void *baton, const clang::DeclContext *DC, clang::DeclarationName Name,
      llvm::SmallVectorImpl<clang::NamedDecl *> *results);
  typedef bool (*LayoutRecordTypeCallback)(
      void *baton, const clang::RecordDecl *Record, uint64_t &Size,
      uint64_t &Alignment,
      llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
      llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
          &BaseOffsets,
      llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
          &VirtualBaseOffsets);

  ClangExternalASTSourceCallbacks(
      CompleteTagDeclCallback tag_decl_callback,
      CompleteObjCInterfaceDeclCallback objc_decl_callback,
      FindExternalVisibleDeclsByNameCallback find_by_name_callback,
      LayoutRecordTypeCallback layout_record_type_callback,
      void *callback_baton)
      : m_callback_tag_decl(tag_decl_callback),
        m_callback_objc_decl(objc_decl_callback),
        m_callback_find_by_name(find_by_name_callback),
        m_callback_layout_record_type(layout_record_type_callback),
        m_callback_baton(callback_baton) {}

  // clang::ExternalASTSource

  clang::Decl *GetExternalDecl(uint32_t ID) override {
    // This method only needs to be implemented if the AST source ever passes
    // back decl sets as VisibleDeclaration objects.
    return nullptr;
  }

  clang::Stmt *GetExternalDeclStmt(uint64_t Offset) override {
    // This operation is meant to be used via a LazyOffsetPtr.  It only needs
    // to be implemented if the AST source uses methods like
    // FunctionDecl::setLazyBody when building decls.
    return nullptr;
  }

  clang::Selector GetExternalSelector(uint32_t ID) override {
    // This operation only needs to be implemented if the AST source returns
    // non-zero for GetNumKnownSelectors().
    return clang::Selector();
  }

  uint32_t GetNumExternalSelectors() override { return 0; }

  clang::CXXBaseSpecifier *
  GetExternalCXXBaseSpecifiers(uint64_t Offset) override {
    return nullptr;
  }

  virtual void MaterializeVisibleDecls(const clang::DeclContext *decl_ctx) {}

  void FindExternalLexicalDecls(
      const clang::DeclContext *DC,
      llvm::function_ref<bool(clang::Decl::Kind)> IsKindWeWant,
      llvm::SmallVectorImpl<clang::Decl *> &Result) override;

  bool
  FindExternalVisibleDeclsByName(const clang::DeclContext *decl_ctx,
                                 clang::DeclarationName decl_name) override;

  void CompleteType(clang::TagDecl *tag_decl) override;

  void CompleteType(clang::ObjCInterfaceDecl *objc_decl) override;

  bool layoutRecordType(
      const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
      llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
      llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
          &BaseOffsets,
      llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
          &VirtualBaseOffsets) override;

  void SetExternalSourceCallbacks(
      CompleteTagDeclCallback tag_decl_callback,
      CompleteObjCInterfaceDeclCallback objc_decl_callback,
      FindExternalVisibleDeclsByNameCallback find_by_name_callback,
      LayoutRecordTypeCallback layout_record_type_callback,
      void *callback_baton) {
    m_callback_tag_decl = tag_decl_callback;
    m_callback_objc_decl = objc_decl_callback;
    m_callback_find_by_name = find_by_name_callback;
    m_callback_layout_record_type = layout_record_type_callback;
    m_callback_baton = callback_baton;
  }

  void RemoveExternalSourceCallbacks(void *callback_baton) {
    if (callback_baton == m_callback_baton) {
      m_callback_tag_decl = nullptr;
      m_callback_objc_decl = nullptr;
      m_callback_find_by_name = nullptr;
      m_callback_layout_record_type = nullptr;
    }
  }

protected:
  // Classes that inherit from ClangExternalASTSourceCallbacks can see and
  // modify these
  CompleteTagDeclCallback m_callback_tag_decl;
  CompleteObjCInterfaceDeclCallback m_callback_objc_decl;
  FindExternalVisibleDeclsByNameCallback m_callback_find_by_name;
  LayoutRecordTypeCallback m_callback_layout_record_type;
  void *m_callback_baton;
};

} // namespace lldb_private

#endif // liblldb_ClangExternalASTSourceCallbacks_h_