Implement mangling of declarations inside functions.

llvm-svn: 68321
This commit is contained in:
Anders Carlsson 2009-04-02 16:24:45 +00:00
parent f2125a02db
commit 4eca109941
2 changed files with 18 additions and 3 deletions

View File

@ -42,6 +42,7 @@ namespace {
void mangleName(const NamedDecl *ND); void mangleName(const NamedDecl *ND);
void mangleUnqualifiedName(const NamedDecl *ND); void mangleUnqualifiedName(const NamedDecl *ND);
void mangleSourceName(const IdentifierInfo *II); void mangleSourceName(const IdentifierInfo *II);
void mangleLocalName(const NamedDecl *ND);
void mangleNestedName(const NamedDecl *ND); void mangleNestedName(const NamedDecl *ND);
void manglePrefix(const DeclContext *DC); void manglePrefix(const DeclContext *DC);
void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity); void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity);
@ -149,9 +150,10 @@ void CXXNameMangler::mangleName(const NamedDecl *ND) {
else if (isStdNamespace(ND->getDeclContext())) { else if (isStdNamespace(ND->getDeclContext())) {
Out << "St"; Out << "St";
mangleUnqualifiedName(ND); mangleUnqualifiedName(ND);
} else { } else if (isa<FunctionDecl>(ND->getDeclContext()))
mangleLocalName(ND);
else
mangleNestedName(ND); mangleNestedName(ND);
}
} }
void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND) { void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND) {
@ -226,6 +228,16 @@ void CXXNameMangler::mangleNestedName(const NamedDecl *ND) {
Out << 'E'; Out << 'E';
} }
void CXXNameMangler::mangleLocalName(const NamedDecl *ND) {
// <local-name> := Z <function encoding> E <entity name> [<discriminator>]
// := Z <function encoding> E s [<discriminator>]
// <discriminator> := _ <non-negative number>
Out << 'Z';
mangleFunctionEncoding(cast<FunctionDecl>(ND->getDeclContext()));
Out << 'E';
mangleSourceName(ND->getIdentifier());
}
void CXXNameMangler::manglePrefix(const DeclContext *DC) { void CXXNameMangler::manglePrefix(const DeclContext *DC) {
// <prefix> ::= <prefix> <unqualified-name> // <prefix> ::= <prefix> <unqualified-name>
// ::= <template-prefix> <template-args> // ::= <template-prefix> <template-args>

View File

@ -39,5 +39,8 @@ extern "C" { namespace N { void unmangled_function() { } } }
// RUN: grep unmangled_variable %t | count 1 && // RUN: grep unmangled_variable %t | count 1 &&
extern "C" { namespace N { int unmangled_variable; } } extern "C" { namespace N { int unmangled_variable; } }
// RUN: grep _ZN1N1iE %t | count 1 // RUN: grep _ZN1N1iE %t | count 1 &&
namespace N { int i; } namespace N { int i; }
// RUN: grep _ZZN1N1fEiiE1b %t | count 2
namespace N { int f(int, int) { static int b; return b; } }