Add support for attribute(deprecated), patch by Nuno Lopes!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47753 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2008-02-29 16:48:43 +00:00
Родитель 5c61e7a1fc
Коммит 7e669b2514
6 изменённых файлов: 34 добавлений и 4 удалений

Просмотреть файл

@ -61,7 +61,10 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
if (!memcmp(Str, "annotate", 8)) return AT_annotate; if (!memcmp(Str, "annotate", 8)) return AT_annotate;
if (!memcmp(Str, "noreturn", 8)) return AT_noreturn; if (!memcmp(Str, "noreturn", 8)) return AT_noreturn;
break; 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; if (!memcmp(Str, "vector_size", 11)) return AT_vector_size;
break; break;
case 13: case 13:

Просмотреть файл

@ -255,6 +255,8 @@ FunctionDecl *Sema::MergeFunctionDecl(FunctionDecl *New, ScopedDecl *OldD) {
Diag(OldD->getLocation(), diag::err_previous_definition); Diag(OldD->getLocation(), diag::err_previous_definition);
return New; return New;
} }
// FIXME: propagate old Attrs to the New decl
QualType OldQType = Old->getCanonicalType(); QualType OldQType = Old->getCanonicalType();
QualType NewQType = New->getCanonicalType(); QualType NewQType = New->getCanonicalType();
@ -1778,6 +1780,9 @@ void Sema::HandleDeclAttribute(Decl *New, AttributeList *Attr) {
vDecl->setType(newType); vDecl->setType(newType);
} }
break; break;
case AttributeList::AT_deprecated:
New->addAttr(new DeprecatedAttr());
break;
case AttributeList::AT_aligned: case AttributeList::AT_aligned:
HandleAlignedAttribute(New, Attr); HandleAlignedAttribute(New, Attr);
break; break;
@ -1791,7 +1796,11 @@ void Sema::HandleDeclAttribute(Decl *New, AttributeList *Attr) {
HandleNoReturnAttribute(New, Attr); HandleNoReturnAttribute(New, Attr);
break; break;
default: 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; break;
} }
} }

Просмотреть файл

@ -100,6 +100,10 @@ Sema::ExprResult Sema::ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
} }
} }
if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) { 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. // Only create DeclRefExpr's for valid Decl's.
if (VD->isInvalidDecl()) if (VD->isInvalidDecl())
return true; return true;

Просмотреть файл

@ -26,7 +26,8 @@ public:
Aligned, Aligned,
Packed, Packed,
Annotate, Annotate,
NoReturn NoReturn,
Deprecated
}; };
private: private:
@ -107,6 +108,16 @@ public:
static bool classof(const NoReturnAttr *A) { return true; } 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 } // end namespace clang
#endif #endif

Просмотреть файл

@ -617,6 +617,8 @@ DIAG(err_unexpected_typedef, ERROR,
"unexpected type name '%0': expected expression") "unexpected type name '%0': expected expression")
DIAG(err_undeclared_var_use, ERROR, DIAG(err_undeclared_var_use, ERROR,
"use of undeclared identifier '%0'") "use of undeclared identifier '%0'")
DIAG(warn_deprecated, WARNING,
"'%0' is deprecated")
DIAG(err_redefinition, ERROR, DIAG(err_redefinition, ERROR,
"redefinition of '%0'") "redefinition of '%0'")
DIAG(err_static_non_static, ERROR, DIAG(err_static_non_static, ERROR,

Просмотреть файл

@ -49,7 +49,8 @@ public:
AT_aligned, AT_aligned,
AT_packed, AT_packed,
AT_annotate, AT_annotate,
AT_noreturn AT_noreturn,
AT_deprecated
}; };
IdentifierInfo *getName() const { return AttrName; } IdentifierInfo *getName() const { return AttrName; }