Exemplo n.º 1
0
		public MethodInfo EmitLambda(string name, AST.DirectVarUse variable, AST.Expression/*!*/ expression,
			PhpTypeCode returnType)
		{
			MethodBuilder result = linqContextBuilder.DefineMethod(name, MethodAttributes.PrivateScope | MethodAttributes.SpecialName,
				PhpTypeCodeEnum.ToType(returnType), new Type[] { typeof(object) });

			ILEmitter il = new ILEmitter(result);

			EnterLambdaDeclaration(il);

			if (variable != null)
			{
				// <variable> = COPY(<argument>);
				variable.Emit(cg);
				il.Emit(OpCodes.Ldarg_1);
				cg.EmitVariableCopy(CopyReason.Assigned, null);
				variable.EmitAssign(cg);
			}

			cg.EmitConversion(expression, returnType);
			il.Emit(OpCodes.Ret);

			LeaveLambdaDeclaration();

			return result;
		}
Exemplo n.º 2
0
		/// <summary>
		/// Called when a <see cref="PHP.Core.AST.FieldDecl"/> AST node is visited during the emit phase.
		/// </summary>
		public void InitializeField(PhpField/*!*/ field, AST.Expression initVal)
		{
			ILEmitter cil;
			IPlace sc_place;
            
			if (field.IsStatic)
			{
                // (J) even overiding static field is created again in derivating type
				// there is no initialization taking place if the implementing CLI field does not live in current class
				//if (field.Overrides != null) return;

				if (field.IsAppStatic)
				{
					// app-static field initialization is emitted into the static ctor
					cil = field.DeclaringPhpType.Builder.StaticCtorEmitter;

					sc_place = new LazyLoadSCPlace();
				}
				else
				{
					// thread-static field initialization is emitted into the __InitializeStaticFields method
					cil = new ILEmitter(field.DeclaringPhpType.StaticFieldInitMethodBuilder);

					sc_place = new IndexedPlace(PlaceHolder.Argument, ScriptBuilder.ArgContext);
				}
			}
			else
			{
                if (initVal == null && field.Implementor != field.DeclaringType)
                    return;

				// instance field initialization is emitted into the <InitializeInstanceFields> method
				cil = field.DeclaringPhpType.Builder.InstanceFieldInitEmitter;

				sc_place = new IndexedPlace(PlaceHolder.Argument, FunctionBuilder.ArgContextInstance);

				cil.Ldarg(FunctionBuilder.ArgThis);
			}

			if (initVal != null)
			{
				// emit the expression evaluating code
				ILEmitter old_il = il;
				IPlace old_sc_place = ScriptContextPlace;

				try
				{
					// set il and SC-emitter appropriately
					il = cil;
					ScriptContextPlace = sc_place;

					EmitBoxing(initVal.Emit(this));
				}
				finally
				{
					// restore the saved il and SC-emitter
					il = old_il;
					ScriptContextPlace = old_sc_place;
				}

				cil.Emit(OpCodes.Newobj, Constructors.PhpSmartReference.Object);
			}
			else cil.Emit(OpCodes.Newobj, Constructors.PhpSmartReference.Void);

			// store it in the field
            Debug.Assert(field.IsStatic == field.RealField.IsStatic);
			cil.Emit(field.IsStatic ? OpCodes.Stsfld : OpCodes.Stfld, field.RealField);
		}
Exemplo n.º 3
0
 public void Visit(AST ast)
 {
     // process every statement
     foreach (Statement stmt in ast.stmt_list)
         Visit(stmt);
 }
Exemplo n.º 4
0
 public void Visit(AST ast)
 {
     // put class __MAIN at beginning of modified statement list
     modifiedStmtList.Add(cd__MAIN);
     // leave top class declarations, move top function declarations to class __MAIN, move everything else to function __MAIN()
     foreach (Statement stmt in ast.stmt_list)
         Visit(stmt);
     // replace AST's old statement list by modified one
     ast.stmt_list = modifiedStmtList;
 }
Exemplo n.º 5
0
 public void Visit(AST ast)
 {
     // start with emtpy symbol table
     SymbolTable.reset();
     // build symbol table and at the same time check references
     foreach (Statement stmt in ast.stmt_list)
         Visit(stmt);
 }
Exemplo n.º 6
0
		public override void ApplyCustomAttribute(AST.SpecialAttributes kind, Attribute attribute, AST.CustomAttribute.TargetSelectors selector)
		{
			switch (kind)
			{
				case AST.SpecialAttributes.Export:
					this.exportInfo = (ExportAttribute)attribute;
					break;

				default:
					Debug.Fail("N/A");
					break;
			}
		}
Exemplo n.º 7
0
		public abstract void CustomAttributeDefined(ErrorSink errors, AST.CustomAttribute customAttribute);
Exemplo n.º 8
0
		public override int GetAttributeUsageCount(DType type, AST.CustomAttribute.TargetSelectors selector)
		{
			Debug.Fail("Custom attributes cannot be defined on transient assemblies or modules.");
			throw null;
		}
