本文整理汇总了C++中SmallVectorImpl::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ SmallVectorImpl::insert方法的具体用法?C++ SmallVectorImpl::insert怎么用?C++ SmallVectorImpl::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SmallVectorImpl
的用法示例。
在下文中一共展示了SmallVectorImpl::insert方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: localUncachedLookup
void DeclContext::localUncachedLookup(DeclarationName Name,
SmallVectorImpl<NamedDecl *> &Results) {
Results.clear();
// If there's no external storage, just perform a normal lookup and copy
// the results.
if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
lookup_result LookupResults = lookup(Name);
Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
return;
}
// If we have a lookup table, check there first. Maybe we'll get lucky.
if (Name && !LookupPtr.getInt()) {
if (StoredDeclsMap *Map = LookupPtr.getPointer()) {
StoredDeclsMap::iterator Pos = Map->find(Name);
if (Pos != Map->end()) {
Results.insert(Results.end(),
Pos->second.getLookupResult().begin(),
Pos->second.getLookupResult().end());
return;
}
}
}
// Slow case: grovel through the declarations in our chain looking for
// matches.
for (Decl *D = FirstDecl; D; D = D->getNextDeclInContext()) {
if (NamedDecl *ND = dyn_cast<NamedDecl>(D))
if (ND->getDeclName() == Name)
Results.push_back(ND);
}
}
示例2: insertArgsFromProgramName
static void insertArgsFromProgramName(StringRef ProgName,
const DriverSuffix *DS,
SmallVectorImpl<const char *> &ArgVector,
std::set<std::string> &SavedStrings) {
if (!DS)
return;
if (const char *Flag = DS->ModeFlag) {
// Add Flag to the arguments.
auto it = ArgVector.begin();
if (it != ArgVector.end())
++it;
ArgVector.insert(it, Flag);
}
StringRef::size_type LastComponent = ProgName.rfind(
'-', ProgName.size() - strlen(DS->Suffix));
if (LastComponent == StringRef::npos)
return;
// Infer target from the prefix.
StringRef Prefix = ProgName.slice(0, LastComponent);
std::string IgnoredError;
if (llvm::TargetRegistry::lookupTarget(Prefix, IgnoredError)) {
auto it = ArgVector.begin();
if (it != ArgVector.end())
++it;
const char *arr[] = { "-target", GetStableCStr(SavedStrings, Prefix) };
ArgVector.insert(it, std::begin(arr), std::end(arr));
}
}
示例3: ParseProgName
static void ParseProgName(SmallVectorImpl<const char *> &ArgVector,
std::set<std::string> &SavedStrings) {
// Try to infer frontend type and default target from the program name by
// comparing it against DriverSuffixes in order.
// If there is a match, the function tries to identify a target as prefix.
// E.g. "x86_64-linux-clang" as interpreted as suffix "clang" with target
// prefix "x86_64-linux". If such a target prefix is found, is gets added via
// -target as implicit first argument.
std::string ProgName =llvm::sys::path::stem(ArgVector[0]);
#ifdef LLVM_ON_WIN32
// Transform to lowercase for case insensitive file systems.
ProgName = StringRef(ProgName).lower();
#endif
StringRef ProgNameRef = ProgName;
const DriverSuffix *DS = FindDriverSuffix(ProgNameRef);
if (!DS) {
// Try again after stripping any trailing version number:
// clang++3.5 -> clang++
ProgNameRef = ProgNameRef.rtrim("0123456789.");
DS = FindDriverSuffix(ProgNameRef);
}
if (!DS) {
// Try again after stripping trailing -component.
// clang++-tot -> clang++
ProgNameRef = ProgNameRef.slice(0, ProgNameRef.rfind('-'));
DS = FindDriverSuffix(ProgNameRef);
}
if (DS) {
if (const char *Flag = DS->ModeFlag) {
// Add Flag to the arguments.
auto it = ArgVector.begin();
if (it != ArgVector.end())
++it;
ArgVector.insert(it, Flag);
}
StringRef::size_type LastComponent = ProgNameRef.rfind(
'-', ProgNameRef.size() - strlen(DS->Suffix));
if (LastComponent == StringRef::npos)
return;
// Infer target from the prefix.
StringRef Prefix = ProgNameRef.slice(0, LastComponent);
std::string IgnoredError;
if (llvm::TargetRegistry::lookupTarget(Prefix, IgnoredError)) {
auto it = ArgVector.begin();
if (it != ArgVector.end())
++it;
const char *arr[] = { "-target", GetStableCStr(SavedStrings, Prefix) };
ArgVector.insert(it, std::begin(arr), std::end(arr));
}
}
}
示例4: insertTargetAndModeArgs
static void insertTargetAndModeArgs(StringRef Target, StringRef Mode,
SmallVectorImpl<const char *> &ArgVector,
std::set<std::string> &SavedStrings) {
if (!Mode.empty()) {
// Add the mode flag to the arguments.
auto it = ArgVector.begin();
if (it != ArgVector.end())
++it;
ArgVector.insert(it, GetStableCStr(SavedStrings, Mode));
}
if (!Target.empty()) {
auto it = ArgVector.begin();
if (it != ArgVector.end())
++it;
const char *arr[] = {"-target", GetStableCStr(SavedStrings, Target)};
ArgVector.insert(it, std::begin(arr), std::end(arr));
}
}
示例5: constructScopeDIE
// Construct a DIE for this scope.
void DwarfCompileUnit::constructScopeDIE(
LexicalScope *Scope, SmallVectorImpl<DIE *> &FinalChildren) {
if (!Scope || !Scope->getScopeNode())
return;
auto *DS = Scope->getScopeNode();
assert((Scope->getInlinedAt() || !isa<DISubprogram>(DS)) &&
"Only handle inlined subprograms here, use "
"constructSubprogramScopeDIE for non-inlined "
"subprograms");
SmallVector<DIE *, 8> Children;
// We try to create the scope DIE first, then the children DIEs. This will
// avoid creating un-used children then removing them later when we find out
// the scope DIE is null.
DIE *ScopeDIE;
if (Scope->getParent() && isa<DISubprogram>(DS)) {
ScopeDIE = constructInlinedScopeDIE(Scope);
if (!ScopeDIE)
return;
// We create children when the scope DIE is not null.
createScopeChildrenDIE(Scope, Children);
} else {
// Early exit when we know the scope DIE is going to be null.
if (DD->isLexicalScopeDIENull(Scope))
return;
bool HasNonScopeChildren = false;
// We create children here when we know the scope DIE is not going to be
// null and the children will be added to the scope DIE.
createScopeChildrenDIE(Scope, Children, &HasNonScopeChildren);
// If there are only other scopes as children, put them directly in the
// parent instead, as this scope would serve no purpose.
if (!HasNonScopeChildren) {
FinalChildren.insert(FinalChildren.end(),
std::make_move_iterator(Children.begin()),
std::make_move_iterator(Children.end()));
return;
}
ScopeDIE = constructLexicalScopeDIE(Scope);
assert(ScopeDIE && "Scope DIE should not be null.");
}
// Add children
for (auto &I : Children)
ScopeDIE->addChild(std::move(I));
FinalChildren.push_back(std::move(ScopeDIE));
}
示例6: getNameWithPrefix
/// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
/// and the specified global variable's name. If the global variable doesn't
/// have a name, this fills in a unique name for the global.
void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
const GlobalValue *GV) {
ManglerPrefixTy PrefixTy = Mangler::Default;
if (GV->hasPrivateLinkage())
PrefixTy = Mangler::Private;
else if (GV->hasLinkerPrivateLinkage() || GV->hasLinkerPrivateWeakLinkage())
PrefixTy = Mangler::LinkerPrivate;
// If this global has a name, handle it simply.
if (GV->hasName()) {
StringRef Name = GV->getName();
getNameWithPrefix(OutName, Name, PrefixTy);
// No need to do anything else if the global has the special "do not mangle"
// flag in the name.
if (Name[0] == 1)
return;
} else {
// Get the ID for the global, assigning a new one if we haven't got one
// already.
unsigned &ID = AnonGlobalIDs[GV];
if (ID == 0) ID = NextAnonGlobalID++;
// Must mangle the global into a unique ID.
getNameWithPrefix(OutName, "__unnamed_" + Twine(ID), PrefixTy);
}
// If we are supposed to add a microsoft-style suffix for stdcall/fastcall,
// add it.
if (DL->hasMicrosoftFastStdCallMangling()) {
if (const Function *F = dyn_cast<Function>(GV)) {
CallingConv::ID CC = F->getCallingConv();
// fastcall functions need to start with @.
// FIXME: This logic seems unlikely to be right.
if (CC == CallingConv::X86_FastCall) {
if (OutName[0] == '_')
OutName[0] = '@';
else
OutName.insert(OutName.begin(), '@');
}
// fastcall and stdcall functions usually need @42 at the end to specify
// the argument info.
FunctionType *FT = F->getFunctionType();
if ((CC == CallingConv::X86_FastCall || CC == CallingConv::X86_StdCall) &&
// "Pure" variadic functions do not receive @0 suffix.
(!FT->isVarArg() || FT->getNumParams() == 0 ||
(FT->getNumParams() == 1 && F->hasStructRetAttr())))
AddFastCallStdCallSuffix(OutName, F, *DL);
}
}
}
示例7: insertTargetAndModeArgs
static void insertTargetAndModeArgs(const ParsedClangName &NameParts,
SmallVectorImpl<const char *> &ArgVector,
std::set<std::string> &SavedStrings) {
// Put target and mode arguments at the start of argument list so that
// arguments specified in command line could override them. Avoid putting
// them at index 0, as an option like '-cc1' must remain the first.
int InsertionPoint = 0;
if (ArgVector.size() > 0)
++InsertionPoint;
if (NameParts.DriverMode) {
// Add the mode flag to the arguments.
ArgVector.insert(ArgVector.begin() + InsertionPoint,
GetStableCStr(SavedStrings, NameParts.DriverMode));
}
if (NameParts.TargetIsValid) {
const char *arr[] = {"-target", GetStableCStr(SavedStrings,
NameParts.TargetPrefix)};
ArgVector.insert(ArgVector.begin() + InsertionPoint,
std::begin(arr), std::end(arr));
}
}
示例8: sizeof
// Include the debug info compression header:
// "ZLIB" followed by 8 bytes representing the uncompressed size of the section,
// useful for consumers to preallocate a buffer to decompress into.
static bool
prependCompressionHeader(uint64_t Size,
SmallVectorImpl<char> &CompressedContents) {
const StringRef Magic = "ZLIB";
if (Size <= Magic.size() + sizeof(Size) + CompressedContents.size())
return false;
if (sys::IsLittleEndianHost)
sys::swapByteOrder(Size);
CompressedContents.insert(CompressedContents.begin(),
Magic.size() + sizeof(Size), 0);
std::copy(Magic.begin(), Magic.end(), CompressedContents.begin());
std::copy(reinterpret_cast<char *>(&Size),
reinterpret_cast<char *>(&Size + 1),
CompressedContents.begin() + Magic.size());
return true;
}
示例9: AnalyzeBranch
MipsInstrInfo::BranchType MipsInstrInfo::AnalyzeBranch(
MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB,
SmallVectorImpl<MachineOperand> &Cond, bool AllowModify,
SmallVectorImpl<MachineInstr *> &BranchInstrs) const {
MachineBasicBlock::reverse_iterator I = MBB.rbegin(), REnd = MBB.rend();
// Skip all the debug instructions.
while (I != REnd && I->isDebugValue())
++I;
if (I == REnd || !isUnpredicatedTerminator(*I)) {
// This block ends with no branches (it just falls through to its succ).
// Leave TBB/FBB null.
TBB = FBB = nullptr;
return BT_NoBranch;
}
MachineInstr *LastInst = &*I;
unsigned LastOpc = LastInst->getOpcode();
BranchInstrs.push_back(LastInst);
// Not an analyzable branch (e.g., indirect jump).
if (!getAnalyzableBrOpc(LastOpc))
return LastInst->isIndirectBranch() ? BT_Indirect : BT_None;
// Get the second to last instruction in the block.
unsigned SecondLastOpc = 0;
MachineInstr *SecondLastInst = nullptr;
if (++I != REnd) {
SecondLastInst = &*I;
SecondLastOpc = getAnalyzableBrOpc(SecondLastInst->getOpcode());
// Not an analyzable branch (must be an indirect jump).
if (isUnpredicatedTerminator(*SecondLastInst) && !SecondLastOpc)
return BT_None;
}
// If there is only one terminator instruction, process it.
if (!SecondLastOpc) {
// Unconditional branch.
if (LastInst->isUnconditionalBranch()) {
TBB = LastInst->getOperand(0).getMBB();
return BT_Uncond;
}
// Conditional branch
AnalyzeCondBr(LastInst, LastOpc, TBB, Cond);
return BT_Cond;
}
// If we reached here, there are two branches.
// If there are three terminators, we don't know what sort of block this is.
if (++I != REnd && isUnpredicatedTerminator(*I))
return BT_None;
BranchInstrs.insert(BranchInstrs.begin(), SecondLastInst);
// If second to last instruction is an unconditional branch,
// analyze it and remove the last instruction.
if (SecondLastInst->isUnconditionalBranch()) {
// Return if the last instruction cannot be removed.
if (!AllowModify)
return BT_None;
TBB = SecondLastInst->getOperand(0).getMBB();
LastInst->eraseFromParent();
BranchInstrs.pop_back();
return BT_Uncond;
}
// Conditional branch followed by an unconditional branch.
// The last one must be unconditional.
if (!LastInst->isUnconditionalBranch())
return BT_None;
AnalyzeCondBr(SecondLastInst, SecondLastOpc, TBB, Cond);
FBB = LastInst->getOperand(0).getMBB();
return BT_CondUncond;
}
示例10: ParseProgName
static void ParseProgName(SmallVectorImpl<const char *> &ArgVector,
std::set<std::string> &SavedStrings,
Driver &TheDriver)
{
// Try to infer frontend type and default target from the program name.
// suffixes[] contains the list of known driver suffixes.
// Suffixes are compared against the program name in order.
// If there is a match, the frontend type is updated as necessary (CPP/C++).
// If there is no match, a second round is done after stripping the last
// hyphen and everything following it. This allows using something like
// "clang++-2.9".
// If there is a match in either the first or second round,
// the function tries to identify a target as prefix. E.g.
// "x86_64-linux-clang" as interpreted as suffix "clang" with
// target prefix "x86_64-linux". If such a target prefix is found,
// is gets added via -target as implicit first argument.
static const struct {
const char *Suffix;
const char *ModeFlag;
} suffixes [] = {
{ "templight", nullptr },
{ "templight++", "--driver-mode=g++" },
{ "templight-c++", "--driver-mode=g++" },
{ "templight-cc", nullptr },
{ "templight-cpp", "--driver-mode=cpp" },
{ "templight-g++", "--driver-mode=g++" },
{ "templight-gcc", nullptr },
{ "templight-cl", "--driver-mode=cl" },
{ "cc", nullptr },
{ "cpp", "--driver-mode=cpp" },
{ "cl" , "--driver-mode=cl" },
{ "++", "--driver-mode=g++" },
};
std::string ProgName(llvm::sys::path::stem(ArgVector[0]));
#ifdef LLVM_ON_WIN32
// Transform to lowercase for case insensitive file systems.
std::transform(ProgName.begin(), ProgName.end(), ProgName.begin(),
toLowercase);
#endif
StringRef ProgNameRef(ProgName);
StringRef Prefix;
for (int Components = 2; Components; --Components) {
bool FoundMatch = false;
size_t i;
for (i = 0; i < sizeof(suffixes) / sizeof(suffixes[0]); ++i) {
if (ProgNameRef.endswith(suffixes[i].Suffix)) {
FoundMatch = true;
SmallVectorImpl<const char *>::iterator it = ArgVector.begin();
if (it != ArgVector.end())
++it;
if (suffixes[i].ModeFlag)
ArgVector.insert(it, suffixes[i].ModeFlag);
break;
}
}
if (FoundMatch) {
StringRef::size_type LastComponent = ProgNameRef.rfind('-',
ProgNameRef.size() - strlen(suffixes[i].Suffix));
if (LastComponent != StringRef::npos)
Prefix = ProgNameRef.slice(0, LastComponent);
break;
}
StringRef::size_type LastComponent = ProgNameRef.rfind('-');
if (LastComponent == StringRef::npos)
break;
ProgNameRef = ProgNameRef.slice(0, LastComponent);
}
if (Prefix.empty())
return;
std::string IgnoredError;
if (llvm::TargetRegistry::lookupTarget(Prefix, IgnoredError)) {
SmallVectorImpl<const char *>::iterator it = ArgVector.begin();
if (it != ArgVector.end())
++it;
const char* Strings[] =
{ GetStableCStr(SavedStrings, std::string("-target")),
GetStableCStr(SavedStrings, Prefix) };
ArgVector.insert(it, Strings, Strings + llvm::array_lengthof(Strings));
}
}
示例11: GenerateNewArgTokens
/// GenerateNewArgTokens - Returns true if OldTokens can be converted to a new
/// vector of tokens in NewTokens. The new number of arguments will be placed
/// in NumArgs and the ranges which need to surrounded in parentheses will be
/// in ParenHints.
/// Returns false if the token stream cannot be changed. If this is because
/// of an initializer list starting a macro argument, the range of those
/// initializer lists will be place in InitLists.
static bool GenerateNewArgTokens(Preprocessor &PP,
SmallVectorImpl<Token> &OldTokens,
SmallVectorImpl<Token> &NewTokens,
unsigned &NumArgs,
SmallVectorImpl<SourceRange> &ParenHints,
SmallVectorImpl<SourceRange> &InitLists) {
if (!CheckMatchedBrackets(OldTokens))
return false;
// Once it is known that the brackets are matched, only a simple count of the
// braces is needed.
unsigned Braces = 0;
// First token of a new macro argument.
SmallVectorImpl<Token>::iterator ArgStartIterator = OldTokens.begin();
// First closing brace in a new macro argument. Used to generate
// SourceRanges for InitLists.
SmallVectorImpl<Token>::iterator ClosingBrace = OldTokens.end();
NumArgs = 0;
Token TempToken;
// Set to true when a macro separator token is found inside a braced list.
// If true, the fixed argument spans multiple old arguments and ParenHints
// will be updated.
bool FoundSeparatorToken = false;
for (SmallVectorImpl<Token>::iterator I = OldTokens.begin(),
E = OldTokens.end();
I != E; ++I) {
if (I->is(tok::l_brace)) {
++Braces;
} else if (I->is(tok::r_brace)) {
--Braces;
if (Braces == 0 && ClosingBrace == E && FoundSeparatorToken)
ClosingBrace = I;
} else if (I->is(tok::eof)) {
// EOF token is used to separate macro arguments
if (Braces != 0) {
// Assume comma separator is actually braced list separator and change
// it back to a comma.
FoundSeparatorToken = true;
I->setKind(tok::comma);
I->setLength(1);
} else { // Braces == 0
// Separator token still separates arguments.
++NumArgs;
// If the argument starts with a brace, it can't be fixed with
// parentheses. A different diagnostic will be given.
if (FoundSeparatorToken && ArgStartIterator->is(tok::l_brace)) {
InitLists.push_back(
SourceRange(ArgStartIterator->getLocation(),
PP.getLocForEndOfToken(ClosingBrace->getLocation())));
ClosingBrace = E;
}
// Add left paren
if (FoundSeparatorToken) {
TempToken.startToken();
TempToken.setKind(tok::l_paren);
TempToken.setLocation(ArgStartIterator->getLocation());
TempToken.setLength(0);
NewTokens.push_back(TempToken);
}
// Copy over argument tokens
NewTokens.insert(NewTokens.end(), ArgStartIterator, I);
// Add right paren and store the paren locations in ParenHints
if (FoundSeparatorToken) {
SourceLocation Loc = PP.getLocForEndOfToken((I - 1)->getLocation());
TempToken.startToken();
TempToken.setKind(tok::r_paren);
TempToken.setLocation(Loc);
TempToken.setLength(0);
NewTokens.push_back(TempToken);
ParenHints.push_back(SourceRange(ArgStartIterator->getLocation(),
Loc));
}
// Copy separator token
NewTokens.push_back(*I);
// Reset values
ArgStartIterator = I + 1;
FoundSeparatorToken = false;
}
}
}
return !ParenHints.empty() && InitLists.empty();
}