151 lines
5.1 KiB
C
Raw Normal View History

2009-06-02 17:58:47 +00:00
//===--- Mangle.h - Mangle C++ Names ----------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Defines the C++ name mangling interface.
2009-06-02 17:58:47 +00:00
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_AST_MANGLE_H
#define LLVM_CLANG_AST_MANGLE_H
2009-06-02 17:58:47 +00:00
2009-10-14 18:03:49 +00:00
#include "clang/AST/Type.h"
#include "clang/Basic/ABI.h"
2009-10-14 18:03:49 +00:00
#include "llvm/ADT/DenseMap.h"
2010-03-21 10:50:08 +00:00
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/SmallString.h"
2010-05-27 15:17:06 +00:00
#include "llvm/Support/raw_ostream.h"
2009-06-02 17:58:47 +00:00
namespace clang {
class ASTContext;
2010-05-27 15:17:06 +00:00
class BlockDecl;
2009-06-02 17:58:47 +00:00
class CXXConstructorDecl;
class CXXDestructorDecl;
2010-04-02 08:55:10 +00:00
class CXXMethodDecl;
2009-10-14 18:03:49 +00:00
class FunctionDecl;
2009-06-02 17:58:47 +00:00
class NamedDecl;
2010-05-27 15:17:06 +00:00
class ObjCMethodDecl;
2009-06-02 17:58:47 +00:00
class VarDecl;
2010-04-02 08:55:10 +00:00
struct ThisAdjustment;
struct ThunkInfo;
2010-03-21 10:50:08 +00: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;
};
2010-05-27 15:17:06 +00:00
2009-12-01 11:08:04 +00:00
/// MangleContext - Context for tracking state which persists across multiple
/// calls to the C++ name mangler.
class MangleContext {
ASTContext &Context;
2010-05-04 16:12:48 +00:00
Diagnostic &Diags;
2009-10-14 18:03:49 +00:00
2010-05-27 15:17:06 +00:00
llvm::DenseMap<const BlockDecl*, unsigned> GlobalBlockIds;
llvm::DenseMap<const BlockDecl*, unsigned> LocalBlockIds;
2010-03-06 09:23:02 +00:00
2009-12-01 11:08:04 +00:00
public:
2010-05-04 16:12:48 +00:00
explicit MangleContext(ASTContext &Context,
Diagnostic &Diags)
: Context(Context), Diags(Diags) { }
2009-12-01 11:08:04 +00:00
2010-07-13 17:21:42 +00:00
virtual ~MangleContext() { }
2009-12-01 11:08:04 +00:00
ASTContext &getASTContext() const { return Context; }
2010-05-04 16:12:48 +00:00
Diagnostic &getDiags() const { return Diags; }
virtual void startNewFunction() { LocalBlockIds.clear(); }
2010-05-27 15:17:06 +00:00
unsigned getBlockId(const BlockDecl *BD, bool Local) {
llvm::DenseMap<const BlockDecl *, unsigned> &BlockIds
= Local? LocalBlockIds : GlobalBlockIds;
std::pair<llvm::DenseMap<const BlockDecl *, unsigned>::iterator, bool>
Result = BlockIds.insert(std::make_pair(BD, BlockIds.size()));
return Result.first->second;
}
2009-12-01 11:08:04 +00:00
/// @name Mangler Entry Points
/// @{
2009-10-14 18:03:49 +00:00
virtual bool shouldMangleDeclName(const NamedDecl *D) = 0;
virtual void mangleName(const NamedDecl *D, llvm::raw_ostream &)=0;
2010-05-27 15:17:06 +00:00
virtual void mangleThunk(const CXXMethodDecl *MD,
const ThunkInfo &Thunk,
llvm::raw_ostream &) = 0;
2010-05-27 15:17:06 +00:00
virtual void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type,
const ThisAdjustment &ThisAdjustment,
llvm::raw_ostream &) = 0;
2010-07-13 17:21:42 +00:00
virtual void mangleReferenceTemporary(const VarDecl *D,
llvm::raw_ostream &) = 0;
2010-05-27 15:17:06 +00:00
virtual void mangleCXXVTable(const CXXRecordDecl *RD,
llvm::raw_ostream &) = 0;
2010-05-27 15:17:06 +00:00
virtual void mangleCXXVTT(const CXXRecordDecl *RD,
llvm::raw_ostream &) = 0;
2010-05-27 15:17:06 +00:00
virtual void mangleCXXCtorVTable(const CXXRecordDecl *RD, int64_t Offset,
const CXXRecordDecl *Type,
llvm::raw_ostream &) = 0;
virtual void mangleCXXRTTI(QualType T, llvm::raw_ostream &) = 0;
virtual void mangleCXXRTTIName(QualType T, llvm::raw_ostream &) = 0;
2010-05-27 15:17:06 +00:00
virtual void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
llvm::raw_ostream &) = 0;
2010-05-27 15:17:06 +00:00
virtual void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
llvm::raw_ostream &) = 0;
void mangleGlobalBlock(const BlockDecl *BD,
llvm::raw_ostream &Out);
void mangleCtorBlock(const CXXConstructorDecl *CD, CXXCtorType CT,
const BlockDecl *BD, llvm::raw_ostream &Out);
void mangleDtorBlock(const CXXDestructorDecl *CD, CXXDtorType DT,
const BlockDecl *BD, llvm::raw_ostream &Out);
void mangleBlock(const DeclContext *DC, const BlockDecl *BD,
llvm::raw_ostream &Out);
// Do the right thing.
void mangleBlock(const BlockDecl *BD, llvm::raw_ostream &Out);
void mangleObjCMethodName(const ObjCMethodDecl *MD,
llvm::raw_ostream &);
// This is pretty lame.
virtual void mangleItaniumGuardVariable(const VarDecl *D,
llvm::raw_ostream &) {
assert(0 && "Target does not support mangling guard variables");
2010-03-06 09:23:02 +00:00
}
2009-12-01 11:08:04 +00:00
/// @}
};
2010-05-27 15:17:06 +00:00
MangleContext *createItaniumMangleContext(ASTContext &Context,
Diagnostic &Diags);
MangleContext *createMicrosoftMangleContext(ASTContext &Context,
Diagnostic &Diags);
2010-05-27 15:17:06 +00:00
2009-06-02 17:58:47 +00:00
}
2009-10-14 18:03:49 +00:00
#endif