comparison dmd/doc.c @ 336:aaade6ded589 trunk

[svn r357] Merged DMD 1.033
author lindquist
date Sat, 12 Jul 2008 19:38:31 +0200
parents 5acec6b2eef8
children 6aee82889553
comparison
equal deleted inserted replaced
335:17b844102023 336:aaade6ded589
398 sc->lastoffset += b.offset; 398 sc->lastoffset += b.offset;
399 } 399 }
400 400
401 void ScopeDsymbol::emitMemberComments(Scope *sc) 401 void ScopeDsymbol::emitMemberComments(Scope *sc)
402 { 402 {
403 //printf("ScopeDsymbol::emitMemberComments()\n"); 403 //printf("ScopeDsymbol::emitMemberComments() %s\n", toChars());
404 OutBuffer *buf = sc->docbuf; 404 OutBuffer *buf = sc->docbuf;
405 405
406 if (members) 406 if (members)
407 { char *m = "$(DDOC_MEMBERS \n"; 407 { char *m = "$(DDOC_MEMBERS \n";
408 408
415 else if (isEnumDeclaration()) 415 else if (isEnumDeclaration())
416 m = "$(DDOC_ENUM_MEMBERS \n"; 416 m = "$(DDOC_ENUM_MEMBERS \n";
417 else if (isTemplateDeclaration()) 417 else if (isTemplateDeclaration())
418 m = "$(DDOC_TEMPLATE_MEMBERS \n"; 418 m = "$(DDOC_TEMPLATE_MEMBERS \n";
419 419
420 // BUG: if no members are actually printed, we should not emit DDOC_MEMBERS 420 unsigned offset1 = buf->offset; // save starting offset
421 buf->writestring(m); 421 buf->writestring(m);
422 unsigned offset2 = buf->offset; // to see if we write anything
422 sc = sc->push(this); 423 sc = sc->push(this);
423 for (int i = 0; i < members->dim; i++) 424 for (int i = 0; i < members->dim; i++)
424 { 425 {
425 Dsymbol *s = (Dsymbol *)members->data[i]; 426 Dsymbol *s = (Dsymbol *)members->data[i];
426 //printf("\ts = '%s'\n", s->toChars()); 427 //printf("\ts = '%s'\n", s->toChars());
427 s->emitComment(sc); 428 s->emitComment(sc);
428 } 429 }
429 sc->pop(); 430 sc->pop();
430 buf->writestring(")\n"); 431 if (buf->offset == offset2)
432 {
433 /* Didn't write out any members, so back out last write
434 */
435 buf->offset = offset1;
436 }
437 else
438 buf->writestring(")\n");
431 } 439 }
432 } 440 }
433 441
434 void emitProtection(OutBuffer *buf, PROT prot) 442 void emitProtection(OutBuffer *buf, PROT prot)
435 { 443 {
446 buf->printf("%s ", p); 454 buf->printf("%s ", p);
447 } 455 }
448 456
449 void Dsymbol::emitComment(Scope *sc) { } 457 void Dsymbol::emitComment(Scope *sc) { }
450 void InvariantDeclaration::emitComment(Scope *sc) { } 458 void InvariantDeclaration::emitComment(Scope *sc) { }
451 //void PostBlitDeclaration::emitComment(Scope *sc) { } 459 #if DMDV2
460 void PostBlitDeclaration::emitComment(Scope *sc) { }
461 #endif
452 void DtorDeclaration::emitComment(Scope *sc) { } 462 void DtorDeclaration::emitComment(Scope *sc) { }
453 void StaticCtorDeclaration::emitComment(Scope *sc) { } 463 void StaticCtorDeclaration::emitComment(Scope *sc) { }
454 void StaticDtorDeclaration::emitComment(Scope *sc) { } 464 void StaticDtorDeclaration::emitComment(Scope *sc) { }
455 void ClassInfoDeclaration::emitComment(Scope *sc) { } 465 void ClassInfoDeclaration::emitComment(Scope *sc) { }
456 void ModuleInfoDeclaration::emitComment(Scope *sc) { } 466 void ModuleInfoDeclaration::emitComment(Scope *sc) { }
523 void TemplateDeclaration::emitComment(Scope *sc) 533 void TemplateDeclaration::emitComment(Scope *sc)
524 { 534 {
525 //printf("TemplateDeclaration::emitComment() '%s', kind = %s\n", toChars(), kind()); 535 //printf("TemplateDeclaration::emitComment() '%s', kind = %s\n", toChars(), kind());
526 if (prot() == PROTprivate) 536 if (prot() == PROTprivate)
527 return; 537 return;
528 if (!comment) 538
529 return; 539 unsigned char *com = comment;
530
531 OutBuffer *buf = sc->docbuf;
532 DocComment *dc = DocComment::parse(sc, this, comment);
533 unsigned o;
534 int hasmembers = 1; 540 int hasmembers = 1;
535 541
536 Dsymbol *ss = this; 542 Dsymbol *ss = this;
537 543
538 if (onemember) 544 if (onemember)
540 ss = onemember->isAggregateDeclaration(); 546 ss = onemember->isAggregateDeclaration();
541 if (!ss) 547 if (!ss)
542 { 548 {
543 ss = onemember->isFuncDeclaration(); 549 ss = onemember->isFuncDeclaration();
544 if (ss) 550 if (ss)
545 hasmembers = 0; 551 { hasmembers = 0;
552 if (com != ss->comment)
553 com = Lexer::combineComments(com, ss->comment);
554 }
546 else 555 else
547 ss = this; 556 ss = this;
548 } 557 }
549 } 558 }
559
560 if (!com)
561 return;
562
563 OutBuffer *buf = sc->docbuf;
564 DocComment *dc = DocComment::parse(sc, this, com);
565 unsigned o;
550 566
551 if (!dc) 567 if (!dc)
552 { 568 {
553 ss->emitDitto(sc); 569 ss->emitDitto(sc);
554 return; 570 return;
665 buf->writestring("abstract "); 681 buf->writestring("abstract ");
666 if (d->isStatic()) 682 if (d->isStatic())
667 buf->writestring("static "); 683 buf->writestring("static ");
668 if (d->isConst()) 684 if (d->isConst())
669 buf->writestring("const "); 685 buf->writestring("const ");
670 #if V2 686 #if DMDV2
671 if (d->isInvariant()) 687 if (d->isInvariant())
672 buf->writestring("invariant "); 688 buf->writestring("invariant ");
673 #endif 689 #endif
674 if (d->isFinal()) 690 if (d->isFinal())
675 buf->writestring("final "); 691 buf->writestring("final ");
741 TemplateDeclaration *td; 757 TemplateDeclaration *td;
742 758
743 if (parent && 759 if (parent &&
744 (td = parent->isTemplateDeclaration()) != NULL && 760 (td = parent->isTemplateDeclaration()) != NULL &&
745 td->onemember == this) 761 td->onemember == this)
746 { HdrGenState hgs; 762 { /* It's a function template
763 */
764 HdrGenState hgs;
747 unsigned o = buf->offset; 765 unsigned o = buf->offset;
748 TypeFunction *tf = (TypeFunction *)type; 766 TypeFunction *tf = (TypeFunction *)type;
749 767
750 hgs.ddoc = 1; 768 hgs.ddoc = 1;
751 prefix(buf, td); 769 prefix(buf, td);
1579 1597
1580 /* f->type may be NULL for template members. 1598 /* f->type may be NULL for template members.
1581 */ 1599 */
1582 if (f && f->type) 1600 if (f && f->type)
1583 { 1601 {
1584 TypeFunction *tf = (TypeFunction *)f->type; 1602 TypeFunction *tf;
1603 if (f->originalType)
1604 {
1605 tf = (TypeFunction *)f->originalType;
1606 }
1607 else
1608 tf = (TypeFunction *)f->type;
1585 1609
1586 if (tf->parameters) 1610 if (tf->parameters)
1587 { 1611 {
1588 for (size_t k = 0; k < tf->parameters->dim; k++) 1612 for (size_t k = 0; k < tf->parameters->dim; k++)
1589 { Argument *arg = (Argument *)tf->parameters->data[k]; 1613 { Argument *arg = (Argument *)tf->parameters->data[k];