MCPcopy Create free account
hub / github.com/CE-Programming/CEmu / debugBasicCreateTokenMap

Method debugBasicCreateTokenMap

gui/qt/basicdebugger.cpp:229–314  ·  view source on GitHub ↗

function to parse the program and store the mapping of all bytes to highlights who cares about eating all of the user's ram

Source from the content-addressed store, hash-verified

227// function to parse the program and store the mapping of all bytes to highlights
228// who cares about eating all of the user's ram
229void MainWindow::debugBasicCreateTokenMap(int idx, const QByteArray &data) {
230 auto &tokensMap = m_basicPrgmsTokensMap[idx];
231 tokensMap.clear();
232 token_highlight_t posinfo = { 0, 0, 0 };
233 int i = 0;
234
235 // if we are doing normal debug, we just highlight based on the
236 // entire string from (:,\n) to the next break
237 if (!m_basicShowFetches) {
238 while (i < data.size()) {
239 bool instr = false;
240 int j = 0;
241 while (i < data.size() && data[i] != 0x3F) {
242 uint8_t token = static_cast<uint8_t>(data[i]);
243 uint8_t tokenNext = i < data.size() - 1 ? static_cast<uint8_t>(data[i + 1]) : static_cast<uint8_t>(-1u);
244
245 // check for : (make sure not in string)
246 if (token == 0x04) {
247 instr = false;
248 }
249 if (token == 0x2A) {
250 instr = !instr;
251 } else if (token == 0x3E && !instr) {
252 break;
253 }
254
255 // get current token
256 int incr;
257 data_t tokBytes(2);
258 tokBytes[0] = token;
259 tokBytes[1] = tokenNext;
260 std::string tokStr = tivars::TypeHandlers::TH_Tokenized::tokenToString(tokBytes, &incr, { { "prettify", true } });
261
262 if (!tokStr.empty()) {
263 posinfo.len += utf8_strlen(tokStr.c_str());
264 }
265
266 i += incr;
267 j += incr;
268 }
269 j++;
270 while (j) {
271 tokensMap.append(posinfo);
272 j--;
273 }
274 posinfo.offset += posinfo.len + 1;
275 posinfo.line++;
276 posinfo.len = 0;
277 i++;
278 }
279 } else {
280 while (i < data.size()) {
281 uint8_t token = static_cast<uint8_t>(data[i]);
282 uint8_t tokenNext = i < data.size() - 1 ? static_cast<uint8_t>(data[i + 1]) : static_cast<uint8_t>(-1u);
283
284 // check for newline
285 if (token == 0x3F) {
286 posinfo.len = 1;

Callers

nothing calls this directly

Calls 2

utf8_strlenFunction · 0.85
clearMethod · 0.45

Tested by

no test coverage detected