diff options
| author | Alp Toker <alp@nuanti.com> | 2014-05-17 04:53:25 +0000 |
|---|---|---|
| committer | Alp Toker <alp@nuanti.com> | 2014-05-17 04:53:25 +0000 |
| commit | 2d57cea25688fc3372467ee97505ed07d8474d48 (patch) | |
| tree | efe2fab72e9981b40469865ef663b56ae7cb8db8 /clang/lib/Lex | |
| parent | ec2748a8ad62769ff1a76d6ba2e57c17e888ded7 (diff) | |
| download | bcm5719-llvm-2d57cea25688fc3372467ee97505ed07d8474d48.tar.gz bcm5719-llvm-2d57cea25688fc3372467ee97505ed07d8474d48.zip | |
Provide and use a safe Token::getRawIdentifier() accessor
llvm-svn: 209061
Diffstat (limited to 'clang/lib/Lex')
| -rw-r--r-- | clang/lib/Lex/Lexer.cpp | 5 | ||||
| -rw-r--r-- | clang/lib/Lex/ModuleMap.cpp | 10 | ||||
| -rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 5 |
4 files changed, 14 insertions, 14 deletions
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; |

