[cfe-commits] r138248 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseDeclCXX.cpp lib/Parse/ParseObjc.cpp lib/Parse/ParseTemplate.cpp lib/Parse/Parser.cpp
Fariborz Jahanian
fjahanian at apple.com
Mon Aug 22 10:59:19 PDT 2011
Author: fjahanian
Date: Mon Aug 22 12:59:19 2011
New Revision: 138248
URL: http://llvm.org/viewvc/llvm-project?rev=138248&view=rev
Log:
objc - Simplify switing objc decl context by using
a context switching object.
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/ParseTemplate.cpp
cfe/trunk/lib/Parse/Parser.cpp
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=138248&r1=138247&r2=138248&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Aug 22 12:59:19 2011
@@ -503,6 +503,23 @@
}
};
+ /// ObjCDeclContextSwitch - An object used to switch context from
+ /// an objective-c decl context to its enclosing decl context and
+ /// back.
+ class ObjCDeclContextSwitch {
+ Parser &P;
+ Decl *DC;
+ public:
+ explicit ObjCDeclContextSwitch(Parser &p) : P(p),
+ DC(p.getObjCDeclContext()) {
+ if (DC)
+ P.Actions.ActOnObjCContainerFinishDefinition(DC);
+ }
+ ~ObjCDeclContextSwitch() {
+ if (DC)
+ P.Actions.ActOnObjCContainerStartDefinition(DC);
+ }
+ };
SourceLocation MatchRHSPunctuation(tok::TokenKind RHSTok,
SourceLocation LHSLoc);
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=138248&r1=138247&r2=138248&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Mon Aug 22 12:59:19 2011
@@ -52,9 +52,7 @@
SourceLocation InlineLoc) {
assert(Tok.is(tok::kw_namespace) && "Not a namespace!");
SourceLocation NamespaceLoc = ConsumeToken(); // eat the 'namespace'.
- Decl *DC = getObjCDeclContext();
- if (DC)
- Actions.ActOnObjCContainerFinishDefinition(DC);
+ ObjCDeclContextSwitch ObjCDC(*this);
if (Tok.is(tok::code_completion)) {
Actions.CodeCompleteNamespaceDecl(getCurScope());
@@ -92,10 +90,7 @@
if (InlineLoc.isValid())
Diag(InlineLoc, diag::err_inline_namespace_alias)
<< FixItHint::CreateRemoval(InlineLoc);
- Decl *Res = ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd);
- if (DC)
- Actions.ActOnObjCContainerStartDefinition(DC);
- return Res;
+ return ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd);
}
@@ -106,8 +101,6 @@
}
Diag(Tok, Ident ? diag::err_expected_lbrace :
diag::err_expected_ident_lbrace);
- if (DC)
- Actions.ActOnObjCContainerStartDefinition(DC);
return 0;
}
@@ -122,8 +115,6 @@
}
Diag(LBrace, diag::err_namespace_nonnamespace_scope);
SkipUntil(tok::r_brace, false);
- if (DC)
- Actions.ActOnObjCContainerStartDefinition(DC);
return 0;
}
@@ -182,8 +173,6 @@
Actions.ActOnFinishNamespaceDef(NamespcDecl, RBraceLoc);
DeclEnd = RBraceLoc;
- if (DC)
- Actions.ActOnObjCContainerStartDefinition(DC);
return NamespcDecl;
}
@@ -328,9 +317,8 @@
ParsedAttributesWithRange &attrs,
Decl **OwnedType) {
assert(Tok.is(tok::kw_using) && "Not using token");
- Decl *DC = getObjCDeclContext();
- if (DC)
- Actions.ActOnObjCContainerFinishDefinition(DC);
+ ObjCDeclContextSwitch ObjCDC(*this);
+
// Eat 'using'.
SourceLocation UsingLoc = ConsumeToken();
@@ -348,10 +336,7 @@
<< R << FixItHint::CreateRemoval(R);
}
- Decl *Res = ParseUsingDirective(Context, UsingLoc, DeclEnd, attrs);
- if (DC)
- Actions.ActOnObjCContainerStartDefinition(DC);
- return Res;
+ return ParseUsingDirective(Context, UsingLoc, DeclEnd, attrs);
}
// Otherwise, it must be a using-declaration or an alias-declaration.
@@ -359,11 +344,8 @@
// Using declarations can't have attributes.
ProhibitAttributes(attrs);
- Decl *Res = ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd,
+ return ParseUsingDeclaration(Context, TemplateInfo, UsingLoc, DeclEnd,
AS_none, OwnedType);
- if (DC)
- Actions.ActOnObjCContainerStartDefinition(DC);
- return Res;
}
/// ParseUsingDirective - Parse C++ using-directive, assumes
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=138248&r1=138247&r2=138248&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Mon Aug 22 12:59:19 2011
@@ -776,9 +776,8 @@
SourceLocation LParenLoc = ConsumeParen();
SourceLocation TypeStartLoc = Tok.getLocation();
- Decl *DC = getObjCDeclContext();
- if (DC)
- Actions.ActOnObjCContainerFinishDefinition(DC);
+ ObjCDeclContextSwitch ObjCDC(*this);
+
// Parse type qualifiers, in, inout, etc.
ParseObjCTypeQualifierList(DS, Context);
@@ -801,8 +800,6 @@
// place. Emit an error then return what we have as the type.
MatchRHSPunctuation(tok::r_paren, LParenLoc);
}
- if (DC)
- Actions.ActOnObjCContainerStartDefinition(DC);
return Ty;
}
Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=138248&r1=138247&r2=138248&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTemplate.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTemplate.cpp Mon Aug 22 12:59:19 2011
@@ -27,20 +27,13 @@
Parser::ParseDeclarationStartingWithTemplate(unsigned Context,
SourceLocation &DeclEnd,
AccessSpecifier AS) {
- Decl *DC = getObjCDeclContext();
- if (DC)
- Actions.ActOnObjCContainerFinishDefinition(DC);
+ ObjCDeclContextSwitch ObjCDC(*this);
+
if (Tok.is(tok::kw_template) && NextToken().isNot(tok::less)) {
- Decl *Res = ParseExplicitInstantiation(SourceLocation(), ConsumeToken(),
+ return ParseExplicitInstantiation(SourceLocation(), ConsumeToken(),
DeclEnd);
- if (DC)
- Actions.ActOnObjCContainerStartDefinition(DC);
- return Res;
- }
- Decl *Res = ParseTemplateDeclarationOrSpecialization(Context, DeclEnd, AS);
- if (DC)
- Actions.ActOnObjCContainerStartDefinition(DC);
- return Res;
+ }
+ return ParseTemplateDeclarationOrSpecialization(Context, DeclEnd, AS);
}
/// \brief RAII class that manages the template parameter depth.
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=138248&r1=138247&r2=138248&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Mon Aug 22 12:59:19 2011
@@ -811,16 +811,12 @@
AccessSpecifier AS) {
ParsingDeclSpec DS(*this);
DS.takeAttributesFrom(attrs);
- Decl *DC = getObjCDeclContext();
- if (DC)
- // Must temporarily exit the objective-c container scope for
- // parsing c constructs and re-enter objc container scope
- // afterwards.
- Actions.ActOnObjCContainerFinishDefinition(DC);
- DeclGroupPtrTy resPtrTy = ParseDeclarationOrFunctionDefinition(DS, AS);
- if (DC)
- Actions.ActOnObjCContainerStartDefinition(DC);
- return resPtrTy;
+ // Must temporarily exit the objective-c container scope for
+ // parsing c constructs and re-enter objc container scope
+ // afterwards.
+ ObjCDeclContextSwitch ObjCDC(*this);
+
+ return ParseDeclarationOrFunctionDefinition(DS, AS);
}
/// ParseFunctionDefinition - We parsed and verified that the specified
More information about the cfe-commits
mailing list