/// 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;
*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;
}
// 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,
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()) {
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()) {
// 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,
// 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;
// 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.
// 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.
break;
case AttributeList::AT_Pcs: {
StringRef StrRef;
- if (!checkStringLiteralArgument(*this, StrRef, attr, 0)) {
+ if (!checkStringLiteralArgumentAttr(attr, 0, StrRef)) {
attr.setInvalid();
return true;
}
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