summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-06-18 07:35:33 +0000
committerChris Lattner <sabre@nondot.org>2006-06-18 07:35:33 +0000
commit33ce7283ee667d76a714ea4419857b1ece10a4e8 (patch)
treef376e2c6a9770b7d5edd962697df98c684d23f09
parent504f2ebb8becedb73c597743ba07c6d21125caf1 (diff)
downloadbcm5719-llvm-33ce7283ee667d76a714ea4419857b1ece10a4e8.tar.gz
bcm5719-llvm-33ce7283ee667d76a714ea4419857b1ece10a4e8.zip
Change the token representation to take a Start and Length instead of a
Start/End pointer. llvm-svn: 38548
-rw-r--r--clang/Driver/clang.cpp2
-rw-r--r--clang/Lex/Lexer.cpp18
-rw-r--r--clang/include/clang/Lex/Lexer.h11
3 files changed, 18 insertions, 13 deletions
diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp
index a1449390781..41d5adac528 100644
--- a/clang/Driver/clang.cpp
+++ b/clang/Driver/clang.cpp
@@ -626,7 +626,7 @@ void DoPrintPreprocessedInput(Preprocessor &PP) {
}
isFirstToken = false;
- if (Tok.getEnd()-Tok.getStart() < 256) {
+ if (Tok.getLength() < 256) {
unsigned Len = Lexer::getSpelling(Tok, Buffer, PP.getLangOptions());
Buffer[Len] = 0;
std::cout << Buffer;
diff --git a/clang/Lex/Lexer.cpp b/clang/Lex/Lexer.cpp
index f0c242744b8..fac724529fc 100644
--- a/clang/Lex/Lexer.cpp
+++ b/clang/Lex/Lexer.cpp
@@ -86,10 +86,10 @@ void LexerToken::dump(bool DumpFlags) const {
// #define TWELVE 1\ <whitespace only>
// 2
// TWELVE
- std::cerr << "*unspelled*" << std::string(Start, End);
+ std::cerr << "*unspelled*" << std::string(getStart(), getEnd());
}
} else
- std::cerr << std::string(Start, End);
+ std::cerr << std::string(getStart(), getEnd());
std::cerr << "'";
if (DumpFlags) {
@@ -99,7 +99,7 @@ void LexerToken::dump(bool DumpFlags) const {
if (hasLeadingSpace())
std::cerr << " [LeadingSpace]";
if (needsCleaning())
- std::cerr << " [Spelling='" << std::string(Start, End) << "']";
+ std::cerr << " [Spelling='" << std::string(getStart(), getEnd()) << "']";
}
}
@@ -387,14 +387,14 @@ std::string Lexer::getSpelling(const LexerToken &Tok,
// Otherwise, hard case, relex the characters into the string.
std::string Result;
- Result.reserve(Tok.getEnd()-Tok.getStart());
+ Result.reserve(Tok.getLength());
for (const char *Ptr = Tok.getStart(), *End = Tok.getEnd(); Ptr != End; ) {
unsigned CharSize;
Result.push_back(getCharAndSizeNoWarn(Ptr, CharSize, Features));
Ptr += CharSize;
}
- assert(Result.size() != unsigned(Tok.getEnd()-Tok.getStart()) &&
+ assert(Result.size() != unsigned(Tok.getLength()) &&
"NeedsCleaning flag set on something that didn't need cleaning!");
return Result;
}
@@ -409,13 +409,13 @@ unsigned Lexer::getSpelling(const LexerToken &Tok, char *Buffer,
// If this token contains nothing interesting, return it directly.
if (!Tok.needsCleaning()) {
- unsigned Size = Tok.getEnd()-Tok.getStart();
+ unsigned Size = Tok.getLength();
memcpy(Buffer, Tok.getStart(), Size);
return Size;
}
// Otherwise, hard case, relex the characters into the string.
std::string Result;
- Result.reserve(Tok.getEnd()-Tok.getStart());
+ Result.reserve(Tok.getLength());
char *OutBuf = Buffer;
for (const char *Ptr = Tok.getStart(), *End = Tok.getEnd(); Ptr != End; ) {
@@ -423,7 +423,7 @@ unsigned Lexer::getSpelling(const LexerToken &Tok, char *Buffer,
*OutBuf++ = getCharAndSizeNoWarn(Ptr, CharSize, Features);
Ptr += CharSize;
}
- assert(OutBuf-Buffer != Tok.getEnd()-Tok.getStart() &&
+ assert(unsigned(OutBuf-Buffer) != Tok.getLength() &&
"NeedsCleaning flag set on something that didn't need cleaning!");
return OutBuf-Buffer;
@@ -459,7 +459,7 @@ FinishIdentifier:
SpelledTokEnd = Result.getEnd();
} else {
// Cleaning needed, alloca a buffer, clean into it, then use the buffer.
- char *TmpBuf = (char*)alloca(Result.getEnd()-Result.getStart());
+ char *TmpBuf = (char*)alloca(Result.getLength());
unsigned Size = getSpelling(Result, TmpBuf);
SpelledTokStart = TmpBuf;
SpelledTokEnd = TmpBuf+Size;
diff --git a/clang/include/clang/Lex/Lexer.h b/clang/include/clang/Lex/Lexer.h
index 604928b641f..894f56c6eb6 100644
--- a/clang/include/clang/Lex/Lexer.h
+++ b/clang/include/clang/Lex/Lexer.h
@@ -54,7 +54,8 @@ struct LangOptions {
/// compressed into a smaller form if memory footprint is important.
class LexerToken {
/// The start and end of the token text itself.
- const char *Start, *End;
+ const char *Start;
+ unsigned Length;
/// TheLexer - The lexer object this token came from.
const Lexer *TheLexer;
@@ -84,9 +85,13 @@ public:
void SetKind(tok::TokenKind K) { Kind = K; }
const char *getStart() const { return Start; }
- const char *getEnd() const { return End; }
+ const char *getEnd() const { return Start+Length; }
+ unsigned getLength() const { return Length; }
void SetStart(const char *S) { Start = S; }
- void SetEnd (const char *E) { End = E; }
+
+ /// SetEnd - Specify the length of the token as lexed. This relies on the
+ /// start of the token having already been set.
+ void SetEnd(const char *End) { Length = End-Start; }
const Lexer *getLexer() const { return TheLexer; }
OpenPOWER on IntegriCloud