コード例 #1
0
        private static FixedList <ParameterIL> BuildConstructorParameters(IConstructorDeclaration constructorDeclaration)
        {
            var selfParameterSymbol = constructorDeclaration.ImplicitSelfParameter.Symbol;
            var selfParameter       = new SelfParameterIL(selfParameterSymbol);

            return(selfParameter.Yield().Concat(constructorDeclaration.Parameters.Select(BuildParameter)).ToFixedList());
        }
コード例 #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);
        }