mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
MC: Clean up error paths in AsmParser::parseMacroArgument
Use an RAII object Instead of inserting a call to AsmLexer::setSkipSpace(true) in all error paths. No functional change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200358 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1863,29 +1863,40 @@ static bool isOperator(AsmToken::TokenKind kind) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
class AsmLexerSkipSpaceRAII {
|
||||||
|
public:
|
||||||
|
AsmLexerSkipSpaceRAII(AsmLexer &Lexer, bool SkipSpace) : Lexer(Lexer) {
|
||||||
|
Lexer.setSkipSpace(SkipSpace);
|
||||||
|
}
|
||||||
|
|
||||||
|
~AsmLexerSkipSpaceRAII() {
|
||||||
|
Lexer.setSkipSpace(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
AsmLexer &Lexer;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
|
bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
|
||||||
AsmToken::TokenKind &ArgumentDelimiter) {
|
AsmToken::TokenKind &ArgumentDelimiter) {
|
||||||
unsigned ParenLevel = 0;
|
unsigned ParenLevel = 0;
|
||||||
unsigned AddTokens = 0;
|
unsigned AddTokens = 0;
|
||||||
|
|
||||||
// gas accepts arguments separated by whitespace, except on Darwin
|
// Darwin doesn't use spaces to delmit arguments.
|
||||||
if (!IsDarwin)
|
AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
|
||||||
Lexer.setSkipSpace(false);
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (Lexer.is(AsmToken::Eof) || Lexer.is(AsmToken::Equal)) {
|
if (Lexer.is(AsmToken::Eof) || Lexer.is(AsmToken::Equal))
|
||||||
Lexer.setSkipSpace(true);
|
|
||||||
return TokError("unexpected token in macro instantiation");
|
return TokError("unexpected token in macro instantiation");
|
||||||
}
|
|
||||||
|
|
||||||
if (ParenLevel == 0 && Lexer.is(AsmToken::Comma)) {
|
if (ParenLevel == 0 && Lexer.is(AsmToken::Comma)) {
|
||||||
// Spaces and commas cannot be mixed to delimit parameters
|
// Spaces and commas cannot be mixed to delimit parameters
|
||||||
if (ArgumentDelimiter == AsmToken::Eof)
|
if (ArgumentDelimiter == AsmToken::Eof)
|
||||||
ArgumentDelimiter = AsmToken::Comma;
|
ArgumentDelimiter = AsmToken::Comma;
|
||||||
else if (ArgumentDelimiter != AsmToken::Comma) {
|
else if (ArgumentDelimiter != AsmToken::Comma)
|
||||||
Lexer.setSkipSpace(true);
|
|
||||||
return TokError("expected ' ' for macro argument separator");
|
return TokError("expected ' ' for macro argument separator");
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1932,7 +1943,6 @@ bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
|
|||||||
Lex();
|
Lex();
|
||||||
}
|
}
|
||||||
|
|
||||||
Lexer.setSkipSpace(true);
|
|
||||||
if (ParenLevel != 0)
|
if (ParenLevel != 0)
|
||||||
return TokError("unbalanced parentheses in macro argument");
|
return TokError("unbalanced parentheses in macro argument");
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user