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

22 class Preprocessor;

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

50 }

51

52

53

54

55

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 ||

153 }

154

155 public:

158 StringifyBefore(false), CharifyBefore(false),

159 BeginsWithPlaceholder(false), EndsWithPlaceholder(false) {

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 }

209 }

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.

void setIsPoisoned(bool Value=true)

setIsPoisoned - Mark this identifier as poisoned.

bool isPoisoned() const

Return true if this token has been poisoned.

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

Encodes a location in the source.

bool isValid() const

Return true if this is a valid SourceLocation object.

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

void setKind(tok::TokenKind K)

void startToken()

Reset all flags to cleared.

A class for tracking whether we're inside a VA_OPT during a traversal of the tokens of a variadic mac...

VAOptDefinitionContext(Preprocessor &PP)

SourceLocation getUnmatchedOpeningParenLoc() const

bool isInVAOpt() const

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

bool isVAOptToken(const Token &T) const

void sawOpeningParen(SourceLocation LParenLoc)

Call this function each time an lparen is seen.

bool isAtTopLevel() const

Are we at the top level within the VA_OPT?

bool sawClosingParen()

Call this function each time an rparen is seen.

void sawVAOptFollowedByOpeningParens(const SourceLocation LParenLoc)

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

A class for tracking whether we're inside a VA_OPT during a traversal of the tokens of a macro during...

VAOptExpansionContext(Preprocessor &PP)

void hasPlaceholderAfterHashhashAtStart()

void sawHashOrHashAtBefore(const bool HasLeadingSpace, const bool IsHashAt)

SourceLocation getVAOptLoc() const

unsigned int getNumberOfTokensPriorToVAOpt() const

bool getLeadingSpaceForStringifiedToken() const

bool hasStringifyOrCharifyBefore() const

bool hasCharifyBefore() const

void hasPlaceholderBeforeRParen()

const Token & getEOFTok() const

bool beginsWithPlaceholder() const

bool endsWithPlaceholder() const

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

An RAII class that tracks when the Preprocessor starts and stops lexing the definition of a (ISO C/C+...

void exitScope()

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

void enterScope()

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

~VariadicMacroScopeGuard()

VariadicMacroScopeGuard(const Preprocessor &P)

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

const FunctionProtoType * T