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>()) {
131 if (GlobalPrefix && !ALA->getLabel().startswith(
"llvm."))
134 Out << ALA->getLabel();
173 assert(!Proto->isVariadic());
174 unsigned ArgWords = 0;
178 for (
const auto &AT : Proto->param_types())
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);
214 raw_ostream &ResStream) {
216 llvm::raw_svector_ostream Out(Buffer);
223 assert(!isa<CXXConstructorDecl>(DC) && !isa<CXXDestructorDecl>(DC));
226 llvm::raw_svector_ostream Stream(Buffer);
227 if (
const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(DC)) {
230 assert((isa<NamedDecl>(DC) || isa<BlockDecl>(DC)) &&
231 "expected a NamedDecl or BlockDecl");
232 if (isa<BlockDecl>(DC))
233 for (; DC && isa<BlockDecl>(DC); DC = DC->
getParent())
235 assert((isa<TranslationUnitDecl>(DC) || isa<NamedDecl>(DC)) &&
236 "expected a TranslationUnitDecl or a NamedDecl");
237 if (
const auto *CD = dyn_cast<CXXConstructorDecl>(DC))
239 else if (
const auto *DD = dyn_cast<CXXDestructorDecl>(DC))
241 else if (
auto ND = dyn_cast<NamedDecl>(DC)) {
243 Stream << ND->getIdentifier()->getName();
261 assert (CD &&
"Missing container decl in GetNameForMethod");
264 OS <<
'(' << *CID <<
')';
273 llvm::raw_svector_ostream OS(Name);
276 Out << OS.str().size() << OS.str();
Defines the clang::ASTContext interface.
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
A (possibly-)qualified type.
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
FunctionType - C99 6.7.5.3 - Function Declarators.
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
std::unique_ptr< llvm::MemoryBuffer > Buffer
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.
ObjCMethodDecl - Represents an instance or class method declaration.
Defines the clang::Expr interface and subclasses for C++ expressions.
void mangleObjCMethodNameWithoutSize(const ObjCMethodDecl *MD, raw_ostream &)
static CCMangling getCallingConvMangling(const ASTContext &Context, const NamedDecl *ND)
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
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
ObjCContainerDecl - Represents a container for method declarations.
const LangOptions & getLangOpts() const
The Microsoft ABI is the ABI used by Microsoft Visual Studio (and compatible compilers).
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 &)
Represents a prototype with parameter type info, e.g.
Exposes information about the current target.
CXXDtorType
C++ destructor types.
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
StringRef getName() const
Return the actual identifier string.
Represents a C++ destructor within a class.
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.
MangleContext - Context for tracking state which persists across multiple calls to the C++ name mangl...
virtual void mangleCXXName(const NamedDecl *D, raw_ostream &)=0
const T * castAs() const
Member-template castAs<specific type>.
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)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
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.
NamedDecl - This represents a decl with a name.
const llvm::DataLayout & getDataLayout() const
void mangleCtorBlock(const CXXConstructorDecl *CD, CXXCtorType CT, const BlockDecl *BD, raw_ostream &Out)
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
static bool isExternC(const NamedDecl *ND)