-
Notifications
You must be signed in to change notification settings - Fork 4
/
NacroParsers.h
65 lines (47 loc) · 1.23 KB
/
NacroParsers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef NACRO_NACRO_PARSERS_H
#define NACRO_NACRO_PARSERS_H
#include "clang/Basic/TokenKinds.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include "NacroRule.h"
#include <memory>
namespace clang {
class NacroParser {
protected:
/// #pragma nacro <category> [pragma params...]
llvm::ArrayRef<Token> PragmaParams;
Preprocessor& PP;
bool HasEncounteredError;
NacroParser(Preprocessor& PP, llvm::ArrayRef<Token> PragmaParams)
: PragmaParams(PragmaParams),
PP(PP),
HasEncounteredError(false) {}
public:
/// False if there is an error
virtual operator bool() const {
return !HasEncounteredError;
}
virtual bool Parse() = 0;
};
class NacroRuleParser : public NacroParser {
NacroRule* CurrentRule;
Token CurTok;
void WrapNacroBody();
public:
NacroRuleParser(Preprocessor& PP, llvm::ArrayRef<Token> Params);
inline
NacroRule* getNacroRule() { return CurrentRule; }
inline void Advance() {
PP.Lex(CurTok);
}
bool ParseArgList();
bool ParseStmts();
bool ParseStr();
llvm::Optional<NacroRule::Loop> ParseLoopHeader();
bool ParseLoop();
bool Parse() override;
};
} // end namespace clang
#endif