clang: include/clang/Lex/VariadicMacroSupport.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15#ifndef LLVM_CLANG_LEX_VARIADICMACROSUPPORT_H

16#define LLVM_CLANG_LEX_VARIADICMACROSUPPORT_H

17

19#include "llvm/ADT/SmallVector.h"

20

23

24

25

26

27

28

29

34

35 public:

37 : PP(P), Ident__VA_ARGS__(PP.Ident__VA_ARGS__),

38 Ident__VA_OPT__(PP.Ident__VA_OPT__) {

39 assert(Ident__VA_ARGS__->isPoisoned() && "__VA_ARGS__ should be poisoned "

40 "outside an ISO C/C++ variadic "

41 "macro definition!");

42 assert(Ident__VA_OPT__->isPoisoned() && "__VA_OPT__ should be poisoned!");

43 }

44

45

46

48 Ident__VA_ARGS__->setIsPoisoned(false);

49 Ident__VA_OPT__->setIsPoisoned(false);

50 }

51

52

53

54

55

57 Ident__VA_ARGS__->setIsPoisoned(true);

58 Ident__VA_OPT__->setIsPoisoned(true);

59 }

60

62 };

63

64

65

67

69

71

72

73 public:

75 : Ident__VA_OPT__(PP.Ident__VA_OPT__) {}

76

78 return Ident__VA_OPT__ && T.getIdentifierInfo() == Ident__VA_OPT__;

79 }

80

81

82

83 bool isInVAOpt() const { return UnmatchedOpeningParens.size(); }

84

85

87 assert(isInVAOpt() && "Must NOT be within VAOPT context to call this");

88 UnmatchedOpeningParens.push_back(LParenLoc);

89

90 }

91

93 assert(isInVAOpt() && "Must be within VAOPT context to call this");

94 return UnmatchedOpeningParens.back();

95 }

96

97

98

99

101 assert(isInVAOpt() && "Must be within VAOPT context to call this");

102 UnmatchedOpeningParens.pop_back();

103 return !UnmatchedOpeningParens.size();

104 }

105

106

108 assert(isInVAOpt() && "Must be within VAOPT context to call this");

109 UnmatchedOpeningParens.push_back(LParenLoc);

110 }

111

112

113 bool isAtTopLevel() const { return UnmatchedOpeningParens.size() == 1; }

114 };

115

116

117

119

120 Token SyntheticEOFToken;

121

122

123

125

126

127

128

129

130 int NumOfTokensPriorToVAOpt = -1;

131

132 LLVM_PREFERRED_TYPE(bool)

133 unsigned LeadingSpaceForStringifiedToken : 1;

134

135 LLVM_PREFERRED_TYPE(bool)

136 unsigned StringifyBefore : 1;

137 LLVM_PREFERRED_TYPE(bool)

138 unsigned CharifyBefore : 1;

139 LLVM_PREFERRED_TYPE(bool)

140 unsigned BeginsWithPlaceholder : 1;

141 LLVM_PREFERRED_TYPE(bool)

142 unsigned EndsWithPlaceholder : 1;

143

144 bool hasStringifyBefore() const {

145 assert(!isReset() &&

146 "Must only be called if the state has not been reset");

147 return StringifyBefore;

148 }

149

150 bool isReset() const {

151 return NumOfTokensPriorToVAOpt == -1 ||

152 VAOptLoc.isInvalid();

153 }

154

155 public:

158 StringifyBefore(false), CharifyBefore(false),

159 BeginsWithPlaceholder(false), EndsWithPlaceholder(false) {

160 SyntheticEOFToken.startToken();

161 SyntheticEOFToken.setKind(tok::eof);

162 }

163

166 NumOfTokensPriorToVAOpt = -1;

167 LeadingSpaceForStringifiedToken = false;

168 StringifyBefore = false;

169 CharifyBefore = false;

170 BeginsWithPlaceholder = false;

171 EndsWithPlaceholder = false;

172 }

173

175

177 const bool IsHashAt) {

178

179 StringifyBefore = !IsHashAt;

180 CharifyBefore = IsHashAt;

181 LeadingSpaceForStringifiedToken = HasLeadingSpace;

182 }

183

187 EndsWithPlaceholder = true;

188 }

189

190

192 assert(!isReset() &&

193 "Must only be called if the state has not been reset");

194 return BeginsWithPlaceholder;

195 }

197 assert(!isReset() &&

198 "Must only be called if the state has not been reset");

