コード例 #1
0
ファイル: CodeGenerator.cs プロジェクト: dw4dev/Phalanger
		public void EmitConstantExportStub(ClassConstant/*!*/ constant, PropertyBuilder/*!*/ property)
		{
			Debug.Assert(constant != null && constant.IsExported && property != null);

			MethodBuilder getter = (MethodBuilder)property.GetGetMethod(true);

			// emit getter:
			if (getter != null)
			{
				EmissionContext emission_context = SetupStubPlaces(constant.DeclaringPhpType, getter.IsStatic);
				il = new ILEmitter(getter);

				try
				{
					// read the field
					PhpTypeCode type_code = constant.EmitGet(this, null, false, null);

					// convert it to the return type
					//ClrOverloadBuilder.EmitConvertToClr(
					//    il,
					//    type_code,
					//    getter.ReturnType);

					il.EmitBoxing(type_code);

					il.Emit(OpCodes.Ret);
				}
				finally
				{
					RestorePlaces(emission_context);
				}
			}
		}
コード例 #2
0
ファイル: CodeGenerator.cs プロジェクト: dw4dev/Phalanger
		/// <summary>
		/// Called when a <see cref="PHP.Core.AST.ConstantDecl"/> AST node is visited during the emit phase.
		/// </summary>
		/// <param name="constant">The constant.</param>
		/// <remarks>
		/// Even interface constants are permitted in PHP. These are implemented by <B>static</B> <B>initonly</B>
		/// fields in the interface, which causes some complaints in the .NET Framework 1.1 verifier.
		/// However it is rather a verifier bug - .NET Framework 2.0 verifier is fixed and verifies it OK.
		/// </remarks>
		public void InitializeClassConstant(ClassConstant/*!*/ constant)
		{
			Debug.Assert(constant != null);

            // real constant definition
            if (constant.RealField.IsLiteral)
            {
                Debug.Assert(constant.RealFieldBuilder != null);
                constant.RealFieldBuilder.SetConstant(constant.Value);
                return;
            }

			// class constant initialization is emitted into the static constructor
			ILEmitter old_il = il;
			IPlace old_sc_emitter = ScriptContextPlace;
			try
			{
				// set il and SC-emitter appropriately
				
				if (constant.HasValue)
				{
					il = constant.DeclaringPhpType.Builder.StaticCtorEmitter;
                    il.LoadLiteralBox(constant.Value);
				}
				else
				{
                    il = new ILEmitter(constant.DeclaringPhpType.StaticFieldInitMethodBuilder);
                    ScriptContextPlace = new IndexedPlace(PlaceHolder.Argument, ScriptBuilder.ArgContext);

					// emit the expression evaluating code
					EmitBoxing(constant.Node.Initializer.Emit(this));
				}

				// store it in the field
				il.Emit(OpCodes.Stsfld, constant.RealField);
			}
			finally
			{
				// restore the saved il and SC-emitter
				il = old_il;
				ScriptContextPlace = old_sc_emitter;
			}
		}
コード例 #3
0
ファイル: TypeDecl.cs プロジェクト: Ashod/Phalanger
		internal void AnalyzeMember(Analyzer/*!*/ analyzer, ClassConstant/*!*/ constant)
		{
			this.constant = constant;

			// constant redeclared:
			if (constant == null) return;

			// initialize constant so that it has no value:
			this.constant.SetNode(this);
		}