[llvm] r200358 - MC: Clean up error paths in AsmParser::parseMacroArgument
David Majnemer
david.majnemer at gmail.com
Tue Jan 28 16:07:39 PST 2014
Author: majnemer
Date: Tue Jan 28 18:07:39 2014
New Revision: 200358
URL: http://llvm.org/viewvc/llvm-project?rev=200358&view=rev
Log:
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.
Modified:
llvm/trunk/lib/MC/MCParser/AsmParser.cpp
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=200358&r1=200357&r2=200358&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Tue Jan 28 18:07:39 2014
@@ -1863,29 +1863,40 @@ static bool isOperator(AsmToken::TokenKi
}
}
+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(MCAsm
Lex();
}
- Lexer.setSkipSpace(true);
if (ParenLevel != 0)
return TokError("unbalanced parentheses in macro argument");
return false;
More information about the llvm-commits
mailing list