LLVM API Documentation

StringMatcher.h
Go to the documentation of this file.
00001 //===- StringMatcher.h - Generate a matcher for input strings ---*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the StringMatcher class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_TABLEGEN_STRINGMATCHER_H
00015 #define LLVM_TABLEGEN_STRINGMATCHER_H
00016 
00017 #include "llvm/ADT/StringRef.h"
00018 #include <string>
00019 #include <utility>
00020 #include <vector>
00021 
00022 namespace llvm {
00023   class raw_ostream;
00024 
00025 /// StringMatcher - Given a list of strings and code to execute when they match,
00026 /// output a simple switch tree to classify the input string.
00027 ///
00028 /// If a match is found, the code in Vals[i].second is executed; control must
00029 /// not exit this code fragment.  If nothing matches, execution falls through.
00030 ///
00031 class StringMatcher {
00032 public:
00033   typedef std::pair<std::string, std::string> StringPair;
00034 
00035 private:
00036   StringRef StrVariableName;
00037   const std::vector<StringPair> &Matches;
00038   raw_ostream &OS;
00039 
00040 public:
00041   StringMatcher(StringRef strVariableName, 
00042                 const std::vector<StringPair> &matches, raw_ostream &os)
00043     : StrVariableName(strVariableName), Matches(matches), OS(os) {}
00044 
00045   void Emit(unsigned Indent = 0) const;
00046 
00047 private:
00048   bool EmitStringMatcherForChar(const std::vector<const StringPair*> &Matches,
00049                                 unsigned CharNo, unsigned IndentCount) const;
00050 };
00051 
00052 } // end llvm namespace.
00053 
00054 #endif