/// <summary> /// Sets the function definition for this scope, and the trace index at which it was resolved. /// </summary> /// <param name="traceIndex">The trace index at which this function definition was resolved.</param> /// <param name="functionDefinition">The function definition which this scope executed inside of.</param> public void SetFunctionDefinitionAndIndex(int traceIndex, AstFunctionDefinition functionDefinition) { // Try to set our scope definition properties. FunctionDefinitionIndex = traceIndex; FunctionDefinition = new AstFunctionDefinition(functionDefinition); ContractDefinition = functionDefinition?.GetImmediateOrAncestor <AstContractDefinition>(); }
public override IAstElement ProcessAfterChildren(AstRoot root, ProcessingContext context) { var statements = root.Children <IAstStatement>(); var main = new AstFunctionDefinition("Main", No.Parameters, statements, AstVoidType.Instance) { Compilation = { Static = true, EntryPoint = true } }; if (!main.Body.Any()) { return(root); } // TODO: this should be done by GenerateReturns, but the ordering behavior is somewhat incorrect right now if (!main.Descendants <AstReturnStatement>().Any()) { main.Body.Add(new AstReturnStatement()); } root.Elements.RemoveWhere(s => s is IAstStatement); var program = new AstTypeDefinition(TypeDefintionTypes.Class, "Program", main); root.Elements.Add(program); return(root); }
public IDisposable AddFunction(AstFunctionDefinition function) { if (Scopes.Count == 0) { throw new InvalidOperationException("A Module must be added first."); } var method = ModuleClass.AddFunction(function); var scope = new FunctionScope(this, method.GetBody(8)); Scopes.Push(scope); return(scope); }
public CSharp.Method AddFunction(AstFunctionDefinition function) { var method = new CSharp.Method(function.Identifier.SymbolName.CanonicalName.FullName, function.FunctionType.TypeReference.ToCode()) { AccessModifiers = function.Symbol.SymbolLocality == AstSymbolLocality.Exported ? AccessModifiers.Public : AccessModifiers.Private, MethodModifiers = MethodModifiers.Static, }; foreach (var parameter in function.FunctionType.Parameters) { method.AddParameter( new CSharp.Parameter( parameter.Identifier.SymbolName.CanonicalName.FullName, parameter.TypeReference.ToCode() ) ); } _moduleClass.AddMethod(method); return(method); }
public override void VisitFunctionDefinition(AstFunctionDefinition function) { using var scope = Context.AddFunction(function); function.VisitChildren(this); }
public override void VisitFunctionDefinition(AstFunctionDefinition function) { function.FunctionType.TypeReference.Should().NotBeNull(); function.VisitChildren(this); }
protected virtual void AppendFunctionDefinition(StringBuilder builder, AstFunctionDefinition functionDefinition) { builder.Append(functionDefinition); }
public override void VisitFunctionDefinition(AstFunctionDefinition function) { function.Symbol.Should().NotBeNull(); function.VisitChildren(this); }
public override void Build(CsBuilder builder, AstFunctionDefinition functionDef) { var conversion = "Conversion"; builder.Append($"Zsharp.Runtime.{conversion}.{functionDef.Identifier.SymbolName.CanonicalName.FullName}"); }
public virtual void Build(CsBuilder builder, AstFunctionDefinition functionDef) => throw new ZsharpException("Not Implemented.");
public AstDefinedMethod(AstFunctionDefinition definition) { this.Definition = definition; this.GenericArgumentTypes = new List <IAstTypeReference>(); }
public virtual void VisitFunctionDefinition(AstFunctionDefinition function) { function.VisitChildren(this); }