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()); }
public string Convert(ParameterIL parameter) { var type = typeConverter.Convert(parameter.DataType); return(parameter switch { NamedParameterIL param => $"{type} {nameMangler.Mangle(param.Symbol.Name)}", SelfParameterIL _ => $"{type} {nameMangler.SelfName}", FieldParameterIL param => $"{type} {nameMangler.Mangle(param.InitializeField.Name)}", _ => throw ExhaustiveMatch.Failed(parameter) });
private static string FormatParameter(ParameterIL parameter) { var format = parameter.IsMutableBinding ? "var {0}: {1}" : "{0}: {1}"; return(parameter switch { // TODO what about escaping the name? NamedParameterIL param => string.Format(CultureInfo.InvariantCulture, format, param.Symbol.Name, param.DataType), // TODO is this the correct name for self? SelfParameterIL param => string.Format(CultureInfo.InvariantCulture, format, "self", param.DataType), FieldParameterIL param => $".{param.InitializeField.Name}", _ => throw ExhaustiveMatch.Failed(parameter) });
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); }