Example #1
0
        public static void WriteOperand(ITextOutput writer, object operand)
        {
            if (operand == null)
            {
                throw new ArgumentNullException(nameof(operand));
            }

            Instruction targetInstruction = operand as Instruction;

            if (targetInstruction != null)
            {
                WriteOffsetReference(writer, targetInstruction);
                return;
            }

            Instruction[] targetInstructions = operand as Instruction[];
            if (targetInstructions != null)
            {
                WriteLabelList(writer, targetInstructions);
                return;
            }

            VariableReference variableRef = operand as VariableReference;

            if (variableRef != null)
            {
                writer.WriteReference(variableRef.Index.ToString(), variableRef);
                return;
            }

            ParameterReference paramRef = operand as ParameterReference;

            if (paramRef != null)
            {
                if (string.IsNullOrEmpty(paramRef.Name))
                {
                    writer.WriteReference(paramRef.Index.ToString(), paramRef);
                }
                else
                {
                    writer.WriteReference(Escape(paramRef.Name), paramRef);
                }
                return;
            }

            MethodReference methodRef = operand as MethodReference;

            if (methodRef != null)
            {
                methodRef.WriteTo(writer);
                return;
            }

            TypeReference typeRef = operand as TypeReference;

            if (typeRef != null)
            {
                typeRef.WriteTo(writer, ILNameSyntax.TypeName);
                return;
            }

            FieldReference fieldRef = operand as FieldReference;

            if (fieldRef != null)
            {
                fieldRef.WriteTo(writer);
                return;
            }

            string s = operand as string;

            if (s != null)
            {
                WriteOperand(writer, s);
            }
            else if (operand is char)
            {
                writer.Write(((int)(char)operand).ToString());
            }
            else if (operand is float)
            {
                WriteOperand(writer, (float)operand);
            }
            else if (operand is double)
            {
                WriteOperand(writer, (double)operand);
            }
            else if (operand is bool)
            {
                writer.Write((bool)operand ? "true" : "false");
            }
            else
            {
                s = ToInvariantCultureString(operand);
                writer.Write(s);
            }
        }
Example #2
0
        public static void WriteOperand(ITextOutput writer, object operand)
        {
            if (operand == null)
            {
                throw new ArgumentNullException("operand");
            }

            Instruction targetInstruction = operand as Instruction;

            if (targetInstruction != null)
            {
                WriteOffsetReference(writer, targetInstruction);
                return;
            }

            Instruction[] targetInstructions = operand as Instruction[];
            if (targetInstructions != null)
            {
                WriteLabelList(writer, targetInstructions);
                return;
            }

            VariableReference variableRef = operand as VariableReference;

            if (variableRef != null)
            {
                if (string.IsNullOrEmpty(variableRef.Name))
                {
                    writer.WriteReference(variableRef.Index.ToString(), variableRef);
                }
                else
                {
                    writer.WriteReference(Escape(variableRef.Name), variableRef);
                }
                return;
            }

            ParameterReference paramRef = operand as ParameterReference;

            if (paramRef != null)
            {
                if (string.IsNullOrEmpty(paramRef.Name))
                {
                    writer.WriteReference(paramRef.Index.ToString(), paramRef);
                }
                else
                {
                    writer.WriteReference(Escape(paramRef.Name), paramRef);
                }
                return;
            }

            MethodReference methodRef = operand as MethodReference;

            if (methodRef != null)
            {
                methodRef.WriteTo(writer);
                return;
            }

            TypeReference typeRef = operand as TypeReference;

            if (typeRef != null)
            {
                typeRef.WriteTo(writer, ILNameSyntax.TypeName);
                return;
            }

            FieldReference fieldRef = operand as FieldReference;

            if (fieldRef != null)
            {
                fieldRef.WriteTo(writer);
                return;
            }

            string s = operand as string;

            if (s != null)
            {
                writer.Write("\"" + ICSharpCode.NRefactory.CSharp.CSharpOutputVisitor.ConvertString(s) + "\"");
            }
            else if (operand is char)
            {
                writer.Write(((int)(char)operand).ToString());
            }
            else if (operand is float)
            {
                float val = (float)operand;
                if (val == 0)
                {
                    if (1 / val == float.NegativeInfinity)
                    {
                        // negative zero is a special case
                        writer.Write('-');
                    }
                    writer.Write("0.0");
                }
                else if (float.IsInfinity(val) || float.IsNaN(val))
                {
                    byte[] data = BitConverter.GetBytes(val);
                    writer.Write('(');
                    for (int i = 0; i < data.Length; i++)
                    {
                        if (i > 0)
                        {
                            writer.Write(' ');
                        }
                        writer.Write(data[i].ToString("X2"));
                    }
                    writer.Write(')');
                }
                else
                {
                    writer.Write(val.ToString("R", System.Globalization.CultureInfo.InvariantCulture));
                }
            }
            else if (operand is double)
            {
                double val = (double)operand;
                if (val == 0)
                {
                    if (1 / val == double.NegativeInfinity)
                    {
                        // negative zero is a special case
                        writer.Write('-');
                    }
                    writer.Write("0.0");
                }
                else if (double.IsInfinity(val) || double.IsNaN(val))
                {
                    byte[] data = BitConverter.GetBytes(val);
                    writer.Write('(');
                    for (int i = 0; i < data.Length; i++)
                    {
                        if (i > 0)
                        {
                            writer.Write(' ');
                        }
                        writer.Write(data[i].ToString("X2"));
                    }
                    writer.Write(')');
                }
                else
                {
                    writer.Write(val.ToString("R", System.Globalization.CultureInfo.InvariantCulture));
                }
            }
            else if (operand is bool)
            {
                writer.Write((bool)operand ? "true" : "false");
            }
            else
            {
                s = ToInvariantCultureString(operand);
                writer.Write(s);
            }
        }
