Mercurial > projects > ldc
comparison dmd2/attrib.c @ 1526:54b3c1394d62
Merged dmdfe 2.031.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Tue, 07 Jul 2009 02:26:11 +0100 |
parents | 638d16625da2 |
children | e4f7b5d9c68a |
comparison
equal
deleted
inserted
replaced
1525:d28cd7c45267 | 1526:54b3c1394d62 |
---|---|
24 #include "dsymbol.h" | 24 #include "dsymbol.h" |
25 #include "aggregate.h" | 25 #include "aggregate.h" |
26 #include "module.h" | 26 #include "module.h" |
27 #include "parse.h" | 27 #include "parse.h" |
28 #include "template.h" | 28 #include "template.h" |
29 #if TARGET_NET | |
30 #include "frontend.net/pragma.h" | |
31 #endif | |
29 | 32 |
30 #if IN_LLVM | 33 #if IN_LLVM |
31 #include "../gen/enums.h" | 34 #include "../gen/enums.h" |
32 | 35 |
33 #include "llvm/Support/CommandLine.h" | 36 #include "llvm/Support/CommandLine.h" |
70 { Dsymbol *s = (Dsymbol *)d->data[i]; | 73 { Dsymbol *s = (Dsymbol *)d->data[i]; |
71 m |= s->addMember(sc, sd, m | memnum); | 74 m |= s->addMember(sc, sd, m | memnum); |
72 } | 75 } |
73 } | 76 } |
74 return m; | 77 return m; |
78 } | |
79 | |
80 void AttribDeclaration::semanticNewSc(Scope *sc, | |
81 unsigned stc, enum LINK linkage, enum PROT protection, int explicitProtection, | |
82 unsigned structalign) | |
83 { | |
84 if (decl) | |
85 { | |
86 Scope *newsc = sc; | |
87 if (stc != sc->stc || | |
88 linkage != sc->linkage || | |
89 protection != sc->protection || | |
90 explicitProtection != sc->explicitProtection || | |
91 structalign != sc->structalign) | |
92 { | |
93 // create new one for changes | |
94 newsc = new Scope(*sc); | |
95 newsc->flags &= ~SCOPEfree; | |
96 newsc->stc = stc; | |
97 newsc->linkage = linkage; | |
98 newsc->protection = protection; | |
99 newsc->explicitProtection = explicitProtection; | |
100 newsc->structalign = structalign; | |
101 } | |
102 for (unsigned i = 0; i < decl->dim; i++) | |
103 { Dsymbol *s = (Dsymbol *)decl->data[i]; | |
104 | |
105 s->semantic(newsc); | |
106 } | |
107 if (newsc != sc) | |
108 { | |
109 sc->offset = newsc->offset; | |
110 newsc->pop(); | |
111 } | |
112 } | |
75 } | 113 } |
76 | 114 |
77 void AttribDeclaration::semantic(Scope *sc) | 115 void AttribDeclaration::semantic(Scope *sc) |
78 { | 116 { |
79 Array *d = include(sc, NULL); | 117 Array *d = include(sc, NULL); |
303 } | 341 } |
304 | 342 |
305 void StorageClassDeclaration::semantic(Scope *sc) | 343 void StorageClassDeclaration::semantic(Scope *sc) |
306 { | 344 { |
307 if (decl) | 345 if (decl) |
308 { unsigned stc_save = sc->stc; | 346 { |
309 | 347 #if 1 |
310 if (stc & (STCauto | STCscope | STCstatic | STCextern)) | 348 unsigned scstc = sc->stc; |
311 sc->stc &= ~(STCauto | STCscope | STCstatic | STCextern); | 349 |
350 /* These sets of storage classes are mutually exclusive, | |
351 * so choose the innermost or most recent one. | |
352 */ | |
353 if (stc & (STCauto | STCscope | STCstatic | STCextern | STCmanifest)) | |
354 scstc &= ~(STCauto | STCscope | STCstatic | STCextern | STCmanifest); | |
355 if (stc & (STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared)) | |
356 scstc &= ~(STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared); | |
357 if (stc & (STCconst | STCimmutable | STCmanifest)) | |
358 scstc &= ~(STCconst | STCimmutable | STCmanifest); | |
359 if (stc & (STCgshared | STCshared | STCtls)) | |
360 scstc &= ~(STCgshared | STCshared | STCtls); | |
361 scstc |= stc; | |
362 | |
363 semanticNewSc(sc, scstc, sc->linkage, sc->protection, sc->explicitProtection, sc->structalign); | |
364 #else | |
365 unsigned stc_save = sc->stc; | |
366 | |
367 /* These sets of storage classes are mutually exclusive, | |
368 * so choose the innermost or most recent one. | |
369 */ | |
370 if (stc & (STCauto | STCscope | STCstatic | STCextern | STCmanifest)) | |
371 sc->stc &= ~(STCauto | STCscope | STCstatic | STCextern | STCmanifest); | |
372 if (stc & (STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared)) | |
373 sc->stc &= ~(STCauto | STCscope | STCstatic | STCtls | STCmanifest | STCgshared); | |
374 if (stc & (STCconst | STCimmutable | STCmanifest)) | |
375 sc->stc &= ~(STCconst | STCimmutable | STCmanifest); | |
376 if (stc & (STCgshared | STCshared | STCtls)) | |
377 sc->stc &= ~(STCgshared | STCshared | STCtls); | |
312 sc->stc |= stc; | 378 sc->stc |= stc; |
313 for (unsigned i = 0; i < decl->dim; i++) | 379 for (unsigned i = 0; i < decl->dim; i++) |
314 { | 380 { |
315 Dsymbol *s = (Dsymbol *)decl->data[i]; | 381 Dsymbol *s = (Dsymbol *)decl->data[i]; |
316 | 382 |
317 s->semantic(sc); | 383 s->semantic(sc); |
318 } | 384 } |
319 sc->stc = stc_save; | 385 sc->stc = stc_save; |
320 } | 386 #endif |
321 else | 387 } |
322 sc->stc = stc; | |
323 } | 388 } |
324 | 389 |
325 void StorageClassDeclaration::stcToCBuffer(OutBuffer *buf, int stc) | 390 void StorageClassDeclaration::stcToCBuffer(OutBuffer *buf, int stc) |
326 { | 391 { |
327 struct SCstring | 392 struct SCstring |
391 | 456 |
392 void LinkDeclaration::semantic(Scope *sc) | 457 void LinkDeclaration::semantic(Scope *sc) |
393 { | 458 { |
394 //printf("LinkDeclaration::semantic(linkage = %d, decl = %p)\n", linkage, decl); | 459 //printf("LinkDeclaration::semantic(linkage = %d, decl = %p)\n", linkage, decl); |
395 if (decl) | 460 if (decl) |
396 { enum LINK linkage_save = sc->linkage; | 461 { |
462 #if 1 | |
463 semanticNewSc(sc, sc->stc, linkage, sc->protection, sc->explicitProtection, sc->structalign); | |
464 #else | |
465 enum LINK linkage_save = sc->linkage; | |
397 | 466 |
398 sc->linkage = linkage; | 467 sc->linkage = linkage; |
399 for (unsigned i = 0; i < decl->dim; i++) | 468 for (unsigned i = 0; i < decl->dim; i++) |
400 { | 469 { |
401 Dsymbol *s = (Dsymbol *)decl->data[i]; | 470 Dsymbol *s = (Dsymbol *)decl->data[i]; |
402 | 471 |
403 s->semantic(sc); | 472 s->semantic(sc); |
404 } | 473 } |
405 sc->linkage = linkage_save; | 474 sc->linkage = linkage_save; |
406 } | 475 #endif |
407 else | |
408 { | |
409 sc->linkage = linkage; | |
410 } | 476 } |
411 } | 477 } |
412 | 478 |
413 void LinkDeclaration::semantic3(Scope *sc) | 479 void LinkDeclaration::semantic3(Scope *sc) |
414 { | 480 { |
479 } | 545 } |
480 | 546 |
481 void ProtDeclaration::semantic(Scope *sc) | 547 void ProtDeclaration::semantic(Scope *sc) |
482 { | 548 { |
483 if (decl) | 549 if (decl) |
484 { enum PROT protection_save = sc->protection; | 550 { |
551 #if 1 | |
552 semanticNewSc(sc, sc->stc, sc->linkage, protection, 1, sc->structalign); | |
553 #else | |
554 enum PROT protection_save = sc->protection; | |
485 int explicitProtection_save = sc->explicitProtection; | 555 int explicitProtection_save = sc->explicitProtection; |
486 | 556 |
487 sc->protection = protection; | 557 sc->protection = protection; |
488 sc->explicitProtection = 1; | 558 sc->explicitProtection = 1; |
489 for (unsigned i = 0; i < decl->dim; i++) | 559 for (unsigned i = 0; i < decl->dim; i++) |
492 | 562 |
493 s->semantic(sc); | 563 s->semantic(sc); |
494 } | 564 } |
495 sc->protection = protection_save; | 565 sc->protection = protection_save; |
496 sc->explicitProtection = explicitProtection_save; | 566 sc->explicitProtection = explicitProtection_save; |
497 } | 567 #endif |
498 else | 568 } |
499 { sc->protection = protection; | 569 } |
500 sc->explicitProtection = 1; | 570 |
501 } | 571 void ProtDeclaration::protectionToCBuffer(OutBuffer *buf, enum PROT protection) |
502 } | 572 { |
503 | 573 const char *p; |
504 void ProtDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
505 { const char *p; | |
506 | 574 |
507 switch (protection) | 575 switch (protection) |
508 { | 576 { |
509 case PROTprivate: p = "private"; break; | 577 case PROTprivate: p = "private"; break; |
510 case PROTpackage: p = "package"; break; | 578 case PROTpackage: p = "package"; break; |
514 default: | 582 default: |
515 assert(0); | 583 assert(0); |
516 break; | 584 break; |
517 } | 585 } |
518 buf->writestring(p); | 586 buf->writestring(p); |
587 buf->writeByte(' '); | |
588 } | |
589 | |
590 void ProtDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) | |
591 { | |
592 protectionToCBuffer(buf, protection); | |
519 AttribDeclaration::toCBuffer(buf, hgs); | 593 AttribDeclaration::toCBuffer(buf, hgs); |
520 } | 594 } |
521 | 595 |
522 /********************************* AlignDeclaration ****************************/ | 596 /********************************* AlignDeclaration ****************************/ |
523 | 597 |
543 // we only support packed structs, as from the spec: align(1) struct Packed { ... } | 617 // we only support packed structs, as from the spec: align(1) struct Packed { ... } |
544 // other alignments are simply ignored. my tests show this is what llvm-gcc does too ... | 618 // other alignments are simply ignored. my tests show this is what llvm-gcc does too ... |
545 | 619 |
546 //printf("\tAlignDeclaration::semantic '%s'\n",toChars()); | 620 //printf("\tAlignDeclaration::semantic '%s'\n",toChars()); |
547 if (decl) | 621 if (decl) |
548 { unsigned salign_save = sc->structalign; | 622 { |
623 #if 1 | |
624 semanticNewSc(sc, sc->stc, sc->linkage, sc->protection, sc->explicitProtection, salign); | |
625 #else | |
626 unsigned salign_save = sc->structalign; | |
627 | |
549 #if IN_DMD | 628 #if IN_DMD |
550 sc->structalign = salign; | 629 sc->structalign = salign; |
551 #endif | 630 #endif |
552 for (unsigned i = 0; i < decl->dim; i++) | 631 for (unsigned i = 0; i < decl->dim; i++) |
553 { | 632 { |
554 Dsymbol *s = (Dsymbol *)decl->data[i]; | 633 Dsymbol *s = (Dsymbol *)decl->data[i]; |
555 | 634 |
635 #if IN_LLVM | |
556 if (s->isStructDeclaration() && salign == 1) | 636 if (s->isStructDeclaration() && salign == 1) |
557 { | 637 { |
558 sc->structalign = salign; | 638 sc->structalign = salign; |
559 s->semantic(sc); | 639 s->semantic(sc); |
560 sc->structalign = salign_save; | 640 sc->structalign = salign_save; |
561 } | 641 } |
562 else | 642 else |
563 { | 643 { |
644 #endif | |
564 s->semantic(sc); | 645 s->semantic(sc); |
565 } | 646 #if IN_LLVM |
647 } | |
648 #endif | |
566 } | 649 } |
567 sc->structalign = salign_save; | 650 sc->structalign = salign_save; |
651 #endif | |
568 } | 652 } |
569 else | 653 else |
570 assert(0 && "what kind of align use triggers this?"); | 654 assert(0 && "what kind of align use triggers this?"); |
571 } | 655 } |
572 | 656 |
582 AnonDeclaration::AnonDeclaration(Loc loc, int isunion, Array *decl) | 666 AnonDeclaration::AnonDeclaration(Loc loc, int isunion, Array *decl) |
583 : AttribDeclaration(decl) | 667 : AttribDeclaration(decl) |
584 { | 668 { |
585 this->loc = loc; | 669 this->loc = loc; |
586 this->isunion = isunion; | 670 this->isunion = isunion; |
587 this->scope = NULL; | |
588 this->sem = 0; | 671 this->sem = 0; |
589 } | 672 } |
590 | 673 |
591 Dsymbol *AnonDeclaration::syntaxCopy(Dsymbol *s) | 674 Dsymbol *AnonDeclaration::syntaxCopy(Dsymbol *s) |
592 { | 675 { |
893 if (!sa || !sa->isFuncDeclaration()) | 976 if (!sa || !sa->isFuncDeclaration()) |
894 error("function name expected for start address, not '%s'", e->toChars()); | 977 error("function name expected for start address, not '%s'", e->toChars()); |
895 } | 978 } |
896 goto Lnodecl; | 979 goto Lnodecl; |
897 } | 980 } |
898 | 981 #if TARGET_NET |
982 else if (ident == Lexer::idPool("assembly")) | |
983 { | |
984 if (!args || args->dim != 1) | |
985 error("pragma has invalid number of arguments"); | |
986 else | |
987 { | |
988 Expression *e = (Expression *)args->data[0]; | |
989 e = e->semantic(sc); | |
990 e = e->optimize(WANTvalue | WANTinterpret); | |
991 args->data[0] = (void *)e; | |
992 if (e->op != TOKstring) | |
993 { | |
994 error("string expected, not '%s'", e->toChars()); | |
995 } | |
996 PragmaScope* pragma = new PragmaScope(this, sc->parent, static_cast<StringExp*>(e)); | |
997 decl = new Array; | |
998 decl->push(pragma); | |
999 } | |
1000 } | |
1001 #endif // TARGET_NET | |
899 // LDC | 1002 // LDC |
900 #if IN_LLVM | 1003 #if IN_LLVM |
901 | 1004 |
902 // pragma(intrinsic, "string") { funcdecl(s) } | 1005 // pragma(intrinsic, "string") { funcdecl(s) } |
903 else if (ident == Id::intrinsic) | 1006 else if (ident == Id::intrinsic) |