Ejemplo n.º 1
0
        public VariableDefinition Acquire(TypeReference type)
        {
            Contract.Requires(type != null);
            Contract.Ensures(Contract.Result <VariableDefinition>() != null);

            if (temporaryVariables == null)
            {
                temporaryVariables = new List <TempVariable>();
            }

            for (int i = 0; i < temporaryVariables.Count; i++)
            {
                if (!temporaryVariables[i].isTaken)
                {
                    var tempVariableType = temporaryVariables[i].variable.VariableType;

                    if (tempVariableType.FullName == type.FullName && tempVariableType.Scope == type.Scope)
                    {
                        var result = temporaryVariables[i].variable;
                        temporaryVariables[i] = new TempVariable(result, true);
                        return(result);
                    }
                }
            }

            var variableName = "$Temp" + (temporaryVariables.Count + 1).ToString();
            var variable     = new VariableDefinition(variableName, type);

            temporaryVariables.Add(new TempVariable(variable, true));
            methodBody.Variables.Add(variable);
            assembly.AddTypeUsage(type);
            return(variable);
        }
Ejemplo n.º 2
0
        public void ReleaseAll()
        {
            if (temporaryVariables == null)
            {
                return;
            }

            for (int i = 0; i < temporaryVariables.Count; i++)
            {
                if (temporaryVariables[i].isTaken)
                {
                    temporaryVariables[i] = new TempVariable(temporaryVariables[i].variable, false);
                }
            }
        }
Ejemplo n.º 3
0
        public void Release(VariableDefinition variable)
        {
            Contract.Requires(variable != null);

            for (int i = 0; i < temporaryVariables.Count; i++)
            {
                if (temporaryVariables[i].variable == variable)
                {
                    temporaryVariables[i] = new TempVariable(variable, false);
                    return;
                }
            }

            ContractsHelper.AssertUnreachable("Invalid variable was passed to TemporaryVairables.Release().");
        }
Ejemplo n.º 4
0
 public override string Print(int depth)
 {
     return("for (" + TempVariable.Print(depth) + " in [" + Lower.Print(depth) + " .. " + Upper.Print(depth) + "])"
            + NewLine(depth + 1) + Body.Print(depth + 1));
 }