1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 05:01:59 +01:00

TableGen: Remove space at EOL in TGLexer.{h,cpp}

Change-Id: Ica5f39470174e85f173d3b6db95789033f75ce17
llvm-svn: 327158
This commit is contained in:
Nicolai Haehnle 2018-03-09 18:32:04 +00:00
parent bd3a277bb8
commit 450382f892
2 changed files with 34 additions and 34 deletions

View File

@ -56,7 +56,7 @@ int TGLexer::getNextChar() {
// a random nul in the file. Disambiguate that here. // a random nul in the file. Disambiguate that here.
if (CurPtr-1 != CurBuf.end()) if (CurPtr-1 != CurBuf.end())
return 0; // Just whitespace. return 0; // Just whitespace.
// If this is the end of an included file, pop the parent file off the // If this is the end of an included file, pop the parent file off the
// include stack. // include stack.
SMLoc ParentIncludeLoc = SrcMgr.getParentIncludeLoc(CurBuffer); SMLoc ParentIncludeLoc = SrcMgr.getParentIncludeLoc(CurBuffer);
@ -66,9 +66,9 @@ int TGLexer::getNextChar() {
CurPtr = ParentIncludeLoc.getPointer(); CurPtr = ParentIncludeLoc.getPointer();
return getNextChar(); return getNextChar();
} }
// Otherwise, return end of file. // Otherwise, return end of file.
--CurPtr; // Another call to lex will return EOF again. --CurPtr; // Another call to lex will return EOF again.
return EOF; return EOF;
} }
case '\n': case '\n':
@ -80,7 +80,7 @@ int TGLexer::getNextChar() {
*CurPtr != CurChar) *CurPtr != CurChar)
++CurPtr; // Eat the two char newline sequence. ++CurPtr; // Eat the two char newline sequence.
return '\n'; return '\n';
} }
} }
int TGLexer::peekNextChar(int Index) { int TGLexer::peekNextChar(int Index) {
@ -115,7 +115,7 @@ tgtok::TokKind TGLexer::LexToken() {
case '=': return tgtok::equal; case '=': return tgtok::equal;
case '?': return tgtok::question; case '?': return tgtok::question;
case '#': return tgtok::paste; case '#': return tgtok::paste;
case 0: case 0:
case ' ': case ' ':
case '\t': case '\t':
@ -154,7 +154,7 @@ tgtok::TokKind TGLexer::LexToken() {
switch (NextNextChar) { switch (NextNextChar) {
default: default:
break; break;
case '0': case '1': case '0': case '1':
if (NextChar == 'b') if (NextChar == 'b')
return LexNumber(); return LexNumber();
LLVM_FALLTHROUGH; LLVM_FALLTHROUGH;
@ -184,24 +184,24 @@ tgtok::TokKind TGLexer::LexToken() {
/// LexString - Lex "[^"]*" /// LexString - Lex "[^"]*"
tgtok::TokKind TGLexer::LexString() { tgtok::TokKind TGLexer::LexString() {
const char *StrStart = CurPtr; const char *StrStart = CurPtr;
CurStrVal = ""; CurStrVal = "";
while (*CurPtr != '"') { while (*CurPtr != '"') {
// If we hit the end of the buffer, report an error. // If we hit the end of the buffer, report an error.
if (*CurPtr == 0 && CurPtr == CurBuf.end()) if (*CurPtr == 0 && CurPtr == CurBuf.end())
return ReturnError(StrStart, "End of file in string literal"); return ReturnError(StrStart, "End of file in string literal");
if (*CurPtr == '\n' || *CurPtr == '\r') if (*CurPtr == '\n' || *CurPtr == '\r')
return ReturnError(StrStart, "End of line in string literal"); return ReturnError(StrStart, "End of line in string literal");
if (*CurPtr != '\\') { if (*CurPtr != '\\') {
CurStrVal += *CurPtr++; CurStrVal += *CurPtr++;
continue; continue;
} }
++CurPtr; ++CurPtr;
switch (*CurPtr) { switch (*CurPtr) {
case '\\': case '\'': case '"': case '\\': case '\'': case '"':
// These turn into their literal character. // These turn into their literal character.
@ -215,7 +215,7 @@ tgtok::TokKind TGLexer::LexString() {
CurStrVal += '\n'; CurStrVal += '\n';
++CurPtr; ++CurPtr;
break; break;
case '\n': case '\n':
case '\r': case '\r':
return ReturnError(CurPtr, "escaped newlines not supported in tblgen"); return ReturnError(CurPtr, "escaped newlines not supported in tblgen");
@ -229,7 +229,7 @@ tgtok::TokKind TGLexer::LexString() {
return ReturnError(CurPtr, "invalid escape in string literal"); return ReturnError(CurPtr, "invalid escape in string literal");
} }
} }
++CurPtr; ++CurPtr;
return tgtok::StrVal; return tgtok::StrVal;
} }
@ -237,10 +237,10 @@ tgtok::TokKind TGLexer::LexString() {
tgtok::TokKind TGLexer::LexVarName() { tgtok::TokKind TGLexer::LexVarName() {
if (!isalpha(CurPtr[0]) && CurPtr[0] != '_') if (!isalpha(CurPtr[0]) && CurPtr[0] != '_')
return ReturnError(TokStart, "Invalid variable name"); return ReturnError(TokStart, "Invalid variable name");
// Otherwise, we're ok, consume the rest of the characters. // Otherwise, we're ok, consume the rest of the characters.
const char *VarNameStart = CurPtr++; const char *VarNameStart = CurPtr++;
while (isalpha(*CurPtr) || isdigit(*CurPtr) || *CurPtr == '_') while (isalpha(*CurPtr) || isdigit(*CurPtr) || *CurPtr == '_')
++CurPtr; ++CurPtr;
@ -309,7 +309,7 @@ bool TGLexer::LexInclude() {
PrintError(getLoc(), "Could not find include file '" + Filename + "'"); PrintError(getLoc(), "Could not find include file '" + Filename + "'");
return true; return true;
} }
DependenciesMapTy::const_iterator Found = Dependencies.find(IncludedFile); DependenciesMapTy::const_iterator Found = Dependencies.find(IncludedFile);
if (Found != Dependencies.end()) { if (Found != Dependencies.end()) {
PrintError(getLoc(), PrintError(getLoc(),
@ -348,7 +348,7 @@ void TGLexer::SkipBCPLComment() {
bool TGLexer::SkipCComment() { bool TGLexer::SkipCComment() {
++CurPtr; // skip the star. ++CurPtr; // skip the star.
unsigned CommentDepth = 1; unsigned CommentDepth = 1;
while (true) { while (true) {
int CurChar = getNextChar(); int CurChar = getNextChar();
switch (CurChar) { switch (CurChar) {
@ -358,7 +358,7 @@ bool TGLexer::SkipCComment() {
case '*': case '*':
// End of the comment? // End of the comment?
if (CurPtr[0] != '/') break; if (CurPtr[0] != '/') break;
++CurPtr; // End the */. ++CurPtr; // End the */.
if (--CommentDepth == 0) if (--CommentDepth == 0)
return false; return false;
@ -384,7 +384,7 @@ tgtok::TokKind TGLexer::LexNumber() {
const char *NumStart = CurPtr; const char *NumStart = CurPtr;
while (isxdigit(CurPtr[0])) while (isxdigit(CurPtr[0]))
++CurPtr; ++CurPtr;
// Requires at least one hex digit. // Requires at least one hex digit.
if (CurPtr == NumStart) if (CurPtr == NumStart)
return ReturnError(TokStart, "Invalid hexadecimal number"); return ReturnError(TokStart, "Invalid hexadecimal number");
@ -423,7 +423,7 @@ tgtok::TokKind TGLexer::LexNumber() {
else if (CurPtr[-1] == '+') else if (CurPtr[-1] == '+')
return tgtok::plus; return tgtok::plus;
} }
while (isdigit(CurPtr[0])) while (isdigit(CurPtr[0]))
++CurPtr; ++CurPtr;
CurIntVal = strtoll(TokStart, nullptr, 10); CurIntVal = strtoll(TokStart, nullptr, 10);
@ -440,9 +440,9 @@ tgtok::TokKind TGLexer::LexBracket() {
while (true) { while (true) {
int Char = getNextChar(); int Char = getNextChar();
if (Char == EOF) break; if (Char == EOF) break;
if (Char != '}') continue; if (Char != '}') continue;
Char = getNextChar(); Char = getNextChar();
if (Char == EOF) break; if (Char == EOF) break;
if (Char == ']') { if (Char == ']') {
@ -450,7 +450,7 @@ tgtok::TokKind TGLexer::LexBracket() {
return tgtok::CodeFragment; return tgtok::CodeFragment;
} }
} }
return ReturnError(CodeStart-2, "Unterminated Code Block"); return ReturnError(CodeStart-2, "Unterminated Code Block");
} }
@ -458,11 +458,11 @@ tgtok::TokKind TGLexer::LexBracket() {
tgtok::TokKind TGLexer::LexExclaim() { tgtok::TokKind TGLexer::LexExclaim() {
if (!isalpha(*CurPtr)) if (!isalpha(*CurPtr))
return ReturnError(CurPtr - 1, "Invalid \"!operator\""); return ReturnError(CurPtr - 1, "Invalid \"!operator\"");
const char *Start = CurPtr++; const char *Start = CurPtr++;
while (isalpha(*CurPtr)) while (isalpha(*CurPtr))
++CurPtr; ++CurPtr;
// Check to see which operator this is. // Check to see which operator this is.
tgtok::TokKind Kind = tgtok::TokKind Kind =
StringSwitch<tgtok::TokKind>(StringRef(Start, CurPtr - Start)) StringSwitch<tgtok::TokKind>(StringRef(Start, CurPtr - Start))

View File

@ -30,7 +30,7 @@ namespace tgtok {
enum TokKind { enum TokKind {
// Markers // Markers
Eof, Error, Eof, Error,
// Tokens with no info. // Tokens with no info.
minus, plus, // - + minus, plus, // - +
l_square, r_square, // [ ] l_square, r_square, // [ ]
@ -56,7 +56,7 @@ namespace tgtok {
// Binary constant. Note that these are sized according to the number of // Binary constant. Note that these are sized according to the number of
// bits given. // bits given.
BinaryIntVal, BinaryIntVal,
// String valued tokens. // String valued tokens.
Id, StrVal, VarName, CodeFragment Id, StrVal, VarName, CodeFragment
}; };
@ -65,7 +65,7 @@ namespace tgtok {
/// TGLexer - TableGen Lexer class. /// TGLexer - TableGen Lexer class.
class TGLexer { class TGLexer {
SourceMgr &SrcMgr; SourceMgr &SrcMgr;
const char *CurPtr; const char *CurPtr;
StringRef CurBuf; StringRef CurBuf;
@ -95,11 +95,11 @@ public:
const DependenciesMapTy &getDependencies() const { const DependenciesMapTy &getDependencies() const {
return Dependencies; return Dependencies;
} }
tgtok::TokKind getCode() const { return CurCode; } tgtok::TokKind getCode() const { return CurCode; }
const std::string &getCurStrVal() const { const std::string &getCurStrVal() const {
assert((CurCode == tgtok::Id || CurCode == tgtok::StrVal || assert((CurCode == tgtok::Id || CurCode == tgtok::StrVal ||
CurCode == tgtok::VarName || CurCode == tgtok::CodeFragment) && CurCode == tgtok::VarName || CurCode == tgtok::CodeFragment) &&
"This token doesn't have a string value"); "This token doesn't have a string value");
return CurStrVal; return CurStrVal;
@ -115,13 +115,13 @@ public:
} }
SMLoc getLoc() const; SMLoc getLoc() const;
private: private:
/// LexToken - Read the next token and return its code. /// LexToken - Read the next token and return its code.
tgtok::TokKind LexToken(); tgtok::TokKind LexToken();
tgtok::TokKind ReturnError(const char *Loc, const Twine &Msg); tgtok::TokKind ReturnError(const char *Loc, const Twine &Msg);
int getNextChar(); int getNextChar();
int peekNextChar(int Index); int peekNextChar(int Index);
void SkipBCPLComment(); void SkipBCPLComment();
@ -134,7 +134,7 @@ private:
tgtok::TokKind LexBracket(); tgtok::TokKind LexBracket();
tgtok::TokKind LexExclaim(); tgtok::TokKind LexExclaim();
}; };
} // end namespace llvm } // end namespace llvm
#endif #endif