LLVM 22.0.0git
DirectiveNameParser.h
Go to the documentation of this file.
1//===- DirectiveNameParser.h ------------------------------------- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_FRONTEND_OPENMP_DIRECTIVENAMEPARSER_H
10#define LLVM_FRONTEND_OPENMP_DIRECTIVENAMEPARSER_H
11
13#include "llvm/ADT/StringMap.h"
14#include "llvm/ADT/StringRef.h"
17
18#include <memory>
19
20namespace llvm::omp {
21/// Parser class for OpenMP directive names. It only recognizes names listed
22/// in OMP.td, in particular it does not recognize Fortran's end-directives
23/// if they are not explicitly listed in OMP.td.
24///
25/// The class itself may be a singleton, once it's constructed it never
26/// changes.
27///
28/// Usage:
29/// {
30/// DirectiveNameParser Parser; // Could be static const.
31///
32/// DirectiveNameParser::State *S = Parser.initial();
33/// for (StringRef Token : Tokens)
34/// S = Parser.consume(S, Token); // Passing nullptr is ok.
35///
36/// if (S == nullptr) {
37/// // Error: ended up in a state from which there is no possible path
38/// // to a successful parse.
39/// } else if (S->Value == OMPD_unknown) {
40/// // Parsed a sequence of tokens that are not a complete name, but
41/// // parsing more tokens could lead to a successful parse.
42/// } else {
43/// // Success.
44/// ParsedId = S->Value;
45/// }
46/// }
48 LLVM_ABI DirectiveNameParser(SourceLanguage L = SourceLanguage::C);
49
50 struct State {
51 Directive Value = Directive::OMPD_unknown;
52
53 private:
55 std::unique_ptr<TransitionMapTy> Transition;
56
57 State *next(StringRef Tok);
58 const State *next(StringRef Tok) const;
59 bool isValid() const {
60 return Value != Directive::OMPD_unknown || !Transition->empty();
61 }
62 friend struct DirectiveNameParser;
63 };
64
65 const State *initial() const { return &InitialState; }
66 LLVM_ABI const State *consume(const State *Current, StringRef Tok) const;
67
69
70private:
71 void insertName(StringRef Name, Directive D);
72 State *insertTransition(State *From, StringRef Tok);
73
74 State InitialState;
75};
76} // namespace llvm::omp
77
78#endif // LLVM_FRONTEND_OPENMP_DIRECTIVENAMEPARSER_H
This file defines the StringMap class.
BlockVerifier::State From
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_ABI
Definition: Compiler.h:213
std::string Name
This file defines the SmallVector class.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
LLVM Value Representation.
Definition: Value.h:75
#define N
Parser class for OpenMP directive names.
static LLVM_ABI SmallVector< StringRef > tokenize(StringRef N)