本文整理汇总了C#中Mono.CSharp.Constant.ConvertImplicitly方法的典型用法代码示例。如果您正苦于以下问题:C# Constant.ConvertImplicitly方法的具体用法?C# Constant.ConvertImplicitly怎么用?C# Constant.ConvertImplicitly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.Constant
的用法示例。
在下文中一共展示了Constant.ConvertImplicitly方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertPromotion
static bool ConvertPromotion (ResolveContext rc, ref Constant prim, ref Constant second, TypeSpec type)
{
Constant c = prim.ConvertImplicitly (type);
if (c != null) {
prim = c;
return true;
}
if (type.BuiltinType == BuiltinTypeSpec.Type.UInt) {
type = rc.BuiltinTypes.Long;
prim = prim.ConvertImplicitly (type);
second = second.ConvertImplicitly (type);
return prim != null && second != null;
}
return false;
}
示例2: ConvertPromotion
static bool ConvertPromotion (ref Constant prim, ref Constant second, Type type)
{
Constant c = prim.ConvertImplicitly (type);
if (c != null) {
prim = c;
return true;
}
if (type == TypeManager.uint32_type) {
type = TypeManager.int64_type;
prim = prim.ConvertImplicitly (type);
second = second.ConvertImplicitly (type);
return prim != null && second != null;
}
return false;
}
示例3: DoBinaryNumericPromotions
//
// Performs the numeric promotions on the left and right expresions
// and deposits the results on `lc' and `rc'.
//
// On success, the types of `lc' and `rc' on output will always match,
// and the pair will be one of:
//
// TODO: BinaryFold should be called as an optimization step only,
// error checking here is weak
//
static bool DoBinaryNumericPromotions (ResolveContext rc, ref Constant left, ref Constant right)
{
TypeSpec ltype = left.Type;
TypeSpec rtype = right.Type;
foreach (TypeSpec t in rc.BuiltinTypes.BinaryPromotionsTypes) {
if (t == ltype)
return t == rtype || ConvertPromotion (rc, ref right, ref left, t);
if (t == rtype)
return t == ltype || ConvertPromotion (rc, ref left, ref right, t);
}
left = left.ConvertImplicitly (rc.BuiltinTypes.Int);
right = right.ConvertImplicitly (rc.BuiltinTypes.Int);
return left != null && right != null;
}
示例4: DoBinaryNumericPromotions
//
// Performs the numeric promotions on the left and right expresions
// and deposits the results on `lc' and `rc'.
//
// On success, the types of `lc' and `rc' on output will always match,
// and the pair will be one of:
//
static bool DoBinaryNumericPromotions (ref Constant left, ref Constant right)
{
Type ltype = left.Type;
Type rtype = right.Type;
foreach (Type t in binary_promotions) {
if (t == ltype)
return t == rtype || ConvertPromotion (ref right, ref left, t);
if (t == rtype)
return t == ltype || ConvertPromotion (ref left, ref right, t);
}
left = left.ConvertImplicitly (TypeManager.int32_type);
right = right.ConvertImplicitly (TypeManager.int32_type);
return left != null && right != null;
}
示例5: DoBinaryNumericPromotions
//
// Performs the numeric promotions on the left and right expresions
// and deposits the results on `lc' and `rc'.
//
// On success, the types of `lc' and `rc' on output will always match,
// and the pair will be one of:
//
// TODO: BinaryFold should be called as an optimization step only,
// error checking here is weak
//
static bool DoBinaryNumericPromotions (ResolveContext rc, ref Constant left, ref Constant right)
{
TypeSpec ltype = left.Type;
TypeSpec rtype = right.Type;
// PlayScript - AS has bool as an additional binary promotion type.
TypeSpec[] binaryPromotionsTypes = (rc.FileType == SourceFileType.PlayScript ?
rc.BuiltinTypes.AsBinaryPromotionsTypes : rc.BuiltinTypes.BinaryPromotionsTypes);
foreach (TypeSpec t in binaryPromotionsTypes) {
if (t == ltype)
return t == rtype || ConvertPromotion (rc, ref right, ref left, t);
if (t == rtype)
return t == ltype || ConvertPromotion (rc, ref left, ref right, t);
}
left = left.ConvertImplicitly (rc.BuiltinTypes.Int, rc);
right = right.ConvertImplicitly (rc.BuiltinTypes.Int, rc);
return left != null && right != null;
}
示例6: ConvertInitializer
public virtual Constant ConvertInitializer (ResolveContext rc, Constant expr)
{
return expr.ConvertImplicitly (MemberType);
}
示例7: BinaryFold
//.........这里部分代码省略.........
if (lt == InternalType.NullLiteral)
return right;
if (rt == InternalType.NullLiteral)
return left;
//
// If both sides are strings, then concatenate, if
// one is a string, and the other is not, then defer
// to runtime concatenation
//
if (lt.BuiltinType == BuiltinTypeSpec.Type.String || rt.BuiltinType == BuiltinTypeSpec.Type.String){
if (lt == rt)
return new StringConstant (ec.BuiltinTypes, (string)left.GetValue () + (string)right.GetValue (),
left.Location);
return null;
}
//
// handle "E operator + (E x, U y)"
// handle "E operator + (Y y, E x)"
//
EnumConstant lc = left as EnumConstant;
EnumConstant rc = right as EnumConstant;
if (lc != null || rc != null){
if (lc == null) {
lc = rc;
lt = lc.Type;
right = left;
}
// U has to be implicitly convetible to E.base
right = right.ConvertImplicitly (lc.Child.Type);
if (right == null)
return null;
result = BinaryFold (ec, oper, lc.Child, right, loc);
if (result == null)
return null;
result = result.TryReduce (ec, lt);
if (result == null)
return null;
return new EnumConstant (result, lt);
}
if (!DoBinaryNumericPromotions (ec, ref left, ref right))
return null;
try {
if (left is DoubleConstant){
double res;
if (ec.ConstantCheckState)
res = checked (((DoubleConstant) left).Value +
((DoubleConstant) right).Value);
else
res = unchecked (((DoubleConstant) left).Value +
((DoubleConstant) right).Value);
return new DoubleConstant (ec.BuiltinTypes, res, left.Location);
}
if (left is FloatConstant){
float res;
示例8: BinaryFold
//.........这里部分代码省略.........
case Binary.Operator.Addition:
//
// If both sides are strings, then concatenate, if
// one is a string, and the other is not, then defer
// to runtime concatenation
//
if (lt == TypeManager.string_type || rt == TypeManager.string_type){
if (lt == TypeManager.string_type && rt == TypeManager.string_type)
return new StringConstant (
((StringConstant) left).Value +
((StringConstant) right).Value, left.Location);
return null;
}
if (lt == TypeManager.null_type && lt == rt)
return left;
//
// handle "E operator + (E x, U y)"
// handle "E operator + (Y y, E x)"
//
EnumConstant lc = left as EnumConstant;
EnumConstant rc = right as EnumConstant;
if (lc != null || rc != null){
if (lc == null) {
lc = rc;
lt = lc.Type;
right = left;
}
// U has to be implicitly convetible to E.base
right = right.ConvertImplicitly (lc.Child.Type);
if (right == null)
return null;
result = BinaryFold (ec, oper, lc.Child, right, loc);
if (result == null)
return null;
result = result.TryReduce (ec, lt, loc);
if (result == null)
return null;
return new EnumConstant (result, lt);
}
if (!DoBinaryNumericPromotions (ref left, ref right))
return null;
try {
if (left is DoubleConstant){
double res;
if (ec.ConstantCheckState)
res = checked (((DoubleConstant) left).Value +
((DoubleConstant) right).Value);
else
res = unchecked (((DoubleConstant) left).Value +
((DoubleConstant) right).Value);
return new DoubleConstant (res, left.Location);
}
if (left is FloatConstant){
float res;