comparison dmd/attrib.c @ 737:041c1596d217

Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... } Changed the way struct/class fields are added, first small part of cleaning up these... Make struct/class/union fields aware of any anonymous struct/union they might be part of, not yet really useful, but part of getting better union support.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 28 Oct 2008 15:41:09 +0100
parents 55f6c2e454d7
children 661384d6a936
comparison
equal deleted inserted replaced
736:e4e50f4b58cd 737:041c1596d217
499 AlignDeclaration::AlignDeclaration(Loc loc, unsigned sa, Array *decl) 499 AlignDeclaration::AlignDeclaration(Loc loc, unsigned sa, Array *decl)
500 : AttribDeclaration(decl) 500 : AttribDeclaration(decl)
501 { 501 {
502 this->loc = loc; 502 this->loc = loc;
503 salign = sa; 503 salign = sa;
504
505 if (global.params.warnings && salign != 1)
506 warning("%s: align(%d) is not implemented and specified to be unportable anyway, use align(1) and manual fillers instead", loc.toChars(), salign);
507 } 504 }
508 505
509 Dsymbol *AlignDeclaration::syntaxCopy(Dsymbol *s) 506 Dsymbol *AlignDeclaration::syntaxCopy(Dsymbol *s)
510 { 507 {
511 AlignDeclaration *ad; 508 AlignDeclaration *ad;
515 return ad; 512 return ad;
516 } 513 }
517 514
518 void AlignDeclaration::semantic(Scope *sc) 515 void AlignDeclaration::semantic(Scope *sc)
519 { 516 {
517 // LDC
518 // we only support packed structs, as from the spec: align(1) struct Packed { ... }
519 // other alignments are simply ignored. my tests show this is what llvm-gcc does too ...
520
520 //printf("\tAlignDeclaration::semantic '%s'\n",toChars()); 521 //printf("\tAlignDeclaration::semantic '%s'\n",toChars());
521 if (decl) 522 if (decl)
522 { unsigned salign_save = sc->structalign; 523 { unsigned salign_save = sc->structalign;
523 524
524 sc->structalign = salign;
525 for (unsigned i = 0; i < decl->dim; i++) 525 for (unsigned i = 0; i < decl->dim; i++)
526 { 526 {
527 Dsymbol *s = (Dsymbol *)decl->data[i]; 527 Dsymbol *s = (Dsymbol *)decl->data[i];
528 528
529 s->semantic(sc); 529 if (s->isStructDeclaration() && salign == 1)
530 {
531 sc->structalign = salign;
532 s->semantic(sc);
533 sc->structalign = salign_save;
534 }
535 else
536 {
537 s->semantic(sc);
538 }
530 } 539 }
531 sc->structalign = salign_save; 540 sc->structalign = salign_save;
532 } 541 }
533 else 542 else
534 sc->structalign = salign; 543 assert(0 && "what kind of align use triggers this?");
535 } 544 }
536 545
537 546
538 void AlignDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 547 void AlignDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
539 { 548 {
656 ad->alignmember(aad.structalign, aad.alignsize, &sc->offset); 665 ad->alignmember(aad.structalign, aad.alignsize, &sc->offset);
657 //ad->structsize = sc->offset; 666 //ad->structsize = sc->offset;
658 //printf("sc->offset = %d\n", sc->offset); 667 //printf("sc->offset = %d\n", sc->offset);
659 668
660 // Add members of aad to ad 669 // Add members of aad to ad
661 //printf("\tadding members of aad to '%s'\n", ad->toChars()); 670 //printf("\tadding members of aad (%p) to '%s'\n", &aad, ad->toChars());
662 for (unsigned i = 0; i < aad.fields.dim; i++) 671 for (unsigned i = 0; i < aad.fields.dim; i++)
663 { 672 {
664 VarDeclaration *v = (VarDeclaration *)aad.fields.data[i]; 673 VarDeclaration *v = (VarDeclaration *)aad.fields.data[i];
665 674
666 v->offset += sc->offset; 675 v->offset += sc->offset;
676
677 // LDC
678 if (!v->anonDecl)
679 v->anonDecl = this;
680
667 ad->fields.push(v); 681 ad->fields.push(v);
668 } 682 }
669 683
670 // Add size of aad to ad 684 // Add size of aad to ad
671 if (adisunion) 685 if (adisunion)