Fixed matching item list dump. Improved debug.
This commit is contained in:
parent
e3f3ba3884
commit
1efb132281
|
@ -2485,6 +2485,19 @@ static const TokenDict s_miDumpFlags[] = {
|
||||||
{0,0}
|
{0,0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline String dumpIndent(const String& buf)
|
||||||
|
{
|
||||||
|
String s;
|
||||||
|
for (const char* ss = buf; (ss && *ss); ++ss)
|
||||||
|
if (*ss == '\r')
|
||||||
|
s << "\\r";
|
||||||
|
else if (*ss == '\n')
|
||||||
|
s << "\\n";
|
||||||
|
else
|
||||||
|
s << *ss;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
void MatchingItemDump::init(const NamedList& params)
|
void MatchingItemDump::init(const NamedList& params)
|
||||||
{
|
{
|
||||||
for (ObjList* o = params.paramList()->skipNull(); o; o = o->skipNext()) {
|
for (ObjList* o = params.paramList()->skipNull(); o; o = o->skipNext()) {
|
||||||
|
@ -2517,8 +2530,10 @@ String& MatchingItemDump::dumpValue(const MatchingItemBase* item, String& buf,
|
||||||
// Done if already dumped (item implements dumpValue())
|
// Done if already dumped (item implements dumpValue())
|
||||||
if (item->dumpValue(tmp,this,indent,origIndent,depth))
|
if (item->dumpValue(tmp,this,indent,origIndent,depth))
|
||||||
return buf << tmp;
|
return buf << tmp;
|
||||||
XDebug("MatchingItemDump",DebugAll,"dumpValue (%p) %s '%s' indent='%s' origIndent='%s'",
|
XDebug("MatchingItemDump",DebugAll,
|
||||||
item,miType(item),item->name().safe(),indent.safe(),origIndent.safe());
|
"dumpValue (%p) %s '%s' depth=%u indent='%s'/'%s' [%p]",
|
||||||
|
item,miType(item),item->name().safe(),depth,dumpIndent(indent).safe(),
|
||||||
|
dumpIndent(origIndent).safe(),this);
|
||||||
if (item->itemList()) {
|
if (item->itemList()) {
|
||||||
for (unsigned int i = 0; i < item->itemList()->length(); ++i) {
|
for (unsigned int i = 0; i < item->itemList()->length(); ++i) {
|
||||||
String tmp;
|
String tmp;
|
||||||
|
@ -2562,8 +2577,8 @@ String& MatchingItemDump::dumpValue(const MatchingItemBase* item, String& buf,
|
||||||
buf << "<UNKNOWN>";
|
buf << "<UNKNOWN>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
XDebug("MatchingItemDump",DebugAll,"Dumped value (%p) '%s'\r\n-----\r\n%s\r\n-----",
|
XDebug("MatchingItemDump",DebugAll,"Dumped value (%p) '%s' [%p]\r\n-----\r\n%s\r\n-----",
|
||||||
item,item->name().safe(),buf.safe());
|
item,item->name().safe(),this,buf.safe());
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2573,8 +2588,10 @@ String& MatchingItemDump::dump(const MatchingItemBase* item, String& buf,
|
||||||
if (!item)
|
if (!item)
|
||||||
return buf;
|
return buf;
|
||||||
|
|
||||||
XDebug("MatchingItemDump",DebugAll,"dump (%p) %s '%s' indent='%s' origIndent='%s'",
|
XDebug("MatchingItemDump",DebugAll,
|
||||||
item,miType(item),item->name().safe(),indent.safe(),origIndent.safe());
|
"dump (%p) %s '%s' flags=0x%x depth=%u indent='%s'/'%s' [%p]",
|
||||||
|
item,miType(item),item->name().safe(),m_flags,depth,
|
||||||
|
dumpIndent(indent).safe(),dumpIndent(origIndent).safe(),this);
|
||||||
unsigned int oLen = buf.length();
|
unsigned int oLen = buf.length();
|
||||||
item->dump(buf,this,indent,origIndent,depth);
|
item->dump(buf,this,indent,origIndent,depth);
|
||||||
// Done if already dumped (item implements dump())
|
// Done if already dumped (item implements dump())
|
||||||
|
@ -2583,7 +2600,7 @@ String& MatchingItemDump::dump(const MatchingItemBase* item, String& buf,
|
||||||
|
|
||||||
const MatchingItemList* list = item->itemList();
|
const MatchingItemList* list = item->itemList();
|
||||||
if (list) {
|
if (list) {
|
||||||
String newIndent = indent;
|
String tmp;
|
||||||
if (depth || 0 == (m_flags & NoInitialListDesc)) {
|
if (depth || 0 == (m_flags & NoInitialListDesc)) {
|
||||||
String flags;
|
String flags;
|
||||||
if (list->negated())
|
if (list->negated())
|
||||||
|
@ -2592,14 +2609,18 @@ String& MatchingItemDump::dump(const MatchingItemBase* item, String& buf,
|
||||||
flags.append("any",",");
|
flags.append("any",",");
|
||||||
if (flags)
|
if (flags)
|
||||||
flags.printf(" [%s]",flags.safe());
|
flags.printf(" [%s]",flags.safe());
|
||||||
if (flags || depth || item->name()) {
|
if (depth || flags || item->name())
|
||||||
buf << indent << item->name().safe("List") << ':' << flags;
|
tmp << item->name().safe("List") << ':' << flags;
|
||||||
if (depth)
|
}
|
||||||
newIndent += origIndent;
|
// Nothing dumped at first level:
|
||||||
}
|
// print the rest of the list at same alignment
|
||||||
|
String newIndent = indent;
|
||||||
|
if (tmp) {
|
||||||
|
buf << indent << tmp;
|
||||||
|
newIndent += origIndent;
|
||||||
}
|
}
|
||||||
for (unsigned int i = 0; i < list->length(); ++i) {
|
for (unsigned int i = 0; i < list->length(); ++i) {
|
||||||
String tmp;
|
tmp.clear();
|
||||||
buf << dump(list->at(i),tmp,newIndent,origIndent,depth + 1);
|
buf << dump(list->at(i),tmp,newIndent,origIndent,depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2607,14 +2628,14 @@ String& MatchingItemDump::dump(const MatchingItemBase* item, String& buf,
|
||||||
String val;
|
String val;
|
||||||
dumpValue(item,val);
|
dumpValue(item,val);
|
||||||
if (item->name() || val) {
|
if (item->name() || val) {
|
||||||
buf << indent << origIndent;
|
buf << indent;
|
||||||
if (item->name())
|
if (item->name())
|
||||||
buf << item->name() << m_nameValueSep.safe("=");
|
buf << item->name() << m_nameValueSep.safe("=");
|
||||||
buf << val;
|
buf << val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
XDebug("MatchingItemDump",DebugAll,"Dumped (%p) '%s'\r\n-----\r\n%s\r\n-----",
|
XDebug("MatchingItemDump",DebugAll,"Dumped (%p) '%s' [%p]\r\n-----\r\n%s\r\n-----",
|
||||||
item,item->name().safe(),buf.safe());
|
item,item->name().safe(),this,buf.safe());
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2707,13 +2728,21 @@ MatchingItemBase* MatchingItemList::copy() const
|
||||||
static inline bool matchingListRun(const MatchingItemList& mil, MatchingParams* params,
|
static inline bool matchingListRun(const MatchingItemList& mil, MatchingParams* params,
|
||||||
const NamedList* list, const String& str = String::empty())
|
const NamedList* list, const String& str = String::empty())
|
||||||
{
|
{
|
||||||
int pos = -1;
|
|
||||||
bool allMatch = mil.matchAll();
|
bool allMatch = mil.matchAll();
|
||||||
|
#ifdef XDEBUG
|
||||||
|
Debugger dbg(DebugAll,"MatchingItemList MATCHING",
|
||||||
|
" name='%s' all=%s negated=%s input='%s' params=(%p) [%p]",
|
||||||
|
mil.name().safe(),String::boolText(allMatch),String::boolText(mil.negated()),
|
||||||
|
list ? list->safe("list") : "<string>",params,&mil);
|
||||||
|
#endif
|
||||||
|
int pos = -1;
|
||||||
while (true) {
|
while (true) {
|
||||||
const MatchingItemBase* item = const_cast<MatchingItemBase*>(mil.at(++pos));
|
const MatchingItemBase* item = const_cast<MatchingItemBase*>(mil.at(++pos));
|
||||||
if (!item)
|
if (!item)
|
||||||
break;
|
break;
|
||||||
bool ok = list ? item->matchListParam(*list,params) : item->matchString(str,params);
|
bool ok = list ? item->matchListParam(*list,params) : item->matchString(str,params);
|
||||||
|
XDebug("MatchingItemList",DebugAll,"matched [%s] idx=%d (%p) '%s' type=%s [%p]",
|
||||||
|
String::boolText(ok),pos,item,item->name().safe(),miType(item),&mil);
|
||||||
// Matched: done if not all match (any match)
|
// Matched: done if not all match (any match)
|
||||||
// Not matched: done if all match is required
|
// Not matched: done if all match is required
|
||||||
if (ok) {
|
if (ok) {
|
||||||
|
@ -2726,6 +2755,8 @@ static inline bool matchingListRun(const MatchingItemList& mil, MatchingParams*
|
||||||
// End of list reached
|
// End of list reached
|
||||||
// Empty list or match any: not matched
|
// Empty list or match any: not matched
|
||||||
// Otherwise: matched
|
// Otherwise: matched
|
||||||
|
XDebug("MatchingItemList",DebugAll,"End of matching [%s] pos=%d [%p]",
|
||||||
|
String::boolText(pos && allMatch),pos,&mil);
|
||||||
return pos && allMatch;
|
return pos && allMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2739,8 +2770,6 @@ bool MatchingItemList::runMatchListParam(const NamedList& list, MatchingParams*
|
||||||
return matchingListRun(*this,params,&list);
|
return matchingListRun(*this,params,&list);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef MatchingItemList_RUN_LIST
|
|
||||||
|
|
||||||
MatchingItemBase* MatchingItemList::optimize(MatchingItemList* list)
|
MatchingItemBase* MatchingItemList::optimize(MatchingItemList* list)
|
||||||
{
|
{
|
||||||
if (!list || list->at(1))
|
if (!list || list->at(1))
|
||||||
|
|
Loading…
Reference in New Issue