Example #3
0
 protected override string GetArgumentName(ParameterReference parameter)
 {
     return(parameter.Name);
 }
Example #4
0
		public HoistedParameter (AnonymousMethodStorey scope, ParameterReference par)
			: base (scope, par.Name, par.Type)
		{
			this.parameter = par;
		}
 void PushArgumentReference(ParameterReference parameter)
 {
     Push(new ArgumentReferenceExpression(parameter));
 }
Example #6
0
 public static JSVariable New(ParameterReference parameter, MethodReference function)
 {
     return(new JSParameter(parameter.Name, parameter.ParameterType, function));
 }
        private void OpCodeToInputType(Instruction instr, bool readOperand)
        {
            #region Read PickOperandType
            switch (instr.OpCode.OperandType)
            {
            case OperandType.InlineArg:
            case OperandType.ShortInlineArg:
                currentPOT = PickOperandType.ParameterReference;
                break;

            case OperandType.InlineBrTarget:
            case OperandType.ShortInlineBrTarget:
                currentPOT = PickOperandType.InstructionReference;
                break;

            case OperandType.InlineField:
                currentPOT = PickOperandType.FieldReference;
                break;

            case OperandType.InlineI:
                currentPOT = PickOperandType.Int32;
                break;

            case OperandType.InlineI8:
                currentPOT = PickOperandType.Int64;
                break;

            case OperandType.InlineMethod:
                currentPOT = PickOperandType.MethodReference;
                break;

            case OperandType.InlineNone:
                currentPOT = PickOperandType.None;
                break;

            case OperandType.InlineR:
                currentPOT = PickOperandType.Double;
                break;

            case OperandType.InlineString:
                currentPOT = PickOperandType.String;
                break;

            case OperandType.InlineSwitch:
                currentPOT = PickOperandType.InstructionArrReference;
                break;

            case OperandType.InlineTok:
                currentPOT = PickOperandType.TMFReferenceDynamic;
                break;

            case OperandType.InlineType:
                currentPOT = PickOperandType.TypeReference;
                break;

            case OperandType.InlineVar:
            case OperandType.ShortInlineVar:
                currentPOT = PickOperandType.VariableReference;
                break;

            case OperandType.ShortInlineI:
                if (instr.OpCode == OpCodes.Ldc_I4_S)
                {
                    currentPOT = PickOperandType.SByte;
                }
                else
                {
                    currentPOT = PickOperandType.Byte;
                }
                break;

            case OperandType.ShortInlineR:
                currentPOT = PickOperandType.Single;
                break;

            case OperandType.InlinePhi:
            case OperandType.InlineSig:
            default:
                Log.Write(Log.Level.Warning, $"OperandType \"{instr.OpCode.Name}\" is not processed");
                break;
            }
            #endregion

            #region Show the corresponding control
            foreach (Control c in OperandCList)
            {
                c.Visible = false;
            }
            switch (currentPOT)
            {
            case PickOperandType.Byte:
            case PickOperandType.SByte:
            case PickOperandType.Int32:
            case PickOperandType.Int64:
            case PickOperandType.Single:
            case PickOperandType.Double:
            case PickOperandType.String:
                if (readOperand)
                {
                    txtOperand.Text = instr.Operand.ToString();
                }
                txtOperand.Visible = true;
                break;

            case PickOperandType.InstructionReference:
                InitCbxOperand();
                if (readOperand)
                {
                    Instruction pr = instr.Operand as Instruction;
                    if (pr != null)
                    {
                        cbxOperand.SelectedIndex = mInstructBox.Items.FindIndex(x => ((InstructionInfo)x).NewInstruction == pr);
                    }
                }
                cbxOperand.Visible = true;
                break;

            case PickOperandType.InstructionArrReference:
                lblTMFPicker.Text    = "<Instruction Array>";
                panTMFPicker.Visible = true;
                break;

            case PickOperandType.VariableReference:
                InitCbxOperand();
                if (readOperand)
                {
                    ParameterReference pr = instr.Operand as ParameterReference;
                    if (pr != null)
                    {
                        cbxOperand.SelectedIndex = pr.Index;
                    }
                }
                cbxOperand.Visible = true;
                break;

            case PickOperandType.ParameterReference:
                InitCbxOperand();
                if (readOperand)
                {
                    VariableReference vr = instr.Operand as VariableReference;
                    if (vr != null)
                    {
                        cbxOperand.SelectedIndex = vr.Index;
                    }
                }
                cbxOperand.Visible = true;
                break;

            case PickOperandType.None:
            case PickOperandType.FieldReference:
            case PickOperandType.MethodReference:
            case PickOperandType.TypeReference:
            case PickOperandType.TMFReferenceDynamic:
                if (readOperand)
                {
                    lblTMFPicker.Text = CecilFormatter.TryFormat(instr.Operand);
                }

                btnTMFPicker.Text    = currentPOT == PickOperandType.None ? "Clear" : "Pick";
                panTMFPicker.Visible = true;
                break;

            default:
                Log.Write(Log.Level.Warning, $"PickOperadType \"{currentPOT}\" is not processed");
                break;
            }
            #endregion

            lblOperandType.Text = currentPOT.ToString();             // TODO: read from dict
            MakeItemAvailable();
            Controls_Reorganize();
        }
