]> granicus.if.org Git - clang/commitdiff
Use StringRef in Attr constructors.
authorBenjamin Kramer <benny.kra@googlemail.com>
Mon, 30 Nov 2009 17:08:26 +0000 (17:08 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Mon, 30 Nov 2009 17:08:26 +0000 (17:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90140 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Attr.h
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclAttr.cpp

index f8c2aa9c69ee5b118c030746e975ab5a9eca84c1..2c7ab9d67e95392245937d202b6e314e423b2103 100644 (file)
 #define LLVM_CLANG_AST_ATTR_H
 
 #include "llvm/Support/Casting.h"
-using llvm::dyn_cast;
-
+#include "llvm/ADT/StringRef.h"
 #include <cassert>
 #include <cstring>
 #include <string>
 #include <algorithm>
+using llvm::dyn_cast;
 
 namespace clang {
   class ASTContext;
@@ -217,7 +217,7 @@ public:
 class AnnotateAttr : public Attr {
   std::string Annotation;
 public:
-  AnnotateAttr(const std::string &ann) : Attr(Annotate), Annotation(ann) {}
+  AnnotateAttr(llvm::StringRef ann) : Attr(Annotate), Annotation(ann) {}
 
   const std::string& getAnnotation() const { return Annotation; }
 
@@ -233,7 +233,7 @@ public:
 class AsmLabelAttr : public Attr {
   std::string Label;
 public:
-  AsmLabelAttr(const std::string &L) : Attr(AsmLabel), Label(L) {}
+  AsmLabelAttr(llvm::StringRef L) : Attr(AsmLabel), Label(L) {}
 
   const std::string& getLabel() const { return Label; }
 
@@ -251,7 +251,7 @@ DEF_SIMPLE_ATTR(AlwaysInline);
 class AliasAttr : public Attr {
   std::string Aliasee;
 public:
-  AliasAttr(const std::string &aliasee) : Attr(Alias), Aliasee(aliasee) {}
+  AliasAttr(llvm::StringRef aliasee) : Attr(Alias), Aliasee(aliasee) {}
 
   const std::string& getAliasee() const { return Aliasee; }
 
@@ -325,7 +325,7 @@ DEF_SIMPLE_ATTR(Final);
 class SectionAttr : public Attr {
   std::string Name;
 public:
-  SectionAttr(const std::string &N) : Attr(Section), Name(N) {}
+  SectionAttr(llvm::StringRef N) : Attr(Section), Name(N) {}
 
   const std::string& getName() const { return Name; }
 
@@ -384,11 +384,11 @@ class FormatAttr : public Attr {
   std::string Type;
   int formatIdx, firstArg;
 public:
-  FormatAttr(const std::string &type, int idx, int first) : Attr(Format),
+  FormatAttr(llvm::StringRef type, int idx, int first) : Attr(Format),
              Type(type), formatIdx(idx), firstArg(first) {}
 
   const std::string& getType() const { return Type; }
-  void setType(const std::string &type) { Type = type; }
+  void setType(llvm::StringRef type) { Type = type; }
   int getFormatIdx() const { return formatIdx; }
   int getFirstArg() const { return firstArg; }
 
index 6121719abb6ac44df61223890aeb3ab0a2f71a79..220ceddbf6596f577d076974728b923546623d78 100644 (file)
@@ -2407,8 +2407,7 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
   if (Expr *E = (Expr*) D.getAsmLabel()) {
     // The parser guarantees this is a string.
     StringLiteral *SE = cast<StringLiteral>(E);
-    NewVD->addAttr(::new (Context) AsmLabelAttr(std::string(SE->getStrData(),
-                                                        SE->getByteLength())));
+    NewVD->addAttr(::new (Context) AsmLabelAttr(SE->getString()));
   }
 
   // Don't consider existing declarations that are in a different
@@ -2924,8 +2923,7 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
   if (Expr *E = (Expr*) D.getAsmLabel()) {
     // The parser guarantees this is a string.
     StringLiteral *SE = cast<StringLiteral>(E);
-    NewFD->addAttr(::new (Context) AsmLabelAttr(std::string(SE->getStrData(),
-                                                        SE->getByteLength())));
+    NewFD->addAttr(::new (Context) AsmLabelAttr(SE->getString()));
   }
 
   // Copy the parameter declarations from the declarator D to the function
index f40f125683b7de9f167da7f01d1adc2a12b9cc9b..b2124fe01459b8b23fb1ab0b71b0018e8da961e3 100644 (file)
@@ -411,12 +411,9 @@ static void HandleAliasAttr(Decl *d, const AttributeList &Attr, Sema &S) {
     return;
   }
 
-  const char *Alias = Str->getStrData();
-  unsigned AliasLen = Str->getByteLength();
-
   // FIXME: check if target symbol exists in current file
 
-  d->addAttr(::new (S.Context) AliasAttr(std::string(Alias, AliasLen)));
+  d->addAttr(::new (S.Context) AliasAttr(Str->getString()));
 }
 
 static void HandleAlwaysInlineAttr(Decl *d, const AttributeList &Attr,
@@ -1006,12 +1003,10 @@ static void HandleSectionAttr(Decl *D, const AttributeList &Attr, Sema &S) {
     return;
   }
 
-  std::string SectionStr(SE->getStrData(), SE->getByteLength());
-
   // If the target wants to validate the section specifier, make it happen.
-  std::string Error = S.Context.Target.isValidSectionSpecifier(SectionStr);
+  std::string Error = S.Context.Target.isValidSectionSpecifier(SE->getString());
   if (Error.empty()) {
-    D->addAttr(::new (S.Context) SectionAttr(SectionStr));
+    D->addAttr(::new (S.Context) SectionAttr(SE->getString()));
     return;
   }
 
@@ -1518,8 +1513,7 @@ static void HandleAnnotateAttr(Decl *d, const AttributeList &Attr, Sema &S) {
     S.Diag(ArgExpr->getLocStart(), diag::err_attribute_not_string) <<"annotate";
     return;
   }
-  d->addAttr(::new (S.Context) AnnotateAttr(std::string(SE->getStrData(),
-                                                        SE->getByteLength())));
+  d->addAttr(::new (S.Context) AnnotateAttr(SE->getString()));
 }
 
 static void HandleAlignedAttr(Decl *d, const AttributeList &Attr, Sema &S) {