Esempio n. 1
0
		internal PhpTypeCode EmitArrayKey(ChainBuilder chain, Expression key)
		{
			PhpTypeCode result;

			if (key != null)
			{
				if (chain != null) chain.Create();
				
                // convert the key into integer if necessary and possible in compile time
                IntStringKey array_key;
                if (key.HasValue() && Convert.ObjectToArrayKey(key.GetValue(), out array_key) && array_key.IsInteger)
                {
                    il.LdcI4(array_key.Integer);
                    result = PhpTypeCode.Integer;
                }
                else
                {
                    // Emit index and box the result
                    switch (result = key.Emit(this))
                    {
                        case PhpTypeCode.Integer:
                            break;

                        case PhpTypeCode.String:
                            break;

                        default:
                            EmitBoxing(result);
                            result = PhpTypeCode.Object;
                            break;
                    }
                }
				
				if (chain != null) chain.End();
			}
			else
				result = PhpTypeCode.Invalid;

			return result;
		}
Esempio n. 2
0
        /// <summary>
		/// Initializes a new instance of the <see cref="PHP.Core.CodeGenerator"/> class.
		/// </summary>
		public CodeGenerator(CompilationContext/*!*/ context)
		{
			ScriptContextPlace = new IndexedPlace(PlaceHolder.Argument, ScriptBuilder.ArgContext);
			TypeContextPlace = new IndexedPlace(PlaceHolder.Argument, ScriptBuilder.ArgIncluder);

			this.context = context;

			this.il = null;
			this.currentVariablesTable = null;
			this.currentLabels = null;
			this.locationStack = new CompilerLocationStack();
			this.branchingStack = new BranchingStack(this);
			this.chainBuilder = new ChainBuilder(this);
		}