Example #8
0
        InlineExpansion(MethodInvocationExpression mInvoke, Expression target, AstMethodDefinition source)
        {
            ILtoASTTransformer  il2astTransformer = new ILtoASTTransformer();
            AstMethodDefinition ast;

            AstPreInsertFixer preFixer = new AstPreInsertFixer();

            MethodReferenceExpression mRef = mInvoke.Method as MethodReferenceExpression;

            MethodDefinition mDef = mRef.Method.Resolve();
            var result            = new CodeNodeCollection <Statement> ();
            ParameterDefinition paramDef;
            Expression          arg;

            ReturnVariable  = null;
            ReturnParameter = null;
            if (target == null)
            {
                //Mono.Cecil 0.9.3 migration: if (mDef.ReturnType.ReturnType.FullName != "System.Void") {
                //Mono.Cecil 0.9.3 migration:   ReturnVariable = RegisterVariable(mDef.ReturnType.ReturnType, source.Method);
                if (mDef.ReturnType.FullName != "System.Void")
                {
                    ReturnVariable = RegisterVariable(mDef.ReturnType, source.Method);
                }
            }
            else if (target is VariableReferenceExpression)
            {
                ReturnVariable = (target as VariableReferenceExpression).Variable;
            }
            else if (target is VariableDeclarationExpression)
            {
                //Mono.Cecil 0.9.3 migration: ReturnVariable = RegisterVariable(mDef.ReturnType.ReturnType, source.Method);
                ReturnVariable = RegisterVariable(mDef.ReturnType, source.Method);
            }
            else if (target is ArgumentReferenceExpression)
            {
                ReturnParameter = (target as ArgumentReferenceExpression).Parameter;
            }

            //заместване на this

            if (mRef.Target != null)
            {
                thisSubstitution = new VariableReferenceExpression(
                    //Mono.Cecil 0.9.3 migration: RegisterVariable(mDef.This.ParameterType, source.Method));
                    //new ParameterDefinition ("this", (ParameterAttributes) 0, null);
                    RegisterVariable(null, source.Method));
            }
            else
            {
                thisSubstitution = null;
            }

            for (int current = mInvoke.Arguments.Count - 1; current >= 0; current--)
            {
                arg      = mInvoke.Arguments[current];
                paramDef = mRef.Method.Parameters[current];
                paramVarSubstitution[paramDef] = arg;
            }

            //Ако вече е inline-вано
            if (mDef.Body.Variables.Count != 0 && (!localVarSubstitution.ContainsKey(mDef.Body.Variables[0])))
            {
                foreach (VariableDefinition variable in mDef.Body.Variables)
                {
                    localVarSubstitution[variable] = RegisterVariable(variable.VariableType, source.Method);
                }
            }

//      foreach (KeyValuePair<VariableDefinition, VariableDefinition> pair in localVarSubstitution) {
//        Console.WriteLine("!!! {0} -> {1}", pair.Key.Name, pair.Value.Name);
//      }

            ast = preFixer.FixUp(il2astTransformer.Decompile(mDef), paramVarSubstitution, thisSubstitution);


            //this
            if (thisSubstitution != null)
            {
                result.Add(new ExpressionStatement(new AssignExpression(thisSubstitution, mRef.Target)));
            }

            for (int i = 0; i < ast.Block.Statements.Count; i++)
            {
                result.Add(ast.CecilBlock.Statements[i]);
            }

            return(result);
        }
