MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / stringToType

Function stringToType

pcsx2-qt/Debugger/SymbolTree/TypeString.cpp:10–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include "common/Pcsx2Types.h"
9
10std::unique_ptr<ccc::ast::Node> stringToType(std::string_view string, const ccc::SymbolDatabase& database, QString& error_out)
11{
12 if (string.empty())
13 return nullptr;
14
15 size_t i = string.size();
16
17 // Parse array subscripts and pointer characters.
18 std::vector<s32> components;
19 for (; i > 0; i--)
20 {
21 if (string[i - 1] == '*' || string[i - 1] == '&')
22 {
23 components.emplace_back(-string[i - 1]);
24 continue;
25 }
26
27 if (string[i - 1] != ']' || i < 2)
28 break;
29
30 size_t j = i - 1;
31 for (; j > 0; j--)
32 if (string[j - 1] < '0' || string[j - 1] > '9')
33 break;
34
35 if (string[j - 1] != '[')
36 break;
37
38 s32 element_count = atoi(&string[j]);
39 if (element_count < 0 || element_count > 1024 * 1024)
40 {
41 error_out = QCoreApplication::translate("TypeString", "Invalid array subscript.");
42 return nullptr;
43 }
44
45 components.emplace_back(element_count);
46
47 i = j;
48 }
49
50 // Lookup the type.
51 std::string type_name_string(string.data(), string.data() + i);
52 if (type_name_string.empty())
53 {
54 error_out = QCoreApplication::translate("TypeString", "No type name provided.");
55 return nullptr;
56 }
57
58 ccc::DataTypeHandle handle = database.data_types.first_handle_from_name(type_name_string);
59 const ccc::DataType* data_type = database.data_types.symbol_from_handle(handle);
60 if (!data_type || !data_type->type())
61 {
62 error_out = QCoreApplication::translate("TypeString", "Type '%1' not found.").arg(QString::fromStdString(type_name_string));
63 return nullptr;
64 }
65
66 std::unique_ptr<ccc::ast::Node> result;
67

Callers 3

setModelDataMethod · 0.85
changeTypeTemporarilyMethod · 0.85
parseUserInputMethod · 0.85

Calls 8

symbol_from_handleMethod · 0.80
argMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
typeMethod · 0.45
handleMethod · 0.45

Tested by

no test coverage detected