199 return EndsWithPlaceholder;

200 }

201

203 assert(!isReset() &&

204 "Must only be called if the state has not been reset");

205 return CharifyBefore;

206 }

210

212 assert(!isReset() &&

213 "Must only be called if the state has not been reset");

214 return NumOfTokensPriorToVAOpt;

215 }

216

218 assert(hasStringifyBefore() &&

219 "Must only be called if this has been marked for stringification");

220 return LeadingSpaceForStringifiedToken;

221 }

222

224 const unsigned int NumPriorTokens) {

225 assert(VAOptLoc.isFileID() && "Must not come from a macro expansion");

226 assert(isReset() && "Must only be called if the state has been reset");

228 this->VAOptLoc = VAOptLoc;

229 NumOfTokensPriorToVAOpt = NumPriorTokens;

230 assert(NumOfTokensPriorToVAOpt > -1 &&

231 "Too many prior tokens");

232 }

233

235 assert(!isReset() &&

236 "Must only be called if the state has not been reset");

237 assert(VAOptLoc.isValid() && "__VA_OPT__ location must be valid");

238 return VAOptLoc;

239 }

244

245 };

246}

247

248#endif

Defines the clang::Preprocessor interface.

One of these records is kept for each identifier that is lexed.

Engages in a tight little dance with the lexer to efficiently preprocess tokens.

Encodes a location in the source.

Token - This structure provides full information about a lexed token.

VAOptDefinitionContext(Preprocessor &PP)

Definition VariadicMacroSupport.h:74

SourceLocation getUnmatchedOpeningParenLoc() const

Definition VariadicMacroSupport.h:92

bool isInVAOpt() const

Returns true if we have seen the VA_OPT and '(' but before having seen the matching ')'.

Definition VariadicMacroSupport.h:83

bool isVAOptToken(const Token &T) const

Definition VariadicMacroSupport.h:77

void sawOpeningParen(SourceLocation LParenLoc)

Call this function each time an lparen is seen.

Definition VariadicMacroSupport.h:107

bool isAtTopLevel() const

Are we at the top level within the VA_OPT?

Definition VariadicMacroSupport.h:113

bool sawClosingParen()

Call this function each time an rparen is seen.

Definition VariadicMacroSupport.h:100

void sawVAOptFollowedByOpeningParens(const SourceLocation LParenLoc)

Call this function as soon as you see VA_OPT and '('.

Definition VariadicMacroSupport.h:86

VAOptExpansionContext(Preprocessor &PP)

Definition VariadicMacroSupport.h:156

void hasPlaceholderAfterHashhashAtStart()

Definition VariadicMacroSupport.h:184

void sawHashOrHashAtBefore(const bool HasLeadingSpace, const bool IsHashAt)

Definition VariadicMacroSupport.h:176

SourceLocation getVAOptLoc() const

Definition VariadicMacroSupport.h:234

unsigned int getNumberOfTokensPriorToVAOpt() const

Definition VariadicMacroSupport.h:211

bool getLeadingSpaceForStringifiedToken() const

Definition VariadicMacroSupport.h:217

void reset()

Definition VariadicMacroSupport.h:164

bool hasStringifyOrCharifyBefore() const

Definition VariadicMacroSupport.h:207

bool hasCharifyBefore() const

Definition VariadicMacroSupport.h:202

void hasPlaceholderBeforeRParen()

Definition VariadicMacroSupport.h:185

const Token & getEOFTok() const

Definition VariadicMacroSupport.h:174

bool beginsWithPlaceholder() const

Definition VariadicMacroSupport.h:191

bool endsWithPlaceholder() const

Definition VariadicMacroSupport.h:196

void sawVAOptFollowedByOpeningParens(const SourceLocation VAOptLoc, const unsigned int NumPriorTokens)

Definition VariadicMacroSupport.h:223

void exitScope()

Client code should call this function as soon as the Preprocessor has either completed lexing the mac...

Definition VariadicMacroSupport.h:56

void enterScope()

Client code should call this function just before the Preprocessor is about to Lex tokens from the de...

Definition VariadicMacroSupport.h:47

~VariadicMacroScopeGuard()

Definition VariadicMacroSupport.h:61

VariadicMacroScopeGuard(const Preprocessor &P)

Definition VariadicMacroSupport.h:36

The JSON file list parser is used to communicate input to InstallAPI.

const FunctionProtoType * T