comparison dmd/func.c @ 510:6aee82889553

Merged DMD 1.034, array operations are not yet implemented ;)
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Thu, 14 Aug 2008 06:55:41 +0200
parents 45a67b6f1310
children 49466efd4fba
comparison
equal deleted inserted replaced
509:337554fd34f1 510:6aee82889553
66 semanticRun = 0; 66 semanticRun = 0;
67 nestedFrameRef = 0; 67 nestedFrameRef = 0;
68 fes = NULL; 68 fes = NULL;
69 introducing = 0; 69 introducing = 0;
70 tintro = NULL; 70 tintro = NULL;
71 /* The type given for "infer the return type" is a TypeFunction with
72 * NULL for the return type.
73 */
71 inferRetType = (type && type->nextOf() == NULL); 74 inferRetType = (type && type->nextOf() == NULL);
72 scope = NULL; 75 scope = NULL;
73 hasReturnExp = 0; 76 hasReturnExp = 0;
74 nrvo_can = 1; 77 nrvo_can = 1;
75 nrvo_var = NULL; 78 nrvo_var = NULL;
110 #if 0 113 #if 0
111 printf("FuncDeclaration::semantic(sc = %p, this = %p, '%s', linkage = %d)\n", sc, this, toPrettyChars(), sc->linkage); 114 printf("FuncDeclaration::semantic(sc = %p, this = %p, '%s', linkage = %d)\n", sc, this, toPrettyChars(), sc->linkage);
112 if (isFuncLiteralDeclaration()) 115 if (isFuncLiteralDeclaration())
113 printf("\tFuncLiteralDeclaration()\n"); 116 printf("\tFuncLiteralDeclaration()\n");
114 printf("sc->parent = %s\n", sc->parent->toChars()); 117 printf("sc->parent = %s\n", sc->parent->toChars());
115 printf("type: %s\n", type->toChars()); 118 printf("type: %p, %s\n", type, type->toChars());
116 #endif 119 #endif
117 120
118 if (type->nextOf()) 121 if (type->nextOf())
119 type = type->semantic(loc, sc); 122 type = type->semantic(loc, sc);
120 //type->print(); 123 //type->print();
279 282
280 // Find index of existing function in vtbl[] to override 283 // Find index of existing function in vtbl[] to override
281 vi = findVtblIndex(&cd->vtbl, cd->baseClass ? cd->baseClass->vtbl.dim : 0); 284 vi = findVtblIndex(&cd->vtbl, cd->baseClass ? cd->baseClass->vtbl.dim : 0);
282 switch (vi) 285 switch (vi)
283 { 286 {
284 case -1: // didn't find one 287 case -1:
285 // This is an 'introducing' function. 288 /* Didn't find one, so
289 * This is an 'introducing' function which gets a new
290 * slot in the vtbl[].
291 */
286 292
287 // Verify this doesn't override previous final function 293 // Verify this doesn't override previous final function
288 if (cd->baseClass) 294 if (cd->baseClass)
289 { Dsymbol *s = cd->baseClass->search(loc, ident, 0); 295 { Dsymbol *s = cd->baseClass->search(loc, ident, 0);
290 if (s) 296 if (s)
630 f = (TypeFunction *)(type); 636 f = (TypeFunction *)(type);
631 size_t nparams = Argument::dim(f->parameters); 637 size_t nparams = Argument::dim(f->parameters);
632 638
633 // Check the 'throws' clause 639 // Check the 'throws' clause
634 if (fthrows) 640 if (fthrows)
635 { int i; 641 {
636 642 for (int i = 0; i < fthrows->dim; i++)
637 for (i = 0; i < fthrows->dim; i++)
638 { 643 {
639 Type *t = (Type *)fthrows->data[i]; 644 Type *t = (Type *)fthrows->data[i];
640 645
641 t = t->semantic(loc, sc); 646 t = t->semantic(loc, sc);
642 if (!t->isClassHandle()) 647 if (!t->isClassHandle())
694 vthis = v; 699 vthis = v;
695 } 700 }
696 } 701 }
697 else if (isNested()) 702 else if (isNested())
698 { 703 {
699 VarDeclaration *v; 704 /* The 'this' for a nested function is the link to the
700 705 * enclosing function's stack frame.
701 v = new ThisDeclaration(Type::tvoid->pointerTo()); 706 * Note that nested functions and member functions are disjoint.
707 */
708 VarDeclaration *v = new ThisDeclaration(Type::tvoid->pointerTo());
702 v->storage_class |= STCparameter | STCin; 709 v->storage_class |= STCparameter | STCin;
703 v->semantic(sc2); 710 v->semantic(sc2);
704 if (!sc2->insert(v)) 711 if (!sc2->insert(v))
705 assert(0); 712 assert(0);
706 v->parent = this; 713 v->parent = this;
779 if (!id) 786 if (!id)
780 { 787 {
781 /* Generate identifier for un-named parameter, 788 /* Generate identifier for un-named parameter,
782 * because we need it later on. 789 * because we need it later on.
783 */ 790 */
784 OutBuffer buf; 791 arg->ident = id = Identifier::generateId("_param_", i);
785 buf.printf("_param_%"PRIuSIZE, i);
786 char *name = (char *)buf.extractData();
787 id = new Identifier(name, TOKidentifier);
788 arg->ident = id;
789 } 792 }
790 VarDeclaration *v = new VarDeclaration(loc, arg->type, id, NULL); 793 VarDeclaration *v = new VarDeclaration(loc, arg->type, id, NULL);
791 //printf("declaring parameter %s of type %s\n", v->toChars(), v->type->toChars()); 794 //printf("declaring parameter %s of type %s\n", v->toChars(), v->type->toChars());
792 v->storage_class |= STCparameter; 795 v->storage_class |= STCparameter;
793 if (f->varargs == 2 && i + 1 == nparams) 796 if (f->varargs == 2 && i + 1 == nparams)
822 for (size_t j = 0; j < dim; j++) 825 for (size_t j = 0; j < dim; j++)
823 { Argument *narg = Argument::getNth(t->arguments, j); 826 { Argument *narg = Argument::getNth(t->arguments, j);
824 assert(narg->ident); 827 assert(narg->ident);
825 VarDeclaration *v = sc2->search(0, narg->ident, NULL)->isVarDeclaration(); 828 VarDeclaration *v = sc2->search(0, narg->ident, NULL)->isVarDeclaration();
826 assert(v); 829 assert(v);
827 Expression *e = new VarExp(0, v); 830 Expression *e = new VarExp(v->loc, v);
828 exps->data[j] = (void *)e; 831 exps->data[j] = (void *)e;
829 } 832 }
830 assert(arg->ident); 833 assert(arg->ident);
831 TupleDeclaration *v = new TupleDeclaration(0, arg->ident, exps); 834 TupleDeclaration *v = new TupleDeclaration(loc, arg->ident, exps);
832 //printf("declaring tuple %s\n", v->toChars()); 835 //printf("declaring tuple %s\n", v->toChars());
833 v->isexp = 1; 836 v->isexp = 1;
834 if (!sc2->insert(v)) 837 if (!sc2->insert(v))
835 error("parameter %s.%s is already defined", toChars(), v->toChars()); 838 error("parameter %s.%s is already defined", toChars(), v->toChars());
836 localsymtab->insert(v); 839 localsymtab->insert(v);
1567 Expressions *arguments = p->arguments; 1570 Expressions *arguments = p->arguments;
1568 MATCH match; 1571 MATCH match;
1569 1572
1570 if (f != m->lastf) // skip duplicates 1573 if (f != m->lastf) // skip duplicates
1571 { 1574 {
1572 TypeFunction *tf;
1573
1574 m->anyf = f; 1575 m->anyf = f;
1575 tf = (TypeFunction *)f->type; 1576 TypeFunction *tf = (TypeFunction *)f->type;
1576 match = (MATCH) tf->callMatch(arguments); 1577 match = (MATCH) tf->callMatch(arguments);
1577 //printf("match = %d\n", match); 1578 //printf("match = %d\n", match);
1578 if (match != MATCHnomatch) 1579 if (match != MATCHnomatch)
1579 { 1580 {
1580 if (match > m->last) 1581 if (match > m->last)
1908 linkage != LINKc && !isMember() && !isNested(); 1909 linkage != LINKc && !isMember() && !isNested();
1909 } 1910 }
1910 1911
1911 int FuncDeclaration::isWinMain() 1912 int FuncDeclaration::isWinMain()
1912 { 1913 {
1914 //printf("FuncDeclaration::isWinMain() %s\n", toChars());
1915 #if 0
1916 int x = ident == Id::WinMain &&
1917 linkage != LINKc && !isMember();
1918 printf("%s\n", x ? "yes" : "no");
1919 return x;
1920 #else
1913 return ident == Id::WinMain && 1921 return ident == Id::WinMain &&
1914 linkage != LINKc && !isMember(); 1922 linkage != LINKc && !isMember();
1923 #endif
1915 } 1924 }
1916 1925
1917 int FuncDeclaration::isDllMain() 1926 int FuncDeclaration::isDllMain()
1918 { 1927 {
1919 return ident == Id::DllMain && 1928 return ident == Id::DllMain &&
2088 //printf("\t\tf = %s, %d, %d\n", f->toChars(), f->isVirtual(), f->tookAddressOf); 2097 //printf("\t\tf = %s, %d, %d\n", f->toChars(), f->isVirtual(), f->tookAddressOf);
2089 if (f->isThis() || f->tookAddressOf) 2098 if (f->isThis() || f->tookAddressOf)
2090 goto Lyes; // assume f escapes this function's scope 2099 goto Lyes; // assume f escapes this function's scope
2091 2100
2092 // Look to see if any parents of f that are below this escape 2101 // Look to see if any parents of f that are below this escape
2093 for (Dsymbol *s = f->parent; s != this; s = s->parent) 2102 for (Dsymbol *s = f->parent; s && s != this; s = s->parent)
2094 { 2103 {
2095 f = s->isFuncDeclaration(); 2104 f = s->isFuncDeclaration();
2096 if (f && (f->isThis() || f->tookAddressOf)) 2105 if (f && (f->isThis() || f->tookAddressOf))
2097 goto Lyes; 2106 goto Lyes;
2098 } 2107 }
2194 CtorDeclaration::CtorDeclaration(Loc loc, Loc endloc, Arguments *arguments, int varargs) 2203 CtorDeclaration::CtorDeclaration(Loc loc, Loc endloc, Arguments *arguments, int varargs)
2195 : FuncDeclaration(loc, endloc, Id::ctor, STCundefined, NULL) 2204 : FuncDeclaration(loc, endloc, Id::ctor, STCundefined, NULL)
2196 { 2205 {
2197 this->arguments = arguments; 2206 this->arguments = arguments;
2198 this->varargs = varargs; 2207 this->varargs = varargs;
2199 //printf("CtorDeclaration() %s\n", toChars()); 2208 //printf("CtorDeclaration(loc = %s) %s\n", loc.toChars(), toChars());
2200 } 2209 }
2201 2210
2202 Dsymbol *CtorDeclaration::syntaxCopy(Dsymbol *s) 2211 Dsymbol *CtorDeclaration::syntaxCopy(Dsymbol *s)
2203 { 2212 {
2204 CtorDeclaration *f; 2213 CtorDeclaration *f;