Error OptionValueArch::SetValueFromString (llvm::StringRef value, VarSetOperationType op) { Error error; switch (op) { case eVarSetOperationClear: Clear(); NotifyValueChanged(); break; case eVarSetOperationReplace: case eVarSetOperationAssign: { std::string value_str = value.trim().str(); if (m_current_value.SetTriple (value_str.c_str())) { m_value_was_set = true; NotifyValueChanged(); } else error.SetErrorStringWithFormat("unsupported architecture '%s'", value_str.c_str()); break; } case eVarSetOperationInsertBefore: case eVarSetOperationInsertAfter: case eVarSetOperationRemove: case eVarSetOperationAppend: case eVarSetOperationInvalid: error = OptionValue::SetValueFromString (value, op); break; } return error; }
Status OptionValueUInt64::SetValueFromString(llvm::StringRef value_ref, VarSetOperationType op) { Status error; switch (op) { case eVarSetOperationClear: Clear(); NotifyValueChanged(); break; case eVarSetOperationReplace: case eVarSetOperationAssign: { bool success = false; std::string value_str = value_ref.trim().str(); uint64_t value = StringConvert::ToUInt64(value_str.c_str(), 0, 0, &success); if (success) { m_value_was_set = true; m_current_value = value; NotifyValueChanged(); } else { error.SetErrorStringWithFormat("invalid uint64_t string value: '%s'", value_str.c_str()); } } break; case eVarSetOperationInsertBefore: case eVarSetOperationInsertAfter: case eVarSetOperationRemove: case eVarSetOperationAppend: case eVarSetOperationInvalid: error = OptionValue::SetValueFromString(value_ref, op); break; } return error; }
void MetaSema::actOnShellCommand(llvm::StringRef commandLine) const { llvm::StringRef trimmed(commandLine.trim(" \t\n\v\f\r ")); if (!trimmed.empty()) { int ret = std::system(trimmed.str().c_str()); (void) ret; // Silence warning unused return result of system. } }
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; }
Status OptionValueFormatEntity::SetValueFromString(llvm::StringRef value_str, VarSetOperationType op) { Status error; switch (op) { case eVarSetOperationClear: Clear(); NotifyValueChanged(); break; case eVarSetOperationReplace: case eVarSetOperationAssign: { // Check if the string starts with a quote character after removing leading // and trailing spaces. If it does start with a quote character, make sure // it ends with the same quote character and remove the quotes before we // parse the format string. If the string doesn't start with a quote, leave // the string alone and parse as is. llvm::StringRef trimmed_value_str = value_str.trim(); if (!trimmed_value_str.empty()) { const char first_char = trimmed_value_str[0]; if (first_char == '"' || first_char == '\'') { const size_t trimmed_len = trimmed_value_str.size(); if (trimmed_len == 1 || value_str[trimmed_len - 1] != first_char) { error.SetErrorStringWithFormat("mismatched quotes"); return error; } value_str = trimmed_value_str.substr(1, trimmed_len - 2); } } FormatEntity::Entry entry; error = FormatEntity::Parse(value_str, entry); if (error.Success()) { m_current_entry = std::move(entry); m_current_format = value_str; m_value_was_set = true; NotifyValueChanged(); } } break; case eVarSetOperationInsertBefore: case eVarSetOperationInsertAfter: case eVarSetOperationRemove: case eVarSetOperationAppend: case eVarSetOperationInvalid: error = OptionValue::SetValueFromString(value_str, op); break; } return error; }
Error OptionValueEnumeration::SetValueFromString(llvm::StringRef value, VarSetOperationType op) { Error error; switch (op) { case eVarSetOperationClear: Clear(); NotifyValueChanged(); break; case eVarSetOperationReplace: case eVarSetOperationAssign: { ConstString const_enumerator_name(value.trim()); const EnumerationMapEntry *enumerator_entry = m_enumerations.FindFirstValueForName( const_enumerator_name.GetStringRef()); if (enumerator_entry) { m_current_value = enumerator_entry->value.value; NotifyValueChanged(); } else { StreamString error_strm; error_strm.Printf("invalid enumeration value '%s'", value.str().c_str()); const size_t count = m_enumerations.GetSize(); if (count) { error_strm.Printf(", valid values are: %s", m_enumerations.GetCStringAtIndex(0).str().c_str()); for (size_t i = 1; i < count; ++i) { error_strm.Printf(", %s", m_enumerations.GetCStringAtIndex(i).str().c_str()); } } error.SetErrorString(error_strm.GetData()); } break; } case eVarSetOperationInsertBefore: case eVarSetOperationInsertAfter: case eVarSetOperationRemove: case eVarSetOperationAppend: case eVarSetOperationInvalid: error = OptionValue::SetValueFromString(value, op); break; } return error; }
Error OptionValueFileSpec::SetValueFromString (llvm::StringRef value, VarSetOperationType op) { Error error; switch (op) { case eVarSetOperationClear: Clear (); NotifyValueChanged(); break; case eVarSetOperationReplace: case eVarSetOperationAssign: if (value.size() > 0) { // The setting value may have whitespace, double-quotes, or single-quotes around the file // path to indicate that internal spaces are not word breaks. Strip off any ws & quotes // from the start and end of the file path - we aren't doing any word // breaking here so // the quoting is unnecessary. NB this will cause a problem if someone tries to specify // a file path that legitimately begins or ends with a " or ' character, or whitespace. value = value.trim("\"' \t"); m_value_was_set = true; m_current_value.SetFile(value.str().c_str(), m_resolve); m_data_sp.reset(); m_data_mod_time.Clear(); NotifyValueChanged(); } else { error.SetErrorString("invalid value string"); } break; case eVarSetOperationInsertBefore: case eVarSetOperationInsertAfter: case eVarSetOperationRemove: case eVarSetOperationAppend: case eVarSetOperationInvalid: error = OptionValue::SetValueFromString (value, op); break; } return error; }
Status OptionValueLanguage::SetValueFromString(llvm::StringRef value, VarSetOperationType op) { Status error; switch (op) { case eVarSetOperationClear: Clear(); break; case eVarSetOperationReplace: case eVarSetOperationAssign: { ConstString lang_name(value.trim()); std::set<lldb::LanguageType> languages_for_types; std::set<lldb::LanguageType> languages_for_expressions; Language::GetLanguagesSupportingTypeSystems(languages_for_types, languages_for_expressions); LanguageType new_type = Language::GetLanguageTypeFromString(lang_name.GetStringRef()); if (new_type && languages_for_types.count(new_type)) { m_value_was_set = true; m_current_value = new_type; } else { StreamString error_strm; error_strm.Printf("invalid language type '%s', ", value.str().c_str()); error_strm.Printf("valid values are:\n"); for (lldb::LanguageType language : languages_for_types) { error_strm.Printf("%s%s%s", " ", Language::GetNameForLanguageType(language), "\n"); } error.SetErrorString(error_strm.GetString()); } } break; case eVarSetOperationInsertBefore: case eVarSetOperationInsertAfter: case eVarSetOperationRemove: case eVarSetOperationAppend: case eVarSetOperationInvalid: error = OptionValue::SetValueFromString(value, op); break; } return error; }
MetaSema::ActionResult MetaSema::actOnShellCommand(llvm::StringRef commandLine, Value* result) const { llvm::StringRef trimmed(commandLine.trim(" \t\n\v\f\r ")); if (!trimmed.empty()) { int ret = std::system(trimmed.str().c_str()); // Build the result clang::ASTContext& Ctx = m_Interpreter.getCI()->getASTContext(); if (result) { *result = Value(Ctx.IntTy, m_Interpreter); result->getAs<long long>() = ret; } return (ret == 0) ? AR_Success : AR_Failure; } if (result) *result = Value(); // nothing to run - should this be success or failure? return AR_Failure; }
MetaSema::ActionResult MetaSema::actOnShellCommand(llvm::StringRef commandLine, StoredValueRef* result) const { llvm::StringRef trimmed(commandLine.trim(" \t\n\v\f\r ")); if (!trimmed.empty()) { int ret = std::system(trimmed.str().c_str()); // Build the result clang::ASTContext& Ctx = m_Interpreter.getCI()->getASTContext(); llvm::GenericValue retGV; retGV.IntVal = llvm::APInt(sizeof(int) * 8, ret, true /*isSigned*/); Value V(retGV, Ctx.IntTy); if (result) *result = StoredValueRef::bitwiseCopy(Ctx, V); return (ret == 0) ? AR_Success : AR_Failure; } if (result) *result = StoredValueRef(); // nothing to run - should this be success or failure? return AR_Failure; }
Status OptionValueString::SetValueFromString(llvm::StringRef value, VarSetOperationType op) { Status error; std::string value_str = value.str(); value = value.trim(); if (value.size() > 0) { switch (value.front()) { case '"': case '\'': { if (value.size() <= 1 || value.back() != value.front()) { error.SetErrorString("mismatched quotes"); return error; } value = value.drop_front().drop_back(); } break; } value_str = value.str(); } switch (op) { case eVarSetOperationInvalid: case eVarSetOperationInsertBefore: case eVarSetOperationInsertAfter: case eVarSetOperationRemove: if (m_validator) { error = m_validator(value_str.c_str(), m_validator_baton); if (error.Fail()) return error; } error = OptionValue::SetValueFromString(value, op); break; case eVarSetOperationAppend: { std::string new_value(m_current_value); if (value.size() > 0) { if (m_options.Test(eOptionEncodeCharacterEscapeSequences)) { std::string str; Args::EncodeEscapeSequences(value_str.c_str(), str); new_value.append(str); } else new_value.append(value); } if (m_validator) { error = m_validator(new_value.c_str(), m_validator_baton); if (error.Fail()) return error; } m_current_value.assign(new_value); NotifyValueChanged(); } break; case eVarSetOperationClear: Clear(); NotifyValueChanged(); break; case eVarSetOperationReplace: case eVarSetOperationAssign: if (m_validator) { error = m_validator(value_str.c_str(), m_validator_baton); if (error.Fail()) return error; } m_value_was_set = true; if (m_options.Test(eOptionEncodeCharacterEscapeSequences)) { Args::EncodeEscapeSequences(value_str.c_str(), m_current_value); } else { SetCurrentValue(value_str); } NotifyValueChanged(); break; } return error; }