Chris Lattner | 5845e5c | 2010-09-06 02:01:51 +0000 | [diff] [blame] | 1 | //===- StringMatcher.h - Generate a matcher for input strings ---*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the StringMatcher class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef STRINGMATCHER_H |
| 15 | #define STRINGMATCHER_H |
| 16 | |
| 17 | #include <vector> |
| 18 | #include <string> |
| 19 | #include <utility> |
| 20 | #include "llvm/ADT/StringRef.h" |
| 21 | |
| 22 | namespace llvm { |
| 23 | class raw_ostream; |
| 24 | |
| 25 | /// StringMatcher - Given a list of strings and code to execute when they match, |
| 26 | /// output a simple switch tree to classify the input string. |
| 27 | /// |
| 28 | /// If a match is found, the code in Vals[i].second is executed; control must |
| 29 | /// not exit this code fragment. If nothing matches, execution falls through. |
| 30 | /// |
| 31 | class StringMatcher { |
| 32 | public: |
| 33 | typedef std::pair<std::string, std::string> StringPair; |
| 34 | private: |
| 35 | StringRef StrVariableName; |
| 36 | const std::vector<StringPair> &Matches; |
| 37 | raw_ostream &OS; |
| 38 | |
| 39 | public: |
| 40 | StringMatcher(StringRef strVariableName, |
| 41 | const std::vector<StringPair> &matches, raw_ostream &os) |
| 42 | : StrVariableName(strVariableName), Matches(matches), OS(os) {} |
| 43 | |
Chris Lattner | 902edf2 | 2010-09-06 03:50:59 +0000 | [diff] [blame] | 44 | void Emit(unsigned Indent = 0) const; |
Chris Lattner | 5845e5c | 2010-09-06 02:01:51 +0000 | [diff] [blame] | 45 | |
| 46 | |
| 47 | private: |
| 48 | bool EmitStringMatcherForChar(const std::vector<const StringPair*> &Matches, |
| 49 | unsigned CharNo, unsigned IndentCount) const; |
| 50 | }; |
| 51 | |
| 52 | } // end llvm namespace. |
| 53 | |
| 54 | #endif |