Skip to content

Commit a873a19

Browse files
committed
Logging for ParseScript().
Improved debug output.
1 parent a604621 commit a873a19

File tree

3 files changed

+52
-13
lines changed

3 files changed

+52
-13
lines changed

src/lexer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ struct _Node
322322

323323
uint line; /**< current line of document */
324324
uint column; /**< current column of document */
325+
326+
int idx; /**< general purpose register */
325327

326328
Bool closed; /**< true if closed by explicit end tag */
327329
Bool implicit; /**< true if inferred */

src/parser.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5154,6 +5154,12 @@ Node* TY_(ParseRowGroup)( TidyDocImpl* doc, Node *rowgroup, GetTokenMode ARG_UNU
51545154
Node* TY_(ParseScript)( TidyDocImpl* doc, Node *script, GetTokenMode ARG_UNUSED(mode) )
51555155
{
51565156
Node *node = NULL;
5157+
#if defined(ENABLE_DEBUG_LOG)
5158+
static int depth_parser = 0;
5159+
static int count_parser = 0;
5160+
#endif
5161+
5162+
DEBUG_LOG_ENTER_WITH_NODE(script);
51575163

51585164
doc->lexer->parent = script;
51595165
node = TY_(GetToken)(doc, CdataContent);
@@ -5167,10 +5173,12 @@ Node* TY_(ParseScript)( TidyDocImpl* doc, Node *script, GetTokenMode ARG_UNUSED(
51675173
{
51685174
/* handle e.g. a document like "<script>" */
51695175
TY_(Report)(doc, script, NULL, MISSING_ENDTAG_FOR);
5176+
DEBUG_LOG_EXIT;
51705177
return NULL;
51715178
}
51725179

51735180
node = TY_(GetToken)(doc, IgnoreWhitespace);
5181+
DEBUG_LOG_GOT_TOKEN(node);
51745182

51755183
if (!(node && node->type == EndTag && node->tag &&
51765184
node->tag->id == script->tag->id))
@@ -5184,6 +5192,7 @@ Node* TY_(ParseScript)( TidyDocImpl* doc, Node *script, GetTokenMode ARG_UNUSED(
51845192
{
51855193
TY_(FreeNode)(doc, node);
51865194
}
5195+
DEBUG_LOG_EXIT;
51875196
return NULL;
51885197
}
51895198

src/tidylib.c

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,24 +2048,52 @@ void dbg_show_node( TidyDocImpl* doc, Node *node, int caller, int indent )
20482048
SPRTF("\n");
20492049
}
20502050

2051-
/* Tail recursion here with sensible compilers will re-use
2052-
the stack frame and avoid overflows during debugging.
2051+
/* Make this non-recursive, because we really do want to eliminate
2052+
recursion that makes us crash, even when debugging.
20532053
*/
2054-
void dbg_show_all_nodes_loop( TidyDocImpl* doc, Node *node, int indent )
2054+
void dbg_show_all_nodes( TidyDocImpl* doc, Node *node, int indent )
20552055
{
2056-
while ( node && (node = node->next) )
2056+
Stack *stack = TY_(newStack)(doc, 16);
2057+
Node *child = NULL;
2058+
Node *next = NULL;
2059+
2060+
dbg_show_node( doc, node, 0, indent++ );
2061+
2062+
if ( (child = node->content) )
20572063
{
2058-
dbg_show_node( doc, node, 0, indent );
2059-
dbg_show_all_nodes_loop( doc, node->content, indent + 1 );
2060-
}
2061-
}
2064+
while ( child )
2065+
{
2066+
if ( (next = child->next) )
2067+
{
2068+
next->idx = indent;
2069+
}
2070+
2071+
dbg_show_node( doc, child, 0, indent );
2072+
2073+
if (child->content)
2074+
{
2075+
TY_(push)(stack, next);
2076+
indent++;
2077+
child = child->content;
2078+
continue;
2079+
}
20622080

2063-
void dbg_show_all_nodes( TidyDocImpl* doc, Node *node, int indent )
2064-
{
2065-
dbg_show_node( doc, node, 0, indent );
2066-
dbg_show_all_nodes_loop( doc, node->content, indent + 1 );
2067-
}
2081+
if (next)
2082+
{
2083+
child = next;
2084+
}
2085+
else
2086+
{
2087+
if ( (child = TY_(pop)(stack)) )
2088+
{
2089+
indent = child->idx;
2090+
}
2091+
}
20682092

2093+
}
2094+
TY_(freeStack)(stack);
2095+
}
2096+
}
20692097
#endif
20702098

20712099
int tidyDocCleanAndRepair( TidyDocImpl* doc )

0 commit comments

Comments
 (0)