Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
Line
Count
Source (jump to first uncovered line)
1
//===-- ObjCLanguage.h ------------------------------------------*- C++ -*-===//
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
#ifndef LLDB_SOURCE_PLUGINS_LANGUAGE_OBJC_OBJCLANGUAGE_H
10
#define LLDB_SOURCE_PLUGINS_LANGUAGE_OBJC_OBJCLANGUAGE_H
11
12
#include <cstring>
13
#include <vector>
14
15
#include "Plugins/Language/ClangCommon/ClangHighlighter.h"
16
#include "lldb/Target/Language.h"
17
#include "lldb/Utility/ConstString.h"
18
#include "lldb/lldb-private.h"
19
20
namespace lldb_private {
21
22
class ObjCLanguage : public Language {
23
  ClangHighlighter m_highlighter;
24
25
public:
26
  class MethodName {
27
  public:
28
    enum Type { eTypeUnspecified, eTypeClassMethod, eTypeInstanceMethod };
29
30
0
    MethodName() : m_full(), m_class(), m_category(), m_selector() {}
31
32
    MethodName(const char *name, bool strict)
33
        : m_full(), m_class(), m_category(), m_selector(),
34
96.9M
          m_type(eTypeUnspecified), m_category_is_valid(false) {
35
96.9M
      SetName(name, strict);
36
96.9M
    }
37
    MethodName(llvm::StringRef name, bool strict)
38
        : m_full(), m_class(), m_category(), m_selector(),
39
65.8k
          m_type(eTypeUnspecified), m_category_is_valid(false) {
40
65.8k
      SetName(name, strict);
41
65.8k
    }
42
43
    void Clear();
44
45
222M
    bool IsValid(bool strict) const {
46
      // If "strict" is true, the name must have everything specified including
47
      // the leading "+" or "-" on the method name
48
222M
      if (strict && 
m_type == eTypeUnspecified142k
)
49
140k
        return false;
50
      // Other than that, m_full will only be filled in if the objective C
51
      // name is valid.
52
222M
      return (bool)m_full;
53
222M
    }
54
55
9.07M
    bool HasCategory() { return !GetCategory().IsEmpty(); }
56
57
18.1M
    Type GetType() const { return m_type; }
58
59
12
    ConstString GetFullName() const { return m_full; }
60
61
    ConstString GetFullNameWithoutCategory(bool empty_if_no_category);
62
63
    bool SetName(const char *name, bool strict);
64
    bool SetName(llvm::StringRef name, bool strict);
65
66
    ConstString GetClassName();
67
68
    ConstString GetClassNameWithCategory();
69
70
    ConstString GetCategory();
71
72
    ConstString GetSelector();
73
74
  protected:
75
    ConstString
76
        m_full; // Full name:   "+[NSString(my_additions) myStringWithCString:]"
77
    ConstString m_class; // Class name:  "NSString"
78
    ConstString
79
        m_class_category;   // Class with category: "NSString(my_additions)"
80
    ConstString m_category; // Category:    "my_additions"
81
    ConstString m_selector; // Selector:    "myStringWithCString:"
82
    Type m_type = eTypeUnspecified;
83
    bool m_category_is_valid = false;
84
  };
85
86
1.02k
  ObjCLanguage() = default;
87
88
0
  ~ObjCLanguage() override = default;
89
90
150k
  lldb::LanguageType GetLanguageType() const override {
91
150k
    return lldb::eLanguageTypeObjC;
92
150k
  }
93
94
  // Get all possible names for a method. Examples:
95
  // If method_name is "+[NSString(my_additions) myStringWithCString:]"
96
  //   variant_names[0] => "+[NSString myStringWithCString:]"
97
  // If name is specified without the leading '+' or '-' like
98
  // "[NSString(my_additions) myStringWithCString:]"
99
  //  variant_names[0] => "+[NSString(my_additions) myStringWithCString:]"
100
  //  variant_names[1] => "-[NSString(my_additions) myStringWithCString:]"
101
  //  variant_names[2] => "+[NSString myStringWithCString:]"
102
  //  variant_names[3] => "-[NSString myStringWithCString:]"
103
  // Also returns the FunctionNameType of each possible name.
104
  std::vector<Language::MethodNameVariant>
105
  GetMethodNameVariants(ConstString method_name) const override;
106
107
  bool SymbolNameFitsToLanguage(Mangled mangled) const override;
108
109
  lldb::TypeCategoryImplSP GetFormatters() override;
110
111
  std::vector<ConstString>
112
  GetPossibleFormattersMatches(ValueObject &valobj,
113
                               lldb::DynamicValueType use_dynamic) override;
114
115
  std::unique_ptr<TypeScavenger> GetTypeScavenger() override;
116
117
  bool GetFormatterPrefixSuffix(ValueObject &valobj, ConstString type_hint,
118
                                std::string &prefix,
119
                                std::string &suffix) override;
120
121
  bool IsNilReference(ValueObject &valobj) override;
122
123
48
  llvm::StringRef GetNilReferenceSummaryString() override { return "nil"; }
124
125
  bool IsSourceFile(llvm::StringRef file_path) const override;
126
127
2.29k
  const Highlighter *GetHighlighter() const override { return &m_highlighter; }
128
129
  // Static Functions
130
  static void Initialize();
131
132
  static void Terminate();
133
134
  static lldb_private::Language *CreateInstance(lldb::LanguageType language);
135
136
4.11k
  static llvm::StringRef GetPluginNameStatic() { return "objc"; }
137
138
121k
  static bool IsPossibleObjCMethodName(const char *name) {
139
121k
    if (!name)
140
0
      return false;
141
121k
    bool starts_right = (name[0] == '+' || 
name[0] == '-'115k
) &&
name[1] == '['43.7k
;
142
121k
    bool ends_right = (name[strlen(name) - 1] == ']');
143
121k
    return (starts_right && 
ends_right43.7k
);
144
121k
  }
145
146
4.45k
  static bool IsPossibleObjCSelector(const char *name) {
147
4.45k
    if (!name)
148
0
      return false;
149
150
4.45k
    if (strchr(name, ':') == nullptr)
151
3.37k
      return true;
152
1.07k
    else if (name[strlen(name) - 1] == ':')
153
6
      return true;
154
1.07k
    else
155
1.07k
      return false;
156
4.45k
  }
157
158
  // PluginInterface protocol
159
646
  llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
160
};
161
162
} // namespace lldb_private
163
164
#endif // LLDB_SOURCE_PLUGINS_LANGUAGE_OBJC_OBJCLANGUAGE_H