1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

allow specifying an indentation level for the string matcher.

llvm-svn: 113143
This commit is contained in:
Chris Lattner 2010-09-06 03:50:59 +00:00
parent 8d0ee62652
commit 8615b37209
2 changed files with 12 additions and 8 deletions

View File

@ -112,7 +112,10 @@ EmitStringMatcherForChar(const std::vector<const StringPair*> &Matches,
/// Emit - Top level entry point. /// Emit - Top level entry point.
/// ///
void StringMatcher::Emit() const { void StringMatcher::Emit(unsigned Indent) const {
// If nothing to match, just fall through.
if (Matches.empty()) return;
// First level categorization: group strings by length. // First level categorization: group strings by length.
std::map<unsigned, std::vector<const StringPair*> > MatchesByLength; std::map<unsigned, std::vector<const StringPair*> > MatchesByLength;
@ -121,16 +124,17 @@ void StringMatcher::Emit() const {
// Output a switch statement on length and categorize the elements within each // Output a switch statement on length and categorize the elements within each
// bin. // bin.
OS << " switch (" << StrVariableName << ".size()) {\n"; OS.indent(Indent*2+2) << "switch (" << StrVariableName << ".size()) {\n";
OS << " default: break;\n"; OS.indent(Indent*2+2) << "default: break;\n";
for (std::map<unsigned, std::vector<const StringPair*> >::iterator LI = for (std::map<unsigned, std::vector<const StringPair*> >::iterator LI =
MatchesByLength.begin(), E = MatchesByLength.end(); LI != E; ++LI) { MatchesByLength.begin(), E = MatchesByLength.end(); LI != E; ++LI) {
OS << " case " << LI->first << ":\t // " << LI->second.size() OS.indent(Indent*2+2) << "case " << LI->first << ":\t // "
<< LI->second.size()
<< " string" << (LI->second.size() == 1 ? "" : "s") << " to match.\n"; << " string" << (LI->second.size() == 1 ? "" : "s") << " to match.\n";
if (EmitStringMatcherForChar(LI->second, 0, 0)) if (EmitStringMatcherForChar(LI->second, 0, Indent))
OS << " break;\n"; OS.indent(Indent*2+4) << "break;\n";
} }
OS << " }\n"; OS.indent(Indent*2+2) << "}\n";
} }

View File

@ -41,7 +41,7 @@ public:
const std::vector<StringPair> &matches, raw_ostream &os) const std::vector<StringPair> &matches, raw_ostream &os)
: StrVariableName(strVariableName), Matches(matches), OS(os) {} : StrVariableName(strVariableName), Matches(matches), OS(os) {}
void Emit() const; void Emit(unsigned Indent = 0) const;
private: private: