15 #ifndef LLVM_CLANG_LEX_VARIADICMACROSUPPORT_H 16 #define LLVM_CLANG_LEX_VARIADICMACROSUPPORT_H 19 #include "llvm/ADT/SmallVector.h" 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 " 44 (Ident__VA_OPT__->
isPoisoned() &&
"__VA_OPT__ should be poisoned!"));
79 : Ident__VA_OPT__(PP.Ident__VA_OPT__) {}
87 bool isInVAOpt()
const {
return UnmatchedOpeningParens.size(); }
91 assert(!isInVAOpt() &&
"Must NOT be within VAOPT context to call this");
92 UnmatchedOpeningParens.push_back(LParenLoc);
97 assert(isInVAOpt() &&
"Must be within VAOPT context to call this");
98 return UnmatchedOpeningParens.back();
105 assert(isInVAOpt() &&
"Must be within VAOPT context to call this");
106 UnmatchedOpeningParens.pop_back();
107 return !UnmatchedOpeningParens.size();
112 assert(isInVAOpt() &&
"Must be within VAOPT context to call this");
113 UnmatchedOpeningParens.push_back(LParenLoc);
117 bool isAtTopLevel()
const {
return UnmatchedOpeningParens.size() == 1; }
124 Token SyntheticEOFToken;
134 int NumOfTokensPriorToVAOpt = -1;
136 unsigned LeadingSpaceForStringifiedToken : 1;
138 unsigned StringifyBefore : 1;
139 unsigned CharifyBefore : 1;
140 unsigned BeginsWithPlaceholder : 1;
141 unsigned EndsWithPlaceholder : 1;
143 bool hasStringifyBefore()
const {
145 "Must only be called if the state has not been reset");
146 return StringifyBefore;
149 bool isReset()
const {
150 return NumOfTokensPriorToVAOpt == -1 ||
158 BeginsWithPlaceholder(
false), EndsWithPlaceholder(
false) {
165 NumOfTokensPriorToVAOpt = -1;
166 LeadingSpaceForStringifiedToken =
false;
167 StringifyBefore =
false;
168 CharifyBefore =
false;
169 BeginsWithPlaceholder =
false;
170 EndsWithPlaceholder =
false;
176 const bool IsHashAt) {
178 StringifyBefore = !IsHashAt;
179 CharifyBefore = IsHashAt;
180 LeadingSpaceForStringifiedToken = HasLeadingSpace;
186 EndsWithPlaceholder =
true;
192 "Must only be called if the state has not been reset");
193 return BeginsWithPlaceholder;
197 "Must only be called if the state has not been reset");
198 return EndsWithPlaceholder;
203 "Must only be called if the state has not been reset");
204 return CharifyBefore;
207 return hasStringifyBefore() || hasCharifyBefore();
212 "Must only be called if the state has not been reset");
213 return NumOfTokensPriorToVAOpt;
217 assert(hasStringifyBefore() &&
218 "Must only be called if this has been marked for stringification");
219 return LeadingSpaceForStringifiedToken;
223 const unsigned int NumPriorTokens) {
224 assert(VAOptLoc.
isFileID() &&
"Must not come from a macro expansion");
225 assert(isReset() &&
"Must only be called if the state has been reset");
227 this->VAOptLoc = VAOptLoc;
228 NumOfTokensPriorToVAOpt = NumPriorTokens;
229 assert(NumOfTokensPriorToVAOpt > -1 &&
230 "Too many prior tokens");
235 "Must only be called if the state has not been reset");
236 assert(VAOptLoc.
isValid() &&
"__VA_OPT__ location must be valid");
void sawOpeningParen(SourceLocation LParenLoc)
Call this function each time an lparen is seen.
bool sawClosingParen()
Call this function each time an rparen is seen.
A class for tracking whether we're inside a VA_OPT during a traversal of the tokens of a macro during...
bool hasCharifyBefore() const
bool getLeadingSpaceForStringifiedToken() const
bool hasStringifyOrCharifyBefore() const
One of these records is kept for each identifier that is lexed.
const Token & getEOFTok() const
void sawVAOptFollowedByOpeningParens(const SourceLocation VAOptLoc, const unsigned int NumPriorTokens)
Token - This structure provides full information about a lexed token.
void setKind(tok::TokenKind K)
void exitScope()
Client code should call this function as soon as the Preprocessor has either completed lexing the mac...
VAOptDefinitionContext(Preprocessor &PP)
~VariadicMacroScopeGuard()
SourceLocation getVAOptLoc() const
A class for tracking whether we're inside a VA_OPT during a traversal of the tokens of a variadic mac...
Defines the clang::Preprocessor interface.
void setIsPoisoned(bool Value=true)
setIsPoisoned - Mark this identifier as poisoned.
void enterScope()
Client code should call this function just before the Preprocessor is about to Lex tokens from the de...
SourceLocation getUnmatchedOpeningParenLoc() const
bool isVAOptToken(const Token &T) const
Encodes a location in the source.
bool beginsWithPlaceholder() const
IdentifierInfo * getIdentifierInfo() const
bool isInVAOpt() const
Returns true if we have seen the VA_OPT and '(' but before having seen the matching ')'...
void hasPlaceholderBeforeRParen()
bool isPoisoned() const
Return true if this token has been poisoned.
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
VariadicMacroScopeGuard(const Preprocessor &P)
void hasPlaceholderAfterHashhashAtStart()
bool isAtTopLevel() const
Are we at the top level within the VA_OPT?
bool endsWithPlaceholder() const
void sawHashOrHashAtBefore(const bool HasLeadingSpace, const bool IsHashAt)
unsigned int getNumberOfTokensPriorToVAOpt() const
void sawVAOptFollowedByOpeningParens(const SourceLocation LParenLoc)
Call this function as soon as you see VA_OPT and '('.
VAOptExpansionContext(Preprocessor &PP)
void startToken()
Reset all flags to cleared.
An RAII class that tracks when the Preprocessor starts and stops lexing the definition of a (ISO C/C+...
Engages in a tight little dance with the lexer to efficiently preprocess tokens.