Skip to content
Snippets Groups Projects
Commit 96fe532c authored by Chris Lattner's avatar Chris Lattner
Browse files

allow specifying an indentation level for the string matcher.

llvm-svn: 113143
parent 497d13e8
No related branches found
No related tags found
No related merge requests found
...@@ -112,7 +112,10 @@ EmitStringMatcherForChar(const std::vector<const StringPair*> &Matches, ...@@ -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 { ...@@ -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";
} }
...@@ -41,7 +41,7 @@ public: ...@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment