Move checkStringLiteralArgument into Sema class
It's a useful function to have around for target-specific attributes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191768 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 3d46f87..950c8df 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -287,17 +287,16 @@
/// If not emit an error and return false. If the argument is an identifier it
/// will emit an error with a fixit hint and treat it as if it was a string
/// literal.
-static bool checkStringLiteralArgument(Sema &S, StringRef &Str,
- const AttributeList &Attr,
- unsigned ArgNum,
- SourceLocation *ArgLocation = 0) {
+bool Sema::checkStringLiteralArgumentAttr(const AttributeList &Attr,
+ unsigned ArgNum, StringRef &Str,
+ SourceLocation *ArgLocation = 0) {
// Look for identifiers. If we have one emit a hint to fix it to a literal.
if (Attr.isArgIdent(ArgNum)) {
IdentifierLoc *Loc = Attr.getArgAsIdent(ArgNum);
- S.Diag(Loc->Loc, diag::err_attribute_argument_type)
+ Diag(Loc->Loc, diag::err_attribute_argument_type)
<< Attr.getName() << AANT_ArgumentString
<< FixItHint::CreateInsertion(Loc->Loc, "\"")
- << FixItHint::CreateInsertion(S.PP.getLocForEndOfToken(Loc->Loc), "\"");
+ << FixItHint::CreateInsertion(PP.getLocForEndOfToken(Loc->Loc), "\"");
Str = Loc->Ident->getName();
if (ArgLocation)
*ArgLocation = Loc->Loc;
@@ -311,7 +310,7 @@
*ArgLocation = ArgExpr->getLocStart();
if (!Literal || !Literal->isAscii()) {
- S.Diag(ArgExpr->getLocStart(), diag::err_attribute_argument_type)
+ Diag(ArgExpr->getLocStart(), diag::err_attribute_argument_type)
<< Attr.getName() << AANT_ArgumentString;
return false;
}
@@ -1564,7 +1563,7 @@
// of transforming it into an AliasAttr. The WeakRefAttr never uses the
// StringRef parameter it was given anyway.
StringRef Str;
- if (Attr.getNumArgs() && checkStringLiteralArgument(S, Str, Attr, 0))
+ if (Attr.getNumArgs() && S.checkStringLiteralArgumentAttr(Attr, 0, Str))
// GCC will accept anything as the argument of weakref. Should we
// check for an existing decl?
D->addAttr(::new (S.Context) AliasAttr(Attr.getRange(), S.Context, Str,
@@ -1577,7 +1576,7 @@
static void handleAliasAttr(Sema &S, Decl *D, const AttributeList &Attr) {
StringRef Str;
- if (!checkStringLiteralArgument(S, Str, Attr, 0))
+ if (!S.checkStringLiteralArgumentAttr(Attr, 0, Str))
return;
if (S.Context.getTargetInfo().getTriple().isOSDarwin()) {
@@ -1667,7 +1666,7 @@
StringRef Model;
SourceLocation LiteralLoc;
// Check that it is a string.
- if (!checkStringLiteralArgument(S, Model, Attr, 0, &LiteralLoc))
+ if (!S.checkStringLiteralArgumentAttr(Attr, 0, Model, &LiteralLoc))
return;
if (!isa<VarDecl>(D) || !cast<VarDecl>(D)->getTLSKind()) {
@@ -1999,7 +1998,7 @@
// Handle the case where the attribute has a text message.
StringRef Str;
- if (NumArgs == 1 && !checkStringLiteralArgument(S, Str, Attr, 0))
+ if (NumArgs == 1 && !S.checkStringLiteralArgumentAttr(Attr, 0, Str))
return;
D->addAttr(::new (S.Context) AttrTy(Attr.getRange(), S.Context, Str,
@@ -2310,7 +2309,7 @@
// Check that the argument is a string literal.
StringRef TypeStr;
SourceLocation LiteralLoc;
- if (!checkStringLiteralArgument(S, TypeStr, Attr, 0, &LiteralLoc))
+ if (!S.checkStringLiteralArgumentAttr(Attr, 0, TypeStr, &LiteralLoc))
return;
VisibilityAttr::VisibilityType type;
@@ -2724,7 +2723,7 @@
// argument.
StringRef Str;
SourceLocation LiteralLoc;
- if (!checkStringLiteralArgument(S, Str, Attr, 0, &LiteralLoc))
+ if (!S.checkStringLiteralArgumentAttr(Attr, 0, Str, &LiteralLoc))
return;
// If the target wants to validate the section specifier, make it happen.
@@ -3195,7 +3194,7 @@
// Make sure that there is a string literal as the annotation's single
// argument.
StringRef Str;
- if (!checkStringLiteralArgument(S, Str, Attr, 0))
+ if (!S.checkStringLiteralArgumentAttr(Attr, 0, Str))
return;
// Don't duplicate annotations that are already set.
@@ -3793,7 +3792,7 @@
break;
case AttributeList::AT_Pcs: {
StringRef StrRef;
- if (!checkStringLiteralArgument(*this, StrRef, attr, 0)) {
+ if (!checkStringLiteralArgumentAttr(attr, 0, StrRef)) {
attr.setInvalid();
return true;
}
@@ -4353,7 +4352,7 @@
StringRef StrRef;
SourceLocation LiteralLoc;
- if (!checkStringLiteralArgument(S, StrRef, Attr, 0, &LiteralLoc))
+ if (!S.checkStringLiteralArgumentAttr(Attr, 0, StrRef, &LiteralLoc))
return;
// GUID format is "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" or