 |
|
 |
|
| Files: |
1 |
|
Branches Taken: |
25.0% |
2 / 8 |
| Generated: |
2010-02-10 01:31 |
|
Branches Executed: |
62.5% |
5 / 8 |
| |
|
Line Coverage: |
100.0% |
36 / 36 |
| |
 |
|
 |
1 : //===--- GlobalDecl.h - Global declaration holder ---------------*- 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 : // A GlobalDecl can hold either a regular variable/function or a C++ ctor/dtor
11 : // together with its type.
12 : //
13 : //===----------------------------------------------------------------------===//
14 :
15 : #ifndef CLANG_CODEGEN_GLOBALDECL_H
16 : #define CLANG_CODEGEN_GLOBALDECL_H
17 :
18 : #include "CGCXX.h"
19 : #include "clang/AST/DeclCXX.h"
20 : #include "clang/AST/DeclObjC.h"
21 :
22 : namespace clang {
23 :
24 : namespace CodeGen {
25 :
26 : /// GlobalDecl - represents a global declaration. This can either be a
27 : /// CXXConstructorDecl and the constructor type (Base, Complete).
28 : /// a CXXDestructorDecl and the destructor type (Base, Complete) or
29 : /// a VarDecl, a FunctionDecl or a BlockDecl.
30 203175: class GlobalDecl {
31 : llvm::PointerIntPair<const Decl*, 2> Value;
32 :
33 14501: void Init(const Decl *D) {
14501: branch 1 taken
0: branch 2 not taken
34 14501: assert(!isa<CXXConstructorDecl>(D) && "Use other ctor with ctor decls!");
14501: branch 1 taken
0: branch 2 not taken
35 14501: assert(!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!");
36 :
37 14501: Value.setPointer(D);
38 14501: }
39 :
40 : public:
41 63891: GlobalDecl() {}
42 :
43 750: GlobalDecl(const VarDecl *D) { Init(D);}
44 13425: GlobalDecl(const FunctionDecl *D) { Init(D); }
45 35: GlobalDecl(const BlockDecl *D) { Init(D); }
46 291: GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
47 :
48 2672: GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type)
49 2672: : Value(D, Type) {}
50 1102: GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type)
51 1102: : Value(D, Type) {}
52 :
53 51662: const Decl *getDecl() const { return Value.getPointer(); }
54 :
55 2294: CXXCtorType getCtorType() const {
0: branch 2 not taken
0: branch 3 not taken
56 2294: assert(isa<CXXConstructorDecl>(getDecl()) && "Decl is not a ctor!");
57 2294: return static_cast<CXXCtorType>(Value.getInt());
58 : }
59 :
60 684: CXXDtorType getDtorType() const {
0: branch 3 not taken
0: branch 3 not taken
61 684: assert(isa<CXXDestructorDecl>(getDecl()) && "Decl is not a dtor!");
62 684: return static_cast<CXXDtorType>(Value.getInt());
63 : }
64 :
65 427287: friend bool operator==(const GlobalDecl &LHS, const GlobalDecl &RHS) {
66 427287: return LHS.Value == RHS.Value;
67 : }
68 :
69 12990: void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
70 :
71 23809: static GlobalDecl getFromOpaquePtr(void *P) {
72 23809: GlobalDecl GD;
73 23809: GD.Value.setFromOpaqueValue(P);
74 : return GD;
75 : }
76 : };
77 :
78 : } // end namespace CodeGen
79 : } // end namespace clang
80 :
81 : namespace llvm {
82 : template<class> struct DenseMapInfo;
83 :
84 : template<> struct DenseMapInfo<clang::CodeGen::GlobalDecl> {
85 33829: static inline clang::CodeGen::GlobalDecl getEmptyKey() {
86 33829: return clang::CodeGen::GlobalDecl();
87 : }
88 :
89 23809: static inline clang::CodeGen::GlobalDecl getTombstoneKey() {
90 : return clang::CodeGen::GlobalDecl::
91 23809: getFromOpaquePtr(reinterpret_cast<void*>(-1));
92 : }
93 :
94 12990: static unsigned getHashValue(clang::CodeGen::GlobalDecl GD) {
95 12990: return DenseMapInfo<void*>::getHashValue(GD.getAsOpaquePtr());
96 : }
97 :
98 : static bool isEqual(clang::CodeGen::GlobalDecl LHS,
99 426691: clang::CodeGen::GlobalDecl RHS) {
100 426691: return LHS == RHS;
101 : }
102 :
103 : };
104 :
105 : // GlobalDecl isn't *technically* a POD type. However, its copy constructor,
106 : // copy assignment operator, and destructor are all trivial.
107 : template <>
108 : struct isPodLike<clang::CodeGen::GlobalDecl> {
109 : static const bool value = true;
110 : };
111 : } // end namespace llvm
112 :
113 : #endif
Generated: 2010-02-10 01:31 by zcov