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:
David Majnemer 2014-01-29 00:07:39 +00:00
parent 07dc57c38a
commit 7a3457077e

View File

@ -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,
AsmToken::TokenKind &ArgumentDelimiter) {
unsigned ParenLevel = 0;
unsigned AddTokens = 0;
// gas accepts arguments separated by whitespace, except on Darwin
if (!IsDarwin)
Lexer.setSkipSpace(false);
// Darwin doesn't use spaces to delmit arguments.
AsmLexerSkipSpaceRAII ScopedSkipSpace(Lexer, IsDarwin);
for (;;) {
if (Lexer.is(AsmToken::Eof) || Lexer.is(AsmToken::Equal)) {
Lexer.setSkipSpace(true);
if (Lexer.is(AsmToken::Eof) || Lexer.is(AsmToken::Equal))
return TokError("unexpected token in macro instantiation");
}
if (ParenLevel == 0 && Lexer.is(AsmToken::Comma)) {
// Spaces and commas cannot be mixed to delimit parameters
if (ArgumentDelimiter == AsmToken::Eof)
ArgumentDelimiter = AsmToken::Comma;
else if (ArgumentDelimiter != AsmToken::Comma) {
Lexer.setSkipSpace(true);
else if (ArgumentDelimiter != AsmToken::Comma)
return TokError("expected ' ' for macro argument separator");
}
break;
}
@ -1932,7 +1943,6 @@ bool AsmParser::parseMacroArgument(MCAsmMacroArgument &MA,
Lex();
}
Lexer.setSkipSpace(true);
if (ParenLevel != 0)
return TokError("unbalanced parentheses in macro argument");
return false;