@@ -329,6 +329,36 @@ struct Tag {
329
329
size_t StartPosition = StringRef::npos;
330
330
};
331
331
332
+ static const char *tagKindToString (Tag::Kind K) {
333
+ switch (K) {
334
+ case Tag::Kind::None:
335
+ return " None" ;
336
+ case Tag::Kind::Normal:
337
+ return " Normal" ;
338
+ case Tag::Kind::Triple:
339
+ return " Triple" ;
340
+ }
341
+ llvm_unreachable (" Unknown Tag::Kind" );
342
+ }
343
+
344
+ static const char *jsonKindToString (json::Value::Kind K) {
345
+ switch (K) {
346
+ case json::Value::Kind::Null:
347
+ return " JSON_KIND_NULL" ;
348
+ case json::Value::Kind::Boolean:
349
+ return " JSON_KIND_BOOLEAN" ;
350
+ case json::Value::Kind::Number:
351
+ return " JSON_KIND_NUMBER" ;
352
+ case json::Value::Kind::String:
353
+ return " JSON_KIND_STRING" ;
354
+ case json::Value::Kind::Array:
355
+ return " JSON_KIND_ARRAY" ;
356
+ case json::Value::Kind::Object:
357
+ return " JSON_KIND_OBJECT" ;
358
+ }
359
+ llvm_unreachable (" Unknown json::Value::Kind" );
360
+ }
361
+
332
362
static Tag findNextTag (StringRef Template, size_t StartPos, StringRef Open,
333
363
StringRef Close) {
334
364
const StringLiteral TripleOpen (" {{{" );
@@ -373,19 +403,17 @@ static Tag findNextTag(StringRef Template, size_t StartPos, StringRef Open,
373
403
374
404
static std::optional<std::pair<StringRef, StringRef>>
375
405
processTag (const Tag &T, SmallVectorImpl<Token> &Tokens) {
376
- LLVM_DEBUG (dbgs () << " Found tag: \" " << T.FullMatch << " \" , Content: \" "
377
- << T. Content << " \ "\n" );
406
+ LLVM_DEBUG (dbgs () << " [Tag] " << T.FullMatch << " , Content: " << T. Content
407
+ << " , Kind: " << tagKindToString (T. TagKind ) << " \n " );
378
408
if (T.TagKind == Tag::Kind::Triple) {
379
409
Tokens.emplace_back (T.FullMatch .str (), " &" + T.Content .str (), ' &' );
380
- LLVM_DEBUG (dbgs () << " Created UnescapeVariable token.\n " );
381
410
return std::nullopt ;
382
411
}
383
412
StringRef Interpolated = T.Content ;
384
413
std::string RawBody = T.FullMatch .str ();
385
414
if (!Interpolated.trim ().starts_with (" =" )) {
386
415
char Front = Interpolated.empty () ? ' ' : Interpolated.trim ().front ();
387
416
Tokens.emplace_back (RawBody, Interpolated.str (), Front);
388
- LLVM_DEBUG (dbgs () << " Created tag token of type '" << Front << " '\n " );
389
417
return std::nullopt ;
390
418
}
391
419
Tokens.emplace_back (RawBody, Interpolated.str (), ' =' );
@@ -395,8 +423,8 @@ processTag(const Tag &T, SmallVectorImpl<Token> &Tokens) {
395
423
DelimSpec = DelimSpec.trim ();
396
424
397
425
std::pair<StringRef, StringRef> Ret = DelimSpec.split (' ' );
398
- LLVM_DEBUG (dbgs () << " Found Set Delimiter tag. NewOpen=' " << Ret.first
399
- << " ' , NewClose=' " << Ret.second << " ' \n " );
426
+ LLVM_DEBUG (dbgs () << " [ Set Delimiter] NewOpen: " << Ret.first
427
+ << " , NewClose: " << Ret.second << " \n " );
400
428
return Ret;
401
429
}
402
430
@@ -405,15 +433,15 @@ processTag(const Tag &T, SmallVectorImpl<Token> &Tokens) {
405
433
// but we don't support that here. An unescape variable
406
434
// is represented only by {{& variable}}.
407
435
static SmallVector<Token> tokenize (StringRef Template) {
408
- LLVM_DEBUG (dbgs () << " Tokenizing template: \" " << Template << " \"\n " );
436
+ LLVM_DEBUG (dbgs () << " [Tokenize Template] \" " << Template << " \"\n " );
409
437
SmallVector<Token> Tokens;
410
438
SmallString<8 > Open (" {{" );
411
439
SmallString<8 > Close (" }}" );
412
440
size_t Start = 0 ;
413
441
414
442
while (Start < Template.size ()) {
415
- LLVM_DEBUG (dbgs () << " Loop start. Start= " << Start << " , Open= '" << Open
416
- << " ', Close= '" << Close << " '\n " );
443
+ LLVM_DEBUG (dbgs () << " [Tokenize Loop] Start: " << Start << " , Open: '" << Open
444
+ << " ', Close: '" << Close << " '\n " );
417
445
Tag T = findNextTag (Template, Start, Open, Close);
418
446
419
447
if (T.TagKind == Tag::Kind::None) {
@@ -428,7 +456,6 @@ static SmallVector<Token> tokenize(StringRef Template) {
428
456
if (T.StartPosition > Start) {
429
457
StringRef Text = Template.substr (Start, T.StartPosition - Start);
430
458
Tokens.emplace_back (Text.str ());
431
- LLVM_DEBUG (dbgs () << " Created Text token: \" " << Text << " \"\n " );
432
459
}
433
460
434
461
if (auto NewDelims = processTag (T, Tokens)) {
@@ -479,7 +506,6 @@ static SmallVector<Token> tokenize(StringRef Template) {
479
506
if ((!HasTextBehind && !HasTextAhead) || (!HasTextBehind && Idx == LastIdx))
480
507
stripTokenBefore (Tokens, Idx, CurrentToken, CurrentType);
481
508
}
482
- LLVM_DEBUG (dbgs () << " Tokenizing finished.\n " );
483
509
return Tokens;
484
510
}
485
511
@@ -545,8 +571,8 @@ class AddIndentationStringStream : public MustacheOutputStream {
545
571
Indent.resize (Indentation, ' ' );
546
572
547
573
for (char C : Data) {
548
- LLVM_DEBUG (dbgs () << " IndentationStream: NeedsIndent= " << NeedsIndent
549
- << " , C= '" << C << " ', Indentation= " << Indentation
574
+ LLVM_DEBUG (dbgs () << " [Indentation Stream] NeedsIndent: " << NeedsIndent
575
+ << " , C: '" << C << " ', Indentation: " << Indentation
550
576
<< " \n " );
551
577
if (NeedsIndent && C != ' \n ' ) {
552
578
WrappedStream << Indent;
@@ -654,7 +680,9 @@ void Parser::parseMustache(ASTNode *Parent) {
654
680
}
655
681
}
656
682
static void toMustacheString (const json::Value &Data, raw_ostream &OS) {
657
- LLVM_DEBUG (dbgs () << " toMustacheString: kind=" << (int )Data.kind () << " \n " );
683
+ LLVM_DEBUG (dbgs () << " [To Mustache String] Kind: "
684
+ << jsonKindToString (Data.kind ()) << " , Data: " << Data
685
+ << " \n " );
658
686
switch (Data.kind ()) {
659
687
case json::Value::Null:
660
688
return ;
@@ -667,7 +695,6 @@ static void toMustacheString(const json::Value &Data, raw_ostream &OS) {
667
695
}
668
696
case json::Value::String: {
669
697
auto Str = *Data.getAsString ();
670
- LLVM_DEBUG (dbgs () << " --> writing string: \" " << Str << " \"\n " );
671
698
OS << Str.str ();
672
699
return ;
673
700
}
@@ -696,8 +723,8 @@ void ASTNode::renderText(MustacheOutputStream &OS) { OS << Body; }
696
723
697
724
void ASTNode::renderPartial (const json::Value &CurrentCtx,
698
725
MustacheOutputStream &OS) {
699
- LLVM_DEBUG (dbgs () << " renderPartial: Accessor= " << AccessorValue[0 ]
700
- << " , Indentation= " << Indentation << " \n " );
726
+ LLVM_DEBUG (dbgs () << " [Render Partial] Accessor: " << AccessorValue[0 ]
727
+ << " , Indentation: " << Indentation << " \n " );
701
728
auto Partial = Ctx.Partials .find (AccessorValue[0 ]);
702
729
if (Partial != Ctx.Partials .end ())
703
730
renderPartial (CurrentCtx, OS, Partial->getValue ().get ());
@@ -716,13 +743,12 @@ void ASTNode::renderVariable(const json::Value &CurrentCtx,
716
743
717
744
void ASTNode::renderUnescapeVariable (const json::Value &CurrentCtx,
718
745
MustacheOutputStream &OS) {
719
- LLVM_DEBUG (dbgs () << " renderUnescapeVariable: Accessor= " << AccessorValue[0 ]
746
+ LLVM_DEBUG (dbgs () << " [Render UnescapeVariable] Accessor: " << AccessorValue[0 ]
720
747
<< " \n " );
721
748
auto Lambda = Ctx.Lambdas .find (AccessorValue[0 ]);
722
749
if (Lambda != Ctx.Lambdas .end ()) {
723
750
renderLambdas (CurrentCtx, OS, Lambda->getValue ());
724
751
} else if (const json::Value *ContextPtr = findContext ()) {
725
- LLVM_DEBUG (dbgs () << " --> Found context value, writing to stream.\n " );
726
752
OS.suspendIndentation ();
727
753
toMustacheString (*ContextPtr, OS);
728
754
OS.resumeIndentation ();
@@ -792,8 +818,6 @@ void ASTNode::render(const llvm::json::Value &Data, MustacheOutputStream &OS) {
792
818
}
793
819
794
820
const json::Value *ASTNode::findContext () {
795
- LLVM_DEBUG (dbgs () << " findContext: AccessorValue[0]=" << AccessorValue[0 ]
796
- << " \n " );
797
821
// The mustache spec allows for dot notation to access nested values
798
822
// a single dot refers to the current context.
799
823
// We attempt to find the JSON context in the current node, if it is not
@@ -808,22 +832,12 @@ const json::Value *ASTNode::findContext() {
808
832
StringRef CurrentAccessor = AccessorValue[0 ];
809
833
ASTNode *CurrentParent = Parent;
810
834
811
- LLVM_DEBUG (dbgs () << " findContext: ParentContext: " ;
812
- if (ParentContext) ParentContext->print (dbgs ());
813
- else dbgs () << " nullptr" ; dbgs () << " \n " );
814
-
815
835
while (!CurrentContext || !CurrentContext->get (CurrentAccessor)) {
816
- LLVM_DEBUG (dbgs () << " findContext: climbing parent\n " );
817
836
if (CurrentParent->Ty != Root) {
818
837
CurrentContext = CurrentParent->ParentContext ->getAsObject ();
819
838
CurrentParent = CurrentParent->Parent ;
820
- LLVM_DEBUG (dbgs () << " findContext: new ParentContext: " ;
821
- if (CurrentParent->ParentContext )
822
- CurrentParent->ParentContext ->print (dbgs ());
823
- else dbgs () << " nullptr" ; dbgs () << " \n " );
824
839
continue ;
825
840
}
826
- LLVM_DEBUG (dbgs () << " findContext: reached root, not found\n " );
827
841
return nullptr ;
828
842
}
829
843
const json::Value *Context = nullptr ;
@@ -839,9 +853,6 @@ const json::Value *ASTNode::findContext() {
839
853
Context = CurrentValue;
840
854
}
841
855
}
842
- LLVM_DEBUG (dbgs () << " findContext: found value: " ;
843
- if (Context) Context->print (dbgs ()); else dbgs () << " nullptr" ;
844
- dbgs () << " \n " );
845
856
return Context;
846
857
}
847
858
@@ -853,8 +864,7 @@ void ASTNode::renderChild(const json::Value &Contexts,
853
864
854
865
void ASTNode::renderPartial (const json::Value &Contexts,
855
866
MustacheOutputStream &OS, ASTNode *Partial) {
856
- LLVM_DEBUG (dbgs () << " renderPartial (helper): Indentation=" << Indentation
857
- << " \n " );
867
+ LLVM_DEBUG (dbgs () << " [Render Partial Indentation] Indentation: " << Indentation << " \n " );
858
868
AddIndentationStringStream IS (OS, Indentation);
859
869
Partial->render (Contexts, IS);
860
870
}
0 commit comments