Example #9
0
 public static bool UsesParameter(this MethodReference method, ParameterReference parameter) => UsesParameter(method, parameter.Index);
Example #10
0
 public ArgumentReferenceExpression(ParameterReference parameter)
 {
     this.parameter = parameter;
 }
Example #11
0
 public TypeReference ResolveParameterType(MethodReference method, ParameterReference parameter)
 {
     return(Resolve(GenericParameterResolver.ResolveParameterTypeIfNeeded(method, parameter)));
 }
Example #12
0
        private static ReachabilityAnnotation?BuildReachabilityAnnotation(IInvocableDeclarationSyntax invocable)
        {
            var parameters = invocable.Parameters.Select((p, i) => new { Param = p, Index = i })
                             .Where(x => x.Param is INamedParameterSyntax)
                             .ToDictionary(x => ((INamedParameterSyntax)x.Param).Name, x => ParameterReference.Create(x.Index));

            ReachabilityAnnotation?annotation = null;

            var canReach = ToReferences(invocable.ReachabilityAnnotations.CanReachAnnotation, parameters);

            if (canReach.Count != 0)
            {
                var refs = new ReachableReferences(canReach);
                annotation = new ReachabilityAnnotation(ReturnReference.Instance, refs);
            }

            var reachableFrom = ToReferences(invocable.ReachabilityAnnotations.ReachableFromAnnotation, parameters);

            if (reachableFrom.Count != 0)
            {
                var chain = (ReachabilityChain?)annotation ?? new ReachableReferences(ReturnReference.Instance);
                annotation = new ReachabilityAnnotation(reachableFrom, chain);
            }

            return(annotation);
        }
Example #13
0
 /// <summary>
 /// A cecil parameter reference will be directed to this method.
 /// </summary>
 /// <param name="item">Cecil reference.</param>
 /// <param name="resolvedItem">Output parameter that will be populated with the resolved cecil definition.</param>
 /// <returns><c>true</c></returns>
 private static bool TryResolve(ParameterReference item, out object resolvedItem)
 {
     resolvedItem = item.Resolve();
     return(true);
 }
Example #14
0
        public ParameterContext(CilWorker worker, TypeReference interfaceType, MethodReference currentMethod, VariableDefinition currentArguments, VariableDefinition currentArgument, TypeReference targetDependency, MethodDefinition adapterConstructor, ParameterReference param)
        {
            CilWorker        = worker;
            CurrentArguments = currentArguments;
            CurrentArgument  = currentArgument;
            TargetDependency = targetDependency;

            Parameter          = param;
            InterfaceType      = interfaceType;
            AdapterConstructor = adapterConstructor;
            CurrentMethod      = currentMethod;
        }
Example #15
0
 public ArgumentReferenceExpression(ParameterReference parameter, IEnumerable <Instruction> instructions)
     : base(instructions)
 {
     this.Parameter = parameter;
 }
Example #16
0
 public StoreParameterStatement(ParameterReference parameter, Expression value)
     : this(parameter, value, instruction : null)
 {
 }
Example #17
0
 public virtual void VisitParameterReference(ParameterReference parameterReference)
 {
     DefaultVisit(parameterReference);
 }
