r191768 - Move checkStringLiteralArgument into Sema class

Tim Northover tnorthover at apple.com
Tue Oct 1 07:34:19 PDT 2013


Author: tnorthover
Date: Tue Oct  1 09:34:18 2013
New Revision: 191768

URL: http://llvm.org/viewvc/llvm-project?rev=191768&view=rev
Log:
Move checkStringLiteralArgument into Sema class

It's a useful function to have around for target-specific attributes.

Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=191768&r1=191767&r2=191768&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Oct  1 09:34:18 2013
@@ -2543,6 +2543,10 @@ public:
   bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC, 
                             const FunctionDecl *FD = 0);
   bool CheckNoReturnAttr(const AttributeList &attr);
+  bool checkStringLiteralArgumentAttr(const AttributeList &Attr,
+                                      unsigned ArgNum, StringRef &Str,
+                                      SourceLocation *ArgLocation = 0);
+
   void CheckAlignasUnderalignment(Decl *D);
 
   /// Adjust the calling convention of a method to be the ABI default if it

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=191768&r1=191767&r2=191768&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Oct  1 09:34:18 2013
@@ -287,17 +287,16 @@ static bool checkFunctionOrMethodArgumen
 /// 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 @@ static bool checkStringLiteralArgument(S
     *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 @@ static void handleWeakRefAttr(Sema &S, D
   // 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 handleWeakRefAttr(Sema &S, D
 
 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 @@ static void handleTLSModelAttr(Sema &S,
   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 @@ static void handleAttrWithMessage(Sema &
 
   // 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 @@ static void handleVisibilityAttr(Sema &S
   // 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 @@ static void handleSectionAttr(Sema &S, D
   // 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 @@ static void handleAnnotateAttr(Sema &S,
   // 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 @@ bool Sema::CheckCallingConvAttr(const At
     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 @@ static void handleUuidAttr(Sema &S, Decl
 
   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





More information about the cfe-commits mailing list