Patch to implement AST generation for objective-c's @selector expression.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43038 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/Sema.cpp b/Sema/Sema.cpp
index 330d9dc..dc68eb0 100644
--- a/Sema/Sema.cpp
+++ b/Sema/Sema.cpp
@@ -45,6 +45,23 @@
return Context.getObjcIdType();
}
+/// GetObjcSelType - See comments for Sema::GetObjcIdType above; replace "id"
+/// with "SEL".
+QualType Sema::GetObjcSelType(SourceLocation Loc) {
+ assert(TUScope && "GetObjcSelType(): Top-level scope is null");
+ if (Context.getObjcSelType().isNull()) {
+ IdentifierInfo *SelIdent = &Context.Idents.get("SEL");
+ ScopedDecl *SelDecl = LookupScopedDecl(SelIdent, Decl::IDNS_Ordinary,
+ SourceLocation(), TUScope);
+ TypedefDecl *ObjcSelTypedef = dyn_cast_or_null<TypedefDecl>(SelDecl);
+ if (!ObjcSelTypedef) {
+ Diag(Loc, diag::err_missing_sel_definition);
+ return QualType();
+ }
+ Context.setObjcSelType(ObjcSelTypedef);
+ }
+ return Context.getObjcSelType();
+}
Sema::Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup)
: PP(pp), Context(ctxt), CurFunctionDecl(0), LastInGroupList(prevInGroup) {
diff --git a/Sema/Sema.h b/Sema/Sema.h
index c45bbf8..9d58779 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -277,6 +277,9 @@
/// GetObjcIdType - Getter for the build-in "id" type.
QualType GetObjcIdType(SourceLocation Loc = SourceLocation());
+ /// GetObjcSelType - Getter for the build-in "SEL" type.
+ QualType GetObjcSelType(SourceLocation Loc = SourceLocation());
+
/// AddInstanceMethodToGlobalPool - All instance methods in a translation
/// unit are added to a global pool. This allows us to efficiently associate
/// a selector with a method declaraation for purposes of typechecking
@@ -441,6 +444,12 @@
TypeTy *Ty,
SourceLocation RParenLoc);
+ // ParseObjCSelectorExpression - Build selector expression for @selector
+ virtual ExprResult ParseObjCSelectorExpression(Selector Sel,
+ SourceLocation AtLoc,
+ SourceLocation LParenLoc,
+ SourceLocation RParenLoc);
+
// Objective-C declarations.
virtual DeclTy *ActOnStartClassInterface(
SourceLocation AtInterafceLoc,
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp
index daa1a7c..082b718 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -1919,6 +1919,14 @@
return new ObjCEncodeExpr(t, EncodedType, AtLoc, RParenLoc);
}
+Sema::ExprResult Sema::ParseObjCSelectorExpression(Selector Sel,
+ SourceLocation AtLoc,
+ SourceLocation LParenLoc,
+ SourceLocation RParenLoc) {
+ QualType t = GetObjcSelType(AtLoc);
+ return new ObjCSelectorExpr(t, Sel, AtLoc, RParenLoc);
+}
+
// ActOnClassMessage - used for both unary and keyword messages.
// ArgExprs is optional - if it is present, the number of expressions
// is obtained from Sel.getNumArgs().