本文整理汇总了C++中llvm::StringRef::startswith方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRef::startswith方法的具体用法?C++ StringRef::startswith怎么用?C++ StringRef::startswith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类llvm::StringRef
的用法示例。
在下文中一共展示了StringRef::startswith方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doesNoDiscardMacroExist
static bool doesNoDiscardMacroExist(ASTContext &Context,
const llvm::StringRef &MacroId) {
// Don't check for the Macro existence if we are using an attribute
// either a C++17 standard attribute or pre C++17 syntax
if (MacroId.startswith("[[") || MacroId.startswith("__attribute__"))
return true;
// Otherwise look up the macro name in the context to see if its defined.
return Context.Idents.get(MacroId).hasMacroDefinition();
}
示例2: if
lldb::SymbolType
ObjectFile::GetSymbolTypeFromName(llvm::StringRef name,
lldb::SymbolType symbol_type_hint) {
if (!name.empty()) {
if (name.startswith("_T")) {
// Swift
if (name.startswith("_TM"))
return lldb::eSymbolTypeMetadata;
if (name.startswith("_TWvd"))
return lldb::eSymbolTypeIVarOffset;
} else if (name.startswith("_OBJC_")) {
// ObjC
if (name.startswith("_OBJC_CLASS_$_"))
return lldb::eSymbolTypeObjCClass;
if (name.startswith("_OBJC_METACLASS_$_"))
return lldb::eSymbolTypeObjCMetaClass;
if (name.startswith("_OBJC_IVAR_$_"))
return lldb::eSymbolTypeObjCIVar;
} else if (name.startswith(".objc_class_name_")) {
// ObjC v1
return lldb::eSymbolTypeObjCClass;
}
}
return symbol_type_hint;
}
示例3: 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();
}
示例4: 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;
}
示例5: Scheme
URI::URI(llvm::StringRef Scheme, llvm::StringRef Authority,
llvm::StringRef Body)
: Scheme(Scheme), Authority(Authority), Body(Body) {
assert(!Scheme.empty());
assert((Authority.empty() || Body.startswith("/")) &&
"URI body must start with '/' when authority is present.");
}
示例6: 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));
}
}
示例7: replacementToEdit
llvm::Optional<TextEdit>
IncludeInserter::insert(llvm::StringRef VerbatimHeader) const {
llvm::Optional<TextEdit> Edit = None;
if (auto Insertion = Inserter.insert(VerbatimHeader.trim("\"<>"),
VerbatimHeader.startswith("<")))
Edit = replacementToEdit(Code, *Insertion);
return Edit;
}
示例8: report
void AutoloadCallback::report(clang::SourceLocation l, llvm::StringRef name,
llvm::StringRef header) {
Sema& sema= m_Interpreter->getSema();
unsigned id
= sema.getDiagnostics().getCustomDiagID (DiagnosticsEngine::Level::Warning,
"Note: '%0' can be found in %1");
/* unsigned idn //TODO: To be enabled after we have a way to get the full path
= sema.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Level::Note,
"Type : %0 , Full Path: %1")*/;
if (header.startswith(llvm::StringRef(annoTag, lenAnnoTag)))
sema.Diags.Report(l, id) << name << header.drop_front(lenAnnoTag);
}
示例9: IsValidBasename
static bool IsValidBasename(const llvm::StringRef &basename) {
// Check that the basename matches with the following regular expression or is
// an operator name:
// "^~?([A-Za-z_][A-Za-z_0-9]*)(<.*>)?$"
// We are using a hand written implementation because it is significantly more
// efficient then
// using the general purpose regular expression library.
size_t idx = 0;
if (basename.size() > 0 && basename[0] == '~')
idx = 1;
if (basename.size() <= idx)
return false; // Empty string or "~"
if (!std::isalpha(basename[idx]) && basename[idx] != '_')
return false; // First charater (after removing the possible '~'') isn't in
// [A-Za-z_]
// Read all characters matching [A-Za-z_0-9]
++idx;
while (idx < basename.size()) {
if (!std::isalnum(basename[idx]) && basename[idx] != '_')
break;
++idx;
}
// We processed all characters. It is a vaild basename.
if (idx == basename.size())
return true;
// Check for basename with template arguments
// TODO: Improve the quality of the validation with validating the template
// arguments
if (basename[idx] == '<' && basename.back() == '>')
return true;
// Check if the basename is a vaild C++ operator name
if (!basename.startswith("operator"))
return false;
static RegularExpression g_operator_regex(
llvm::StringRef("^(operator)( "
"?)([A-Za-z_][A-Za-z_0-9]*|\\(\\)|"
"\\[\\]|[\\^<>=!\\/"
"*+-]+)(<.*>)?(\\[\\])?$"));
std::string basename_str(basename.str());
return g_operator_regex.Execute(basename_str, nullptr);
}
示例10: FileNotFound
bool MocPPCallbacks::FileNotFound(llvm::StringRef FileName, llvm::SmallVectorImpl< char >& RecoveryPath) {
if (FileName.endswith(".moc") || FileName.endswith("_moc.cpp") || FileName.startswith("moc_")) {
if (!PP.GetSuppressIncludeNotFoundError()) {
PP.SetSuppressIncludeNotFoundError(true);
IncludeNotFoundSupressed = true;
}
} else {
if (IncludeNotFoundSupressed) {
PP.SetSuppressIncludeNotFoundError(false);
IncludeNotFoundSupressed = false;
} else {
ShouldWarnHeaderNotFound = true;
}
}
return false;
}
示例11: 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;
}
示例12: isRefType
bool cocoa::isRefType(QualType RetTy, llvm::StringRef Prefix,
llvm::StringRef Name) {
// Recursively walk the typedef stack, allowing typedefs of reference types.
while (const TypedefType *TD = dyn_cast<TypedefType>(RetTy.getTypePtr())) {
llvm::StringRef TDName = TD->getDecl()->getIdentifier()->getName();
if (TDName.startswith(Prefix) && TDName.endswith("Ref"))
return true;
RetTy = TD->getDecl()->getUnderlyingType();
}
if (Name.empty())
return false;
// Is the type void*?
const PointerType* PT = RetTy->getAs<PointerType>();
if (!(PT->getPointeeType().getUnqualifiedType()->isVoidType()))
return false;
// Does the name start with the prefix?
return Name.startswith(Prefix);
}
示例13: normalizePath
std::string
DynamicLibraryManager::lookupLibrary(llvm::StringRef libStem) const {
llvm::SmallString<128> Absolute(libStem);
llvm::sys::fs::make_absolute(Absolute);
bool isAbsolute = libStem == Absolute;
// If it is an absolute path, don't try iterate over the paths.
if (isAbsolute) {
if (isSharedLib(libStem))
return normalizePath(libStem);
else
return "";
}
std::string foundName = lookupLibMaybeAddExt(libStem);
if (foundName.empty() && !libStem.startswith("lib")) {
// try with "lib" prefix:
foundName = lookupLibMaybeAddExt("lib" + libStem.str());
}
if (isSharedLib(foundName))
return normalizePath(foundName);
return "";
}
示例14: migrateInclude
void XCTMigrator::migrateInclude(llvm::StringRef Filename,
CharSourceRange FilenameRange,
SourceLocation HashLoc, bool isAngled) {
StringRef Parent = "SenTestingKit/";
if (!Filename.startswith(Parent))
return;
if (isFromSenTestInclude(HashLoc))
return;
edit::Commit commit(Editor);
StringRef HeaderName = Filename.substr(Parent.size());
llvm::StringMap<llvm::StringRef>::iterator I = IncludesMap.find(HeaderName);
if (I == IncludesMap.end() || I->second.empty()) {
commit.remove(CharSourceRange::getCharRange(HashLoc,FilenameRange.getEnd()));
} else {
SmallString<128> NewInclude;
NewInclude.push_back(isAngled ? '<' : '"');
NewInclude += "XCTest/";
NewInclude += I->second;
NewInclude.push_back(isAngled ? '>' : '"');
commit.replace(FilenameRange, NewInclude.str());
}
Editor.commit(commit);
}
示例15: first
std::vector<find_all_symbols::SymbolInfo>
SymbolIndexManager::search(llvm::StringRef Identifier,
bool IsNestedSearch) const {
// The identifier may be fully qualified, so split it and get all the context
// names.
llvm::SmallVector<llvm::StringRef, 8> Names;
Identifier.split(Names, "::");
bool IsFullyQualified = false;
if (Identifier.startswith("::")) {
Names.erase(Names.begin()); // Drop first (empty) element.
IsFullyQualified = true;
}
// As long as we don't find a result keep stripping name parts from the end.
// This is to support nested classes which aren't recorded in the database.
// Eventually we will either hit a class (namespaces aren't in the database
// either) and can report that result.
bool TookPrefix = false;
std::vector<clang::find_all_symbols::SymbolInfo> MatchedSymbols;
do {
std::vector<clang::find_all_symbols::SymbolInfo> Symbols;
for (const auto &DB : SymbolIndices) {
auto Res = DB->search(Names.back().str());
Symbols.insert(Symbols.end(), Res.begin(), Res.end());
}
DEBUG(llvm::dbgs() << "Searching " << Names.back() << "... got "
<< Symbols.size() << " results...\n");
for (const auto &Symbol : Symbols) {
// Match the identifier name without qualifier.
if (Symbol.getName() == Names.back()) {
bool IsMatched = true;
auto SymbolContext = Symbol.getContexts().begin();
auto IdentiferContext = Names.rbegin() + 1; // Skip identifier name.
// Match the remaining context names.
while (IdentiferContext != Names.rend() &&
SymbolContext != Symbol.getContexts().end()) {
if (SymbolContext->second == *IdentiferContext) {
++IdentiferContext;
++SymbolContext;
} else if (SymbolContext->first ==
find_all_symbols::SymbolInfo::ContextType::EnumDecl) {
// Skip non-scoped enum context.
++SymbolContext;
} else {
IsMatched = false;
break;
}
}
// If the name was qualified we only want to add results if we evaluated
// all contexts.
if (IsFullyQualified)
IsMatched &= (SymbolContext == Symbol.getContexts().end());
// FIXME: Support full match. At this point, we only find symbols in
// database which end with the same contexts with the identifier.
if (IsMatched && IdentiferContext == Names.rend()) {
// If we're in a situation where we took a prefix but the thing we
// found couldn't possibly have a nested member ignore it.
if (TookPrefix &&
(Symbol.getSymbolKind() == SymbolInfo::SymbolKind::Function ||
Symbol.getSymbolKind() == SymbolInfo::SymbolKind::Variable ||
Symbol.getSymbolKind() ==
SymbolInfo::SymbolKind::EnumConstantDecl ||
Symbol.getSymbolKind() == SymbolInfo::SymbolKind::Macro))
continue;
MatchedSymbols.push_back(Symbol);
}
}
}
Names.pop_back();
TookPrefix = true;
} while (MatchedSymbols.empty() && !Names.empty() && IsNestedSearch);
rankByPopularity(MatchedSymbols);
return MatchedSymbols;
}