From 84abcafaed59e34643ab72c571ad12235c895a37 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Wed, 5 Mar 2014 18:55:38 +0000 Subject: [PATCH] AST: Remove layering violation with Sema Scope lives in Sema and cannot be used in AST. Shuffle things around. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202993 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/MangleNumberingContext.h | 7 ++++--- include/clang/Parse/Parser.h | 5 ++++- include/clang/Sema/Sema.h | 5 +++++ lib/AST/ItaniumCXXABI.cpp | 4 ++-- lib/AST/MicrosoftCXXABI.cpp | 10 ++++++---- lib/Sema/SemaDecl.cpp | 12 ++++++++---- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/include/clang/AST/MangleNumberingContext.h b/include/clang/AST/MangleNumberingContext.h index adf2b30818..56c995264b 100644 --- a/include/clang/AST/MangleNumberingContext.h +++ b/include/clang/AST/MangleNumberingContext.h @@ -16,7 +16,6 @@ #define LLVM_CLANG_MANGLENUMBERINGCONTEXT_H #include "clang/Basic/LLVM.h" -#include "clang/Sema/Scope.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" @@ -51,11 +50,13 @@ public: /// \brief Retrieve the mangling number of a static local variable within /// this context. - virtual unsigned getManglingNumber(const VarDecl *VD, Scope *S) = 0; + virtual unsigned getManglingNumber(const VarDecl *VD, + unsigned MSLocalManglingNumber) = 0; /// \brief Retrieve the mangling number of a static local variable within /// this context. - virtual unsigned getManglingNumber(const TagDecl *TD, Scope *S) = 0; + virtual unsigned getManglingNumber(const TagDecl *TD, + unsigned MSLocalManglingNumber) = 0; }; } // end namespace clang diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index e452ecff13..93fc611bdb 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -235,6 +235,9 @@ public: const Token &getCurToken() const { return Tok; } Scope *getCurScope() const { return Actions.getCurScope(); } + void incrementMSLocalManglingNumber() const { + return Actions.incrementMSLocalManglingNumber(); + } Decl *getObjCDeclContext() const { return Actions.getObjCDeclContext(); } @@ -745,7 +748,7 @@ public: Self->EnterScope(ScopeFlags); else { if (BeforeCompoundStmt) - Self->getCurScope()->incrementMSLocalManglingNumber(); + Self->incrementMSLocalManglingNumber(); this->Self = 0; } diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index c3844fb57f..b56995ba82 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -38,6 +38,7 @@ #include "clang/Sema/LocInfoType.h" #include "clang/Sema/ObjCMethodList.h" #include "clang/Sema/Ownership.h" +#include "clang/Sema/Scope.h" #include "clang/Sema/ScopeInfo.h" #include "clang/Sema/TypoCorrection.h" #include "clang/Sema/Weak.h" @@ -8052,6 +8053,10 @@ public: /// template substitution or instantiation. Scope *getCurScope() const { return CurScope; } + void incrementMSLocalManglingNumber() const { + return CurScope->incrementMSLocalManglingNumber(); + } + IdentifierInfo *getSuperIdentifier() const; IdentifierInfo *getFloat128Identifier() const; diff --git a/lib/AST/ItaniumCXXABI.cpp b/lib/AST/ItaniumCXXABI.cpp index f0d20c3696..e1bc0da83b 100644 --- a/lib/AST/ItaniumCXXABI.cpp +++ b/lib/AST/ItaniumCXXABI.cpp @@ -37,11 +37,11 @@ class ItaniumNumberingContext : public MangleNumberingContext { public: /// Variable decls are numbered by identifier. - virtual unsigned getManglingNumber(const VarDecl *VD, Scope *) { + virtual unsigned getManglingNumber(const VarDecl *VD, unsigned) { return ++VarManglingNumbers[VD->getIdentifier()]; } - virtual unsigned getManglingNumber(const TagDecl *TD, Scope *) { + virtual unsigned getManglingNumber(const TagDecl *TD, unsigned) { return ++TagManglingNumbers[TD->getIdentifier()]; } }; diff --git a/lib/AST/MicrosoftCXXABI.cpp b/lib/AST/MicrosoftCXXABI.cpp index f2fd848d26..9ee0321b0b 100644 --- a/lib/AST/MicrosoftCXXABI.cpp +++ b/lib/AST/MicrosoftCXXABI.cpp @@ -29,12 +29,14 @@ namespace { /// Typically these are things like static locals, lambdas, or blocks. class MicrosoftNumberingContext : public MangleNumberingContext { public: - virtual unsigned getManglingNumber(const VarDecl *VD, Scope *S) { - return S->getMSLocalManglingNumber(); + virtual unsigned getManglingNumber(const VarDecl *VD, + unsigned MSLocalManglingNumber) { + return MSLocalManglingNumber; } - virtual unsigned getManglingNumber(const TagDecl *TD, Scope *S) { - return S->getMSLocalManglingNumber(); + virtual unsigned getManglingNumber(const TagDecl *TD, + unsigned MSLocalManglingNumber) { + return MSLocalManglingNumber; } }; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 71a79b2261..9870ab1e54 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3168,7 +3168,8 @@ static void HandleTagNumbering(Sema &S, const TagDecl *Tag, Scope *TagScope) { return; MangleNumberingContext &MCtx = S.Context.getManglingNumberContext(Tag->getParent()); - S.Context.setManglingNumber(Tag, MCtx.getManglingNumber(Tag, TagScope)); + S.Context.setManglingNumber( + Tag, MCtx.getManglingNumber(Tag, TagScope->getMSLocalManglingNumber())); return; } @@ -3177,7 +3178,9 @@ static void HandleTagNumbering(Sema &S, const TagDecl *Tag, Scope *TagScope) { if (MangleNumberingContext *MCtx = S.getCurrentMangleNumberContext(Tag->getDeclContext(), ManglingContextDecl)) { - S.Context.setManglingNumber(Tag, MCtx->getManglingNumber(Tag, TagScope)); + S.Context.setManglingNumber( + Tag, + MCtx->getManglingNumber(Tag, TagScope->getMSLocalManglingNumber())); } } @@ -3816,7 +3819,7 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, if (MangleNumberingContext *MCtx = getCurrentMangleNumberContext(NewVD->getDeclContext(), ManglingContextDecl)) { - Context.setManglingNumber(NewVD, MCtx->getManglingNumber(NewVD, S)); + Context.setManglingNumber(NewVD, MCtx->getManglingNumber(NewVD, S->getMSLocalManglingNumber())); Context.setStaticLocalNumber(NewVD, MCtx->getStaticLocalNumber(NewVD)); } } @@ -5482,7 +5485,8 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, if (MangleNumberingContext *MCtx = getCurrentMangleNumberContext(NewVD->getDeclContext(), ManglingContextDecl)) { - Context.setManglingNumber(NewVD, MCtx->getManglingNumber(NewVD, S)); + Context.setManglingNumber( + NewVD, MCtx->getManglingNumber(NewVD, S->getMSLocalManglingNumber())); Context.setStaticLocalNumber(NewVD, MCtx->getStaticLocalNumber(NewVD)); } } -- 2.40.0