diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-05-13 18:09:35 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-05-13 18:09:35 +0000 |
commit | 5b53005fb9ef24b8bdfe995f29b4662de468128a (patch) | |
tree | 4cf8977db699190b663a82fa036fc8b825571ce3 | |
parent | cfe858aa7c2ad7005c614772c7cfceb1525996cb (diff) |
Some early declarations to support sentinel attribute on
message dispatches (and function calls later). No change in
functionality.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71683 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/Attr.h | 18 | ||||
-rw-r--r-- | lib/Frontend/PCHReaderDecl.cpp | 7 | ||||
-rw-r--r-- | lib/Frontend/PCHWriter.cpp | 7 | ||||
-rw-r--r-- | lib/Sema/Sema.h | 2 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 9 | ||||
-rw-r--r-- | lib/Sema/SemaExprObjC.cpp | 2 |
6 files changed, 45 insertions, 0 deletions
diff --git a/include/clang/AST/Attr.h b/include/clang/AST/Attr.h index 287d80f93f..feed54b7ec 100644 --- a/include/clang/AST/Attr.h +++ b/include/clang/AST/Attr.h @@ -66,6 +66,7 @@ public: Pure, Regparm, Section, + Sentinel, StdCall, TransparentUnion, Unavailable, @@ -359,6 +360,23 @@ public: static bool classof(const FormatAttr *A) { return true; } }; +class SentinelAttr : public Attr { + int sentinel, NullPos; +public: + SentinelAttr(int sentinel_val, int nullPos) : Attr(Sentinel), + sentinel(sentinel_val), NullPos(nullPos) {} + int getSentinel() const { return sentinel; } + int getNullPos() const { return NullPos; } + + virtual Attr *clone(ASTContext &C) const { + return ::new (C) SentinelAttr(sentinel, NullPos); + } + + // Implement isa/cast/dyncast/etc. + static bool classof(const Attr *A) { return A->getKind() == Sentinel; } + static bool classof(const SentinelAttr *A) { return true; } +}; + class VisibilityAttr : public Attr { public: /// @brief An enumeration for the kinds of visibility of symbols. diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp index e623b6f1d7..3db00ec1b7 100644 --- a/lib/Frontend/PCHReaderDecl.cpp +++ b/lib/Frontend/PCHReaderDecl.cpp @@ -452,6 +452,13 @@ Attr *PCHReader::ReadAttributes() { New = ::new (*Context) FormatAttr(Type, FormatIdx, FirstArg); break; } + + case Attr::Sentinel: { + int sentinel = Record[Idx++]; + int nullPos = Record[Idx++]; + New = ::new (*Context) SentinelAttr(sentinel, nullPos); + break; + } SIMPLE_ATTR(GNUInline); diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index dbe0e536e5..e05a73568f 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -1556,6 +1556,13 @@ void PCHWriter::WriteAttributeRecord(const Attr *Attr) { break; } + case Attr::Sentinel : { + const SentinelAttr *Sentinel = cast<SentinelAttr>(Attr); + Record.push_back(Sentinel->getSentinel()); + Record.push_back(Sentinel->getNullPos()); + break; + } + case Attr::GNUInline: case Attr::IBOutletKind: case Attr::NoReturn: diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 2e617f573b..8c38c2bfd2 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -1274,6 +1274,8 @@ public: bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, ObjCMethodDecl *Getter, SourceLocation Loc); + void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, + Expr **Args, unsigned NumArgs); // Primary Expressions. virtual SourceRange getExprRange(ExprTy *E) const; diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index d2e84c10e2..f1da408669 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -88,6 +88,15 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) { return false; } +/// DiagnoseSentinelCalls - This routine checks on method dispatch calls +/// (and other functions in future), which have been declared with sentinel +/// attribute. It warns if call does not have the sentinel argument. +/// +void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, + Expr **Args, unsigned NumArgs) +{ +} + SourceRange Sema::getExprRange(ExprTy *E) const { Expr *Ex = (Expr *)E; return Ex? Ex->getSourceRange() : SourceRange(); diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index de6b69f90f..0073fd9f28 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -626,6 +626,8 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, return true; } + if (Method) + DiagnoseSentinelCalls(Method, receiverLoc, ArgExprs, NumArgs); if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false, lbrac, rbrac, returnType)) return true; |