diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-07-02 17:43:08 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-07-02 17:43:08 +0000 |
commit | 23c94dbb6631fecdb55ba401aa93722803d980c6 (patch) | |
tree | 19240dbaae509d69e403e4962fd5a14b9c8d5c53 /lib/Parse/Parser.cpp | |
parent | fe2dd6ceeeb31a7c681b2873a8459c5de5d1a3e9 (diff) |
Move the "current scope" state from the Parser into Action. This
allows Sema some limited access to the current scope, which we only
use in one way: when Sema is performing some kind of declaration that
is not directly driven by the parser (e.g., due to template
instantiatio or lazy declaration of a member), we can find the Scope
associated with a DeclContext, if that DeclContext is still in the
process of being parsed.
Use this to make the implicit declaration of special member functions
in a C++ class more "scope-less", rather than using the NULL Scope hack.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107491 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/Parser.cpp')
-rw-r--r-- | lib/Parse/Parser.cpp | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 7d999ac408..b4118fbd0a 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -26,7 +26,7 @@ Parser::Parser(Preprocessor &pp, Action &actions) GreaterThanIsOperator(true), ColonIsSacred(false), TemplateParameterDepth(0) { Tok.setKind(tok::eof); - CurScope = 0; + Actions.CurScope = 0; NumCachedScopes = 0; ParenCount = BracketCount = BraceCount = 0; ObjCImpDecl = DeclPtrTy(); @@ -270,25 +270,25 @@ bool Parser::SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, void Parser::EnterScope(unsigned ScopeFlags) { if (NumCachedScopes) { Scope *N = ScopeCache[--NumCachedScopes]; - N->Init(CurScope, ScopeFlags); - CurScope = N; + N->Init(getCurScope(), ScopeFlags); + Actions.CurScope = N; } else { - CurScope = new Scope(CurScope, ScopeFlags); + Actions.CurScope = new Scope(getCurScope(), ScopeFlags); } - CurScope->setNumErrorsAtStart(Diags.getNumErrors()); + getCurScope()->setNumErrorsAtStart(Diags.getNumErrors()); } /// ExitScope - Pop a scope off the scope stack. void Parser::ExitScope() { - assert(CurScope && "Scope imbalance!"); + assert(getCurScope() && "Scope imbalance!"); // Inform the actions module that this scope is going away if there are any // decls in it. - if (!CurScope->decl_empty()) - Actions.ActOnPopScope(Tok.getLocation(), CurScope); + if (!getCurScope()->decl_empty()) + Actions.ActOnPopScope(Tok.getLocation(), getCurScope()); - Scope *OldScope = CurScope; - CurScope = OldScope->getParent(); + Scope *OldScope = getCurScope(); + Actions.CurScope = OldScope->getParent(); if (NumCachedScopes == ScopeCacheSize) delete OldScope; @@ -305,8 +305,9 @@ void Parser::ExitScope() { Parser::~Parser() { // If we still have scopes active, delete the scope tree. - delete CurScope; - + delete getCurScope(); + Actions.CurScope = 0; + // Free the scope cache. for (unsigned i = 0, e = NumCachedScopes; i != e; ++i) delete ScopeCache[i]; @@ -329,9 +330,9 @@ void Parser::Initialize() { ConsumeToken(); // Create the translation unit scope. Install it as the current scope. - assert(CurScope == 0 && "A scope is already active?"); + assert(getCurScope() == 0 && "A scope is already active?"); EnterScope(Scope::DeclScope); - Actions.ActOnTranslationUnitScope(Tok.getLocation(), CurScope); + Actions.ActOnTranslationUnitScope(Tok.getLocation(), getCurScope()); if (Tok.is(tok::eof) && !getLang().CPlusPlus) // Empty source file is an extension in C @@ -384,7 +385,7 @@ void Parser::ParseTranslationUnit() { /*parse them all*/; ExitScope(); - assert(CurScope == 0 && "Scope imbalance!"); + assert(getCurScope() == 0 && "Scope imbalance!"); } /// ParseExternalDeclaration: @@ -466,7 +467,7 @@ Parser::DeclGroupPtrTy Parser::ParseExternalDeclaration(CXX0XAttributeList Attr) SingleDecl = ParseObjCMethodDefinition(); break; case tok::code_completion: - Actions.CodeCompleteOrdinaryName(CurScope, + Actions.CodeCompleteOrdinaryName(getCurScope(), ObjCImpDecl? Action::CCC_ObjCImplementation : Action::CCC_Namespace); ConsumeCodeCompletionToken(); @@ -560,7 +561,7 @@ Parser::ParseDeclarationOrFunctionDefinition(ParsingDeclSpec &DS, // declaration-specifiers init-declarator-list[opt] ';' if (Tok.is(tok::semi)) { ConsumeToken(); - DeclPtrTy TheDecl = Actions.ParsedFreeStandingDeclSpec(CurScope, AS, DS); + DeclPtrTy TheDecl = Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS, DS); DS.complete(TheDecl); return Actions.ConvertDeclToDeclGroup(TheDecl); } @@ -671,12 +672,12 @@ Parser::DeclPtrTy Parser::ParseFunctionDefinition(ParsingDeclarator &D, // Tell the actions module that we have entered a function definition with the // specified Declarator for the function. DeclPtrTy Res = TemplateInfo.TemplateParams? - Actions.ActOnStartOfFunctionTemplateDef(CurScope, + Actions.ActOnStartOfFunctionTemplateDef(getCurScope(), Action::MultiTemplateParamsArg(Actions, TemplateInfo.TemplateParams->data(), TemplateInfo.TemplateParams->size()), D) - : Actions.ActOnStartOfFunctionDef(CurScope, D); + : Actions.ActOnStartOfFunctionDef(getCurScope(), D); // Break out of the ParsingDeclarator context before we parse the body. D.complete(Res); @@ -762,7 +763,7 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { // Ask the actions module to compute the type for this declarator. Action::DeclPtrTy Param = - Actions.ActOnParamDeclarator(CurScope, ParmDeclarator); + Actions.ActOnParamDeclarator(getCurScope(), ParmDeclarator); if (Param && // A missing identifier has already been diagnosed. @@ -818,7 +819,7 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { } // The actions module must verify that all arguments were declared. - Actions.ActOnFinishKNRParamDeclarations(CurScope, D, Tok.getLocation()); + Actions.ActOnFinishKNRParamDeclarations(getCurScope(), D, Tok.getLocation()); } @@ -930,7 +931,7 @@ bool Parser::TryAnnotateTypeOrScopeToken(bool EnteringContext) { TypeResult Ty; if (Tok.is(tok::identifier)) { // FIXME: check whether the next token is '<', first! - Ty = Actions.ActOnTypenameType(CurScope, TypenameLoc, SS, + Ty = Actions.ActOnTypenameType(getCurScope(), TypenameLoc, SS, *Tok.getIdentifierInfo(), Tok.getLocation()); } else if (Tok.is(tok::annot_template_id)) { @@ -946,7 +947,7 @@ bool Parser::TryAnnotateTypeOrScopeToken(bool EnteringContext) { assert(Tok.is(tok::annot_typename) && "AnnotateTemplateIdTokenAsType isn't working properly"); if (Tok.getAnnotationValue()) - Ty = Actions.ActOnTypenameType(CurScope, TypenameLoc, SS, + Ty = Actions.ActOnTypenameType(getCurScope(), TypenameLoc, SS, SourceLocation(), Tok.getAnnotationValue()); else @@ -977,7 +978,7 @@ bool Parser::TryAnnotateTypeOrScopeToken(bool EnteringContext) { if (Tok.is(tok::identifier)) { // Determine whether the identifier is a type name. if (TypeTy *Ty = Actions.getTypeName(*Tok.getIdentifierInfo(), - Tok.getLocation(), CurScope, &SS)) { + Tok.getLocation(), getCurScope(), &SS)) { // This is a typename. Replace the current token in-place with an // annotation type token. Tok.setKind(tok::annot_typename); @@ -1006,7 +1007,7 @@ bool Parser::TryAnnotateTypeOrScopeToken(bool EnteringContext) { TemplateName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation()); bool MemberOfUnknownSpecialization; if (TemplateNameKind TNK - = Actions.isTemplateName(CurScope, SS, TemplateName, + = Actions.isTemplateName(getCurScope(), SS, TemplateName, /*ObjectType=*/0, EnteringContext, Template, MemberOfUnknownSpecialization)) { // Consume the identifier. @@ -1097,19 +1098,19 @@ bool Parser::TryAnnotateCXXScopeToken(bool EnteringContext) { } void Parser::CodeCompletionRecovery() { - for (Scope *S = CurScope; S; S = S->getParent()) { + for (Scope *S = getCurScope(); S; S = S->getParent()) { if (S->getFlags() & Scope::FnScope) { - Actions.CodeCompleteOrdinaryName(CurScope, Action::CCC_RecoveryInFunction); + Actions.CodeCompleteOrdinaryName(getCurScope(), Action::CCC_RecoveryInFunction); return; } if (S->getFlags() & Scope::ClassScope) { - Actions.CodeCompleteOrdinaryName(CurScope, Action::CCC_Class); + Actions.CodeCompleteOrdinaryName(getCurScope(), Action::CCC_Class); return; } } - Actions.CodeCompleteOrdinaryName(CurScope, Action::CCC_Namespace); + Actions.CodeCompleteOrdinaryName(getCurScope(), Action::CCC_Namespace); } // Anchor the Parser::FieldCallback vtable to this translation unit. |