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 "
42 assert(Ident__VA_OPT__->
isPoisoned() &&
"__VA_OPT__ should be poisoned!");
75 : Ident__VA_OPT__(PP.Ident__VA_OPT__) {}
78 return Ident__VA_OPT__ &&
T.getIdentifierInfo() == Ident__VA_OPT__;
83 bool isInVAOpt()
const {
return UnmatchedOpeningParens.size(); }
87 assert(!
isInVAOpt() &&
"Must NOT be within VAOPT context to call this");
88 UnmatchedOpeningParens.push_back(LParenLoc);
93 assert(
isInVAOpt() &&
"Must be within VAOPT context to call this");
94 return UnmatchedOpeningParens.back();
101 assert(
isInVAOpt() &&
"Must be within VAOPT context to call this");
102 UnmatchedOpeningParens.pop_back();
103 return !UnmatchedOpeningParens.size();
108 assert(
isInVAOpt() &&
"Must be within VAOPT context to call this");
109 UnmatchedOpeningParens.push_back(LParenLoc);
113 bool isAtTopLevel()
const {
return UnmatchedOpeningParens.size() == 1; }
120 Token SyntheticEOFToken;
130 int NumOfTokensPriorToVAOpt = -1;
132 LLVM_PREFERRED_TYPE(
bool)
133 unsigned LeadingSpaceForStringifiedToken : 1;
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;
144 bool hasStringifyBefore()
const {
146 "Must only be called if the state has not been reset");
147 return StringifyBefore;
150 bool isReset()
const {
151 return NumOfTokensPriorToVAOpt == -1 ||
159 BeginsWithPlaceholder(
false), EndsWithPlaceholder(
false) {
161 SyntheticEOFToken.
setKind(tok::eof);
166 NumOfTokensPriorToVAOpt = -1;
167 LeadingSpaceForStringifiedToken =
false;
168 StringifyBefore =
false;
169 CharifyBefore =
false;
170 BeginsWithPlaceholder =
false;
171 EndsWithPlaceholder =
false;
177 const bool IsHashAt) {
179 StringifyBefore = !IsHashAt;
180 CharifyBefore = IsHashAt;
181 LeadingSpaceForStringifiedToken = HasLeadingSpace;
187 EndsWithPlaceholder =
true;
193 "Must only be called if the state has not been reset");
194 return BeginsWithPlaceholder;
198 "Must only be called if the state has not been reset");
199 return EndsWithPlaceholder;
204 "Must only be called if the state has not been reset");
205 return CharifyBefore;
213 "Must only be called if the state has not been reset");
214 return NumOfTokensPriorToVAOpt;
218 assert(hasStringifyBefore() &&
219 "Must only be called if this has been marked for stringification");
220 return LeadingSpaceForStringifiedToken;
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");
236 "Must only be called if the state has not been reset");
237 assert(VAOptLoc.
isValid() &&
"__VA_OPT__ location must be valid");
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