LLVM  5.0.0
StringMatcher.h
Go to the documentation of this file.
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 LLVM_TABLEGEN_STRINGMATCHER_H
15 #define LLVM_TABLEGEN_STRINGMATCHER_H
16 
17 #include "llvm/ADT/StringRef.h"
18 #include <string>
19 #include <utility>
20 #include <vector>
21 
22 namespace llvm {
23 
24 class raw_ostream;
25 
26 /// StringMatcher - Given a list of strings and code to execute when they match,
27 /// output a simple switch tree to classify the input string.
28 ///
29 /// If a match is found, the code in Vals[i].second is executed; control must
30 /// not exit this code fragment. If nothing matches, execution falls through.
31 ///
33 public:
34  using StringPair = std::pair<std::string, std::string>;
35 
36 private:
37  StringRef StrVariableName;
38  const std::vector<StringPair> &Matches;
39  raw_ostream &OS;
40 
41 public:
42  StringMatcher(StringRef strVariableName,
43  const std::vector<StringPair> &matches, raw_ostream &os)
44  : StrVariableName(strVariableName), Matches(matches), OS(os) {}
45 
46  void Emit(unsigned Indent = 0) const;
47 
48 private:
49  bool EmitStringMatcherForChar(const std::vector<const StringPair*> &Matches,
50  unsigned CharNo, unsigned IndentCount) const;
51 };
52 
53 } // end namespace llvm
54 
55 #endif // LLVM_TABLEGEN_STRINGMATCHER_H
StringMatcher(StringRef strVariableName, const std::vector< StringPair > &matches, raw_ostream &os)
Definition: StringMatcher.h:42
std::pair< std::string, std::string > StringPair
Definition: StringMatcher.h:34
StringMatcher - Given a list of strings and code to execute when they match, output a simple switch t...
Definition: StringMatcher.h:32
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void Emit(unsigned Indent=0) const
Emit - Top level entry point.