comparison dmd2/expression.c @ 847:356e65836fb5

Merged DMD 2.021 frontend. Removed generated files from dmd/dmd2 dirs.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sat, 13 Dec 2008 16:14:37 +0100
parents 783f67fbdf4a
children 063ba84a965f
comparison
equal deleted inserted replaced
846:bc982f1ad106 847:356e65836fb5
10 10
11 #include <stdio.h> 11 #include <stdio.h>
12 #include <stdlib.h> 12 #include <stdlib.h>
13 #include <ctype.h> 13 #include <ctype.h>
14 #include <assert.h> 14 #include <assert.h>
15 #if _MSC_VER
15 #include <complex> 16 #include <complex>
17 #else
18 #endif
16 #include <math.h> 19 #include <math.h>
17 20
18 #if _WIN32 && __DMC__ 21 #if _WIN32 && __DMC__
19 extern "C" char * __cdecl __locale_decpoint; 22 extern "C" char * __cdecl __locale_decpoint;
20 #endif 23 #endif
713 // Convert lazy argument to a delegate 716 // Convert lazy argument to a delegate
714 if (p->storageClass & STClazy) 717 if (p->storageClass & STClazy)
715 { 718 {
716 arg = arg->toDelegate(sc, p->type); 719 arg = arg->toDelegate(sc, p->type);
717 } 720 }
721
722 /* Look for arguments that cannot 'escape' from the called
723 * function.
724 */
725 if (!tf->parameterEscapes(p))
726 {
727 /* Function literals can only appear once, so if this
728 * appearance was scoped, there cannot be any others.
729 */
730 if (arg->op == TOKfunction)
731 { FuncExp *fe = (FuncExp *)arg;
732 fe->fd->tookAddressOf = 0;
733 }
734
735 /* For passing a delegate to a scoped parameter,
736 * this doesn't count as taking the address of it.
737 * We only worry about 'escaping' references to the function.
738 */
739 else if (arg->op == TOKdelegate)
740 { DelegateExp *de = (DelegateExp *)arg;
741 if (de->e1->op == TOKvar)
742 { VarExp *ve = (VarExp *)de->e1;
743 FuncDeclaration *f = ve->var->isFuncDeclaration();
744 if (f)
745 { f->tookAddressOf--;
746 //printf("tookAddressOf = %d\n", f->tookAddressOf);
747 }
748 }
749 }
750 }
718 } 751 }
719 else 752 else
720 { 753 {
721 754
722 // If not D linkage, do promotions 755 // If not D linkage, do promotions
2182 return this; 2215 return this;
2183 } 2216 }
2184 sd = s->isStructDeclaration(); 2217 sd = s->isStructDeclaration();
2185 if (sd) 2218 if (sd)
2186 { 2219 {
2220 #if STRUCTTHISREF
2221 type = sd->type;
2222 #else
2187 type = sd->type->pointerTo(); 2223 type = sd->type->pointerTo();
2224 #endif
2188 return this; 2225 return this;
2189 } 2226 }
2190 } 2227 }
2191 } 2228 }
2192 2229
5174 5211
5175 Type *t1b = e1->type->toBasetype(); 5212 Type *t1b = e1->type->toBasetype();
5176 5213
5177 if (eright->op == TOKimport) // also used for template alias's 5214 if (eright->op == TOKimport) // also used for template alias's
5178 { 5215 {
5179 Dsymbol *s;
5180 ScopeExp *ie = (ScopeExp *)eright; 5216 ScopeExp *ie = (ScopeExp *)eright;
5181 5217
5182 s = ie->sds->search(loc, ident, 0); 5218 /* Disable access to another module's private imports.
5219 * The check for 'is sds our current module' is because
5220 * the current module should have access to its own imports.
5221 */
5222 Dsymbol *s = ie->sds->search(loc, ident,
5223 (ie->sds->isModule() && ie->sds != sc->module) ? 1 : 0);
5183 if (s) 5224 if (s)
5184 { 5225 {
5185 s = s->toAlias(); 5226 s = s->toAlias();
5186 checkDeprecated(sc, s); 5227 checkDeprecated(sc, s);
5187 5228
6017 Expression *av = new DeclarationExp(loc, tmp); 6058 Expression *av = new DeclarationExp(loc, tmp);
6018 av = new CommaExp(loc, av, new VarExp(loc, tmp)); 6059 av = new CommaExp(loc, av, new VarExp(loc, tmp));
6019 6060
6020 Expression *e = new DotVarExp(loc, av, ad->ctor, 1); 6061 Expression *e = new DotVarExp(loc, av, ad->ctor, 1);
6021 e = new CallExp(loc, e, arguments); 6062 e = new CallExp(loc, e, arguments);
6063 #if !STRUCTTHISREF
6064 /* Constructors return a pointer to the instance
6065 */
6022 e = new PtrExp(loc, e); 6066 e = new PtrExp(loc, e);
6067 #endif
6023 e = e->semantic(sc); 6068 e = e->semantic(sc);
6024 return e; 6069 return e;
6025 } 6070 }
6026 6071
6027 // No constructor, look for overload of opCall 6072 // No constructor, look for overload of opCall
6458 FuncDeclaration *f = dve->var->isFuncDeclaration(); 6503 FuncDeclaration *f = dve->var->isFuncDeclaration();
6459 6504
6460 if (f) 6505 if (f)
6461 { 6506 {
6462 if (!dve->hasOverloads) 6507 if (!dve->hasOverloads)
6463 f->tookAddressOf = 1; 6508 f->tookAddressOf++;
6464 Expression *e = new DelegateExp(loc, dve->e1, f, dve->hasOverloads); 6509 Expression *e = new DelegateExp(loc, dve->e1, f, dve->hasOverloads);
6465 e = e->semantic(sc); 6510 e = e->semantic(sc);
6466 return e; 6511 return e;
6467 } 6512 }
6468 } 6513 }
6476 6521
6477 FuncDeclaration *f = ve->var->isFuncDeclaration(); 6522 FuncDeclaration *f = ve->var->isFuncDeclaration();
6478 6523
6479 if (f) 6524 if (f)
6480 { 6525 {
6481 if (!ve->hasOverloads) 6526 if (!ve->hasOverloads ||
6482 f->tookAddressOf = 1; 6527 /* Because nested functions cannot be overloaded,
6528 * mark here that we took its address because castTo()
6529 * may not be called with an exact match.
6530 */
6531 f->toParent2()->isFuncDeclaration())
6532 f->tookAddressOf++;
6483 6533
6484 // LDC 6534 // LDC
6485 if (f && f->isIntrinsic()) 6535 if (f && f->isIntrinsic())
6486 { 6536 {
6487 error("cannot take the address of intrinsic function %s", e1->toChars()); 6537 error("cannot take the address of intrinsic function %s", e1->toChars());