11
11
#include " lldb/Target/Target.h"
12
12
13
13
#include " llvm/ADT/SmallVector.h"
14
+ #include " llvm/ADT/StringExtras.h"
14
15
#include " llvm/ADT/StringRef.h"
15
16
#include " llvm/Support/Error.h"
16
17
@@ -31,62 +32,35 @@ Expression::Expression(ExecutionContextScope &exe_scope)
31
32
assert (m_target_wp.lock ());
32
33
}
33
34
34
- // / Returns the components of the specified function call label.
35
- // /
36
- // / The format of \c label is described in \c FunctionCallLabel.
37
- // / The label prefix is not one of the components.
38
- static llvm::Expected<llvm::SmallVector<llvm::StringRef, 3 >>
39
- splitFunctionCallLabel (llvm::StringRef label) {
40
- if (!label.consume_front (FunctionCallLabelPrefix))
41
- return llvm::createStringError (
42
- " expected function call label prefix not found." );
43
- if (!label.consume_front (" :" ))
44
- return llvm::createStringError (
45
- " expected ':' as the first character after prefix." );
46
-
47
- auto sep1 = label.find_first_of (" :" );
48
- if (sep1 == llvm::StringRef::npos)
49
- return llvm::createStringError (" no ':' separator found." );
50
-
51
- auto sep2 = label.find_first_of (" :" , sep1 + 1 );
52
- if (sep2 == llvm::StringRef::npos)
53
- return llvm::createStringError (" only single ':' separator found." );
54
-
55
- llvm::SmallVector<llvm::StringRef, 3 > components;
56
- components.push_back (label.slice (0 , sep1));
57
- components.push_back (label.slice (sep1 + 1 , sep2));
58
- components.push_back (label.slice (sep2 + 1 , llvm::StringRef::npos));
59
-
60
- return components;
61
- }
62
-
63
35
llvm::Expected<FunctionCallLabel>
64
36
lldb_private::FunctionCallLabel::fromString (llvm::StringRef label) {
65
- auto components_or_err = splitFunctionCallLabel (label);
66
- if (!components_or_err)
67
- return llvm::joinErrors (
68
- llvm::createStringError (" failed to split function call label '%s'" ,
69
- label.data ()),
70
- components_or_err.takeError ());
37
+ llvm::SmallVector<llvm::StringRef, 4 > components;
38
+ label.split (components, " :" , /* MaxSplit=*/ 3 );
39
+
40
+ if (components.size () != 4 )
41
+ return llvm::createStringError (" malformed function call label." );
71
42
72
- const auto &components = *components_or_err;
43
+ if (components[0 ] != FunctionCallLabelPrefix)
44
+ return llvm::createStringError (llvm::formatv (
45
+ " expected function call label prefix '{0}' but found '{1}' instead." ,
46
+ FunctionCallLabelPrefix, components[0 ]));
73
47
74
- llvm::StringRef module_label = components[0 ];
75
- llvm::StringRef die_label = components[1 ];
48
+ llvm::StringRef module_label = components[1 ];
49
+ llvm::StringRef die_label = components[2 ];
76
50
77
51
lldb::user_id_t module_id = 0 ;
78
- if (module_label. consumeInteger ( 0 , module_id))
52
+ if (! llvm::to_integer (module_label , module_id))
79
53
return llvm::createStringError (
80
- llvm::formatv (" failed to parse module ID from '{0}'." , components[ 0 ] ));
54
+ llvm::formatv (" failed to parse module ID from '{0}'." , module_label ));
81
55
82
56
lldb::user_id_t die_id;
83
- if (die_label. consumeInteger ( /* Radix= */ 0 , die_id))
57
+ if (! llvm::to_integer (die_label , die_id))
84
58
return llvm::createStringError (
85
- llvm::formatv (" failed to parse symbol ID from '{0}'." , components[ 1 ] ));
59
+ llvm::formatv (" failed to parse symbol ID from '{0}'." , die_label ));
86
60
87
61
return FunctionCallLabel{/* .module_id=*/ module_id,
88
62
/* .symbol_id=*/ die_id,
89
- /* .lookup_name=*/ components[2 ]};
63
+ /* .lookup_name=*/ components[3 ]};
90
64
}
91
65
92
66
std::string lldb_private::FunctionCallLabel::toString () const {
0 commit comments