ClangExternalASTSourceCommon.h revision a32c5a5aa1fec0f9bc2a5b123f07ff6b8c979999
1//===-- ClangExternalASTSourceCommon.h --------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_ClangExternalASTSourceCommon_h
11#define liblldb_ClangExternalASTSourceCommon_h
12
13// Clang headers like to use NDEBUG inside of them to enable/disable debug
14// releated features using "#ifndef NDEBUG" preprocessor blocks to do one thing
15// or another. This is bad because it means that if clang was built in release
16// mode, it assumes that you are building in release mode which is not always
17// the case. You can end up with functions that are defined as empty in header
18// files when NDEBUG is not defined, and this can cause link errors with the
19// clang .a files that you have since you might be missing functions in the .a
20// file. So we have to define NDEBUG when including clang headers to avoid any
21// mismatches. This is covered by rdar://problem/8691220
22
23#if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF)
24#define LLDB_DEFINED_NDEBUG_FOR_CLANG
25#define NDEBUG
26// Need to include assert.h so it is as clang would expect it to be (disabled)
27#include <assert.h>
28#endif
29
30#include "clang/AST/ExternalASTSource.h"
31
32#ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG
33#undef NDEBUG
34#undef LLDB_DEFINED_NDEBUG_FOR_CLANG
35// Need to re-include assert.h so it is as _we_ would expect it to be (enabled)
36#include <assert.h>
37#endif
38
39#include "lldb/lldb-defines.h"
40#include "lldb/Core/dwarf.h"
41
42namespace lldb_private {
43
44class ClangASTMetadata
45{
46public:
47    ClangASTMetadata () :
48        m_user_id(0),
49        m_union_is_user_id(false),
50        m_union_is_isa_ptr(false),
51        m_has_object_ptr(false),
52        m_is_self (false)
53    {
54    }
55
56    void
57    SetUserID (lldb::user_id_t user_id)
58    {
59        m_user_id = user_id;
60        m_union_is_user_id = true;
61        m_union_is_isa_ptr = false;
62    }
63    lldb::user_id_t GetUserID () const
64    {
65        if (m_union_is_user_id)
66            return m_user_id;
67        else
68            return LLDB_INVALID_UID;
69    }
70
71    void
72    SetISAPtr (uint64_t isa_ptr)
73    {
74        m_isa_ptr = isa_ptr;
75        m_union_is_user_id = false;
76        m_union_is_isa_ptr = true;
77    }
78
79    uint64_t GetISAPtr () const
80    {
81        if (m_union_is_isa_ptr)
82            return m_isa_ptr;
83        else
84            return 0;
85    }
86
87    void SetObjectPtrName(const char *name)
88    {
89        m_has_object_ptr = true;
90        if (strcmp (name, "self") == 0)
91            m_is_self = true;
92        else if (strcmp (name, "this") == 0)
93            m_is_self = false;
94        else
95            m_has_object_ptr = false;
96    }
97
98    const char *GetObjectPtrName() const
99    {
100        if (m_has_object_ptr)
101        {
102            if (m_is_self)
103                return "self";
104            else
105                return "this";
106        }
107        else
108            return NULL;
109    }
110
111    bool HasObjectPtr() const
112    {
113        return m_has_object_ptr;
114    }
115
116private:
117    union
118    {
119        lldb::user_id_t m_user_id;
120        uint64_t  m_isa_ptr;
121    };
122    bool m_union_is_user_id : 1,
123         m_union_is_isa_ptr : 1,
124         m_has_object_ptr : 1,
125         m_is_self : 1;
126
127};
128
129class ClangExternalASTSourceCommon : public clang::ExternalASTSource
130{
131public:
132    ClangExternalASTSourceCommon();
133    ~ClangExternalASTSourceCommon();
134
135    virtual ClangASTMetadata *GetMetadata(uintptr_t object);
136    virtual void SetMetadata(uintptr_t object, ClangASTMetadata &metadata);
137    virtual bool HasMetadata(uintptr_t object);
138private:
139    typedef llvm::DenseMap<uintptr_t, ClangASTMetadata> MetadataMap;
140
141    MetadataMap m_metadata;
142    uint64_t    m_magic;        ///< Because we don't have RTTI, we must take it
143                                ///< on faith that any valid ExternalASTSource that
144                                ///< we try to use the *Metadata APIs on inherits
145                                ///< from ClangExternalASTSourceCommon.  This magic
146                                ///< number exists to enforce that.
147};
148
149}
150
151#endif
152