本文整理汇总了C++中MacroInfo::getNumTokens方法的典型用法代码示例。如果您正苦于以下问题:C++ MacroInfo::getNumTokens方法的具体用法?C++ MacroInfo::getNumTokens怎么用?C++ MacroInfo::getNumTokens使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MacroInfo
的用法示例。
在下文中一共展示了MacroInfo::getNumTokens方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printMacros
void Preprocessor::printMacros(raw_ostream &OS) const {
for (macro_iterator I = macro_begin(), E = macro_end(); I != E; ++I) {
OS << "<MD: " << I->second << ">";
OS << I->first->getName() << " ";
OS << "(Tokens:)";
MacroInfo* MI = I->second->getMacroInfo();
for (unsigned i = 0, e = MI->getNumTokens(); i != e; ++i) {
const Token &Tok = MI->getReplacementToken(i);
OS << tok::getTokenName(Tok.getKind()) << " '"
<< getSpelling(Tok) << "'";
OS << "\t";
if (Tok.isAtStartOfLine())
OS << " [StartOfLine]";
if (Tok.hasLeadingSpace())
OS << " [LeadingSpace]";
if (Tok.isExpandDisabled())
OS << " [ExpandDisabled]";
if (Tok.needsCleaning()) {
const char *Start = SourceMgr.getCharacterData(Tok.getLocation());
OS << " [UnClean='" << StringRef(Start, Tok.getLength())
<< "']";
}
//Do not print location it uses the SourceManager dump to llvm::errs.
OS << "\tLoc=<";
Tok.getLocation().print(OS, SourceMgr);
OS << ">";
OS << " ";
}
OS << "\n";
}
}
示例2: DumpMacro
void Preprocessor::DumpMacro(const MacroInfo &MI) const {
llvm::errs() << "MACRO: ";
for (unsigned i = 0, e = MI.getNumTokens(); i != e; ++i) {
DumpToken(MI.getReplacementToken(i));
llvm::errs() << " ";
}
llvm::errs() << "\n";
}
示例3: HandleMacroExpandedIdentifier
/// HandleMacroExpandedIdentifier - If an identifier token is read that is to be
/// expanded as a macro, handle it and return the next token as 'Identifier'.
bool Preprocessor::HandleMacroExpandedIdentifier(Token &Identifier,
const MacroDefinition &M) {
MacroInfo *MI = M.getMacroInfo();
// If this is a macro expansion in the "#if !defined(x)" line for the file,
// then the macro could expand to different things in other contexts, we need
// to disable the optimization in this case.
if (CurPPLexer) CurPPLexer->MIOpt.ExpandedMacro();
// If this is a builtin macro, like __LINE__ or _Pragma, handle it specially.
if (MI->isBuiltinMacro()) {
ExpandBuiltinMacro(Identifier);
return true;
}
/// Args - If this is a function-like macro expansion, this contains,
/// for each macro argument, the list of tokens that were provided to the
/// invocation.
MacroArgs *Args = nullptr;
// Remember where the end of the expansion occurred. For an object-like
// macro, this is the identifier. For a function-like macro, this is the ')'.
SourceLocation ExpansionEnd = Identifier.getLocation();
// If this is a function-like macro, read the arguments.
if (MI->isFunctionLike()) {
// Remember that we are now parsing the arguments to a macro invocation.
// Preprocessor directives used inside macro arguments are not portable, and
// this enables the warning.
InMacroArgs = true;
Args = ReadMacroCallArgumentList(Identifier, MI, ExpansionEnd);
// Finished parsing args.
InMacroArgs = false;
// If there was an error parsing the arguments, bail out.
if (!Args) return true;
++NumFnMacroExpanded;
} else {
++NumMacroExpanded;
}
// Notice that this macro has been used.
markMacroAsUsed(MI);
// Remember where the token is expanded.
SourceLocation ExpandLoc = Identifier.getLocation();
SourceRange ExpansionRange(ExpandLoc, ExpansionEnd);
// If the macro definition is ambiguous, complain.
if (M.isAmbiguous()) {
Diag(Identifier, diag::warn_pp_ambiguous_macro)
<< Identifier.getIdentifierInfo();
Diag(MI->getDefinitionLoc(), diag::note_pp_ambiguous_macro_chosen)
<< Identifier.getIdentifierInfo();
M.forAllDefinitions([&](const MacroInfo *OtherMI) {
if (OtherMI != MI)
Diag(OtherMI->getDefinitionLoc(), diag::note_pp_ambiguous_macro_other)
<< Identifier.getIdentifierInfo();
});
}
// If we started lexing a macro, enter the macro expansion body.
// If this macro expands to no tokens, don't bother to push it onto the
// expansion stack, only to take it right back off.
if (MI->getNumTokens() == 0) {
// No need for arg info.
if (Args) Args->destroy(*this);
// Propagate whitespace info as if we had pushed, then popped,
// a macro context.
Identifier.setFlag(Token::LeadingEmptyMacro);
PropagateLineStartLeadingSpaceInfo(Identifier);
++NumFastMacroExpanded;
return false;
} else if (MI->getNumTokens() == 1 &&
isTrivialSingleTokenExpansion(MI, Identifier.getIdentifierInfo(),
*this)) {
// Otherwise, if this macro expands into a single trivially-expanded
// token: expand it now. This handles common cases like
// "#define VAL 42".
// No need for arg info.
if (Args) Args->destroy(*this);
// Propagate the isAtStartOfLine/hasLeadingSpace markers of the macro
// identifier to the expanded token.
bool isAtStartOfLine = Identifier.isAtStartOfLine();
bool hasLeadingSpace = Identifier.hasLeadingSpace();
// Replace the result token.
Identifier = MI->getReplacementToken(0);
// Restore the StartOfLine/LeadingSpace markers.
Identifier.setFlagValue(Token::StartOfLine , isAtStartOfLine);
//.........这里部分代码省略.........