summaryrefslogtreecommitdiffstats
path: root/include/clang/Sema/Scope.h
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-03-05 08:57:59 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-03-05 08:57:59 +0000
commitadb19e62bb227aa5ba8eac89731f54f3007ab8fb (patch)
tree6feb3afef5cdb2b0c006d6a8488adfe1c26f7207 /include/clang/Sema/Scope.h
parent9d33e30aba42a968017b1bfe51951337322f06eb (diff)
[-cxx-abi microsoft] Implement local manglings accurately
Summary: The MSVC ABI appears to mangle the lexical scope into the names of statics. Specifically, a counter is incremented whenever a scope is entered where things can be declared in such a way that an ambiguity can arise. For example, a class scope inside of a class scope doesn't do anything interesting because the nested class cannot collide with another nested class. There are problems with this scheme: - It is unreliable. The counter is only incremented when a previously never encountered scope is entered. There are cases where this will cause ambiguity amongst declarations that have the same name where one was introduced in a deep scope while the other was introduced right after in the previous lexical scope. - It is wasteful. Statements like: {{{{{{{ static int foo = a; }}}}}}} will make the mangling of "foo" larger than it need be because the scope counter has been incremented many times. Because of these problems, and practical implementation concerns. We choose not to implement this scheme if the local static or local type isn't visible. The mangling of these declarations will look very similar but the numbering will make far more sense, this scheme is lifted from the Itanium ABI implementation. Reviewers: rsmith, doug.gregor, rnk, eli.friedman, cdavis5x Reviewed By: rnk CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D2953 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202951 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Sema/Scope.h')
-rw-r--r--include/clang/Sema/Scope.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/include/clang/Sema/Scope.h b/include/clang/Sema/Scope.h
index 7e15fdeafd..21e5cde3f7 100644
--- a/include/clang/Sema/Scope.h
+++ b/include/clang/Sema/Scope.h
@@ -18,6 +18,12 @@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
+namespace llvm {
+
+class raw_ostream;
+
+}
+
namespace clang {
class Decl;
@@ -109,6 +115,10 @@ private:
/// interrelates with other control flow statements.
unsigned short Flags;
+ /// \brief Declarations with static linkage are mangled with the number of
+ /// scopes seen as a component.
+ unsigned short MSLocalManglingNumber;
+
/// PrototypeDepth - This is the number of function prototype scopes
/// enclosing this scope, including this scope.
unsigned short PrototypeDepth;
@@ -120,6 +130,7 @@ private:
/// FnParent - If this scope has a parent scope that is a function body, this
/// pointer is non-null and points to it. This is used for label processing.
Scope *FnParent;
+ Scope *MSLocalManglingParent;
/// BreakParent/ContinueParent - This is a direct link to the innermost
/// BreakScope/ContinueScope which contains the contents of this scope
@@ -181,6 +192,11 @@ public:
const Scope *getFnParent() const { return FnParent; }
Scope *getFnParent() { return FnParent; }
+ const Scope *getMSLocalManglingParent() const {
+ return MSLocalManglingParent;
+ }
+ Scope *getMSLocalManglingParent() { return MSLocalManglingParent; }
+
/// getContinueParent - Return the closest scope that a continue statement
/// would be affected by.
Scope *getContinueParent() {
@@ -232,6 +248,22 @@ public:
DeclsInScope.erase(D);
}
+ void incrementMSLocalManglingNumber() {
+ if (Scope *MSLMP = getMSLocalManglingParent())
+ MSLMP->MSLocalManglingNumber += 1;
+ }
+
+ void decrementMSLocalManglingNumber() {
+ if (Scope *MSLMP = getMSLocalManglingParent())
+ MSLMP->MSLocalManglingNumber -= 1;
+ }
+
+ unsigned getMSLocalManglingNumber() const {
+ if (const Scope *MSLMP = getMSLocalManglingParent())
+ return MSLMP->MSLocalManglingNumber;
+ return 1;
+ }
+
/// isDeclScope - Return true if this is the scope that the specified decl is
/// declared in.
bool isDeclScope(Decl *D) {
@@ -359,6 +391,9 @@ public:
/// variables accordingly.
///
void AddFlags(unsigned Flags);
+
+ void dumpImpl(raw_ostream &OS) const;
+ void dump() const;
};
} // end namespace clang