Esempio n. 1
0
        /// <summary>
        /// Emit load of variable named <paramref name="varName"/>.
        /// </summary>
        internal static PhpTypeCode EmitLoad(CodeGenerator codeGenerator, VariableName varName)
        {
            ILEmitter il = codeGenerator.IL;            

            // Check if the variable is auto-global
            if (codeGenerator.VariableIsAutoGlobal(varName))
            {
                codeGenerator.EmitAutoGlobalLoad(varName);
                return PhpTypeCode.Object;
            }

            // Variable is local
            if (codeGenerator.OptimizedLocals)
            {
                // Template:
                //			ldloc loc
                //	***** // If the specidied variable is of type PhpReference
                //				ldfld PhpReference.value
                //	*****
                VariablesTable.Entry entry = codeGenerator.CurrentVariablesTable[varName];
                entry.Variable.EmitLoad(il);
                if (entry.IsPhpReference)
                    il.Emit(OpCodes.Ldfld, Fields.PhpReference_Value);

                return PhpTypeCode.Object;
            }

            // LOAD Operators.GetVariable[Unchecked](<script context>, <local variable table>, <name>);
            codeGenerator.EmitLoadScriptContext();
            codeGenerator.EmitLoadRTVariablesTable();
            il.Emit(OpCodes.Ldstr, varName.Value);

            if (codeGenerator.ChainBuilder.QuietRead)
                il.Emit(OpCodes.Call, Methods.Operators.GetVariableUnchecked);
            else
                il.Emit(OpCodes.Call, Methods.Operators.GetVariable);

            return PhpTypeCode.Object;
        }