]> granicus.if.org Git - clang/commitdiff
Add support for attribute(deprecated), patch by Nuno Lopes!
authorChris Lattner <sabre@nondot.org>
Fri, 29 Feb 2008 16:48:43 +0000 (16:48 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 29 Feb 2008 16:48:43 +0000 (16:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47753 91177308-0d34-0410-b5e6-96231b3b80d8

Parse/AttributeList.cpp
Sema/SemaDecl.cpp
Sema/SemaExpr.cpp
include/clang/AST/Attr.h
include/clang/Basic/DiagnosticKinds.def
include/clang/Parse/AttributeList.h

index 4ceece8f27a619a3b8caa8337e8ec4394297222c..4fac91fa572cb301f3a56885840dab606d252962 100644 (file)
@@ -61,7 +61,10 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
     if (!memcmp(Str, "annotate", 8)) return AT_annotate;
     if (!memcmp(Str, "noreturn", 8)) return AT_noreturn;
     break;
-  case 11:   
+  case 10:
+    if (!memcmp(Str, "deprecated", 10)) return AT_deprecated;
+    break;
+  case 11:
     if (!memcmp(Str, "vector_size", 11)) return AT_vector_size;
     break;
   case 13:
index df6dd5c2e18ffb0ab16bdb840f715cc970ead1c4..26528485db1cca7ecc32b5fb3c1fa587cad77804 100644 (file)
@@ -255,6 +255,8 @@ FunctionDecl *Sema::MergeFunctionDecl(FunctionDecl *New, ScopedDecl *OldD) {
     Diag(OldD->getLocation(), diag::err_previous_definition);
     return New;
   }
+
+  // FIXME: propagate old Attrs to the New decl
   
   QualType OldQType = Old->getCanonicalType();
   QualType NewQType = New->getCanonicalType();
@@ -1778,6 +1780,9 @@ void Sema::HandleDeclAttribute(Decl *New, AttributeList *Attr) {
       vDecl->setType(newType);
     }
     break;
+  case AttributeList::AT_deprecated:
+    New->addAttr(new DeprecatedAttr());
+    break;
   case AttributeList::AT_aligned:
     HandleAlignedAttribute(New, Attr);
     break;
@@ -1791,7 +1796,11 @@ void Sema::HandleDeclAttribute(Decl *New, AttributeList *Attr) {
     HandleNoReturnAttribute(New, Attr);
     break;
   default:
-    // FIXME: add other attributes...
+#if 0
+    // TODO: when we have the full set of attributes, warn about unknown ones.
+    Diag(Attr->getLoc(), diag::warn_attribute_ignored,
+         Attr->getName()->getName());
+#endif
     break;
   }
 }
index 3d60866c015c9ac643fc1b0a0f70483b83b19ca6..5b5b2d235ce5fa74fd52f8683ee7a52e332e538d 100644 (file)
@@ -100,6 +100,10 @@ Sema::ExprResult Sema::ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
     }
   }
   if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
+    // check if referencing an identifier with __attribute__((deprecated)).
+    if (VD->getAttr<DeprecatedAttr>())
+      Diag(Loc, diag::warn_deprecated, VD->getName());
+
     // Only create DeclRefExpr's for valid Decl's.
     if (VD->isInvalidDecl())
       return true;
index 2517288460497fae66216873545d691f0c716110..0e5ae58efacdd3db6816cdb06fa4a90b0359a9fd 100644 (file)
@@ -26,7 +26,8 @@ public:
     Aligned,
     Packed,
     Annotate,
-    NoReturn
+    NoReturn,
+    Deprecated
   };
     
 private:
@@ -107,6 +108,16 @@ public:
   static bool classof(const NoReturnAttr *A) { return true; }
 };
 
+class DeprecatedAttr : public Attr {
+public:
+  DeprecatedAttr() : Attr(Deprecated) {}
+
+  // Implement isa/cast/dyncast/etc.
+
+  static bool classof(const Attr *A) { return A->getKind() == Deprecated; }
+  static bool classof(const DeprecatedAttr *A) { return true; }
+};
+
 }  // end namespace clang
 
 #endif
index 21f348216dafb5a608e04b6ca748130af49afd67..3d0a3f8815f8128ce71b7023841af537327f6026 100644 (file)
@@ -617,6 +617,8 @@ DIAG(err_unexpected_typedef, ERROR,
      "unexpected type name '%0': expected expression")
 DIAG(err_undeclared_var_use, ERROR,
      "use of undeclared identifier '%0'")
+DIAG(warn_deprecated, WARNING,
+     "'%0' is deprecated")
 DIAG(err_redefinition, ERROR,
      "redefinition of '%0'")
 DIAG(err_static_non_static, ERROR,
index a6a699ef8bad0987209b39ae1311b5213fd68749..6300b984b5b6f08739ae0ec523d91eac0f6ec217 100644 (file)
@@ -49,7 +49,8 @@ public:
     AT_aligned,
     AT_packed,
     AT_annotate,
-    AT_noreturn
+    AT_noreturn,
+    AT_deprecated
   };
   
   IdentifierInfo *getName() const { return AttrName; }