[cfe-commits] r47753 - in /cfe/trunk: Parse/AttributeList.cpp Sema/SemaDecl.cpp Sema/SemaExpr.cpp include/clang/AST/Attr.h include/clang/Basic/DiagnosticKinds.def include/clang/Parse/AttributeList.h
Chris Lattner
sabre at nondot.org
Fri Feb 29 08:48:45 PST 2008
Author: lattner
Date: Fri Feb 29 10:48:43 2008
New Revision: 47753
URL: http://llvm.org/viewvc/llvm-project?rev=47753&view=rev
Log:
Add support for attribute(deprecated), patch by Nuno Lopes!
Modified:
cfe/trunk/Parse/AttributeList.cpp
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/AST/Attr.h
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/include/clang/Parse/AttributeList.h
Modified: cfe/trunk/Parse/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/AttributeList.cpp?rev=47753&r1=47752&r2=47753&view=diff
==============================================================================
--- cfe/trunk/Parse/AttributeList.cpp (original)
+++ cfe/trunk/Parse/AttributeList.cpp Fri Feb 29 10:48:43 2008
@@ -61,7 +61,10 @@
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:
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=47753&r1=47752&r2=47753&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Fri Feb 29 10:48:43 2008
@@ -255,6 +255,8 @@
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 @@
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 @@
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;
}
}
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=47753&r1=47752&r2=47753&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Fri Feb 29 10:48:43 2008
@@ -100,6 +100,10 @@
}
}
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;
Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=47753&r1=47752&r2=47753&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Fri Feb 29 10:48:43 2008
@@ -26,7 +26,8 @@
Aligned,
Packed,
Annotate,
- NoReturn
+ NoReturn,
+ Deprecated
};
private:
@@ -107,6 +108,16 @@
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
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=47753&r1=47752&r2=47753&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Fri Feb 29 10:48:43 2008
@@ -617,6 +617,8 @@
"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,
Modified: cfe/trunk/include/clang/Parse/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/AttributeList.h?rev=47753&r1=47752&r2=47753&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/AttributeList.h (original)
+++ cfe/trunk/include/clang/Parse/AttributeList.h Fri Feb 29 10:48:43 2008
@@ -49,7 +49,8 @@
AT_aligned,
AT_packed,
AT_annotate,
- AT_noreturn
+ AT_noreturn,
+ AT_deprecated
};
IdentifierInfo *getName() const { return AttrName; }
More information about the cfe-commits
mailing list