Пример #1
0
 private static int ConvertToInt(Expression expression)
 {
     CompileTimeConstant/*?*/ cc = expression as CompileTimeConstant;
       if (cc == null) return 0; //TODO: error
       IConvertible/*?*/ ic = cc.Value as IConvertible;
       if (ic == null) return 0; //TODO: error
       switch (ic.GetTypeCode()) {
     case TypeCode.SByte:
     case TypeCode.Byte:
     case TypeCode.Int16:
     case TypeCode.UInt16:
     case TypeCode.Int32:
       return ic.ToInt32(null);
     case TypeCode.Int64:
       return (int)ic.ToInt64(null); //TODO: error
     case TypeCode.UInt32:
     case TypeCode.UInt64:
       return (int)ic.ToUInt64(null); //TODO: error
       }
       return 0; //TODO: error
 }
Пример #2
0
 private Expression ConvertToUnsigned(Expression expression)
 {
     CompileTimeConstant/*?*/ cc = expression as CompileTimeConstant;
       if (cc == null) return new ConvertToUnsigned(expression);
       IConvertible/*?*/ ic = cc.Value as IConvertible;
       if (ic == null) {
     if (cc.Value is System.IntPtr) {
       cc.Value = (System.UIntPtr)(ulong)(System.IntPtr)cc.Value;
       cc.Type = this.platformType.SystemUIntPtr;
       return cc;
     }
     return new ConvertToUnsigned(expression);
       }
       switch (ic.GetTypeCode()) {
     case TypeCode.SByte:
       cc.Value = (byte)ic.ToSByte(null); cc.Type = this.platformType.SystemUInt8; break;
     case TypeCode.Int16:
       cc.Value = (ushort)ic.ToInt16(null); cc.Type = this.platformType.SystemUInt16; break;
     case TypeCode.Int32:
       cc.Value = (uint)ic.ToInt32(null); cc.Type = this.platformType.SystemUInt32; break;
     case TypeCode.Int64:
       cc.Value = (ulong)ic.ToInt64(null); cc.Type = this.platformType.SystemUInt64; break;
       }
       return expression;
 }
Пример #3
0
    private static Expression ConvertToUnsigned2(Expression expression) {
      Contract.Requires(expression != null);
      Contract.Ensures(Contract.Result<Expression>() != null);

      var resultType = TypeHelper.UnsignedEquivalent(expression.Type);
      if (resultType != expression.Type)
        return new Conversion() { ValueToConvert = expression, TypeAfterConversion = resultType };
      return expression;
    }
Пример #4
0
 private void CopyChildren(Expression expression)
 {
     expression.Type = this.Copy(expression.Type);
       Contract.Assume(expression.Type is Microsoft.Cci.MutableCodeModel.NamedTypeDefinition || expression.Type is Microsoft.Cci.MutableCodeModel.TypeReference);
 }
Пример #5
0
 internal EndFilter(EndFilter endFilter)
   : base(endFilter) {
   Contract.Requires(endFilter != null);
   this.FilterResult = endFilter.FilterResult;
 }
Пример #6
0
 internal SinglePopReplacer(IMetadataHost host, Expression previouslyPushedExpression)
   : base(host) {
   Contract.Requires(previouslyPushedExpression != null);
   this.previouslyPushedExpression = previouslyPushedExpression;
 }
Пример #7
0
 /// <summary>
 /// Called from the type specific rewrite method to rewrite the common part of all expressions.
 /// </summary>
 public virtual void RewriteChildren(Expression expression)
 {
     expression.Type = this.Rewrite(expression.Type);
 }