Skip to content

Commit c52a7a5

Browse files
committed
php,html: add tracing code for debugging
1 parent 37b43b3 commit c52a7a5

File tree

2 files changed

+64
-12
lines changed

2 files changed

+64
-12
lines changed

parsers/html.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "routines.h"
2020
#include "keyword.h"
2121
#include "promise.h"
22+
#include "trace.h"
2223

2324
/* The max. number of nested elements - prevents further recursion if the limit
2425
* is exceeded and avoids stack overflow for invalid input containing too many
@@ -167,7 +168,7 @@ typedef enum {
167168
} tokenType;
168169

169170
#ifdef DEBUG
170-
const char *tokenTypes[] = {
171+
static const char *tokenTypes[] = {
171172
#define E(X) [TOKEN_##X] = #X
172173
E(EOF),
173174
E(NAME),
@@ -195,17 +196,6 @@ static int Lang_html;
195196

196197
static void readTag (tokenInfo *token, vString *text, int depth);
197198

198-
#ifdef DEBUG
199-
#if 0
200-
static void dumpToken (tokenInfo *token, const char *context, const char* extra_context)
201-
{
202-
fprintf (stderr, "[%7s] %-20s@%s.%s\n",
203-
tokenTypes[token->type], vStringValue(token->string),
204-
context, extra_context? extra_context: "_");
205-
}
206-
#endif
207-
#endif
208-
209199
static void readTokenText (tokenInfo *const token, bool collectText)
210200
{
211201
int c;
@@ -356,6 +346,8 @@ static void readToken (tokenInfo *const token, bool skipComments)
356346
break;
357347
}
358348
}
349+
350+
TRACE_PRINT("token: %s (%s)", tokenTypes[token->type], vStringValue (token->string));
359351
}
360352

361353
static void appendText (vString *text, vString *appendedText)
@@ -373,6 +365,8 @@ static void appendText (vString *text, vString *appendedText)
373365

374366
static bool readTagContent (tokenInfo *token, vString *text, long *line, long *lineOffset, int depth)
375367
{
368+
TRACE_ENTER();
369+
376370
tokenType type;
377371

378372
readTokenText (token, text != NULL);
@@ -394,11 +388,15 @@ static bool readTagContent (tokenInfo *token, vString *text, long *line, long *l
394388
}
395389
while (type == TOKEN_COMMENT || type == TOKEN_TAG_START);
396390

391+
TRACE_LEAVE_TEXT("is_close_tag? %d", type == TOKEN_CLOSE_TAG_START);
392+
397393
return type == TOKEN_TAG_START2;
398394
}
399395

400396
static bool skipScriptContent (tokenInfo *token, long *line, long *lineOffset)
401397
{
398+
TRACE_ENTER();
399+
402400
bool found_start = false;
403401
bool found_script = false;
404402

@@ -434,6 +432,8 @@ static bool skipScriptContent (tokenInfo *token, long *line, long *lineOffset)
434432
}
435433
while ((type != TOKEN_EOF) && (!found_script));
436434

435+
TRACE_LEAVE_TEXT("found_script? %d", found_script);
436+
437437
return found_script;
438438
}
439439

@@ -463,6 +463,8 @@ static void makeClassRefTags (const char *classes)
463463

464464
static void readTag (tokenInfo *token, vString *text, int depth)
465465
{
466+
TRACE_ENTER();
467+
466468
bool textCreated = false;
467469

468470
readToken (token, true);
@@ -640,10 +642,14 @@ static void readTag (tokenInfo *token, vString *text, int depth)
640642
out:
641643
if (textCreated)
642644
vStringDelete (text);
645+
646+
TRACE_LEAVE();
643647
}
644648

645649
static void findHtmlTags (void)
646650
{
651+
TRACE_ENTER();
652+
647653
tokenInfo token;
648654

649655
token.string = vStringNew ();
@@ -657,6 +663,8 @@ static void findHtmlTags (void)
657663
while (token.type != TOKEN_EOF);
658664

659665
vStringDelete (token.string);
666+
667+
TRACE_LEAVE();
660668
}
661669

662670
static void initialize (const langType language)

parsers/php.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "debug.h"
2727
#include "objpool.h"
2828
#include "promise.h"
29+
#include "trace.h"
2930

3031
#define isIdentChar(c) (isalnum (c) || (c) == '_' || (c) >= 0x80)
3132
#define newToken() (objPoolGet (TokenPool))
@@ -238,6 +239,35 @@ typedef enum eTokenType {
238239
TOKEN_QMARK,
239240
} tokenType;
240241

242+
#ifdef DEBUG
243+
static const char *tokenTypes[] = {
244+
#define E(X) [TOKEN_##X] = #X
245+
E(UNDEFINED),
246+
E(EOF),
247+
E(CHARACTER),
248+
E(CLOSE_PAREN),
249+
E(SEMICOLON),
250+
E(COLON),
251+
E(COMMA),
252+
E(KEYWORD),
253+
E(OPEN_PAREN),
254+
E(OPERATOR),
255+
E(IDENTIFIER),
256+
E(STRING),
257+
E(PERIOD),
258+
E(OPEN_CURLY),
259+
E(CLOSE_CURLY),
260+
E(EQUAL_SIGN),
261+
E(OPEN_SQUARE),
262+
E(CLOSE_SQUARE),
263+
E(VARIABLE),
264+
E(AMPERSAND),
265+
E(BACKSLASH),
266+
E(QMARK),
267+
#undef E
268+
};
269+
#endif
270+
241271
typedef struct {
242272
tokenType type;
243273
keywordId keyword;
@@ -1128,6 +1158,8 @@ static void readToken (tokenInfo *const token)
11281158
}
11291159

11301160
MayBeKeyword = nextMayBeKeyword;
1161+
1162+
TRACE_PRINT("token: %s (%s)", tokenTypes[token->type], vStringValue (token->string));
11311163
}
11321164

11331165
static void readQualifiedName (tokenInfo *const token, vString *name,
@@ -1712,6 +1744,8 @@ static void enterScope (tokenInfo *const parentToken,
17121744
const vString *const extraScope,
17131745
const int parentKind)
17141746
{
1747+
TRACE_ENTER();
1748+
17151749
tokenInfo *token = newToken ();
17161750
vString *typeName = vStringNew ();
17171751
int origParentKind = parentToken->parentKind;
@@ -1811,10 +1845,14 @@ static void enterScope (tokenInfo *const parentToken,
18111845
parentToken->parentKind = origParentKind;
18121846
vStringDelete (typeName);
18131847
deleteToken (token);
1848+
1849+
TRACE_LEAVE();
18141850
}
18151851

18161852
static void findTags (bool startsInPhpMode)
18171853
{
1854+
TRACE_ENTER();
1855+
18181856
tokenInfo *const token = newToken ();
18191857

18201858
InPhp = startsInPhpMode;
@@ -1834,16 +1872,22 @@ static void findTags (bool startsInPhpMode)
18341872
vStringDelete (FullScope);
18351873
vStringDelete (CurrentNamesapce);
18361874
deleteToken (token);
1875+
1876+
TRACE_LEAVE();
18371877
}
18381878

18391879
static void findPhpTags (void)
18401880
{
1881+
TRACE_ENTER();
18411882
findTags (false);
1883+
TRACE_LEAVE();
18421884
}
18431885

18441886
static void findZephirTags (void)
18451887
{
1888+
TRACE_ENTER();
18461889
findTags (true);
1890+
TRACE_LEAVE();
18471891
}
18481892

18491893
static void initializePool (void)

0 commit comments

Comments
 (0)