Changeset 578
- Timestamp:
- 07/17/10 09:29:10 (14 years ago)
- Files:
-
- trunk/src/mtype.c (modified) (2 diffs)
- trunk/src/mtype.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/mtype.c
r569 r578 4726 4726 if (next) 4727 4727 next->toCBuffer2(buf, hgs, 0); 4728 4728 if (hgs->ddoc != 1) 4729 4729 { 4730 4730 switch (linkage) 4731 4731 { 4732 4732 case LINKd: p = NULL; break; 4733 4733 case LINKc: p = " C"; break; 4734 4734 case LINKwindows: p = " Windows"; break; 4735 4735 case LINKpascal: p = " Pascal"; break; 4736 4736 case LINKcpp: p = " C++"; break; 4737 4737 default: 4738 4738 assert(0); 4739 4739 } 4740 4740 } 4741 4741 4742 4742 if (!hgs->hdrgen && p) 4743 4743 buf->writestring(p); 4744 4744 buf->writestring(" function"); 4745 4745 Parameter::argsToCBuffer(buf, hgs, parameters, varargs); 4746 4746 attributesToCBuffer(buf, mod); 4747 inuse--; 4748 } 4749 4750 void TypeFunction::attributesToCBuffer(OutBuffer *buf, int mod) 4751 { 4747 4752 /* Use postfix style for attributes 4748 4753 */ 4749 4754 if (mod != this->mod) 4750 4755 { 4751 4756 modToBuffer(buf); 4752 4757 } 4753 4758 if (ispure) 4754 4759 buf->writestring(" pure"); 4755 4760 if (isnothrow) 4756 4761 buf->writestring(" nothrow"); 4757 4762 if (isproperty) 4758 4763 buf->writestring(" @property"); 4759 4764 if (isref) 4760 4765 buf->writestring(" ref"); 4761 4766 4762 4767 switch (trust) 4763 4768 { 4764 4769 case TRUSTsystem: 4765 buf->writestring(" @system");4770 buf->writestring(" @system"); 4766 4771 break; 4767 4772 4768 4773 case TRUSTtrusted: 4769 4774 buf->writestring(" @trusted"); 4770 4775 break; 4771 4776 4772 4777 case TRUSTsafe: 4773 4778 buf->writestring(" @safe"); 4774 4779 break; 4775 4780 } 4776 inuse--;4777 4781 } 4778 4782 4779 4783 Type *TypeFunction::semantic(Loc loc, Scope *sc) 4780 4784 { 4781 4785 if (deco) // if semantic() already run 4782 4786 { 4783 4787 //printf("already done\n"); 4784 4788 return this; 4785 4789 } 4786 4790 //printf("TypeFunction::semantic() this = %p\n", this); 4787 4791 //printf("TypeFunction::semantic() %s, sc->stc = %llx, fargs = %p\n", toChars(), sc->stc, fargs); 4788 4792 4789 4793 /* Copy in order to not mess up original. 4790 4794 * This can produce redundant copies if inferring return type, 4791 4795 * as semantic() will get called again on this. 4792 4796 */ 4793 4797 TypeFunction *tf = (TypeFunction *)mem.malloc(sizeof(TypeFunction)); 4794 4798 memcpy(tf, this, sizeof(TypeFunction)); 4795 4799 if (parameters) 4796 4800 { tf->parameters = (Parameters *)parameters->copy(); … … 5262 5266 if (this == to) 5263 5267 return MATCHexact; 5264 5268 #if 0 // not allowing covariant conversions because it interferes with overriding 5265 5269 if (to->ty == Tdelegate && this->nextOf()->covariant(to->nextOf()) == 1) 5266 5270 return MATCHconvert; 5267 5271 #endif 5268 5272 return MATCHnomatch; 5269 5273 } 5270 5274 5271 5275 void TypeDelegate::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) 5272 5276 { 5273 5277 if (mod != this->mod) 5274 5278 { toCBuffer3(buf, hgs, mod); 5275 5279 return; 5276 5280 } 5277 5281 TypeFunction *tf = (TypeFunction *)next; 5278 5282 5279 5283 tf->next->toCBuffer2(buf, hgs, 0); 5280 5284 buf->writestring(" delegate"); 5281 5285 Parameter::argsToCBuffer(buf, hgs, tf->parameters, tf->varargs); 5286 tf->attributesToCBuffer(buf, mod); 5282 5287 } 5283 5288 5284 5289 Expression *TypeDelegate::defaultInit(Loc loc) 5285 5290 { 5286 5291 #if LOGDEFAULTINIT 5287 5292 printf("TypeDelegate::defaultInit() '%s'\n", toChars()); 5288 5293 #endif 5289 5294 return new NullExp(loc, this); 5290 5295 } 5291 5296 5292 5297 int TypeDelegate::isZeroInit(Loc loc) 5293 5298 { 5294 5299 return 1; 5295 5300 } 5296 5301 5297 5302 int TypeDelegate::checkBoolean() 5298 5303 { 5299 5304 return TRUE; 5300 5305 } 5301 5306 trunk/src/mtype.h
r523 r578 551 551 552 552 Parameters *parameters; // function parameters 553 553 int varargs; // 1: T t, ...) style for variable number of arguments 554 554 // 2: T t ...) style for variable number of arguments 555 555 bool isnothrow; // true: nothrow 556 556 bool ispure; // true: pure 557 557 bool isproperty; // can be called without parentheses 558 558 bool isref; // true: returns a reference 559 559 enum LINK linkage; // calling convention 560 560 enum TRUST trust; // level of trust 561 561 Expressions *fargs; // function arguments 562 562 563 563 int inuse; 564 564 565 565 TypeFunction(Parameters *parameters, Type *treturn, int varargs, enum LINK linkage, StorageClass stc = 0); 566 566 Type *syntaxCopy(); 567 567 Type *semantic(Loc loc, Scope *sc); 568 568 void toDecoBuffer(OutBuffer *buf, int flag); 569 569 void toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs); 570 570 void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod); 571 void attributesToCBuffer(OutBuffer *buf, int mod); 571 572 MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes); 572 573 TypeInfoDeclaration *getTypeInfoDeclaration(); 573 574 Type *reliesOnTident(); 574 575 #if CPP_MANGLE 575 576 void toCppMangle(OutBuffer *buf, CppMangleState *cms); 576 577 #endif 577 578 bool parameterEscapes(Parameter *p); 578 579 579 580 int callMatch(Expression *ethis, Expressions *toargs, int flag = 0); 580 581 type *toCtype(); 581 582 enum RET retStyle(); 582 583 583 584 unsigned totym(); 584 585 }; 585 586 586 587 struct TypeDelegate : TypeNext 587 588 { 588 589 // .next is a TypeFunction 589 590 590 591 TypeDelegate(Type *t);
