Refactor diagnostics for MS attributes without -fms-extensions

This shares the warn_attribute_unused diagnostic and reduces the
indentation level.  No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182096 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Kleckner 2013-05-17 14:04:52 +00:00
Родитель e9aae62e8b
Коммит 8fbda8e4a0
1 изменённых файлов: 73 добавлений и 66 удалений

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

@ -4576,66 +4576,74 @@ static void handleObjCPreciseLifetimeAttr(Sema &S, Decl *D,
// Microsoft specific attribute handlers. // Microsoft specific attribute handlers.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Check if MS extensions or some other language extensions are enabled. If
// not, issue a diagnostic that the given attribute is unused.
static bool checkMicrosoftExt(Sema &S, const AttributeList &Attr,
bool OtherExtension = false) {
if (S.LangOpts.MicrosoftExt || OtherExtension)
return true;
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
return false;
}
static void handleUuidAttr(Sema &S, Decl *D, const AttributeList &Attr) { static void handleUuidAttr(Sema &S, Decl *D, const AttributeList &Attr) {
if (S.LangOpts.MicrosoftExt || S.LangOpts.Borland) { if (!checkMicrosoftExt(S, Attr, S.LangOpts.Borland))
// check the attribute arguments. return;
if (!checkAttributeNumArgs(S, Attr, 1))
return;
Expr *Arg = Attr.getArg(0); // check the attribute arguments.
StringLiteral *Str = dyn_cast<StringLiteral>(Arg); if (!checkAttributeNumArgs(S, Attr, 1))
if (!Str || !Str->isAscii()) { return;
S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_string)
<< "uuid" << 1;
return;
}
StringRef StrRef = Str->getString(); Expr *Arg = Attr.getArg(0);
StringLiteral *Str = dyn_cast<StringLiteral>(Arg);
if (!Str || !Str->isAscii()) {
S.Diag(Attr.getLoc(), diag::err_attribute_argument_n_not_string)
<< "uuid" << 1;
return;
}
bool IsCurly = StrRef.size() > 1 && StrRef.front() == '{' && StringRef StrRef = Str->getString();
StrRef.back() == '}';
// Validate GUID length. bool IsCurly = StrRef.size() > 1 && StrRef.front() == '{' &&
if (IsCurly && StrRef.size() != 38) { StrRef.back() == '}';
S.Diag(Attr.getLoc(), diag::err_attribute_uuid_malformed_guid);
return;
}
if (!IsCurly && StrRef.size() != 36) {
S.Diag(Attr.getLoc(), diag::err_attribute_uuid_malformed_guid);
return;
}
// GUID format is "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" or // Validate GUID length.
// "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}" if (IsCurly && StrRef.size() != 38) {
StringRef::iterator I = StrRef.begin(); S.Diag(Attr.getLoc(), diag::err_attribute_uuid_malformed_guid);
if (IsCurly) // Skip the optional '{' return;
++I; }
if (!IsCurly && StrRef.size() != 36) {
S.Diag(Attr.getLoc(), diag::err_attribute_uuid_malformed_guid);
return;
}
for (int i = 0; i < 36; ++i) { // GUID format is "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" or
if (i == 8 || i == 13 || i == 18 || i == 23) { // "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
if (*I != '-') { StringRef::iterator I = StrRef.begin();
S.Diag(Attr.getLoc(), diag::err_attribute_uuid_malformed_guid); if (IsCurly) // Skip the optional '{'
return; ++I;
}
} else if (!isHexDigit(*I)) { for (int i = 0; i < 36; ++i) {
if (i == 8 || i == 13 || i == 18 || i == 23) {
if (*I != '-') {
S.Diag(Attr.getLoc(), diag::err_attribute_uuid_malformed_guid); S.Diag(Attr.getLoc(), diag::err_attribute_uuid_malformed_guid);
return; return;
} }
I++; } else if (!isHexDigit(*I)) {
S.Diag(Attr.getLoc(), diag::err_attribute_uuid_malformed_guid);
return;
} }
I++;
}
D->addAttr(::new (S.Context) D->addAttr(::new (S.Context)
UuidAttr(Attr.getRange(), S.Context, Str->getString(), UuidAttr(Attr.getRange(), S.Context, Str->getString(),
Attr.getAttributeSpellingListIndex())); Attr.getAttributeSpellingListIndex()));
} else
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "uuid";
} }
static void handleInheritanceAttr(Sema &S, Decl *D, const AttributeList &Attr) { static void handleInheritanceAttr(Sema &S, Decl *D, const AttributeList &Attr) {
if (!S.LangOpts.MicrosoftExt) { if (!checkMicrosoftExt(S, Attr))
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
return; return;
}
AttributeList::Kind Kind = Attr.getKind(); AttributeList::Kind Kind = Attr.getKind();
if (Kind == AttributeList::AT_SingleInheritance) if (Kind == AttributeList::AT_SingleInheritance)
@ -4656,31 +4664,30 @@ static void handleInheritanceAttr(Sema &S, Decl *D, const AttributeList &Attr) {
} }
static void handlePortabilityAttr(Sema &S, Decl *D, const AttributeList &Attr) { static void handlePortabilityAttr(Sema &S, Decl *D, const AttributeList &Attr) {
if (S.LangOpts.MicrosoftExt) { if (!checkMicrosoftExt(S, Attr))
AttributeList::Kind Kind = Attr.getKind(); return;
if (Kind == AttributeList::AT_Ptr32)
D->addAttr( AttributeList::Kind Kind = Attr.getKind();
::new (S.Context) Ptr32Attr(Attr.getRange(), S.Context, if (Kind == AttributeList::AT_Ptr32)
Attr.getAttributeSpellingListIndex())); D->addAttr(
else if (Kind == AttributeList::AT_Ptr64) ::new (S.Context) Ptr32Attr(Attr.getRange(), S.Context,
D->addAttr( Attr.getAttributeSpellingListIndex()));
::new (S.Context) Ptr64Attr(Attr.getRange(), S.Context, else if (Kind == AttributeList::AT_Ptr64)
Attr.getAttributeSpellingListIndex())); D->addAttr(
else if (Kind == AttributeList::AT_Win64) ::new (S.Context) Ptr64Attr(Attr.getRange(), S.Context,
D->addAttr( Attr.getAttributeSpellingListIndex()));
::new (S.Context) Win64Attr(Attr.getRange(), S.Context, else if (Kind == AttributeList::AT_Win64)
Attr.getAttributeSpellingListIndex())); D->addAttr(
} else ::new (S.Context) Win64Attr(Attr.getRange(), S.Context,
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName(); Attr.getAttributeSpellingListIndex()));
} }
static void handleForceInlineAttr(Sema &S, Decl *D, const AttributeList &Attr) { static void handleForceInlineAttr(Sema &S, Decl *D, const AttributeList &Attr) {
if (S.LangOpts.MicrosoftExt) if (!checkMicrosoftExt(S, Attr))
D->addAttr(::new (S.Context) return;
ForceInlineAttr(Attr.getRange(), S.Context, D->addAttr(::new (S.Context)
Attr.getAttributeSpellingListIndex())); ForceInlineAttr(Attr.getRange(), S.Context,
else Attr.getAttributeSpellingListIndex()));
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//