| 1 | //===-- ObjCPlusPlusLanguage.cpp ------------------------------------------===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "ObjCPlusPlusLanguage.h" |
| 10 | |
| 11 | #include "lldb/Core/PluginManager.h" |
| 12 | #include "lldb/Utility/ConstString.h" |
| 13 | |
| 14 | using namespace lldb; |
| 15 | using namespace lldb_private; |
| 16 | |
| 17 | LLDB_PLUGIN_DEFINE(ObjCPlusPlusLanguage) |
| 18 | |
| 19 | bool ObjCPlusPlusLanguage::IsSourceFile(llvm::StringRef file_path) const { |
| 20 | const auto suffixes = {".h", ".mm"}; |
| 21 | for (auto suffix : suffixes) { |
| 22 | if (file_path.ends_with_insensitive(Suffix: suffix)) |
| 23 | return true; |
| 24 | } |
| 25 | return false; |
| 26 | } |
| 27 | |
| 28 | void ObjCPlusPlusLanguage::Initialize() { |
| 29 | PluginManager::RegisterPlugin(name: GetPluginNameStatic(), description: "Objective-C++ Language", |
| 30 | create_callback: CreateInstance); |
| 31 | } |
| 32 | |
| 33 | void ObjCPlusPlusLanguage::Terminate() { |
| 34 | PluginManager::UnregisterPlugin(create_callback: CreateInstance); |
| 35 | } |
| 36 | |
| 37 | // Static Functions |
| 38 | Language *ObjCPlusPlusLanguage::CreateInstance(lldb::LanguageType language) { |
| 39 | switch (language) { |
| 40 | case lldb::eLanguageTypeObjC_plus_plus: |
| 41 | return new ObjCPlusPlusLanguage(); |
| 42 | default: |
| 43 | return nullptr; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | std::optional<bool> |
| 48 | ObjCPlusPlusLanguage::GetBooleanFromString(llvm::StringRef str) const { |
| 49 | return llvm::StringSwitch<std::optional<bool>>(str) |
| 50 | .Cases(S0: "true", S1: "YES", Value: {true}) |
| 51 | .Cases(S0: "false", S1: "NO", Value: {false}) |
| 52 | .Default(Value: {}); |
| 53 | } |
| 54 |