Example #18
0
 public StoreParameterStatement(ParameterReference parameter, Expression value, Instruction instruction) : base(instruction)
 {
     Parameter = parameter;
     Value     = value;
 }
Example #19
0
 private string FormatParameterReference(ParameterReference comment)
 {
     return("<var>" + comment.Parameter + "</var>");
 }
        internal static TypeReference ResolveParameterTypeIfNeeded(MethodReference method, ParameterReference parameter)
        {
            GenericInstanceMethod genericInstanceMethod = method as GenericInstanceMethod;
            GenericInstanceType   declaringType         = method.DeclaringType as GenericInstanceType;

            if ((genericInstanceMethod == null) && (declaringType == null))
            {
                return(parameter.ParameterType);
            }
            return(ResolveIfNeeded(genericInstanceMethod, declaringType, parameter.ParameterType));
        }
Example #21
0
		public void CaptureParameter (ResolveContext ec, ParametersBlock.ParameterInfo parameterInfo, ParameterReference parameterReference)
		{
			if (!(this is StateMachine)) {
				ec.CurrentBlock.Explicit.HasCapturedVariable = true;
			}

			var hoisted = parameterInfo.Parameter.HoistedVariant;

			if (parameterInfo.Block.StateMachine != null) {
				//
				// Another storey in same block exists but state machine does not
				// have parameter captured. We need to add it there as well to
				// proxy parameter value correctly.
				//
				if (hoisted == null && parameterInfo.Block.StateMachine != this) {
					var storey = parameterInfo.Block.StateMachine;

					hoisted = new HoistedParameter (storey, parameterReference);
					parameterInfo.Parameter.HoistedVariant = hoisted;

					if (storey.hoisted_params == null)
						storey.hoisted_params = new List<HoistedParameter> ();

					storey.hoisted_params.Add (hoisted);
				}

				//
				// Lift captured parameter from value type storey to reference type one. Otherwise
				// any side effects would be done on a copy
				//
				if (hoisted != null && hoisted.Storey != this && hoisted.Storey is StateMachine) {
					if (hoisted_local_params == null)
						hoisted_local_params = new List<HoistedParameter> ();

					hoisted_local_params.Add (hoisted);
					hoisted = null;
				}
			}

			if (hoisted == null) {
				hoisted = new HoistedParameter (this, parameterReference);
				parameterInfo.Parameter.HoistedVariant = hoisted;

				if (hoisted_params == null)
					hoisted_params = new List<HoistedParameter> ();

				hoisted_params.Add (hoisted);
			}

			//
			// Register link between current block and parameter storey. It will
			// be used when setting up storey definition to deploy storey reference
			// when parameters are used from multiple blocks
			//
			if (ec.CurrentBlock.Explicit != parameterInfo.Block) {
				hoisted.Storey.AddReferenceFromChildrenBlock (ec.CurrentBlock.Explicit);
			}
		}
        private void UpdateParameterLeastType(ParameterReference parameter, IEnumerable <StackEntryUsageResult> usageResults)
        {
            int pIndex         = parameter.Index;
            int parameterDepth = GetActualTypeDepth(parameter.ParameterType);

            int                    currentLeastDepth = 0;
            TypeReference          currentLeastType  = null;
            List <MethodSignature> signatures        = null;

            //update the result array as in if (needUpdate) block below
            foreach (var usage in usageResults)
            {
                bool needUpdate = false;

                switch (usage.Instruction.OpCode.Code)
                {
                case Code.Newobj:
                case Code.Call:
                case Code.Callvirt:
                    MethodReference method = (MethodReference)usage.Instruction.Operand;

                    //potential generalization to object does not really make sense
                    //from a readability/maintainability point of view
                    if (IsSystemObjectMethod(method))
                    {
                        continue;
                    }
                    //we cannot really know if suggestion would work since the collection
                    //is non-generic thus we ignore it
                    TypeReference type = method.DeclaringType;
                    if (IsFromNonGenericCollectionNamespace(type.Namespace))
                    {
                        continue;
                    }

                    int pcount = method.HasParameters ? method.Parameters.Count : 0;
                    if (usage.StackOffset == pcount)
                    {
                        //argument is used as `this` in the call
                        if (signatures == null)
                        {
                            signatures = GetSignatures(usageResults);
                        }
                        currentLeastType = GetBaseImplementor(GetActualType(type), signatures);
                    }
                    else
                    {
                        //argument is also used as an argument in the call
                        currentLeastType = method.Parameters [pcount - usage.StackOffset - 1].ParameterType;

                        //if parameter type is a generic, find the 'real' constructed type
                        GenericParameter gp = (currentLeastType as GenericParameter);
                        if (gp != null)
                        {
                            currentLeastType = GetConstructedGenericType(method, gp);
                        }
                    }

                    //if the best we could find is object or non-generic collection, ignore this round
                    if (currentLeastType == null || IsIgnoredSuggestionType(currentLeastType))
                    {
                        continue;
                    }

                    needUpdate = true;
                    break;

                case Code.Stfld:
                case Code.Stsfld:
                    FieldReference field = (FieldReference)usage.Instruction.Operand;
                    currentLeastType = field.FieldType;

                    needUpdate = true;
                    break;
                }

                if (needUpdate)
                {
                    currentLeastDepth = GetActualTypeDepth(currentLeastType);
                    if (null == types_least [pIndex] || currentLeastDepth > depths_least [pIndex])
                    {
                        types_least [pIndex]  = currentLeastType;
                        depths_least [pIndex] = currentLeastDepth;
                    }
                    if (currentLeastDepth == parameterDepth)                     //no need to check further
                    {
                        return;
                    }
                }
            }
        }
