BoundNodeClassWriter.cs (171)
130WriteLine("{{");
137WriteLine("}}");
155WriteLine("// <auto-generated />");
156WriteLine("#nullable enable");
159WriteLine("' <auto-generated />"); break;
209WriteLine("using {0};", nsName); break;
211WriteLine("Imports {0}", nsName); break;
222WriteLine("namespace Microsoft.CodeAnalysis.CSharp");
226WriteLine("Namespace Microsoft.CodeAnalysis.VisualBasic");
243WriteLine("End Namespace");
255WriteLine("internal enum BoundKind : byte");
258WriteLine("{0},", FixKeyword(StripBound(node.Name)));
263WriteLine("Friend Enum BoundKind as Byte");
266WriteLine("{0}", FixKeyword(StripBound(node.Name)));
268WriteLine("End Enum");
302WriteLine("internal {2}partial class {0} : {1}", node.Name, node.Base, abstr);
314WriteLine("Partial Friend {1}Class {0}", node.Name, abstr);
316WriteLine("Inherits {0}", node.Base);
336WriteLine("End Class");
465WriteLine("this.{0} = {1};", field.Name, FieldNullHandling(node, field.Name) == NullHandling.Always ? "null" : ToCamelCase(field.Name));
472WriteLine("Validate();");
480WriteLine(@"[Conditional(""DEBUG"")]");
481WriteLine("private partial void Validate();");
530WriteLine("Me._{0} = {1}", field.Name, FieldNullHandling(node, field.Name) == NullHandling.Always ? "Nothing" : ToCamelCase(field.Name));
537WriteLine("Validate()");
541WriteLine("End Sub");
546WriteLine("Private Partial Sub Validate()");
547WriteLine("End Sub");
601WriteLine("this.{0} = {1};", field.Name, FieldNullHandling(node, field.Name) == NullHandling.Always ? "null" : ToCamelCase(field.Name));
640WriteLine("Me._{0} = {1}", field.Name, FieldNullHandling(node, field.Name) == NullHandling.Always ? "Nothing" : ToCamelCase(field.Name));
645WriteLine("Validate()");
649WriteLine("End Sub");
675WriteLine("RoslynDebug.Assert(!{0}.IsDefault, \"Field '{0}' cannot be null (use Null=\\\"allow\\\" in BoundNodes.xml to remove this check)\");", ToCamelCase(field.Name));
677WriteLine("RoslynDebug.Assert({0} is object, \"Field '{0}' cannot be null (make the type nullable in BoundNodes.xml to remove this check)\");", ToCamelCase(field.Name));
682WriteLine("Debug.Assert(Not ({0}.IsDefault), \"Field '{0}' cannot be null (use Null=\"\"allow\"\" in BoundNodes.xml to remove this check)\")", ToCamelCase(field.Name));
684WriteLine("Debug.Assert({0} IsNot Nothing, \"Field '{0}' cannot be null (use Null=\"\"allow\"\" in BoundNodes.xml to remove this check)\")", ToCamelCase(field.Name));
830WriteLine("public override {0}{1} {2} {{ get; }}", (IsNew(field) ? "new " : ""), field.Type, field.Name);
842WriteLine($"public new {field.Type} {field.Name} => base.{field.Name}{suppression};");
846WriteLine("public {0}{1} {2} {{ get; }}", (IsNew(field) ? "new " : ""), field.Type, field.Name);
852WriteLine("Private {0}ReadOnly _{2} As {1}", (IsNew(field) ? "Shadows " : ""), field.Type, field.Name);
853WriteLine("Public {0}ReadOnly Property {2} As {1}", (IsNew(field) ? "Shadows " : IsPropertyOverrides(field) ? "Overrides " : ""), field.Type, field.Name);
855WriteLine("Get");
857WriteLine("Return _{0}", field.Name);
859WriteLine("End Get");
861WriteLine("End Property");
875WriteLine("[DebuggerStepThrough]");
876WriteLine("public override BoundNode? Accept(BoundTreeVisitor visitor) => visitor.Visit{0}(this);", StripBound(name));
881WriteLine("<DebuggerStepThrough>");
882WriteLine("Public Overrides Function Accept(visitor as BoundTreeVisitor) As BoundNode");
884WriteLine("Return visitor.Visit{0}(Me)", StripBound(name));
886WriteLine("End Function");
968WriteLine(";");
969WriteLine("result.CopyAttributes(this);");
970WriteLine("return result;");
973WriteLine("return this;");
1004WriteLine(" As {0}", node.Name);
1011WriteLine(" Then");
1016WriteLine("");
1017WriteLine("result.CopyAttributes(Me)");
1018WriteLine("Return result");
1020WriteLine("End If");
1022WriteLine("Return Me");
1025WriteLine("End Function");
1064WriteLine("internal abstract partial class BoundTreeVisitor<A, R>");
1068WriteLine("[MethodImpl(MethodImplOptions.NoInlining), DebuggerStepThrough]");
1069WriteLine("internal R VisitInternal(BoundNode node, A arg)");
1071WriteLine("switch (node.Kind)");
1075WriteLine("case BoundKind.{0}:", FixKeyword(StripBound(node.Name)));
1077WriteLine("return Visit{0}(({1})node, arg);", StripBound(node.Name), node.Name);
1082WriteLine("return default(R)!;");
1087WriteLine("internal abstract partial class BoundTreeVisitor<A, R>");
1091WriteLine($"public virtual R Visit{StripBound(node.Name)}({node.Name} node, A arg) => this.DefaultVisit(node, arg);");
1096WriteLine("internal abstract partial class BoundTreeVisitor");
1100WriteLine($"public virtual BoundNode? Visit{StripBound(node.Name)}({node.Name} node) => this.DefaultVisit(node);");
1107WriteLine("Friend MustInherit Partial Class BoundTreeVisitor(Of A, R)");
1111WriteLine("<MethodImpl(MethodImplOptions.NoInlining), DebuggerStepThrough>");
1112WriteLine("Friend Function VisitInternal(node As BoundNode, arg As A) As R");
1114WriteLine("Select Case node.Kind");
1118WriteLine("Case BoundKind.{0}", FixKeyword(StripBound(node.Name)));
1120WriteLine("Return Visit{0}(CType(node, {1}), arg)", StripBound(node.Name), node.Name);
1124WriteLine("End Select");
1125WriteLine("Return DefaultVisit(node, arg)");
1127WriteLine("End Function");
1131WriteLine("End Class");
1134WriteLine("Friend MustInherit Partial Class BoundTreeVisitor(Of A, R)");
1138WriteLine("Public Overridable Function Visit{0}(node As {1}, arg As A) As R", StripBound(node.Name), node.Name);
1140WriteLine("Return Me.DefaultVisit(node, arg)");
1142WriteLine("End Function");
1146WriteLine("End Class");
1149WriteLine("Friend MustInherit Partial Class BoundTreeVisitor");
1153WriteLine(GetVisitFunctionDeclaration(node.Name, isOverride: false));
1155WriteLine("Return Me.DefaultVisit(node)");
1157WriteLine("End Function");
1161WriteLine("End Class");
1175WriteLine("internal abstract partial class BoundTreeWalker : BoundTreeVisitor");
1182WriteLine($"{GetVisitFunctionDeclaration(node.Name, isOverride: true)} => null;");
1185WriteLine(GetVisitFunctionDeclaration(node.Name, isOverride: true));
1189WriteLine("this.Visit{1}(node.{0});", field.Name, IsNodeList(field.Type) ? "List" : "");
1191WriteLine("return null;");
1200WriteLine("Friend MustInherit Partial Class BoundTreeWalker");
1202WriteLine("Inherits BoundTreeVisitor");
1207WriteLine(GetVisitFunctionDeclaration(node.Name, isOverride: true));
1210WriteLine("Me.Visit{1}(node.{0})", field.Name, IsNodeList(field.Type) ? "List" : "");
1211WriteLine("Return Nothing");
1213WriteLine("End Function");
1218WriteLine("End Class");
1233WriteLine("internal sealed class BoundTreeDumperNodeProducer : BoundTreeVisitor<object?, TreeDumperNode>");
1235WriteLine("private BoundTreeDumperNodeProducer()");
1238WriteLine("public static TreeDumperNode MakeTree(BoundNode node) => (new BoundTreeDumperNodeProducer()).Visit(node, null);");
1245WriteLine("new TreeDumperNode[]");
1267WriteLine(",");
1272WriteLine(",");
1278WriteLine(",");
1282WriteLine("");
1287WriteLine("Array.Empty<TreeDumperNode>()");
1289WriteLine(");");
1296WriteLine("Friend NotInheritable Class BoundTreeDumperNodeProducer");
1298WriteLine("Inherits BoundTreeVisitor(Of Object, TreeDumperNode)");
1300WriteLine("Private Sub New()");
1301WriteLine("End Sub");
1303WriteLine("Public Shared Function MakeTree(node As BoundNode) As TreeDumperNode");
1305WriteLine("Return (New BoundTreeDumperNodeProducer()).Visit(node, Nothing)");
1307WriteLine("End Function");
1312WriteLine("Public Overrides Function Visit{0}(node As {1}, arg As Object) As TreeDumperNode", StripBound(node.Name), node.Name);
1318WriteLine("New TreeDumperNode() {{");
1331WriteLine("");
1333WriteLine(",");
1336WriteLine("}})");
1340WriteLine("Array.Empty(Of TreeDumperNode)())");
1343WriteLine("End Function");
1347WriteLine("End Class");
1362WriteLine("internal abstract partial class BoundTreeRewriter : BoundTreeVisitor");
1368WriteLine($"{GetVisitFunctionDeclaration(node.Name, isOverride: true)} => node;");
1371WriteLine(GetVisitFunctionDeclaration(node.Name, isOverride: true));
1382WriteLine("TypeSymbol? {0} = this.VisitType(node.{1});", ToCamelCase(field.Name), field.Name);
1388WriteLine(";");
1392WriteLine("return node;");
1404WriteLine("Friend MustInherit Partial Class BoundTreeRewriter");
1406WriteLine("Inherits BoundTreeVisitor");
1410WriteLine(GetVisitFunctionDeclaration(node.Name, isOverride: true));
1423WriteLine("Dim {0} as TypeSymbol = Me.VisitType(node.{1})", ToCamelCase(field.Name), field.Name);
1430WriteLine("");
1434WriteLine("Return node");
1438WriteLine("End Function");
1442WriteLine("End Class");
1461WriteLine("internal sealed partial class NullabilityRewriter : BoundTreeRewriter");
1467WriteLine($"private readonly ImmutableDictionary<BoundExpression, (NullabilityInfo Info, TypeSymbol? Type)> {updatedNullabilities};");
1468WriteLine($"private readonly NullableWalker.SnapshotManager? {snapshotManager};");
1469WriteLine($"private readonly ImmutableDictionary<Symbol, Symbol>.Builder {remappedSymbols};");
1472WriteLine("public NullabilityRewriter(ImmutableDictionary<BoundExpression, (NullabilityInfo Info, TypeSymbol? Type)> updatedNullabilities, NullableWalker.SnapshotManager? snapshotManager, ImmutableDictionary<Symbol, Symbol>.Builder remappedSymbols)");
1474WriteLine($"{updatedNullabilities} = updatedNullabilities;");
1475WriteLine($"{snapshotManager} = snapshotManager;");
1476WriteLine($"{remappedSymbols} = remappedSymbols;");
1493WriteLine(GetVisitFunctionDeclaration(node.Name, isOverride: true));
1501WriteLine($"{field.Type} {ToCamelCase(field.Name)} = GetUpdatedSymbol(node, node.{field.Name});");
1506WriteLine($"{field.Type} {ToCamelCase(field.Name)} = GetUpdatedArray(node, node.{field.Name});");
1521WriteLine($"{node.Name} updatedNode;");
1528WriteLine("else");
1532WriteLine("return updatedNode;");
1538WriteLine("return node;");
1543WriteLine("return updatedNode;");
1550WriteLine(";");
1556=> WriteLine($"if ({(inverted ? "!" : "")}{updatedNullabilities}.TryGetValue(node, out (NullabilityInfo Info, TypeSymbol? Type) infoAndType))");
1562WriteLine(";");
1599WriteLine($"updatedNode.TopLevelNullability = infoAndType.Info;");
1869WriteLine($"{field.Type} {ToCamelCase(field.Name)} = node.{field.Name};");
1873WriteLine($"{field.Type} {ToCamelCase(field.Name)} = this.VisitList(node.{field.Name});");
1877WriteLine($"{field.Type} {ToCamelCase(field.Name)} = ({field.Type})this.Visit(node.{field.Name});");
1885WriteLine("Dim {0} As {2} = node.{1}", ToCamelCase(field.Name), field.Name, field.Type);
1889WriteLine("Dim {0} As {2} = Me.VisitList(node.{1})", ToCamelCase(field.Name), field.Name, field.Type);
1893WriteLine("Dim {0} As {2} = DirectCast(Me.Visit(node.{1}), {2})", ToCamelCase(field.Name), field.Name, field.Type);