-
Notifications
You must be signed in to change notification settings - Fork 4
/
NacroRule.cpp
35 lines (28 loc) · 1006 Bytes
/
NacroRule.cpp
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
#include "llvm/ADT/StringSwitch.h"
#include "clang/Basic/IdentifierTable.h"
#include "NacroRule.h"
#include <memory>
#include <vector>
using namespace clang;
using llvm::StringRef;
using llvm::ArrayRef;
static std::vector<std::unique_ptr<NacroRule>> NacroRulesOwner;
NacroRule* NacroRule::Create(IdentifierInfo* NameII) {
NacroRulesOwner.emplace_back(new NacroRule(NameII));
return NacroRulesOwner.back().get();
}
NacroRule::ReplacementTy NacroRule::GetReplacementTy(StringRef RawType) {
return llvm::StringSwitch<ReplacementTy>(RawType)
.Case("$expr", ReplacementTy::Expr)
.Case("$stmt", ReplacementTy::Stmt)
.Case("$block", ReplacementTy::Block)
.Default(ReplacementTy::UNKNOWN);
}
void NacroRule::AddReplacement(IdentifierInfo* II, ReplacementTy Ty,
bool VarArgs) {
Replacements.push_back({II, Ty, VarArgs});
}
bool NacroRule::needsPPHooks() const {
// For now only loops need PPCallbacks
return !loop_empty();
}