Lines Matching refs:exp

74 Expression *semanticY(DotIdExp *exp, Scope *sc, int flag);
75 Expression *semanticY(DotTemplateInstanceExp *exp, Scope *sc, int flag);
76 StringExp *semanticString(Scope *sc, Expression *exp, const char *s);
196 * Determine if `exp`, which takes the address of `v`, can do so safely.
199 * exp = expression that takes the address of `v`
284 void visit(IdentifierExp *exp)
286 if (exp->type) // This is used as the dummy expression
288 result = exp;
293 Dsymbol *s = sc->search(exp->loc, exp->ident, &scopesym);
324 exp->error("with symbol %s is shadowing local symbol %s", s->toPrettyChars(), s2->toPrettyChars());
333 e = new VarExp(exp->loc, withsym->withstate->wthis);
334 e = new DotIdExp(exp->loc, e, exp->ident);
343 checkAccess(exp->loc, sc, NULL, d);
357 e = new TemplateExp(exp->loc, td, f);
364 e = resolve(exp->loc, sc, s, true);
376 e = new IdentifierExp(exp->loc, Id::This);
377 e = new DotIdExp(exp->loc, e, ad->aliasthis->ident);
378 e = new DotIdExp(exp->loc, e, exp->ident);
388 if (exp->ident == Id::ctfe)
392 exp->error("variable __ctfe cannot be read at compile time");
397 VarDeclaration *vd = new VarDeclaration(exp->loc, Type::tbool, Id::ctfe, NULL);
400 Expression *e = new VarExp(exp->loc, vd);
420 e = new VarExp(exp->loc, ss->withstate->wthis);
421 e = new DotIdExp(exp->loc, e, exp->ident);
435 if (const char *n = importHint(exp->ident->toChars()))
436 exp->error("`%s` is not defined, perhaps `import %s;` is needed?", exp->ident->toChars(), n);
437 else if (Dsymbol *s2 = sc->search_correct(exp->ident))
438 exp->error("undefined identifier `%s`, did you mean %s `%s`?", exp->ident->toChars(), s2->kind(), s2->toChars());
439 else if (const char *p = Scope::search_correct_C(exp->ident))
440 exp->error("undefined identifier `%s`, did you mean `%s`?", exp->ident->toChars(), p);
442 exp->error("undefined identifier `%s`", exp->ident->toChars());
802 void visit(TypeExp *exp)
804 if (exp->type->ty == Terror)
807 //printf("TypeExp::semantic(%s)\n", exp->type->toChars());
812 exp->type->resolve(exp->loc, sc, &e, &t, &s, true);
819 if (ve && ve->var && exp->parens && !ve->var->isStatic() && !(sc->stc & STCstatic) &&
823 e = new DotVarExp(exp->loc, new ThisExp(exp->loc), ve->var, false);
831 exp->type = t->semantic(exp->loc, sc);
832 e = exp;
837 e = resolve(exp->loc, sc, s, true);
843 exp->type->checkComplexTransition(exp->loc);
848 void visit(ScopeExp *exp)
850 if (exp->type)
852 result = exp;
856 ScopeDsymbol *sds2 = exp->sds;
866 Expression *e = new VarExp(exp->loc, withsym->withstate->wthis);
867 e = new DotTemplateInstanceExp(exp->loc, e, ti);
881 Expression *e = new DotTemplateInstanceExp(exp->loc, new ThisExp(exp->loc), ti->name, ti->tiargs);
892 Expression *e = new DotTemplateInstanceExp(exp->loc, new ThisExp(exp->loc), ti->name, ti->tiargs);
898 exp->sds = ti;
899 exp->type = Type::tvoid;
900 result = exp;
910 exp->sds = ti;
911 exp->type = Type::tvoid;
912 result = exp;
927 exp->error("forward reference of %s %s", v->kind(), v->toChars());
948 exp->error("recursive expansion of %s '%s'", ti->kind(), ti->toPrettyChars());
952 Expression *e = v->expandInitializer(exp->loc);
962 Expression *e = resolve(exp->loc, sc, s, true);
974 Expression *ex = new TypeExp(exp->loc, t);
981 result = semantic(new TemplateExp(exp->loc, td), sc);
985 exp->sds = sds2;
986 exp->type = Type::tvoid;
987 //printf("-2ScopeExp::semantic() %s\n", exp->toChars());
988 result = exp;
991 void visit(NewExp *exp)
993 if (exp->type) // if semantic() already run
995 result = exp;
1003 if (!exp->arguments && exp->newtype->ty == Tsarray)
1005 edim = ((TypeSArray *)exp->newtype)->dim;
1006 exp->newtype = ((TypeNext *)exp->newtype)->next;
1010 if (exp->thisexp)
1012 exp->thisexp = semantic(exp->thisexp, sc);
1013 if (exp->thisexp->op == TOKerror)
1015 cdthis = exp->thisexp->type->isClassHandle();
1018 exp->error("'this' for nested class must be a class type, not %s", exp->thisexp->type->toChars());
1023 exp->type = exp->newtype->semantic(exp->loc, sc);
1028 exp->type = exp->newtype->semantic(exp->loc, sc);
1030 if (exp->type->ty == Terror)
1035 if (exp->type->toBasetype()->ty == Ttuple)
1038 exp->type = new TypeSArray(exp->type, edim);
1039 exp->type = exp->type->semantic(exp->loc, sc);
1040 if (exp->type->ty == Terror)
1046 exp->arguments = new Expressions();
1047 exp->arguments->push(edim);
1048 exp->type = exp->type->arrayOf();
1052 exp->newtype = exp->type; // in case type gets cast to something else
1053 Type *tb = exp->type->toBasetype();
1056 if (arrayExpressionSemantic(exp->newargs, sc) ||
1057 preFunctionParameters(sc, exp->newargs))
1061 if (arrayExpressionSemantic(exp->arguments, sc) ||
1062 preFunctionParameters(sc, exp->arguments))
1067 if (exp->thisexp && tb->ty != Tclass)
1069 exp->error("e.new is only for allocating nested classes, not %s", tb->toChars());
1073 size_t nargs = exp->arguments ? exp->arguments->dim : 0;
1079 cd->size(exp->loc);
1086 exp->error("default construction is disabled for type %s", cd->type->toChars());
1092 exp->error("cannot create instance of interface %s", cd->toChars());
1097 exp->error("cannot create instance of abstract class %s", cd->toChars());
1102 errorSupplemental(exp->loc, "function '%s' is not implemented", fd->toFullSignature());
1120 exp->thisexp = new ThisExp(exp->loc);
1125 exp->error("outer class %s 'this' needed to 'new' nested class %s", cdn->toChars(), cd->toChars());
1134 exp->thisexp = new DotIdExp(exp->loc, exp->thisexp, Id::outer);
1136 exp->thisexp = semantic(exp->thisexp, sc);
1137 if (exp->thisexp->op == TOKerror)
1139 cdthis = exp->thisexp->type->isClassHandle();
1144 exp->error("'this' for nested class must be of type %s, not %s",
1145 cdn->toChars(), exp->thisexp->type->toChars());
1148 if (!MODimplicitConv(exp->thisexp->type->mod, exp->newtype->mod))
1150 exp->error("nested type %s should have the same or weaker constancy as enclosing type %s",
1151 exp->newtype->toChars(), exp->thisexp->type->toChars());
1155 else if (exp->thisexp)
1157 exp->error("e.new is only for allocating nested classes");
1165 exp->error("outer function context of %s is needed to 'new' nested class %s",
1173 else if (exp->thisexp)
1175 exp->error("e.new is only for allocating nested classes");
1182 Expression *e = new IntegerExp(exp->loc, cd->size(exp->loc), Type::tsize_t);
1183 if (!exp->newargs)
1184 exp->newargs = new Expressions();
1185 exp->newargs->shift(e);
1187 FuncDeclaration *f = resolveFuncCall(exp->loc, sc, cd->aggNew, NULL, tb, exp->newargs);
1190 exp->checkDeprecated(sc, f);
1191 exp->checkPurity(sc, f);
1192 exp->checkSafety(sc, f);
1193 exp->checkNogc(sc, f);
1194 checkAccess(cd, exp->loc, sc, f);
1198 if (functionParameters(exp->loc, sc, tf, NULL, exp->newargs, f, &rettype, &newprefix))
1201 exp->allocator = f->isNewDeclaration();
1202 assert(exp->allocator);
1206 if (exp->newargs && exp->newargs->dim)
1208 exp->error("no allocator for %s", cd->toChars());
1215 FuncDeclaration *f = resolveFuncCall(exp->loc, sc, cd->ctor, NULL, tb, exp->arguments, 0);
1218 exp->checkDeprecated(sc, f);
1219 exp->checkPurity(sc, f);
1220 exp->checkSafety(sc, f);
1221 exp->checkNogc(sc, f);
1222 checkAccess(cd, exp->loc, sc, f);
1225 if (!exp->arguments)
1226 exp->arguments = new Expressions();
1227 if (functionParameters(exp->loc, sc, tf, exp->type, exp->arguments, f, &exp->type, &exp->argprefix))
1230 exp->member = f->isCtorDeclaration();
1231 assert(exp->member);
1237 exp->error("no constructor for %s", cd->toChars());
1262 sd->size(exp->loc);
1269 exp->error("default construction is disabled for type %s", sd->type->toChars());
1277 Expression *e = new IntegerExp(exp->loc, sd->size(exp->loc), Type::tsize_t);
1278 if (!exp->newargs)
1279 exp->newargs = new Expressions();
1280 exp->newargs->shift(e);
1282 FuncDeclaration *f = resolveFuncCall(exp->loc, sc, sd->aggNew, NULL, tb, exp->newargs);
1285 exp->checkDeprecated(sc, f);
1286 exp->checkPurity(sc, f);
1287 exp->checkSafety(sc, f);
1288 exp->checkNogc(sc, f);
1289 checkAccess(sd, exp->loc, sc, f);
1293 if (functionParameters(exp->loc, sc, tf, NULL, exp->newargs, f, &rettype, &newprefix))
1296 exp->allocator = f->isNewDeclaration();
1297 assert(exp->allocator);
1301 if (exp->newargs && exp->newargs->dim)
1303 exp->error("no allocator for %s", sd->toChars());
1310 FuncDeclaration *f = resolveFuncCall(exp->loc, sc, sd->ctor, NULL, tb, exp->arguments, 0);
1313 exp->checkDeprecated(sc, f);
1314 exp->checkPurity(sc, f);
1315 exp->checkSafety(sc, f);
1316 exp->checkNogc(sc, f);
1317 checkAccess(sd, exp->loc, sc, f);
1320 if (!exp->arguments)
1321 exp->arguments = new Expressions();
1322 if (functionParameters(exp->loc, sc, tf, exp->type, exp->arguments, f, &exp->type, &exp->argprefix))
1325 exp->member = f->isCtorDeclaration();
1326 assert(exp->member);
1328 if (checkFrameAccess(exp->loc, sc, sd, sd->fields.dim))
1333 if (!exp->arguments)
1334 exp->arguments = new Expressions();
1336 if (!sd->fit(exp->loc, sc, exp->arguments, tb))
1338 if (!sd->fill(exp->loc, exp->arguments, false))
1340 if (checkFrameAccess(exp->loc, sc, sd, exp->arguments ? exp->arguments->dim : 0))
1344 exp->type = exp->type->pointerTo();
1353 exp->error("default construction is disabled for type %s", tb->nextOf()->toChars());
1360 exp->error("too many arguments for array");
1364 Expression *arg = (*exp->arguments)[i];
1370 exp->error("negative array index %s", arg->toChars());
1373 (*exp->arguments)[i] = arg;
1384 Expression *e = (*exp->arguments)[0];
1386 (*exp->arguments)[0] = e;
1390 exp->error("more than one argument for construction of %s", exp->type->toChars());
1394 exp->type = exp->type->pointerTo();
1398 exp->error("new can only create structs, dynamic arrays or class objects, not %s's", exp->type->toChars());
1403 //printf("NewExp:type '%s'\n", exp->type->toChars());
1404 semanticTypeInfo(sc, exp->type);
1408 result = Expression::combine(newprefix, exp);
1411 result = exp;
1507 void visit(TupleExp *exp)
1509 if (exp->type)
1511 result = exp;
1515 if (exp->e0)
1516 exp->e0 = semantic(exp->e0, sc);
1520 for (size_t i = 0; i < exp->exps->dim; i++)
1522 Expression *e = (*exp->exps)[i];
1526 exp->error("%s has no value", e->toChars());
1532 (*exp->exps)[i] = e;
1537 expandTuples(exp->exps);
1538 exp->type = new TypeTuple(exp->exps);
1539 exp->type = exp->type->semantic(exp->loc, sc);
1540 //printf("-TupleExp::semantic(%s)\n", exp->toChars());
1541 result = exp;
1544 void visit(FuncExp *exp)
1546 Expression *e = exp;
1552 if (!exp->type || exp->type == Type::tvoid)
1559 //if (exp->fd->treq)
1560 // exp->fd->treq = exp->fd->treq->semantic(exp->loc, sc);
1562 exp->genIdent(sc);
1565 if (exp->fd->treq && !exp->fd->type->nextOf())
1568 if (exp->fd->treq->ty == Tdelegate ||
1569 (exp->fd->treq->ty == Tpointer && exp->fd->treq->nextOf()->ty == Tfunction))
1570 tfv = (TypeFunction *)exp->fd->treq->nextOf();
1573 TypeFunction *tfl = (TypeFunction *)exp->fd->type;
1578 //printf("td = %p, treq = %p\n", exp->td, exp->fd->treq);
1579 if (exp->td)
1581 assert(exp->td->parameters && exp->td->parameters->dim);
1582 exp->td->semantic(sc);
1583 exp->type = Type::tvoid; // temporary type
1585 if (exp->fd->treq) // defer type determination
1588 if (exp->matchType(exp->fd->treq, sc, &fe) > MATCHnomatch)
1597 exp->fd->semantic(sc);
1600 exp->fd->semantic2(sc);
1602 exp->fd->semantic3(sc);
1606 if (exp->fd->type && exp->fd->type->ty == Tfunction && !exp->fd->type->nextOf())
1607 ((TypeFunction *)exp->fd->type)->next = Type::terror;
1613 if ((exp->fd->isNested() && exp->fd->tok == TOKdelegate) ||
1614 (exp->tok == TOKreserved && exp->fd->treq && exp->fd->treq->ty == Tdelegate))
1616 exp->type = new TypeDelegate(exp->fd->type);
1617 exp->type = exp->type->semantic(exp->loc, sc);
1619 exp->fd->tok = TOKdelegate;
1623 exp->type = new TypePointer(exp->fd->type);
1624 exp->type = exp->type->semantic(exp->loc, sc);
1625 //exp->type = exp->fd->type->pointerTo();
1635 if (exp->fd->treq && exp->fd->treq->ty == Tpointer)
1638 exp->fd->tok = TOKfunction;
1639 exp->fd->vthis = NULL;
1642 exp->fd->tookAddressOf++;
1650 Expression *callExpSemantic(FuncExp *exp, Scope *sc, Expressions *arguments)
1652 if ((!exp->type || exp->type == Type::tvoid) && exp->td && arguments && arguments->dim)
1660 exp->genIdent(sc);
1662 assert(exp->td->parameters && exp->td->parameters->dim);
1663 exp->td->semantic(sc);
1665 TypeFunction *tfl = (TypeFunction *)exp->fd->type;
1678 tiargs->reserve(exp->td->parameters->dim);
1680 for (size_t i = 0; i < exp->td->parameters->dim; i++)
1682 TemplateParameter *tp = (*exp->td->parameters)[i];
1694 TemplateInstance *ti = new TemplateInstance(exp->loc, exp->td, tiargs);
1695 Expression *se = new ScopeExp(exp->loc, ti);
1698 exp->error("cannot infer function literal type");
1701 return semantic(exp, sc);
1824 void visit(TypeidExp *exp)
1826 Type *ta = isType(exp->obj);
1827 Expression *ea = isExpression(exp->obj);
1828 Dsymbol *sa = isDsymbol(exp->obj);
1834 ta->resolve(exp->loc, sc, &ea, &ta, &sa, true);
1840 ea = resolve(exp->loc, sc, sym, false);
1852 exp->error("no type for typeid(%s)", ea ? ea->toChars() : (sa ? sa->toChars() : ""));
1857 ta->checkComplexTransition(exp->loc);
1864 error(exp->loc, "`object.TypeInfo_Class` could not be found, but is implicitly used");
1883 e = new TypeidExp(exp->loc, ta);
1884 e->type = getTypeInfoType(exp->loc, ta, sc);
1890 e = new CommaExp(exp->loc, ea, e); // execute ea
2221 void visit(BinAssignExp *exp)
2223 if (exp->type)
2225 result = exp;
2229 Expression *e = exp->op_overload(sc);
2236 if (exp->e1->checkReadModifyWrite(exp->op, exp->e2))
2239 if (exp->e1->op == TOKarraylength)
2242 e = ArrayLengthExp::rewriteOpAssign(exp);
2247 if (exp->e1->op == TOKslice || exp->e1->type->ty == Tarray || exp->e1->type->ty == Tsarray)
2249 if (checkNonAssignmentArrayOp(exp->e1))
2252 if (exp->e1->op == TOKslice)
2253 ((SliceExp *)exp->e1)->arrayop = true;
2256 if (exp->e2->implicitConvTo(exp->e1->type->nextOf()))
2259 exp->e2 = exp->e2->castTo(sc, exp->e1->type->nextOf());
2261 else if (Expression *ex = typeCombine(exp, sc))
2266 exp->type = exp->e1->type;
2267 result = arrayOp(exp, sc);
2271 exp->e1 = semantic(exp->e1, sc);
2272 exp->e1 = exp->e1->optimize(WANTvalue);
2273 exp->e1 = exp->e1->modifiableLvalue(sc, exp->e1);
2274 exp->type = exp->e1->type;
2275 if (exp->checkScalar())
2278 int arith = (exp->op == TOKaddass || exp->op == TOKminass || exp->op == TOKmulass ||
2279 exp->op == TOKdivass || exp->op == TOKmodass || exp->op == TOKpowass);
2280 int bitwise = (exp->op == TOKandass || exp->op == TOKorass || exp->op == TOKxorass);
2281 int shift = (exp->op == TOKshlass || exp->op == TOKshrass || exp->op == TOKushrass);
2283 if (bitwise && exp->type->toBasetype()->ty == Tbool)
2284 exp->e2 = exp->e2->implicitCastTo(sc, exp->type);
2285 else if (exp->checkNoBool())
2288 if ((exp->op == TOKaddass || exp->op == TOKminass) &&
2289 exp->e1->type->toBasetype()->ty == Tpointer &&
2290 exp->e2->type->toBasetype()->isintegral())
2292 result = scaleFactor(exp, sc);
2296 if (Expression *ex = typeCombine(exp, sc))
2302 if (arith && exp->checkArithmeticBin())
2304 if ((bitwise || shift) && exp->checkIntegralBin())
2308 if (exp->e2->type->toBasetype()->ty != Tvector)
2309 exp->e2 = exp->e2->castTo(sc, Type::tshiftcnt);
2312 if (!Target::isVectorOpSupported(exp->type->toBasetype(), exp->op, exp->e2->type->toBasetype()))
2314 result = exp->incompatibleTypes();
2318 if (exp->e1->op == TOKerror || exp->e2->op == TOKerror)
2321 e = exp->checkOpAssignTypes(sc);
2328 assert(e->op == TOKassign || e == exp);
2332 void visit(CompileExp *exp)
2334 StringExp *se = semanticString(sc, exp->e1, "argument to mixin");
2339 Parser p(exp->loc, sc->_module, (utf8_t *)se->string, se->len, 0);
2350 exp->error("incomplete mixin expression (%s)", se->toChars());
2421 void visit(AssertExp *exp)
2423 if (Expression *ex = unaSemantic(exp, sc))
2428 exp->e1 = resolveProperties(sc, exp->e1);
2430 exp->e1 = exp->e1->optimize(WANTvalue);
2431 exp->e1 = exp->e1->toBoolean(sc);
2432 if (exp->msg)
2434 exp->msg = semantic(exp->msg, sc);
2435 exp->msg = resolveProperties(sc, exp->msg);
2436 exp->msg = exp->msg->implicitCastTo(sc, Type::tchar->constOf()->arrayOf());
2437 exp->msg = exp->msg->optimize(WANTvalue);
2440 if (exp->e1->op == TOKerror)
2442 result = exp->e1;
2445 if (exp->msg && exp->msg->op == TOKerror)
2447 result = exp->msg;
2451 bool f1 = checkNonAssignmentArrayOp(exp->e1);
2452 bool f2 = exp->msg && checkNonAssignmentArrayOp(exp->msg);
2456 if (exp->e1->isBool(false))
2470 Expression *e = new HaltExp(exp->loc);
2476 exp->type = Type::tvoid;
2477 result = exp;
2480 void visit(DotIdExp *exp)
2482 Expression *e = semanticY(exp, sc, 1);
2502 e = resolveUFCSProperties(sc, exp);
2524 void visit(DotVarExp *exp)
2526 if (exp->type)
2528 result = exp;
2532 exp->var = exp->var->toAlias()->isDeclaration();
2534 exp->e1 = semantic(exp->e1, sc);
2536 if (TupleDeclaration *tup = exp->var->isTupleDeclaration())
2544 Expression *ev = sc->func ? extractSideEffect(sc, "__tup", &e0, exp->e1) : exp->e1;
2558 e = new DotVarExp(exp->loc, ev, s->isDeclaration());
2563 e = new DsymbolExp(exp->loc, (Dsymbol *)o);
2567 e = new TypeExp(exp->loc, (Type *)o);
2571 exp->error("%s is not an expression", o->toChars());
2577 Expression *e = new TupleExp(exp->loc, e0, exps);
2583 exp->e1 = exp->e1->addDtorHook(sc);
2585 Type *t1 = exp->e1->type;
2587 if (FuncDeclaration *fd = exp->var->isFuncDeclaration())
2599 Expression *e = resolve(exp->loc, sc, fd, false);
2600 result = Expression::combine(exp->e1, e);
2604 exp->type = fd->type;
2605 assert(exp->type);
2607 else if (exp->var->isOverDeclaration())
2609 exp->type = Type::tvoid; // ambiguous type?
2613 exp->type = exp->var->type;
2614 if (!exp->type && global.errors)
2619 assert(exp->type);
2624 exp->type = exp->type->addMod(t1->mod);
2626 Dsymbol *vparent = exp->var->toParent();
2629 if (Expression *e1x = getRightThis(exp->loc, sc, ad, exp->e1, exp->var, 1))
2630 exp->e1 = e1x;
2635 Expression *e = new VarExp(exp->loc, exp->var);
2640 checkAccess(exp->loc, sc, exp->e1, exp->var);
2642 VarDeclaration *v = exp->var->isVarDeclaration();
2656 checkAccess(exp->loc, sc, exp->e1, v);
2657 Expression *e = new VarExp(exp->loc, v);
2658 e = new CommaExp(exp->loc, exp->e1, e);
2665 //printf("-DotVarExp::semantic('%s')\n", exp->toChars());
2666 result = exp;
2669 void visit(DotTemplateInstanceExp *exp)
2672 Expression *e = semanticY(exp, sc, 1);
2674 e = resolveUFCSProperties(sc, exp);
2715 void visit(DotTypeExp *exp)
2717 if (exp->type)
2719 result = exp;
2723 if (Expression *e = unaSemantic(exp, sc))
2729 exp->type = exp->sym->getType()->addMod(exp->e1->type->mod);
2730 result = exp;
2733 void visit(CallExp *exp)
2735 if (exp->type)
2737 result = exp; // semantic() already run
2745 Expression *e1org = exp->e1;
2747 if (exp->e1->op == TOKcomma)
2751 CommaExp *ce = (CommaExp *)exp->e1;
2752 exp->e1 = ce->e2;
2753 ce->e2 = exp;
2758 if (exp->e1->op == TOKdelegate)
2760 DelegateExp *de = (DelegateExp *)exp->e1;
2761 exp->e1 = new DotVarExp(de->loc, de->e1, de->func, de->hasOverloads);
2762 result = semantic(exp, sc);
2766 if (exp->e1->op == TOKfunction)
2768 if (arrayExpressionSemantic(exp->arguments, sc) ||
2769 preFunctionParameters(sc, exp->arguments))
2775 FuncExp *fe = (FuncExp *)exp->e1;
2776 exp->e1 = callExpSemantic(fe, sc, exp->arguments);
2777 if (exp->e1->op == TOKerror)
2779 result = exp->e1;
2784 if (Expression *ex = resolveUFCS(sc, exp))
2793 if (exp->e1->op == TOKscope)
2795 ScopeExp *se = (ScopeExp *)exp->e1;
2810 exp->e1 = new VarExp(exp->e1->loc, withsym->withstate->wthis);
2811 exp->e1 = new DotTemplateInstanceExp(exp->e1->loc, exp->e1, ti);
2821 exp->e1 = new TemplateExp(exp->loc, td);
2823 exp->e1 = new VarExp(exp->loc, od);
2825 exp->e1 = new OverExp(exp->loc, ti->tempdecl->isOverloadSet());
2829 Expression *e1x = semantic(exp->e1, sc);
2835 exp->e1 = e1x;
2844 if (exp->e1->op == TOKdotti && !exp->e1->type)
2846 DotTemplateInstanceExp *se = (DotTemplateInstanceExp *)exp->e1;
2864 exp->e1 = new DotTemplateExp(exp->loc, se->e1, td);
2867 exp->e1 = new DotVarExp(exp->loc, se->e1, od, true);
2870 exp->e1 = new DotExp(exp->loc, se->e1, new OverExp(exp->loc, ti->tempdecl->isOverloadSet()));
2874 Expression *e1x = semantic(exp->e1, sc);
2880 exp->e1 = e1x;
2886 //printf("Lagain: %s\n", exp->toChars());
2887 exp->f = NULL;
2888 if (exp->e1->op == TOKthis || exp->e1->op == TOKsuper)
2894 if (exp->e1->op == TOKdotid)
2896 DotIdExp *die = (DotIdExp *)exp->e1;
2897 exp->e1 = semantic(die, sc);
2902 if (exp->e1->op == TOKdotti && !exp->e1->type)
2912 exp->error("recursive evaluation of %s", exp->toChars());
2916 Expression *ex = unaSemantic(exp, sc);
2927 if (exp->e1->op == TOKvar)
2929 VarExp *ve = (VarExp *)exp->e1;
2936 (tf = (TypeFunction *)tf->semantic(exp->loc, sc))->next = tw; // hack for bug7757
2938 ve->type = t->semantic(exp->loc, sc);
2945 if (exp->e1->op == TOKsymoff && ((SymOffExp *)exp->e1)->hasOverloads)
2947 SymOffExp *se = (SymOffExp *)exp->e1;
2948 exp->e1 = new VarExp(se->loc, se->var, true);
2949 exp->e1 = semantic(exp->e1, sc);
2951 else if (exp->e1->op == TOKdot)
2953 DotExp *de = (DotExp *) exp->e1;
2959 exp->e1 = de->e2;
2962 else if (exp->e1->op == TOKstar && exp->e1->type->ty == Tfunction)
2965 exp->e1 = ((PtrExp *)exp->e1)->e1;
2969 t1 = exp->e1->type ? exp->e1->type->toBasetype() : NULL;
2971 if (exp->e1->op == TOKerror)
2973 result = exp->e1;
2976 if (arrayExpressionSemantic(exp->arguments, sc) ||
2977 preFunctionParameters(sc, exp->arguments))
2988 sd->size(exp->loc); // Resolve forward references to construct object
2995 if (exp->e1->op == TOKtype && sd->ctor)
2997 if (!sd->noDefaultCtor && !(exp->arguments && exp->arguments->dim))
3000 StructLiteralExp *sle = new StructLiteralExp(exp->loc, sd, NULL, exp->e1->type);
3001 if (!sd->fill(exp->loc, sle->elements, true))
3003 if (checkFrameAccess(exp->loc, sc, sd, sle->elements->dim))
3006 sle->type = exp->e1->type;
3016 e = new DotVarExp(exp->loc, e, cf, true);
3020 e = new DotTemplateExp(exp->loc, e, td);
3024 e = new DotExp(exp->loc, e, new OverExp(exp->loc, os));
3028 e = new CallExp(exp->loc, e, exp->arguments);
3036 if (exp->e1->op != TOKtype)
3038 if (sd->aliasthis && exp->e1->type != exp->att1)
3040 if (!exp->att1 && exp->e1->type->checkAliasThisRec())
3041 exp->att1 = exp->e1->type;
3042 exp->e1 = resolveAliasThis(sc, exp->e1);
3045 exp->error("%s %s does not overload ()", sd->kind(), sd->toChars());
3052 Expression *e = new StructLiteralExp(exp->loc, sd, exp->arguments, exp->e1->type);
3060 Expression *e = new DotIdExp(exp->loc, exp->e1, Id::call);
3061 e = new CallExp(exp->loc, e, exp->arguments);
3065 else if (exp->e1->op == TOKtype && t1->isscalar())
3071 if (exp->e1->type->ty == Tenum)
3073 t1 = exp->e1->type;
3076 if (!exp->arguments || exp->arguments->dim == 0)
3078 e = t1->defaultInitLiteral(exp->loc);
3080 else if (exp->arguments->dim == 1)
3082 e = (*exp->arguments)[0];
3084 e = new CastExp(exp->loc, e, t1);
3088 exp->error("more than one argument for construction of %s", t1->toChars());
3096 if ((exp->e1->op == TOKdotvar && t1->ty == Tfunction) ||
3097 exp->e1->op == TOKdottd)
3099 UnaExp *ue = (UnaExp *)(exp->e1);
3115 if (exp->e1->op == TOKdotvar)
3117 dve = (DotVarExp *)(exp->e1);
3125 dte = (DotTemplateExp *)(exp->e1);
3130 exp->f = resolveFuncCall(exp->loc, sc, s, tiargs, ue1 ? ue1->type : NULL, exp->arguments);
3131 if (!exp->f || exp->f->errors || exp->f->type->ty == Terror)
3133 if (exp->f->interfaceVirtual)
3137 BaseClass *b = exp->f->interfaceVirtual;
3142 int vi = exp->f->findVtblIndex((Dsymbols*)&ad2->vtbl, (int)ad2->vtbl.dim);
3144 exp->f = ad2->vtbl[vi]->isFuncDeclaration();
3145 assert(exp->f);
3147 if (exp->f->needThis())
3149 AggregateDeclaration *ad = exp->f->toParent2()->isAggregateDeclaration();
3150 ue->e1 = getRightThis(exp->loc, sc, ad, ue->e1, exp->f);
3158 if (!(exp->f->type->ty == Tfunction && ((TypeFunction *)exp->f->type)->isscope))
3160 if (global.params.vsafe && checkParamArgumentEscape(sc, exp->f, Id::This, ethis, false))
3170 exp->f->addPostInvariant()
3173 exp->error("cannot call public/export function %s from invariant", exp->f->toChars());
3177 exp->checkDeprecated(sc, exp->f);
3178 exp->checkPurity(sc, exp->f);
3179 exp->checkSafety(sc, exp->f);
3180 exp->checkNogc(sc, exp->f);
3181 checkAccess(exp->loc, sc, ue->e1, exp->f);
3182 if (!exp->f->needThis())
3184 exp->e1 = Expression::combine(ue->e1, new VarExp(exp->loc, exp->f, false));
3190 if (exp->e1->op == TOKdotvar)
3192 dve->var = exp->f;
3193 exp->e1->type = exp->f->type;
3197 exp->e1 = new DotVarExp(exp->loc, dte->e1, exp->f, false);
3198 exp->e1 = semantic(exp->e1, sc);
3199 if (exp->e1->op == TOKerror)
3201 ue = (UnaExp *)exp->e1;
3205 AggregateDeclaration *ad = exp->f->isThis();
3212 exp->directcall = true;
3215 exp->directcall = true;
3217 exp->directcall = true;
3228 if (exp->e1->type->ty == Tpointer && exp->e1->type->nextOf()->ty == Tfunction)
3230 Expression *e = new PtrExp(exp->loc, exp->e1);
3231 e->type = exp->e1->type->nextOf();
3232 exp->e1 = e;
3234 t1 = exp->e1->type;
3236 else if (exp->e1->op == TOKsuper)
3243 exp->error("super class constructor call must be in a constructor");
3248 exp->error("no super class constructor for %s", cd->baseClass->toChars());
3255 exp->error("constructor calls not allowed in loops or after labels");
3257 exp->error("multiple constructor calls");
3259 exp->error("an earlier return statement skips constructor");
3265 exp->f = resolveOverloadSet(exp->loc, sc, os, NULL, tthis, exp->arguments);
3267 exp->f = resolveFuncCall(exp->loc, sc, cd->baseClass->ctor, NULL, tthis, exp->arguments, 0);
3268 if (!exp->f || exp->f->errors)
3270 exp->checkDeprecated(sc, exp->f);
3271 exp->checkPurity(sc, exp->f);
3272 exp->checkSafety(sc, exp->f);
3273 exp->checkNogc(sc, exp->f);
3274 checkAccess(exp->loc, sc, NULL, exp->f);
3276 exp->e1 = new DotVarExp(exp->e1->loc, exp->e1, exp->f, false);
3277 exp->e1 = semantic(exp->e1, sc);
3278 t1 = exp->e1->type;
3280 else if (exp->e1->op == TOKthis)
3286 exp->error("constructor call must be in a constructor");
3293 exp->error("constructor calls not allowed in loops or after labels");
3295 exp->error("multiple constructor calls");
3297 exp->error("an earlier return statement skips constructor");
3303 exp->f = resolveOverloadSet(exp->loc, sc, os, NULL, tthis, exp->arguments);
3305 exp->f = resolveFuncCall(exp->loc, sc, ad->ctor, NULL, tthis, exp->arguments, 0);
3306 if (!exp->f || exp->f->errors)
3308 exp->checkDeprecated(sc, exp->f);
3309 exp->checkPurity(sc, exp->f);
3310 exp->checkSafety(sc, exp->f);
3311 exp->checkNogc(sc, exp->f);
3312 //checkAccess(exp->loc, sc, NULL, exp->f); // necessary?
3314 exp->e1 = new DotVarExp(exp->e1->loc, exp->e1, exp->f, false);
3315 exp->e1 = semantic(exp->e1, sc);
3316 t1 = exp->e1->type;
3320 if (exp->f == sc->func)
3322 exp->error("cyclic constructor call");
3326 else if (exp->e1->op == TOKoverloadset)
3328 OverloadSet *os = ((OverExp *)exp->e1)->vars;
3329 exp->f = resolveOverloadSet(exp->loc, sc, os, tiargs, tthis, exp->arguments);
3330 if (!exp->f)
3333 exp->e1 = new DotVarExp(exp->loc, ethis, exp->f, false);
3335 exp->e1 = new VarExp(exp->loc, exp->f, false);
3340 exp->error("function expected before (), not '%s'", exp->e1->toChars());
3352 exp->f = NULL;
3353 if (exp->e1->op == TOKfunction)
3356 assert(((FuncExp *)exp->e1)->fd);
3357 exp->f = ((FuncExp *)exp->e1)->fd;
3358 tf = (TypeFunction *)exp->f->type;
3373 else if (exp->e1->op == TOKdotvar &&
3374 ((DotVarExp *)exp->e1)->var->isOverDeclaration())
3376 DotVarExp *dve = (DotVarExp *)exp->e1;
3377 exp->f = resolveFuncCall(exp->loc, sc, dve->var, tiargs, dve->e1->type, exp->arguments, 2);
3378 if (!exp->f)
3380 if (exp->f->needThis())
3382 dve->var = exp->f;
3383 dve->type = exp->f->type;
3387 exp->e1 = new VarExp(dve->loc, exp->f, false);
3388 Expression *e = new CommaExp(exp->loc, dve->e1, exp);
3392 else if (exp->e1->op == TOKvar &&
3393 ((VarExp *)exp->e1)->var->isOverDeclaration())
3395 s = ((VarExp *)exp->e1)->var;
3398 else if (exp->e1->op == TOKtemplate)
3400 s = ((TemplateExp *)exp->e1)->td;
3402 exp->f = resolveFuncCall(exp->loc, sc, s, tiargs, NULL, exp->arguments);
3403 if (!exp->f || exp->f->errors)
3405 if (exp->f->needThis())
3411 Expression *ex = new ThisExp(exp->loc);
3413 exp->e1 = new DotVarExp(exp->loc, ex, exp->f, false);
3416 else if (isNeedThisScope(sc, exp->f))
3418 exp->error("need 'this' for '%s' of type '%s'", exp->f->toChars(), exp->f->type->toChars());
3422 exp->e1 = new VarExp(exp->e1->loc, exp->f, false);
3427 exp->error("function expected before (), not %s of type %s", exp->e1->toChars(), exp->e1->type->toChars());
3431 if (!tf->callMatch(NULL, exp->arguments))
3436 argExpTypesToCBuffer(&buf, exp->arguments);
3441 //printf("tf = %s, args = %s\n", tf->deco, (*exp->arguments)[0]->type->deco);
3442 ::error(exp->loc, "%s %s %s is not callable using argument types %s",
3443 p, exp->e1->toChars(), parametersTypeToChars(tf->parameters, tf->varargs),
3450 if (exp->f)
3452 exp->checkPurity(sc, exp->f);
3453 exp->checkSafety(sc, exp->f);
3454 exp->checkNogc(sc, exp->f);
3455 if (exp->f->checkNestedReference(sc, exp->loc))
3463 exp->error("pure %s '%s' cannot call impure %s '%s'",
3464 sc->func->kind(), sc->func->toPrettyChars(), p, exp->e1->toChars());
3469 exp->error("@nogc %s '%s' cannot call non-@nogc %s '%s'",
3470 sc->func->kind(), sc->func->toPrettyChars(), p, exp->e1->toChars());
3475 exp->error("@safe %s '%s' cannot call @system %s '%s'",
3476 sc->func->kind(), sc->func->toPrettyChars(), p, exp->e1->toChars());
3485 Expression *e = new PtrExp(exp->loc, exp->e1);
3487 exp->e1 = e;
3491 else if (exp->e1->op == TOKvar)
3494 VarExp *ve = (VarExp *)exp->e1;
3496 exp->f = ve->var->isFuncDeclaration();
3497 assert(exp->f);
3501 exp->f = resolveFuncCall(exp->loc, sc, exp->f, tiargs, NULL, exp->arguments, 2);
3504 exp->f = exp->f->toAliasFunc();
3505 TypeFunction *tf = (TypeFunction *)exp->f->type;
3506 if (!tf->callMatch(NULL, exp->arguments))
3511 argExpTypesToCBuffer(&buf, exp->arguments);
3514 //printf("tf = %s, args = %s\n", tf->deco, (*exp->arguments)[0]->type->deco);
3515 ::error(exp->loc, "%s %s is not callable using argument types %s",
3516 exp->e1->toChars(), parametersTypeToChars(tf->parameters, tf->varargs),
3519 exp->f = NULL;
3522 if (!exp->f || exp->f->errors)
3525 if (exp->f->needThis())
3528 if (exp->f->checkNestedReference(sc, exp->loc))
3536 Expression *ex = new ThisExp(exp->loc);
3538 exp->e1 = new DotVarExp(exp->loc, ex, ve->var);
3543 else if (isNeedThisScope(sc, exp->f))
3545 exp->error("need 'this' for '%s' of type '%s'", exp->f->toChars(), exp->f->type->toChars());
3550 exp->checkDeprecated(sc, exp->f);
3551 exp->checkPurity(sc, exp->f);
3552 exp->checkSafety(sc, exp->f);
3553 exp->checkNogc(sc, exp->f);
3554 checkAccess(exp->loc, sc, NULL, exp->f);
3555 if (exp->f->checkNestedReference(sc, exp->loc))
3563 exp->e1 = new VarExp(ve->loc, exp->f, false);
3564 exp->e1->type = exp->f->type;
3566 t1 = exp->f->type;
3571 if (!exp->arguments)
3572 exp->arguments = new Expressions();
3573 if (functionParameters(exp->loc, sc, (TypeFunction *)(t1), tthis, exp->arguments, exp->f, &exp->type, &argprefix))
3576 if (!exp->type)
3578 exp->e1 = e1org; // Bugzilla 10922, avoid recursive expression printing
3579 exp->error("forward reference to inferred return type of function call '%s'", exp->toChars());
3583 if (exp->f && exp->f->tintro)
3585 Type *t = exp->type;
3587 TypeFunction *tf = (TypeFunction *)exp->f->tintro;
3591 exp->type = tf->next;
3592 result = Expression::combine(argprefix, exp->castTo(sc, t));
3598 if (exp->f && exp->f->isFuncLiteralDeclaration() &&
3601 exp->f->tookAddressOf = 0;
3604 result = Expression::combine(argprefix, exp);
3607 void visit(AddrExp *exp)
3609 if (exp->type)
3611 result = exp;
3615 if (Expression *ex = unaSemantic(exp, sc))
3620 int wasCond = exp->e1->op == TOKquestion;
3621 if (exp->e1->op == TOKdotti)
3623 DotTemplateInstanceExp* dti = (DotTemplateInstanceExp *)exp->e1;
3634 exp->e1 = new DotVarExp(exp->e1->loc, dti->e1, f);
3635 exp->e1 = semantic(exp->e1, sc);
3639 else if (exp->e1->op == TOKscope)
3641 TemplateInstance *ti = ((ScopeExp *)exp->e1)->sds->isTemplateInstance();
3652 exp->e1 = new VarExp(exp->e1->loc, f);
3653 exp->e1 = semantic(exp->e1, sc);
3657 exp->e1 = exp->e1->toLvalue(sc, NULL);
3658 if (exp->e1->op == TOKerror)
3660 result = exp->e1;
3663 if (checkNonAssignmentArrayOp(exp->e1))
3666 if (!exp->e1->type)
3668 exp->error("cannot take address of %s", exp->e1->toChars());
3673 if (FuncDeclaration *f = isFuncAddress(exp, &hasOverloads))
3675 if (!hasOverloads && f->checkForwardRef(exp->loc))
3678 else if (!exp->e1->type->deco)
3680 if (exp->e1->op == TOKvar)
3682 VarExp *ve = (VarExp *)exp->e1;
3684 exp->error("forward reference to %s %s", d->kind(), d->toChars());
3687 exp->error("forward reference to %s", exp->e1->toChars());
3691 exp->type = exp->e1->type->pointerTo();
3694 if (exp->e1->op == TOKdotvar)
3696 DotVarExp *dve = (DotVarExp *)exp->e1;
3706 e = new DelegateExp(exp->loc, dve->e1, f, dve->hasOverloads);
3708 e = new CommaExp(exp->loc, dve->e1, new AddrExp(exp->loc, new VarExp(exp->loc, f, dve->hasOverloads)));
3715 if (checkUnsafeAccess(sc, dve, !exp->type->isMutable(), true))
3724 if (!checkAddressVar(sc, exp, v))
3734 if (!checkAddressVar(sc, exp, v))
3739 else if (exp->e1->op == TOKvar)
3741 VarExp *ve = (VarExp *)exp->e1;
3746 if (!checkAddressVar(sc, exp, v))
3769 Expression *e = new DelegateExp(exp->loc, new NullExp(exp->loc, Type::tnull), f, ve->hasOverloads);
3775 Expression *e = new DelegateExp(exp->loc, exp->e1, f, ve->hasOverloads);
3787 Expression *ethis = new ThisExp(exp->loc);
3788 Expression *e = new DelegateExp(exp->loc, ethis, f, ve->hasOverloads);
3797 exp->error("'this' reference necessary to take address of member %s in @safe function %s",
3804 else if ((exp->e1->op == TOKthis || exp->e1->op == TOKsuper) && global.params.vsafe)
3806 ThisExp *ve = (ThisExp *)exp->e1;
3810 if (!checkAddressVar(sc, exp, v))
3814 else if (exp->e1->op == TOKcall)
3816 CallExp *ce = (CallExp *)exp->e1;
3822 exp->error("cannot take address of ref return of %s() in @safe function %s",
3827 else if (exp->e1->op == TOKindex)
3834 IndexExp *ei = (IndexExp *)exp->e1;
3842 if (!checkAddressVar(sc, exp, v))
3854 assert(exp->e1->op == TOKstar);
3855 PtrExp *pe = (PtrExp *)exp->e1;
3868 result = exp->optimize(WANTvalue);
3871 void visit(PtrExp *exp)
3873 if (exp->type)
3875 result = exp;
3879 Expression *e = exp->op_overload(sc);
3886 Type *tb = exp->e1->type->toBasetype();
3890 exp->type = ((TypePointer *)tb)->next;
3895 exp->error("using * on an array is no longer supported; use *(%s).ptr instead", exp->e1->toChars());
3896 exp->type = ((TypeArray *)tb)->next;
3897 exp->e1 = exp->e1->castTo(sc, exp->type->pointerTo());
3901 exp->error("can only * a pointer, not a '%s'", exp->e1->type->toChars());
3907 if (exp->checkValue())
3910 result = exp;
3913 void visit(NegExp *exp)
3915 if (exp->type)
3917 result = exp;
3921 Expression *e = exp->op_overload(sc);
3928 exp->type = exp->e1->type;
3929 Type *tb = exp->type->toBasetype();
3932 if (!isArrayOpValid(exp->e1))
3934 exp->error("invalid array operation %s (possible missing [])", exp->toChars());
3937 result = exp;
3941 if (!Target::isVectorOpSupported(tb, exp->op))
3943 result = exp->incompatibleTypes();
3946 if (exp->e1->checkNoBool())
3948 if (exp->e1->checkArithmetic())
3951 result = exp;
3954 void visit(UAddExp *exp)
3956 assert(!exp->type);
3958 Expression *e = exp->op_overload(sc);
3965 if (!Target::isVectorOpSupported(exp->e1->type->toBasetype(), exp->op))
3967 result = exp->incompatibleTypes();
3970 if (exp->e1->checkNoBool())
3972 if (exp->e1->checkArithmetic())
3975 result = exp->e1;
3978 void visit(ComExp *exp)
3980 if (exp->type)
3982 result = exp;
3986 Expression *e = exp->op_overload(sc);
3993 exp->type = exp->e1->type;
3994 Type *tb = exp->type->toBasetype();
3997 if (!isArrayOpValid(exp->e1))
3999 exp->error("invalid array operation %s (possible missing [])", exp->toChars());
4002 result = exp;
4006 if (!Target::isVectorOpSupported(tb, exp->op))
4008 result = exp->incompatibleTypes();
4011 if (exp->e1->checkNoBool())
4013 if (exp->e1->checkIntegral())
4016 result = exp;
4061 void visit(DeleteExp *exp)
4063 if (Expression *ex = unaSemantic(exp, sc))
4068 exp->e1 = resolveProperties(sc, exp->e1);
4069 exp->e1 = exp->e1->modifiableLvalue(sc, NULL);
4070 if (exp->e1->op == TOKerror)
4072 result = exp->e1;
4075 exp->type = Type::tvoid;
4078 Type *tb = exp->e1->type->toBasetype();
4087 exp->error("cannot delete instance of COM interface %s", cd->toChars());
4120 v = copyToTemp(0, "__tmpea", exp->e1);
4122 ea = new DeclarationExp(exp->loc, v);
4128 Expression *e = ea ? new VarExp(exp->loc, v) : exp->e1;
4130 eb = new CallExp(exp->loc, e);
4137 Expression *e = ea ? new VarExp(exp->loc, v) : exp->e1->castTo(sc, tpv);
4138 e = new CallExp(exp->loc, new VarExp(exp->loc, f, false), e);
4161 exp->error("cannot delete type %s", exp->e1->type->toChars());
4170 err |= exp->checkPurity(sc, ad->dtor);
4171 err |= exp->checkSafety(sc, ad->dtor);
4172 err |= exp->checkNogc(sc, ad->dtor);
4176 err |= exp->checkPurity(sc, ad->aggDelete);
4177 err |= exp->checkSafety(sc, ad->aggDelete);
4178 err |= exp->checkNogc(sc, ad->aggDelete);
4185 !exp->isRAII &&
4188 exp->error("%s is not @safe but is used in @safe function %s", exp->toChars(), sc->func->toChars());
4194 result = exp;
4197 void visit(CastExp *exp)
4200 if (exp->type)
4202 result = exp;
4206 if (exp->to)
4208 exp->to = exp->to->semantic(exp->loc, sc);
4209 if (exp->to == Type::terror)
4212 if (!exp->to->hasPointers())
4213 setNoderefOperand(exp);
4217 exp->e1 = inferType(exp->e1, exp->to);
4220 if (Expression *ex = unaSemantic(exp, sc))
4225 Expression *e1x = resolveProperties(sc, exp->e1);
4233 exp->e1 = e1x;
4235 if (!exp->e1->type)
4237 exp->error("cannot cast %s", exp->e1->toChars());
4241 if (!exp->to) // Handle cast(const) and cast(immutable), etc.
4243 exp->to = exp->e1->type->castMod(exp->mod);
4244 exp->to = exp->to->semantic(exp->loc, sc);
4245 if (exp->to == Type::terror)
4249 if (exp->to->ty == Ttuple)
4251 exp->error("cannot cast %s to tuple type %s", exp->e1->toChars(), exp->to->toChars());
4254 if (exp->e1->type->ty != Tvoid ||
4255 (exp->e1->op == TOKfunction && exp->to->ty == Tvoid) ||
4256 exp->e1->op == TOKtype ||
4257 exp->e1->op == TOKtemplate)
4259 if (exp->e1->checkValue())
4264 if (exp->to->ty == Tvoid)
4266 exp->type = exp->to;
4267 result = exp;
4271 if (!exp->to->equals(exp->e1->type) && exp->mod == (unsigned char)~0)
4273 if (Expression *e = exp->op_overload(sc))
4275 result = e->implicitCastTo(sc, exp->to);
4280 Type *t1b = exp->e1->type->toBasetype();
4281 Type *tob = exp->to->toBasetype();
4292 Expression *e = new TypeExp(exp->loc, exp->to);
4293 e = new CallExp(exp->loc, e, exp->e1);
4304 if (checkNonAssignmentArrayOp(exp->e1))
4311 result = new VectorExp(exp->loc, exp->e1, exp->to);
4316 Expression *ex = exp->e1->castTo(sc, exp->to);
4328 exp->error("cast from %s to %s not allowed in safe code", exp->e1->type->toChars(), exp->to->toChars());
4335 void visit(VectorExp *exp)
4337 if (exp->type)
4339 result = exp;
4343 exp->e1 = semantic(exp->e1, sc);
4344 exp->type = exp->to->semantic(exp->loc, sc);
4345 if (exp->e1->op == TOKerror || exp->type->ty == Terror)
4347 result = exp->e1;
4351 Type *tb = exp->type->toBasetype();
4355 exp->dim = (int)(tv->size(exp->loc) / te->size(exp->loc));
4357 exp->e1 = exp->e1->optimize(WANTvalue);
4359 if (exp->e1->op == TOKarrayliteral)
4361 for (size_t i = 0; i < exp->dim; i++)
4364 res |= checkVectorElem(exp, ((ArrayLiteralExp *)exp->e1)->getElement(i));
4367 else if (exp->e1->type->ty == Tvoid)
4368 res = checkVectorElem(exp, exp->e1);
4370 Expression *e = exp;
4395 void visit(SliceExp *exp)
4397 if (exp->type)
4399 result = exp;
4405 if (Expression *ex = unaSemantic(exp, sc))
4410 exp->e1 = resolveProperties(sc, exp->e1);
4411 if (exp->e1->op == TOKtype && exp->e1->type->ty != Ttuple)
4413 if (exp->lwr || exp->upr)
4415 exp->error("cannot slice type '%s'", exp->e1->toChars());
4418 Expression *e = new TypeExp(exp->loc, exp->e1->type->arrayOf());
4422 if (!exp->lwr && !exp->upr)
4424 if (exp->e1->op == TOKarrayliteral)
4427 Type *t1b = exp->e1->type->toBasetype();
4428 Expression *e = exp->e1;
4437 if (exp->e1->op == TOKslice)
4440 SliceExp *se = (SliceExp *)exp->e1;
4447 if (isArrayOpOperand(exp->e1))
4450 result = exp->e1;
4454 if (exp->e1->op == TOKerror)
4456 result = exp->e1;
4459 if (exp->e1->type->ty == Terror)
4462 Type *t1b = exp->e1->type->toBasetype();
4467 exp->error("cannot slice function pointer %s", exp->e1->toChars());
4470 if (!exp->lwr || !exp->upr)
4472 exp->error("need upper and lower bound to slice pointer");
4477 exp->error("pointer slicing not allowed in safe functions");
4486 if (!exp->arrayop && global.params.vsafe)
4492 if (exp->e1->op == TOKdotvar)
4494 DotVarExp *dve = (DotVarExp *)exp->e1;
4508 else if (exp->e1->op == TOKvar)
4510 VarExp *ve = (VarExp *)exp->e1;
4513 else if (exp->e1->op == TOKthis || exp->e1->op == TOKsuper)
4515 ThisExp *ve = (ThisExp *)exp->e1;
4521 if (!checkAddressVar(sc, exp, v))
4528 if (!exp->lwr && !exp->upr)
4530 result = exp->e1;
4533 if (!exp->lwr || !exp->upr)
4535 exp->error("need upper and lower bound to slice tuple");
4545 exp->e1->type = t1b;
4549 exp->error("%s cannot be sliced with []",
4550 t1b->ty == Tvoid ? exp->e1->toChars() : t1b->toChars());
4560 ScopeDsymbol *sym = new ArrayScopeSymbol(sc, exp);
4561 sym->loc = exp->loc;
4565 if (exp->lwr)
4568 exp->lwr = semantic(exp->lwr, sc);
4569 exp->lwr = resolveProperties(sc, exp->lwr);
4571 exp->lwr = exp->lwr->implicitCastTo(sc, Type::tsize_t);
4573 if (exp->upr)
4576 exp->upr = semantic(exp->upr, sc);
4577 exp->upr = resolveProperties(sc, exp->upr);
4579 exp->upr = exp->upr->implicitCastTo(sc, Type::tsize_t);
4583 if ((exp->lwr && exp->lwr->type == Type::terror) ||
4584 (exp->upr && exp->upr->type == Type::terror))
4591 exp->lwr = exp->lwr->ctfeInterpret();
4592 exp->upr = exp->upr->ctfeInterpret();
4593 uinteger_t i1 = exp->lwr->toUInteger();
4594 uinteger_t i2 = exp->upr->toUInteger();
4599 if (exp->e1->op == TOKtuple) // slicing an expression tuple
4601 te = (TupleExp *)exp->e1;
4605 else if (exp->e1->op == TOKtype) // slicing a type tuple
4616 exp->error("string slice [%llu .. %llu] is out of bounds", i1, i2);
4623 if (exp->e1->op == TOKtuple)
4631 e = new TupleExp(exp->loc, te->e0, exps);
4642 e = new TypeExp(exp->e1->loc, new TypeTuple(args));
4649 exp->type = t1b->nextOf()->arrayOf();
4651 if (exp->type->equals(t1b))
4652 exp->type = exp->e1->type;
4654 if (exp->lwr && exp->upr)
4656 exp->lwr = exp->lwr->optimize(WANTvalue);
4657 exp->upr = exp->upr->optimize(WANTvalue);
4659 IntRange lwrRange = getIntRange(exp->lwr);
4660 IntRange uprRange = getIntRange(exp->upr);
4664 Expression *el = new ArrayLengthExp(exp->loc, exp->e1);
4671 exp->upperIsInBounds = bounds.contains(uprRange);
4676 exp->upperIsInBounds = true;
4681 exp->lowerIsLessThanUpper = (lwrRange.imax <= uprRange.imin);
4686 result = exp;
4776 void visit(ArrayExp *exp)
4778 assert(!exp->type);
4780 Expression *e = exp->op_overload(sc);
4787 if (isAggregate(exp->e1->type))
4788 exp->error("no [] operator overload for type %s", exp->e1->type->toChars());
4790 exp->error("only one index allowed to index %s", exp->e1->type->toChars());
4794 void visit(DotExp *exp)
4796 exp->e1 = semantic(exp->e1, sc);
4797 exp->e2 = semantic(exp->e2, sc);
4799 if (exp->e1->op == TOKtype)
4801 result = exp->e2;
4804 if (exp->e2->op == TOKtype)
4806 result = exp->e2;
4809 if (exp->e2->op == TOKtemplate)
4811 TemplateDeclaration *td = ((TemplateExp *)exp->e2)->td;
4812 Expression *e = new DotTemplateExp(exp->loc, exp->e1, td);
4816 if (!exp->type)
4817 exp->type = exp->e2->type;
4818 result = exp;
4854 void visit(IndexExp *exp)
4856 if (exp->type)
4858 result = exp;
4864 if (!exp->e1->type)
4865 exp->e1 = semantic(exp->e1, sc);
4866 assert(exp->e1->type); // semantic() should already be run on it
4867 if (exp->e1->op == TOKtype && exp->e1->type->ty != Ttuple)
4869 exp->e2 = semantic(exp->e2, sc);
4870 exp->e2 = resolveProperties(sc, exp->e2);
4872 if (exp->e2->op == TOKtype)
4873 nt = new TypeAArray(exp->e1->type, exp->e2->type);
4875 nt = new TypeSArray(exp->e1->type, exp->e2);
4876 Expression *e = new TypeExp(exp->loc, nt);
4880 if (exp->e1->op == TOKerror)
4882 result = exp->e1;
4885 if (exp->e1->type->ty == Terror)
4890 Type *t1b = exp->e1->type->toBasetype();
4898 exp->e1->type = t1b;
4907 ScopeDsymbol *sym = new ArrayScopeSymbol(sc, exp);
4908 sym->loc = exp->loc;
4913 exp->e2 = semantic(exp->e2, sc);
4914 exp->e2 = resolveProperties(sc, exp->e2);
4916 if (exp->e2->op == TOKtuple)
4918 TupleExp *te = (TupleExp *)exp->e2;
4920 exp->e2 = Expression::combine(te->e0, (*te->exps)[0]); // bug 4444 fix
4924 if (exp->e2->type == Type::terror)
4927 if (checkNonAssignmentArrayOp(exp->e1))
4935 exp->error("cannot index function pointer %s", exp->e1->toChars());
4938 exp->e2 = exp->e2->implicitCastTo(sc, Type::tsize_t);
4939 if (exp->e2->type == Type::terror)
4941 exp->e2 = exp->e2->optimize(WANTvalue);
4942 if (exp->e2->op == TOKint64 && exp->e2->toInteger() == 0)
4946 exp->error("safe function '%s' cannot index pointer '%s'",
4947 sc->func->toPrettyChars(), exp->e1->toChars());
4950 exp->type = ((TypeNext *)t1b)->next;
4954 exp->e2 = exp->e2->implicitCastTo(sc, Type::tsize_t);
4955 if (exp->e2->type == Type::terror)
4957 exp->type = ((TypeNext *)t1b)->next;
4962 exp->e2 = exp->e2->implicitCastTo(sc, Type::tsize_t);
4963 if (exp->e2->type == Type::terror)
4965 exp->type = t1b->nextOf();
4975 if (!arrayTypeCompatibleWithoutCasting(exp->e2->type, taa->index))
4977 exp->e2 = exp->e2->implicitCastTo(sc, taa->index); // type checking
4978 if (exp->e2->type == Type::terror)
4984 exp->type = taa->next;
4990 exp->e2 = exp->e2->implicitCastTo(sc, Type::tsize_t);
4991 if (exp->e2->type == Type::terror)
4993 exp->e2 = exp->e2->ctfeInterpret();
4994 uinteger_t index = exp->e2->toUInteger();
4999 if (exp->e1->op == TOKtuple)
5001 te = (TupleExp *)exp->e1;
5005 else if (exp->e1->op == TOKtype)
5016 exp->error("array index [%llu] is outside array bounds [0 .. %llu]",
5022 if (exp->e1->op == TOKtuple)
5028 e = new TypeExp(exp->e1->loc, Parameter::getNth(tup->arguments, (size_t)index)->type);
5034 exp->error("%s must be an array or pointer type, not %s",
5035 exp->e1->toChars(), exp->e1->type->toChars());
5041 Expression *el = new ArrayLengthExp(exp->loc, exp->e1);
5046 exp->e2 = exp->e2->optimize(WANTvalue);
5051 exp->indexIsInBounds = bounds.contains(getIntRange(exp->e2));
5056 result = exp;
5059 void visit(PostExp *exp)
5061 if (exp->type)
5063 result = exp;
5067 if (Expression *ex = binSemantic(exp, sc))
5072 Expression *e1x = resolveProperties(sc, exp->e1);
5078 exp->e1 = e1x;
5080 Expression *e = exp->op_overload(sc);
5087 if (exp->e1->checkReadModifyWrite(exp->op))
5089 if (exp->e1->op == TOKslice)
5091 const char *s = exp->op == TOKplusplus ? "increment" : "decrement";
5092 exp->error("cannot post-%s array slice '%s', use pre-%s instead", s, exp->e1->toChars(), s);
5096 exp->e1 = exp->e1->optimize(WANTvalue);
5098 Type *t1 = exp->e1->type->toBasetype();
5099 if (t1->ty == Tclass || t1->ty == Tstruct || exp->e1->op == TOKarraylength)
5108 if (exp->e1->op != TOKvar && exp->e1->op != TOKarraylength)
5111 VarDeclaration *v = copyToTemp(STCref, "__postref", exp->e1);
5112 de = new DeclarationExp(exp->loc, v);
5113 exp->e1 = new VarExp(exp->e1->loc, v);
5119 VarDeclaration *tmp = copyToTemp(0, "__pitmp", exp->e1);
5120 Expression *ea = new DeclarationExp(exp->loc, tmp);
5122 Expression *eb = exp->e1->syntaxCopy();
5123 eb = new PreExp(exp->op == TOKplusplus ? TOKpreplusplus : TOKpreminusminus, exp->loc, eb);
5125 Expression *ec = new VarExp(exp->loc, tmp);
5129 ea = new CommaExp(exp->loc, de, ea);
5130 e = new CommaExp(exp->loc, ea, eb);
5131 e = new CommaExp(exp->loc, e, ec);
5137 exp->e1 = exp->e1->modifiableLvalue(sc, exp->e1);
5139 e = exp;
5140 if (exp->e1->checkScalar())
5142 if (exp->e1->checkNoBool())
5145 if (exp->e1->type->ty == Tpointer)
5146 e = scaleFactor(exp, sc);
5148 exp->e2 = exp->e2->castTo(sc, exp->e1->type);
5149 e->type = exp->e1->type;
5153 void visit(PreExp *exp)
5155 Expression *e = exp->op_overload(sc);
5156 // printf("PreExp::semantic('%s')\n", exp->toChars());
5165 if (exp->op == TOKpreplusplus)
5166 e = new AddAssignExp(exp->loc, exp->e1, new IntegerExp(exp->loc, 1, Type::tint32));
5168 e = new MinAssignExp(exp->loc, exp->e1, new IntegerExp(exp->loc, 1, Type::tint32));
5172 void visit(AssignExp *exp)
5174 //printf("e1->op = %d, '%s'\n", exp->e1->op, Token::toChars(exp->e1->op));
5175 //printf("e2->op = %d, '%s'\n", exp->e2->op, Token::toChars(exp->e2->op));
5176 if (exp->type)
5178 result = exp;
5182 Expression *e1old = exp->e1;
5184 if (exp->e2->op == TOKcomma)
5188 if (!((CommaExp *)exp->e2)->isGenerated)
5189 exp->deprecation("Using the result of a comma expression is deprecated");
5191 exp->e2 = Expression::extractLast(exp->e2, &e0);
5192 Expression *e = Expression::combine(e0, exp);
5201 if (exp->e1->op == TOKarray)
5205 ArrayExp *ae = (ArrayExp *)exp->e1;
5247 res = semantic(exp->e2, sc);
5253 exp->e2 = res;
5259 a->insert(0, exp->e2);
5260 res = new DotIdExp(exp->loc, ae->e1, Id::indexass);
5261 res = new CallExp(exp->loc, res, a);
5284 res = semantic(exp->e2, sc);
5290 exp->e2 = res;
5296 a->push(exp->e2);
5302 res = new DotIdExp(exp->loc, ae->e1, Id::sliceass);
5303 res = new CallExp(exp->loc, res, a);
5330 /* Run exp->e1 semantic.
5333 Expression *e1x = exp->e1;
5347 result = resolveUFCSProperties(sc, e1x, exp->e2);
5359 e = resolvePropertiesX(sc, e, exp->e2);
5370 result = resolveUFCSProperties(sc, e1x, exp->e2);
5389 if (Expression *e = resolvePropertiesX(sc, e1x, exp->e2))
5396 exp->e1 = e1x;
5397 assert(exp->e1->type);
5399 Type *t1 = exp->e1->type->toBasetype();
5401 /* Run exp->e2 semantic.
5406 Expression *e2x = inferType(exp->e2, t1->baseElemOf());
5420 exp->e2 = e2x;
5426 Expression *e2x = exp->e2;
5429 if (exp->e1->op == TOKtuple && e2x->op == TOKtuple)
5431 TupleExp *tup1 = (TupleExp *)exp->e1;
5437 exp->error("mismatched tuple lengths, %d and %d", (int)dim, (int)tup2->exps->dim);
5442 e = new IntegerExp(exp->loc, 0, Type::tint32);
5443 e = new CastExp(exp->loc, e, Type::tvoid); // avoid "has no effect" error
5454 (*exps)[i] = new AssignExp(exp->loc, ex1, ex2);
5456 e = new TupleExp(exp->loc, Expression::combine(tup1->e0, tup2->e0), exps);
5464 if (exp->e1->op == TOKtuple)
5470 assert(exp->e1->type->ty == Ttuple);
5471 TypeTuple *tt = (TypeTuple *)exp->e1->type;
5508 // Do not need to overwrite exp->e2
5518 if (exp->op == TOKassign && exp->e1->checkModifiable(sc) == 2)
5520 //printf("[%s] change to init - %s\n", exp->loc.toChars(), toChars());
5521 exp->op = TOKconstruct;
5524 if (exp->e1->op == TOKindex)
5526 Expression *e1x = ((IndexExp *)exp->e1)->markSettingAAElem();
5534 else if (exp->op == TOKconstruct && exp->e1->op == TOKvar &&
5535 ((VarExp *)exp->e1)->var->storage_class & (STCout | STCref))
5537 exp->memset |= referenceInit;
5543 if (exp->memset & referenceInit)
5550 Expression *e1x = exp->e1;
5551 Expression *e2x = exp->e2;
5554 if (exp->op == TOKconstruct)
5559 sd->size(exp->loc);
5584 AssignExp *ae = exp;
5588 ae = new BlitExp(ae->loc, ae->e1, new IntegerExp(exp->loc, 0, Type::tint32));
5593 ae->e2 = sd->isNested() ? t1->defaultInitLiteral(exp->loc) : t1->defaultInit(exp->loc);
5627 Expression *e = new CondExp(exp->loc, econd->econd, ea1, ea2);
5636 exp->error("conversion error from %s to %s", e2x->type->toChars(), e1x->type->toChars());
5648 e = new BlitExp(exp->loc, e, e2x);
5649 e = new DotVarExp(exp->loc, e, sd->postblit, false);
5650 e = new CallExp(exp->loc, e);
5665 sd->size(exp->loc);
5678 einit = new BlitExp(exp->loc, e1x, e1x->type->defaultInit(exp->loc));
5682 e = new DotIdExp(exp->loc, e1x, Id::ctor);
5683 e = new CallExp(exp->loc, e, e2x);
5684 e = new CommaExp(exp->loc, einit, e);
5697 e2x = new CallExp(exp->loc, e2x, exp->e2);
5713 if (ad2 && ad2->aliasthis && !(exp->att2 && e2x->type == exp->att2))
5715 if (!exp->att2 && exp->e2->type->checkAliasThisRec())
5716 exp->att2 = exp->e2->type;
5721 exp->e2 = new DotIdExp(exp->e2->loc, exp->e2, ad2->aliasthis->ident);
5722 result = semantic(exp, sc);
5727 else if (exp->op == TOKassign)
5751 AssignExp *ae = (AssignExp *)exp->copy();
5752 ae->e1 = new IndexExp(exp->loc, ea, ek);
5768 ey = new StructLiteralExp(exp->loc, sd, NULL);
5769 ey = new DotIdExp(exp->loc, ey, Id::ctor);
5770 ey = new CallExp(exp->loc, ey, ev);
5776 ex = new IndexExp(exp->loc, ea, ek);
5780 ey = new ConstructExp(exp->loc, ex, ey);
5798 e = new CondExp(exp->loc, new InExp(exp->loc, ek, ea), ex, ey);
5808 Expression *e = exp->op_overload(sc);
5817 assert(exp->op == TOKblit);
5819 exp->e1 = e1x;
5820 exp->e2 = e2x;
5825 if (exp->op == TOKassign && !exp->e2->implicitConvTo(exp->e1->type))
5827 Expression *e = exp->op_overload(sc);
5838 assert(exp->e1->op != TOKslice);
5840 Expression *e1x = exp->e1;
5841 Expression *e2x = exp->e2;
5845 if (exp->op != TOKblit &&
5888 exp->error("mismatched array lengths, %d and %d", (int)dim1, (int)dim2);
5895 if (exp->op != TOKassign)
5898 dinteger_t dim = t1->numberOfElems(exp->loc);
5916 exp->e1 = e1x;
5917 exp->e2 = e2x;
5923 if (exp->e1->op == TOKarraylength)
5926 ArrayLengthExp *ale = (ArrayLengthExp *)exp->e1;
5929 ale1x = ale1x->modifiableLvalue(sc, exp->e1);
5941 else if (exp->e1->op == TOKslice)
5943 Type *tn = exp->e1->type->nextOf();
5944 if (exp->op == TOKassign && !tn->isMutable())
5946 exp->error("slice %s is not mutable", exp->e1->toChars());
5951 SliceExp *se = (SliceExp *)exp->e1;
5957 se->e1 = se->e1->modifiableLvalue(sc, exp->e1);
5967 Expression *e1x = exp->e1;
5974 if (exp->op == TOKassign)
5982 exp->e1 = e1x;
5987 Expression *e2x = exp->e2;
5996 if (exp->e1->op == TOKslice &&
6004 exp->memset |= blockAssign; // make it easy for back end to tell what this is
6006 if (exp->op != TOKblit && e2x->isLvalue() &&
6007 exp->e1->checkPostblit(sc, t1->nextOf()))
6010 else if (exp->e1->op == TOKslice &&
6019 SliceExp *se1 = (SliceExp *)exp->e1;
6034 exp->error("mismatched array lengths, %d and %d", (int)dim1, (int)dim2);
6039 if (exp->op != TOKblit &&
6044 if (exp->e1->checkPostblit(sc, t1->nextOf()))
6048 if (0 && global.params.warnings != DIAGNOSTICoff && !global.gag && exp->op == TOKassign &&
6058 const char* e1str = exp->e1->toChars();
6060 exp->warning("explicit element-wise assignment %s = (%s)[] is better than %s = %s",
6083 e2x->type = exp->e1->type->constOf();
6086 e2x = e2x->castTo(sc, exp->e1->type->constOf());
6097 e2x = e2x->implicitCastTo(sc, exp->e1->type->constOf());
6099 e2x = e2x->implicitCastTo(sc, exp->e1->type);
6105 exp->error("cannot copy void[] to void[] in @safe code");
6112 if (0 && global.params.warnings != DIAGNOSTICoff && !global.gag && exp->op == TOKassign &&
6118 const char* e1str = exp->e1->toChars();
6120 const char* atypestr = exp->e1->op == TOKslice ? "element-wise" : "slice";
6121 exp->warning("explicit %s assignment %s = (%s)[] is better than %s = %s",
6124 if (exp->op == TOKblit)
6125 e2x = e2x->castTo(sc, exp->e1->type);
6127 e2x = e2x->implicitCastTo(sc, exp->e1->type);
6134 exp->e2 = e2x;
6135 t2 = exp->e2->type->toBasetype();
6139 if ((t2->ty == Tarray || t2->ty == Tsarray) && isArrayOpValid(exp->e2))
6142 if (!(exp->memset & blockAssign) && exp->e1->op == TOKslice &&
6143 (isUnaArrayOp(exp->e2->op) || isBinArrayOp(exp->e2->op)))
6145 exp->type = exp->e1->type;
6146 if (exp->op == TOKconstruct) // Bugzilla 10282: tweak mutability of e1 element
6147 exp->e1->type = exp->e1->type->nextOf()->mutableOf()->arrayOf();
6148 result = arrayOp(exp, sc);
6154 if (checkNonAssignmentArrayOp(exp->e2, !(exp->memset & blockAssign) && exp->op == TOKassign))
6165 if (exp->e1->op == TOKvar && exp->op == TOKassign)
6167 VarExp *ve = (VarExp *)exp->e1;
6172 exp->error("cannot rebind scope variables");
6175 if (exp->e1->op == TOKvar && ((VarExp *)exp->e1)->var->ident == Id::ctfe)
6177 exp->error("cannot modify compiler-generated variable __ctfe");
6180 exp->type = exp->e1->type;
6181 assert(exp->type);
6182 Expression *res = exp->op == TOKassign ? exp->reorderSettingAAElem(sc) : exp;
6187 void visit(CatAssignExp *exp)
6189 if (exp->type)
6191 result = exp;
6196 Expression *e = exp->op_overload(sc);
6203 if (exp->e1->op == TOKslice)
6205 SliceExp *se = (SliceExp *)exp->e1;
6208 exp->error("cannot append to static array %s", se->e1->type->toChars());
6213 exp->e1 = exp->e1->modifiableLvalue(sc, exp->e1);
6214 if (exp->e1->op == TOKerror)
6216 result = exp->e1;
6219 if (exp->e2->op == TOKerror)
6221 result = exp->e2;
6225 if (checkNonAssignmentArrayOp(exp->e2))
6228 Type *tb1 = exp->e1->type->toBasetype();
6230 Type *tb2 = exp->e2->type->toBasetype();
6234 (exp->e2->implicitConvTo(exp->e1->type)
6241 if (exp->e1->checkPostblit(sc, tb1next))
6243 exp->e2 = exp->e2->castTo(sc, exp->e1->type);
6246 exp->e2->implicitConvTo(tb1next)
6250 if (exp->e2->checkPostblit(sc, tb2))
6252 exp->e2 = exp->e2->castTo(sc, tb1next);
6253 exp->e2 = doCopyOrMove(sc, exp->e2);
6257 exp->e2->type->ty != tb1next->ty &&
6258 exp->e2->implicitConvTo(Type::tdchar)
6261 exp->e2 = exp->e2->castTo(sc, Type::tdchar);
6269 exp->error("cannot append type %s to type %s", tb2->toChars(), tb1->toChars());
6272 if (exp->e2->checkValue())
6275 exp->type = exp->e1->type;
6276 result = exp->reorderSettingAAElem(sc);
6279 void visit(PowAssignExp *exp)
6281 if (exp->type)
6283 result = exp;
6287 Expression *e = exp->op_overload(sc);
6294 if (exp->e1->checkReadModifyWrite(exp->op, exp->e2))
6297 assert(exp->e1->type && exp->e2->type);
6298 if (exp->e1->op == TOKslice || exp->e1->type->ty == Tarray || exp->e1->type->ty == Tsarray)
6300 if (checkNonAssignmentArrayOp(exp->e1))
6304 if (exp->e2->implicitConvTo(exp->e1->type->nextOf()))
6307 exp->e2 = exp->e2->castTo(sc, exp->e1->type->nextOf());
6309 else if (Expression *ex = typeCombine(exp, sc))
6316 Type *tb1 = exp->e1->type->nextOf()->toBasetype();
6317 Type *tb2 = exp->e2->type->toBasetype();
6324 exp->type = exp->e1->type;
6325 result = arrayOp(exp, sc);
6331 exp->e1 = exp->e1->modifiableLvalue(sc, exp->e1);
6334 if ((exp->e1->type->isintegral() || exp->e1->type->isfloating()) &&
6335 (exp->e2->type->isintegral() || exp->e2->type->isfloating()))
6338 e = exp->reorderSettingAAElem(sc);
6340 assert(e == exp);
6342 if (exp->e1->op == TOKvar)
6345 e = new PowExp(exp->loc, exp->e1->syntaxCopy(), exp->e2);
6346 e = new AssignExp(exp->loc, exp->e1, e);
6351 VarDeclaration *v = copyToTemp(STCref, "__powtmp", exp->e1);
6352 Expression *de = new DeclarationExp(exp->e1->loc, v);
6353 VarExp *ve = new VarExp(exp->e1->loc, v);
6354 e = new PowExp(exp->loc, ve, exp->e2);
6355 e = new AssignExp(exp->loc, new VarExp(exp->e1->loc, v), e);
6356 e = new CommaExp(exp->loc, de, e);
6363 result = exp->incompatibleTypes();
6366 void visit(AddExp *exp)
6368 if (exp->type)
6370 result = exp;
6374 if (Expression *ex = binSemanticProp(exp, sc))
6379 Expression *e = exp->op_overload(sc);
6386 Type *tb1 = exp->e1->type->toBasetype();
6387 Type *tb2 = exp->e2->type->toBasetype();
6393 err |= exp->e1->checkArithmetic();
6398 err |= exp->e2->checkArithmetic();
6403 if ((tb1->ty == Tpointer && exp->e2->type->isintegral()) ||
6404 (tb2->ty == Tpointer && exp->e1->type->isintegral()))
6406 result = scaleFactor(exp, sc);
6412 result = exp->incompatibleTypes();
6416 if (Expression *ex = typeCombine(exp, sc))
6422 Type *tb = exp->type->toBasetype();
6425 if (!isArrayOpValid(exp))
6427 exp->error("invalid array operation %s (possible missing [])", exp->toChars());
6430 result = exp;
6434 tb1 = exp->e1->type->toBasetype();
6435 if (!Target::isVectorOpSupported(tb1, exp->op, tb2))
6437 result = exp->incompatibleTypes();
6440 if ((tb1->isreal() && exp->e2->type->isimaginary()) ||
6441 (tb1->isimaginary() && exp->e2->type->isreal()))
6443 switch (exp->type->toBasetype()->ty)
6447 exp->type = Type::tcomplex32;
6452 exp->type = Type::tcomplex64;
6457 exp->type = Type::tcomplex80;
6464 result = exp;
6467 void visit(MinExp *exp)
6469 if (exp->type)
6471 result = exp;
6475 if (Expression *ex = binSemanticProp(exp, sc))
6480 Expression *e = exp->op_overload(sc);
6487 Type *t1 = exp->e1->type->toBasetype();
6488 Type *t2 = exp->e2->type->toBasetype();
6494 err |= exp->e1->checkArithmetic();
6499 err |= exp->e2->checkArithmetic();
6513 if (Expression *ex = typeCombine(exp, sc))
6519 exp->type = Type::tptrdiff_t;
6523 e = new IntegerExp(exp->loc, 0, Type::tptrdiff_t);
6527 e = new DivExp(exp->loc, exp, new IntegerExp(Loc(), stride, Type::tptrdiff_t));
6532 e = scaleFactor(exp, sc);
6535 exp->error("can't subtract %s from pointer", t2->toChars());
6543 exp->type = exp->e2->type;
6544 exp->error("can't subtract pointer from %s", exp->e1->type->toChars());
6548 if (Expression *ex = typeCombine(exp, sc))
6554 Type *tb = exp->type->toBasetype();
6557 if (!isArrayOpValid(exp))
6559 exp->error("invalid array operation %s (possible missing [])", exp->toChars());
6562 result = exp;
6566 t1 = exp->e1->type->toBasetype();
6567 t2 = exp->e2->type->toBasetype();
6568 if (!Target::isVectorOpSupported(t1, exp->op, t2))
6570 result = exp->incompatibleTypes();
6576 switch (exp->type->ty)
6580 exp->type = Type::tcomplex32;
6585 exp->type = Type::tcomplex64;
6590 exp->type = Type::tcomplex80;
6597 result = exp;
6600 void visit(CatExp *exp)
6602 //printf("CatExp::semantic() %s\n", exp->toChars());
6603 if (exp->type)
6605 result = exp;
6609 if (Expression *ex = binSemanticProp(exp, sc))
6614 Expression *e = exp->op_overload(sc);
6621 Type *tb1 = exp->e1->type->toBasetype();
6622 Type *tb2 = exp->e2->type->toBasetype();
6624 bool f1 = checkNonAssignmentArrayOp(exp->e1);
6625 bool f2 = checkNonAssignmentArrayOp(exp->e2);
6641 (exp->e1->op == TOKarrayliteral && exp->e1->implicitConvTo(tb2)) ||
6642 (exp->e2->op == TOKarrayliteral && exp->e2->implicitConvTo(tb1))
6666 if (exp->e1->op == TOKarrayliteral)
6668 exp->e2 = exp->e2->isLvalue() ? callCpCtor(sc, exp->e2) : valueNoDtor(exp->e2);
6672 else if (exp->e1->op == TOKstring)
6678 if (exp->e2->checkPostblit(sc, tb2))
6683 if (exp->e1->op == TOKarrayliteral && exp->e1->implicitConvTo(tb2->arrayOf()))
6685 exp->e1 = exp->e1->implicitCastTo(sc, tb2->arrayOf());
6686 exp->type = tb2->arrayOf();
6689 if (exp->e2->implicitConvTo(tb1next) >= MATCHconvert)
6691 exp->e2 = exp->e2->implicitCastTo(sc, tb1next);
6692 exp->type = tb1next->arrayOf();
6697 exp->e2 = new ArrayLiteralExp(exp->e2->loc, exp->type, exp->e2);
6699 result = exp->optimize(WANTvalue);
6706 if (exp->e2->op == TOKarrayliteral)
6708 exp->e1 = exp->e1->isLvalue() ? callCpCtor(sc, exp->e1) : valueNoDtor(exp->e1);
6710 else if (exp->e2->op == TOKstring)
6715 if (exp->e1->checkPostblit(sc, tb1))
6719 if (exp->e2->op == TOKarrayliteral && exp->e2->implicitConvTo(tb1->arrayOf()))
6721 exp->e2 = exp->e2->implicitCastTo(sc, tb1->arrayOf());
6722 exp->type = tb1->arrayOf();
6725 if (exp->e1->implicitConvTo(tb2next) >= MATCHconvert)
6727 exp->e1 = exp->e1->implicitCastTo(sc, tb2next);
6728 exp->type = tb2next->arrayOf();
6733 exp->e1 = new ArrayLiteralExp(exp->e1->loc, exp->type, exp->e1);
6735 result = exp->optimize(WANTvalue);
6749 if (exp->e1->op == TOKstring && !((StringExp *)exp->e1)->committed)
6750 exp->e1->type = t1;
6752 exp->e1 = exp->e1->castTo(sc, t1);
6753 if (exp->e2->op == TOKstring && !((StringExp *)exp->e2)->committed)
6754 exp->e2->type = t2;
6756 exp->e2 = exp->e2->castTo(sc, t2);
6759 if (Expression *ex = typeCombine(exp, sc))
6764 exp->type = exp->type->toHeadMutable();
6766 Type *tb = exp->type->toBasetype();
6768 exp->type = tb->nextOf()->arrayOf();
6769 if (exp->type->ty == Tarray && tb1next && tb2next &&
6772 exp->type = exp->type->nextOf()->toHeadMutable()->arrayOf();
6776 if (exp->checkPostblit(sc, tbn))
6779 Type *t1 = exp->e1->type->toBasetype();
6780 Type *t2 = exp->e2->type->toBasetype();
6785 e = exp->optimize(WANTvalue);
6789 //printf("(%s) ~ (%s)\n", exp->e1->toChars(), exp->e2->toChars());
6790 result = exp->incompatibleTypes();
6796 void visit(MulExp *exp)
6798 if (exp->type)
6800 result = exp;
6804 if (Expression *ex = binSemanticProp(exp, sc))
6809 Expression *e = exp->op_overload(sc);
6816 if (Expression *ex = typeCombine(exp, sc))
6822 Type *tb = exp->type->toBasetype();
6825 if (!isArrayOpValid(exp))
6827 exp->error("invalid array operation %s (possible missing [])", exp->toChars());
6830 result = exp;
6834 if (exp->checkArithmeticBin())
6837 if (exp->type->isfloating())
6839 Type *t1 = exp->e1->type;
6840 Type *t2 = exp->e2->type;
6844 exp->type = t2;
6848 exp->type = t1;
6858 exp->type = Type::tfloat32;
6862 exp->type = Type::tfloat64;
6866 exp->type = Type::tfloat80;
6874 exp->e1->type = exp->type;
6875 exp->e2->type = exp->type;
6876 e = new NegExp(exp->loc, exp);
6882 exp->type = t2; // t2 is complex
6886 exp->type = t1; // t1 is complex
6889 else if (!Target::isVectorOpSupported(tb, exp->op, exp->e2->type->toBasetype()))
6891 result = exp->incompatibleTypes();
6894 result = exp;
6897 void visit(DivExp *exp)
6899 if (exp->type)
6901 result = exp;
6905 if (Expression *ex = binSemanticProp(exp, sc))
6910 Expression *e = exp->op_overload(sc);
6917 if (Expression *ex = typeCombine(exp, sc))
6923 Type *tb = exp->type->toBasetype();
6926 if (!isArrayOpValid(exp))
6928 exp->error("invalid array operation %s (possible missing [])", exp->toChars());
6931 result = exp;
6935 if (exp->checkArithmeticBin())
6938 if (exp->type->isfloating())
6940 Type *t1 = exp->e1->type;
6941 Type *t2 = exp->e2->type;
6945 exp->type = t2;
6949 exp->e2->type = t1;
6950 e = new NegExp(exp->loc, exp);
6958 exp->type = t1;
6967 exp->type = Type::tfloat32;
6971 exp->type = Type::tfloat64;
6975 exp->type = Type::tfloat80;
6983 exp->type = t2; // t2 is complex
6987 exp->type = t1; // t1 is complex
6990 else if (!Target::isVectorOpSupported(tb, exp->op, exp->e2->type->toBasetype()))
6992 result = exp->incompatibleTypes();
6995 result = exp;
6998 void visit(ModExp *exp)
7000 if (exp->type)
7002 result = exp;
7006 if (Expression *ex = binSemanticProp(exp, sc))
7011 Expression *e = exp->op_overload(sc);
7018 if (Expression *ex = typeCombine(exp, sc))
7024 Type *tb = exp->type->toBasetype();
7027 if (!isArrayOpValid(exp))
7029 exp->error("invalid array operation %s (possible missing [])", exp->toChars());
7032 result = exp;
7035 if (!Target::isVectorOpSupported(tb, exp->op, exp->e2->type->toBasetype()))
7037 result = exp->incompatibleTypes();
7041 if (exp->checkArithmeticBin())
7044 if (exp->type->isfloating())
7046 exp->type = exp->e1->type;
7047 if (exp->e2->type->iscomplex())
7049 exp->error("cannot perform modulo complex arithmetic");
7053 result = exp;
7075 void visit(PowExp *exp)
7077 if (exp->type)
7079 result = exp;
7083 //printf("PowExp::semantic() %s\n", exp->toChars());
7084 if (Expression *ex = binSemanticProp(exp, sc))
7089 Expression *e = exp->op_overload(sc);
7096 if (Expression *ex = typeCombine(exp, sc))
7102 Type *tb = exp->type->toBasetype();
7105 if (!isArrayOpValid(exp))
7107 exp->error("invalid array operation %s (possible missing [])", exp->toChars());
7110 result = exp;
7114 if (exp->checkArithmeticBin())
7117 if (!Target::isVectorOpSupported(exp->e1->type->toBasetype(), exp->op, exp->e2->type->toBasetype()))
7119 result = exp->incompatibleTypes();
7127 e = exp->optimize(WANTvalue);
7137 if (exp->e2->op == TOKint64 && ((sinteger_t)exp->e2->toInteger() == 2 || (sinteger_t)exp->e2->toInteger() == 3))
7138 intpow = exp->e2->toInteger();
7139 else if (exp->e2->op == TOKfloat64 && (exp->e2->toReal() == ldouble((sinteger_t)exp->e2->toReal())))
7140 intpow = (sinteger_t)(exp->e2->toReal());
7147 VarDeclaration *tmp = copyToTemp(0, "__powtmp", exp->e1);
7148 Expression *de = new DeclarationExp(exp->loc, tmp);
7149 Expression *ve = new VarExp(exp->loc, tmp);
7153 Expression *me = new MulExp(exp->loc, ve, ve);
7155 me = new MulExp(exp->loc, me, ve);
7156 e = new CommaExp(exp->loc, de, me);
7165 //exp->error("requires std.math for ^^ operators");
7170 if (Expression *ex = typeCombine(exp, sc))
7175 result = exp;
7178 e = new ScopeExp(exp->loc, mmath);
7180 if (exp->e2->op == TOKfloat64 && exp->e2->toReal() == CTFloat::half)
7183 e = new CallExp(exp->loc, new DotIdExp(exp->loc, e, Id::_sqrt), exp->e1);
7188 e = new CallExp(exp->loc, new DotIdExp(exp->loc, e, Id::_pow), exp->e1, exp->e2);
7194 void visit(ShlExp *exp)
7196 //printf("ShlExp::semantic(), type = %p\n", exp->type);
7197 if (exp->type)
7199 result = exp;
7203 if (Expression *ex = binSemanticProp(exp, sc))
7208 Expression *e = exp->op_overload(sc);
7215 if (exp->checkIntegralBin())
7217 if (!Target::isVectorOpSupported(exp->e1->type->toBasetype(), exp->op, exp->e2->type->toBasetype()))
7219 result = exp->incompatibleTypes();
7222 exp->e1 = integralPromotions(exp->e1, sc);
7223 if (exp->e2->type->toBasetype()->ty != Tvector)
7224 exp->e2 = exp->e2->castTo(sc, Type::tshiftcnt);
7226 exp->type = exp->e1->type;
7227 result = exp;
7230 void visit(ShrExp *exp)
7232 if (exp->type)
7234 result = exp;
7238 if (Expression *ex = binSemanticProp(exp, sc))
7243 Expression *e = exp->op_overload(sc);
7250 if (exp->checkIntegralBin())
7252 if (!Target::isVectorOpSupported(exp->e1->type->toBasetype(), exp->op, exp->e2->type->toBasetype()))
7254 result = exp->incompatibleTypes();
7257 exp->e1 = integralPromotions(exp->e1, sc);
7258 if (exp->e2->type->toBasetype()->ty != Tvector)
7259 exp->e2 = exp->e2->castTo(sc, Type::tshiftcnt);
7261 exp->type = exp->e1->type;
7262 result = exp;
7265 void visit(UshrExp *exp)
7267 if (exp->type)
7269 result = exp;
7273 if (Expression *ex = binSemanticProp(exp, sc))
7278 Expression *e = exp->op_overload(sc);
7285 if (exp->checkIntegralBin())
7287 if (!Target::isVectorOpSupported(exp->e1->type->toBasetype(), exp->op, exp->e2->type->toBasetype()))
7289 result = exp->incompatibleTypes();
7292 exp->e1 = integralPromotions(exp->e1, sc);
7293 if (exp->e2->type->toBasetype()->ty != Tvector)
7294 exp->e2 = exp->e2->castTo(sc, Type::tshiftcnt);
7296 exp->type = exp->e1->type;
7297 result = exp;
7300 void visit(AndExp *exp)
7302 if (exp->type)
7304 result = exp;
7308 if (Expression *ex = binSemanticProp(exp, sc))
7313 Expression *e = exp->op_overload(sc);
7320 if (exp->e1->type->toBasetype()->ty == Tbool &&
7321 exp->e2->type->toBasetype()->ty == Tbool)
7323 exp->type = exp->e1->type;
7324 result = exp;
7328 if (Expression *ex = typeCombine(exp, sc))
7334 Type *tb = exp->type->toBasetype();
7337 if (!isArrayOpValid(exp))
7339 exp->error("invalid array operation %s (possible missing [])", exp->toChars());
7342 result = exp;
7346 if (!Target::isVectorOpSupported(tb, exp->op, exp->e2->type->toBasetype()))
7348 result = exp->incompatibleTypes();
7351 if (exp->checkIntegralBin())
7354 result = exp;
7357 void visit(OrExp *exp)
7359 if (exp->type)
7361 result = exp;
7365 if (Expression *ex = binSemanticProp(exp, sc))
7370 Expression *e = exp->op_overload(sc);
7377 if (exp->e1->type->toBasetype()->ty == Tbool &&
7378 exp->e2->type->toBasetype()->ty == Tbool)
7380 exp->type = exp->e1->type;
7381 result = exp;
7385 if (Expression *ex = typeCombine(exp, sc))
7391 Type *tb = exp->type->toBasetype();
7394 if (!isArrayOpValid(exp))
7396 exp->error("invalid array operation %s (possible missing [])", exp->toChars());
7399 result = exp;
7403 if (!Target::isVectorOpSupported(tb, exp->op, exp->e2->type->toBasetype()))
7405 result = exp->incompatibleTypes();
7408 if (exp->checkIntegralBin())
7411 result = exp;
7414 void visit(XorExp *exp)
7416 if (exp->type)
7418 result = exp;
7422 if (Expression *ex = binSemanticProp(exp, sc))
7427 Expression *e = exp->op_overload(sc);
7434 if (exp->e1->type->toBasetype()->ty == Tbool &&
7435 exp->e2->type->toBasetype()->ty == Tbool)
7437 exp->type = exp->e1->type;
7438 result = exp;
7442 if (Expression *ex = typeCombine(exp, sc))
7448 Type *tb = exp->type->toBasetype();
7451 if (!isArrayOpValid(exp))
7453 exp->error("invalid array operation %s (possible missing [])", exp->toChars());
7456 result = exp;
7460 if (!Target::isVectorOpSupported(tb, exp->op, exp->e2->type->toBasetype()))
7462 result = exp->incompatibleTypes();
7465 if (exp->checkIntegralBin())
7468 result = exp;
7471 void visit(OrOrExp *exp)
7473 if (exp->type)
7475 result = exp;
7479 setNoderefOperands(exp);
7482 Expression *e1x = semantic(exp->e1, sc);
7499 result = new IntegerExp(exp->loc, 1, Type::tbool);
7504 Expression *e2x = semantic(exp->e2, sc);
7505 sc->mergeCallSuper(exp->loc, cs1);
7524 exp->error("%s is not an expression", exp->e2->toChars());
7540 exp->type = Type::tvoid;
7542 exp->type = Type::tbool;
7544 exp->e1 = e1x;
7545 exp->e2 = e2x;
7546 result = exp;
7549 void visit(AndAndExp *exp)
7551 if (exp->type)
7553 result = exp;
7557 setNoderefOperands(exp);
7560 Expression *e1x = semantic(exp->e1, sc);
7577 result = new IntegerExp(exp->loc, 0, Type::tbool);
7582 Expression *e2x = semantic(exp->e2, sc);
7583 sc->mergeCallSuper(exp->loc, cs1);
7602 exp->error("%s is not an expression", exp->e2->toChars());
7618 exp->type = Type::tvoid;
7620 exp->type = Type::tbool;
7622 exp->e1 = e1x;
7623 exp->e2 = e2x;
7624 result = exp;
7627 void visit(InExp *exp)
7629 if (exp->type)
7631 result = exp;
7635 if (Expression *ex = binSemanticProp(exp, sc))
7640 Expression *e = exp->op_overload(sc);
7647 Type *t2b = exp->e2->type->toBasetype();
7655 if (!arrayTypeCompatible(exp->e1->loc, exp->e1->type, ta->index))
7658 exp->e1 = exp->e1->implicitCastTo(sc, ta->index);
7664 exp->type = ta->nextOf()->pointerTo();
7669 result = exp->incompatibleTypes();
7675 result = exp;
7688 void visit(CmpExp *exp)
7690 if (exp->type)
7692 result = exp;
7696 setNoderefOperands(exp);
7698 if (Expression *ex = binSemanticProp(exp, sc))
7703 Type *t1 = exp->e1->type->toBasetype();
7704 Type *t2 = exp->e2->type->toBasetype();
7705 if ((t1->ty == Tclass && exp->e2->op == TOKnull) ||
7706 (t2->ty == Tclass && exp->e1->op == TOKnull))
7708 exp->error("do not use null when comparing class types");
7712 Expression *e = exp->op_overload(sc);
7715 if (!e->type->isscalar() && e->type->equals(exp->e1->type))
7717 exp->error("recursive opCmp expansion");
7722 e = new CmpExp(exp->op, exp->loc, e, new IntegerExp(exp->loc, 0, Type::tint32));
7729 if (Expression *ex = typeCombine(exp, sc))
7735 bool f1 = checkNonAssignmentArrayOp(exp->e1);
7736 bool f2 = checkNonAssignmentArrayOp(exp->e2);
7740 exp->type = Type::tbool;
7743 t1 = exp->e1->type->toBasetype();
7744 t2 = exp->e2->type->toBasetype();
7754 exp->error("array comparison type mismatch, %s vs %s", t1next->toChars(), t2next->toChars());
7767 exp->error("need member function opCmp() for %s %s to compare", t2->toDsymbol(sc)->kind(), t2->toChars());
7769 exp->error("need member function opCmp() for %s %s to compare", t1->toDsymbol(sc)->kind(), t1->toChars());
7774 exp->error("compare not defined for complex operands");
7779 exp->error("%s is not defined for associative arrays", Token::toChars(exp->op));
7782 else if (!Target::isVectorOpSupported(t1, exp->op, t2))
7784 result = exp->incompatibleTypes();
7789 bool r1 = exp->e1->checkValue();
7790 bool r2 = exp->e2->checkValue();
7796 switch (exp->op)
7813 exp->error("'%s' is not defined for array comparisons", Token::toChars(exp->op));
7822 const char *s = exp->op == TOKunord ? "false" : "true";
7823 exp->error("floating point operator '%s' always returns %s for non-floating comparisons",
7824 Token::toChars(exp->op), s);
7828 exp->error("use '%s' for non-floating comparisons rather than floating point operator '%s'",
7829 Token::toChars(altop), Token::toChars(exp->op));
7834 exp->error("use std.math.isNaN to deal with NaN operands rather than floating point operator '%s'",
7835 Token::toChars(exp->op));
7841 result = exp;
7844 void visit(EqualExp *exp)
7847 if (exp->type)
7849 result = exp;
7853 setNoderefOperands(exp);
7855 if (Expression *e = binSemanticProp(exp, sc))
7860 if (exp->e1->op == TOKtype || exp->e2->op == TOKtype)
7862 result = exp->incompatibleTypes();
7867 Type *t1 = exp->e1->type;
7868 Type *t2 = exp->e2->type;
7870 exp->deprecation("Comparison between different enumeration types `%s` and `%s`; If this behavior is intended consider using `std.conv.asOriginalType`",
7878 if (exp->e1->op == TOKaddress && exp->e2->op == TOKaddress)
7880 AddrExp *ae1 = (AddrExp *)exp->e1;
7881 AddrExp *ae2 = (AddrExp *)exp->e2;
7890 result = new IntegerExp(exp->loc, (exp->op == TOKequal), Type::tbool);
7896 if (Expression *e = exp->op_overload(sc))
7902 if (Expression *e = typeCombine(exp, sc))
7908 bool f1 = checkNonAssignmentArrayOp(exp->e1);
7909 bool f2 = checkNonAssignmentArrayOp(exp->e2);
7913 exp->type = Type::tbool;
7916 if (!arrayTypeCompatible(exp->loc, exp->e1->type, exp->e2->type))
7918 if (exp->e1->type != exp->e2->type && exp->e1->type->isfloating() && exp->e2->type->isfloating())
7921 exp->e1 = exp->e1->castTo(sc, Type::tcomplex80);
7922 exp->e2 = exp->e2->castTo(sc, Type::tcomplex80);
7925 if (exp->e1->type->toBasetype()->ty == Taarray)
7926 semanticTypeInfo(sc, exp->e1->type->toBasetype());
7928 Type *t1 = exp->e1->type->toBasetype();
7929 Type *t2 = exp->e2->type->toBasetype();
7931 if (!Target::isVectorOpSupported(t1, exp->op, t2))
7933 result = exp->incompatibleTypes();
7937 result = exp;
7940 void visit(IdentityExp *exp)
7942 if (exp->type)
7944 result = exp;
7948 setNoderefOperands(exp);
7950 if (Expression *ex = binSemanticProp(exp, sc))
7956 if (Expression *ex = typeCombine(exp, sc))
7962 bool f1 = checkNonAssignmentArrayOp(exp->e1);
7963 bool f2 = checkNonAssignmentArrayOp(exp->e2);
7967 if (exp->e1->op == TOKtype || exp->e2->op == TOKtype)
7969 result = exp->incompatibleTypes();
7973 exp->type = Type::tbool;
7975 if (exp->e1->type != exp->e2->type && exp->e1->type->isfloating() && exp->e2->type->isfloating())
7978 exp->e1 = exp->e1->castTo(sc, Type::tcomplex80);
7979 exp->e2 = exp->e2->castTo(sc, Type::tcomplex80);
7982 Type *tb1 = exp->e1->type->toBasetype();
7983 Type *tb2 = exp->e2->type->toBasetype();
7984 if (!Target::isVectorOpSupported(tb1, exp->op, tb2))
7986 result = exp->incompatibleTypes();
7990 result = exp;
7993 void visit(CondExp *exp)
7995 if (exp->type)
7997 result = exp;
8001 if (exp->econd->op == TOKdotid)
8002 ((DotIdExp *)exp->econd)->noderef = true;
8004 Expression *ec = semantic(exp->econd, sc);
8010 Expression *e1x = semantic(exp->e1, sc);
8017 Expression *e2x = semantic(exp->e2, sc);
8020 sc->mergeCallSuper(exp->loc, cs1);
8021 sc->mergeFieldInit(exp->loc, fi1);
8030 exp->econd = ec;
8039 exp->e1 = e1x;
8048 exp->e2 = e2x;
8050 bool f0 = checkNonAssignmentArrayOp(exp->econd);
8051 bool f1 = checkNonAssignmentArrayOp(exp->e1);
8052 bool f2 = checkNonAssignmentArrayOp(exp->e2);
8056 Type *t1 = exp->e1->type;
8057 Type *t2 = exp->e2->type;
8063 exp->type = Type::tvoid;
8064 exp->e1 = exp->e1->castTo(sc, exp->type);
8065 exp->e2 = exp->e2->castTo(sc, exp->type);
8068 exp->type = t1;
8071 if (Expression *ex = typeCombine(exp, sc))
8076 switch (exp->e1->type->toBasetype()->ty)
8081 exp->e2 = exp->e2->castTo(sc, exp->e1->type);
8084 switch (exp->e2->type->toBasetype()->ty)
8089 exp->e1 = exp->e1->castTo(sc, exp->e2->type);
8092 if (exp->type->toBasetype()->ty == Tarray)
8094 exp->e1 = exp->e1->castTo(sc, exp->type);
8095 exp->e2 = exp->e2->castTo(sc, exp->type);
8098 exp->type = exp->type->merge2();
8110 exp->hookDtors(sc);
8112 result = exp;
8164 Expression *trySemantic(Expression *exp, Scope* sc)
8168 Expression *e = semantic(exp, sc);
8237 Expression *semanticX(DotIdExp *exp, Scope *sc)
8240 if (Expression *ex = unaSemantic(exp, sc))
8243 if (exp->ident == Id::_mangleof)
8247 switch (exp->e1->op)
8250 ds = ((ScopeExp *)exp->e1)->sds;
8253 ds = ((VarExp *)exp->e1)->var;
8256 ds = ((DotVarExp *)exp->e1)->var;
8259 ds = ((OverExp *)exp->e1)->vars;
8263 TemplateExp *te = (TemplateExp *)exp->e1;
8271 if (f->checkForwardRef(exp->loc))
8277 Expression *e = new StringExp(exp->loc, const_cast<char*>(s), strlen(s));
8286 if (exp->e1->op == TOKvar && exp->e1->type->toBasetype()->ty == Tsarray && exp->ident == Id::length)
8289 return exp->e1->type->dotExp(sc, exp->e1, exp->ident, exp->noderef ? 2 : 0);
8292 if (exp->e1->op == TOKdot)
8297 exp->e1 = resolvePropertiesX(sc, exp->e1);
8299 if (exp->e1->op == TOKtuple && exp->ident == Id::offsetof)
8303 TupleExp *te = (TupleExp *)exp->e1;
8314 Expression *e = new TupleExp(exp->loc, NULL, exps);
8318 if (exp->e1->op == TOKtuple && exp->ident == Id::length)
8320 TupleExp *te = (TupleExp *)exp->e1;
8322 Expression *e = new IntegerExp(exp->loc, te->exps->dim, Type::tsize_t);
8327 if ((exp->e1->op == TOKdottd || exp->e1->op == TOKtemplate) && exp->ident != Id::stringof)
8329 exp->error("template %s does not have property '%s'", exp->e1->toChars(), exp->ident->toChars());
8333 if (!exp->e1->type)
8335 exp->error("expression %s does not have property '%s'", exp->e1->toChars(), exp->ident->toChars());
8339 return exp;
8344 Expression *semanticY(DotIdExp *exp, Scope *sc, int flag)
8354 if ((exp->e1->op == TOKthis || exp->e1->op == TOKsuper) && !hasThis(sc))
8358 if (exp->e1->op == TOKthis)
8360 exp->e1 = new TypeExp(exp->e1->loc, ad->type);
8366 exp->e1 = new TypeExp(exp->e1->loc, cd->baseClass->type);
8371 Expression *e = semanticX(exp, sc);
8372 if (e != exp)
8377 if (exp->e1->op == TOKdot)
8379 DotExp *de = (DotExp *)exp->e1;
8386 eright = exp->e1;
8389 Type *t1b = exp->e1->type->toBasetype();
8404 Dsymbol *s = ie->sds->search(exp->loc, exp->ident, flags);
8411 ::error(exp->loc, "%s is not visible from module %s", s->toPrettyChars(), sc->_module->toChars());
8413 ::deprecation(exp->loc, "%s is not visible from module %s", s->toPrettyChars(), sc->_module->toChars());
8419 checkAccess(exp->loc, sc, p);
8424 exp->checkDeprecated(sc, s);
8429 return em->getVarExp(exp->loc, sc);
8440 exp->error("circular reference to %s '%s'", v->kind(), v->toPrettyChars());
8442 exp->error("forward reference to %s '%s'", v->kind(), v->toPrettyChars());
8448 if ((v->storage_class & STCmanifest) && v->_init && !exp->wantsym)
8456 ::error(exp->loc, "circular initialization of %s '%s'", v->kind(), v->toPrettyChars());
8459 e = v->expandInitializer(exp->loc);
8469 eleft = new ThisExp(exp->loc);
8470 e = new DotVarExp(exp->loc, eleft, v);
8475 e = new VarExp(exp->loc, v);
8477 { e = new CommaExp(exp->loc, eleft, e);
8494 eleft = new ThisExp(exp->loc);
8495 e = new DotVarExp(exp->loc, eleft, f, true);
8500 e = new VarExp(exp->loc, f, true);
8502 { e = new CommaExp(exp->loc, eleft, e);
8511 e = new DotTemplateExp(exp->loc, eleft, td);
8513 e = new TemplateExp(exp->loc, td);
8519 e = new VarExp(exp->loc, od, true);
8522 e = new CommaExp(exp->loc, eleft, e);
8530 return new OverExp(exp->loc, o);
8535 return semantic(new TypeExp(exp->loc, t), sc);
8543 e = new DotVarExp(exp->loc, eleft, tup);
8547 e = new TupleExp(exp->loc, tup);
8555 //printf("it's a ScopeDsymbol %s\n", exp->ident->toChars());
8556 e = new ScopeExp(exp->loc, sds);
8559 e = new DotExp(exp->loc, eleft, e);
8566 ie = new ScopeExp(exp->loc, imp->pkg);
8573 else if (exp->ident == Id::stringof)
8576 e = new StringExp(exp->loc, const_cast<char *>(p), strlen(p));
8588 s = ie->sds->search_correct(exp->ident);
8590 exp->error("undefined identifier '%s' in %s '%s', did you mean %s '%s'?",
8591 exp->ident->toChars(), ie->sds->kind(), ie->sds->toPrettyChars(), s->kind(), s->toChars());
8593 exp->error("undefined identifier '%s' in %s '%s'",
8594 exp->ident->toChars(), ie->sds->kind(), ie->sds->toPrettyChars());
8597 else if (t1b->ty == Tpointer && exp->e1->type->ty != Tenum &&
8598 exp->ident != Id::_init && exp->ident != Id::__sizeof &&
8599 exp->ident != Id::__xalignof && exp->ident != Id::offsetof &&
8600 exp->ident != Id::_mangleof && exp->ident != Id::stringof)
8617 e = new PtrExp(exp->loc, exp->e1);
8619 return e->type->dotExp(sc, e, exp->ident, flag | (exp->noderef ? 2 : 0));
8623 if (exp->e1->op == TOKtype || exp->e1->op == TOKtemplate)
8625 e = exp->e1->type->dotExp(sc, exp->e1, exp->ident, flag | (exp->noderef ? 2 : 0));
8634 Expression *semanticY(DotTemplateInstanceExp *exp, Scope *sc, int flag)
8636 DotIdExp *die = new DotIdExp(exp->loc, exp->e1, exp->ti->name);
8641 exp->e1 = die->e1; // take back
8643 Type *t1b = exp->e1->type->toBasetype();
8682 exp->e1 = dve->e1; // pull semantic() result
8683 if (!exp->findTempDecl(sc))
8685 if (exp->ti->needsTypeInference(sc))
8686 return exp;
8687 exp->ti->semantic(sc);
8688 if (!exp->ti->inst || exp->ti->errors) // if template failed to expand
8690 Dsymbol *s = exp->ti->toAlias();
8696 e = new DotVarExp(exp->loc, exp->e1, v);
8700 e = new ScopeExp(exp->loc, exp->ti);
8701 e = new DotExp(exp->loc, exp->e1, e);
8720 exp->ti->tempdecl = od;
8721 e = new ScopeExp(exp->loc, exp->ti);
8729 exp->e1 = dte->e1; // pull semantic() result
8731 exp->ti->tempdecl = dte->td;
8732 if (!exp->ti->semanticTiargs(sc))
8734 if (exp->ti->needsTypeInference(sc))
8735 return exp;
8736 exp->ti->semantic(sc);
8737 if (!exp->ti->inst || exp->ti->errors) // if template failed to expand
8739 Dsymbol *s = exp->ti->toAlias();
8743 e = new DotVarExp(exp->loc, exp->e1, v);
8747 e = new ScopeExp(exp->loc, exp->ti);
8748 e = new DotExp(exp->loc, exp->e1, e);
8754 exp->ti->tempdecl = ((TemplateExp *)e)->td;
8755 e = new ScopeExp(exp->loc, exp->ti);
8765 if (!exp->findTempDecl(sc) ||
8766 !exp->ti->semanticTiargs(sc))
8770 if (exp->ti->needsTypeInference(sc))
8771 return exp;
8772 exp->ti->semantic(sc);
8773 if (!exp->ti->inst || exp->ti->errors) // if template failed to expand
8775 Dsymbol *s = exp->ti->toAlias();
8781 e = new DotVarExp(exp->loc, exp->e1, v);
8785 e = new ScopeExp(exp->loc, exp->ti);
8786 e = new DotExp(exp->loc, exp->e1, e);
8794 exp->ti->tempdecl = oe->vars;
8795 e = new ScopeExp(exp->loc, exp->ti);