本文整理汇总了C++中Twine::toVector方法的典型用法代码示例。如果您正苦于以下问题:C++ Twine::toVector方法的具体用法?C++ Twine::toVector怎么用?C++ Twine::toVector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twine
的用法示例。
在下文中一共展示了Twine::toVector方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setName
void Value::setName(const Twine &NewName) {
// Fast path for common IRBuilder case of setName("") when there is no name.
if (NewName.isTriviallyEmpty() && !hasName())
return;
SmallString<256> NameData;
NewName.toVector(NameData);
const char *NameStr = NameData.data();
unsigned NameLen = NameData.size();
// Name isn't changing?
if (getName() == StringRef(NameStr, NameLen))
return;
assert(getType() != Type::getVoidTy(getContext()) &&
"Cannot assign a name to void values!");
// Get the symbol table to update for this object.
ValueSymbolTable *ST;
if (getSymTab(this, ST))
return; // Cannot set a name on this value (e.g. constant).
if (!ST) { // No symbol table to update? Just do the change.
if (NameLen == 0) {
// Free the name for this value.
Name->Destroy();
Name = 0;
return;
}
if (Name)
Name->Destroy();
// NOTE: Could optimize for the case the name is shrinking to not deallocate
// then reallocated.
// Create the new name.
Name = ValueName::Create(NameStr, NameStr+NameLen);
Name->setValue(this);
return;
}
// NOTE: Could optimize for the case the name is shrinking to not deallocate
// then reallocated.
if (hasName()) {
// Remove old name.
ST->removeValueName(Name);
Name->Destroy();
Name = 0;
if (NameLen == 0)
return;
}
// Name is changing to something new.
Name = ST->createValueName(StringRef(NameStr, NameLen), this);
}
示例2: native
void native(const Twine &path, SmallVectorImpl<char> &result, Style style) {
assert((!path.isSingleStringRef() ||
path.getSingleStringRef().data() != result.data()) &&
"path and result are not allowed to overlap!");
// Clear result.
result.clear();
path.toVector(result);
native(result, style);
}
示例3: error_code
ErrorOr<Entry *> VFSFromYAML::lookupPath(const Twine &Path_) {
SmallString<256> Path;
Path_.toVector(Path);
// Handle relative paths
if (error_code EC = sys::fs::make_absolute(Path))
return EC;
if (Path.empty())
return error_code(errc::invalid_argument, system_category());
sys::path::const_iterator Start = sys::path::begin(Path);
sys::path::const_iterator End = sys::path::end(Path);
for (std::vector<Entry *>::iterator I = Roots.begin(), E = Roots.end();
I != E; ++I) {
ErrorOr<Entry *> Result = lookupPath(Start, End, *I);
if (Result || Result.getError() != errc::no_such_file_or_directory)
return Result;
}
return error_code(errc::no_such_file_or_directory, system_category());
}
示例4: EmitRawText
void MCStreamer::EmitRawText(const Twine &T) {
SmallString<128> Str;
T.toVector(Str);
EmitRawText(Str.str());
}
示例5: error_code
static std::error_code createUniqueEntity(const Twine &Model, int &ResultFD,
SmallVectorImpl<char> &ResultPath,
bool MakeAbsolute, unsigned Mode,
FSEntity Type) {
SmallString<128> ModelStorage;
Model.toVector(ModelStorage);
if (MakeAbsolute) {
// Make model absolute by prepending a temp directory if it's not already.
if (!sys::path::is_absolute(Twine(ModelStorage))) {
SmallString<128> TDir;
sys::path::system_temp_directory(true, TDir);
sys::path::append(TDir, Twine(ModelStorage));
ModelStorage.swap(TDir);
}
}
// From here on, DO NOT modify model. It may be needed if the randomly chosen
// path already exists.
ResultPath = ModelStorage;
// Null terminate.
ResultPath.push_back(0);
ResultPath.pop_back();
retry_random_path:
// Replace '%' with random chars.
for (unsigned i = 0, e = ModelStorage.size(); i != e; ++i) {
if (ModelStorage[i] == '%')
ResultPath[i] = "0123456789abcdef"[sys::Process::GetRandomNumber() & 15];
}
// Try to open + create the file.
switch (Type) {
case FS_File: {
if (std::error_code EC =
sys::fs::openFileForWrite(Twine(ResultPath.begin()), ResultFD,
sys::fs::F_RW | sys::fs::F_Excl, Mode)) {
if (EC == errc::file_exists)
goto retry_random_path;
return EC;
}
return std::error_code();
}
case FS_Name: {
std::error_code EC =
sys::fs::access(ResultPath.begin(), sys::fs::AccessMode::Exist);
if (EC == errc::no_such_file_or_directory)
return std::error_code();
if (EC)
return EC;
goto retry_random_path;
}
case FS_Dir: {
if (std::error_code EC =
sys::fs::create_directory(ResultPath.begin(), false)) {
if (EC == errc::file_exists)
goto retry_random_path;
return EC;
}
return std::error_code();
}
}
llvm_unreachable("Invalid Type");
}
示例6: error_code
static std::error_code
createUniqueEntity(const Twine &Model, int &ResultFD,
SmallVectorImpl<char> &ResultPath, bool MakeAbsolute,
unsigned Mode, FSEntity Type,
sys::fs::OpenFlags Flags = sys::fs::OF_None) {
SmallString<128> ModelStorage;
Model.toVector(ModelStorage);
if (MakeAbsolute) {
// Make model absolute by prepending a temp directory if it's not already.
if (!sys::path::is_absolute(Twine(ModelStorage))) {
SmallString<128> TDir;
sys::path::system_temp_directory(true, TDir);
sys::path::append(TDir, Twine(ModelStorage));
ModelStorage.swap(TDir);
}
}
// From here on, DO NOT modify model. It may be needed if the randomly chosen
// path already exists.
ResultPath = ModelStorage;
// Null terminate.
ResultPath.push_back(0);
ResultPath.pop_back();
// Limit the number of attempts we make, so that we don't infinite loop. E.g.
// "permission denied" could be for a specific file (so we retry with a
// different name) or for the whole directory (retry would always fail).
// Checking which is racy, so we try a number of times, then give up.
std::error_code EC;
for (int Retries = 128; Retries > 0; --Retries) {
// Replace '%' with random chars.
for (unsigned i = 0, e = ModelStorage.size(); i != e; ++i) {
if (ModelStorage[i] == '%')
ResultPath[i] =
"0123456789abcdef"[sys::Process::GetRandomNumber() & 15];
}
// Try to open + create the file.
switch (Type) {
case FS_File: {
EC = sys::fs::openFileForReadWrite(Twine(ResultPath.begin()), ResultFD,
sys::fs::CD_CreateNew, Flags, Mode);
if (EC) {
// errc::permission_denied happens on Windows when we try to open a file
// that has been marked for deletion.
if (EC == errc::file_exists || EC == errc::permission_denied)
continue;
return EC;
}
return std::error_code();
}
case FS_Name: {
EC = sys::fs::access(ResultPath.begin(), sys::fs::AccessMode::Exist);
if (EC == errc::no_such_file_or_directory)
return std::error_code();
if (EC)
return EC;
continue;
}
case FS_Dir: {
EC = sys::fs::create_directory(ResultPath.begin(), false);
if (EC) {
if (EC == errc::file_exists)
continue;
return EC;
}
return std::error_code();
}
}
llvm_unreachable("Invalid Type");
}
return EC;
}