| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1 | //===-- OCamlLanguage.cpp ----------------------------------------*- C++ |
| 2 | //-*-===// |
| Tamas Berghammer | 00adc41 | 2016-08-02 11:15:55 +0000 | [diff] [blame] | 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file is distributed under the University of Illinois Open Source |
| 7 | // License. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | // C Includes |
| 12 | #include <string.h> |
| 13 | // C++ Includes |
| 14 | #include <functional> |
| 15 | #include <mutex> |
| 16 | |
| 17 | // Other libraries and framework includes |
| 18 | #include "llvm/ADT/StringRef.h" |
| 19 | |
| 20 | // Project includes |
| 21 | #include "OCamlLanguage.h" |
| Tamas Berghammer | 00adc41 | 2016-08-02 11:15:55 +0000 | [diff] [blame] | 22 | #include "lldb/Core/PluginManager.h" |
| 23 | #include "lldb/DataFormatters/DataVisualization.h" |
| 24 | #include "lldb/DataFormatters/FormattersHelpers.h" |
| 25 | #include "lldb/Symbol/OCamlASTContext.h" |
| Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 26 | #include "lldb/Utility/ConstString.h" |
| Tamas Berghammer | 00adc41 | 2016-08-02 11:15:55 +0000 | [diff] [blame] | 27 | |
| 28 | using namespace lldb; |
| 29 | using namespace lldb_private; |
| 30 | |
| Raphael Isemann | 566afa0 | 2018-08-02 00:30:15 +0000 | [diff] [blame^] | 31 | bool OCamlLanguage::IsSourceFile(llvm::StringRef file_path) const { |
| 32 | const auto suffixes = {".ml", ".mli"}; |
| 33 | for (auto suffix : suffixes) { |
| 34 | if (file_path.endswith_lower(suffix)) |
| 35 | return true; |
| 36 | } |
| 37 | return false; |
| 38 | } |
| 39 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 40 | void OCamlLanguage::Initialize() { |
| 41 | PluginManager::RegisterPlugin(GetPluginNameStatic(), "OCaml Language", |
| 42 | CreateInstance); |
| Tamas Berghammer | 00adc41 | 2016-08-02 11:15:55 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 45 | void OCamlLanguage::Terminate() { |
| 46 | PluginManager::UnregisterPlugin(CreateInstance); |
| Tamas Berghammer | 00adc41 | 2016-08-02 11:15:55 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 49 | lldb_private::ConstString OCamlLanguage::GetPluginNameStatic() { |
| 50 | static ConstString g_name("OCaml"); |
| 51 | return g_name; |
| Tamas Berghammer | 00adc41 | 2016-08-02 11:15:55 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | lldb_private::ConstString OCamlLanguage::GetPluginName() { |
| 55 | return GetPluginNameStatic(); |
| Tamas Berghammer | 00adc41 | 2016-08-02 11:15:55 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 58 | uint32_t OCamlLanguage::GetPluginVersion() { return 1; } |
| 59 | |
| 60 | Language *OCamlLanguage::CreateInstance(lldb::LanguageType language) { |
| 61 | if (language == eLanguageTypeOCaml) |
| 62 | return new OCamlLanguage(); |
| 63 | return nullptr; |
| Tamas Berghammer | 00adc41 | 2016-08-02 11:15:55 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 66 | bool OCamlLanguage::IsNilReference(ValueObject &valobj) { |
| 67 | if (!valobj.GetCompilerType().IsReferenceType()) |
| 68 | return false; |
| 69 | |
| 70 | // If we failed to read the value then it is not a nil reference. |
| 71 | return valobj.GetValueAsUnsigned(UINT64_MAX) == 0; |
| Tamas Berghammer | 00adc41 | 2016-08-02 11:15:55 +0000 | [diff] [blame] | 72 | } |