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.
//===----------------------------------------------------------------------===//
// 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) {
if (S.LangOpts.MicrosoftExt || S.LangOpts.Borland) {
// check the attribute arguments.
if (!checkAttributeNumArgs(S, Attr, 1))
return;
if (!checkMicrosoftExt(S, Attr, S.LangOpts.Borland))
return;
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;
}
// check the attribute arguments.
if (!checkAttributeNumArgs(S, Attr, 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() == '{' &&
StrRef.back() == '}';
StringRef StrRef = Str->getString();
// Validate GUID length.
if (IsCurly && StrRef.size() != 38) {
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;
}
bool IsCurly = StrRef.size() > 1 && StrRef.front() == '{' &&
StrRef.back() == '}';
// GUID format is "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" or
// "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
StringRef::iterator I = StrRef.begin();
if (IsCurly) // Skip the optional '{'
++I;
// Validate GUID length.
if (IsCurly && StrRef.size() != 38) {
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;
}
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);
return;
}
} else if (!isHexDigit(*I)) {
// GUID format is "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" or
// "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
StringRef::iterator I = StrRef.begin();
if (IsCurly) // Skip the optional '{'
++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);
return;
}
I++;
} else if (!isHexDigit(*I)) {
S.Diag(Attr.getLoc(), diag::err_attribute_uuid_malformed_guid);
return;
}
I++;
}
D->addAttr(::new (S.Context)
UuidAttr(Attr.getRange(), S.Context, Str->getString(),
Attr.getAttributeSpellingListIndex()));
} else
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "uuid";
D->addAttr(::new (S.Context)
UuidAttr(Attr.getRange(), S.Context, Str->getString(),
Attr.getAttributeSpellingListIndex()));
}
static void handleInheritanceAttr(Sema &S, Decl *D, const AttributeList &Attr) {
if (!S.LangOpts.MicrosoftExt) {
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
if (!checkMicrosoftExt(S, Attr))
return;
}
AttributeList::Kind Kind = Attr.getKind();
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) {
if (S.LangOpts.MicrosoftExt) {
AttributeList::Kind Kind = Attr.getKind();
if (Kind == AttributeList::AT_Ptr32)
D->addAttr(
::new (S.Context) Ptr32Attr(Attr.getRange(), S.Context,
Attr.getAttributeSpellingListIndex()));
else if (Kind == AttributeList::AT_Ptr64)
D->addAttr(
::new (S.Context) Ptr64Attr(Attr.getRange(), S.Context,
Attr.getAttributeSpellingListIndex()));
else if (Kind == AttributeList::AT_Win64)
D->addAttr(
::new (S.Context) Win64Attr(Attr.getRange(), S.Context,
Attr.getAttributeSpellingListIndex()));
} else
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
if (!checkMicrosoftExt(S, Attr))
return;
AttributeList::Kind Kind = Attr.getKind();
if (Kind == AttributeList::AT_Ptr32)
D->addAttr(
::new (S.Context) Ptr32Attr(Attr.getRange(), S.Context,
Attr.getAttributeSpellingListIndex()));
else if (Kind == AttributeList::AT_Ptr64)
D->addAttr(
::new (S.Context) Ptr64Attr(Attr.getRange(), S.Context,
Attr.getAttributeSpellingListIndex()));
else if (Kind == AttributeList::AT_Win64)
D->addAttr(
::new (S.Context) Win64Attr(Attr.getRange(), S.Context,
Attr.getAttributeSpellingListIndex()));
}
static void handleForceInlineAttr(Sema &S, Decl *D, const AttributeList &Attr) {
if (S.LangOpts.MicrosoftExt)
D->addAttr(::new (S.Context)
ForceInlineAttr(Attr.getRange(), S.Context,
Attr.getAttributeSpellingListIndex()));
else
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
if (!checkMicrosoftExt(S, Attr))
return;
D->addAttr(::new (S.Context)
ForceInlineAttr(Attr.getRange(), S.Context,
Attr.getAttributeSpellingListIndex()));
}
//===----------------------------------------------------------------------===//