public EXPRHOISTEDLOCALEXPR CreateHoistedLocalInExpression(EXPRLOCAL localToHoist) { Debug.Assert(localToHoist != null); EXPRHOISTEDLOCALEXPR rval = new EXPRHOISTEDLOCALEXPR(); rval.kind = ExpressionKind.EK_HOISTEDLOCALEXPR; rval.type = GetTypes().GetOptPredefAgg(PredefinedType.PT_EXPRESSION).getThisType(); rval.flags = 0; return(rval); }
public EXPRLOCAL CreateLocal(EXPRFLAG nFlags, LocalVariableSymbol pLocal) { Debug.Assert(0 == (nFlags & ~(EXPRFLAG.EXF_MASK_ANY))); CType type = null; if (pLocal != null) { type = pLocal.GetType(); } EXPRLOCAL rval = new EXPRLOCAL(); rval.kind = ExpressionKind.EK_LOCAL; rval.type = type; rval.flags = nFlags; rval.local = pLocal; Debug.Assert(rval != null); return(rval); }
protected override EXPR VisitLOCAL(EXPRLOCAL local) { Debug.Assert(local != null); Debug.Assert(alwaysRewrite || currentAnonMeth != null); Debug.Assert(!local.local.isThis); // this is true for all parameters of an expression lambda if (local.local.wrap != null) { return local.local.wrap; } Debug.Assert(local.local.fUsedInAnonMeth); return GetExprFactory().CreateHoistedLocalInExpression(local); }
protected EXPRQUESTIONMARK BindPtrToArray(EXPRLOCAL exprLoc, EXPR array) { CType typeElem = array.type.AsArrayType().GetElementType(); CType typePtrElem = GetTypes().GetPointer(typeElem); // element must be unmanaged... if (GetSymbolLoader().isManagedType(typeElem)) { ErrorContext.Error(ErrorCode.ERR_ManagedAddr, typeElem); } SetExternalRef(typeElem); EXPR test = null; // we need to wrap the array so we can effectively generate something like this: // (((temp = array) != null && temp.Length > 0) ? loc = temp[0] : loc = null) // NOTE: The assignment needs to be inside the ExpressionKind.EK_QUESTIONMARK. // We can't do loc = (... ? ... : ...) since the CLR type of temp[0] is a managed // pointer and null is a UIntPtr - which confuses the JIT. We can't just convert // temp[0] to UIntPtr with a conv.u instruction because then if a GC occurs between // the time of the cast and the assignment to the local, we're toast. EXPRWRAP wrapArray = WrapShortLivedExpression(array).asWRAP(); EXPR save = GetExprFactory().CreateSave(wrapArray); EXPR nullTest = GetExprFactory().CreateBinop(ExpressionKind.EK_NE, GetReqPDT(PredefinedType.PT_BOOL), save, GetExprFactory().CreateConstant(wrapArray.type, ConstValFactory.GetInt(0))); EXPR lenTest; if (array.type.AsArrayType().rank == 1) { EXPR len = GetExprFactory().CreateArrayLength(wrapArray); lenTest = GetExprFactory().CreateBinop(ExpressionKind.EK_NE, GetReqPDT(PredefinedType.PT_BOOL), len, GetExprFactory().CreateConstant(GetReqPDT(PredefinedType.PT_INT), ConstValFactory.GetInt(0))); } else { EXPRCALL call = BindPredefMethToArgs(PREDEFMETH.PM_ARRAY_GETLENGTH, wrapArray, null, null, null); lenTest = GetExprFactory().CreateBinop(ExpressionKind.EK_NE, GetReqPDT(PredefinedType.PT_BOOL), call, GetExprFactory().CreateConstant(GetReqPDT(PredefinedType.PT_INT), ConstValFactory.GetInt(0))); } test = GetExprFactory().CreateBinop(ExpressionKind.EK_LOGAND, GetReqPDT(PredefinedType.PT_BOOL), nullTest, lenTest); EXPR list = null; EXPR pList = list; EXPR pLastList = null; for (int cc = 0; cc < array.type.AsArrayType().rank; cc++) { GetExprFactory().AppendItemToList(GetExprFactory().CreateConstant(GetReqPDT(PredefinedType.PT_INT), ConstValFactory.GetInt(0)), ref pList, ref pLastList); } Debug.Assert(list != null); EXPR exprAddr = GetExprFactory().CreateUnaryOp(ExpressionKind.EK_ADDR, typePtrElem, GetExprFactory().CreateArrayIndex(wrapArray, list)); exprAddr.flags |= EXPRFLAG.EXF_ADDRNOCONV; exprAddr = mustConvert(exprAddr, exprLoc.type, CONVERTTYPE.NOUDC); exprAddr = GetExprFactory().CreateAssignment(exprLoc, exprAddr); exprAddr.flags |= EXPRFLAG.EXF_ASSGOP; exprAddr = GetExprFactory().CreateBinop(ExpressionKind.EK_SEQREV, exprLoc.type, exprAddr, WrapShortLivedExpression(wrapArray)); // free the temp EXPR exprnull = GetExprFactory().CreateZeroInit(exprLoc.type); exprnull = GetExprFactory().CreateAssignment(exprLoc, exprnull); exprnull.flags |= EXPRFLAG.EXF_ASSGOP; EXPRBINOP exprRes = GetExprFactory().CreateBinop(ExpressionKind.EK_BINOP, exprAddr.type, exprAddr, exprnull); return GetExprFactory().CreateQuestionMark(test, exprRes); }
protected virtual EXPR VisitLOCAL(EXPRLOCAL pExpr) { return VisitEXPR(pExpr); }
protected virtual EXPR VisitLOCAL(EXPRLOCAL pExpr) { return(VisitEXPR(pExpr)); }
public EXPRHOISTEDLOCALEXPR CreateHoistedLocalInExpression(EXPRLOCAL localToHoist) { Debug.Assert(localToHoist != null); EXPRHOISTEDLOCALEXPR rval = new EXPRHOISTEDLOCALEXPR(); rval.kind = ExpressionKind.EK_HOISTEDLOCALEXPR; rval.type = GetTypes().GetOptPredefAgg(PredefinedType.PT_EXPRESSION).getThisType(); rval.flags = 0; return rval; }
public EXPRLOCAL CreateLocal(EXPRFLAG nFlags, LocalVariableSymbol pLocal) { Debug.Assert(0 == (nFlags & ~(EXPRFLAG.EXF_MASK_ANY))); CType type = null; if (pLocal != null) { type = pLocal.GetType(); } EXPRLOCAL rval = new EXPRLOCAL(); rval.kind = ExpressionKind.EK_LOCAL; rval.type = type; rval.flags = nFlags; rval.local = pLocal; Debug.Assert(rval != null); return (rval); }