/// isObjCAtKeyword - Return true if we have an ObjC keyword identifier.
bool Token::isObjCAtKeyword(tok::ObjCKeywordKind objcKey) const {
- return getKind() == tok::identifier &&
- getIdentifierInfo()->getObjCKeywordID() == objcKey;
+ return is(tok::identifier) &&
+ getIdentifierInfo()->getObjCKeywordID() == objcKey;
}
/// getObjCKeywordID - Return the ObjC keyword kind.
ParsingFilename = false;
// No filename?
- if (FilenameTok.getKind() == tok::eom)
+ if (FilenameTok.is(tok::eom))
Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
}
// Next, lex the character, which should handle the EOM transition.
Lex(Tmp);
- assert(Tmp.getKind() == tok::eom && "Unexpected token!");
+ assert(Tmp.is(tok::eom) && "Unexpected token!");
// Finally, we're done, return the string we found.
return Result;
// Restore the lexer back to non-skipping mode.
LexingRawMode = false;
- if (Tok.getKind() == tok::eof)
+ if (Tok.is(tok::eof))
return 2;
- return Tok.getKind() == tok::l_paren;
+ return Tok.is(tok::l_paren);
}
// literal, the result is a wide-string literal [C99 6.4.5p4].
MaxTokenLength = StringToks[0].getLength();
SizeBound = StringToks[0].getLength()-2; // -2 for "".
- AnyWide = StringToks[0].getKind() == tok::wide_string_literal;
+ AnyWide = StringToks[0].is(tok::wide_string_literal);
hadError = false;
MaxTokenLength = StringToks[i].getLength();
// Remember if we see any wide strings.
- AnyWide |= StringToks[i].getKind() == tok::wide_string_literal;
+ AnyWide |= StringToks[i].is(tok::wide_string_literal);
}
/// argument.
unsigned MacroArgs::getArgLength(const Token *ArgPtr) {
unsigned NumArgTokens = 0;
- for (; ArgPtr->getKind() != tok::eof; ++ArgPtr)
+ for (; ArgPtr->isNot(tok::eof); ++ArgPtr)
++NumArgTokens;
return NumArgTokens;
}
// Scan to find Arg.
for (; Arg; ++Result) {
assert(Result < Start+NumUnexpArgTokens && "Invalid arg #");
- if (Result->getKind() == tok::eof)
+ if (Result->is(tok::eof))
--Arg;
}
return Result;
Preprocessor &PP) const {
// If there are no identifiers in the argument list, or if the identifiers are
// known to not be macros, pre-expansion won't modify it.
- for (; ArgTok->getKind() != tok::eof; ++ArgTok)
+ for (; ArgTok->isNot(tok::eof); ++ArgTok)
if (IdentifierInfo *II = ArgTok->getIdentifierInfo()) {
if (II->hasMacroDefinition() && PP.getMacroInfo(II)->isEnabled())
// Return true even though the macro could be a function-like macro
do {
Result.push_back(Token());
PP.Lex(Result.back());
- } while (Result.back().getKind() != tok::eof);
+ } while (Result.back().isNot(tok::eof));
// Pop the token stream off the top of the stack. We know that the internal
// pointer inside of it is to the "end" of the token stream, but the stack
std::string Result = "\"";
// FIXME: Optimize this loop to not use std::strings.
bool isFirst = true;
- for (; ArgToks->getKind() != tok::eof; ++ArgToks) {
+ for (; ArgToks->isNot(tok::eof); ++ArgToks) {
const Token &Tok = *ArgToks;
if (!isFirst && (Tok.hasLeadingSpace() || Tok.isAtStartOfLine()))
Result += ' ';
// If this is a string or character constant, escape the token as specified
// by 6.10.3.2p2.
- if (Tok.getKind() == tok::string_literal || // "foo"
- Tok.getKind() == tok::wide_string_literal || // L"foo"
- Tok.getKind() == tok::char_constant) { // 'x' and L'x'.
+ if (Tok.is(tok::string_literal) || // "foo"
+ Tok.is(tok::wide_string_literal) || // L"foo"
+ Tok.is(tok::char_constant)) { // 'x' and L'x'.
Result += Lexer::Stringify(PP.getSpelling(Tok));
} else {
// Otherwise, just append the token.
memset(&StringifiedArgs[0], 0,
sizeof(StringifiedArgs[0])*getNumArguments());
}
- if (StringifiedArgs[ArgNo].getKind() != tok::string_literal)
+ if (StringifiedArgs[ArgNo].isNot(tok::string_literal))
StringifiedArgs[ArgNo] = StringifyArgument(getUnexpArgument(ArgNo), PP);
return StringifiedArgs[ArgNo];
}
// preprocessor already verified that the following token is a macro name
// when the #define was parsed.
const Token &CurTok = MacroTokens[i];
- if (CurTok.getKind() == tok::hash || CurTok.getKind() == tok::hashat) {
+ if (CurTok.is(tok::hash) || CurTok.is(tok::hashat)) {
int ArgNo = Macro->getArgumentNum(MacroTokens[i+1].getIdentifierInfo());
assert(ArgNo != -1 && "Token following # is not an argument?");
Token Res;
- if (CurTok.getKind() == tok::hash) // Stringify
+ if (CurTok.is(tok::hash)) // Stringify
Res = ActualArgs->getStringifiedArgument(ArgNo, PP);
else {
// 'charify': don't bother caching these.
// Otherwise, this is a use of the argument. Find out if there is a paste
// (##) operator before or after the argument.
bool PasteBefore =
- !ResultToks.empty() && ResultToks.back().getKind() == tok::hashhash;
- bool PasteAfter = i+1 != e && MacroTokens[i+1].getKind() == tok::hashhash;
+ !ResultToks.empty() && ResultToks.back().is(tok::hashhash);
+ bool PasteAfter = i+1 != e && MacroTokens[i+1].is(tok::hashhash);
// If it is not the LHS/RHS of a ## operator, we must pre-expand the
// argument and substitute the expanded tokens into the result. This is
ResultArgToks = ArgTok; // Use non-preexpanded tokens.
// If the arg token expanded into anything, append it.
- if (ResultArgToks->getKind() != tok::eof) {
+ if (ResultArgToks->isNot(tok::eof)) {
unsigned FirstResult = ResultToks.size();
unsigned NumToks = MacroArgs::getArgLength(ResultArgToks);
ResultToks.append(ResultArgToks, ResultArgToks+NumToks);
// If this is on the RHS of a paste operator, we've already copied the
// paste operator to the ResultToks list. Remove it.
- assert(PasteBefore && ResultToks.back().getKind() == tok::hashhash);
+ assert(PasteBefore && ResultToks.back().is(tok::hashhash));
NextTokGetsSpace |= ResultToks.back().hasLeadingSpace();
ResultToks.pop_back();
// the ## was a comma, remove the comma.
if ((unsigned)ArgNo == Macro->getNumArgs()-1 && // is __VA_ARGS__
ActualArgs->isVarargsElidedUse() && // Argument elided.
- !ResultToks.empty() && ResultToks.back().getKind() == tok::comma) {
+ !ResultToks.empty() && ResultToks.back().is(tok::comma)) {
// Never add a space, even if the comma, ##, or arg had a space.
NextTokGetsSpace = false;
ResultToks.pop_back();
Tok = MacroTokens[CurToken++];
// If this token is followed by a token paste (##) operator, paste the tokens!
- if (!isAtEnd() && MacroTokens[CurToken].getKind() == tok::hashhash)
+ if (!isAtEnd() && MacroTokens[CurToken].is(tok::hashhash))
PasteTokens(Tok);
// The token's current location indicate where the token was lexed from. We
// Avoid testing /*, as the lexer would think it is the start of a comment
// and emit an error that it is unterminated.
- if (Tok.getKind() == tok::slash && RHS.getKind() == tok::star) {
+ if (Tok.is(tok::slash) && RHS.is(tok::star)) {
isInvalid = true;
- } else if (Tok.getKind() == tok::identifier &&
- RHS.getKind() == tok::identifier) {
+ } else if (Tok.is(tok::identifier) && RHS.is(tok::identifier)) {
// Common paste case: identifier+identifier = identifier. Avoid creating
// a lexer and other overhead.
PP.IncrementPasteCounter(true);
// If we got an EOF token, we didn't form even ONE token. For example, we
// did "/ ## /" to get "//".
- IsComplete &= Result.getKind() != tok::eof;
+ IsComplete &= Result.isNot(tok::eof);
isInvalid = !IsComplete;
// We're now done with the temporary lexer.
}
// Turn ## into 'other' to avoid # ## # from looking like a paste operator.
- if (Result.getKind() == tok::hashhash)
+ if (Result.is(tok::hashhash))
Result.setKind(tok::unknown);
// FIXME: Turn __VARRGS__ into "not a token"?
// Finally, replace LHS with the result, consume the RHS, and iterate.
++CurToken;
Tok = Result;
- } while (!isAtEnd() && MacroTokens[CurToken].getKind() == tok::hashhash);
+ } while (!isAtEnd() && MacroTokens[CurToken].is(tok::hashhash));
// Now that we got the result token, it will be subject to expansion. Since
// token pasting re-lexes the result token in raw mode, identifier information
// isn't looked up. As such, if the result is an identifier, look up id info.
- if (Tok.getKind() == tok::identifier) {
+ if (Tok.is(tok::identifier)) {
// Look up the identifier info for the token. We disabled identifier lookup
// by saying we're skipping contents, so we need to do this manually.
Tok.setIdentifierInfo(PP.LookUpIdentifierInfo(Tok));
// Out of tokens?
if (isAtEnd())
return 2;
- return MacroTokens[CurToken].getKind() == tok::l_paren;
+ return MacroTokens[CurToken].is(tok::l_paren);
}
// Two options, it can either be a pp-identifier or a (.
bool InParens = false;
- if (PeekTok.getKind() == tok::l_paren) {
+ if (PeekTok.is(tok::l_paren)) {
// Found a paren, remember we saw it and skip it.
InParens = true;
PP.LexUnexpandedToken(PeekTok);
// If we are in parens, ensure we have a trailing ).
if (InParens) {
- if (PeekTok.getKind() != tok::r_paren) {
+ if (PeekTok.isNot(tok::r_paren)) {
PP.Diag(PeekTok, diag::err_pp_missing_rparen);
return true;
}
// If this is a silly value like (X), which doesn't need parens, check for
// !(defined X).
- if (PeekTok.getKind() == tok::r_paren) {
+ if (PeekTok.is(tok::r_paren)) {
// Just use DT unmodified as our result.
} else {
if (EvaluateDirectiveSubExpr(Result, 1, PeekTok, ValueLive, PP))
return true;
- if (PeekTok.getKind() != tok::r_paren) {
+ if (PeekTok.isNot(tok::r_paren)) {
PP.Diag(PeekTok, diag::err_pp_expected_rparen);
return true;
}
break;
case tok::question: {
// Parse the : part of the expression.
- if (PeekTok.getKind() != tok::colon) {
+ if (PeekTok.isNot(tok::colon)) {
PP.Diag(OpToken, diag::err_pp_question_without_colon);
return true;
}
DefinedTracker DT;
if (EvaluateValue(ResVal, Tok, DT, true, *this)) {
// Parse error, skip the rest of the macro line.
- if (Tok.getKind() != tok::eom)
+ if (Tok.isNot(tok::eom))
DiscardUntilEndOfDirective();
return false;
}
// If we are at the end of the expression after just parsing a value, there
// must be no (unparenthesized) binary operators involved, so we can exit
// directly.
- if (Tok.getKind() == tok::eom) {
+ if (Tok.is(tok::eom)) {
// If the expression we parsed was of the form !defined(macro), return the
// macro in IfNDefMacro.
if (DT.State == DefinedTracker::NotDefinedMacro)
// operator and the stuff after it.
if (EvaluateDirectiveSubExpr(ResVal, 1, Tok, true, *this)) {
// Parse error, skip the rest of the macro line.
- if (Tok.getKind() != tok::eom)
+ if (Tok.isNot(tok::eom))
DiscardUntilEndOfDirective();
return false;
}
// If we aren't at the tok::eom token, something bad happened, like an extra
// ')' token.
- if (Tok.getKind() != tok::eom) {
+ if (Tok.isNot(tok::eom)) {
Diag(Tok, diag::err_pp_expected_eol);
DiscardUntilEndOfDirective();
}
// Read the '('.
Lex(Tok);
- if (Tok.getKind() != tok::l_paren)
+ if (Tok.isNot(tok::l_paren))
return Diag(PragmaLoc, diag::err__Pragma_malformed);
// Read the '"..."'.
Lex(Tok);
- if (Tok.getKind() != tok::string_literal &&
- Tok.getKind() != tok::wide_string_literal)
+ if (Tok.isNot(tok::string_literal) && Tok.isNot(tok::wide_string_literal))
return Diag(PragmaLoc, diag::err__Pragma_malformed);
// Remember the string.
// Read the ')'.
Lex(Tok);
- if (Tok.getKind() != tok::r_paren)
+ if (Tok.isNot(tok::r_paren))
return Diag(PragmaLoc, diag::err__Pragma_malformed);
// The _Pragma is lexically sound. Destringize according to C99 6.10.9.1.
if (CurLexer) CurLexer->LexingRawMode = false;
// If we reached the end of line, we're done.
- if (Tok.getKind() == tok::eom) return;
+ if (Tok.is(tok::eom)) return;
// Can only poison identifiers.
- if (Tok.getKind() != tok::identifier) {
+ if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_pp_invalid_poison);
return;
}
CurLexer->LexIncludeFilename(FilenameTok);
// If the token kind is EOM, the error has already been diagnosed.
- if (FilenameTok.getKind() == tok::eom)
+ if (FilenameTok.is(tok::eom))
return;
// Reserve a buffer to get the spelling.
// Lex tokens at the end of the message and include them in the message.
std::string Message;
Lex(DependencyTok);
- while (DependencyTok.getKind() != tok::eom) {
+ while (DependencyTok.isNot(tok::eom)) {
Message += getSpelling(DependencyTok) + " ";
Lex(DependencyTok);
}
Token Tok;
LexUnexpandedToken(Tok);
- assert(Tok.getKind() == tok::l_paren && "Error computing l-paren-ness?");
+ assert(Tok.is(tok::l_paren) && "Error computing l-paren-ness?");
return true;
}
llvm::SmallVector<Token, 64> ArgTokens;
unsigned NumActuals = 0;
- while (Tok.getKind() == tok::comma) {
+ while (Tok.is(tok::comma)) {
// C99 6.10.3p11: Keep track of the number of l_parens we have seen. Note
// that we already consumed the first one.
unsigned NumParens = 0;
// an argument value in a macro could expand to ',' or '(' or ')'.
LexUnexpandedToken(Tok);
- if (Tok.getKind() == tok::eof) {
+ if (Tok.is(tok::eof)) {
Diag(MacroName, diag::err_unterm_macro_invoc);
// Do not lose the EOF. Return it to the client.
MacroName = Tok;
return 0;
- } else if (Tok.getKind() == tok::r_paren) {
+ } else if (Tok.is(tok::r_paren)) {
// If we found the ) token, the macro arg list is done.
if (NumParens-- == 0)
break;
- } else if (Tok.getKind() == tok::l_paren) {
+ } else if (Tok.is(tok::l_paren)) {
++NumParens;
- } else if (Tok.getKind() == tok::comma && NumParens == 0) {
+ } else if (Tok.is(tok::comma) && NumParens == 0) {
// Comma ends this argument if there are more fixed arguments expected.
if (NumFixedArgsLeft)
break;
return 0;
}
// Otherwise, continue to add the tokens to this variable argument.
- } else if (Tok.getKind() == tok::comment && !KeepMacroComments) {
+ } else if (Tok.is(tok::comment) && !KeepMacroComments) {
// If this is a comment token in the argument list and we're just in
// -C mode (not -CC mode), discard the comment.
continue;
/// identifier information for the token and install it into the token.
IdentifierInfo *Preprocessor::LookUpIdentifierInfo(Token &Identifier,
const char *BufPtr) {
- assert(Identifier.getKind() == tok::identifier && "Not an identifier!");
+ assert(Identifier.is(tok::identifier) && "Not an identifier!");
assert(Identifier.getIdentifierInfo() == 0 && "Identinfo already exists!");
// Look up this token, see if it is a macro, or if it is a language keyword.
Token Tmp;
do {
LexUnexpandedToken(Tmp);
- } while (Tmp.getKind() != tok::eom);
+ } while (Tmp.isNot(tok::eom));
}
/// isCXXNamedOperator - Returns "true" if the token is a named operator in C++.
LexUnexpandedToken(MacroNameTok);
// Missing macro name?
- if (MacroNameTok.getKind() == tok::eom)
+ if (MacroNameTok.is(tok::eom))
return Diag(MacroNameTok, diag::err_pp_missing_macro_name);
IdentifierInfo *II = MacroNameTok.getIdentifierInfo();
Lex(Tmp);
// There should be no tokens after the directive, but we allow them as an
// extension.
- while (Tmp.getKind() == tok::comment) // Skip comments in -C mode.
+ while (Tmp.is(tok::comment)) // Skip comments in -C mode.
Lex(Tmp);
- if (Tmp.getKind() != tok::eom) {
+ if (Tmp.isNot(tok::eom)) {
Diag(Tmp, diag::ext_pp_extra_tokens_at_eol, DirType);
DiscardUntilEndOfDirective();
}
CurLexer->Lex(Tok);
// If this is the end of the buffer, we have an error.
- if (Tok.getKind() == tok::eof) {
+ if (Tok.is(tok::eof)) {
// Emit errors for each unterminated conditional on the stack, including
// the current one.
while (!CurLexer->ConditionalStack.empty()) {
}
// If this token is not a preprocessor directive, just skip it.
- if (Tok.getKind() != tok::hash || !Tok.isAtStartOfLine())
+ if (Tok.isNot(tok::hash) || !Tok.isAtStartOfLine())
continue;
// We just parsed a # character at the start of a line, so we're in
// If this isn't an identifier directive (e.g. is "# 1\n" or "#\n", or
// something bogus), skip it.
- if (Tok.getKind() != tok::identifier) {
+ if (Tok.isNot(tok::identifier)) {
CurLexer->ParsingPreprocessorDirective = false;
// Restore comment saving mode.
CurLexer->KeepCommentMode = KeepComments;
Lex(StrTok);
// If the token kind isn't a string, it's a malformed directive.
- if (StrTok.getKind() != tok::string_literal &&
- StrTok.getKind() != tok::wide_string_literal)
+ if (StrTok.isNot(tok::string_literal) &&
+ StrTok.isNot(tok::wide_string_literal))
return Diag(StrTok, diag::err_pp_malformed_ident);
// Verify that there is nothing after the string, other than EOM.
Token CurTok;
PP.Lex(CurTok);
- while (CurTok.getKind() != tok::eom) {
+ while (CurTok.isNot(tok::eom)) {
// Append the spelling of this token to the buffer. If there was a space
// before it, add it now.
if (CurTok.hasLeadingSpace())
FilenameBuffer.resize(PreAppendSize+ActualLen);
// If we found the '>' marker, return success.
- if (CurTok.getKind() == tok::greater)
+ if (CurTok.is(tok::greater))
return false;
PP.Lex(CurTok);
// Lex the token after the identifier.
LexUnexpandedToken(Tok);
- if (Tok.getKind() != tok::r_paren) {
+ if (Tok.isNot(tok::r_paren)) {
Diag(Tok, diag::err_pp_missing_rparen_in_macro_def);
return true;
}
// Lex the token after the identifier.
LexUnexpandedToken(Tok);
- if (Tok.getKind() != tok::r_paren) {
+ if (Tok.isNot(tok::r_paren)) {
Diag(Tok, diag::err_pp_missing_rparen_in_macro_def);
return true;
}
ReadMacroName(MacroNameTok, 1);
// Error reading macro name? If so, diagnostic already issued.
- if (MacroNameTok.getKind() == tok::eom)
+ if (MacroNameTok.is(tok::eom))
return;
// If we are supposed to keep comments in #defines, reenable comment saving
// If this is a function-like macro definition, parse the argument list,
// marking each of the identifiers as being used as macro arguments. Also,
// check other constraints on the first token of the macro body.
- if (Tok.getKind() == tok::eom) {
+ if (Tok.is(tok::eom)) {
// If there is no body to this macro, we have no special handling here.
- } else if (Tok.getKind() == tok::l_paren && !Tok.hasLeadingSpace()) {
+ } else if (Tok.is(tok::l_paren) && !Tok.hasLeadingSpace()) {
// This is a function-like macro definition. Read the argument list.
MI->setIsFunctionLike();
if (ReadMacroDefinitionArgList(MI)) {
// Read the rest of the macro body.
if (MI->isObjectLike()) {
// Object-like macros are very simple, just read their body.
- while (Tok.getKind() != tok::eom) {
+ while (Tok.isNot(tok::eom)) {
MI->AddTokenToBody(Tok);
// Get the next token of the macro.
LexUnexpandedToken(Tok);
} else {
// Otherwise, read the body of a function-like macro. This has to validate
// the # (stringize) operator.
- while (Tok.getKind() != tok::eom) {
+ while (Tok.isNot(tok::eom)) {
MI->AddTokenToBody(Tok);
// Check C99 6.10.3.2p1: ensure that # operators are followed by macro
// parameters in function-like macro expansions.
- if (Tok.getKind() != tok::hash) {
+ if (Tok.isNot(tok::hash)) {
// Get the next token of the macro.
LexUnexpandedToken(Tok);
continue;
// replacement list.
unsigned NumTokens = MI->getNumTokens();
if (NumTokens != 0) {
- if (MI->getReplacementToken(0).getKind() == tok::hashhash) {
+ if (MI->getReplacementToken(0).is(tok::hashhash)) {
Diag(MI->getReplacementToken(0), diag::err_paste_at_start);
delete MI;
return;
}
- if (MI->getReplacementToken(NumTokens-1).getKind() == tok::hashhash) {
+ if (MI->getReplacementToken(NumTokens-1).is(tok::hashhash)) {
Diag(MI->getReplacementToken(NumTokens-1), diag::err_paste_at_end);
delete MI;
return;
ReadMacroName(MacroNameTok, 1);
// Error reading macro name? If so, diagnostic already issued.
- if (MacroNameTok.getKind() == tok::eom)
+ if (MacroNameTok.is(tok::eom))
return;
// Check to see if this is the last token on the #undef line.
ReadMacroName(MacroNameTok, 2);
// Error reading macro name? If so, diagnostic already issued.
- if (MacroNameTok.getKind() == tok::eom)
+ if (MacroNameTok.is(tok::eom))
return;
// Check to see if this is the last token on the #undef line.
ReadMacroName(MacroNameTok);
// Error reading macro name? If so, diagnostic already issued.
- if (MacroNameTok.getKind() == tok::eom) {
+ if (MacroNameTok.is(tok::eom)) {
// Skip code until we get to #endif. This helps with recovery by not
// emitting an error when the #endif is reached.
SkipExcludedConditionalBlock(DirectiveTok.getLocation(),