Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/Language/CPlusPlus/MSVCUndecoratedNameParser.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- MSVCUndecoratedNameParser.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 "MSVCUndecoratedNameParser.h"
10
11
#include <stack>
12
13
3
MSVCUndecoratedNameParser::MSVCUndecoratedNameParser(llvm::StringRef name) {
14
3
  std::size_t last_base_start = 0;
15
16
3
  std::stack<std::size_t> stack;
17
3
  unsigned int open_angle_brackets = 0;
18
104
  for (size_t i = 0; i < name.size(); 
i++101
) {
19
101
    switch (name[i]) {
20
5
    case '<':
21
      // Do not treat `operator<' and `operator<<' as templates
22
      // (sometimes they represented as `<' and `<<' in the name).
23
5
      if (i == last_base_start ||
24
5
          
(4
i == last_base_start + 14
&&
name[last_base_start] == '<'2
))
25
2
        break;
26
27
3
      stack.push(i);
28
3
      open_angle_brackets++;
29
30
3
      break;
31
3
    case '>':
32
3
      if (!stack.empty() && 
name[stack.top()] == '<'2
) {
33
2
        open_angle_brackets--;
34
2
        stack.pop();
35
2
      }
36
37
3
      break;
38
4
    case '`':
39
4
      stack.push(i);
40
41
4
      break;
42
4
    case '\'':
43
5
      while (!stack.empty()) {
44
5
        std::size_t top = stack.top();
45
5
        if (name[top] == '<')
46
1
          open_angle_brackets--;
47
48
5
        stack.pop();
49
50
5
        if (name[top] == '`')
51
4
          break;
52
5
      }
53
54
4
      break;
55
16
    case ':':
56
16
      if (open_angle_brackets)
57
0
        break;
58
16
      if (i == 0 || name[i - 1] != ':')
59
8
        break;
60
61
8
      m_specifiers.emplace_back(name.take_front(i - 1),
62
8
                                name.slice(last_base_start, i - 1));
63
64
8
      last_base_start = i + 1;
65
8
      break;
66
69
    default:
67
69
      break;
68
101
    }
69
101
  }
70
71
3
  m_specifiers.emplace_back(name, name.drop_front(last_base_start));
72
3
}
73
74
34.6k
bool MSVCUndecoratedNameParser::IsMSVCUndecoratedName(llvm::StringRef name) {
75
34.6k
  return name.contains('`');
76
34.6k
}
77
78
bool MSVCUndecoratedNameParser::ExtractContextAndIdentifier(
79
    llvm::StringRef name, llvm::StringRef &context,
80
3
    llvm::StringRef &identifier) {
81
3
  MSVCUndecoratedNameParser parser(name);
82
3
  llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs = parser.GetSpecifiers();
83
84
3
  std::size_t count = specs.size();
85
3
  identifier = count > 0 ? specs[count - 1].GetBaseName() : 
""0
;
86
3
  context = count > 1 ? specs[count - 2].GetFullName() : 
""0
;
87
88
3
  return count;
89
3
}
90
91
0
llvm::StringRef MSVCUndecoratedNameParser::DropScope(llvm::StringRef name) {
92
0
  MSVCUndecoratedNameParser parser(name);
93
0
  llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs = parser.GetSpecifiers();
94
0
  if (specs.empty())
95
0
    return "";
96
97
0
  return specs[specs.size() - 1].GetBaseName();
98
0
}