當前位置: 首頁>>代碼示例>>C#>>正文


C# CSharp.Constant類代碼示例

本文整理匯總了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;
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:17,代碼來源:cfold.cs

示例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;
		}
開發者ID:adisik,項目名稱:simple-assembly-explorer,代碼行數:17,代碼來源:cfold.cs

示例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;
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:24,代碼來源:cfold.cs

示例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;
		}
開發者ID:adisik,項目名稱:simple-assembly-explorer,代碼行數:27,代碼來源:cfold.cs

示例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);
        }
開發者ID:speier,項目名稱:shake,代碼行數:18,代碼來源:const.cs

示例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);
		}
開發者ID:nylen,項目名稱:SharpDevelop,代碼行數:19,代碼來源:enum.cs

示例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;
		}
開發者ID:edisontung,項目名稱:playscript-mono,代碼行數:31,代碼來源:cfold.cs

示例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);
		}
開發者ID:calumjiao,項目名稱:Mono-Class-Libraries,代碼行數:52,代碼來源:expression.cs

示例9: EnumConstant

 public EnumConstant(Constant child, TypeSpec enum_type)
     : base(child.Location)
 {
     this.Child = child;
     this.type = enum_type;
 }
開發者ID:speier,項目名稱:shake,代碼行數:6,代碼來源:ecore.cs

示例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;
			}
開發者ID:aleksandersumowski,項目名稱:monodevelop,代碼行數:13,代碼來源:CSharpParser.cs

示例11: Visit

		public virtual object Visit (Constant constant)
		{
			return null;
		}
開發者ID:KAW0,項目名稱:Alter-Native,代碼行數:4,代碼來源:visit.cs

示例12: ConvertInitializer

		public override Constant ConvertInitializer (ResolveContext rc, Constant expr)
		{
			return expr.ImplicitConversionRequired (rc, rc.BuiltinTypes.Int, Location);
		}
開發者ID:agallero,項目名稱:mono,代碼行數:4,代碼來源:field.cs

示例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;
			}
開發者ID:rmattuschka,項目名稱:ILSpy,代碼行數:7,代碼來源:CSharpParser.cs

示例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;
			}
開發者ID:0xb1dd1e,項目名稱:NRefactory,代碼行數:13,代碼來源:CSharpParser.cs

示例15: Visit

			public override object Visit (Constant constant)
			{
				var result = new PrimitiveExpression (constant.GetValue (), Convert (constant.Location), constant.AsString ().Length);
				return result;
			}
開發者ID:pgoron,項目名稱:monodevelop,代碼行數:5,代碼來源:CSharpParser.cs


注:本文中的Mono.CSharp.Constant類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。