Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/REPL/Clang/ClangREPL.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- ClangREPL.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 "ClangREPL.h"
10
#include "lldb/Core/Debugger.h"
11
#include "lldb/Core/PluginManager.h"
12
#include "lldb/Expression/ExpressionVariable.h"
13
14
using namespace lldb_private;
15
16
LLDB_PLUGIN_DEFINE(ClangREPL)
17
18
ClangREPL::ClangREPL(lldb::LanguageType language, Target &target)
19
    : REPL(eKindClang, target), m_language(language),
20
0
      m_implicit_expr_result_regex("\\$[0-9]+") {}
21
22
0
ClangREPL::~ClangREPL() {}
23
24
3.44k
void ClangREPL::Initialize() {
25
3.44k
  LanguageSet languages;
26
  // FIXME: There isn't a way to ask CPlusPlusLanguage and ObjCLanguage for
27
  // a list of languages they support.
28
3.44k
  languages.Insert(lldb::LanguageType::eLanguageTypeC);
29
3.44k
  languages.Insert(lldb::LanguageType::eLanguageTypeC89);
30
3.44k
  languages.Insert(lldb::LanguageType::eLanguageTypeC99);
31
3.44k
  languages.Insert(lldb::LanguageType::eLanguageTypeC11);
32
3.44k
  languages.Insert(lldb::LanguageType::eLanguageTypeC_plus_plus);
33
3.44k
  languages.Insert(lldb::LanguageType::eLanguageTypeC_plus_plus_03);
34
3.44k
  languages.Insert(lldb::LanguageType::eLanguageTypeC_plus_plus_11);
35
3.44k
  languages.Insert(lldb::LanguageType::eLanguageTypeC_plus_plus_14);
36
3.44k
  languages.Insert(lldb::LanguageType::eLanguageTypeObjC);
37
3.44k
  languages.Insert(lldb::LanguageType::eLanguageTypeObjC_plus_plus);
38
3.44k
  PluginManager::RegisterPlugin(GetPluginNameStatic(), "C language REPL",
39
3.44k
                                &CreateInstance, languages);
40
3.44k
}
41
42
3.43k
void ClangREPL::Terminate() {
43
3.43k
  PluginManager::UnregisterPlugin(&CreateInstance);
44
3.43k
}
45
46
lldb::REPLSP ClangREPL::CreateInstance(Status &error,
47
                                       lldb::LanguageType language,
48
                                       Debugger *debugger, Target *target,
49
1
                                       const char *repl_options) {
50
  // Creating a dummy target if only a debugger is given isn't implemented yet.
51
1
  if (!target) {
52
1
    error.SetErrorString("must have a target to create a REPL");
53
1
    return nullptr;
54
1
  }
55
0
  lldb::REPLSP result = std::make_shared<ClangREPL>(language, *target);
56
0
  target->SetREPL(language, result);
57
0
  error = Status();
58
0
  return result;
59
1
}
60
61
0
Status ClangREPL::DoInitialization() { return Status(); }
62
63
0
ConstString ClangREPL::GetSourceFileBasename() {
64
0
  return ConstString("repl.c");
65
0
}
66
67
0
const char *ClangREPL::GetAutoIndentCharacters() { return "  "; }
68
69
0
bool ClangREPL::SourceIsComplete(const std::string &source) {
70
  // FIXME: There isn't a good way to know if the input source is complete or
71
  // not, so just say that every single REPL line is ready to be parsed.
72
0
  return !source.empty();
73
0
}
74
75
lldb::offset_t ClangREPL::GetDesiredIndentation(const StringList &lines,
76
                                                int cursor_position,
77
0
                                                int tab_size) {
78
  // FIXME: Not implemented.
79
0
  return LLDB_INVALID_OFFSET;
80
0
}
81
82
0
lldb::LanguageType ClangREPL::GetLanguage() { return m_language; }
83
84
bool ClangREPL::PrintOneVariable(Debugger &debugger,
85
                                 lldb::StreamFileSP &output_sp,
86
                                 lldb::ValueObjectSP &valobj_sp,
87
0
                                 ExpressionVariable *var) {
88
  // If a ExpressionVariable was passed, check first if that variable is just
89
  // an automatically created expression result. These variables are already
90
  // printed by the REPL so this is done to prevent printing the variable twice.
91
0
  if (var) {
92
0
    if (m_implicit_expr_result_regex.Execute(var->GetName().GetStringRef()))
93
0
      return true;
94
0
  }
95
0
  valobj_sp->Dump(*output_sp);
96
0
  return true;
97
0
}
98
99
void ClangREPL::CompleteCode(const std::string &current_code,
100
0
                             CompletionRequest &request) {
101
  // Not implemented.
102
0
}