本文整理汇总了C++中llvm::StringRef::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRef::substr方法的具体用法?C++ StringRef::substr怎么用?C++ StringRef::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类llvm::StringRef
的用法示例。
在下文中一共展示了StringRef::substr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getThunkTarget
std::string Context::getThunkTarget(llvm::StringRef MangledName) {
if (!isThunkSymbol(MangledName))
return std::string();
if (isMangledName(MangledName)) {
// The targets of those thunks not derivable from the mangling.
if (MangledName.endswith("TR") ||
MangledName.endswith("Tr") ||
MangledName.endswith("TW") )
return std::string();
if (MangledName.endswith("fC")) {
std::string target = MangledName.str();
target[target.size() - 1] = 'c';
return target;
}
return MangledName.substr(0, MangledName.size() - 2).str();
}
// Old mangling.
assert(MangledName.startswith("_T"));
StringRef Remaining = MangledName.substr(2);
if (Remaining.startswith("PA_"))
return Remaining.substr(3).str();
if (Remaining.startswith("PAo_"))
return Remaining.substr(4).str();
assert(Remaining.startswith("To") || Remaining.startswith("TO"));
return std::string("_T") + Remaining.substr(2).str();
}
示例2: StripSpaces
static inline void StripSpaces(llvm::StringRef &Str)
{
while (!Str.empty() && isspace(Str[0]))
Str = Str.substr(1);
while (!Str.empty() && isspace(Str.back()))
Str = Str.substr(0, Str.size()-1);
}
示例3: ResolveName
PythonObject PythonObject::ResolveName(llvm::StringRef name) const {
// Resolve the name in the context of the specified object. If, for example,
// `this` refers to a PyModule, then this will look for `name` in this
// module. If `this` refers to a PyType, then it will resolve `name` as an
// attribute of that type. If `this` refers to an instance of an object,
// then it will resolve `name` as the value of the specified field.
//
// This function handles dotted names so that, for example, if `m_py_obj`
// refers to the `sys` module, and `name` == "path.append", then it will find
// the function `sys.path.append`.
size_t dot_pos = name.find('.');
if (dot_pos == llvm::StringRef::npos) {
// No dots in the name, we should be able to find the value immediately as
// an attribute of `m_py_obj`.
return GetAttributeValue(name);
}
// Look up the first piece of the name, and resolve the rest as a child of
// that.
PythonObject parent = ResolveName(name.substr(0, dot_pos));
if (!parent.IsAllocated())
return PythonObject();
// Tail recursion.. should be optimized by the compiler
return parent.ResolveName(name.substr(dot_pos + 1));
}
示例4: symbol
Symbol symbol(llvm::StringRef QName) {
Symbol Sym;
Sym.ID = SymbolID(QName.str());
size_t Pos = QName.rfind("::");
if (Pos == llvm::StringRef::npos) {
Sym.Name = QName;
Sym.Scope = "";
} else {
Sym.Name = QName.substr(Pos + 2);
Sym.Scope = QName.substr(0, Pos + 2);
}
return Sym;
}
示例5:
PythonObject
PythonObject::ResolveNameWithDictionary(llvm::StringRef name,
const PythonDictionary &dict) {
size_t dot_pos = name.find('.');
llvm::StringRef piece = name.substr(0, dot_pos);
PythonObject result = dict.GetItemForKey(PythonString(piece));
if (dot_pos == llvm::StringRef::npos) {
// There was no dot, we're done.
return result;
}
// There was a dot. The remaining portion of the name should be looked up in
// the context of the object that was found in the dictionary.
return result.ResolveName(name.substr(dot_pos + 1));
}
示例6: ParseCudaVersionFile
// Parses the contents of version.txt in an CUDA installation. It should
// contain one line of the from e.g. "CUDA Version 7.5.2".
static CudaVersion ParseCudaVersionFile(llvm::StringRef V) {
if (!V.startswith("CUDA Version "))
return CudaVersion::UNKNOWN;
V = V.substr(strlen("CUDA Version "));
int Major = -1, Minor = -1;
auto First = V.split('.');
auto Second = First.second.split('.');
if (First.first.getAsInteger(10, Major) ||
Second.first.getAsInteger(10, Minor))
return CudaVersion::UNKNOWN;
if (Major == 7 && Minor == 0) {
// This doesn't appear to ever happen -- version.txt doesn't exist in the
// CUDA 7 installs I've seen. But no harm in checking.
return CudaVersion::CUDA_70;
}
if (Major == 7 && Minor == 5)
return CudaVersion::CUDA_75;
if (Major == 8 && Minor == 0)
return CudaVersion::CUDA_80;
if (Major == 9 && Minor == 0)
return CudaVersion::CUDA_90;
if (Major == 9 && Minor == 1)
return CudaVersion::CUDA_91;
return CudaVersion::UNKNOWN;
}
示例7: demangle
static void demangle(llvm::raw_ostream &os, llvm::StringRef name,
const swift::Demangle::DemangleOptions &options) {
bool hadLeadingUnderscore = false;
if (name.startswith("__")) {
hadLeadingUnderscore = true;
name = name.substr(1);
}
swift::Demangle::NodePointer pointer =
swift::demangle_wrappers::demangleSymbolAsNode(name);
if (ExpandMode || TreeOnly) {
llvm::outs() << "Demangling for " << name << '\n';
swift::demangle_wrappers::NodeDumper(pointer).print(llvm::outs());
}
if (RemangleMode) {
if (hadLeadingUnderscore) llvm::outs() << '_';
// Just reprint the original mangled name if it didn't demangle.
// This makes it easier to share the same database between the
// mangling and demangling tests.
if (!pointer) {
llvm::outs() << name;
} else {
llvm::outs() << swift::Demangle::mangleNode(pointer);
}
return;
}
if (!TreeOnly) {
std::string string = swift::Demangle::nodeToString(pointer, options);
if (!CompactMode)
llvm::outs() << name << " ---> ";
llvm::outs() << (string.empty() ? name : llvm::StringRef(string));
}
}
示例8: HandleComment
/// HandleComment - Hook into the preprocessor and extract comments containing
/// expected errors and warnings.
bool VerifyDiagnosticConsumer::HandleComment(Lexer &PP, const SourceLocation& CommentBegin, const llvm::StringRef &C) {
const llvm::SourceMgr &SM = PP.getSourceManager();
// If this comment is for a different source manager, ignore it.
if (SrcManager && &SM != SrcManager)
return false;
if (C.empty())
return false;
// Fold any "\<EOL>" sequences
size_t loc = C.find('\\');
if (loc == StringRef::npos) {
ParseDirective(C, &ED, SM, &PP, CommentBegin, Status);
return false;
}
std::string C2;
C2.reserve(C.size());
for (size_t last = 0;; loc = C.find('\\', last)) {
if (loc == StringRef::npos || loc == C.size()) {
C2 += C.substr(last);
break;
}
C2 += C.substr(last, loc-last);
last = loc + 1;
if (C[last] == '\n' || C[last] == '\r') {
++last;
// Escape \r\n or \n\r, but not \n\n.
if (last < C.size())
if (C[last] == '\n' || C[last] == '\r')
if (C[last] != C[last-1])
++last;
} else {
// This was just a normal backslash.
C2 += '\\';
}
}
if (!C2.empty())
ParseDirective(C2, &ED, SM, &PP, CommentBegin, Status);
return false;
}
示例9: AddDelimitedPaths
void InitHeaderSearch::AddDelimitedPaths(llvm::StringRef at) {
if (at.empty()) // Empty string should not add '.' path.
return;
llvm::StringRef::size_type delim;
while ((delim = at.find(llvm::sys::PathSeparator)) != llvm::StringRef::npos) {
if (delim == 0)
AddPath(".", Angled, false, true, false);
else
AddPath(at.substr(0, delim), Angled, false, true, false);
at = at.substr(delim + 1);
}
if (at.empty())
AddPath(".", Angled, false, true, false);
else
AddPath(at, Angled, false, true, false);
}
示例10: sym
// Helpers to produce fake index symbols for memIndex() or completions().
// USRFormat is a regex replacement string for the unqualified part of the USR.
Symbol sym(llvm::StringRef QName, index::SymbolKind Kind,
llvm::StringRef USRFormat) {
Symbol Sym;
std::string USR = "c:"; // We synthesize a few simple cases of USRs by hand!
size_t Pos = QName.rfind("::");
if (Pos == llvm::StringRef::npos) {
Sym.Name = QName;
Sym.Scope = "";
} else {
Sym.Name = QName.substr(Pos + 2);
Sym.Scope = QName.substr(0, Pos + 2);
USR += "@[email protected]" + replace(QName.substr(0, Pos), "::", "@[email protected]"); // ns:: -> @[email protected]
}
USR += llvm::Regex("^.*$").sub(USRFormat, Sym.Name); // e.g. func -> @[email protected]#
Sym.ID = SymbolID(USR);
Sym.SymInfo.Kind = Kind;
Sym.Flags |= Symbol::IndexedForCodeCompletion;
Sym.Origin = SymbolOrigin::Static;
return Sym;
}
示例11: shouldProcess
bool ProjectManager::shouldProcess(llvm::StringRef filename, ProjectInfo* project)
{
if (!project)
return false;
if (project->type == ProjectInfo::External)
return false;
std::string fn = outputPrefix % "/" % project->name % "/" % filename.substr(project->source_path.size()) % ".html";
return !llvm::sys::fs::exists(fn);
// || boost::filesystem::last_write_time(p) < entry->getModificationTime();
}
示例12: isThunkSymbol
bool Context::isThunkSymbol(llvm::StringRef MangledName) {
if (isMangledName(MangledName)) {
// First do a quick check
if (MangledName.endswith("TA") || // partial application forwarder
MangledName.endswith("Ta") || // ObjC partial application forwarder
MangledName.endswith("To") || // swift-as-ObjC thunk
MangledName.endswith("TO") || // ObjC-as-swift thunk
MangledName.endswith("TR") || // reabstraction thunk helper function
MangledName.endswith("Tr") || // reabstraction thunk
MangledName.endswith("TW") || // protocol witness thunk
MangledName.endswith("fC")) { // allocating constructor
// To avoid false positives, we need to fully demangle the symbol.
NodePointer Nd = D->demangleSymbol(MangledName);
if (!Nd || Nd->getKind() != Node::Kind::Global ||
Nd->getNumChildren() == 0)
return false;
switch (Nd->getFirstChild()->getKind()) {
case Node::Kind::ObjCAttribute:
case Node::Kind::NonObjCAttribute:
case Node::Kind::PartialApplyObjCForwarder:
case Node::Kind::PartialApplyForwarder:
case Node::Kind::ReabstractionThunkHelper:
case Node::Kind::ReabstractionThunk:
case Node::Kind::ProtocolWitness:
case Node::Kind::Allocator:
return true;
default:
break;
}
}
return false;
}
if (MangledName.startswith("_T")) {
// Old mangling.
StringRef Remaining = MangledName.substr(2);
if (Remaining.startswith("To") || // swift-as-ObjC thunk
Remaining.startswith("TO") || // ObjC-as-swift thunk
Remaining.startswith("PA_") || // partial application forwarder
Remaining.startswith("PAo_")) { // ObjC partial application forwarder
return true;
}
}
return false;
}
示例13: open
static bool GetDescriptionSysV4L(llvm::StringRef path, std::string* desc) {
llvm::SmallString<64> ifpath{"/sys/class/video4linux/"};
ifpath += path.substr(5);
ifpath += "/device/interface";
int fd = open(ifpath.c_str(), O_RDONLY);
if (fd < 0) return false;
char readBuf[128];
ssize_t n = read(fd, readBuf, sizeof(readBuf));
close(fd);
if (n <= 0) return false;
*desc = llvm::StringRef(readBuf, n).rtrim();
return true;
}
示例14: Args
CompletionRequest::CompletionRequest(llvm::StringRef command_line,
unsigned raw_cursor_pos,
int match_start_point,
int max_return_elements,
CompletionResult &result)
: m_command(command_line), m_raw_cursor_pos(raw_cursor_pos),
m_match_start_point(match_start_point),
m_max_return_elements(max_return_elements), m_result(result) {
// We parse the argument up to the cursor, so the last argument in
// parsed_line is the one containing the cursor, and the cursor is after the
// last character.
m_parsed_line = Args(command_line);
m_partial_parsed_line = Args(command_line.substr(0, raw_cursor_pos));
m_cursor_index = m_partial_parsed_line.GetArgumentCount() - 1;
if (m_cursor_index == -1)
m_cursor_char_position = 0;
else
m_cursor_char_position =
strlen(m_partial_parsed_line.GetArgumentAtIndex(m_cursor_index));
const char *cursor = command_line.data() + raw_cursor_pos;
if (raw_cursor_pos > 0 && cursor[-1] == ' ') {
// We are just after a space. If we are in an argument, then we will
// continue parsing, but if we are between arguments, then we have to
// complete whatever the next element would be. We can distinguish the two
// cases because if we are in an argument (e.g. because the space is
// protected by a quote) then the space will also be in the parsed
// argument...
const char *current_elem =
m_partial_parsed_line.GetArgumentAtIndex(m_cursor_index);
if (m_cursor_char_position == 0 ||
current_elem[m_cursor_char_position - 1] != ' ') {
m_parsed_line.InsertArgumentAtIndex(m_cursor_index + 1, llvm::StringRef(),
'\0');
m_cursor_index++;
m_cursor_char_position = 0;
}
}
}
示例15: GetSystemLibraryPaths
bool GetSystemLibraryPaths(llvm::SmallVectorImpl<std::string>& Paths) {
#if defined(__APPLE__) || defined(__CYGWIN__)
Paths.push_back("/usr/local/lib/");
Paths.push_back("/usr/X11R6/lib/");
Paths.push_back("/usr/lib/");
Paths.push_back("/lib/");
#ifndef __APPLE__
Paths.push_back("/lib/x86_64-linux-gnu/");
Paths.push_back("/usr/local/lib64/");
Paths.push_back("/usr/lib64/");
Paths.push_back("/lib64/");
#endif
#else
llvm::SmallString<1024> Buf;
platform::Popen("LD_DEBUG=libs LD_PRELOAD=DOESNOTEXIST ls", Buf, true);
const llvm::StringRef Result = Buf.str();
const std::size_t NPos = std::string::npos;
const std::size_t LD = Result.find("(LD_LIBRARY_PATH)");
std::size_t From = Result.find("search path=", LD == NPos ? 0 : LD);
if (From != NPos) {
const std::size_t To = Result.find("(system search path)", From);
if (To != NPos) {
From += 12;
std::string SysPath = Result.substr(From, To-From);
SysPath.erase(std::remove_if(SysPath.begin(), SysPath.end(), isspace),
SysPath.end());
llvm::SmallVector<llvm::StringRef, 10> CurPaths;
SplitPaths(SysPath, CurPaths);
for (const auto& Path : CurPaths)
Paths.push_back(Path.str());
}
}
#endif
return true;
}