Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:36

0001 //===- StringMatcher.h - Generate a matcher for input strings ---*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file implements the StringMatcher class.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_TABLEGEN_STRINGMATCHER_H
0014 #define LLVM_TABLEGEN_STRINGMATCHER_H
0015 
0016 #include "llvm/ADT/StringRef.h"
0017 #include <string>
0018 #include <utility>
0019 #include <vector>
0020 
0021 namespace llvm {
0022 
0023 class raw_ostream;
0024 
0025 /// Given a list of strings and code to execute when they match, output a
0026 /// simple switch tree to classify the input string.
0027 ///
0028 /// If a match is found, the code in Matches[i].second is executed; control must
0029 /// not exit this code fragment.  If nothing matches, execution falls through.
0030 class StringMatcher {
0031 public:
0032   using StringPair = std::pair<std::string, std::string>;
0033 
0034 private:
0035   StringRef StrVariableName;
0036   const std::vector<StringPair> &Matches;
0037   raw_ostream &OS;
0038 
0039 public:
0040   StringMatcher(StringRef strVariableName,
0041                 const std::vector<StringPair> &matches, raw_ostream &os)
0042     : StrVariableName(strVariableName), Matches(matches), OS(os) {}
0043 
0044   void Emit(unsigned Indent = 0, bool IgnoreDuplicates = false) const;
0045 
0046 private:
0047   bool EmitStringMatcherForChar(const std::vector<const StringPair *> &Matches,
0048                                 unsigned CharNo, unsigned IndentCount,
0049                                 bool IgnoreDuplicates) const;
0050 };
0051 
0052 } // end namespace llvm
0053 
0054 #endif // LLVM_TABLEGEN_STRINGMATCHER_H