Exemplo n.º 9
0
        public void Visit(AST ast)
        {
            // process each statement of php script recursively
            foreach (Statement stmt in ast.stmt_list)
                Visit(stmt);

            // save module
            PEmitter.EndModule();
        }
Exemplo n.º 10
0
		public override void CustomAttributeDefined(ErrorSink errors, AST.CustomAttribute customAttribute)
		{
			Debug.Fail("Custom attributes cannot be defined on transient assemblies or modules.");
			throw null;
		}
Exemplo n.º 11
0
		public override void EmitCustomAttribute(CustomAttributeBuilder builder, AST.CustomAttribute.TargetSelectors selector)
		{
			Debug.Fail("Custom attributes cannot be defined on transient assemblies or modules.");
			throw null;
		}
Exemplo n.º 12
0
		public override void ApplyCustomAttribute(AST.SpecialAttributes kind, Attribute attribute, AST.CustomAttribute.TargetSelectors selector)
		{
			Debug.Fail("Custom attributes cannot be defined on transient assemblies or modules.");
			throw null;
		}
Exemplo n.º 13
0
		public abstract int GetAttributeUsageCount(DType type, AST.CustomAttribute.TargetSelectors selector);
Exemplo n.º 14
0
		public abstract void EmitCustomAttribute(CustomAttributeBuilder builder, AST.CustomAttribute.TargetSelectors selector);
Exemplo n.º 15
0
		public override void CustomAttributeDefined(ErrorSink errors, AST.CustomAttribute/*!*/ customAttribute)
		{
			attributes.Attributes.Add(customAttribute);
		}
Exemplo n.º 16
0
 public void Visit(AST ast)
 {
     // create module
     PEmitter.BeginModule();
     // process each statement of php script recursively
     foreach (Statement stmt in ast.stmt_list)
         Visit(stmt);
     // set entry point at __MAIN.__MAIN()
     if (PEmitter.target == PEmitter.EXE)
         PEmitter.asmBld.SetEntryPoint(mainMethod, PEFileKinds.ConsoleApplication);
 }
Exemplo n.º 17
0
		public override int GetAttributeUsageCount(DType/*!*/ type, AST.CustomAttribute.TargetSelectors selector)
		{
			return attributes.Count(type, selector);
		}
Exemplo n.º 18
0
 public void Visit(AST ast)
 {
     StatementList originalClassDeclarations = new StatementList();
     StatementList reorderedClassDeclarations = new StatementList();
     // move class declarations from ast.stmt_list to originalClassDeclarations
     for (int i = 0; i < ast.stmt_list.Count(); i++) {
         Statement stmt = ast.stmt_list.Get(i);
         if (stmt is CLASS_DECLARATION) {
             ast.stmt_list.Remove(stmt);
             i--;
             originalClassDeclarations.Add(stmt);
         }
     }
     // reorder class declarations
     ArrayList processedInPreviousIteration;
     ArrayList toBeProcessedInNextIteration = new ArrayList();
     // start with classes with no parent specified
     for (int i = 0; i < originalClassDeclarations.Count(); i++) {
         CLASS_DECLARATION cd = (CLASS_DECLARATION)originalClassDeclarations.Get(i);
         if (cd.extends == null) {
             originalClassDeclarations.Remove(cd);
             i--;
             reorderedClassDeclarations.Add(cd);
             toBeProcessedInNextIteration.Add(cd.name);
         }
     }
     processedInPreviousIteration = toBeProcessedInNextIteration;
     // in each iteration, add those class delcarations which inherit from class declarations processed in the previous iteration
     while (originalClassDeclarations.Count() > 0) {
         toBeProcessedInNextIteration = new ArrayList();
         for (int i = 0; i < originalClassDeclarations.Count(); i++) {
             CLASS_DECLARATION cd = (CLASS_DECLARATION)originalClassDeclarations.Get(i);
             if (processedInPreviousIteration.Contains(cd.extends)) {
                 originalClassDeclarations.Remove(cd);
                 i--;
                 reorderedClassDeclarations.Add(cd);
                 toBeProcessedInNextIteration.Add(cd.name);
             }
         }
         // if there are still classes left, but nothing happened in this iteration, a parent wasn't declared or there is a cycle in inheritance
         if (processedInPreviousIteration.Count == 0)
             Report.Error(100);
         processedInPreviousIteration = toBeProcessedInNextIteration;
     }
     // add reordered class declarations to ast.stmt_list
     ast.stmt_list.AddRange(reorderedClassDeclarations);
 }
Exemplo n.º 19
0
		public override void EmitCustomAttribute(CustomAttributeBuilder/*!*/ builder, AST.CustomAttribute.TargetSelectors selector)
		{
			switch (selector)
			{
				case AST.CustomAttribute.TargetSelectors.Assembly:
					RealAssemblyBuilder.SetCustomAttribute(builder);
					break;

				case AST.CustomAttribute.TargetSelectors.Module:
					RealModuleBuilder.SetCustomAttribute(builder);
					break;
			}
		}
Exemplo n.º 20
0
		public abstract void ApplyCustomAttribute(AST.SpecialAttributes kind, Attribute attribute, AST.CustomAttribute.TargetSelectors selector);