2009-02-19 02:53:56 +03:00
|
|
|
//===--- Mangle.h - Mangle C++ Names ----------------------------*- C++ -*-===//
|
2009-02-13 03:10:09 +03:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Implements C++ name mangling according to the Itanium C++ ABI,
|
|
|
|
// which is used in GCC 3.2 and newer (and many compilers that are
|
|
|
|
// ABI-compatible with GCC):
|
|
|
|
//
|
|
|
|
// http://www.codesourcery.com/public/cxx-abi/abi.html
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-03-21 11:24:40 +03:00
|
|
|
|
2009-02-13 03:10:09 +03:00
|
|
|
#ifndef LLVM_CLANG_CODEGEN_MANGLE_H
|
|
|
|
#define LLVM_CLANG_CODEGEN_MANGLE_H
|
|
|
|
|
2009-04-15 09:36:58 +04:00
|
|
|
#include "CGCXX.h"
|
2009-07-31 22:25:34 +04:00
|
|
|
#include "clang/AST/Type.h"
|
2009-10-07 05:45:02 +04:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2010-03-20 02:29:14 +03:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/ADT/SmallString.h"
|
2009-02-13 03:10:09 +03:00
|
|
|
|
|
|
|
namespace clang {
|
2009-11-26 05:49:32 +03:00
|
|
|
class ASTContext;
|
|
|
|
class CXXConstructorDecl;
|
|
|
|
class CXXDestructorDecl;
|
2010-03-23 20:17:29 +03:00
|
|
|
class CXXMethodDecl;
|
2009-11-26 05:49:32 +03:00
|
|
|
class FunctionDecl;
|
|
|
|
class NamedDecl;
|
|
|
|
class VarDecl;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-11-26 05:49:32 +03:00
|
|
|
namespace CodeGen {
|
2010-03-24 19:59:08 +03:00
|
|
|
struct ThisAdjustment;
|
|
|
|
struct ThunkInfo;
|
2010-03-20 02:29:14 +03:00
|
|
|
|
|
|
|
/// MangleBuffer - a convenient class for storing a name which is
|
|
|
|
/// either the result of a mangling or is a constant string with
|
|
|
|
/// external memory ownership.
|
|
|
|
class MangleBuffer {
|
|
|
|
public:
|
|
|
|
void setString(llvm::StringRef Ref) {
|
|
|
|
String = Ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::SmallVectorImpl<char> &getBuffer() {
|
|
|
|
return Buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::StringRef getString() const {
|
|
|
|
if (!String.empty()) return String;
|
|
|
|
return Buffer.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
operator llvm::StringRef() const {
|
|
|
|
return getString();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
llvm::StringRef String;
|
|
|
|
llvm::SmallString<256> Buffer;
|
|
|
|
};
|
2009-11-26 05:49:32 +03:00
|
|
|
|
2009-11-21 12:06:10 +03:00
|
|
|
/// MangleContext - Context for tracking state which persists across multiple
|
|
|
|
/// calls to the C++ name mangler.
|
|
|
|
class MangleContext {
|
|
|
|
ASTContext &Context;
|
2010-04-10 02:26:14 +04:00
|
|
|
Diagnostic &Diags;
|
2009-10-07 05:45:02 +04:00
|
|
|
|
2009-11-21 12:06:10 +03:00
|
|
|
llvm::DenseMap<const TagDecl *, uint64_t> AnonStructIds;
|
2010-03-04 04:02:03 +03:00
|
|
|
unsigned Discriminator;
|
|
|
|
llvm::DenseMap<const NamedDecl*, unsigned> Uniquifier;
|
|
|
|
|
2009-11-21 12:06:10 +03:00
|
|
|
public:
|
2010-04-10 02:26:14 +04:00
|
|
|
explicit MangleContext(ASTContext &Context,
|
|
|
|
Diagnostic &Diags)
|
|
|
|
: Context(Context), Diags(Diags) { }
|
2009-11-21 12:06:10 +03:00
|
|
|
|
|
|
|
ASTContext &getASTContext() const { return Context; }
|
|
|
|
|
2010-04-10 02:26:14 +04:00
|
|
|
Diagnostic &getDiags() const { return Diags; }
|
|
|
|
|
2009-11-21 12:06:10 +03:00
|
|
|
uint64_t getAnonymousStructId(const TagDecl *TD) {
|
|
|
|
std::pair<llvm::DenseMap<const TagDecl *,
|
|
|
|
uint64_t>::iterator, bool> Result =
|
2009-10-07 05:45:02 +04:00
|
|
|
AnonStructIds.insert(std::make_pair(TD, AnonStructIds.size()));
|
2009-11-21 12:06:10 +03:00
|
|
|
return Result.first->second;
|
|
|
|
}
|
2009-10-07 05:06:45 +04:00
|
|
|
|
2009-11-21 12:06:10 +03:00
|
|
|
/// @name Mangler Entry Points
|
|
|
|
/// @{
|
|
|
|
|
2009-11-21 12:14:52 +03:00
|
|
|
bool shouldMangleDeclName(const NamedDecl *D);
|
|
|
|
|
|
|
|
void mangleName(const NamedDecl *D, llvm::SmallVectorImpl<char> &);
|
2010-03-23 20:17:29 +03:00
|
|
|
void mangleThunk(const CXXMethodDecl *MD,
|
|
|
|
const ThunkInfo &Thunk,
|
|
|
|
llvm::SmallVectorImpl<char> &);
|
|
|
|
void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type,
|
|
|
|
const ThisAdjustment &ThisAdjustment,
|
|
|
|
llvm::SmallVectorImpl<char> &);
|
2009-11-21 12:06:22 +03:00
|
|
|
void mangleGuardVariable(const VarDecl *D, llvm::SmallVectorImpl<char> &);
|
2010-04-18 00:15:18 +04:00
|
|
|
void mangleCXXVTable(const CXXRecordDecl *RD, llvm::SmallVectorImpl<char> &);
|
2009-11-21 12:06:22 +03:00
|
|
|
void mangleCXXVTT(const CXXRecordDecl *RD, llvm::SmallVectorImpl<char> &);
|
2010-04-18 00:15:18 +04:00
|
|
|
void mangleCXXCtorVTable(const CXXRecordDecl *RD, int64_t Offset,
|
2009-11-21 12:06:22 +03:00
|
|
|
const CXXRecordDecl *Type,
|
|
|
|
llvm::SmallVectorImpl<char> &);
|
2009-12-02 21:57:08 +03:00
|
|
|
void mangleCXXRTTI(QualType T, llvm::SmallVectorImpl<char> &);
|
|
|
|
void mangleCXXRTTIName(QualType T, llvm::SmallVectorImpl<char> &);
|
2009-11-21 12:06:10 +03:00
|
|
|
void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
|
2009-11-21 12:06:22 +03:00
|
|
|
llvm::SmallVectorImpl<char> &);
|
2009-11-21 12:06:10 +03:00
|
|
|
void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
|
2009-11-21 12:06:22 +03:00
|
|
|
llvm::SmallVectorImpl<char> &);
|
2010-03-04 04:02:03 +03:00
|
|
|
|
|
|
|
void mangleInitDiscriminator() {
|
|
|
|
Discriminator = 0;
|
|
|
|
}
|
2009-11-21 12:06:10 +03:00
|
|
|
|
2010-03-04 04:02:03 +03:00
|
|
|
bool getNextDiscriminator(const NamedDecl *ND, unsigned &disc) {
|
|
|
|
unsigned &discriminator = Uniquifier[ND];
|
|
|
|
if (!discriminator)
|
|
|
|
discriminator = ++Discriminator;
|
|
|
|
if (discriminator == 1)
|
|
|
|
return false;
|
|
|
|
disc = discriminator-2;
|
|
|
|
return true;
|
|
|
|
}
|
2009-11-21 12:06:10 +03:00
|
|
|
/// @}
|
|
|
|
};
|
2009-11-26 05:49:32 +03:00
|
|
|
|
|
|
|
}
|
2009-02-13 03:10:09 +03:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
#endif
|