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; }
/// <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); }
public void Visit(AST ast) { // process every statement foreach (Statement stmt in ast.stmt_list) Visit(stmt); }
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; }
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); }
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; } }
public abstract void CustomAttributeDefined(ErrorSink errors, AST.CustomAttribute customAttribute);
public override int GetAttributeUsageCount(DType type, AST.CustomAttribute.TargetSelectors selector) { Debug.Fail("Custom attributes cannot be defined on transient assemblies or modules."); throw null; }
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(); }
public override void CustomAttributeDefined(ErrorSink errors, AST.CustomAttribute customAttribute) { Debug.Fail("Custom attributes cannot be defined on transient assemblies or modules."); throw null; }
public override void EmitCustomAttribute(CustomAttributeBuilder builder, AST.CustomAttribute.TargetSelectors selector) { Debug.Fail("Custom attributes cannot be defined on transient assemblies or modules."); throw null; }
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; }
public abstract int GetAttributeUsageCount(DType type, AST.CustomAttribute.TargetSelectors selector);
public abstract void EmitCustomAttribute(CustomAttributeBuilder builder, AST.CustomAttribute.TargetSelectors selector);
public override void CustomAttributeDefined(ErrorSink errors, AST.CustomAttribute/*!*/ customAttribute) { attributes.Attributes.Add(customAttribute); }
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); }
public override int GetAttributeUsageCount(DType/*!*/ type, AST.CustomAttribute.TargetSelectors selector) { return attributes.Count(type, selector); }
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); }
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; } }
public abstract void ApplyCustomAttribute(AST.SpecialAttributes kind, Attribute attribute, AST.CustomAttribute.TargetSelectors selector);