diff options
author | Sjoerd Meijer <sjoerd.meijer@arm.com> | 2019-08-15 07:39:05 +0000 |
---|---|---|
committer | Sjoerd Meijer <sjoerd.meijer@arm.com> | 2019-08-15 07:39:05 +0000 |
commit | 90374f7557211992bbfb0ba51ad31ee49943f0d3 (patch) | |
tree | 1d8fec9e443a7d25679d17785b5b334767a52324 | |
parent | 5c5408ce2c8c870a7365f18b9fb713c8d085f49b (diff) | |
download | llvm-90374f7557211992bbfb0ba51ad31ee49943f0d3.zip llvm-90374f7557211992bbfb0ba51ad31ee49943f0d3.tar.gz llvm-90374f7557211992bbfb0ba51ad31ee49943f0d3.tar.bz2 |
[clang] Loop pragma parsing. NFC.
Just a refactoring and a tidy up.
Differential Revision: https://reviews.llvm.org/D64564
llvm-svn: 368976
-rw-r--r-- | clang/lib/Parse/ParsePragma.cpp | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp index fae9b6c..dac8c41 100644 --- a/clang/lib/Parse/ParsePragma.cpp +++ b/clang/lib/Parse/ParsePragma.cpp @@ -1006,18 +1006,13 @@ struct PragmaLoopHintInfo { } // end anonymous namespace static std::string PragmaLoopHintString(Token PragmaName, Token Option) { - std::string PragmaString; - if (PragmaName.getIdentifierInfo()->getName() == "loop") { - PragmaString = "clang loop "; - PragmaString += Option.getIdentifierInfo()->getName(); - } else if (PragmaName.getIdentifierInfo()->getName() == "unroll_and_jam") { - PragmaString = "unroll_and_jam"; - } else { - assert(PragmaName.getIdentifierInfo()->getName() == "unroll" && - "Unexpected pragma name"); - PragmaString = "unroll"; - } - return PragmaString; + StringRef Str = PragmaName.getIdentifierInfo()->getName(); + std::string ClangLoopStr = (llvm::Twine("clang loop ") + Str).str(); + return llvm::StringSwitch<StringRef>(Str) + .Case("loop", ClangLoopStr) + .Case("unroll_and_jam", Str) + .Case("unroll", Str) + .Default(""); } bool Parser::HandlePragmaLoopHint(LoopHint &Hint) { @@ -1041,12 +1036,12 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) { // Return a valid hint if pragma unroll or nounroll were specified // without an argument. - bool PragmaUnroll = PragmaNameInfo->getName() == "unroll"; - bool PragmaNoUnroll = PragmaNameInfo->getName() == "nounroll"; - bool PragmaUnrollAndJam = PragmaNameInfo->getName() == "unroll_and_jam"; - bool PragmaNoUnrollAndJam = PragmaNameInfo->getName() == "nounroll_and_jam"; - if (Toks.empty() && (PragmaUnroll || PragmaNoUnroll || PragmaUnrollAndJam || - PragmaNoUnrollAndJam)) { + auto IsLoopHint = llvm::StringSwitch<bool>(PragmaNameInfo->getName()) + .Cases("unroll", "nounroll", "unroll_and_jam", + "nounroll_and_jam", true) + .Default(false); + + if (Toks.empty() && IsLoopHint) { ConsumeAnnotationToken(); Hint.Range = Info->PragmaName.getLocation(); return true; |