Mercurial > projects > ldc
comparison dmd/declaration.h @ 1587:def7a1d494fd
Merge DMD 1.051
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Fri, 06 Nov 2009 23:58:01 +0100 |
parents | 05c235309d6f |
children | a413ae7329bf |
comparison
equal
deleted
inserted
replaced
1586:7f728c52e63c | 1587:def7a1d494fd |
---|---|
1 | 1 |
2 // Compiler implementation of the D programming language | 2 // Compiler implementation of the D programming language |
3 // Copyright (c) 1999-2008 by Digital Mars | 3 // Copyright (c) 1999-2009 by Digital Mars |
4 // All Rights Reserved | 4 // All Rights Reserved |
5 // written by Walter Bright | 5 // written by Walter Bright |
6 // http://www.digitalmars.com | 6 // http://www.digitalmars.com |
7 // License for redistribution is by either the Artistic License | 7 // License for redistribution is by either the Artistic License |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | 8 // in artistic.txt, or the GNU General Public License in gnu.txt. |
90 FuncDeclaration *lastf; // last matching function we found | 90 FuncDeclaration *lastf; // last matching function we found |
91 FuncDeclaration *nextf; // current matching function | 91 FuncDeclaration *nextf; // current matching function |
92 FuncDeclaration *anyf; // pick a func, any func, to use for error recovery | 92 FuncDeclaration *anyf; // pick a func, any func, to use for error recovery |
93 }; | 93 }; |
94 | 94 |
95 void overloadResolveX(Match *m, FuncDeclaration *f, Expressions *arguments, Module* from); | 95 void overloadResolveX(Match *m, FuncDeclaration *f, |
96 Expression *ethis, Expressions *arguments, Module *from); | |
96 int overloadApply(Module* from, FuncDeclaration *fstart, | 97 int overloadApply(Module* from, FuncDeclaration *fstart, |
97 int (*fp)(void *, FuncDeclaration *), | 98 int (*fp)(void *, FuncDeclaration *), |
98 void *param); | 99 void *param); |
99 | 100 |
100 /**************************************************************/ | 101 /**************************************************************/ |
113 const char *kind(); | 114 const char *kind(); |
114 unsigned size(Loc loc); | 115 unsigned size(Loc loc); |
115 void checkModify(Loc loc, Scope *sc, Type *t); | 116 void checkModify(Loc loc, Scope *sc, Type *t); |
116 | 117 |
117 void emitComment(Scope *sc); | 118 void emitComment(Scope *sc); |
119 void toJsonBuffer(OutBuffer *buf); | |
118 void toDocBuffer(OutBuffer *buf); | 120 void toDocBuffer(OutBuffer *buf); |
119 | 121 |
120 char *mangle(); | 122 char *mangle(); |
121 int isStatic() { return storage_class & STCstatic; } | 123 int isStatic() { return storage_class & STCstatic; } |
122 virtual int isStaticConstructor(); | 124 virtual int isStaticConstructor(); |
123 virtual int isStaticDestructor(); | 125 virtual int isStaticDestructor(); |
124 virtual int isDelete(); | 126 virtual int isDelete(); |
125 virtual int isDataseg(); | 127 virtual int isDataseg(); |
128 virtual int isThreadlocal(); | |
126 virtual int isCodeseg(); | 129 virtual int isCodeseg(); |
127 int isCtorinit() { return storage_class & STCctorinit; } | 130 int isCtorinit() { return storage_class & STCctorinit; } |
128 int isFinal() { return storage_class & STCfinal; } | 131 int isFinal() { return storage_class & STCfinal; } |
129 int isAbstract() { return storage_class & STCabstract; } | 132 int isAbstract() { return storage_class & STCabstract; } |
130 int isConst() { return storage_class & STCconst; } | 133 int isConst() { return storage_class & STCconst; } |
131 int isInvariant() { return 0; } | 134 int isInvariant() { return storage_class & STCinvariant; } |
132 int isAuto() { return storage_class & STCauto; } | 135 int isAuto() { return storage_class & STCauto; } |
133 int isScope() { return storage_class & STCscope; } | 136 int isScope() { return storage_class & STCscope; } |
134 int isSynchronized() { return storage_class & STCsynchronized; } | 137 int isSynchronized() { return storage_class & STCsynchronized; } |
135 int isParameter() { return storage_class & STCparameter; } | 138 int isParameter() { return storage_class & STCparameter; } |
136 int isDeprecated() { return storage_class & STCdeprecated; } | 139 int isDeprecated() { return storage_class & STCdeprecated; } |
253 struct VarDeclaration : Declaration | 256 struct VarDeclaration : Declaration |
254 { | 257 { |
255 Initializer *init; | 258 Initializer *init; |
256 unsigned offset; | 259 unsigned offset; |
257 int noscope; // no scope semantics | 260 int noscope; // no scope semantics |
261 #if DMDV2 | |
262 FuncDeclarations nestedrefs; // referenced by these lexically nested functions | |
263 #else | |
258 int nestedref; // referenced by a lexically nested function | 264 int nestedref; // referenced by a lexically nested function |
265 #endif | |
259 int ctorinit; // it has been initialized in a ctor | 266 int ctorinit; // it has been initialized in a ctor |
260 int onstack; // 1: it has been allocated on the stack | 267 int onstack; // 1: it has been allocated on the stack |
261 // 2: on stack, run destructor anyway | 268 // 2: on stack, run destructor anyway |
262 int canassign; // it can be assigned to | 269 int canassign; // it can be assigned to |
263 Dsymbol *aliassym; // if redone as alias to another symbol | 270 Dsymbol *aliassym; // if redone as alias to another symbol |
264 Expression *value; // when interpreting, this is the value | 271 Expression *value; // when interpreting, this is the value |
265 // (NULL if value not determinable) | 272 // (NULL if value not determinable) |
266 Scope *scope; // !=NULL means context to use | 273 #if DMDV2 |
274 VarDeclaration *rundtor; // if !NULL, rundtor is tested at runtime to see | |
275 // if the destructor should be run. Used to prevent | |
276 // dtor calls on postblitted vars | |
277 #endif | |
267 | 278 |
268 VarDeclaration(Loc loc, Type *t, Identifier *id, Initializer *init); | 279 VarDeclaration(Loc loc, Type *t, Identifier *id, Initializer *init); |
269 Dsymbol *syntaxCopy(Dsymbol *); | 280 Dsymbol *syntaxCopy(Dsymbol *); |
270 void semantic(Scope *sc); | 281 void semantic(Scope *sc); |
271 void semantic2(Scope *sc); | 282 void semantic2(Scope *sc); |
276 Initializer *hinit; | 287 Initializer *hinit; |
277 #endif | 288 #endif |
278 int needThis(); | 289 int needThis(); |
279 int isImportedSymbol(); | 290 int isImportedSymbol(); |
280 int isDataseg(); | 291 int isDataseg(); |
292 int isThreadlocal(); | |
281 int hasPointers(); | 293 int hasPointers(); |
282 Expression *callScopeDtor(); | 294 #if DMDV2 |
295 int canTakeAddressOf(); | |
296 int needsAutoDtor(); | |
297 #endif | |
298 Expression *callScopeDtor(Scope *sc); | |
283 ExpInitializer *getExpInitializer(); | 299 ExpInitializer *getExpInitializer(); |
300 Expression *getConstInitializer(); | |
284 void checkCtorConstInit(); | 301 void checkCtorConstInit(); |
285 void checkNestedReference(Scope *sc, Loc loc); | 302 void checkNestedReference(Scope *sc, Loc loc); |
286 Dsymbol *toAlias(); | 303 Dsymbol *toAlias(); |
287 | 304 |
288 virtual int isSameAsInitializer(); | 305 virtual int isSameAsInitializer(); |
343 ClassInfoDeclaration(ClassDeclaration *cd); | 360 ClassInfoDeclaration(ClassDeclaration *cd); |
344 Dsymbol *syntaxCopy(Dsymbol *); | 361 Dsymbol *syntaxCopy(Dsymbol *); |
345 void semantic(Scope *sc); | 362 void semantic(Scope *sc); |
346 | 363 |
347 void emitComment(Scope *sc); | 364 void emitComment(Scope *sc); |
365 void toJsonBuffer(OutBuffer *buf); | |
348 | 366 |
349 #if IN_DMD | 367 #if IN_DMD |
350 Symbol *toSymbol(); | 368 Symbol *toSymbol(); |
351 #endif | 369 #endif |
352 | 370 |
360 ModuleInfoDeclaration(Module *mod); | 378 ModuleInfoDeclaration(Module *mod); |
361 Dsymbol *syntaxCopy(Dsymbol *); | 379 Dsymbol *syntaxCopy(Dsymbol *); |
362 void semantic(Scope *sc); | 380 void semantic(Scope *sc); |
363 | 381 |
364 void emitComment(Scope *sc); | 382 void emitComment(Scope *sc); |
383 void toJsonBuffer(OutBuffer *buf); | |
365 | 384 |
366 #if IN_DMD | 385 #if IN_DMD |
367 Symbol *toSymbol(); | 386 Symbol *toSymbol(); |
368 #endif | 387 #endif |
369 }; | 388 }; |
375 TypeInfoDeclaration(Type *tinfo, int internal); | 394 TypeInfoDeclaration(Type *tinfo, int internal); |
376 Dsymbol *syntaxCopy(Dsymbol *); | 395 Dsymbol *syntaxCopy(Dsymbol *); |
377 void semantic(Scope *sc); | 396 void semantic(Scope *sc); |
378 | 397 |
379 void emitComment(Scope *sc); | 398 void emitComment(Scope *sc); |
399 void toJsonBuffer(OutBuffer *buf); | |
380 | 400 |
381 #if IN_DMD | 401 #if IN_DMD |
382 void toObjFile(int multiobj); // compile to .obj file | 402 void toObjFile(int multiobj); // compile to .obj file |
383 Symbol *toSymbol(); | 403 Symbol *toSymbol(); |
384 virtual void toDt(dt_t **pdt); | 404 virtual void toDt(dt_t **pdt); |
614 BUILTINfabs, // std.math.fabs | 634 BUILTINfabs, // std.math.fabs |
615 }; | 635 }; |
616 | 636 |
617 Expression *eval_builtin(enum BUILTIN builtin, Expressions *arguments); | 637 Expression *eval_builtin(enum BUILTIN builtin, Expressions *arguments); |
618 | 638 |
639 #else | |
640 enum BUILTIN { }; | |
619 #endif | 641 #endif |
620 | 642 |
621 struct FuncDeclaration : Declaration | 643 struct FuncDeclaration : Declaration |
622 { | 644 { |
623 Array *fthrows; // Array of Type's of exceptions (not used) | 645 Array *fthrows; // Array of Type's of exceptions (not used) |
624 Statement *frequire; | 646 Statement *frequire; |
625 Statement *fensure; | 647 Statement *fensure; |
626 Statement *fbody; | 648 Statement *fbody; |
649 | |
650 FuncDeclarations foverrides; // functions this function overrides | |
651 FuncDeclaration *fdrequire; // function that does the in contract | |
652 FuncDeclaration *fdensure; // function that does the out contract | |
627 | 653 |
628 Identifier *outId; // identifier for out statement | 654 Identifier *outId; // identifier for out statement |
629 VarDeclaration *vresult; // variable corresponding to outId | 655 VarDeclaration *vresult; // variable corresponding to outId |
630 LabelDsymbol *returnLabel; // where the return goes | 656 LabelDsymbol *returnLabel; // where the return goes |
631 | 657 |
656 int introducing; // !=0 if 'introducing' function | 682 int introducing; // !=0 if 'introducing' function |
657 Type *tintro; // if !=NULL, then this is the type | 683 Type *tintro; // if !=NULL, then this is the type |
658 // of the 'introducing' function | 684 // of the 'introducing' function |
659 // this one is overriding | 685 // this one is overriding |
660 int inferRetType; // !=0 if return type is to be inferred | 686 int inferRetType; // !=0 if return type is to be inferred |
661 Scope *scope; // !=NULL means context to use | |
662 | 687 |
663 // Things that should really go into Scope | 688 // Things that should really go into Scope |
664 int hasReturnExp; // 1 if there's a return exp; statement | 689 int hasReturnExp; // 1 if there's a return exp; statement |
665 // 2 if there's a throw statement | 690 // 2 if there's a throw statement |
666 // 4 if there's an assert(0) | 691 // 4 if there's an assert(0) |
690 FuncDeclaration(Loc loc, Loc endloc, Identifier *id, enum STC storage_class, Type *type); | 715 FuncDeclaration(Loc loc, Loc endloc, Identifier *id, enum STC storage_class, Type *type); |
691 Dsymbol *syntaxCopy(Dsymbol *); | 716 Dsymbol *syntaxCopy(Dsymbol *); |
692 void semantic(Scope *sc); | 717 void semantic(Scope *sc); |
693 void semantic2(Scope *sc); | 718 void semantic2(Scope *sc); |
694 void semantic3(Scope *sc); | 719 void semantic3(Scope *sc); |
720 // called from semantic3 | |
721 void varArgs(Scope *sc, TypeFunction*, VarDeclaration *&, VarDeclaration *&); | |
722 | |
695 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | 723 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
696 void bodyToCBuffer(OutBuffer *buf, HdrGenState *hgs); | 724 void bodyToCBuffer(OutBuffer *buf, HdrGenState *hgs); |
697 int overrides(FuncDeclaration *fd); | 725 int overrides(FuncDeclaration *fd); |
698 int findVtblIndex(Array *vtbl, int dim); | 726 int findVtblIndex(Array *vtbl, int dim); |
699 int overloadInsert(Dsymbol *s); | 727 int overloadInsert(Dsymbol *s); |
700 FuncDeclaration *overloadExactMatch(Type *t, Module* from); | 728 FuncDeclaration *overloadExactMatch(Type *t, Module* from); |
701 FuncDeclaration *overloadResolve(Loc loc, Expressions *arguments, Module* from); | 729 FuncDeclaration *overloadResolve(Loc loc, Expression *ethis, Expressions *arguments, Module *from, int flags = 0); |
730 MATCH leastAsSpecialized(FuncDeclaration *g); | |
702 LabelDsymbol *searchLabel(Identifier *ident); | 731 LabelDsymbol *searchLabel(Identifier *ident); |
703 AggregateDeclaration *isThis(); | 732 AggregateDeclaration *isThis(); |
704 AggregateDeclaration *isMember2(); | 733 AggregateDeclaration *isMember2(); |
705 int getLevel(Loc loc, FuncDeclaration *fd); // lexical nesting level difference | 734 int getLevel(Loc loc, FuncDeclaration *fd); // lexical nesting level difference |
706 void appendExp(Expression *e); | 735 void appendExp(Expression *e); |
707 void appendState(Statement *s); | 736 void appendState(Statement *s); |
708 char *mangle(); | 737 char *mangle(); |
738 const char *toPrettyChars(); | |
709 int isMain(); | 739 int isMain(); |
710 int isWinMain(); | 740 int isWinMain(); |
711 int isDllMain(); | 741 int isDllMain(); |
742 enum BUILTIN isBuiltin(); | |
712 int isExport(); | 743 int isExport(); |
713 int isImportedSymbol(); | 744 int isImportedSymbol(); |
714 int isAbstract(); | 745 int isAbstract(); |
715 int isCodeseg(); | 746 int isCodeseg(); |
747 int isOverloadable(); | |
748 int isPure(); | |
716 virtual int isNested(); | 749 virtual int isNested(); |
717 int needThis(); | 750 int needThis(); |
718 virtual int isVirtual(); | 751 virtual int isVirtual(); |
719 virtual int isFinal(); | 752 virtual int isFinal(); |
720 virtual int addPreInvariant(); | 753 virtual int addPreInvariant(); |
721 virtual int addPostInvariant(); | 754 virtual int addPostInvariant(); |
722 Expression *interpret(InterState *istate, Expressions *arguments); | 755 Expression *interpret(InterState *istate, Expressions *arguments, Expression *thisexp = NULL); |
723 void inlineScan(); | 756 void inlineScan(); |
724 int canInline(int hasthis, int hdrscan = 0); | 757 int canInline(int hasthis, int hdrscan = 0); |
725 Expression *doInline(InlineScanState *iss, Expression *ethis, Array *arguments); | 758 Expression *doInline(InlineScanState *iss, Expression *ethis, Array *arguments); |
726 const char *kind(); | 759 const char *kind(); |
727 void toDocBuffer(OutBuffer *buf); | 760 void toDocBuffer(OutBuffer *buf); |
761 FuncDeclaration *isUnique(); | |
762 int needsClosure(); | |
763 Statement *mergeFrequire(Statement *); | |
764 Statement *mergeFensure(Statement *); | |
728 | 765 |
729 // LDC: give argument types to runtime functions | 766 // LDC: give argument types to runtime functions |
730 static FuncDeclaration *genCfunc(Arguments *args, Type *treturn, const char *name); | 767 static FuncDeclaration *genCfunc(Arguments *args, Type *treturn, const char *name); |
731 static FuncDeclaration *genCfunc(Arguments *args, Type *treturn, Identifier *id); | 768 static FuncDeclaration *genCfunc(Arguments *args, Type *treturn, Identifier *id); |
732 | 769 |
733 #if IN_DMD | 770 #if IN_DMD |
734 Symbol *toSymbol(); | 771 Symbol *toSymbol(); |
735 Symbol *toThunkSymbol(int offset); // thunk version | 772 Symbol *toThunkSymbol(int offset); // thunk version |
736 void toObjFile(int multiobj); // compile to .obj file | 773 void toObjFile(int multiobj); // compile to .obj file |
737 int cvMember(unsigned char *p); | 774 int cvMember(unsigned char *p); |
775 void buildClosure(IRState *irs); | |
738 #endif | 776 #endif |
739 | 777 |
740 FuncDeclaration *isFuncDeclaration() { return this; } | 778 FuncDeclaration *isFuncDeclaration() { return this; } |
741 | 779 |
742 #if IN_LLVM | 780 #if IN_LLVM |
768 | 806 |
769 // true if overridden with the pragma(allow_inline); stmt | 807 // true if overridden with the pragma(allow_inline); stmt |
770 bool allowInlining; | 808 bool allowInlining; |
771 #endif | 809 #endif |
772 }; | 810 }; |
811 | |
812 #if DMDV2 | |
813 FuncDeclaration *resolveFuncCall(Scope *sc, Loc loc, Dsymbol *s, | |
814 Objects *tiargs, | |
815 Expression *ethis, | |
816 Expressions *arguments, | |
817 int flags); | |
818 #endif | |
773 | 819 |
774 struct FuncAliasDeclaration : FuncDeclaration | 820 struct FuncAliasDeclaration : FuncDeclaration |
775 { | 821 { |
776 FuncDeclaration *funcalias; | 822 FuncDeclaration *funcalias; |
777 PROT importprot; // if generated by import, store its protection | 823 PROT importprot; // if generated by import, store its protection |
829 int isVirtual(); | 875 int isVirtual(); |
830 int addPreInvariant(); | 876 int addPreInvariant(); |
831 int addPostInvariant(); | 877 int addPostInvariant(); |
832 int overloadInsert(Dsymbol *s); | 878 int overloadInsert(Dsymbol *s); |
833 void emitComment(Scope *sc); | 879 void emitComment(Scope *sc); |
880 void toJsonBuffer(OutBuffer *buf); | |
834 | 881 |
835 PostBlitDeclaration *isPostBlitDeclaration() { return this; } | 882 PostBlitDeclaration *isPostBlitDeclaration() { return this; } |
836 }; | 883 }; |
837 #endif | 884 #endif |
838 | 885 |
841 DtorDeclaration(Loc loc, Loc endloc); | 888 DtorDeclaration(Loc loc, Loc endloc); |
842 DtorDeclaration(Loc loc, Loc endloc, Identifier *id); | 889 DtorDeclaration(Loc loc, Loc endloc, Identifier *id); |
843 Dsymbol *syntaxCopy(Dsymbol *); | 890 Dsymbol *syntaxCopy(Dsymbol *); |
844 void semantic(Scope *sc); | 891 void semantic(Scope *sc); |
845 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | 892 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
893 const char *kind(); | |
894 char *toChars(); | |
846 int isVirtual(); | 895 int isVirtual(); |
847 int addPreInvariant(); | 896 int addPreInvariant(); |
848 int addPostInvariant(); | 897 int addPostInvariant(); |
849 int overloadInsert(Dsymbol *s); | 898 int overloadInsert(Dsymbol *s); |
850 void emitComment(Scope *sc); | 899 void emitComment(Scope *sc); |
900 void toJsonBuffer(OutBuffer *buf); | |
851 | 901 |
852 DtorDeclaration *isDtorDeclaration() { return this; } | 902 DtorDeclaration *isDtorDeclaration() { return this; } |
853 }; | 903 }; |
854 | 904 |
855 struct StaticCtorDeclaration : FuncDeclaration | 905 struct StaticCtorDeclaration : FuncDeclaration |
861 int isStaticConstructor(); | 911 int isStaticConstructor(); |
862 int isVirtual(); | 912 int isVirtual(); |
863 int addPreInvariant(); | 913 int addPreInvariant(); |
864 int addPostInvariant(); | 914 int addPostInvariant(); |
865 void emitComment(Scope *sc); | 915 void emitComment(Scope *sc); |
916 void toJsonBuffer(OutBuffer *buf); | |
866 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | 917 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
867 | 918 |
868 StaticCtorDeclaration *isStaticCtorDeclaration() { return this; } | 919 StaticCtorDeclaration *isStaticCtorDeclaration() { return this; } |
869 }; | 920 }; |
870 | 921 |
878 int isStaticDestructor(); | 929 int isStaticDestructor(); |
879 int isVirtual(); | 930 int isVirtual(); |
880 int addPreInvariant(); | 931 int addPreInvariant(); |
881 int addPostInvariant(); | 932 int addPostInvariant(); |
882 void emitComment(Scope *sc); | 933 void emitComment(Scope *sc); |
934 void toJsonBuffer(OutBuffer *buf); | |
883 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | 935 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
884 | 936 |
885 StaticDtorDeclaration *isStaticDtorDeclaration() { return this; } | 937 StaticDtorDeclaration *isStaticDtorDeclaration() { return this; } |
886 }; | 938 }; |
887 | 939 |
892 void semantic(Scope *sc); | 944 void semantic(Scope *sc); |
893 int isVirtual(); | 945 int isVirtual(); |
894 int addPreInvariant(); | 946 int addPreInvariant(); |
895 int addPostInvariant(); | 947 int addPostInvariant(); |
896 void emitComment(Scope *sc); | 948 void emitComment(Scope *sc); |
949 void toJsonBuffer(OutBuffer *buf); | |
897 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | 950 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
898 | 951 |
899 InvariantDeclaration *isInvariantDeclaration() { return this; } | 952 InvariantDeclaration *isInvariantDeclaration() { return this; } |
900 }; | 953 }; |
901 | 954 |