blob: 8d9629528d632e61b80c28bf016ee8586bebc3af [file] [log] [blame]
Shih-wei Liaof8fd82b2010-02-10 11:10:31 -08001//===--- Mangle.h - Mangle C++ Names ----------------------------*- 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// Implements C++ name mangling according to the Itanium C++ ABI,
11// which is used in GCC 3.2 and newer (and many compilers that are
12// ABI-compatible with GCC):
13//
14// http://www.codesourcery.com/public/cxx-abi/abi.html
15//
16//===----------------------------------------------------------------------===//
17
18#ifndef LLVM_CLANG_CODEGEN_MANGLE_H
19#define LLVM_CLANG_CODEGEN_MANGLE_H
20
21#include "CGCXX.h"
22#include "clang/AST/Type.h"
23#include "llvm/ADT/DenseMap.h"
24
25namespace llvm {
26 template<typename T> class SmallVectorImpl;
27}
28
29namespace clang {
30 class ASTContext;
31 class CXXConstructorDecl;
32 class CXXDestructorDecl;
33 class FunctionDecl;
34 class NamedDecl;
35 class VarDecl;
36
37namespace CodeGen {
38 class CovariantThunkAdjustment;
39 class ThunkAdjustment;
40
41/// MangleContext - Context for tracking state which persists across multiple
42/// calls to the C++ name mangler.
43class MangleContext {
44 ASTContext &Context;
45
46 llvm::DenseMap<const TagDecl *, uint64_t> AnonStructIds;
47
48public:
49 explicit MangleContext(ASTContext &Context)
50 : Context(Context) { }
51
52 ASTContext &getASTContext() const { return Context; }
53
54 uint64_t getAnonymousStructId(const TagDecl *TD) {
55 std::pair<llvm::DenseMap<const TagDecl *,
56 uint64_t>::iterator, bool> Result =
57 AnonStructIds.insert(std::make_pair(TD, AnonStructIds.size()));
58 return Result.first->second;
59 }
60
61 /// @name Mangler Entry Points
62 /// @{
63
64 bool shouldMangleDeclName(const NamedDecl *D);
65
66 void mangleName(const NamedDecl *D, llvm::SmallVectorImpl<char> &);
67 void mangleThunk(const FunctionDecl *FD,
68 const ThunkAdjustment &ThisAdjustment,
69 llvm::SmallVectorImpl<char> &);
70 void mangleCXXDtorThunk(const CXXDestructorDecl *D, CXXDtorType Type,
71 const ThunkAdjustment &ThisAdjustment,
72 llvm::SmallVectorImpl<char> &);
73 void mangleCovariantThunk(const FunctionDecl *FD,
74 const CovariantThunkAdjustment& Adjustment,
75 llvm::SmallVectorImpl<char> &);
76 void mangleGuardVariable(const VarDecl *D, llvm::SmallVectorImpl<char> &);
77 void mangleCXXVtable(const CXXRecordDecl *RD, llvm::SmallVectorImpl<char> &);
78 void mangleCXXVTT(const CXXRecordDecl *RD, llvm::SmallVectorImpl<char> &);
79 void mangleCXXCtorVtable(const CXXRecordDecl *RD, int64_t Offset,
80 const CXXRecordDecl *Type,
81 llvm::SmallVectorImpl<char> &);
82 void mangleCXXRTTI(QualType T, llvm::SmallVectorImpl<char> &);
83 void mangleCXXRTTIName(QualType T, llvm::SmallVectorImpl<char> &);
84 void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
85 llvm::SmallVectorImpl<char> &);
86 void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
87 llvm::SmallVectorImpl<char> &);
88
89 /// @}
90};
91
92}
93}
94
95#endif