Пример #1
0
        private static Expression NegateBinaryExpression(Expression expression, TypeSystem typeSystem)
        {
            BinaryExpression binary = (BinaryExpression)expression;

            if (IsLogicalOperator(binary.Operator))
            {
                BinaryOperator @operator = binary.Operator == BinaryOperator.LogicalAnd ?
                    BinaryOperator.LogicalOr
                    : BinaryOperator.LogicalAnd;

                binary.Left = Negate(binary.Left, typeSystem);

                binary.Operator = @operator;

                binary.Right = Negate(binary.Right, typeSystem);

                return binary;
            }

            BinaryOperator op;
            if (TryGetInverseOperator(binary.Operator, out op))
            {
                binary.Operator = op;
            }
            return binary;
        }
Пример #2
0
 private static Expression NegateConditionExpression(Expression expression, TypeSystem typeSystem)
 {
     ConditionExpression condition = (ConditionExpression)expression;
     condition.Then = Negate(condition.Then, typeSystem);
     condition.Else = Negate(condition.Else, typeSystem);
     return condition;
 }
 public BlockStatement Process(DecompilationContext context, BlockStatement body)
 {
     this.context = context;
     this.typeSystem = context.MethodContext.Method.Module.TypeSystem;
     InsertTopLevelParameterAssignments(body);
     return body;
 }
Пример #4
0
        public static JSExpression FilterInvocationResult(
            MethodReference methodReference, MethodInfo method, 
            JSExpression result, 
            ITypeInfoSource typeInfo, TypeSystem typeSystem
        )
        {
            if (method == null)
                return result;

            var resultType = result.GetActualType(typeSystem);
            var resultIsPackedArray = PackedArrayUtil.IsPackedArrayType(resultType);
            var returnValueAttribute = method.Metadata.GetAttribute("JSIL.Meta.JSPackedArrayReturnValueAttribute");

            if (returnValueAttribute != null) {
                if (TypeUtil.IsOpenType(resultType)) {
                    // FIXME: We need to restrict substitution to when the result type is a generic parameter owned by the invocation...
                    resultType = JSExpression.SubstituteTypeArgs(typeInfo, resultType, methodReference);
                }

                if (!resultIsPackedArray)
                    return JSChangeTypeExpression.New(result, PackedArrayUtil.MakePackedArrayType(resultType, returnValueAttribute.Entries.First().Type), typeSystem);
            }

            return result;
        }
Пример #5
0
        public static JSExpression DeconstructMutationAssignment (
            JSNode parentNode, JSBinaryOperatorExpression boe, TypeSystem typeSystem, TypeReference intermediateType
        ) {
            var assignmentOperator = boe.Operator as JSAssignmentOperator;
            if (assignmentOperator == null)
                return null;

            JSBinaryOperator replacementOperator;
            if (!IntroduceEnumCasts.ReverseCompoundAssignments.TryGetValue(assignmentOperator, out replacementOperator))
                return null;

            var leftType = boe.Left.GetActualType(typeSystem);

            var newBoe = new JSBinaryOperatorExpression(
                JSOperator.Assignment, MakeLhsForAssignment(boe.Left),
                new JSBinaryOperatorExpression(
                    replacementOperator, boe.Left, boe.Right, intermediateType
                ),
                leftType
            );

            var result = ConvertReadExpressionToWriteExpression(newBoe, typeSystem);
            if (parentNode is JSExpressionStatement) {
                return result;
            } else {
                var comma = new JSCommaExpression(
                    newBoe, boe.Left
                );
                return comma;
            }
        }
Пример #6
0
        public static void CheckInvocationSafety(MethodInfo method, JSExpression[] argumentValues, TypeSystem typeSystem)
        {
            if (method.Metadata.HasAttribute("JSIL.Meta.JSAllowPackedArrayArgumentsAttribute"))
                return;

            TypeReference temp;
            string[] argumentNames = GetPackedArrayArgumentNames(method, out temp);

            for (var i = 0; i < method.Parameters.Length; i++) {
                if (i >= argumentValues.Length)
                    continue;

                var valueType = argumentValues[i].GetActualType(typeSystem);

                if (!IsPackedArrayType(valueType)) {
                    if ((argumentNames != null) && argumentNames.Contains(method.Parameters[i].Name))
                        throw new ArgumentException(
                            "Invalid attempt to pass a normal array as parameter '" + method.Parameters[i].Name + "' to method '" + method.Name + "'. " +
                            "This parameter must be a packed array."
                        );
                } else {
                    if ((argumentNames == null) || !argumentNames.Contains(method.Parameters[i].Name))
                        throw new ArgumentException(
                            "Invalid attempt to pass a packed array as parameter '" + method.Parameters[i].Name + "' to method '" + method.Name + "'. " +
                            "If this is intentional, annotate the method with the JSPackedArrayArguments attribute."
                        );
                }
            }
        }
 /// <summary>
 /// Swaps the then and else and negates the condition
 /// </summary>
 public void Negate(TypeSystem typeSystem)
 {
     this.Condition.Negate(typeSystem);
     BlockLogicalConstruct temp = this.Then;
     this.Then = this.Else;
     this.Else = temp;
 }
 public void Process()
 {
     typeSystem = TypeProcessor.ModuleWeaver.ModuleDefinition.TypeSystem;
     CreateDisposeBoolMethod();
     InjectIntoDispose();
     TypeProcessor.AddFinalizer(DisposeBoolMethod);
 }
