本文整理汇总了C#中Mono.CSharp.Constant类的典型用法代码示例。如果您正苦于以下问题:C# Constant类的具体用法?C# Constant怎么用?C# Constant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Constant类属于Mono.CSharp命名空间,在下文中一共展示了Constant类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例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:
//
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;
}
示例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:
//
// 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;
}
示例5: CreateDecimalConstantAttribute
public static CustomAttributeBuilder CreateDecimalConstantAttribute(Constant c)
{
PredefinedAttribute pa = PredefinedAttributes.Get.DecimalConstant;
if (pa.Constructor == null &&
!pa.ResolveConstructor (c.Location, TypeManager.byte_type, TypeManager.byte_type,
TypeManager.uint32_type, TypeManager.uint32_type, TypeManager.uint32_type))
return null;
Decimal d = (Decimal) c.GetValue ();
int [] bits = Decimal.GetBits (d);
object [] args = new object [] {
(byte) (bits [3] >> 16),
(byte) (bits [3] >> 31),
(uint) bits [2], (uint) bits [1], (uint) bits [0]
};
return new CustomAttributeBuilder (pa.Constructor, args);
}
示例6: ConvertInitializer
public override Constant ConvertInitializer (ResolveContext rc, Constant expr)
{
if (expr is EnumConstant)
expr = ((EnumConstant) expr).Child;
var underlying = ((Enum) Parent).UnderlyingType;
if (expr != null) {
expr = expr.ImplicitConversionRequired (rc, underlying, Location);
if (expr != null && !IsValidEnumType (expr.Type)) {
Enum.Error_1008 (Location, Report);
expr = null;
}
}
if (expr == null)
expr = New.Constantify (underlying, Location);
return new EnumConstant (expr, MemberType);
}
示例7: 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;
}
示例8: CheckUselessComparison
private void CheckUselessComparison (ResolveContext ec, Constant c, Type type)
{
if (c == null || !IsTypeIntegral (type)
|| c is StringConstant
|| c is BoolConstant
|| c is FloatConstant
|| c is DoubleConstant
|| c is DecimalConstant
)
return;
long value = 0;
if (c is ULongConstant) {
ulong uvalue = ((ULongConstant) c).Value;
if (uvalue > long.MaxValue) {
if (type == TypeManager.byte_type ||
type == TypeManager.sbyte_type ||
type == TypeManager.short_type ||
type == TypeManager.ushort_type ||
type == TypeManager.int32_type ||
type == TypeManager.uint32_type ||
type == TypeManager.int64_type ||
type == TypeManager.char_type)
WarnUselessComparison (ec, type);
return;
}
value = (long) uvalue;
}
else if (c is ByteConstant)
value = ((ByteConstant) c).Value;
else if (c is SByteConstant)
value = ((SByteConstant) c).Value;
else if (c is ShortConstant)
value = ((ShortConstant) c).Value;
else if (c is UShortConstant)
value = ((UShortConstant) c).Value;
else if (c is IntConstant)
value = ((IntConstant) c).Value;
else if (c is UIntConstant)
value = ((UIntConstant) c).Value;
else if (c is LongConstant)
value = ((LongConstant) c).Value;
else if (c is CharConstant)
value = ((CharConstant)c).Value;
if (value == 0)
return;
if (IsValueOutOfRange (value, type))
WarnUselessComparison (ec, type);
}
示例9: EnumConstant
public EnumConstant(Constant child, TypeSpec enum_type)
: base(child.Location)
{
this.Child = child;
this.type = enum_type;
}
示例10: Visit
public override object Visit (Constant constant)
{
if (constant.GetValue () == null)
return new NullReferenceExpression (Convert (constant.Location));
string literalValue;
if (constant is ILiteralConstant) {
literalValue = new string (((ILiteralConstant)constant).ParsedValue);
} else {
literalValue = constant.GetValueAsLiteral ();
}
var result = new PrimitiveExpression (constant.GetValue (), Convert (constant.Location), literalValue);
return result;
}
示例11: Visit
public virtual object Visit (Constant constant)
{
return null;
}
示例12: ConvertInitializer
public override Constant ConvertInitializer (ResolveContext rc, Constant expr)
{
return expr.ImplicitConversionRequired (rc, rc.BuiltinTypes.Int, Location);
}
示例13: Visit
public override object Visit (Constant constant)
{
if (constant.GetValue () == null)
return new NullReferenceExpression (Convert (constant.Location));
var result = new PrimitiveExpression (constant.GetValue (), Convert (constant.Location), constant.GetValueAsLiteral ().Length);
return result;
}
示例14: Visit
public override object Visit(Constant constant)
{
if (constant.GetValue() == null)
return new NullReferenceExpression(Convert(constant.Location));
string literalValue;
var literalConstant = constant as ILiteralConstant;
literalValue = literalConstant != null ? new string(literalConstant.ParsedValue) : constant.GetValueAsLiteral();
object val = constant.GetValue();
if (val is bool)
literalValue = (bool)val ? "true" : "false";
var result = new PrimitiveExpression(val, Convert(constant.Location), literalValue);
return result;
}
示例15: Visit
public override object Visit (Constant constant)
{
var result = new PrimitiveExpression (constant.GetValue (), Convert (constant.Location), constant.AsString ().Length);
return result;
}