Example #23
0
		public HoistedParameter (HoistedParameter hp, string name)
			: base (hp.storey, name, hp.parameter.Type)
		{
			this.parameter = hp.parameter;
		}
Example #24
0
 public SsaVariable GetOriginalVariable(ParameterReference parameter)
 {
     if (methodHasThis)
         return parameters[parameter.Index + 1];
     else
         return parameters[parameter.Index];
 }
        void ImportLegacy(ParameterConditionLegacy legacy)
        {
            ParameterReference parameterReference = legacy._Reference;
            Parameter          parameter          = parameterReference.parameter;

            Parameter.Type parameterType = parameter != null ? parameter.type : legacy._ParameterType;

            var condition = new ParameterCondition();

            condition._Reference     = legacy._Reference;
            condition._ParameterType = parameterType;
            condition._ReferenceType = legacy._ReferenceType;
            condition._CompareType   = legacy._CompareType;

            switch (parameterType)
            {
            case Parameter.Type.Int:
                _IntParameters.Add(legacy._IntValue);
                condition._ParameterIndex = _IntParameters.Count - 1;
                break;

            case Parameter.Type.Long:
                _LongParameters.Add(legacy._LongValue);
                condition._ParameterIndex = _LongParameters.Count - 1;
                break;

            case Parameter.Type.Float:
                _FloatParameters.Add(legacy._FloatValue);
                condition._ParameterIndex = _FloatParameters.Count - 1;
                break;

            case Parameter.Type.Bool:
                _BoolParameters.Add(legacy._BoolValue);
                condition._ParameterIndex = _BoolParameters.Count - 1;
                break;

            case Parameter.Type.String:
                _StringParameters.Add(legacy._StringValue);
                condition._ParameterIndex = _StringParameters.Count - 1;
                break;

            case Parameter.Type.Enum:
                _EnumParameters.Add(legacy._EnumValue);
                condition._ParameterIndex = _EnumParameters.Count - 1;
                break;

            case Parameter.Type.GameObject:
                _GameObjectParameters.Add(legacy._GameObjectValue);
                condition._ParameterIndex = _GameObjectParameters.Count - 1;
                break;

            case Parameter.Type.Vector2:
                _Vector2Parameters.Add(legacy._Vector2Value);
                condition._ParameterIndex = _Vector2Parameters.Count - 1;
                break;

            case Parameter.Type.Vector3:
                _Vector3Parameters.Add(legacy._Vector3Value);
                condition._ParameterIndex = _Vector3Parameters.Count - 1;
                break;

            case Parameter.Type.Quaternion:
                _QuaternionParameters.Add(legacy._QuaternionValue);
                condition._ParameterIndex = _QuaternionParameters.Count - 1;
                break;

            case Parameter.Type.Rect:
                _RectParameters.Add(legacy._RectValue);
                condition._ParameterIndex = _RectParameters.Count - 1;
                break;

            case Parameter.Type.Bounds:
                _BoundsParameters.Add(legacy._BoundsValue);
                condition._ParameterIndex = _BoundsParameters.Count - 1;
                break;

            case Parameter.Type.Color:
                _ColorParameters.Add(legacy._ColorValue);
                condition._ParameterIndex = _ColorParameters.Count - 1;
                break;

            case Parameter.Type.Transform:
                _ComponentParameters.Add(legacy._TransformValue.ToFlexibleComponent());
                condition._ParameterIndex = _ComponentParameters.Count - 1;
                break;

            case Parameter.Type.RectTransform:
                _ComponentParameters.Add(legacy._RectTransformValue.ToFlexibleComponent());
                condition._ParameterIndex = _ComponentParameters.Count - 1;
                break;

            case Parameter.Type.Rigidbody:
                _ComponentParameters.Add(legacy._RigidbodyValue.ToFlexibleComponent());
                condition._ParameterIndex = _ComponentParameters.Count - 1;
                break;

            case Parameter.Type.Rigidbody2D:
                _ComponentParameters.Add(legacy._Rigidbody2DValue.ToFlexibleComponent());
                condition._ParameterIndex = _ComponentParameters.Count - 1;
                break;

            case Parameter.Type.Component:
                _ComponentParameters.Add(legacy._ComponentValue);
                condition._ParameterIndex = _ComponentParameters.Count - 1;
                break;

            case Parameter.Type.Variable:
                break;
            }

            condition.owner = this;

            _Conditions.Add(condition);
        }
