本文整理汇总了C++中StringRef::rtrim方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRef::rtrim方法的具体用法?C++ StringRef::rtrim怎么用?C++ StringRef::rtrim使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringRef
的用法示例。
在下文中一共展示了StringRef::rtrim方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: canonicalize
// Convert a path into the canonical form.
// Canonical form is either "/", or "/segment" * N:
// C:\foo\bar --> /c:/foo/bar
// /foo/ --> /foo
// a/b/c --> /a/b/c
static SmallString<128> canonicalize(StringRef Path) {
SmallString<128> Result = Path.rtrim('/');
native(Result, sys::path::Style::posix);
if (Result.empty() || Result.front() != '/')
Result.insert(Result.begin(), '/');
return Result;
}
示例2: 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));
}
}
}
示例3: leadingUnderscores
NameStyle::NameStyle(StringRef name)
: leadingUnderscores(0), trailingUnderscores(0) {
// Trim leading and trailing underscores.
StringRef center = name.ltrim("_");
if (center == "")
return;
leadingUnderscores = name.size() - center.size();
center = center.rtrim("_");
assert(!center.empty());
trailingUnderscores = name.size() - center.size() - leadingUnderscores;
unsigned pos = 0;
enum Case {
None = 0,
Lower,
Upper,
};
auto caseOf = [](char c) {
if (clang::isLowercase(c))
return Lower;
if (clang::isUppercase(c))
return Upper;
return None;
};
unsigned underscores = 0;
unsigned caseCount[3] = {0, 0, 0};
Case leadingCase = None;
for (; pos < center.size(); ++pos) {
char c = center[pos];
Case curCase = caseOf(c);
if (!leadingCase)
leadingCase = curCase;
underscores += (c == '_');
caseCount[curCase] += 1;
}
assert(caseCount[leadingCase] > 0);
if (caseCount[Lower] && !caseCount[Upper]) {
wordDelimiter = underscores ? LowercaseWithUnderscores : Lowercase;
return;
}
if (caseCount[Upper] && !caseCount[Lower]) {
wordDelimiter = underscores ? UppercaseWithUnderscores : Uppercase;
return;
}
if (leadingCase && !underscores) {
wordDelimiter = leadingCase == Lower ? LowerCamelCase : UpperCamelCase;
return;
}
// FIXME: should we try to choose a delimiter if there is more than one?
wordDelimiter = Unknown;
}
示例4: printCOFFSymbolTable
void llvm::printCOFFSymbolTable(const COFFObjectFile *coff) {
for (unsigned SI = 0, SE = coff->getNumberOfSymbols(); SI != SE; ++SI) {
ErrorOr<COFFSymbolRef> Symbol = coff->getSymbol(SI);
StringRef Name;
error(Symbol.getError());
error(coff->getSymbolName(*Symbol, Name));
outs() << "[" << format("%2d", SI) << "]"
<< "(sec " << format("%2d", int(Symbol->getSectionNumber())) << ")"
<< "(fl 0x00)" // Flag bits, which COFF doesn't have.
<< "(ty " << format("%3x", unsigned(Symbol->getType())) << ")"
<< "(scl " << format("%3x", unsigned(Symbol->getStorageClass())) << ") "
<< "(nx " << unsigned(Symbol->getNumberOfAuxSymbols()) << ") "
<< "0x" << format("%08x", unsigned(Symbol->getValue())) << " "
<< Name << "\n";
for (unsigned AI = 0, AE = Symbol->getNumberOfAuxSymbols(); AI < AE; ++AI, ++SI) {
if (Symbol->isSectionDefinition()) {
const coff_aux_section_definition *asd;
error(coff->getAuxSymbol<coff_aux_section_definition>(SI + 1, asd));
int32_t AuxNumber = asd->getNumber(Symbol->isBigObj());
outs() << "AUX "
<< format("scnlen 0x%x nreloc %d nlnno %d checksum 0x%x "
, unsigned(asd->Length)
, unsigned(asd->NumberOfRelocations)
, unsigned(asd->NumberOfLinenumbers)
, unsigned(asd->CheckSum))
<< format("assoc %d comdat %d\n"
, unsigned(AuxNumber)
, unsigned(asd->Selection));
} else if (Symbol->isFileRecord()) {
const char *FileName;
error(coff->getAuxSymbol<char>(SI + 1, FileName));
StringRef Name(FileName, Symbol->getNumberOfAuxSymbols() *
coff->getSymbolTableEntrySize());
outs() << "AUX " << Name.rtrim(StringRef("\0", 1)) << '\n';
SI = SI + Symbol->getNumberOfAuxSymbols();
break;
} else if (Symbol->isWeakExternal()) {
const coff_aux_weak_external *awe;
error(coff->getAuxSymbol<coff_aux_weak_external>(SI + 1, awe));
outs() << "AUX " << format("indx %d srch %d\n",
static_cast<uint32_t>(awe->TagIndex),
static_cast<uint32_t>(awe->Characteristics));
} else {
outs() << "AUX Unknown\n";
}
}
}
}
示例5: StringRef
ErrorOr<StringRef> Archive::Child::getName() const {
StringRef name = getRawName();
// Check if it's a special name.
if (name[0] == '/') {
if (name.size() == 1) // Linker member.
return name;
if (name.size() == 2 && name[1] == '/') // String table.
return name;
// It's a long name.
// Get the offset.
std::size_t offset;
if (name.substr(1).rtrim(' ').getAsInteger(10, offset))
llvm_unreachable("Long name offset is not an integer");
// Verify it.
if (offset >= Parent->StringTable.size())
return object_error::parse_failed;
const char *addr = Parent->StringTable.begin() + offset;
// GNU long file names end with a "/\n".
if (Parent->kind() == K_GNU || Parent->kind() == K_MIPS64) {
StringRef::size_type End = StringRef(addr).find('\n');
return StringRef(addr, End - 1);
}
return StringRef(addr);
} else if (name.startswith("#1/")) {
uint64_t name_size;
if (name.substr(3).rtrim(' ').getAsInteger(10, name_size))
llvm_unreachable("Long name length is not an ingeter");
return Data.substr(Header.getSizeOf(), name_size).rtrim('\0');
} else {
// It is not a long name so trim the blanks at the end of the name.
if (name[name.size() - 1] != '/') {
return name.rtrim(' ');
}
}
// It's a simple name.
if (name[name.size() - 1] == '/')
return name.substr(0, name.size() - 1);
return name;
}
示例6: extractParamOutlineItem
Optional<llvm::markup::ParamField *> extractParamOutlineItem(
llvm::markup::MarkupContext &MC,
llvm::markup::MarkupASTNode *Node) {
auto Item = dyn_cast<llvm::markup::Item>(Node);
if (!Item)
return None;
auto Children = Item->getChildren();
if (Children.empty())
return None;
auto FirstChild = Children.front();
auto FirstParagraph = dyn_cast<llvm::markup::Paragraph>(FirstChild);
if (!FirstParagraph)
return None;
auto FirstParagraphChildren = FirstParagraph->getChildren();
if (FirstParagraphChildren.empty())
return None;
auto ParagraphText =
dyn_cast<llvm::markup::Text>(FirstParagraphChildren.front());
if (!ParagraphText)
return None;
StringRef Name;
StringRef Remainder;
std::tie(Name, Remainder) = ParagraphText->getLiteralContent().split(':');
Name = Name.rtrim();
if (Name.empty())
return None;
ParagraphText->setLiteralContent(Remainder.ltrim());
return llvm::markup::ParamField::create(MC, Name, Children);
}
示例7: Split
BreakableToken::Split
BreakableComment::getReflowSplit(StringRef Text, StringRef ReflowPrefix,
unsigned PreviousEndColumn,
unsigned ColumnLimit) const {
unsigned ReflowStartColumn = PreviousEndColumn + ReflowPrefix.size();
StringRef TrimmedText = Text.rtrim(Blanks);
// This is the width of the resulting line in case the full line of Text gets
// reflown up starting at ReflowStartColumn.
unsigned FullWidth = ReflowStartColumn + encoding::columnWidthWithTabs(
TrimmedText, ReflowStartColumn,
Style.TabWidth, Encoding);
// If the full line fits up, we return a reflow split after it,
// otherwise we compute the largest piece of text that fits after
// ReflowStartColumn.
Split ReflowSplit =
FullWidth <= ColumnLimit
? Split(TrimmedText.size(), Text.size() - TrimmedText.size())
: getCommentSplit(Text, ReflowStartColumn, ColumnLimit,
Style.TabWidth, Encoding);
// We need to be extra careful here, because while it's OK to keep a long line
// if it can't be broken into smaller pieces (like when the first word of a
// long line is longer than the column limit), it's not OK to reflow that long
// word up. So we recompute the size of the previous line after reflowing and
// only return the reflow split if that's under the line limit.
if (ReflowSplit.first != StringRef::npos &&
// Check if the width of the newly reflown line is under the limit.
PreviousEndColumn + ReflowPrefix.size() +
encoding::columnWidthWithTabs(Text.substr(0, ReflowSplit.first),
PreviousEndColumn +
ReflowPrefix.size(),
Style.TabWidth, Encoding) <=
ColumnLimit) {
return ReflowSplit;
}
return Split(StringRef::npos, 0);
}
示例8: emitBuiltinCall
/// emitBuiltinCall - Emit a call to a builtin function.
void irgen::emitBuiltinCall(IRGenFunction &IGF, Identifier FnId,
SILType resultType,
Explosion &args, Explosion &out,
SubstitutionList substitutions) {
// Decompose the function's name into a builtin name and type list.
const BuiltinInfo &Builtin = IGF.getSILModule().getBuiltinInfo(FnId);
if (Builtin.ID == BuiltinValueKind::UnsafeGuaranteedEnd) {
// Just consume the incoming argument.
assert(args.size() == 1 && "Expecting one incoming argument");
(void)args.claimAll();
return;
}
if (Builtin.ID == BuiltinValueKind::UnsafeGuaranteed) {
// Just forward the incoming argument.
assert(args.size() == 1 && "Expecting one incoming argument");
out = std::move(args);
// This is a token.
out.add(llvm::ConstantInt::get(IGF.IGM.Int8Ty, 0));
return;
}
if (Builtin.ID == BuiltinValueKind::OnFastPath) {
// The onFastPath builtin has only an effect on SIL level, so we lower it
// to a no-op.
return;
}
// These builtins don't care about their argument:
if (Builtin.ID == BuiltinValueKind::Sizeof) {
(void)args.claimAll();
auto valueTy = getLoweredTypeAndTypeInfo(IGF.IGM,
substitutions[0].getReplacement());
out.add(valueTy.second.getSize(IGF, valueTy.first));
return;
}
if (Builtin.ID == BuiltinValueKind::Strideof) {
(void)args.claimAll();
auto valueTy = getLoweredTypeAndTypeInfo(IGF.IGM,
substitutions[0].getReplacement());
out.add(valueTy.second.getStride(IGF, valueTy.first));
return;
}
if (Builtin.ID == BuiltinValueKind::Alignof) {
(void)args.claimAll();
auto valueTy = getLoweredTypeAndTypeInfo(IGF.IGM,
substitutions[0].getReplacement());
// The alignof value is one greater than the alignment mask.
out.add(IGF.Builder.CreateAdd(
valueTy.second.getAlignmentMask(IGF, valueTy.first),
IGF.IGM.getSize(Size(1))));
return;
}
if (Builtin.ID == BuiltinValueKind::IsPOD) {
(void)args.claimAll();
auto valueTy = getLoweredTypeAndTypeInfo(IGF.IGM,
substitutions[0].getReplacement());
out.add(valueTy.second.getIsPOD(IGF, valueTy.first));
return;
}
// addressof expects an lvalue argument.
if (Builtin.ID == BuiltinValueKind::AddressOf) {
llvm::Value *address = args.claimNext();
llvm::Value *value = IGF.Builder.CreateBitCast(address,
IGF.IGM.Int8PtrTy);
out.add(value);
return;
}
// Everything else cares about the (rvalue) argument.
// If this is an LLVM IR intrinsic, lower it to an intrinsic call.
const IntrinsicInfo &IInfo = IGF.getSILModule().getIntrinsicInfo(FnId);
llvm::Intrinsic::ID IID = IInfo.ID;
// Calls to the int_instrprof_increment intrinsic are emitted during SILGen.
// At that stage, the function name GV used by the profiling pass is hidden.
// Fix the intrinsic call here by pointing it to the correct GV.
if (IID == llvm::Intrinsic::instrprof_increment) {
// Extract the PGO function name.
auto *NameGEP = cast<llvm::User>(args.claimNext());
auto *NameGV = dyn_cast<llvm::GlobalVariable>(NameGEP->stripPointerCasts());
if (NameGV) {
auto *NameC = NameGV->getInitializer();
StringRef Name = cast<llvm::ConstantDataArray>(NameC)->getRawDataValues();
StringRef PGOFuncName = Name.rtrim(StringRef("\0", 1));
// Point the increment call to the right function name variable.
std::string PGOFuncNameVar = llvm::getPGOFuncNameVarName(
PGOFuncName, llvm::GlobalValue::LinkOnceAnyLinkage);
auto *FuncNamePtr = IGF.IGM.Module.getNamedGlobal(PGOFuncNameVar);
if (FuncNamePtr) {
//.........这里部分代码省略.........
示例9: getLineList
LineList MarkupContext::getLineList(swift::RawComment RC) {
LineListBuilder Builder(*this);
for (const auto &C : RC.Comments) {
if (C.isLine()) {
// Skip comment marker.
unsigned CommentMarkerBytes = 2 + (C.isOrdinary() ? 0 : 1);
StringRef Cleaned = C.RawText.drop_front(CommentMarkerBytes);
// Drop trailing newline.
Cleaned = Cleaned.rtrim("\n\r");
auto CleanedStartLoc =
C.Range.getStart().getAdvancedLocOrInvalid(CommentMarkerBytes);
auto CleanedEndLoc =
C.Range.getStart().getAdvancedLocOrInvalid(Cleaned.size());
Builder.addLine(Cleaned, { CleanedStartLoc, CleanedEndLoc });
} else {
// Skip comment markers at the beginning and at the end.
unsigned CommentMarkerBytes = 2 + (C.isOrdinary() ? 0 : 1);
StringRef Cleaned = C.RawText.drop_front(CommentMarkerBytes);
if (Cleaned.endswith("*/"))
Cleaned = Cleaned.drop_back(2);
else if (Cleaned.endswith("/"))
Cleaned = Cleaned.drop_back(1);
swift::SourceLoc CleanedStartLoc =
C.Range.getStart().getAdvancedLocOrInvalid(CommentMarkerBytes);
// Determine if we have leading decorations in this block comment.
bool HasASCIIArt = false;
if (swift::startsWithNewline(Cleaned)) {
Builder.addLine(Cleaned.substr(0, 0), { C.Range.getStart(),
C.Range.getStart() });
unsigned NewlineBytes = swift::measureNewline(Cleaned);
Cleaned = Cleaned.drop_front(NewlineBytes);
CleanedStartLoc = CleanedStartLoc.getAdvancedLocOrInvalid(NewlineBytes);
HasASCIIArt = measureASCIIArt(Cleaned, C.StartColumn - 1) != 0;
}
while (!Cleaned.empty()) {
size_t Pos = Cleaned.find_first_of("\n\r");
if (Pos == StringRef::npos)
Pos = Cleaned.size();
// Skip over ASCII art, if present.
if (HasASCIIArt)
if (unsigned ASCIIArtBytes =
measureASCIIArt(Cleaned, C.StartColumn - 1)) {
Cleaned = Cleaned.drop_front(ASCIIArtBytes);
CleanedStartLoc =
CleanedStartLoc.getAdvancedLocOrInvalid(ASCIIArtBytes);
Pos -= ASCIIArtBytes;
}
StringRef Line = Cleaned.substr(0, Pos);
auto CleanedEndLoc = CleanedStartLoc.getAdvancedLocOrInvalid(Pos);
Cleaned = Cleaned.drop_front(Pos);
unsigned NewlineBytes = swift::measureNewline(Cleaned);
Cleaned = Cleaned.drop_front(NewlineBytes);
Pos += NewlineBytes;
CleanedStartLoc = CleanedStartLoc.getAdvancedLocOrInvalid(Pos);
Builder.addLine(Line, { CleanedStartLoc, CleanedEndLoc });
}
}
}
return Builder.takeLineList();
}