Exemplo n.º 1
0
 /// <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>();
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
 }
Exemplo n.º 7
0
 protected virtual void AppendFunctionDefinition(StringBuilder builder, AstFunctionDefinition functionDefinition)
 {
     builder.Append(functionDefinition);
 }
Exemplo n.º 8
0
 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}");
            }
Exemplo n.º 10
0
 public virtual void Build(CsBuilder builder, AstFunctionDefinition functionDef)
 => throw new ZsharpException("Not Implemented.");
Exemplo n.º 11
0
 public AstDefinedMethod(AstFunctionDefinition definition)
 {
     this.Definition           = definition;
     this.GenericArgumentTypes = new List <IAstTypeReference>();
 }
Exemplo n.º 12
0
 public virtual void VisitFunctionDefinition(AstFunctionDefinition function)
 {
     function.VisitChildren(this);
 }