/// This is true if the assembler allows the "?" character at the start of
/// of a string to be lexed as an AsmToken::Identifier.
- /// If the CommentString is also set to "?", setting this option will have
- /// no effect, and the string will be lexed as a comment.
- /// Defaults to false.
+ /// If the AsmLexer determines that the string can be lexed as a possible
+ /// comment, setting this option will have no effect, and the string will
+ /// still be lexed as a comment.
bool AllowQuestionAtStartOfIdentifier = false;
/// This is true if the assembler allows the "$" character at the start of
/// of a string to be lexed as an AsmToken::Identifier.
- /// If the CommentString is also set to "$", setting this option will have
- /// no effect, and the string will be lexed as a comment.
- /// Defaults to false.
+ /// If the AsmLexer determines that the string can be lexed as a possible
+ /// comment, setting this option will have no effect, and the string will
+ /// still be lexed as a comment.
bool AllowDollarAtStartOfIdentifier = false;
/// This is true if the assembler allows the "@" character at the start of
/// a string to be lexed as an AsmToken::Identifier.
- /// If the CommentString is also set to "@", setting this option will have
- /// no effect, and the string will be lexed as a comment.
- /// Defaults to false.
+ /// If the AsmLexer determines that the string can be lexed as a possible
+ /// comment, setting this option will have no effect, and the string will
+ /// still be lexed as a comment.
bool AllowAtAtStartOfIdentifier = false;
+ /// This is true if the assembler allows the "#" character at the start of
+ /// a string to be lexed as an AsmToken::Identifier.
+ /// If the AsmLexer determines that the string can be lexed as a possible
+ /// comment, setting this option will have no effect, and the string will
+ /// still be lexed as a comment.
+ bool AllowHashAtStartOfIdentifier = false;
+
/// If this is true, symbol names with invalid characters will be printed in
/// quotes.
bool SupportsQuotedNames = true;
bool doesAllowDollarAtStartOfIdentifier() const {
return AllowDollarAtStartOfIdentifier;
}
+ bool doesAllowHashAtStartOfIdentifier() const {
+ return AllowHashAtStartOfIdentifier;
+ }
bool supportsNameQuoting() const { return SupportsQuotedNames; }
bool doesSupportDataRegionDirectives() const {
void setAllowDollarAtStartOfIdentifier(bool Value) {
AllowDollarAtStartOfIdentifier = Value;
}
+ void setAllowHashAtStartOfIdentifier(bool Value) {
+ AllowHashAtStartOfIdentifier = Value;
+ }
};
// Setup a testing class that the GTest framework can call.
{AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
lexAndCheckTokens(AsmStr, ExpectedTokens);
}
+
+TEST_F(SystemZAsmLexerTest, CheckAcceptHashAtStartOfIdentifier) {
+ StringRef AsmStr = "##a#b$c";
+
+ // Setup.
+ MUPMAI->setAllowHashAtStartOfIdentifier(true);
+ MUPMAI->setCommentString("*");
+ MUPMAI->setAllowAdditionalComments(false);
+ setupCallToAsmParser(AsmStr);
+ Parser->getLexer().setAllowHashInIdentifier(true);
+
+ // Lex initially to get the string.
+ Parser->getLexer().Lex();
+
+ SmallVector<AsmToken::TokenKind> ExpectedTokens(
+ {AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
+ lexAndCheckTokens(AsmStr, ExpectedTokens);
+}
+
+TEST_F(SystemZAsmLexerTest, CheckAcceptHashAtStartOfIdentifier2) {
+ StringRef AsmStr = "##a#b$c";
+
+ // Setup.
+ MUPMAI->setAllowHashAtStartOfIdentifier(true);
+ setupCallToAsmParser(AsmStr);
+ Parser->getLexer().setAllowHashInIdentifier(true);
+
+ // Lex initially to get the string.
+ Parser->getLexer().Lex();
+
+ // By default, the CommentString attribute is set to "#".
+ // Hence, "##a#b$c" is lexed as a line comment irrespective
+ // of whether the AllowHashAtStartOfIdentifier attribute is set to true.
+ SmallVector<AsmToken::TokenKind> ExpectedTokens(
+ {AsmToken::EndOfStatement, AsmToken::Eof});
+ lexAndCheckTokens(AsmStr, ExpectedTokens);
+}
+
+TEST_F(SystemZAsmLexerTest, CheckAcceptHashAtStartOfIdentifier3) {
+ StringRef AsmStr = "##a#b$c";
+
+ // Setup.
+ MUPMAI->setAllowHashAtStartOfIdentifier(true);
+ MUPMAI->setCommentString("*");
+ setupCallToAsmParser(AsmStr);
+ Parser->getLexer().setAllowHashInIdentifier(true);
+
+ // Lex initially to get the string.
+ Parser->getLexer().Lex();
+
+ // By default, the AsmLexer treats strings that start with "#"
+ // as a line comment.
+ // Hence, "##a$b$c" is lexed as a line comment irrespective
+ // of whether the AllowHashAtStartOfIdentifier attribute is set to true.
+ SmallVector<AsmToken::TokenKind> ExpectedTokens(
+ {AsmToken::EndOfStatement, AsmToken::Eof});
+ lexAndCheckTokens(AsmStr, ExpectedTokens);
+}
+
+TEST_F(SystemZAsmLexerTest, CheckAcceptHashAtStartOfIdentifier4) {
+ StringRef AsmStr = "##a#b$c";
+
+ // Setup.
+ MUPMAI->setAllowHashAtStartOfIdentifier(true);
+ MUPMAI->setCommentString("*");
+ MUPMAI->setAllowAdditionalComments(false);
+ setupCallToAsmParser(AsmStr);
+ Parser->getLexer().setAllowHashInIdentifier(true);
+
+ // Lex initially to get the string.
+ Parser->getLexer().Lex();
+
+ // Since, the AllowAdditionalComments attribute is set to false,
+ // only strings starting with the CommentString attribute are
+ // lexed as possible comments.
+ // Hence, "##a$b$c" is lexed as an Identifier because the
+ // AllowHashAtStartOfIdentifier attribute is set to true.
+ SmallVector<AsmToken::TokenKind> ExpectedTokens(
+ {AsmToken::Identifier, AsmToken::EndOfStatement, AsmToken::Eof});
+ lexAndCheckTokens(AsmStr, ExpectedTokens);
+}
} // end anonymous namespace