File: ClangExternalASTSourceCommon.cpp

package info (click to toggle)
llvm-toolchain-3.8 1%3A3.8.1-24
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 379,280 kB
  • ctags: 388,501
  • sloc: cpp: 2,309,705; ansic: 477,070; objc: 100,918; asm: 97,974; python: 95,911; sh: 18,634; makefile: 7,294; perl: 5,584; ml: 5,460; pascal: 4,661; lisp: 2,548; xml: 686; cs: 350; php: 212; csh: 117
file content (107 lines) | stat: -rw-r--r-- 2,553 bytes parent folder | download | duplicates (3)
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
//===-- ClangExternalASTSourceCommon.cpp ------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
#include "lldb/Core/Stream.h"
#include "lldb/Host/Mutex.h"

using namespace lldb_private;

uint64_t g_TotalSizeOfMetadata = 0;

typedef llvm::DenseMap<clang::ExternalASTSource *, ClangExternalASTSourceCommon *> ASTSourceMap;

static ASTSourceMap &GetSourceMap()
{
    static ASTSourceMap s_source_map;
    return s_source_map;
}

ClangExternalASTSourceCommon *
ClangExternalASTSourceCommon::Lookup(clang::ExternalASTSource *source)
{
    ASTSourceMap &source_map = GetSourceMap();
    
    ASTSourceMap::iterator iter = source_map.find(source);
    
    if (iter != source_map.end())
    {
        return iter->second;
    }
    else
    {
        return nullptr;
    }
}

ClangExternalASTSourceCommon::ClangExternalASTSourceCommon() : clang::ExternalASTSource()
{
    g_TotalSizeOfMetadata += m_metadata.size();
    GetSourceMap()[this] = this;
}

ClangExternalASTSourceCommon::~ClangExternalASTSourceCommon()
{
    GetSourceMap().erase(this);
    g_TotalSizeOfMetadata -= m_metadata.size();
}

ClangASTMetadata *
ClangExternalASTSourceCommon::GetMetadata (const void *object)
{
    if (HasMetadata (object))
        return &m_metadata[object];
    else
        return nullptr;
}

void
ClangExternalASTSourceCommon::SetMetadata (const void *object, ClangASTMetadata &metadata)
{
    uint64_t orig_size = m_metadata.size();
    m_metadata[object] = metadata;
    uint64_t new_size = m_metadata.size();
    g_TotalSizeOfMetadata += (new_size - orig_size);
}

bool
ClangExternalASTSourceCommon::HasMetadata (const void *object)
{
    return m_metadata.find(object) != m_metadata.end();
}

void
ClangASTMetadata::Dump (Stream *s)
{
    lldb::user_id_t uid = GetUserID ();
    
    if (uid != LLDB_INVALID_UID)
    {
        s->Printf ("uid=0x%" PRIx64, uid);
    }
    
    uint64_t isa_ptr = GetISAPtr ();
    if (isa_ptr != 0)
    {
        s->Printf ("isa_ptr=0x%" PRIx64, isa_ptr);
    }
    
    const char *obj_ptr_name = GetObjectPtrName();
    if (obj_ptr_name)
    {
        s->Printf ("obj_ptr_name=\"%s\" ", obj_ptr_name);
    }
    
    if (m_is_dynamic_cxx)
    {
        s->Printf ("is_dynamic_cxx=%i ", m_is_dynamic_cxx);
    }
    s->EOL();
}