blob: 15951fe87607731f837db2532e769f1f84fd9d6c [file] [log] [blame]
Douglas Gregor6ec36682009-02-18 23:53:56 +00001//===--- Mangle.h - Mangle C++ Names ----------------------------*- C++ -*-===//
Douglas Gregor5f2bfd42009-02-13 00:10:09 +00002//
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//===----------------------------------------------------------------------===//
Chris Lattnerca3f25c2009-03-21 08:24:40 +000017
Douglas Gregor5f2bfd42009-02-13 00:10:09 +000018#ifndef LLVM_CLANG_CODEGEN_MANGLE_H
19#define LLVM_CLANG_CODEGEN_MANGLE_H
20
Anders Carlsson3ac86b52009-04-15 05:36:58 +000021#include "CGCXX.h"
Mike Stumpf1216772009-07-31 18:25:34 +000022#include "clang/AST/Type.h"
Anders Carlssonc4355b62009-10-07 01:45:02 +000023#include "llvm/ADT/DenseMap.h"
Anders Carlsson3ac86b52009-04-15 05:36:58 +000024
Douglas Gregor5f2bfd42009-02-13 00:10:09 +000025namespace llvm {
Daniel Dunbar94fd26d2009-11-21 09:06:22 +000026template<typename T>
27class SmallVectorImpl;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +000028}
29
30namespace clang {
Daniel Dunbar1b077112009-11-21 09:06:10 +000031class ASTContext;
32class CXXConstructorDecl;
33class CXXDestructorDecl;
34class FunctionDecl;
35class NamedDecl;
36class VarDecl;
Mike Stump1eb44332009-09-09 15:08:12 +000037
Daniel Dunbar1b077112009-11-21 09:06:10 +000038/// MangleContext - Context for tracking state which persists across multiple
39/// calls to the C++ name mangler.
40class MangleContext {
41 ASTContext &Context;
Anders Carlssonc4355b62009-10-07 01:45:02 +000042
Daniel Dunbar1b077112009-11-21 09:06:10 +000043 llvm::DenseMap<const TagDecl *, uint64_t> AnonStructIds;
44
45public:
46 explicit MangleContext(ASTContext &Context)
Anders Carlssonb5404912009-10-07 01:06:45 +000047 : Context(Context) { }
Anders Carlssonb5404912009-10-07 01:06:45 +000048
Daniel Dunbar1b077112009-11-21 09:06:10 +000049 ASTContext &getASTContext() const { return Context; }
50
51 uint64_t getAnonymousStructId(const TagDecl *TD) {
52 std::pair<llvm::DenseMap<const TagDecl *,
53 uint64_t>::iterator, bool> Result =
54 AnonStructIds.insert(std::make_pair(TD, AnonStructIds.size()));
55 return Result.first->second;
56 }
57
58 /// @name Mangler Entry Points
59 /// @{
60
Daniel Dunbarf981bf82009-11-21 09:14:52 +000061 bool shouldMangleDeclName(const NamedDecl *D);
62
63 void mangleName(const NamedDecl *D, llvm::SmallVectorImpl<char> &);
Anders Carlssona94822e2009-11-26 02:32:05 +000064 void mangleThunk(const FunctionDecl *FD,
65 int64_t NonVirtualOffset, int64_t VirtualOffset,
Daniel Dunbar94fd26d2009-11-21 09:06:22 +000066 llvm::SmallVectorImpl<char> &);
Daniel Dunbar1b077112009-11-21 09:06:10 +000067 void mangleCovariantThunk(const FunctionDecl *FD, int64_t nv_t, int64_t v_t,
Daniel Dunbar94fd26d2009-11-21 09:06:22 +000068 int64_t nv_r, int64_t v_r,
69 llvm::SmallVectorImpl<char> &);
70 void mangleGuardVariable(const VarDecl *D, llvm::SmallVectorImpl<char> &);
71 void mangleCXXVtable(const CXXRecordDecl *RD, llvm::SmallVectorImpl<char> &);
72 void mangleCXXVTT(const CXXRecordDecl *RD, llvm::SmallVectorImpl<char> &);
Daniel Dunbar1b077112009-11-21 09:06:10 +000073 void mangleCXXCtorVtable(const CXXRecordDecl *RD, int64_t Offset,
Daniel Dunbar94fd26d2009-11-21 09:06:22 +000074 const CXXRecordDecl *Type,
75 llvm::SmallVectorImpl<char> &);
76 void mangleCXXRtti(QualType T, llvm::SmallVectorImpl<char> &);
77 void mangleCXXRttiName(QualType T, llvm::SmallVectorImpl<char> &);
Daniel Dunbar1b077112009-11-21 09:06:10 +000078 void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
Daniel Dunbar94fd26d2009-11-21 09:06:22 +000079 llvm::SmallVectorImpl<char> &);
Daniel Dunbar1b077112009-11-21 09:06:10 +000080 void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
Daniel Dunbar94fd26d2009-11-21 09:06:22 +000081 llvm::SmallVectorImpl<char> &);
Daniel Dunbar1b077112009-11-21 09:06:10 +000082
83 /// @}
84};
Douglas Gregor5f2bfd42009-02-13 00:10:09 +000085}
86
Mike Stump1eb44332009-09-09 15:08:12 +000087#endif