24 #include "llvm/ADT/StringExtras.h"
25 #include "llvm/Support/ErrorHandling.h"
26 #include "llvm/Support/raw_ostream.h"
28 #define MANGLE_CHECKER 0
34 using namespace clang;
43 unsigned discriminator = Context.
getBlockId(BD,
true);
44 if (discriminator == 0)
45 Out <<
"__" << Outer <<
"_block_invoke";
47 Out <<
"__" << Outer <<
"_block_invoke_" << discriminator+1;
50 void MangleContext::anchor() { }
61 return FD->isExternC();
68 const llvm::Triple &Triple = TI.
getTriple();
69 if (!Triple.isOSWindows() ||
70 !(Triple.getArch() == llvm::Triple::x86 ||
71 Triple.getArch() == llvm::Triple::x86_64))
111 if (D->
hasAttr<AsmLabelAttr>())
120 if (
const AsmLabelAttr *ALA = D->
getAttr<AsmLabelAttr>()) {
129 StringRef UserLabelPrefix =
131 if (!UserLabelPrefix.empty() && !ALA->getLabel().startswith(
"llvm."))
134 Out << ALA->getLabel();
173 assert(!Proto->isVariadic());
174 unsigned ArgWords = 0;
178 for (
const auto &AT : Proto->param_types())
180 ArgWords += llvm::RoundUpToAlignment(ASTContext.
getTypeSize(AT),
189 unsigned discriminator =
getBlockId(BD,
false);
197 if (discriminator == 0)
198 Out <<
"_block_invoke";
200 Out <<
"_block_invoke_" << discriminator+1;
205 raw_ostream &ResStream) {
207 llvm::raw_svector_ostream Out(Buffer);
215 raw_ostream &ResStream) {
217 llvm::raw_svector_ostream Out(Buffer);
225 assert(!isa<CXXConstructorDecl>(DC) && !isa<CXXDestructorDecl>(DC));
228 llvm::raw_svector_ostream Stream(Buffer);
229 if (
const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(DC)) {
232 assert((isa<NamedDecl>(DC) || isa<BlockDecl>(DC)) &&
233 "expected a NamedDecl or BlockDecl");
234 if (isa<BlockDecl>(DC))
235 for (; DC && isa<BlockDecl>(DC); DC = DC->
getParent())
237 assert((isa<TranslationUnitDecl>(DC) || isa<NamedDecl>(DC)) &&
238 "expected a TranslationUnitDecl or a NamedDecl");
239 if (
const auto *CD = dyn_cast<CXXConstructorDecl>(DC))
241 else if (
const auto *DD = dyn_cast<CXXDestructorDecl>(DC))
243 else if (
auto ND = dyn_cast<NamedDecl>(DC)) {
245 Stream << ND->getIdentifier()->getName();
263 llvm::raw_svector_ostream OS(Name);
267 assert (CD &&
"Missing container decl in GetNameForMethod");
270 OS <<
'(' << *CID <<
')';
275 Out << OS.str().size() << OS.str();
Defines the clang::ASTContext interface.
StringRef getName() const
IdentifierInfo * getIdentifier() const
virtual void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type, raw_ostream &)=0
Defines the SourceManager interface.
virtual void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type, raw_ostream &)=0
Defines the C++ template declaration subclasses.
ASTContext & getASTContext() const
Represents a C++ constructor within a class.
CallingConv getCallConv() const
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Defines the clang::Expr interface and subclasses for C++ expressions.
static CCMangling getCallingConvMangling(const ASTContext &Context, const NamedDecl *ND)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool shouldMangleDeclName(const NamedDecl *D)
const TargetInfo & getTargetInfo() const
const LangOptions & getLangOpts() const
Enums/classes describing ABI related information about constructors, destructors and thunks...
void print(llvm::raw_ostream &OS) const
Prints the full selector name (e.g. "foo:bar:").
void mangleName(const NamedDecl *D, raw_ostream &)
ID
Defines the set of possible language-specific address spaces.
Exposes information about the current target.
CXXDtorType
C++ destructor types.
const char * getUserLabelPrefix() const
Returns the default value of the USER_LABEL_PREFIX macro, which is the prefix given to user symbols b...
StringRef getName() const
Return the actual identifier string.
Represents a C++ destructor within a class.
DeclContext * getDeclContext()
bool isInstanceMethod() const
DeclContext * getParent()
getParent - Returns the containing DeclContext.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
unsigned getBlockId(const BlockDecl *BD, bool Local)
void mangleDtorBlock(const CXXDestructorDecl *CD, CXXDtorType DT, const BlockDecl *BD, raw_ostream &Out)
virtual bool shouldMangleCXXName(const NamedDecl *D)=0
Represents a static or instance method of a struct/union/class.
virtual void mangleCXXName(const NamedDecl *D, raw_ostream &)=0
CXXCtorType
C++ constructor types.
void mangleGlobalBlock(const BlockDecl *BD, const NamedDecl *ID, raw_ostream &Out)
void mangleBlock(const DeclContext *DC, const BlockDecl *BD, raw_ostream &Out)
void mangleObjCMethodName(const ObjCMethodDecl *MD, raw_ostream &)
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Selector getSelector() const
static void mangleFunctionBlock(MangleContext &Context, StringRef Outer, const BlockDecl *BD, raw_ostream &Out)
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Defines the clang::TargetInfo interface.
void mangleCtorBlock(const CXXConstructorDecl *CD, CXXCtorType CT, const BlockDecl *BD, raw_ostream &Out)
static bool isExternC(const NamedDecl *ND)