本文整理汇总了C++中MacroInfo类的典型用法代码示例。如果您正苦于以下问题:C++ MacroInfo类的具体用法?C++ MacroInfo怎么用?C++ MacroInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MacroInfo类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ParsePragmaPushOrPopMacro
/// \brief Handle \#pragma pop_macro.
///
/// The syntax is:
/// \code
/// #pragma pop_macro("macro")
/// \endcode
void Preprocessor::HandlePragmaPopMacro(Token &PopMacroTok) {
SourceLocation MessageLoc = PopMacroTok.getLocation();
// Parse the pragma directive and get the macro IdentifierInfo*.
IdentifierInfo *IdentInfo = ParsePragmaPushOrPopMacro(PopMacroTok);
if (!IdentInfo) return;
// Find the vector<MacroInfo*> associated with the macro.
llvm::DenseMap<IdentifierInfo*, std::vector<MacroInfo*> >::iterator iter =
PragmaPushMacroInfo.find(IdentInfo);
if (iter != PragmaPushMacroInfo.end()) {
// Release the MacroInfo currently associated with IdentInfo.
MacroInfo *CurrentMI = getMacroInfo(IdentInfo);
if (CurrentMI) {
if (CurrentMI->isWarnIfUnused())
WarnUnusedMacroLocs.erase(CurrentMI->getDefinitionLoc());
ReleaseMacroInfo(CurrentMI);
}
// Get the MacroInfo we want to reinstall.
MacroInfo *MacroToReInstall = iter->second.back();
// Reinstall the previously pushed macro.
setMacroInfo(IdentInfo, MacroToReInstall);
// Pop PragmaPushMacroInfo stack.
iter->second.pop_back();
if (iter->second.size() == 0)
PragmaPushMacroInfo.erase(iter);
} else {
Diag(MessageLoc, diag::warn_pragma_pop_macro_no_push)
<< IdentInfo->getName();
}
}
示例3: 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";
}
示例4:
/// RegisterBuiltinMacro - Register the specified identifier in the identifier
/// table and mark it as a builtin macro to be expanded.
static IdentifierInfo *RegisterBuiltinMacro(Preprocessor &PP, const char *Name){
// Get the identifier.
IdentifierInfo *Id = PP.getIdentifierInfo(Name);
// Mark it as being a macro that is builtin.
MacroInfo *MI = PP.AllocateMacroInfo(SourceLocation());
MI->setIsBuiltinMacro();
PP.setMacroInfo(Id, MI);
return Id;
}
示例5:
MacroWidgetCommon::MacroWidgetCommon(const MacroInfo& macroInfo, QWidget* parent/*=0*/)
:MacroWidgetParent(macroInfo.GetText(), parent)
, m_macroInfo(macroInfo)
{
auto parameterTypes = macroInfo.GetParameterTypes();
int i = 0;
for (auto type:parameterTypes)
{
AddParameter(type, i++);
}
}
示例6: RegisterBuiltinMacro
/// RegisterBuiltinMacro - Register the specified identifier in the identifier
/// table and mark it as a builtin macro to be expanded.
static IdentifierInfo*
RegisterBuiltinMacro(NasmPreproc& pp, const char* name)
{
// Get the identifier.
IdentifierInfo* id = pp.getIdentifierInfo(name);
#if 0
// Mark it as being a macro that is builtin.
MacroInfo* mi = pp.AllocateMacroInfo(SourceLocation());
mi->setIsBuiltinMacro();
pp.setMacroInfo(id, mi);
#endif
return id;
}
示例7: ParsePragmaPushOrPopMacro
/// \brief Handle \#pragma push_macro.
///
/// The syntax is:
/// \code
/// #pragma push_macro("macro")
/// \endcode
void Preprocessor::HandlePragmaPushMacro(Token &PushMacroTok) {
// Parse the pragma directive and get the macro IdentifierInfo*.
IdentifierInfo *IdentInfo = ParsePragmaPushOrPopMacro(PushMacroTok);
if (!IdentInfo) return;
// Get the MacroInfo associated with IdentInfo.
MacroInfo *MI = getMacroInfo(IdentInfo);
if (MI) {
// Allow the original MacroInfo to be redefined later.
MI->setIsAllowRedefinitionsWithoutWarning(true);
}
// Push the cloned MacroInfo so we can retrieve it later.
PragmaPushMacroInfo[IdentInfo].push_back(MI);
}
示例8: NamespaceUDT
DDR_RC
MacroTool::addMacrosToIR(Symbol_IR *ir)
{
DDR_RC rc = DDR_RC_OK;
/* Create a map of name to IR Type for all types in the IR which
* can contain macros. This is used to add macros to existing types.
*/
unordered_map<string, Type *> irMap;
for (vector<Type *>::iterator it = ir->_types.begin(); it != ir->_types.end(); it += 1) {
NamespaceUDT *ns = dynamic_cast<NamespaceUDT *>(*it);
if (NULL != ns) {
irMap[(*it)->_name] = *it;
}
}
for (vector<MacroInfo>::iterator it = macroList.begin(); it != macroList.end(); it += 1) {
/* For each found MacroInfo which contains macros, add the macros to the IR. */
MacroInfo *macroInfo = &*it;
if (macroInfo->getNumMacros() > 0) {
NamespaceUDT *ns = NULL;
/* If there is a type of the correct name already, use it. Otherwise,
* create a new namespace to contain the macros.
*/
if (irMap.find(macroInfo->getTypeName()) == irMap.end()) {
ns = new NamespaceUDT();
ns->_name = macroInfo->getTypeName();
ir->_types.push_back(ns);
irMap[macroInfo->getTypeName()] = ns;
} else {
ns = dynamic_cast<NamespaceUDT *>(irMap[macroInfo->getTypeName()]);
}
if (NULL == ns) {
ERRMSG("Cannot find or create UDT to add macro");
rc = DDR_RC_ERROR;
break;
} else {
for (set<pair<string, string> >::iterator it = macroInfo->getMacroStart(); it != macroInfo->getMacroEnd(); ++it) {
/* Check if the macro already exists before adding it. */
bool alreadyExists = false;
for (vector<Macro>::iterator it2 = ns->_macros.begin(); it2 != ns->_macros.end(); ++it2) {
if (it2->_name == it->first) {
alreadyExists = true;
break;
}
}
if (!alreadyExists) {
ns->_macros.push_back(Macro(it->first, it->second));
}
}
}
}
}
return rc;
}
示例9: isIdenticalTo
/// isIdenticalTo - Return true if the specified macro definition is equal to
/// this macro in spelling, arguments, and whitespace. This is used to emit
/// duplicate definition warnings. This implements the rules in C99 6.10.3.
///
bool MacroInfo::isIdenticalTo(const MacroInfo &Other, Preprocessor &PP) const {
// Check # tokens in replacement, number of args, and various flags all match.
if (ReplacementTokens.size() != Other.ReplacementTokens.size() ||
getNumArgs() != Other.getNumArgs() ||
isFunctionLike() != Other.isFunctionLike() ||
isC99Varargs() != Other.isC99Varargs() ||
isGNUVarargs() != Other.isGNUVarargs())
return false;
// Check arguments.
for (arg_iterator I = arg_begin(), OI = Other.arg_begin(), E = arg_end();
I != E; ++I, ++OI)
if (*I != *OI) return false;
// Check all the tokens.
for (unsigned i = 0, e = ReplacementTokens.size(); i != e; ++i) {
const Token &A = ReplacementTokens[i];
const Token &B = Other.ReplacementTokens[i];
if (A.getKind() != B.getKind())
return false;
// If this isn't the first first token, check that the whitespace and
// start-of-line characteristics match.
if (i != 0 &&
(A.isAtStartOfLine() != B.isAtStartOfLine() ||
A.hasLeadingSpace() != B.hasLeadingSpace()))
return false;
// If this is an identifier, it is easy.
if (A.getIdentifierInfo() || B.getIdentifierInfo()) {
if (A.getIdentifierInfo() != B.getIdentifierInfo())
return false;
continue;
}
// Otherwise, check the spelling.
if (PP.getSpelling(A) != PP.getSpelling(B))
return false;
}
return true;
}
示例10: isIdenticalTo
/// \brief Return true if the specified macro definition is equal to
/// this macro in spelling, arguments, and whitespace.
///
/// \param Syntactically if true, the macro definitions can be identical even
/// if they use different identifiers for the function macro parameters.
/// Otherwise the comparison is lexical and this implements the rules in
/// C99 6.10.3.
bool MacroInfo::isIdenticalTo(const MacroInfo &Other, Preprocessor &PP,
bool Syntactically) const {
bool Lexically = !Syntactically;
// Check # tokens in replacement, number of args, and various flags all match.
if (ReplacementTokens.size() != Other.ReplacementTokens.size() ||
getNumParams() != Other.getNumParams() ||
isFunctionLike() != Other.isFunctionLike() ||
isC99Varargs() != Other.isC99Varargs() ||
isGNUVarargs() != Other.isGNUVarargs())
return false;
if (Lexically) {
// Check arguments.
for (param_iterator I = param_begin(), OI = Other.param_begin(),
E = param_end();
I != E; ++I, ++OI)
if (*I != *OI) return false;
}
// Check all the tokens.
for (unsigned i = 0, e = ReplacementTokens.size(); i != e; ++i) {
const Token &A = ReplacementTokens[i];
const Token &B = Other.ReplacementTokens[i];
if (A.getKind() != B.getKind())
return false;
// If this isn't the first first token, check that the whitespace and
// start-of-line characteristics match.
if (i != 0 &&
(A.isAtStartOfLine() != B.isAtStartOfLine() ||
A.hasLeadingSpace() != B.hasLeadingSpace()))
return false;
// If this is an identifier, it is easy.
if (A.getIdentifierInfo() || B.getIdentifierInfo()) {
if (A.getIdentifierInfo() == B.getIdentifierInfo())
continue;
if (Lexically)
return false;
// With syntactic equivalence the parameter names can be different as long
// as they are used in the same place.
int AArgNum = getParameterNum(A.getIdentifierInfo());
if (AArgNum == -1)
return false;
if (AArgNum != Other.getParameterNum(B.getIdentifierInfo()))
return false;
continue;
}
// Otherwise, check the spelling.
if (PP.getSpelling(A) != PP.getSpelling(B))
return false;
}
return true;
}
示例11: ExpandBuiltinMacro
/// 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);
//.........这里部分代码省略.........