1: 
  2: // Compiler implementation of the D programming language
  3: // Copyright (c) 1999-2011 by Digital Mars
  4: // All Rights Reserved
  5: // written by Walter Bright
  6: // http://www.digitalmars.com
  7: // License for redistribution is by either the Artistic License
  8: // in artistic.txt, or the GNU General Public License in gnu.txt.
  9: // See the included readme.txt for details.
 10: 
 11: #ifndef DMD_DECLARATION_H
 12: #define DMD_DECLARATION_H
 13: 
 14: #ifdef __DMC__
 15: #pragma once
 16: #endif /* __DMC__ */
 17: 
 18: #include "dsymbol.h"
 19: #include "lexer.h"
 20: #include "mtype.h"
 21: 
 22: struct Expression;
 23: struct Statement;
 24: struct LabelDsymbol;
 25: struct Initializer;
 26: struct Module;
 27: struct InlineScanState;
 28: struct ForeachStatement;
 29: struct FuncDeclaration;
 30: struct ExpInitializer;
 31: struct StructDeclaration;
 32: struct TupleType;
 33: struct InterState;
 34: struct IRState;
 35: 
 36: enum PROT;
 37: enum LINK;
 38: enum TOK;
 39: enum MATCH;
 40: enum PURE;
 41: 
 42: #define STCundefined    0LL
 43: #define STCstatic       1LL
 44: #define STCextern       2LL
 45: #define STCconst        4LL
 46: #define STCfinal        8LL
 47: #define STCabstract     0x10LL
 48: #define STCparameter    0x20LL
 49: #define STCfield        0x40LL
 50: #define STCoverride     0x80LL
 51: #define STCauto         0x100LL
 52: #define STCsynchronized 0x200LL
 53: #define STCdeprecated   0x400LL
 54: #define STCin           0x800LL         // in parameter
 55: #define STCout          0x1000LL        // out parameter
 56: #define STClazy         0x2000LL        // lazy parameter
 57: #define STCforeach      0x4000LL        // variable for foreach loop
 58: #define STCcomdat       0x8000LL        // should go into COMDAT record
 59: #define STCvariadic     0x10000LL       // variadic function argument
 60: #define STCctorinit     0x20000LL       // can only be set inside constructor
 61: #define STCtemplateparameter  0x40000LL // template parameter
 62: #define STCscope        0x80000LL       // template parameter
 63: #define STCimmutable    0x100000LL
 64: #define STCref          0x200000LL
 65: #define STCinit         0x400000LL      // has explicit initializer
 66: #define STCmanifest     0x800000LL      // manifest constant
 67: #define STCnodtor       0x1000000LL     // don't run destructor
 68: #define STCnothrow      0x2000000LL     // never throws exceptions
 69: #define STCpure         0x4000000LL     // pure function
 70: #define STCtls          0x8000000LL     // thread local
 71: #define STCalias        0x10000000LL    // alias parameter
 72: #define STCshared       0x20000000LL    // accessible from multiple threads
 73: #define STCgshared      0x40000000LL    // accessible from multiple threads
 74:                                         // but not typed as "shared"
 75: #define STCwild         0x80000000LL    // for "wild" type constructor
 76: #define STC_TYPECTOR    (STCconst | STCimmutable | STCshared | STCwild)
 77: 
 78: #define STCproperty     0x100000000LL
 79: #define STCsafe         0x200000000LL
 80: #define STCtrusted      0x400000000LL
 81: #define STCsystem       0x800000000LL
 82: #define STCctfe         0x1000000000LL  // can be used in CTFE, even if it is static
 83: #define STCdisable      0x2000000000LL  // for functions that are not callable
 84: #define STCresult       0x4000000000LL  // for result variables passed to out contracts
 85: 
 86: struct Match
 87: {
 88:     int count;                  // number of matches found
 89:     MATCH last;                 // match level of lastf
 90:     FuncDeclaration *lastf;     // last matching function we found
 91:     FuncDeclaration *nextf;     // current matching function
 92:     FuncDeclaration *anyf;      // pick a func, any func, to use for error recovery
 93: };
 94: 
 95: void overloadResolveX(Match *m, FuncDeclaration *f,
 96:         Expression *ethis, Expressions *arguments);
 97: int overloadApply(FuncDeclaration *fstart,
 98:         int (*fp)(void *, FuncDeclaration *),
 99:         void *param);