Пример #9
0
 public ExpandCastExpressions (TypeSystem typeSystem, JSSpecialIdentifiers js, JSILIdentifier jsil, ITypeInfoSource typeInfo, MethodTypeFactory methodTypeFactory) {
     TypeSystem = typeSystem;
     JS = js;
     JSIL = jsil;
     TypeInfo = typeInfo;
     MethodTypeFactory = methodTypeFactory;
 }
		public BlockStatement Process(DecompilationContext context, BlockStatement body)
		{
			this.typeSystem = context.MethodContext.Method.Module.TypeSystem;
			this.decompiledMethodReturnType = context.MethodContext.Method.ReturnType;
			Visit(body);
			return body;
		}
 public BinaryExpression(BinaryOperator @operator, Expression left, Expression right,
     TypeReference expressionType, TypeSystem typeSystem, IEnumerable<Instruction> instructions, bool isOverridenOperation = false)
     : this(@operator, left, right, DetermineIsChecked(instructions), instructions, isOverridenOperation)
 {
     this.ExpressionType = expressionType;
     this.typeSystem = typeSystem;
 }
		public BlockStatement Process(DecompilationContext context, BlockStatement block)
		{
            this.typeSystem = context.MethodContext.Method.Module.TypeSystem;
			this.context = context;
            BlockStatement newBlock = (BlockStatement)VisitBlockStatement(block);
            return newBlock;
		}
Пример #13
0
 public PropertyWeaver(ModuleWeaver moduleWeaver, PropertyData propertyData, TypeNode typeNode, TypeSystem typeSystem )
 {
     this.moduleWeaver = moduleWeaver;
     this.propertyData = propertyData;
     this.typeNode = typeNode;
     this.typeSystem = typeSystem;
 }
Пример #14
0
 public ExpandCastExpressions(TypeSystem typeSystem, JSSpecialIdentifiers js, JSILIdentifier jsil, ITypeInfoSource typeInfo)
 {
     TypeSystem = typeSystem;
     JS = js;
     JSIL = jsil;
     TypeInfo = typeInfo;
 }
Пример #15
0
        public static bool ExtractOffsetFromPointerExpression(JSExpression pointer, TypeSystem typeSystem, out JSExpression newPointer, out JSExpression offset)
        {
            offset = null;
            newPointer = pointer;

            var boe = pointer as JSBinaryOperatorExpression;
            if (boe == null)
                return false;

            var leftType = boe.Left.GetActualType(typeSystem);
            var rightType = boe.Right.GetActualType(typeSystem);
            var resultType = boe.GetActualType(typeSystem);

            if (!resultType.IsPointer)
                return false;

            if (!TypeUtil.IsIntegral(rightType))
                return false;

            if (boe.Operator != JSOperator.Add)
                return false;

            newPointer = boe.Left;
            offset = boe.Right;
            return true;
        }
Пример #16
0
 public static TypeCode GetTypeCode(TypeSystem typeSystem, TypeReference type)
 {
     if (type == typeSystem.Boolean)
         return TypeCode.Boolean;
     else if (type == typeSystem.Byte)
         return TypeCode.Byte;
     else if (type == typeSystem.Char)
         return TypeCode.Char;
     else if (type == typeSystem.Double)
         return TypeCode.Double;
     else if (type == typeSystem.Int16)
         return TypeCode.Int16;
     else if (type == typeSystem.Int32)
         return TypeCode.Int32;
     else if (type == typeSystem.Int64)
         return TypeCode.Int64;
     else if (type == typeSystem.Single)
         return TypeCode.Single;
     else if (type == typeSystem.Double)
         return TypeCode.Double;
     else if (type == typeSystem.SByte)
         return TypeCode.SByte;
     else if (type == typeSystem.UInt16)
         return TypeCode.UInt16;
     else if (type == typeSystem.UInt32)
         return TypeCode.UInt32;
     else if (type == typeSystem.UInt64)
         return TypeCode.UInt64;
     else if (type == typeSystem.String)
         return TypeCode.String;
     else
         return TypeCode.Object;
 }
Пример #17
0
 public EmulateStructAssignment(TypeSystem typeSystem, IFunctionSource functionSource, CLRSpecialIdentifiers clr, bool optimizeCopies)
 {
     TypeSystem = typeSystem;
     FunctionSource = functionSource;
     CLR = clr;
     OptimizeCopies = optimizeCopies;
 }
