Exemple #1
0
        public ControlFlowGraph CreateGraph()
        {
            // Temp Variable for return
            if (selfParameter != null)
            {
                graph.AddSelfParameter(selfParameter);
            }

            foreach (var parameter in invocable.Parameters.Where(p => !p.Unused).OfType <INamedParameter>())
            {
                graph.AddParameter(parameter.Symbol.IsMutableBinding, parameter.Symbol.DataType, CurrentScope, parameter.Symbol);
            }

            currentBlock = graph.NewBlock();
            foreach (var statement in invocable.Body.Statements)
            {
                Convert(statement);
            }

            // Generate the implicit return statement
            if (currentBlock != null && !currentBlock.IsTerminated)
            {
                var span = invocable.Span.AtEnd();
                //EndScope(span);
                currentBlock.End(new ReturnVoidInstruction(span, Scope.Outer));
            }

            return(graph.Build());
        }
Exemple #2
0
        private DeclarationIL?BuildDefaultConstructor(
            IClassDeclaration classDeclaration,
            ISymbolTree symbolTree)
        {
            var constructorSymbol = classDeclaration.DefaultConstructorSymbol;

            if (constructorSymbol is null)
            {
                return(null);
            }

            if (declarationsIL.TryGetValue(constructorSymbol, out var declaration))
            {
                return(declaration);
            }

            var selfParameterSymbol = symbolTree.Children(constructorSymbol).OfType <SelfParameterSymbol>().Single();
            var selfParameter       = new SelfParameterIL(selfParameterSymbol);
            var parameters          = selfParameter.Yield().ToFixedList <ParameterIL>();

            var graph = new ControlFlowGraphBuilder(classDeclaration.File);

            graph.AddSelfParameter(selfParameterSymbol);
            var block = graph.NewBlock();

            block.End(new ReturnVoidInstruction(classDeclaration.NameSpan, Scope.Outer));

            //var il = new ControlFlowGraphBuilder(classDeclaration.File);
            //il.AddSelfParameter(selfType);
            //var block = il.NewBlock();
            //block.End(classDeclaration.NameSpan, Scope.Outer);

            var defaultConstructor = new ConstructorIL(// TODO how to get a name
                constructorSymbol,
                parameters, FixedList <FieldInitializationIL> .Empty, graph.Build());

            //defaultConstructor.ControlFlowOld.InsertedDeletes = new InsertedDeletes();
            declarationsIL.Add(constructorSymbol, defaultConstructor);
            return(defaultConstructor);
        }