summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlp Toker <alp@nuanti.com>2014-05-17 04:53:25 +0000
committerAlp Toker <alp@nuanti.com>2014-05-17 04:53:25 +0000
commit2d57cea25688fc3372467ee97505ed07d8474d48 (patch)
treeefe2fab72e9981b40469865ef663b56ae7cb8db8
parentec2748a8ad62769ff1a76d6ba2e57c17e888ded7 (diff)
downloadbcm5719-llvm-2d57cea25688fc3372467ee97505ed07d8474d48.tar.gz
bcm5719-llvm-2d57cea25688fc3372467ee97505ed07d8474d48.zip
Provide and use a safe Token::getRawIdentifier() accessor
llvm-svn: 209061
-rw-r--r--clang/include/clang/Lex/Token.h11
-rw-r--r--clang/lib/ARCMigrate/Transforms.cpp9
-rw-r--r--clang/lib/Lex/Lexer.cpp5
-rw-r--r--clang/lib/Lex/ModuleMap.cpp10
-rw-r--r--clang/lib/Lex/PPDirectives.cpp8
-rw-r--r--clang/lib/Lex/Preprocessor.cpp5
-rw-r--r--clang/lib/Sema/SemaObjCProperty.cpp3
-rw-r--r--clang/tools/libclang/CIndex.cpp10
8 files changed, 28 insertions, 33 deletions
diff --git a/clang/include/clang/Lex/Token.h b/clang/include/clang/Lex/Token.h
index a38e92d40e4..c8b77d11747 100644
--- a/clang/include/clang/Lex/Token.h
+++ b/clang/include/clang/Lex/Token.h
@@ -18,6 +18,7 @@
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/TemplateKinds.h"
#include "clang/Basic/TokenKinds.h"
+#include "llvm/ADT/StringRef.h"
#include <cstdlib>
namespace clang {
@@ -167,12 +168,12 @@ public:
PtrData = (void*) II;
}
- /// getRawIdentifierData - For a raw identifier token (i.e., an identifier
- /// lexed in raw mode), returns a pointer to the start of it in the text
- /// buffer if known, null otherwise.
- const char *getRawIdentifierData() const {
+ /// getRawIdentifier - For a raw identifier token (i.e., an identifier
+ /// lexed in raw mode), returns a reference to the text substring in the
+ /// buffer if known.
+ StringRef getRawIdentifier() const {
assert(is(tok::raw_identifier));
- return reinterpret_cast<const char*>(PtrData);
+ return StringRef(reinterpret_cast<const char *>(PtrData), getLength());
}
void setRawIdentifierData(const char *Ptr) {
assert(is(tok::raw_identifier));
diff --git a/clang/lib/ARCMigrate/Transforms.cpp b/clang/lib/ARCMigrate/Transforms.cpp
index c349cb59f8f..6ff7b6b9db8 100644
--- a/clang/lib/ARCMigrate/Transforms.cpp
+++ b/clang/lib/ARCMigrate/Transforms.cpp
@@ -413,8 +413,7 @@ bool MigrationContext::rewritePropertyAttribute(StringRef fromAttr,
if (tok.isNot(tok::at)) return false;
lexer.LexFromRawLexer(tok);
if (tok.isNot(tok::raw_identifier)) return false;
- if (StringRef(tok.getRawIdentifierData(), tok.getLength())
- != "property")
+ if (tok.getRawIdentifier() != "property")
return false;
lexer.LexFromRawLexer(tok);
if (tok.isNot(tok::l_paren)) return false;
@@ -430,8 +429,7 @@ bool MigrationContext::rewritePropertyAttribute(StringRef fromAttr,
while (1) {
if (tok.isNot(tok::raw_identifier)) return false;
- StringRef ident(tok.getRawIdentifierData(), tok.getLength());
- if (ident == fromAttr) {
+ if (tok.getRawIdentifier() == fromAttr) {
if (!toAttr.empty()) {
Pass.TA.replaceText(tok.getLocation(), fromAttr, toAttr);
return true;
@@ -496,8 +494,7 @@ bool MigrationContext::addPropertyAttribute(StringRef attr,
if (tok.isNot(tok::at)) return false;
lexer.LexFromRawLexer(tok);
if (tok.isNot(tok::raw_identifier)) return false;
- if (StringRef(tok.getRawIdentifierData(), tok.getLength())
- != "property")
+ if (tok.getRawIdentifier() != "property")
return false;
lexer.LexFromRawLexer(tok);
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 0955cc5b335..2e859d663ff 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -382,7 +382,7 @@ unsigned Lexer::getSpelling(const Token &Tok, const char *&Buffer,
const char *TokStart = 0;
// NOTE: this has to be checked *before* testing for an IdentifierInfo.
if (Tok.is(tok::raw_identifier))
- TokStart = Tok.getRawIdentifierData();
+ TokStart = Tok.getRawIdentifier().data();
else if (!Tok.hasUCN()) {
if (const IdentifierInfo *II = Tok.getIdentifierInfo()) {
// Just return the string from the identifier table, which is very quick.
@@ -637,8 +637,7 @@ Lexer::ComputePreamble(const llvm::MemoryBuffer *Buffer,
// the raw identifier to recognize and categorize preprocessor directives.
TheLexer.LexFromRawLexer(TheTok);
if (TheTok.getKind() == tok::raw_identifier && !TheTok.needsCleaning()) {
- StringRef Keyword(TheTok.getRawIdentifierData(),
- TheTok.getLength());
+ StringRef Keyword = TheTok.getRawIdentifier();
PreambleDirectiveKind PDK
= llvm::StringSwitch<PreambleDirectiveKind>(Keyword)
.Case("include", PDK_Skipped)
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index ce2c4f02e39..bdf71b5f4a1 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1055,10 +1055,11 @@ retry:
L.LexFromRawLexer(LToken);
Tok.Location = LToken.getLocation().getRawEncoding();
switch (LToken.getKind()) {
- case tok::raw_identifier:
- Tok.StringData = LToken.getRawIdentifierData();
- Tok.StringLength = LToken.getLength();
- Tok.Kind = llvm::StringSwitch<MMToken::TokenKind>(Tok.getString())
+ case tok::raw_identifier: {
+ StringRef RI = LToken.getRawIdentifier();
+ Tok.StringData = RI.data();
+ Tok.StringLength = RI.size();
+ Tok.Kind = llvm::StringSwitch<MMToken::TokenKind>(RI)
.Case("config_macros", MMToken::ConfigMacros)
.Case("conflict", MMToken::Conflict)
.Case("exclude", MMToken::ExcludeKeyword)
@@ -1075,6 +1076,7 @@ retry:
.Case("use", MMToken::UseKeyword)
.Default(MMToken::Identifier);
break;
+ }
case tok::comma:
Tok.Kind = MMToken::Comma;
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index b1675bc043c..537d5bf69da 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -310,9 +310,9 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc,
// to spell an i/e in a strange way that is another letter. Skipping this
// allows us to avoid looking up the identifier info for #define/#undef and
// other common directives.
- const char *RawCharData = Tok.getRawIdentifierData();
+ StringRef RI = Tok.getRawIdentifier();
- char FirstChar = RawCharData[0];
+ char FirstChar = RI[0];
if (FirstChar >= 'a' && FirstChar <= 'z' &&
FirstChar != 'i' && FirstChar != 'e') {
CurPPLexer->ParsingPreprocessorDirective = false;
@@ -326,8 +326,8 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc,
// when skipping.
char DirectiveBuf[20];
StringRef Directive;
- if (!Tok.needsCleaning() && Tok.getLength() < 20) {
- Directive = StringRef(RawCharData, Tok.getLength());
+ if (!Tok.needsCleaning() && RI.size() < 20) {
+ Directive = RI;
} else {
std::string DirectiveStr = getSpelling(Tok);
unsigned IdLen = DirectiveStr.size();
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index fec0d5bd732..5072978ed65 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -501,14 +501,13 @@ void Preprocessor::EndSourceFile() {
/// identifier information for the token and install it into the token,
/// updating the token kind accordingly.
IdentifierInfo *Preprocessor::LookUpIdentifierInfo(Token &Identifier) const {
- assert(Identifier.getRawIdentifierData() != 0 && "No raw identifier data!");
+ assert(!Identifier.getRawIdentifier().empty() && "No raw identifier data!");
// Look up this token, see if it is a macro, or if it is a language keyword.
IdentifierInfo *II;
if (!Identifier.needsCleaning() && !Identifier.hasUCN()) {
// No cleaning needed, just use the characters from the lexed buffer.
- II = getIdentifierInfo(StringRef(Identifier.getRawIdentifierData(),
- Identifier.getLength()));
+ II = getIdentifierInfo(Identifier.getRawIdentifier());
} else {
// Cleaning needed, alloca a buffer, clean into it, then use the buffer.
SmallString<64> IdentifierBuffer;
diff --git a/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp
index 1b49c2abdc9..6ece0a53c71 100644
--- a/clang/lib/Sema/SemaObjCProperty.cpp
+++ b/clang/lib/Sema/SemaObjCProperty.cpp
@@ -292,8 +292,7 @@ static bool LocPropertyAttribute( ASTContext &Context, const char *attrName,
Token Tok;
do {
lexer.LexFromRawLexer(Tok);
- if (Tok.is(tok::raw_identifier) &&
- StringRef(Tok.getRawIdentifierData(), Tok.getLength()) == attrName) {
+ if (Tok.is(tok::raw_identifier) && Tok.getRawIdentifier() == attrName) {
Loc = Tok.getLocation();
return true;
}
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 91205602c9f..5710d66890d 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -5694,14 +5694,13 @@ static void annotatePreprocessorTokens(CXTranslationUnit TU,
break;
MacroInfo *MI = 0;
- if (Tok.is(tok::raw_identifier) &&
- StringRef(Tok.getRawIdentifierData(), Tok.getLength()) == "define") {
+ if (Tok.is(tok::raw_identifier) && Tok.getRawIdentifier() == "define") {
if (lexNext(Lex, Tok, NextIdx, NumTokens))
break;
if (Tok.is(tok::raw_identifier)) {
- StringRef Name(Tok.getRawIdentifierData(), Tok.getLength());
- IdentifierInfo &II = PP.getIdentifierTable().get(Name);
+ IdentifierInfo &II =
+ PP.getIdentifierTable().get(Tok.getRawIdentifier());
SourceLocation MappedTokLoc =
CXXUnit->mapLocationToPreamble(Tok.getLocation());
MI = getMacroInfo(II, MappedTokLoc, TU);
@@ -6819,8 +6818,7 @@ MacroDefinition *cxindex::checkForMacroInMacroDefinition(const MacroInfo *MI,
if (!PPRec)
return 0;
- StringRef Name(Tok.getRawIdentifierData(), Tok.getLength());
- IdentifierInfo &II = PP.getIdentifierTable().get(Name);
+ IdentifierInfo &II = PP.getIdentifierTable().get(Tok.getRawIdentifier());
if (!II.hadMacroDefinition())
return 0;
OpenPOWER on IntegriCloud