Пример #18
0
		public BoxExpression(Expression boxedExpression, TypeSystem theTypeSystem, TypeReference boxedAsType, IEnumerable<Instruction> instructions)
            :base(instructions)
		{
			this.theTypeSystem = theTypeSystem;
			this.BoxedExpression = boxedExpression;
			this.BoxedAs = boxedAsType;
			this.IsAutoBox = false;
		}
Пример #19
0
        protected JSExpression FixupThisArgument(JSExpression thisArgument, TypeSystem typeSystem)
        {
            var expectedType = thisArgument.GetActualType(typeSystem);
            if (expectedType.FullName == "System.Type")
                return new JSPublicInterfaceOfExpression(thisArgument);

            return thisArgument;
        }
 public ImplementITrackableInjector(ModuleWeaver moduleWeaver, MsCoreReferenceFinder msCoreReferenceFinder,
                                    TypeSystem typeSystem, List <TypeDefinition> allPocoTypes)
 {
     this.moduleWeaver          = moduleWeaver;
     this.msCoreReferenceFinder = msCoreReferenceFinder;
     this.typeSystem            = typeSystem;
     this._allPocoTypes         = allPocoTypes;
 }
 public SynthesizePropertySetterReturnValues (
     TypeSystem typeSystem, ITypeInfoSource typeInfo,
     IFunctionSource functionSource
 ) {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
     FunctionSource = functionSource;
 }
		public BlockStatement Process(DecompilationContext context, BlockStatement body)
		{
			this.context = context;
            this.typeSystem = context.MethodContext.Method.Module.TypeSystem;
            this.patternsContext = new CodePatternsContext(body);
			body = (BlockStatement)Visit(body);
			return body;
		}
Пример #23
0
        public JSILIdentifier(TypeSystem typeSystem, JSSpecialIdentifiers js)
        {
            TypeSystem = typeSystem;
            JS = js;

            GlobalNamespace = Dot("GlobalNamespace", TypeSystem.Object);
            CopyMembers = Dot("CopyMembers", TypeSystem.Void);
        }
        public UsageBasedExpressionFixer(MethodSpecificContext methodContext)
        {
            this.methodContext = methodContext;
            TypeReference returnType = methodContext.Method.ReturnType;
			this.currentTypeSystem = methodContext.Method.Module.TypeSystem;
            this.isBoolReturnType = returnType.FullName == currentTypeSystem.Boolean.FullName;
            this.isCharReturnType = returnType.FullName == currentTypeSystem.Char.FullName;
        }
Пример #25
0
 public EmulateStructAssignment(QualifiedMemberIdentifier member, IFunctionSource functionSource, TypeSystem typeSystem, TypeInfoProvider typeInfo, CLRSpecialIdentifiers clr, bool optimizeCopies)
     : base(member, functionSource)
 {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
     CLR = clr;
     OptimizeCopies = optimizeCopies;
 }
Пример #26
0
 public FieldToPropertyConverter(ModuleWeaver moduleWeaver, MsCoreReferenceFinder msCoreReferenceFinder,
                                 TypeSystem typeSystem, List<TypeDefinition> allTypes)
 {
     this.moduleWeaver = moduleWeaver;
     this.msCoreReferenceFinder = msCoreReferenceFinder;
     this.typeSystem = typeSystem;
     this.allTypes = allTypes;
 }
 public OptimizePropertyMutationAssignments (
     TypeSystem typeSystem, ITypeInfoSource typeInfo,
     IFunctionSource functionSource
 ) {
     TypeSystem = typeSystem;
     TypeInfo = typeInfo;
     FunctionSource = functionSource;
 }
Пример #28
0
 public ReplaceMethodCalls (
     MethodReference method, JSILIdentifier jsil, JSSpecialIdentifiers js, TypeSystem typeSystem
 ) {
     Method = method;
     JSIL = jsil;
     JS = js;
     TypeSystem = typeSystem;
 }
Пример #29
0
 public EliminateSingleUseTemporaries (
     QualifiedMemberIdentifier member, IFunctionSource functionSource, 
     TypeSystem typeSystem, Dictionary<string, JSVariable> variables,
     ITypeInfoSource typeInfo
 ) : base (member, functionSource) {
     TypeSystem = typeSystem;
     Variables = variables;
     TypeInfo = typeInfo;
 }
        public BlockStatement Process(DecompilationContext context, BlockStatement body)
        {
            this.typeSystem = context.MethodContext.Method.Module.TypeSystem;

            Visit(body);
            CleanupRedundantAssignments();
            CleanupEmptyIfs(body);
            return body;
        }
Пример #31
0
 public UnsafeCodeTransforms (
     Configuration configuration,
     TypeSystem typeSystem, 
     MethodTypeFactory methodTypes
 ) {
     Configuration = configuration;
     TypeSystem = typeSystem;
     MethodTypes = methodTypes;
 }