100: 
101: enum Semantic
102: {
103:     SemanticStart,      // semantic has not been run
104:     SemanticIn,         // semantic() is in progress
105:     SemanticDone,       // semantic() has been run
106:     Semantic2Done,      // semantic2() has been run
107: };
108: 
109: /**************************************************************/
110: 
111: struct Declaration : Dsymbol
112: {
113:     Type *type;
114:     Type *originalType;         // before semantic analysis
115:     StorageClass storage_class;
116:     enum PROT protection;
117:     enum LINK linkage;
118:     int inuse;                  // used to detect cycles
119: 
120:     enum Semantic sem;
121: 
122:     Declaration(Identifier *id);
123:     void semantic(Scope *sc);
124:     const char *kind();
125:     unsigned size(Loc loc);
126:     void checkModify(Loc loc, Scope *sc, Type *t);
127: 
128:     void emitComment(Scope *sc);
129:     void toJsonBuffer(OutBuffer *buf);
130:     void toDocBuffer(OutBuffer *buf);
131: 
132:     char *mangle();
133:     int isStatic() { return storage_class & STCstatic; }
134:     virtual int isDelete();
135:     virtual int isDataseg();
136:     virtual int isThreadlocal();
137:     virtual int isCodeseg();
138:     int isCtorinit()     { return storage_class & STCctorinit; }
139:     int isFinal()        { return storage_class & STCfinal; }
140:     int isAbstract()     { return storage_class & STCabstract; }
141:     int isConst()        { return storage_class & STCconst; }
142:     int isImmutable()    { return storage_class & STCimmutable; }
143:     int isAuto()         { return storage_class & STCauto; }
144:     int isScope()        { return storage_class & STCscope; }
145:     int isSynchronized() { return storage_class & STCsynchronized; }
146:     int isParameter()    { return storage_class & STCparameter; }
147:     int isDeprecated()   { return storage_class & STCdeprecated; }
148:     int isOverride()     { return storage_class & STCoverride; }
149:     int isResult()       { return storage_class & STCresult; }
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
warning C4244: 'return' : conversion from 'StorageClass' to 'int', possible loss of data
150: 151: int isIn() { return storage_class & STCin; } 152: int isOut() { return storage_class & STCout; } 153: int isRef() { return storage_class & STCref; } 154: 155: enum PROT prot(); 156: 157: Declaration *isDeclaration() { return this; } 158: }; 159: 160: /**************************************************************/ 161: 162: struct TupleDeclaration : Declaration 163: { 164: Objects *objects; 165: int isexp; // 1: expression tuple 166: 167: TypeTuple *tupletype; // !=NULL if this is a type tuple 168: 169: TupleDeclaration(Loc loc, Identifier *ident, Objects *objects); 170: Dsymbol *syntaxCopy(Dsymbol *); 171: const char *kind(); 172: Type *getType(); 173: int needThis(); 174: 175: TupleDeclaration *isTupleDeclaration() { return this; } 176: }; 177: 178: /**************************************************************/ 179: 180: struct TypedefDeclaration : Declaration 181: { 182: Type *basetype; 183: Initializer *init; 184: 185: TypedefDeclaration(Loc loc, Identifier *ident, Type *basetype, Initializer *init); 186: Dsymbol *syntaxCopy(Dsymbol *); 187: void semantic(Scope *sc); 188: void semantic2(Scope *sc); 189: char *mangle(); 190: const char *kind(); 191: Type *getType(); 192: void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 193: Type *htype; 194: Type *hbasetype; 195: 196: void toDocBuffer(OutBuffer *buf); 197: 198: void toObjFile(int multiobj); // compile to .obj file 199: void toDebug(); 200: int cvMember(unsigned char *p); 201: 202: TypedefDeclaration *isTypedefDeclaration() { return this; } 203: 204: Symbol *sinit; 205: Symbol *toInitializer(); 206: }; 207: 208: /**************************************************************/ 209: 210: struct AliasDeclaration : Declaration 211: { 212: Dsymbol *aliassym; 213: Dsymbol *overnext; // next in overload list 214: int inSemantic; 215: 216: AliasDeclaration(Loc loc, Identifier *ident, Type *type); 217: AliasDeclaration(Loc loc, Identifier *ident, Dsymbol *s); 218: Dsymbol *syntaxCopy(Dsymbol *); 219: void semantic(Scope *sc); 220: int overloadInsert(Dsymbol *s); 221: const char *kind(); 222: Type *getType(); 223: Dsymbol *toAlias(); 224: void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 225: Type *htype; 226: Dsymbol *haliassym; 227: 228: void toDocBuffer(OutBuffer *buf); 229: 230: AliasDeclaration *isAliasDeclaration() { return this; } 231: }; 232: 233: /**************************************************************/ 234: 235: struct VarDeclaration : Declaration 236: { 237: Initializer *init; 238: unsigned offset; 239: int noscope; // no auto semantics 240: #if DMDV2 241: FuncDeclarations nestedrefs; // referenced by these lexically nested functions 242: bool isargptr; // if parameter that _argptr points to 243: #else 244: int nestedref; // referenced by a lexically nested function 245: #endif 246: int ctorinit; // it has been initialized in a ctor 247: int onstack; // 1: it has been allocated on the stack 248: // 2: on stack, run destructor anyway 249: int canassign; // it can be assigned to 250: Dsymbol *aliassym; // if redone as alias to another symbol 251: 252: // When interpreting, these hold the value (NULL if value not determinable) 253: // The various functions are used only to detect compiler CTFE bugs 254: Expression *literalvalue; 255: Expression *getValue() { return literalvalue; } 256: void setValueNull(); 257: void setValueWithoutChecking(Expression *newval); 258: void createRefValue(Expression *newval); // struct or array literal 259: void setRefValue(Expression *newval); 260: void setStackValue(Expression *newval); 261: void createStackValue(Expression *newval); 262: 263: #if DMDV2 264: VarDeclaration *rundtor; // if !NULL, rundtor is tested at runtime to see 265: // if the destructor should be run. Used to prevent 266: // dtor calls on postblitted vars 267: Expression *edtor; // if !=NULL, does the destruction of the variable 268: #endif 269: 270: VarDeclaration(Loc loc, Type *t, Identifier *id, Initializer *init); 271: Dsymbol *syntaxCopy(Dsymbol *); 272: void semantic(Scope *sc); 273: void semantic2(Scope *sc); 274: const char *kind(); 275: void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 276: Type *htype; 277: Initializer *hinit; 278: AggregateDeclaration *isThis(); 279: int needThis(); 280: int isImportedSymbol(); 281: int isDataseg(); 282: int isThreadlocal(); 283: int isCTFE(); 284: int hasPointers(); 285: #if DMDV2 286: int canTakeAddressOf(); 287: int needsAutoDtor(); 288: #endif 289: Expression *callScopeDtor(Scope *sc); 290: ExpInitializer *getExpInitializer(); 291: Expression *getConstInitializer(); 292: void checkCtorConstInit(); 293: void checkNestedReference(Scope *sc, Loc loc); 294: Dsymbol *toAlias(); 295: 296: Symbol *toSymbol(); 297: void toObjFile(int multiobj); // compile to .obj file 298: int cvMember(unsigned char *p); 299: 300: // Eliminate need for dynamic_cast 301: VarDeclaration *isVarDeclaration() { return (VarDeclaration *)this; } 302: }; 303: 304: /**************************************************************/ 305: 306: // This is a shell around a back end symbol 307: 308: struct SymbolDeclaration : Declaration 309: { 310: Symbol *sym; 311: StructDeclaration *dsym; 312: 313: SymbolDeclaration(Loc loc, Symbol *s, StructDeclaration *dsym); 314: 315: Symbol *toSymbol(); 316: 317: // Eliminate need for dynamic_cast 318: SymbolDeclaration *isSymbolDeclaration() { return (SymbolDeclaration *)this; } 319: }; 320: 321: struct ClassInfoDeclaration : VarDeclaration 322: { 323: ClassDeclaration *cd; 324: 325: ClassInfoDeclaration(ClassDeclaration *cd); 326: Dsymbol *syntaxCopy(Dsymbol *); 327: void semantic(Scope *sc); 328: 329: void emitComment(Scope *sc); 330: void toJsonBuffer(OutBuffer *buf); 331: 332: Symbol *toSymbol(); 333: }; 334: 335: struct ModuleInfoDeclaration : VarDeclaration 336: { 337: Module *mod; 338: 339: ModuleInfoDeclaration(Module *mod); 340: Dsymbol *syntaxCopy(Dsymbol *); 341: void semantic(Scope *sc); 342: 343: void emitComment(Scope *sc); 344: void toJsonBuffer(OutBuffer *buf); 345: 346: Symbol *toSymbol(); 347: }; 348: 349: struct TypeInfoDeclaration : VarDeclaration 350: { 351: Type *tinfo; 352: 353: TypeInfoDeclaration(Type *tinfo, int internal); 354: Dsymbol *syntaxCopy(Dsymbol *); 355: void semantic(Scope *sc); 356: 357: void emitComment(Scope *sc); 358: void toJsonBuffer(OutBuffer *buf); 359: 360: Symbol *toSymbol(); 361: void toObjFile(int multiobj); // compile to .obj file 362: virtual void toDt(dt_t **pdt); 363: }; 364: 365: struct TypeInfoStructDeclaration : TypeInfoDeclaration 366: { 367: TypeInfoStructDeclaration(Type *tinfo); 368: 369: void toDt(dt_t **pdt); 370: }; 371: 372: struct TypeInfoClassDeclaration : TypeInfoDeclaration 373: { 374: TypeInfoClassDeclaration(Type *tinfo); 375: Symbol *toSymbol(); 376: 377: void toDt(dt_t **pdt); 378: }; 379: 380: struct TypeInfoInterfaceDeclaration : TypeInfoDeclaration 381: { 382: TypeInfoInterfaceDeclaration(Type *tinfo); 383: 384: void toDt(dt_t **pdt); 385: }; 386: 387: struct TypeInfoTypedefDeclaration : TypeInfoDeclaration 388: { 389: TypeInfoTypedefDeclaration(Type *tinfo); 390: 391: void toDt(dt_t **pdt); 392: }; 393: 394: struct TypeInfoPointerDeclaration : TypeInfoDeclaration 395: { 396: TypeInfoPointerDeclaration(Type *tinfo); 397: 398: void toDt(dt_t **pdt); 399: }; 400: 401: struct TypeInfoArrayDeclaration : TypeInfoDeclaration 402: { 403: TypeInfoArrayDeclaration(Type *tinfo); 404: 405: void toDt(dt_t **pdt); 406: }; 407: 408: struct TypeInfoStaticArrayDeclaration : TypeInfoDeclaration 409: { 410: TypeInfoStaticArrayDeclaration(Type *tinfo); 411: 412: void toDt(dt_t **pdt); 413: }; 414: 415: struct TypeInfoAssociativeArrayDeclaration : TypeInfoDeclaration 416: { 417: TypeInfoAssociativeArrayDeclaration(Type *tinfo); 418: 419: void toDt(dt_t **pdt); 420: }; 421: 422: struct TypeInfoEnumDeclaration : TypeInfoDeclaration 423: { 424: TypeInfoEnumDeclaration(Type *tinfo); 425: 426: void toDt(dt_t **pdt); 427: }; 428: 429: struct TypeInfoFunctionDeclaration : TypeInfoDeclaration 430: { 431: TypeInfoFunctionDeclaration(Type *tinfo); 432: 433: void toDt(dt_t **pdt); 434: }; 435: 436: struct TypeInfoDelegateDeclaration : TypeInfoDeclaration 437: { 438: TypeInfoDelegateDeclaration(Type *tinfo); 439: 440: void toDt(dt_t **pdt); 441: }; 442: 443: struct TypeInfoTupleDeclaration : TypeInfoDeclaration 444: { 445: TypeInfoTupleDeclaration(Type *tinfo); 446: 447: void toDt(dt_t **pdt); 448: }; 449: 450: #if DMDV2 451: struct TypeInfoConstDeclaration : TypeInfoDeclaration 452: { 453: TypeInfoConstDeclaration(Type *tinfo); 454: 455: void toDt(dt_t **pdt); 456: }; 457: 458: struct TypeInfoInvariantDeclaration : TypeInfoDeclaration 459: { 460: TypeInfoInvariantDeclaration(Type *tinfo); 461: 462: void toDt(dt_t **pdt); 463: }; 464: 465: struct TypeInfoSharedDeclaration : TypeInfoDeclaration 466: { 467: TypeInfoSharedDeclaration(Type *tinfo); 468: 469: void toDt(dt_t **pdt); 470: }; 471: 472: struct TypeInfoWildDeclaration : TypeInfoDeclaration 473: { 474: TypeInfoWildDeclaration(Type *tinfo); 475: 476: void toDt(dt_t **pdt); 477: }; 478: #endif 479: 480: /**************************************************************/ 481: 482: struct ThisDeclaration : VarDeclaration 483: { 484: ThisDeclaration(Loc loc, Type *t); 485: Dsymbol *syntaxCopy(Dsymbol *); 486: ThisDeclaration *isThisDeclaration() { return this; } 487: }; 488: 489: enum ILS 490: { 491: ILSuninitialized, // not computed yet 492: ILSno, // cannot inline 493: ILSyes, // can inline 494: }; 495: 496: /**************************************************************/ 497: #if DMDV2 498: 499: enum BUILTIN 500: { 501: BUILTINunknown = -1, // not known if this is a builtin 502: BUILTINnot, // this is not a builtin 503: BUILTINsin, // std.math.sin 504: BUILTINcos, // std.math.cos 505: BUILTINtan, // std.math.tan 506: BUILTINsqrt, // std.math.sqrt 507: BUILTINfabs, // std.math.fabs 508: }; 509: 510: Expression *eval_builtin(enum BUILTIN builtin, Expressions *arguments); 511: 512: #else 513: enum BUILTIN { }; 514: #endif 515: 516: struct FuncDeclaration : Declaration 517: { 518: Types *fthrows; // Array of Type's of exceptions (not used) 519: Statement *frequire; 520: Statement *fensure; 521: Statement *fbody; 522: 523: FuncDeclarations foverrides; // functions this function overrides 524: FuncDeclaration *fdrequire; // function that does the in contract 525: FuncDeclaration *fdensure; // function that does the out contract 526: 527: Identifier *outId; // identifier for out statement 528: VarDeclaration *vresult; // variable corresponding to outId 529: LabelDsymbol *returnLabel; // where the return goes 530: 531: DsymbolTable *localsymtab; // used to prevent symbols in different 532: // scopes from having the same name 533: VarDeclaration *vthis; // 'this' parameter (member and nested) 534: VarDeclaration *v_arguments; // '_arguments' parameter 535: #if IN_GCC 536: VarDeclaration *v_argptr; // '_argptr' variable 537: #endif 538: VarDeclaration *v_argsave; // save area for args passed in registers for variadic functions 539: VarDeclarations *parameters; // Array of VarDeclaration's for parameters 540: DsymbolTable *labtab; // statement label symbol table 541: Declaration *overnext; // next in overload list 542: Loc endloc; // location of closing curly bracket 543: int vtblIndex; // for member functions, index into vtbl[] 544: int naked; // !=0 if naked 545: ILS inlineStatus; 546: int inlineNest; // !=0 if nested inline 547: int cantInterpret; // !=0 if cannot interpret function 548: int isArrayOp; // !=0 if array operation 549: enum PASS semanticRun; 550: // this function's frame ptr 551: ForeachStatement *fes; // if foreach body, this is the foreach 552: int introducing; // !=0 if 'introducing' function 553: Type *tintro; // if !=NULL, then this is the type 554: // of the 'introducing' function 555: // this one is overriding 556: int inferRetType; // !=0 if return type is to be inferred 557: 558: // Things that should really go into Scope 559: int hasReturnExp; // 1 if there's a return exp; statement 560: // 2 if there's a throw statement 561: // 4 if there's an assert(0) 562: // 8 if there's inline asm 563: 564: // Support for NRVO (named return value optimization) 565: int nrvo_can; // !=0 means we can do it 566: VarDeclaration *nrvo_var; // variable to replace with shidden 567: Symbol *shidden; // hidden pointer passed to function 568: 569: #if DMDV2 570: enum BUILTIN builtin; // set if this is a known, builtin 571: // function we can evaluate at compile 572: // time 573: 574: int tookAddressOf; // set if someone took the address of 575: // this function 576: VarDeclarations closureVars; // local variables in this function 577: // which are referenced by nested 578: // functions 579: 580: unsigned flags; 581: #define FUNCFLAGpurityInprocess 1 // working on determining purity 582: #define FUNCFLAGsafetyInprocess 2 // working on determining safety 583: #define FUNCFLAGnothrowInprocess 4 // working on determining nothrow 584: #else 585: int nestedFrameRef; // !=0 if nested variables referenced 586: #endif 587: 588: FuncDeclaration(Loc loc, Loc endloc, Identifier *id, StorageClass storage_class, Type *type); 589: Dsymbol *syntaxCopy(Dsymbol *); 590: void semantic(Scope *sc); 591: void semantic2(Scope *sc); 592: void semantic3(Scope *sc); 593: // called from semantic3 594: void varArgs(Scope *sc, TypeFunction*, VarDeclaration *&, VarDeclaration *&); 595: int equals(Object *o); 596: 597: void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 598: void bodyToCBuffer(OutBuffer *buf, HdrGenState *hgs); 599: int overrides(FuncDeclaration *fd); 600: int findVtblIndex(Dsymbols *vtbl, int dim); 601: int overloadInsert(Dsymbol *s); 602: FuncDeclaration *overloadExactMatch(Type *t); 603: FuncDeclaration *overloadResolve(Loc loc, Expression *ethis, Expressions *arguments, int flags = 0); 604: MATCH leastAsSpecialized(FuncDeclaration *g); 605: LabelDsymbol *searchLabel(Identifier *ident); 606: AggregateDeclaration *isThis(); 607: AggregateDeclaration *isMember2(); 608: int getLevel(Loc loc, FuncDeclaration *fd); // lexical nesting level difference 609: void appendExp(Expression *e); 610: void appendState(Statement *s); 611: char *mangle(); 612: const char *toPrettyChars(); 613: int isMain(); 614: int isWinMain(); 615: int isDllMain(); 616: enum BUILTIN isBuiltin(); 617: int isExport(); 618: int isImportedSymbol(); 619: int isAbstract(); 620: int isCodeseg(); 621: int isOverloadable(); 622: enum PURE isPure(); 623: bool setImpure(); 624: int isSafe(); 625: int isTrusted(); 626: bool setUnsafe(); 627: virtual int isNested(); 628: int needThis(); 629: virtual int isVirtual(); 630: virtual int isFinal(); 631: virtual int addPreInvariant(); 632: virtual int addPostInvariant(); 633: Expression *interpret(InterState *istate, Expressions *arguments, Expression *thisexp = NULL); 634: void inlineScan(); 635: int canInline(int hasthis, int hdrscan = 0); 636: Expression *doInline(InlineScanState *iss, Expression *ethis, Expressions *arguments); 637: const char *kind(); 638: void toDocBuffer(OutBuffer *buf); 639: FuncDeclaration *isUnique(); 640: int needsClosure(); 641: Statement *mergeFrequire(Statement *); 642: Statement *mergeFensure(Statement *); 643: Parameters *getParameters(int *pvarargs); 644: 645: static FuncDeclaration *genCfunc(Type *treturn, const char *name); 646: static FuncDeclaration *genCfunc(Type *treturn, Identifier *id); 647: 648: Symbol *toSymbol(); 649: Symbol *toThunkSymbol(int offset); // thunk version 650: void toObjFile(int multiobj); // compile to .obj file 651: int cvMember(unsigned char *p); 652: void buildClosure(IRState *irs); 653: 654: FuncDeclaration *isFuncDeclaration() { return this; } 655: }; 656: 657: #if DMDV2 658: FuncDeclaration *resolveFuncCall(Scope *sc, Loc loc, Dsymbol *s, 659: Objects *tiargs, 660: Expression *ethis, 661: Expressions *arguments, 662: int flags); 663: #endif 664: 665: struct FuncAliasDeclaration : FuncDeclaration 666: { 667: FuncDeclaration *funcalias; 668: 669: FuncAliasDeclaration(FuncDeclaration *funcalias); 670: 671: FuncAliasDeclaration *isFuncAliasDeclaration() { return this; } 672: const char *kind(); 673: Symbol *toSymbol(); 674: }; 675: 676: struct FuncLiteralDeclaration : FuncDeclaration 677: { 678: enum TOK tok; // TOKfunction or TOKdelegate 679: 680: FuncLiteralDeclaration(Loc loc, Loc endloc, Type *type, enum TOK tok, 681: ForeachStatement *fes); 682: void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 683: Dsymbol *syntaxCopy(Dsymbol *); 684: int isNested(); 685: int isVirtual(); 686: 687: FuncLiteralDeclaration *isFuncLiteralDeclaration() { return this; } 688: const char *kind(); 689: }; 690: 691: struct CtorDeclaration : FuncDeclaration 692: { 693: CtorDeclaration(Loc loc, Loc endloc, StorageClass stc, Type *type); 694: Dsymbol *syntaxCopy(Dsymbol *); 695: void semantic(Scope *sc); 696: void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 697: const char *kind(); 698: char *toChars(); 699: int isVirtual(); 700: int addPreInvariant(); 701: int addPostInvariant(); 702: 703: CtorDeclaration *isCtorDeclaration() { return this; } 704: }; 705: 706: #if DMDV2 707: struct PostBlitDeclaration : FuncDeclaration 708: { 709: PostBlitDeclaration(Loc loc, Loc endloc); 710: PostBlitDeclaration(Loc loc, Loc endloc, Identifier *id); 711: Dsymbol *syntaxCopy(Dsymbol *); 712: void semantic(Scope *sc); 713: void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 714: int isVirtual(); 715: int addPreInvariant(); 716: int addPostInvariant(); 717: int overloadInsert(Dsymbol *s); 718: void emitComment(Scope *sc); 719: void toJsonBuffer(OutBuffer *buf); 720: 721: PostBlitDeclaration *isPostBlitDeclaration() { return this; } 722: }; 723: #endif 724: 725: struct DtorDeclaration : FuncDeclaration 726: { 727: DtorDeclaration(Loc loc, Loc endloc); 728: DtorDeclaration(Loc loc, Loc endloc, Identifier *id); 729: Dsymbol *syntaxCopy(Dsymbol *); 730: void semantic(Scope *sc); 731: void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 732: const char *kind(); 733: char *toChars(); 734: int isVirtual(); 735: int addPreInvariant(); 736: int addPostInvariant(); 737: int overloadInsert(Dsymbol *s); 738: void emitComment(Scope *sc); 739: void toJsonBuffer(OutBuffer *buf); 740: 741: DtorDeclaration *isDtorDeclaration() { return this; } 742: }; 743: 744: struct StaticCtorDeclaration : FuncDeclaration 745: { 746: StaticCtorDeclaration(Loc loc, Loc endloc); 747: StaticCtorDeclaration(Loc loc, Loc endloc, const char *name); 748: Dsymbol *syntaxCopy(Dsymbol *); 749: void semantic(Scope *sc); 750: AggregateDeclaration *isThis(); 751: int isVirtual(); 752: int addPreInvariant(); 753: int addPostInvariant(); 754: void emitComment(Scope *sc); 755: void toJsonBuffer(OutBuffer *buf); 756: void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 757: 758: StaticCtorDeclaration *isStaticCtorDeclaration() { return this; } 759: }; 760: 761: #if DMDV2 762: struct SharedStaticCtorDeclaration : StaticCtorDeclaration 763: { 764: SharedStaticCtorDeclaration(Loc loc, Loc endloc); 765: Dsymbol *syntaxCopy(Dsymbol *); 766: void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 767: 768: SharedStaticCtorDeclaration *isSharedStaticCtorDeclaration() { return this; } 769: }; 770: #endif 771: 772: struct StaticDtorDeclaration : FuncDeclaration 773: { VarDeclaration *vgate; // 'gate' variable 774: 775: StaticDtorDeclaration(Loc loc, Loc endloc); 776: StaticDtorDeclaration(Loc loc, Loc endloc, const char *name); 777: Dsymbol *syntaxCopy(Dsymbol *); 778: void semantic(Scope *sc); 779: AggregateDeclaration *isThis(); 780: int isVirtual(); 781: int addPreInvariant(); 782: int addPostInvariant(); 783: void emitComment(Scope *sc); 784: void toJsonBuffer(OutBuffer *buf); 785: void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 786: 787: StaticDtorDeclaration *isStaticDtorDeclaration() { return this; } 788: }; 789: 790: #if DMDV2 791: struct SharedStaticDtorDeclaration : StaticDtorDeclaration 792: { 793: SharedStaticDtorDeclaration(Loc loc, Loc endloc); 794: Dsymbol *syntaxCopy(Dsymbol *); 795: void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 796: 797: SharedStaticDtorDeclaration *isSharedStaticDtorDeclaration() { return this; } 798: }; 799: #endif 800: 801: struct InvariantDeclaration : FuncDeclaration 802: { 803: InvariantDeclaration(Loc loc, Loc endloc); 804: Dsymbol *syntaxCopy(Dsymbol *); 805: void semantic(Scope *sc); 806: int isVirtual(); 807: int addPreInvariant(); 808: int addPostInvariant(); 809: void emitComment(Scope *sc); 810: void toJsonBuffer(OutBuffer *buf); 811: void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 812: 813: InvariantDeclaration *isInvariantDeclaration() { return this; } 814: }; 815: 816: struct UnitTestDeclaration : FuncDeclaration 817: { 818: UnitTestDeclaration(Loc loc, Loc endloc); 819: Dsymbol *syntaxCopy(Dsymbol *); 820: void semantic(Scope *sc); 821: AggregateDeclaration *isThis(); 822: int isVirtual(); 823: int addPreInvariant(); 824: int addPostInvariant(); 825: void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 826: void toJsonBuffer(OutBuffer *buf); 827: 828: UnitTestDeclaration *isUnitTestDeclaration() { return this; } 829: }; 830: 831: struct NewDeclaration : FuncDeclaration 832: { Parameters *arguments; 833: int varargs; 834: 835: NewDeclaration(Loc loc, Loc endloc, Parameters *arguments, int varargs); 836: Dsymbol *syntaxCopy(Dsymbol *); 837: void semantic(Scope *sc); 838: void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 839: const char *kind(); 840: int isVirtual(); 841: int addPreInvariant(); 842: int addPostInvariant(); 843: 844: NewDeclaration *isNewDeclaration() { return this; } 845: }; 846: 847: 848: struct DeleteDeclaration : FuncDeclaration 849: { Parameters *arguments; 850: 851: DeleteDeclaration(Loc loc, Loc endloc, Parameters *arguments); 852: Dsymbol *syntaxCopy(Dsymbol *); 853: void semantic(Scope *sc); 854: void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 855: const char *kind(); 856: int isDelete(); 857: int isVirtual(); 858: int addPreInvariant(); 859: int addPostInvariant(); 860: DeleteDeclaration *isDeleteDeclaration() { return this; } 861: }; 862: 863: #endif /* DMD_DECLARATION_H */ 864: