public static CONSTVAL GetBool(bool value) { CONSTVAL result = new CONSTVAL(); result.boolVal = value; return(result); }
public static CONSTVAL GetInt(int value) { CONSTVAL result = new CONSTVAL();; result.iVal = value; return(result); }
internal CONSTVAL Create(object p) { CONSTVAL result = new CONSTVAL(); result.objectVal = p; return(result); }
public static CONSTVAL GetDefaultValue(ConstValKind kind) { CONSTVAL result = new CONSTVAL(); switch (kind) { case ConstValKind.Int: result.iVal = 0; break; case ConstValKind.Double: result.doubleVal = 0; break; case ConstValKind.Long: result.longVal = 0; break; case ConstValKind.Decimal: result.decVal = 0; break; case ConstValKind.Float: result.floatVal = 0; break; case ConstValKind.Boolean: result.boolVal = false; break; } return(result); }
public static CONSTVAL GetUInt(uint value) { CONSTVAL result = new CONSTVAL(); result.uiVal = value; return(result); }
public CONSTVAL Create(decimal value) { CONSTVAL result = new CONSTVAL(); result.decVal = value; return(result); }
internal CONSTVAL Create(bool value) { CONSTVAL result = new CONSTVAL(); result.boolVal = value; return(result); }
public CONSTVAL Create(double value) { CONSTVAL result = new CONSTVAL(); result.doubleVal = value; return(result); }
public CONSTVAL Create(ulong value) { CONSTVAL result = new CONSTVAL(); result.ulongVal = value; return(result); }
public CONSTVAL Create(float value) { CONSTVAL result = new CONSTVAL(); result.floatVal = value; return(result); }
public CONSTVAL Create(string value) { CONSTVAL result = new CONSTVAL(); result.strVal = value; return(result); }
public static CONSTVAL GetDefaultValue(ConstValKind kind) { CONSTVAL result = new CONSTVAL(); switch (kind) { case ConstValKind.Int: result.iVal = 0; break; case ConstValKind.Double: result.doubleVal = 0; break; case ConstValKind.Long: result.longVal = 0; break; case ConstValKind.Decimal: result.decVal = 0; break; case ConstValKind.Float: result.floatVal = 0; break; case ConstValKind.Boolean: result.boolVal = false; break; } return result; }
private EXPR BindIncOpCore(ExpressionKind ek, EXPRFLAG flags, EXPR exprVal, CType type) { Debug.Assert(ek == ExpressionKind.EK_ADD || ek == ExpressionKind.EK_SUB); CONSTVAL cv = new CONSTVAL(); EXPR pExprResult = null; if (type.isEnumType() && type.fundType() > FUNDTYPE.FT_LASTINTEGRAL) { // This is an error case when enum derives from an illegal type. Just treat it as an int. type = GetReqPDT(PredefinedType.PT_INT); } FUNDTYPE ft = type.fundType(); CType typeTmp = type; switch (ft) { default: { Debug.Assert(type.isPredefType(PredefinedType.PT_DECIMAL)); ek = ek == ExpressionKind.EK_ADD ? ExpressionKind.EK_DECIMALINC : ExpressionKind.EK_DECIMALDEC; PREDEFMETH predefMeth = ek == ExpressionKind.EK_DECIMALINC ? PREDEFMETH.PM_DECIMAL_OPINCREMENT : PREDEFMETH.PM_DECIMAL_OPDECREMENT; pExprResult = CreateUnaryOpForPredefMethodCall(ek, predefMeth, type, exprVal); } break; case FUNDTYPE.FT_PTR: cv.iVal = 1; pExprResult = BindPtrBinOp(ek, flags, exprVal, GetExprFactory().CreateConstant(GetReqPDT(PredefinedType.PT_INT), cv)); break; case FUNDTYPE.FT_I1: case FUNDTYPE.FT_I2: case FUNDTYPE.FT_U1: case FUNDTYPE.FT_U2: typeTmp = GetReqPDT(PredefinedType.PT_INT); cv.iVal = 1; pExprResult = LScalar(ek, flags, exprVal, type, cv, pExprResult, typeTmp); break; case FUNDTYPE.FT_I4: case FUNDTYPE.FT_U4: cv.iVal = 1; pExprResult = LScalar(ek, flags, exprVal, type, cv, pExprResult, typeTmp); break; case FUNDTYPE.FT_I8: case FUNDTYPE.FT_U8: cv = GetExprConstants().Create((long)1); pExprResult = LScalar(ek, flags, exprVal, type, cv, pExprResult, typeTmp); break; case FUNDTYPE.FT_R4: case FUNDTYPE.FT_R8: cv = GetExprConstants().Create(1.0); pExprResult = LScalar(ek, flags, exprVal, type, cv, pExprResult, typeTmp); break; } Debug.Assert(pExprResult != null); Debug.Assert(!pExprResult.type.IsNullableType()); return pExprResult; }
public CONSTVAL Create(decimal value) { CONSTVAL result = new CONSTVAL(); result.decVal = value; return result; }
public static CONSTVAL GetInt(int value) { CONSTVAL result = new CONSTVAL(); ; result.iVal = value; return result; }
/* Bind a shift operator: <<, >>. These can have integer or long first operands, and second operand must be int. */ private EXPR BindShiftOp(ExpressionKind ek, EXPRFLAG flags, EXPR arg1, EXPR arg2) { Debug.Assert(ek == ExpressionKind.EK_LSHIFT || ek == ExpressionKind.EK_RSHIFT); Debug.Assert(arg1.type.isPredefined()); Debug.Assert(arg2.type.isPredefType(PredefinedType.PT_INT)); PredefinedType ptOp = arg1.type.getPredefType(); Debug.Assert(ptOp == PredefinedType.PT_INT || ptOp == PredefinedType.PT_UINT || ptOp == PredefinedType.PT_LONG || ptOp == PredefinedType.PT_ULONG); // We want to check up front if we have two constants, because constant folding is supposed to // happen in the initial binding pass. EXPR argConst1 = arg1.GetConst(); EXPR argConst2 = arg2.GetConst(); if (argConst1 == null || argConst2 == null) // One or more aren't constants, so don't fold anything. { return GetExprFactory().CreateBinop(ek, arg1.type, arg1, arg2); } // Both constants, so fold them. CONSTVAL cv = new CONSTVAL(); int cbit = (ptOp == PredefinedType.PT_LONG || ptOp == PredefinedType.PT_ULONG) ? 0x3f : 0x1f; cv.iVal = argConst2.asCONSTANT().getVal().iVal & cbit; cbit = cv.iVal; // Fill in the CONSTVAL. if (ptOp == PredefinedType.PT_LONG || ptOp == PredefinedType.PT_ULONG) { Debug.Assert(0 <= cbit && cbit < 0x40); ulong u1 = argConst1.asCONSTANT().getVal().ulongVal; ulong uval; switch (ek) { case ExpressionKind.EK_LSHIFT: uval = u1 << cbit; break; case ExpressionKind.EK_RSHIFT: uval = (ptOp == PredefinedType.PT_LONG) ? (ulong)((long)u1 >> cbit) : (u1 >> cbit); break; default: VSFAIL("Unknown op"); uval = 0; break; } cv = GetExprConstants().Create(uval); } else { Debug.Assert(0 <= cbit && cbit < 0x20); uint u1 = argConst1.asCONSTANT().getVal().uiVal; switch (ek) { case ExpressionKind.EK_LSHIFT: cv.uiVal = u1 << cbit; break; case ExpressionKind.EK_RSHIFT: cv.uiVal = (ptOp == PredefinedType.PT_INT) ? (uint)((int)u1 >> cbit) : (u1 >> cbit); break; default: VSFAIL("Unknown op"); cv.uiVal = 0; break; } } EXPR exprRes = GetExprFactory().CreateConstant(GetReqPDT(ptOp), cv); return exprRes; }
public CONSTVAL Create(ulong value) { CONSTVAL result = new CONSTVAL(); result.ulongVal = value; return result; }
/* Bind an float/double operator: +, -, , /, %, <, >, <=, >=, ==, !=. If both operations are constants, the result will be a constant also. op2 can be null for a unary operator. The operands are assumed to be already converted to the correct type. */ // We have an intentional divide by 0 there, so disable the warning... #if _MSC_VER #pragma warning( disable : 4723 ) #endif private EXPR bindFloatOp(ExpressionKind kind, EXPRFLAG flags, EXPR op1, EXPR op2) { //Debug.Assert(kind.isRelational() || kind.isArithmetic()); Debug.Assert(op2 == null || op1.type == op2.type); Debug.Assert(op1.type.isPredefType(PredefinedType.PT_FLOAT) || op1.type.isPredefType(PredefinedType.PT_DOUBLE)); EXPR exprRes; EXPR opConst1 = op1.GetConst(); EXPR opConst2 = op2 != null ? op2.GetConst() : null; // Check for constants and fold them. if (opConst1 != null && (op2 == null || opConst2 != null)) { // Get the operands double d1 = opConst1.asCONSTANT().getVal().doubleVal; double d2 = opConst2 != null ? opConst2.asCONSTANT().getVal().doubleVal : 0.0; double result = 0; // if isBoolResult is false bool result_b = false; // if isBoolResult is true // Do the operation. switch (kind) { case ExpressionKind.EK_ADD: result = d1 + d2; break; case ExpressionKind.EK_SUB: result = d1 - d2; break; case ExpressionKind.EK_MUL: result = d1 * d2; break; case ExpressionKind.EK_DIV: result = d1 / d2; break; case ExpressionKind.EK_NEG: result = -d1; break; case ExpressionKind.EK_UPLUS: result = d1; break; case ExpressionKind.EK_MOD: result = d1 % d2; break; case ExpressionKind.EK_EQ: result_b = (d1 == d2); break; case ExpressionKind.EK_NE: result_b = (d1 != d2); break; case ExpressionKind.EK_LE: result_b = (d1 <= d2); break; case ExpressionKind.EK_LT: result_b = (d1 < d2); break; case ExpressionKind.EK_GE: result_b = (d1 >= d2); break; case ExpressionKind.EK_GT: result_b = (d1 > d2); break; default: Debug.Assert(false); result = 0.0; // unexpected operation. break; } CType typeDest; CONSTVAL cv = new CONSTVAL(); // Allocate the result node. if (kind.isRelational()) { cv.iVal = result_b ? 1 : 0; typeDest = GetReqPDT(PredefinedType.PT_BOOL); } else { // NaN has some implementation defined bits that differ between platforms. // Normalize it to produce identical images across all platforms /* * How do we get here? if (_isnan(result)) { cv = ConstValFactory.GetNan(); } else { * */ cv = GetExprConstants().Create(result); typeDest = op1.type; } exprRes = GetExprFactory().CreateConstant(typeDest, cv); } else { // Allocate the result expression. CType typeDest = kind.isRelational() ? GetReqPDT(PredefinedType.PT_BOOL) : op1.type; exprRes = GetExprFactory().CreateOperator(kind, typeDest, op1, op2); flags = ~EXPRFLAG.EXF_CHECKOVERFLOW; exprRes.flags |= flags; } return exprRes; }
private EXPR FoldConstI8Op(ExpressionKind kind, EXPR op1, EXPRCONSTANT opConst1, EXPR op2, EXPRCONSTANT opConst2, PredefinedType ptOp) { Debug.Assert(ptOp == PredefinedType.PT_LONG || ptOp == PredefinedType.PT_ULONG); Debug.Assert(opConst1.isCONSTANT_OK()); Debug.Assert(op1.type.isPredefType(ptOp) && op1.type == opConst1.type); Debug.Assert(op2 == null && opConst2 == null || op2 != null && opConst2 != null && opConst2.isCONSTANT_OK() && op1.type == op2.type && op1.type == opConst2.type); bool fSigned = (ptOp == PredefinedType.PT_LONG); bool fRes = false; // Allocate the result node. CType typeDest; CONSTVAL cv = new CONSTVAL(); if (fSigned) { // long. long u1 = opConst1.asCONSTANT().getVal().longVal; long u2 = opConst2 != null ? opConst2.asCONSTANT().getVal().longVal : 0; long uRes = 0; switch (kind) { case ExpressionKind.EK_ADD: uRes = u1 + u2; break; case ExpressionKind.EK_SUB: uRes = u1 - u2; break; case ExpressionKind.EK_MUL: uRes = u1 * u2; break; case ExpressionKind.EK_DIV: Debug.Assert(u2 != 0); // Caller should have handled this. uRes = u1 / u2; break; case ExpressionKind.EK_MOD: Debug.Assert(u2 != 0); // Caller should have handled this. uRes = u1 % u2; break; case ExpressionKind.EK_NEG: uRes = -u1; break; case ExpressionKind.EK_UPLUS: uRes = u1; break; case ExpressionKind.EK_BITAND: uRes = u1 & u2; break; case ExpressionKind.EK_BITOR: uRes = u1 | u2; break; case ExpressionKind.EK_BITXOR: uRes = u1 ^ u2; break; case ExpressionKind.EK_BITNOT: uRes = ~u1; break; case ExpressionKind.EK_EQ: fRes = (u1 == u2); break; case ExpressionKind.EK_NE: fRes = (u1 != u2); break; case ExpressionKind.EK_LE: fRes = u1 <= u2; break; case ExpressionKind.EK_LT: fRes = u1 < u2; break; case ExpressionKind.EK_GE: fRes = u1 >= u2; break; case ExpressionKind.EK_GT: fRes = u1 > u2; break; default: VSFAIL("Unknown op"); uRes = 0; break; } if (kind.isRelational()) { cv.iVal = fRes ? 1 : 0; typeDest = GetReqPDT(PredefinedType.PT_BOOL); } else { cv = GetExprConstants().Create(uRes); typeDest = GetOptPDT(ptOp); Debug.Assert(typeDest != null); } } else { // ulong. // Get the operands ulong u1 = opConst1.asCONSTANT().getVal().ulongVal; ulong u2 = opConst2 != null ? opConst2.asCONSTANT().getVal().ulongVal : 0; ulong uRes = 0; // Do the operation. switch (kind) { case ExpressionKind.EK_ADD: uRes = u1 + u2; break; case ExpressionKind.EK_SUB: uRes = u1 - u2; break; case ExpressionKind.EK_MUL: uRes = u1 * u2; break; case ExpressionKind.EK_DIV: Debug.Assert(u2 != 0); // Caller should have handled this. uRes = u1 / u2; break; case ExpressionKind.EK_MOD: Debug.Assert(u2 != 0); // Caller should have handled this. uRes = u1 % u2; break; case ExpressionKind.EK_NEG: // You can't do this! return BadOperatorTypesError(kind, op1, op2); case ExpressionKind.EK_UPLUS: uRes = u1; break; case ExpressionKind.EK_BITAND: uRes = u1 & u2; break; case ExpressionKind.EK_BITOR: uRes = u1 | u2; break; case ExpressionKind.EK_BITXOR: uRes = u1 ^ u2; break; case ExpressionKind.EK_BITNOT: uRes = ~u1; break; case ExpressionKind.EK_EQ: fRes = (u1 == u2); break; case ExpressionKind.EK_NE: fRes = (u1 != u2); break; case ExpressionKind.EK_LE: fRes = u1 <= u2; break; case ExpressionKind.EK_LT: fRes = u1 < u2; break; case ExpressionKind.EK_GE: fRes = u1 >= u2; break; case ExpressionKind.EK_GT: fRes = u1 > u2; break; default: VSFAIL("Unknown op"); uRes = 0; break; } if (kind.isRelational()) { cv.iVal = fRes ? 1 : 0; typeDest = GetReqPDT(PredefinedType.PT_BOOL); } else { cv = GetExprConstants().Create(uRes); typeDest = GetOptPDT(ptOp); Debug.Assert(typeDest != null); } } // Allocate the result node. EXPR exprRes = GetExprFactory().CreateConstant(typeDest, cv); return exprRes; }
public CONSTVAL Create(double value) { CONSTVAL result = new CONSTVAL(); result.doubleVal = value; return result; }
internal CONSTVAL Create(object p) { CONSTVAL result = new CONSTVAL(); result.objectVal = p; return result; }
internal CONSTVAL Create(bool value) { CONSTVAL result = new CONSTVAL(); result.boolVal = value; return result; }
private EXPR LScalar(ExpressionKind ek, EXPRFLAG flags, EXPR exprVal, CType type, CONSTVAL cv, EXPR pExprResult, CType typeTmp) { CType typeOne = type; if (typeOne.isEnumType()) { typeOne = typeOne.underlyingEnumType(); } pExprResult = GetExprFactory().CreateBinop(ek, typeTmp, exprVal, GetExprFactory().CreateConstant(typeOne, cv)); pExprResult.flags |= flags; if (typeTmp != type) { pExprResult = mustCast(pExprResult, type, CONVERTTYPE.NOUDC); } return pExprResult; }
public CONSTVAL Copy(ConstValKind kind, CONSTVAL value) { return new CONSTVAL(value.objectVal); }
public CONSTVAL Copy(ConstValKind kind, CONSTVAL value) { return(new CONSTVAL(value.objectVal)); }
public static CONSTVAL GetBool(bool value) { CONSTVAL result = new CONSTVAL(); result.boolVal = value; return result; }
public CONSTVAL Create(float value) { CONSTVAL result = new CONSTVAL(); result.floatVal = value; return result; }
public static CONSTVAL GetUInt(uint value) { CONSTVAL result = new CONSTVAL(); result.uiVal = value; return result; }
public EXPRCONSTANT CreateConstant(CType pType, CONSTVAL constVal) { return CreateConstant(pType, constVal, null); }
public CONSTVAL Create(string value) { CONSTVAL result = new CONSTVAL(); result.strVal = value; return result; }
public EXPRCONSTANT CreateConstant(CType pType, CONSTVAL constVal, EXPR pOriginal) { EXPRCONSTANT rval = CreateConstant(pType); rval.setVal(constVal); Debug.Assert(rval != null); return (rval); }
public void SetDefaultParameterValue(int index, CType type, CONSTVAL cv) { Debug.Assert(_defaultParameterIndex != null); ConstValFactory factory = new ConstValFactory(); _defaultParameterIndex[index] = true; _defaultParameters[index] = factory.Copy(type.constValKind(), cv); _defaultParameterConstValTypes[index] = type; }
public void setVal(CONSTVAL newValue) { Val = newValue; }