Mercurial > projects > dil
comparison trunk/src/cmd/DDoc.d @ 773:6dbbb403fc58
Improved the DDocEmitter.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Mon, 18 Feb 2008 17:36:12 +0100 |
parents | f0efbcb49248 |
children | e76c9fdb83a3 |
comparison
equal
deleted
inserted
replaced
772:f0efbcb49248 | 773:6dbbb403fc58 |
---|---|
142 { | 142 { |
143 if (ddoc(d)) | 143 if (ddoc(d)) |
144 { | 144 { |
145 if (auto copyright = cmnt.takeCopyright()) | 145 if (auto copyright = cmnt.takeCopyright()) |
146 mtable.insert(new Macro("COPYRIGHT", copyright.text)); | 146 mtable.insert(new Macro("COPYRIGHT", copyright.text)); |
147 DESC({ writeComment(); }); | 147 DESC({ |
148 writeComment(); | |
149 MEMBERS("MODULE", { visitD(modul.root); }); | |
150 }); | |
148 } | 151 } |
149 } | 152 } |
150 MEMBERS("MODULE", { visitD(modul.root); }); | 153 else |
151 write(\n); | 154 MEMBERS("MODULE", { visitD(modul.root); }); |
152 return text; | 155 return text; |
153 } | 156 } |
154 | 157 |
155 char[] textSpan(Token* left, Token* right) | 158 char[] textSpan(Token* left, Token* right) |
156 { | 159 { |
438 } | 441 } |
439 | 442 |
440 void SYMBOL(char[] name, Declaration d) | 443 void SYMBOL(char[] name, Declaration d) |
441 { | 444 { |
442 auto loc = d.begin.getRealLocation(); | 445 auto loc = d.begin.getRealLocation(); |
443 auto str = Format("$(SYMBOL {}, {}, {}.d, {})", name, modul.getFQN(), modul.getFQNPath(), loc.lineNum); | 446 auto str = Format("$(SYMBOL {}, {}, {}.{}, {})", |
447 name, modul.getFQN(), modul.getFQNPath(), | |
448 modul.fileExtension(), loc.lineNum); | |
444 write(str); | 449 write(str); |
445 // write("$(DDOC_PSYMBOL ", name, ")"); | 450 // write("$(DDOC_PSYMBOL ", name, ")"); |
446 } | 451 } |
447 | 452 |
448 uint prevDeclOffset; | 453 uint prevDeclOffset; |
521 d.decls && super.visit(d.decls); | 526 d.decls && super.visit(d.decls); |
522 }); | 527 }); |
523 }); | 528 }); |
524 } | 529 } |
525 | 530 |
531 void writeAliasOrTypedef(T)(T d) | |
532 { | |
533 auto prefix = is(T == AliasDeclaration) ? "alias " : "typedef "; | |
534 if (auto vd = d.decl.Is!(VariablesDeclaration)) | |
535 { | |
536 auto type = textSpan(vd.typeNode.baseType.begin, vd.typeNode.end); | |
537 foreach (name; vd.names) | |
538 DECL({ write(prefix); write(escape(type), " "); SYMBOL(name.str, d); }); | |
539 } | |
540 else if (auto fd = d.decl.Is!(FunctionDeclaration)) | |
541 {} | |
542 // DECL({ write(textSpan(d.begin, d.end)); }, false); | |
543 DESC({ writeComment(); }); | |
544 } | |
545 | |
526 alias Declaration D; | 546 alias Declaration D; |
527 | 547 |
528 override: | 548 override: |
529 // D visit(ModuleDeclaration d) | 549 // D visit(ModuleDeclaration d) |
530 // { return d; } | 550 // { return d; } |
531 | 551 |
532 D visit(AliasDeclaration d) | 552 D visit(AliasDeclaration d) |
533 { | 553 { |
534 if (!ddoc(d)) | 554 if (!ddoc(d)) |
535 return d; | 555 return d; |
536 if (auto vd = d.decl.Is!(VariablesDeclaration)) | 556 writeAliasOrTypedef(d); |
537 foreach (name; vd.names) | |
538 DECL({ write("alias "); SYMBOL(name.str, d); }); | |
539 else if (auto fd = d.decl.Is!(FunctionDeclaration)) | |
540 {} | |
541 // DECL({ write(textSpan(d.begin, d.end)); }, false); | |
542 DESC({ writeComment(); }); | |
543 return d; | 557 return d; |
544 } | 558 } |
545 | 559 |
546 D visit(TypedefDeclaration d) | 560 D visit(TypedefDeclaration d) |
547 { | 561 { |
548 if (!ddoc(d)) | 562 if (!ddoc(d)) |
549 return d; | 563 return d; |
550 if (auto vd = d.decl.Is!(VariablesDeclaration)) | 564 writeAliasOrTypedef(d); |
551 foreach (name; vd.names) | |
552 DECL({ write("typedef "); SYMBOL(name.str, d); }); | |
553 else if (auto fd = d.decl.Is!(FunctionDeclaration)) | |
554 {} | |
555 // DECL({ write(textSpan(d.begin, d.end)); }, false); | |
556 DESC({ writeComment(); }); | |
557 return d; | 565 return d; |
558 } | 566 } |
559 | 567 |
560 D visit(EnumDeclaration d) | 568 D visit(EnumDeclaration d) |
561 { | 569 { |
715 | 723 |
716 D visit(InvariantDeclaration d) | 724 D visit(InvariantDeclaration d) |
717 { | 725 { |
718 if (!ddoc(d)) | 726 if (!ddoc(d)) |
719 return d; | 727 return d; |
720 DECL({ write("invariant"); }); | 728 DECL({ SYMBOL("invariant", d); }); |
721 DESC({ writeComment(); }); | 729 DESC({ writeComment(); }); |
722 return d; | 730 return d; |
723 } | 731 } |
724 | 732 |
725 D visit(UnittestDeclaration d) | 733 D visit(UnittestDeclaration d) |
726 { | 734 { |
727 if (!ddoc(d)) | 735 if (!ddoc(d)) |
728 return d; | 736 return d; |
729 DECL({ write("unittest"); }); | 737 DECL({ SYMBOL("unittest", d); }); |
730 DESC({ writeComment(); }); | 738 DESC({ writeComment(); }); |
731 return d; | 739 return d; |
732 } | 740 } |
733 | 741 |
734 D visit(DebugDeclaration d) | 742 D visit(DebugDeclaration d) |