public CilCompilationContext(MethodDefinition method, AstMethodDefinitionBase methodAst, Action<IAstElement, CilCompilationContext> compile, IReferenceContext referenceContext) { this.compile = compile; this.referenceContext = referenceContext; this.Method = method; this.MethodAst = methodAst; }
private void CompileMethod(MethodDefinition method, AstMethodDefinitionBase methodAst, DefinitionBuildingContext parentContext) { var body = method.Body.GetILProcessor(); var context = new CilCompilationContext(method, methodAst, (e, c) => CompileCil(body, e, c), parentContext); foreach (var element in methodAst.Body) { CompileCil(body, element, context); } }
public void MapDefinition(AstMethodDefinitionBase methodAst, MethodDefinition method) { references.Add(methodAst, method); }
private void DefineFunction(TypeDefinition type, AstMethodDefinitionBase methodAst, DefinitionBuildingContext context) { MethodDefinition method; if (methodAst is Ast.Definitions.AstFunctionDefinition) { var functionAst = methodAst as AstFunctionDefinition; var attributes = MethodAttributes.Public; if (methodAst.Compilation.Static) attributes |= MethodAttributes.Static; var returnType = context.ConvertReference(functionAst.ReturnType, returnNullIfFailed: true); method = new MethodDefinition(functionAst.Name, attributes, returnType ?? CecilHelper.GetVoidType(type.Module)); if (returnType == null) context.AddDebt(() => method.ReturnType = context.ConvertReference(functionAst.ReturnType)); if (methodAst.Compilation.EntryPoint) type.Module.EntryPoint = method; } else if (methodAst is Ast.Definitions.AstConstructorDefinition) { method = CecilHelper.CreateConstructor(type); method.Attributes |= MethodAttributes.Public; } else { throw new NotImplementedException("LightCompiler.CompileFunction: cannot compile " + methodAst + "."); } type.Methods.Add(method); context.MapDefinition(methodAst, method); DefineParameters(method, methodAst, context); }
private void DefineParameters(MethodDefinition method, AstMethodDefinitionBase methodAst, DefinitionBuildingContext context) { foreach (var parameter in methodAst.Parameters) { method.Parameters.Add(new ParameterDefinition(parameter.Name, ParameterAttributes.None, context.ConvertReference(parameter.Type))); } }
protected virtual void BuildParameters(MethodDefinition method, AstMethodDefinitionBase ast, DefinitionBuildingContext context) { foreach (var parameter in ast.Parameters) { method.Parameters.Add(new ParameterDefinition(parameter.Name, ParameterAttributes.None, context.ConvertReference(parameter.Type))); } }
public virtual void FinalizeBuild(MethodDefinition method, AstMethodDefinitionBase ast, TypeDefinition type, DefinitionBuildingContext context) { BuildParameters(method, ast, context); type.Methods.Add(method); context.MapDefinition(ast, method); }