Example #26
0
        private StackState Build(IEnumerable <Instruction> instructions)
        {
            StackState state = new StackState();

            foreach (Instruction instruction in instructions)
            {
                this.SetupCatchBlockIfNeeded(instruction);
                switch (instruction.OpCode.Code)
                {
                case Code.Ldarg_0:
                    this.LoadArg(0);
                    break;

                case Code.Ldarg_1:
                    this.LoadArg(1);
                    break;

                case Code.Ldarg_2:
                    this.LoadArg(2);
                    break;

                case Code.Ldarg_3:
                    this.LoadArg(3);
                    break;

                case Code.Ldloc_0:
                    this.LoadLocal(0);
                    break;

                case Code.Ldloc_1:
                    this.LoadLocal(1);
                    break;

                case Code.Ldloc_2:
                    this.LoadLocal(2);
                    break;

                case Code.Ldloc_3:
                    this.LoadLocal(3);
                    break;

                case Code.Stloc_0:
                    this.PopEntry();
                    break;

                case Code.Stloc_1:
                    this.PopEntry();
                    break;

                case Code.Stloc_2:
                    this.PopEntry();
                    break;

                case Code.Stloc_3:
                    this.PopEntry();
                    break;

                case Code.Ldarg_S:
                {
                    ParameterReference operand = (ParameterReference)instruction.Operand;
                    int index = operand.Index;
                    if (this._methodDefinition.HasThis)
                    {
                        index++;
                    }
                    this.LoadArg(index);
                    break;
                }

                case Code.Ldarga_S:
                    this.LoadArgumentAddress((ParameterReference)instruction.Operand);
                    break;

                case Code.Starg_S:
                    this.PopEntry();
                    break;

                case Code.Ldloc_S:
                    this.LoadLocal(((VariableReference)instruction.Operand).Index);
                    break;

                case Code.Ldloca_S:
                    this.LoadLocalAddress((VariableReference)instruction.Operand);
                    break;

                case Code.Stloc_S:
                    this.PopEntry();
                    break;

                case Code.Ldnull:
                    this.PushNullStackEntry();
                    break;

                case Code.Ldc_I4_M1:
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldc_I4_0:
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldc_I4_1:
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldc_I4_2:
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldc_I4_3:
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldc_I4_4:
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldc_I4_5:
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldc_I4_6:
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldc_I4_7:
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldc_I4_8:
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldc_I4_S:
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldc_I4:
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldc_I8:
                    this.PushStackEntry(this.Int64TypeReference);
                    break;

                case Code.Ldc_R4:
                    this.PushStackEntry(this.SingleTypeReference);
                    break;

                case Code.Ldc_R8:
                    this.PushStackEntry(this.DoubleTypeReference);
                    break;

                case Code.Dup:
                    this._simulationStack.Push(this._simulationStack.Peek().Clone());
                    break;

                case Code.Pop:
                    this.PopEntry();
                    break;

                case Code.Call:
                    this.CallMethod((MethodReference)instruction.Operand);
                    break;

                case Code.Calli:
                    this.CallInternalMethod((MethodReference)instruction.Operand);
                    break;

                case Code.Ret:
                    if (this.ReturnsValue())
                    {
                        this.PopEntry();
                    }
                    break;

                case Code.Brfalse_S:
                    this.PopEntry();
                    break;

                case Code.Brtrue_S:
                    this.PopEntry();
                    break;

                case Code.Beq_S:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Bge_S:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Bgt_S:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Ble_S:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Blt_S:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Bne_Un_S:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Bge_Un_S:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Bgt_Un_S:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Ble_Un_S:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Blt_Un_S:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Brfalse:
                    this.PopEntry();
                    break;

                case Code.Brtrue:
                    this.PopEntry();
                    break;

                case Code.Beq:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Bge:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Bgt:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Ble:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Blt:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Bne_Un:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Bge_Un:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Bgt_Un:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Ble_Un:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Blt_Un:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Switch:
                    this.PopEntry();
                    break;

                case Code.Ldind_I1:
                    this.PopEntry();
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldind_U1:
                    this.PopEntry();
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldind_I2:
                    this.PopEntry();
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldind_U2:
                    this.PopEntry();
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldind_I4:
                    this.PopEntry();
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldind_U4:
                    this.PopEntry();
                    this.PushStackEntry(this.Int32TypeReference);
                    break;

                case Code.Ldind_I8:
                    this.PopEntry();
                    this.PushStackEntry(this.Int64TypeReference);
                    break;

                case Code.Ldind_I:
                {
                    TypeReference elementType = this.PopEntry().Types.First <TypeReference>().GetElementType();
                    if (elementType.IsIntegralPointerType())
                    {
                        this.PushStackEntry(elementType);
                    }
                    else
                    {
                        this.PushStackEntry(this.NativeIntTypeReference);
                    }
                    break;
                }

                case Code.Ldind_R4:
                    this.PopEntry();
                    this.PushStackEntry(this.SingleTypeReference);
                    break;

                case Code.Ldind_R8:
                    this.PopEntry();
                    this.PushStackEntry(this.DoubleTypeReference);
                    break;

                case Code.Ldind_Ref:
                {
                    ByReferenceType type = (ByReferenceType)this.PopEntry().Types.First <TypeReference>();
                    this.PushStackEntry(type.ElementType);
                    break;
                }

                case Code.Stind_Ref:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Stind_I1:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Stind_I2:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Stind_I4:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Stind_I8:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Stind_R4:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Stind_R8:
                    this.PopEntry();
                    this.PopEntry();
                    break;

                case Code.Add:
                    if (< > f__mg$cache0 == null)
                    {
                        < > f__mg$cache0 = new StackAnalysisUtils.ResultTypeAnalysisMethod(StackAnalysisUtils.ResultTypeForAdd);
                    }
                    this._simulationStack.Push(this.GetResultEntryUsing(< > f__mg$cache0));
                    break;
 public static int GetSequence(this ParameterReference self)
 {
     return(self.Index + 1);
 }
Example #28
0
 public Value Push(ParameterReference parameterReference)
 {
     return(evaluationStack.Push(parameterReference));
 }
Example #29
0
 public void StoreByRef(ParameterReference par, Action <PointCut> val)
 {
     Load(par);
     val.Invoke(this);
     ByRef(par.ParameterType);
 }
 public ArgumentReferenceExpression(ParameterReference parameter, IEnumerable <Instruction> instructions)
 {
     base(instructions);
     this.set_Parameter(parameter);
     return;
 }
Example #31
0
 /// <summary>
 /// Builds a name for a parameter type that can be used for comparing parameters.  See
 /// <see cref="GetTypeName"/> for details.
 /// </summary>
 public static string GetParameterTypeName(ParameterReference param)
 {
     return(TypeNameCache.GetTypeName(param.ParameterType));
 }
Example #32
0
 /// <summary>
 /// An argument code.
 /// </summary>
 /// <param name="parameter">The parameter.</param>
 /// <returns></returns>
 public static Instruction Arg(ParameterReference parameter) => Instruction.Create(OpCodes.Ldarg, parameter.Resolve());
 private static bool IsBooMacroParameter(ParameterReference p)
 {
     return(p.Name == "macro" && p.ParameterType.IsNamed("Boo.Lang.Compiler.Ast", "MacroStatement"));
 }
 internal Type ResolveParameterType(ParameterReference parameterReference)
 {
     return(ResolveType(parameterReference.ParameterType));
 }