16 #ifndef LLVM_CLANG_LEX_VARIADICMACROSUPPORT_H 17 #define LLVM_CLANG_LEX_VARIADICMACROSUPPORT_H 20 #include "llvm/ADT/SmallVector.h" 38 : PP(P), Ident__VA_ARGS__(PP.Ident__VA_ARGS__),
39 Ident__VA_OPT__(PP.Ident__VA_OPT__) {
40 assert(Ident__VA_ARGS__->
isPoisoned() &&
"__VA_ARGS__ should be poisoned " 41 "outside an ISO C/C++ variadic " 45 (Ident__VA_OPT__->
isPoisoned() &&
"__VA_OPT__ should be poisoned!"));
80 : Ident__VA_OPT__(PP.Ident__VA_OPT__) {}
88 bool isInVAOpt()
const {
return UnmatchedOpeningParens.size(); }
92 assert(!isInVAOpt() &&
"Must NOT be within VAOPT context to call this");
93 UnmatchedOpeningParens.push_back(LParenLoc);
98 assert(isInVAOpt() &&
"Must be within VAOPT context to call this");
99 return UnmatchedOpeningParens.back();
106 assert(isInVAOpt() &&
"Must be within VAOPT context to call this");
107 UnmatchedOpeningParens.pop_back();
108 return !UnmatchedOpeningParens.size();
113 assert(isInVAOpt() &&
"Must be within VAOPT context to call this");
114 UnmatchedOpeningParens.push_back(LParenLoc);
123 Token SyntheticEOFToken;
133 int NumOfTokensPriorToVAOpt = -1;
135 unsigned LeadingSpaceForStringifiedToken : 1;
137 unsigned StringifyBefore : 1;
138 unsigned CharifyBefore : 1;
141 bool hasStringifyBefore()
const {
143 "Must only be called if the state has not been reset");
144 return StringifyBefore;
147 bool isReset()
const {
148 return NumOfTokensPriorToVAOpt == -1 ||
155 StringifyBefore(
false), CharifyBefore(
false) {
162 NumOfTokensPriorToVAOpt = -1;
163 LeadingSpaceForStringifiedToken =
false;
164 StringifyBefore =
false;
165 CharifyBefore =
false;
171 const bool IsHashAt) {
173 StringifyBefore = !IsHashAt;
174 CharifyBefore = IsHashAt;
175 LeadingSpaceForStringifiedToken = HasLeadingSpace;
182 "Must only be called if the state has not been reset");
183 return CharifyBefore;
186 return hasStringifyBefore() || hasCharifyBefore();
191 "Must only be called if the state has not been reset");
192 return NumOfTokensPriorToVAOpt;
196 assert(hasStringifyBefore() &&
197 "Must only be called if this has been marked for stringification");
198 return LeadingSpaceForStringifiedToken;
202 const unsigned int NumPriorTokens) {
203 assert(VAOptLoc.
isFileID() &&
"Must not come from a macro expansion");
204 assert(isReset() &&
"Must only be called if the state has been reset");
206 this->VAOptLoc = VAOptLoc;
207 NumOfTokensPriorToVAOpt = NumPriorTokens;
208 assert(NumOfTokensPriorToVAOpt > -1 &&
209 "Too many prior tokens");
214 "Must only be called if the state has not been reset");
215 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()
const FunctionProtoType * T
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.
IdentifierInfo * getIdentifierInfo() const
bool isInVAOpt() const
Returns true if we have seen the VA_OPT and '(' but before having seen the matching ')'...
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 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.