mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-13 13:45:16 +00:00
Change the token representation to take a Start and Length instead of a
Start/End pointer. llvm-svn: 38548
This commit is contained in:
parent
504f2ebb8b
commit
33ce7283ee
@ -626,7 +626,7 @@ void DoPrintPreprocessedInput(Preprocessor &PP) {
|
|||||||
}
|
}
|
||||||
isFirstToken = false;
|
isFirstToken = false;
|
||||||
|
|
||||||
if (Tok.getEnd()-Tok.getStart() < 256) {
|
if (Tok.getLength() < 256) {
|
||||||
unsigned Len = Lexer::getSpelling(Tok, Buffer, PP.getLangOptions());
|
unsigned Len = Lexer::getSpelling(Tok, Buffer, PP.getLangOptions());
|
||||||
Buffer[Len] = 0;
|
Buffer[Len] = 0;
|
||||||
std::cout << Buffer;
|
std::cout << Buffer;
|
||||||
|
@ -86,10 +86,10 @@ void LexerToken::dump(bool DumpFlags) const {
|
|||||||
// #define TWELVE 1\ <whitespace only>
|
// #define TWELVE 1\ <whitespace only>
|
||||||
// 2
|
// 2
|
||||||
// TWELVE
|
// TWELVE
|
||||||
std::cerr << "*unspelled*" << std::string(Start, End);
|
std::cerr << "*unspelled*" << std::string(getStart(), getEnd());
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
std::cerr << std::string(Start, End);
|
std::cerr << std::string(getStart(), getEnd());
|
||||||
std::cerr << "'";
|
std::cerr << "'";
|
||||||
|
|
||||||
if (DumpFlags) {
|
if (DumpFlags) {
|
||||||
@ -99,7 +99,7 @@ void LexerToken::dump(bool DumpFlags) const {
|
|||||||
if (hasLeadingSpace())
|
if (hasLeadingSpace())
|
||||||
std::cerr << " [LeadingSpace]";
|
std::cerr << " [LeadingSpace]";
|
||||||
if (needsCleaning())
|
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.
|
// Otherwise, hard case, relex the characters into the string.
|
||||||
std::string Result;
|
std::string Result;
|
||||||
Result.reserve(Tok.getEnd()-Tok.getStart());
|
Result.reserve(Tok.getLength());
|
||||||
|
|
||||||
for (const char *Ptr = Tok.getStart(), *End = Tok.getEnd(); Ptr != End; ) {
|
for (const char *Ptr = Tok.getStart(), *End = Tok.getEnd(); Ptr != End; ) {
|
||||||
unsigned CharSize;
|
unsigned CharSize;
|
||||||
Result.push_back(getCharAndSizeNoWarn(Ptr, CharSize, Features));
|
Result.push_back(getCharAndSizeNoWarn(Ptr, CharSize, Features));
|
||||||
Ptr += CharSize;
|
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!");
|
"NeedsCleaning flag set on something that didn't need cleaning!");
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
@ -409,13 +409,13 @@ unsigned Lexer::getSpelling(const LexerToken &Tok, char *Buffer,
|
|||||||
|
|
||||||
// If this token contains nothing interesting, return it directly.
|
// If this token contains nothing interesting, return it directly.
|
||||||
if (!Tok.needsCleaning()) {
|
if (!Tok.needsCleaning()) {
|
||||||
unsigned Size = Tok.getEnd()-Tok.getStart();
|
unsigned Size = Tok.getLength();
|
||||||
memcpy(Buffer, Tok.getStart(), Size);
|
memcpy(Buffer, Tok.getStart(), Size);
|
||||||
return Size;
|
return Size;
|
||||||
}
|
}
|
||||||
// Otherwise, hard case, relex the characters into the string.
|
// Otherwise, hard case, relex the characters into the string.
|
||||||
std::string Result;
|
std::string Result;
|
||||||
Result.reserve(Tok.getEnd()-Tok.getStart());
|
Result.reserve(Tok.getLength());
|
||||||
|
|
||||||
char *OutBuf = Buffer;
|
char *OutBuf = Buffer;
|
||||||
for (const char *Ptr = Tok.getStart(), *End = Tok.getEnd(); Ptr != End; ) {
|
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);
|
*OutBuf++ = getCharAndSizeNoWarn(Ptr, CharSize, Features);
|
||||||
Ptr += CharSize;
|
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!");
|
"NeedsCleaning flag set on something that didn't need cleaning!");
|
||||||
|
|
||||||
return OutBuf-Buffer;
|
return OutBuf-Buffer;
|
||||||
@ -459,7 +459,7 @@ FinishIdentifier:
|
|||||||
SpelledTokEnd = Result.getEnd();
|
SpelledTokEnd = Result.getEnd();
|
||||||
} else {
|
} else {
|
||||||
// Cleaning needed, alloca a buffer, clean into it, then use the buffer.
|
// 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);
|
unsigned Size = getSpelling(Result, TmpBuf);
|
||||||
SpelledTokStart = TmpBuf;
|
SpelledTokStart = TmpBuf;
|
||||||
SpelledTokEnd = TmpBuf+Size;
|
SpelledTokEnd = TmpBuf+Size;
|
||||||
|
@ -54,7 +54,8 @@ struct LangOptions {
|
|||||||
/// compressed into a smaller form if memory footprint is important.
|
/// compressed into a smaller form if memory footprint is important.
|
||||||
class LexerToken {
|
class LexerToken {
|
||||||
/// The start and end of the token text itself.
|
/// 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.
|
/// TheLexer - The lexer object this token came from.
|
||||||
const Lexer *TheLexer;
|
const Lexer *TheLexer;
|
||||||
@ -84,9 +85,13 @@ public:
|
|||||||
void SetKind(tok::TokenKind K) { Kind = K; }
|
void SetKind(tok::TokenKind K) { Kind = K; }
|
||||||
|
|
||||||
const char *getStart() const { return Start; }
|
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 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; }
|
const Lexer *getLexer() const { return TheLexer; }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user