51 assert(
end <= static_cast<int>(s.
length()));
82 while (pos < static_cast<int>(str.
length()) && str[pos]==
wxT(
'.'))
89 int newPos = -1, currPos = pos;
92 if (currPos + 4 >= static_cast<int>(str.
length()))
94 if (str[currPos + 1] !=
wxT(
','))
96 if (str[currPos + 3] ==
wxT(
'\''))
101 size_t start, length;
103 newPos = currPos + 3 + length;
104 if ((newPos + 4 < static_cast<int>(str.
length()))
105 && str[newPos] ==
wxT(
',') && str[newPos + 2] ==
wxT(
'"'))
108 while (newPos < static_cast<int>(str.
length()) && str[newPos] !=
wxT(
'"'))
110 if (newPos + 1 < static_cast<int>(str.
length()) && str[newPos] ==
wxT(
'"'))
130 while (pos < static_cast<int>(str.
length())
131 && (str[pos] ==
_T(
' ') || str[pos] ==
_T(
'\t') || str[pos] ==
_T(
'\n')))
134 if (pos >= static_cast<int>(str.
length()))
138 bool in_quote =
false, in_char =
false;
140 struct BraceType {
enum Enum { None, Angle, Square, Normal }; };
141 BraceType::Enum brace_type = BraceType::None;
143 switch (static_cast<wxChar>(str[pos]))
172 brace_type = BraceType::Angle;
178 brace_type = BraceType::Square;
183 brace_type = BraceType::Normal;
192 bool escape_next =
false;
193 while (pos < static_cast<int>(str.
length()))
195 if (open_braces == 0)
197 if (str[pos] ==
_T(
',') && !in_quote)
202 else if ((str[pos] ==
_T(
'=') || str[pos] ==
_T(
'{') || str[pos] ==
_T(
'}')) && !in_quote && !in_char)
207 else if (str[pos] ==
_T(
'"'))
236 else if (str[pos] ==
_T(
'\''))
242 else if (str[pos] ==
_T(
'\\'))
249 case BraceType::Angle:
250 if (str[pos] ==
wxT(
'<'))
253 case BraceType::Square:
254 if (str[pos] ==
wxT(
'['))
257 case BraceType::None:
266 case BraceType::Angle:
267 if (str[pos] ==
wxT(
'<'))
269 else if (str[pos] ==
wxT(
'>'))
272 case BraceType::Square:
273 if (str[pos] ==
wxT(
'['))
275 else if (str[pos] ==
wxT(
']'))
278 case BraceType::Normal:
279 if (str[pos] ==
wxT(
'('))
281 else if (str[pos] ==
wxT(
')'))
284 case BraceType::None:
307 cb::shared_ptr<cbWatch> old_child = parent->FindChild(str_name);
308 cb::shared_ptr<GDBWatch> child;
310 child = cb::static_pointer_cast<
GDBWatch>(old_child);
313 child = cb::shared_ptr<GDBWatch>(
new GDBWatch(str_name));
316 child->MarkAsRemoved(
false);
320 inline cb::shared_ptr<GDBWatch>
AddChild(cb::shared_ptr<GDBWatch> parent,
wxString const &str_name)
322 int index = parent->FindChildIndex(str_name);
323 cb::shared_ptr<GDBWatch> child;
325 child = cb::static_pointer_cast<
GDBWatch>(parent->GetChild(index));
328 child = cb::shared_ptr<GDBWatch>(
new GDBWatch(str_name));
331 child->MarkAsRemoved(
false);
340 watch->SetDebugValue(value);
341 watch->MarkChildsAsRemoved();
344 watch->GetSymbol(watchSymbol);
345 bool isFortranArray =
false;
347 isFortranArray = regexFortranArray.
Matches(watchSymbol);
349 bool hasNewWatchSymbol =
false;
351 int position =
start;
352 Token token, token_name, token_value;
354 bool skip_comma =
false;
355 bool last_was_closing_brace =
false;
356 int added_children = 0;
357 int token_real_end = 0;
360 token_real_end = token.
end;
373 position = pos_val+1;
374 if (length > 0 && position >= start + length)
384 token.
start += pos + 2;
391 Token expanded_token = token;
394 if (value[expanded_token.
end] ==
wxT(
','))
396 position = token.
end + 1;
397 token_real_end = position;
398 int comma_end = expanded_token.
end;
402 if (!expanded_str.
empty() && (expanded_str[0] !=
wxT(
'"') && expanded_str[0] !=
wxT(
'\'')))
404 token.
end = comma_end;
405 position = comma_end;
406 token_real_end = comma_end;
409 token.
end = expanded_token.
end;
410 if (regexRepeatedChar.
Matches(expanded_str))
412 token_real_end = expanded_token.
end;
415 else if (expanded_token.
end == static_cast<int>(value.
length()) || value[expanded_token.
end] ==
wxT(
'}'))
417 token.
end = expanded_token.
end;
418 token_real_end = expanded_token.
end;
444 Token expanded_token = token;
445 int firstCloseBrace = -1;
446 for (; expanded_token.
end <
static_cast<int>(value.
length()); ++expanded_token.
end)
448 if (value[expanded_token.
end] ==
wxT(
'='))
450 bool foundBrace =
false;
451 for (
int ii = expanded_token.
end + 1; ii < static_cast<int>(value.
length()); ++ii)
453 if (value[ii] ==
wxT(
'{'))
458 else if (value[ii] !=
wxT(
' ') && value[ii] !=
wxT(
'\t')
459 && value[ii] !=
wxT(
'\n') && value[ii] !=
wxT(
' '))
467 token.
end = token_real_end = expanded_token.
end;
474 while (expanded_token.
end >= 0)
476 if (value[expanded_token.
end] ==
wxT(
','))
478 token.
end = token_real_end = expanded_token.
end;
483 expanded_token.
end--;
488 else if (firstCloseBrace == -1 && value[expanded_token.
end] ==
wxT(
'}'))
490 firstCloseBrace=expanded_token.
end;
495 if (pythonToStringValue.
empty())
497 if (firstCloseBrace == -1)
499 token.
end = token_real_end = firstCloseBrace;
502 if (pythonToStringValue.
empty())
509 last_was_closing_brace =
false;
512 last_was_closing_brace =
false;
516 last_was_closing_brace =
false;
525 cb::shared_ptr<GDBWatch> child =
AddChild(watch, value, token_name);
530 cb::shared_ptr<GDBWatch> child;
533 int start_arr = watch->IsArray() ? watch->GetArrayStart() : 0;
538 int start_arr = watch->IsArray() ? watch->GetArrayStart() : 1;
543 childSymbol << watchSymbol.
Mid(1);
549 child =
AddChild(watch, childSymbol);
562 cb::shared_ptr<GDBWatch> child;
567 int start_arr = watch->IsArray() ? watch->GetArrayStart() : 0;
572 int start_arr = watch->IsArray() ? watch->GetArrayStart() : 1;
577 childSymbol << watchSymbol.
Mid(1);
583 child =
AddChild(watch, childSymbol);
589 child =
AddChild(watch, value, token_name);
593 else if (!pythonToStringValue.
empty())
594 child->SetValue(pythonToStringValue);
595 position = token_real_end;
605 child->GetSymbol(childSymbol);
612 watchSymbolNew = childSymbol;
613 watchSymbolNew.
replace(pos+2, pos_com-(pos+2),
wxT(
':'));
614 hasNewWatchSymbol =
true;
619 watchSymbolNew <<
wxT(
"(:,") << watchSymbol.
Mid(1);
620 hasNewWatchSymbol =
true;
624 token_real_end = position;
627 last_was_closing_brace =
true;
631 if (!last_was_closing_brace)
637 cb::shared_ptr<GDBWatch> child =
AddChild(watch, value, token_name);
642 cb::shared_ptr<GDBWatch> child;
645 int start_arr = watch->IsArray() ? watch->GetArrayStart() : 0;
650 int start_arr = watch->IsArray() ? watch->GetArrayStart() : 1;
655 childSymbol << watchSymbol.
Mid(1);
656 if (!hasNewWatchSymbol)
658 watchSymbolNew <<
wxT(
"(:,") << watchSymbol.
Mid(1);
659 hasNewWatchSymbol =
true;
666 child =
AddChild(watch, childSymbol);
674 watch->SetValue(
wxT(
""));
677 if (hasNewWatchSymbol)
678 watch->SetSymbol(watchSymbolNew);
680 start = token_real_end;
687 position = token_real_end;
688 if (length > 0 && position >= start + length)
692 start = position + 1;
697 cb::shared_ptr<GDBWatch> child =
AddChild(watch, value, token_name);
702 cb::shared_ptr<GDBWatch> child;
705 int start_arr = watch->IsArray() ? watch->GetArrayStart() : 0;
710 int start_arr = watch->IsArray() ? watch->GetArrayStart() : 1;
743 pos = input.
find(
wxT(
'\n'), lastPos);
746 if (lastPos < input.
length())
747 result += input.
substr(lastPos, input.
length() - lastPos);
764 static wxRegEx nan_line(
wxT(
"nan\\([a-zA-Z0-9]*\\)"));
772 if(inputValue.
empty())
774 watch->SetValue(inputValue);
792 int t_start = start + 1;
799 referenceValue.
Trim(
true);
800 referenceValue.
Trim(
false);
804 referenceValue.
Trim(
true);
806 watch->SetValue(referenceValue);
808 watch->RemoveMarkedChildren();
814 watch->SetValue(value);
815 watch->RemoveChildren();
850 watch->SetDebugValue(value);
851 watch->MarkChildsAsRemoved();
856 static wxRegEx unexpected_error(
wxT(
"^Unexpected token '.+'$"));
857 static wxRegEx resolve_error(
wxT(
"^Couldn't resolve error at '.+'$"));
860 for (
unsigned ii = 0; ii < lines.
GetCount(); ++ii)
862 if (unexpected_error.
Matches(lines[ii])
863 || resolve_error.
Matches(lines[ii])
864 || lines[ii] ==
wxT(
"No pointer for operator* '<EOL>'"))
866 watch->SetValue(lines[ii]);
878 if (tokens[0] ==
wxT(
"class") || tokens[0] ==
wxT(
"struct"))
881 if (static_cast<int>(tokens.
GetCount()) < type_token + 2)
884 int value_start = type_token + 1;
885 if (tokens[type_token + 1] ==
wxT(
'*'))
887 watch->SetType(tokens[type_token] + tokens[type_token + 1]);
891 watch->SetType(tokens[type_token]);
893 if(value_start >= static_cast<int>(tokens.
GetCount()))
896 watch->SetValue(tokens[value_start]);
897 watch->RemoveMarkedChildren();
907 bool set_type =
true;
910 if (tokens[0] ==
wxT(
"struct") || tokens[0] ==
wxT(
"class"))
912 if (tokens[2] ==
wxT(
'*') || tokens[2].StartsWith(
wxT(
"[")))
914 watch->SetType(tokens[1] + tokens[2]);
920 if (tokens[1] ==
wxT(
'*') || tokens[1].StartsWith(
wxT(
"[")))
923 watch->SetType(tokens[0] + tokens[1]);
924 watch->SetValue(lines[1]);
931 watch->SetType(tokens[1]);
933 static wxRegEx class_line(
wxT(
"[ \\t]*\\+(0x[0-9a-f]+)[ \\t]([a-zA-Z0-9_]+)[ \\t]+:[ \\t]+(.+)"));
941 if (!class_line.
Matches(
wxT(
" +0x000 a : 10")))
948 for (
unsigned ii = 1; ii < lines.
GetCount(); ++ii)
950 if (class_line.
Matches(lines[ii]))
952 cb::shared_ptr<GDBWatch> w =
AddChild(watch, class_line.
GetMatch(lines[ii], 2));
953 w->SetValue(class_line.
GetMatch(lines[ii], 3));
954 w->SetDebugValue(lines[ii]);
957 watch->RemoveMarkedChildren();
966 for (
size_t ii = 0; ii < length; ++ii)
968 if (nameValue[start + ii] ==
wxT(
'='))
970 name = nameValue.
substr(start, ii);
972 value = nameValue.
substr(start + ii + 1, length - ii - 1);
983 size_t count = value.
length();
986 bool inString =
false, inChar =
false;
987 bool escaped =
false;
989 for (
size_t ii = 0; ii < count; ++ii)
995 if (!inString && !inChar && curlyBraces == 0)
1002 if (!inString && !inChar)
1006 if (!inString && !inChar)
1010 if (!inChar && !escaped)
1014 if (!inString && !escaped)
1021 escaped = (ch ==
wxT(
'\\') && !escaped);
DLLIMPORT wxArrayString GetArrayFromString(const wxString &text, const wxString &separator=DEFAULT_ARRAY_SEP, bool trimSpaces=true)
DebuggerLanguage g_DebugLanguage
wxString substr(size_t nStart=0, size_t nLen=npos) const
wxRegEx regexRepeatedChars(wxT("^((\'.{1,6}\')|('.{1,6}'))[ \](<repeats[ \][0-9]+[ \]times>)"), wxRE_ADVANCED)
bool operator==(Token const &t) const
wxString RemoveWarnings(wxString const &input)
wxString & replace(size_t nStart, size_t nLen, const wxString &str)
bool Matches(const wxString &text, int flags=0) const
bool wxIsdigit(const wxUniChar &c)
void TokenizeGDBLocals(std::vector< GDBLocalVariable > &results, wxString const &value)
wxString & Remove(size_t pos)
Token(int start_, int end_, Type type_)
size_t find(const wxString &str, size_t nStart=0) const
wxRegEx regexFortranArray(wxT("^\[0-9,]+)$"))
wxUSE_UNICODE_dependent wxChar
int Replace(wxString *text, const wxString &replacement, size_t maxMatches=0) const
bool GetNextToken(wxString const &str, int pos, Token &token)
bool ParseGDBWatchValue(cb::shared_ptr< GDBWatch > watch, wxString const &value, int &start, int length)
a symbol found in the parsed files, it can be many kinds, such as a variable, a class and so on...
wxString & RemoveLast(size_t n=1)
size_t Replace(const wxString &strOld, const wxString &strNew, bool replaceAll=true)
bool GetMatch(size_t *start, size_t *len, size_t index=0) const
size_t find_last_of(const wxString &str, size_t nStart=npos) const
GDBLocalVariable(wxString const &nameValue, size_t start, size_t length)
wxRegEx regexRepeatedChar(wxT(".+[ \](<repeats[ \][0-9]+[ \]times>)$"))
wxString & Trim(bool fromRight=true)
void RemoveBefore(wxString &str, const wxString &s)
static void AddChild(cb::shared_ptr< cbWatch > parent, cb::shared_ptr< cbWatch > watch)
void PrepareFortranOutput(wxString &outStr)
void Trim(wxString const &s)
bool EndsWith(const wxString &suffix, wxString *rest=NULL) const
bool ParseCDBWatchValue(cb::shared_ptr< GDBWatch > watch, wxString const &value)
bool StartsWith(const wxString &prefix, wxString *rest=NULL) const
static wxString Format(const wxString &format,...)
wxString Mid(size_t first, size_t nCount=wxString::npos) const
int DetectRepeatingSymbols(wxString const &str, int pos)
int SkipShortenedString(wxString const &str, int pos)
GDB can shorten the string.
bool AddChild(int childIdx)
add a child token