-
Notifications
You must be signed in to change notification settings - Fork 4k
/
CSharpOperationFactory.cs
2354 lines (2120 loc) · 145 KB
/
CSharpOperationFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Operations
{
internal sealed partial class CSharpOperationFactory
{
private readonly SemanticModel _semanticModel;
public CSharpOperationFactory(SemanticModel semanticModel)
{
_semanticModel = semanticModel;
}
[return: NotNullIfNotNull("boundNode")]
public IOperation? Create(BoundNode? boundNode)
{
if (boundNode == null)
{
return null;
}
switch (boundNode.Kind)
{
case BoundKind.DeconstructValuePlaceholder:
return CreateBoundDeconstructValuePlaceholderOperation((BoundDeconstructValuePlaceholder)boundNode);
case BoundKind.DeconstructionAssignmentOperator:
return CreateBoundDeconstructionAssignmentOperator((BoundDeconstructionAssignmentOperator)boundNode);
case BoundKind.Call:
return CreateBoundCallOperation((BoundCall)boundNode);
case BoundKind.Local:
return CreateBoundLocalOperation((BoundLocal)boundNode);
case BoundKind.FieldAccess:
return CreateBoundFieldAccessOperation((BoundFieldAccess)boundNode);
case BoundKind.PropertyAccess:
return CreateBoundPropertyAccessOperation((BoundPropertyAccess)boundNode);
case BoundKind.IndexerAccess:
return CreateBoundIndexerAccessOperation((BoundIndexerAccess)boundNode);
case BoundKind.EventAccess:
return CreateBoundEventAccessOperation((BoundEventAccess)boundNode);
case BoundKind.EventAssignmentOperator:
return CreateBoundEventAssignmentOperatorOperation((BoundEventAssignmentOperator)boundNode);
case BoundKind.Parameter:
return CreateBoundParameterOperation((BoundParameter)boundNode);
case BoundKind.Literal:
return CreateBoundLiteralOperation((BoundLiteral)boundNode);
case BoundKind.DynamicInvocation:
return CreateBoundDynamicInvocationExpressionOperation((BoundDynamicInvocation)boundNode);
case BoundKind.DynamicIndexerAccess:
return CreateBoundDynamicIndexerAccessExpressionOperation((BoundDynamicIndexerAccess)boundNode);
case BoundKind.ObjectCreationExpression:
return CreateBoundObjectCreationExpressionOperation((BoundObjectCreationExpression)boundNode);
case BoundKind.WithExpression:
return CreateBoundWithExpressionOperation((BoundWithExpression)boundNode);
case BoundKind.DynamicObjectCreationExpression:
return CreateBoundDynamicObjectCreationExpressionOperation((BoundDynamicObjectCreationExpression)boundNode);
case BoundKind.ObjectInitializerExpression:
return CreateBoundObjectInitializerExpressionOperation((BoundObjectInitializerExpression)boundNode);
case BoundKind.CollectionInitializerExpression:
return CreateBoundCollectionInitializerExpressionOperation((BoundCollectionInitializerExpression)boundNode);
case BoundKind.ObjectInitializerMember:
return CreateBoundObjectInitializerMemberOperation((BoundObjectInitializerMember)boundNode);
case BoundKind.CollectionElementInitializer:
return CreateBoundCollectionElementInitializerOperation((BoundCollectionElementInitializer)boundNode);
case BoundKind.DynamicObjectInitializerMember:
return CreateBoundDynamicObjectInitializerMemberOperation((BoundDynamicObjectInitializerMember)boundNode);
case BoundKind.DynamicMemberAccess:
return CreateBoundDynamicMemberAccessOperation((BoundDynamicMemberAccess)boundNode);
case BoundKind.DynamicCollectionElementInitializer:
return CreateBoundDynamicCollectionElementInitializerOperation((BoundDynamicCollectionElementInitializer)boundNode);
case BoundKind.UnboundLambda:
return CreateUnboundLambdaOperation((UnboundLambda)boundNode);
case BoundKind.Lambda:
return CreateBoundLambdaOperation((BoundLambda)boundNode);
case BoundKind.Conversion:
return CreateBoundConversionOperation((BoundConversion)boundNode);
case BoundKind.AsOperator:
return CreateBoundAsOperatorOperation((BoundAsOperator)boundNode);
case BoundKind.IsOperator:
return CreateBoundIsOperatorOperation((BoundIsOperator)boundNode);
case BoundKind.SizeOfOperator:
return CreateBoundSizeOfOperatorOperation((BoundSizeOfOperator)boundNode);
case BoundKind.TypeOfOperator:
return CreateBoundTypeOfOperatorOperation((BoundTypeOfOperator)boundNode);
case BoundKind.ArrayCreation:
return CreateBoundArrayCreationOperation((BoundArrayCreation)boundNode);
case BoundKind.ArrayInitialization:
return CreateBoundArrayInitializationOperation((BoundArrayInitialization)boundNode);
case BoundKind.DefaultLiteral:
return CreateBoundDefaultLiteralOperation((BoundDefaultLiteral)boundNode);
case BoundKind.DefaultExpression:
return CreateBoundDefaultExpressionOperation((BoundDefaultExpression)boundNode);
case BoundKind.BaseReference:
return CreateBoundBaseReferenceOperation((BoundBaseReference)boundNode);
case BoundKind.ThisReference:
return CreateBoundThisReferenceOperation((BoundThisReference)boundNode);
case BoundKind.AssignmentOperator:
return CreateBoundAssignmentOperatorOrMemberInitializerOperation((BoundAssignmentOperator)boundNode);
case BoundKind.CompoundAssignmentOperator:
return CreateBoundCompoundAssignmentOperatorOperation((BoundCompoundAssignmentOperator)boundNode);
case BoundKind.IncrementOperator:
return CreateBoundIncrementOperatorOperation((BoundIncrementOperator)boundNode);
case BoundKind.BadExpression:
return CreateBoundBadExpressionOperation((BoundBadExpression)boundNode);
case BoundKind.NewT:
return CreateBoundNewTOperation((BoundNewT)boundNode);
case BoundKind.NoPiaObjectCreationExpression:
return CreateNoPiaObjectCreationExpressionOperation((BoundNoPiaObjectCreationExpression)boundNode);
case BoundKind.UnaryOperator:
return CreateBoundUnaryOperatorOperation((BoundUnaryOperator)boundNode);
case BoundKind.BinaryOperator:
case BoundKind.UserDefinedConditionalLogicalOperator:
return CreateBoundBinaryOperatorBase((BoundBinaryOperatorBase)boundNode);
case BoundKind.TupleBinaryOperator:
return CreateBoundTupleBinaryOperatorOperation((BoundTupleBinaryOperator)boundNode);
case BoundKind.ConditionalOperator:
return CreateBoundConditionalOperatorOperation((BoundConditionalOperator)boundNode);
case BoundKind.NullCoalescingOperator:
return CreateBoundNullCoalescingOperatorOperation((BoundNullCoalescingOperator)boundNode);
case BoundKind.AwaitExpression:
return CreateBoundAwaitExpressionOperation((BoundAwaitExpression)boundNode);
case BoundKind.ArrayAccess:
return CreateBoundArrayAccessOperation((BoundArrayAccess)boundNode);
case BoundKind.NameOfOperator:
return CreateBoundNameOfOperatorOperation((BoundNameOfOperator)boundNode);
case BoundKind.ThrowExpression:
return CreateBoundThrowExpressionOperation((BoundThrowExpression)boundNode);
case BoundKind.AddressOfOperator:
return CreateBoundAddressOfOperatorOperation((BoundAddressOfOperator)boundNode);
case BoundKind.ImplicitReceiver:
return CreateBoundImplicitReceiverOperation((BoundImplicitReceiver)boundNode);
case BoundKind.ConditionalAccess:
return CreateBoundConditionalAccessOperation((BoundConditionalAccess)boundNode);
case BoundKind.ConditionalReceiver:
return CreateBoundConditionalReceiverOperation((BoundConditionalReceiver)boundNode);
case BoundKind.FieldEqualsValue:
return CreateBoundFieldEqualsValueOperation((BoundFieldEqualsValue)boundNode);
case BoundKind.PropertyEqualsValue:
return CreateBoundPropertyEqualsValueOperation((BoundPropertyEqualsValue)boundNode);
case BoundKind.ParameterEqualsValue:
return CreateBoundParameterEqualsValueOperation((BoundParameterEqualsValue)boundNode);
case BoundKind.Block:
return CreateBoundBlockOperation((BoundBlock)boundNode);
case BoundKind.ContinueStatement:
return CreateBoundContinueStatementOperation((BoundContinueStatement)boundNode);
case BoundKind.BreakStatement:
return CreateBoundBreakStatementOperation((BoundBreakStatement)boundNode);
case BoundKind.YieldBreakStatement:
return CreateBoundYieldBreakStatementOperation((BoundYieldBreakStatement)boundNode);
case BoundKind.GotoStatement:
return CreateBoundGotoStatementOperation((BoundGotoStatement)boundNode);
case BoundKind.NoOpStatement:
return CreateBoundNoOpStatementOperation((BoundNoOpStatement)boundNode);
case BoundKind.IfStatement:
return CreateBoundIfStatementOperation((BoundIfStatement)boundNode);
case BoundKind.WhileStatement:
return CreateBoundWhileStatementOperation((BoundWhileStatement)boundNode);
case BoundKind.DoStatement:
return CreateBoundDoStatementOperation((BoundDoStatement)boundNode);
case BoundKind.ForStatement:
return CreateBoundForStatementOperation((BoundForStatement)boundNode);
case BoundKind.ForEachStatement:
return CreateBoundForEachStatementOperation((BoundForEachStatement)boundNode);
case BoundKind.TryStatement:
return CreateBoundTryStatementOperation((BoundTryStatement)boundNode);
case BoundKind.CatchBlock:
return CreateBoundCatchBlockOperation((BoundCatchBlock)boundNode);
case BoundKind.FixedStatement:
return CreateBoundFixedStatementOperation((BoundFixedStatement)boundNode);
case BoundKind.UsingStatement:
return CreateBoundUsingStatementOperation((BoundUsingStatement)boundNode);
case BoundKind.ThrowStatement:
return CreateBoundThrowStatementOperation((BoundThrowStatement)boundNode);
case BoundKind.ReturnStatement:
return CreateBoundReturnStatementOperation((BoundReturnStatement)boundNode);
case BoundKind.YieldReturnStatement:
return CreateBoundYieldReturnStatementOperation((BoundYieldReturnStatement)boundNode);
case BoundKind.LockStatement:
return CreateBoundLockStatementOperation((BoundLockStatement)boundNode);
case BoundKind.BadStatement:
return CreateBoundBadStatementOperation((BoundBadStatement)boundNode);
case BoundKind.LocalDeclaration:
return CreateBoundLocalDeclarationOperation((BoundLocalDeclaration)boundNode);
case BoundKind.MultipleLocalDeclarations:
case BoundKind.UsingLocalDeclarations:
return CreateBoundMultipleLocalDeclarationsBaseOperation((BoundMultipleLocalDeclarationsBase)boundNode);
case BoundKind.LabelStatement:
return CreateBoundLabelStatementOperation((BoundLabelStatement)boundNode);
case BoundKind.LabeledStatement:
return CreateBoundLabeledStatementOperation((BoundLabeledStatement)boundNode);
case BoundKind.ExpressionStatement:
return CreateBoundExpressionStatementOperation((BoundExpressionStatement)boundNode);
case BoundKind.TupleLiteral:
case BoundKind.ConvertedTupleLiteral:
return CreateBoundTupleOperation((BoundTupleExpression)boundNode);
case BoundKind.InterpolatedString:
return CreateBoundInterpolatedStringExpressionOperation((BoundInterpolatedString)boundNode);
case BoundKind.StringInsert:
return CreateBoundInterpolationOperation((BoundStringInsert)boundNode);
case BoundKind.LocalFunctionStatement:
return CreateBoundLocalFunctionStatementOperation((BoundLocalFunctionStatement)boundNode);
case BoundKind.AnonymousObjectCreationExpression:
return CreateBoundAnonymousObjectCreationExpressionOperation((BoundAnonymousObjectCreationExpression)boundNode);
case BoundKind.AnonymousPropertyDeclaration:
throw ExceptionUtilities.Unreachable;
case BoundKind.ConstantPattern:
return CreateBoundConstantPatternOperation((BoundConstantPattern)boundNode);
case BoundKind.DeclarationPattern:
return CreateBoundDeclarationPatternOperation((BoundDeclarationPattern)boundNode);
case BoundKind.RecursivePattern:
return CreateBoundRecursivePatternOperation((BoundRecursivePattern)boundNode);
case BoundKind.ITuplePattern:
return CreateBoundRecursivePatternOperation((BoundITuplePattern)boundNode);
case BoundKind.DiscardPattern:
return CreateBoundDiscardPatternOperation((BoundDiscardPattern)boundNode);
case BoundKind.BinaryPattern:
return CreateBoundBinaryPatternOperation((BoundBinaryPattern)boundNode);
case BoundKind.NegatedPattern:
return CreateBoundNegatedPatternOperation((BoundNegatedPattern)boundNode);
case BoundKind.RelationalPattern:
return CreateBoundRelationalPatternOperation((BoundRelationalPattern)boundNode);
case BoundKind.TypePattern:
return CreateBoundTypePatternOperation((BoundTypePattern)boundNode);
case BoundKind.SwitchStatement:
return CreateBoundSwitchStatementOperation((BoundSwitchStatement)boundNode);
case BoundKind.SwitchLabel:
return CreateBoundSwitchLabelOperation((BoundSwitchLabel)boundNode);
case BoundKind.IsPatternExpression:
return CreateBoundIsPatternExpressionOperation((BoundIsPatternExpression)boundNode);
case BoundKind.QueryClause:
return CreateBoundQueryClauseOperation((BoundQueryClause)boundNode);
case BoundKind.DelegateCreationExpression:
return CreateBoundDelegateCreationExpressionOperation((BoundDelegateCreationExpression)boundNode);
case BoundKind.RangeVariable:
return CreateBoundRangeVariableOperation((BoundRangeVariable)boundNode);
case BoundKind.ConstructorMethodBody:
return CreateConstructorBodyOperation((BoundConstructorMethodBody)boundNode);
case BoundKind.NonConstructorMethodBody:
return CreateMethodBodyOperation((BoundNonConstructorMethodBody)boundNode);
case BoundKind.DiscardExpression:
return CreateBoundDiscardExpressionOperation((BoundDiscardExpression)boundNode);
case BoundKind.NullCoalescingAssignmentOperator:
return CreateBoundNullCoalescingAssignmentOperatorOperation((BoundNullCoalescingAssignmentOperator)boundNode);
case BoundKind.FromEndIndexExpression:
return CreateFromEndIndexExpressionOperation((BoundFromEndIndexExpression)boundNode);
case BoundKind.RangeExpression:
return CreateRangeExpressionOperation((BoundRangeExpression)boundNode);
case BoundKind.SwitchSection:
return CreateBoundSwitchSectionOperation((BoundSwitchSection)boundNode);
case BoundKind.UnconvertedConditionalOperator:
throw ExceptionUtilities.Unreachable;
case BoundKind.UnconvertedSwitchExpression:
throw ExceptionUtilities.Unreachable;
case BoundKind.ConvertedSwitchExpression:
return CreateBoundSwitchExpressionOperation((BoundSwitchExpression)boundNode);
case BoundKind.SwitchExpressionArm:
return CreateBoundSwitchExpressionArmOperation((BoundSwitchExpressionArm)boundNode);
case BoundKind.ObjectOrCollectionValuePlaceholder:
return CreateCollectionValuePlaceholderOperation((BoundObjectOrCollectionValuePlaceholder)boundNode);
case BoundKind.FunctionPointerInvocation:
return CreateBoundFunctionPointerInvocationOperation((BoundFunctionPointerInvocation)boundNode);
case BoundKind.UnconvertedAddressOfOperator:
return CreateBoundUnconvertedAddressOfOperatorOperation((BoundUnconvertedAddressOfOperator)boundNode);
case BoundKind.Attribute:
case BoundKind.ArgList:
case BoundKind.ArgListOperator:
case BoundKind.ConvertedStackAllocExpression:
case BoundKind.FixedLocalCollectionInitializer:
case BoundKind.GlobalStatementInitializer:
case BoundKind.HostObjectMemberReference:
case BoundKind.MakeRefOperator:
case BoundKind.MethodGroup:
case BoundKind.NamespaceExpression:
case BoundKind.PointerElementAccess:
case BoundKind.PointerIndirectionOperator:
case BoundKind.PreviousSubmissionReference:
case BoundKind.RefTypeOperator:
case BoundKind.RefValueOperator:
case BoundKind.Sequence:
case BoundKind.StackAllocArrayCreation:
case BoundKind.TypeExpression:
case BoundKind.TypeOrValueExpression:
case BoundKind.IndexOrRangePatternIndexerAccess:
ConstantValue? constantValue = (boundNode as BoundExpression)?.ConstantValue;
bool isImplicit = boundNode.WasCompilerGenerated;
if (!isImplicit)
{
switch (boundNode.Kind)
{
case BoundKind.FixedLocalCollectionInitializer:
isImplicit = true;
break;
}
}
ImmutableArray<IOperation> children = GetIOperationChildren(boundNode);
return new NoneOperation(children, _semanticModel, boundNode.Syntax, type: null, constantValue, isImplicit: isImplicit);
default:
// If you're hitting this because the IOperation test hook has failed, see
// <roslyn-root>/docs/Compilers/IOperation Test Hook.md for instructions on how to fix.
throw ExceptionUtilities.UnexpectedValue(boundNode.Kind);
}
}
public ImmutableArray<TOperation> CreateFromArray<TBoundNode, TOperation>(ImmutableArray<TBoundNode> boundNodes) where TBoundNode : BoundNode where TOperation : class, IOperation
{
if (boundNodes.IsDefault)
{
return ImmutableArray<TOperation>.Empty;
}
var builder = ArrayBuilder<TOperation>.GetInstance(boundNodes.Length);
foreach (var node in boundNodes)
{
builder.AddIfNotNull((TOperation)Create(node));
}
return builder.ToImmutableAndFree();
}
private IMethodBodyOperation CreateMethodBodyOperation(BoundNonConstructorMethodBody boundNode)
{
return new MethodBodyOperation(
(IBlockOperation?)Create(boundNode.BlockBody),
(IBlockOperation?)Create(boundNode.ExpressionBody),
_semanticModel,
boundNode.Syntax,
isImplicit: boundNode.WasCompilerGenerated);
}
private IConstructorBodyOperation CreateConstructorBodyOperation(BoundConstructorMethodBody boundNode)
{
return new ConstructorBodyOperation(
boundNode.Locals.GetPublicSymbols(),
Create(boundNode.Initializer),
(IBlockOperation?)Create(boundNode.BlockBody),
(IBlockOperation?)Create(boundNode.ExpressionBody),
_semanticModel,
boundNode.Syntax,
isImplicit: boundNode.WasCompilerGenerated);
}
internal ImmutableArray<IOperation> GetIOperationChildren(IBoundNodeWithIOperationChildren boundNodeWithChildren)
{
var children = boundNodeWithChildren.Children;
if (children.IsDefaultOrEmpty)
{
return ImmutableArray<IOperation>.Empty;
}
var builder = ArrayBuilder<IOperation>.GetInstance(children.Length);
foreach (BoundNode? childNode in children)
{
if (childNode == null)
{
continue;
}
IOperation operation = Create(childNode);
builder.Add(operation);
}
return builder.ToImmutableAndFree();
}
internal ImmutableArray<IVariableDeclaratorOperation> CreateVariableDeclarator(BoundNode declaration, SyntaxNode declarationSyntax)
{
switch (declaration.Kind)
{
case BoundKind.LocalDeclaration:
{
return ImmutableArray.Create(CreateVariableDeclaratorInternal((BoundLocalDeclaration)declaration, (declarationSyntax as VariableDeclarationSyntax)?.Variables[0] ?? declarationSyntax));
}
case BoundKind.MultipleLocalDeclarations:
case BoundKind.UsingLocalDeclarations:
{
var multipleDeclaration = (BoundMultipleLocalDeclarationsBase)declaration;
var builder = ArrayBuilder<IVariableDeclaratorOperation>.GetInstance(multipleDeclaration.LocalDeclarations.Length);
foreach (var decl in multipleDeclaration.LocalDeclarations)
{
builder.Add((IVariableDeclaratorOperation)CreateVariableDeclaratorInternal(decl, decl.Syntax));
}
return builder.ToImmutableAndFree();
}
default:
throw ExceptionUtilities.UnexpectedValue(declaration.Kind);
}
}
private IPlaceholderOperation CreateBoundDeconstructValuePlaceholderOperation(BoundDeconstructValuePlaceholder boundDeconstructValuePlaceholder)
{
SyntaxNode syntax = boundDeconstructValuePlaceholder.Syntax;
ITypeSymbol? type = boundDeconstructValuePlaceholder.GetPublicTypeSymbol();
bool isImplicit = boundDeconstructValuePlaceholder.WasCompilerGenerated;
return new PlaceholderOperation(PlaceholderKind.Unspecified, _semanticModel, syntax, type, isImplicit);
}
private IDeconstructionAssignmentOperation CreateBoundDeconstructionAssignmentOperator(BoundDeconstructionAssignmentOperator boundDeconstructionAssignmentOperator)
{
IOperation target = Create(boundDeconstructionAssignmentOperator.Left);
// Skip the synthetic deconstruction conversion wrapping the right operand. This is a compiler-generated conversion that we don't want to reflect
// in the public API because it's an implementation detail.
IOperation value = Create(boundDeconstructionAssignmentOperator.Right.Operand);
SyntaxNode syntax = boundDeconstructionAssignmentOperator.Syntax;
ITypeSymbol? type = boundDeconstructionAssignmentOperator.GetPublicTypeSymbol();
bool isImplicit = boundDeconstructionAssignmentOperator.WasCompilerGenerated;
return new DeconstructionAssignmentOperation(target, value, _semanticModel, syntax, type, isImplicit);
}
private IOperation CreateBoundCallOperation(BoundCall boundCall)
{
MethodSymbol targetMethod = boundCall.Method;
SyntaxNode syntax = boundCall.Syntax;
ITypeSymbol? type = boundCall.GetPublicTypeSymbol();
ConstantValue? constantValue = boundCall.ConstantValue;
bool isImplicit = boundCall.WasCompilerGenerated;
if (!boundCall.OriginalMethodsOpt.IsDefault || IsMethodInvalid(boundCall.ResultKind, targetMethod))
{
ImmutableArray<IOperation> children = CreateFromArray<BoundNode, IOperation>(((IBoundInvalidNode)boundCall).InvalidNodeChildren);
return new InvalidOperation(children, _semanticModel, syntax, type, constantValue, isImplicit);
}
bool isVirtual = IsCallVirtual(targetMethod, boundCall.ReceiverOpt);
IOperation? receiver = CreateReceiverOperation(boundCall.ReceiverOpt, targetMethod);
ImmutableArray<IArgumentOperation> arguments = DeriveArguments(boundCall);
return new InvocationOperation(targetMethod.GetPublicSymbol(), receiver, isVirtual, arguments, _semanticModel, syntax, type, isImplicit);
}
private IOperation CreateBoundFunctionPointerInvocationOperation(BoundFunctionPointerInvocation boundFunctionPointerInvocation)
{
ITypeSymbol? type = boundFunctionPointerInvocation.GetPublicTypeSymbol();
SyntaxNode syntax = boundFunctionPointerInvocation.Syntax;
bool isImplicit = boundFunctionPointerInvocation.WasCompilerGenerated;
ImmutableArray<IOperation> children;
if (boundFunctionPointerInvocation.ResultKind != LookupResultKind.Viable)
{
children = CreateFromArray<BoundNode, IOperation>(((IBoundInvalidNode)boundFunctionPointerInvocation).InvalidNodeChildren);
return new InvalidOperation(children, _semanticModel, syntax, type, constantValue: null, isImplicit);
}
children = GetIOperationChildren(boundFunctionPointerInvocation);
return new NoneOperation(children, _semanticModel, syntax, type, constantValue: null, isImplicit);
}
private IOperation CreateBoundUnconvertedAddressOfOperatorOperation(BoundUnconvertedAddressOfOperator boundUnconvertedAddressOf)
{
return new AddressOfOperation(
Create(boundUnconvertedAddressOf.Operand),
_semanticModel,
boundUnconvertedAddressOf.Syntax,
boundUnconvertedAddressOf.GetPublicTypeSymbol(),
boundUnconvertedAddressOf.WasCompilerGenerated);
}
internal ImmutableArray<IOperation> CreateIgnoredDimensions(BoundNode declaration, SyntaxNode declarationSyntax)
{
switch (declaration.Kind)
{
case BoundKind.LocalDeclaration:
{
BoundTypeExpression? declaredTypeOpt = ((BoundLocalDeclaration)declaration).DeclaredTypeOpt;
Debug.Assert(declaredTypeOpt != null);
return CreateFromArray<BoundExpression, IOperation>(declaredTypeOpt.BoundDimensionsOpt);
}
case BoundKind.MultipleLocalDeclarations:
case BoundKind.UsingLocalDeclarations:
{
var declarations = ((BoundMultipleLocalDeclarationsBase)declaration).LocalDeclarations;
ImmutableArray<BoundExpression> dimensions;
if (declarations.Length > 0)
{
BoundTypeExpression? declaredTypeOpt = declarations[0].DeclaredTypeOpt;
Debug.Assert(declaredTypeOpt != null);
dimensions = declaredTypeOpt.BoundDimensionsOpt;
}
else
{
dimensions = ImmutableArray<BoundExpression>.Empty;
}
return CreateFromArray<BoundExpression, IOperation>(dimensions);
}
default:
throw ExceptionUtilities.UnexpectedValue(declaration.Kind);
}
}
internal IOperation CreateBoundLocalOperation(BoundLocal boundLocal, bool createDeclaration = true)
{
ILocalSymbol local = boundLocal.LocalSymbol.GetPublicSymbol();
bool isDeclaration = boundLocal.DeclarationKind != BoundLocalDeclarationKind.None;
SyntaxNode syntax = boundLocal.Syntax;
ITypeSymbol? type = boundLocal.GetPublicTypeSymbol();
ConstantValue? constantValue = boundLocal.ConstantValue;
bool isImplicit = boundLocal.WasCompilerGenerated;
if (isDeclaration && syntax is DeclarationExpressionSyntax declarationExpressionSyntax)
{
syntax = declarationExpressionSyntax.Designation;
if (createDeclaration)
{
IOperation localReference = CreateBoundLocalOperation(boundLocal, createDeclaration: false);
return new DeclarationExpressionOperation(localReference, _semanticModel, declarationExpressionSyntax, type, isImplicit: false);
}
}
return new LocalReferenceOperation(local, isDeclaration, _semanticModel, syntax, type, constantValue, isImplicit);
}
internal IOperation CreateBoundFieldAccessOperation(BoundFieldAccess boundFieldAccess, bool createDeclaration = true)
{
IFieldSymbol field = boundFieldAccess.FieldSymbol.GetPublicSymbol();
bool isDeclaration = boundFieldAccess.IsDeclaration;
SyntaxNode syntax = boundFieldAccess.Syntax;
ITypeSymbol? type = boundFieldAccess.GetPublicTypeSymbol();
ConstantValue? constantValue = boundFieldAccess.ConstantValue;
bool isImplicit = boundFieldAccess.WasCompilerGenerated;
if (isDeclaration && syntax is DeclarationExpressionSyntax declarationExpressionSyntax)
{
syntax = declarationExpressionSyntax.Designation;
if (createDeclaration)
{
IOperation fieldAccess = CreateBoundFieldAccessOperation(boundFieldAccess, createDeclaration: false);
return new DeclarationExpressionOperation(fieldAccess, _semanticModel, declarationExpressionSyntax, type, isImplicit: false);
}
}
IOperation? instance = CreateReceiverOperation(boundFieldAccess.ReceiverOpt, boundFieldAccess.FieldSymbol);
return new FieldReferenceOperation(field, isDeclaration, instance, _semanticModel, syntax, type, constantValue, isImplicit);
}
internal IOperation? CreateBoundPropertyReferenceInstance(BoundNode boundNode)
{
switch (boundNode)
{
case BoundPropertyAccess boundPropertyAccess:
return CreateReceiverOperation(boundPropertyAccess.ReceiverOpt, boundPropertyAccess.PropertySymbol);
case BoundObjectInitializerMember boundObjectInitializerMember:
return boundObjectInitializerMember.MemberSymbol?.IsStatic == true ?
null :
CreateImplicitReceiver(boundObjectInitializerMember.Syntax, boundObjectInitializerMember.ReceiverType);
case BoundIndexerAccess boundIndexerAccess:
return CreateReceiverOperation(boundIndexerAccess.ReceiverOpt, boundIndexerAccess.ExpressionSymbol);
default:
throw ExceptionUtilities.UnexpectedValue(boundNode.Kind);
}
}
private IPropertyReferenceOperation CreateBoundPropertyAccessOperation(BoundPropertyAccess boundPropertyAccess)
{
IOperation? instance = CreateReceiverOperation(boundPropertyAccess.ReceiverOpt, boundPropertyAccess.PropertySymbol);
var arguments = ImmutableArray<IArgumentOperation>.Empty;
IPropertySymbol property = boundPropertyAccess.PropertySymbol.GetPublicSymbol();
SyntaxNode syntax = boundPropertyAccess.Syntax;
ITypeSymbol? type = boundPropertyAccess.GetPublicTypeSymbol();
bool isImplicit = boundPropertyAccess.WasCompilerGenerated;
return new PropertyReferenceOperation(property, arguments, instance, _semanticModel, syntax, type, isImplicit);
}
private IOperation CreateBoundIndexerAccessOperation(BoundIndexerAccess boundIndexerAccess)
{
PropertySymbol property = boundIndexerAccess.Indexer;
SyntaxNode syntax = boundIndexerAccess.Syntax;
ITypeSymbol? type = boundIndexerAccess.GetPublicTypeSymbol();
bool isImplicit = boundIndexerAccess.WasCompilerGenerated;
if (!boundIndexerAccess.OriginalIndexersOpt.IsDefault || boundIndexerAccess.ResultKind == LookupResultKind.OverloadResolutionFailure)
{
var children = CreateFromArray<BoundNode, IOperation>(((IBoundInvalidNode)boundIndexerAccess).InvalidNodeChildren);
return new InvalidOperation(children, _semanticModel, syntax, type, constantValue: null, isImplicit);
}
ImmutableArray<IArgumentOperation> arguments = DeriveArguments(boundIndexerAccess, isObjectOrCollectionInitializer: false);
IOperation? instance = CreateReceiverOperation(boundIndexerAccess.ReceiverOpt, boundIndexerAccess.ExpressionSymbol);
return new PropertyReferenceOperation(property.GetPublicSymbol(), arguments, instance, _semanticModel, syntax, type, isImplicit);
}
private IEventReferenceOperation CreateBoundEventAccessOperation(BoundEventAccess boundEventAccess)
{
IEventSymbol @event = boundEventAccess.EventSymbol.GetPublicSymbol();
IOperation? instance = CreateReceiverOperation(boundEventAccess.ReceiverOpt, boundEventAccess.EventSymbol);
SyntaxNode syntax = boundEventAccess.Syntax;
ITypeSymbol? type = boundEventAccess.GetPublicTypeSymbol();
bool isImplicit = boundEventAccess.WasCompilerGenerated;
return new EventReferenceOperation(@event, instance, _semanticModel, syntax, type, isImplicit);
}
private IEventAssignmentOperation CreateBoundEventAssignmentOperatorOperation(BoundEventAssignmentOperator boundEventAssignmentOperator)
{
IOperation eventReference = CreateBoundEventAccessOperation(boundEventAssignmentOperator);
IOperation handlerValue = Create(boundEventAssignmentOperator.Argument);
SyntaxNode syntax = boundEventAssignmentOperator.Syntax;
bool adds = boundEventAssignmentOperator.IsAddition;
ITypeSymbol? type = boundEventAssignmentOperator.GetPublicTypeSymbol();
bool isImplicit = boundEventAssignmentOperator.WasCompilerGenerated;
return new EventAssignmentOperation(eventReference, handlerValue, adds, _semanticModel, syntax, type, isImplicit);
}
private IParameterReferenceOperation CreateBoundParameterOperation(BoundParameter boundParameter)
{
IParameterSymbol parameter = boundParameter.ParameterSymbol.GetPublicSymbol();
SyntaxNode syntax = boundParameter.Syntax;
ITypeSymbol? type = boundParameter.GetPublicTypeSymbol();
bool isImplicit = boundParameter.WasCompilerGenerated;
return new ParameterReferenceOperation(parameter, _semanticModel, syntax, type, isImplicit);
}
internal ILiteralOperation CreateBoundLiteralOperation(BoundLiteral boundLiteral, bool @implicit = false)
{
SyntaxNode syntax = boundLiteral.Syntax;
ITypeSymbol? type = boundLiteral.GetPublicTypeSymbol();
ConstantValue? constantValue = boundLiteral.ConstantValue;
bool isImplicit = boundLiteral.WasCompilerGenerated || @implicit;
return new LiteralOperation(_semanticModel, syntax, type, constantValue, isImplicit);
}
private IAnonymousObjectCreationOperation CreateBoundAnonymousObjectCreationExpressionOperation(BoundAnonymousObjectCreationExpression boundAnonymousObjectCreationExpression)
{
SyntaxNode syntax = boundAnonymousObjectCreationExpression.Syntax;
ITypeSymbol? type = boundAnonymousObjectCreationExpression.GetPublicTypeSymbol();
Debug.Assert(type is not null);
bool isImplicit = boundAnonymousObjectCreationExpression.WasCompilerGenerated;
ImmutableArray<IOperation> initializers = GetAnonymousObjectCreationInitializers(boundAnonymousObjectCreationExpression.Arguments, boundAnonymousObjectCreationExpression.Declarations, syntax, type, isImplicit);
return new AnonymousObjectCreationOperation(initializers, _semanticModel, syntax, type, isImplicit);
}
private IOperation CreateBoundObjectCreationExpressionOperation(BoundObjectCreationExpression boundObjectCreationExpression)
{
MethodSymbol constructor = boundObjectCreationExpression.Constructor;
SyntaxNode syntax = boundObjectCreationExpression.Syntax;
ITypeSymbol? type = boundObjectCreationExpression.GetPublicTypeSymbol();
ConstantValue? constantValue = boundObjectCreationExpression.ConstantValue;
bool isImplicit = boundObjectCreationExpression.WasCompilerGenerated;
if (boundObjectCreationExpression.ResultKind == LookupResultKind.OverloadResolutionFailure || constructor == null || constructor.OriginalDefinition is ErrorMethodSymbol)
{
var children = CreateFromArray<BoundNode, IOperation>(((IBoundInvalidNode)boundObjectCreationExpression).InvalidNodeChildren);
return new InvalidOperation(children, _semanticModel, syntax, type, constantValue, isImplicit);
}
else if (boundObjectCreationExpression.Type.IsAnonymousType)
{
// Workaround for https://github.com/dotnet/roslyn/issues/28157
Debug.Assert(isImplicit);
Debug.Assert(type is not null);
ImmutableArray<IOperation> initializers = GetAnonymousObjectCreationInitializers(
boundObjectCreationExpression.Arguments,
declarations: ImmutableArray<BoundAnonymousPropertyDeclaration>.Empty,
syntax,
type,
isImplicit);
return new AnonymousObjectCreationOperation(initializers, _semanticModel, syntax, type, isImplicit);
}
ImmutableArray<IArgumentOperation> arguments = DeriveArguments(boundObjectCreationExpression);
IObjectOrCollectionInitializerOperation? initializer = (IObjectOrCollectionInitializerOperation?)Create(boundObjectCreationExpression.InitializerExpressionOpt);
return new ObjectCreationOperation(constructor.GetPublicSymbol(), initializer, arguments, _semanticModel, syntax, type, constantValue, isImplicit);
}
private IOperation CreateBoundWithExpressionOperation(BoundWithExpression boundWithExpression)
{
IOperation operand = Create(boundWithExpression.Receiver);
IObjectOrCollectionInitializerOperation initializer = (IObjectOrCollectionInitializerOperation)Create(boundWithExpression.InitializerExpression);
MethodSymbol? constructor = boundWithExpression.CloneMethod;
SyntaxNode syntax = boundWithExpression.Syntax;
ITypeSymbol? type = boundWithExpression.GetPublicTypeSymbol();
bool isImplicit = boundWithExpression.WasCompilerGenerated;
return new WithOperation(operand, constructor.GetPublicSymbol(), initializer, _semanticModel, syntax, type, isImplicit);
}
private IDynamicObjectCreationOperation CreateBoundDynamicObjectCreationExpressionOperation(BoundDynamicObjectCreationExpression boundDynamicObjectCreationExpression)
{
IObjectOrCollectionInitializerOperation? initializer = (IObjectOrCollectionInitializerOperation?)Create(boundDynamicObjectCreationExpression.InitializerExpressionOpt);
ImmutableArray<IOperation> arguments = CreateFromArray<BoundExpression, IOperation>(boundDynamicObjectCreationExpression.Arguments);
ImmutableArray<string> argumentNames = boundDynamicObjectCreationExpression.ArgumentNamesOpt.NullToEmpty();
ImmutableArray<RefKind> argumentRefKinds = boundDynamicObjectCreationExpression.ArgumentRefKindsOpt.NullToEmpty();
SyntaxNode syntax = boundDynamicObjectCreationExpression.Syntax;
ITypeSymbol? type = boundDynamicObjectCreationExpression.GetPublicTypeSymbol();
bool isImplicit = boundDynamicObjectCreationExpression.WasCompilerGenerated;
return new DynamicObjectCreationOperation(initializer, arguments, argumentNames, argumentRefKinds, _semanticModel, syntax, type, isImplicit);
}
internal IOperation CreateBoundDynamicInvocationExpressionReceiver(BoundNode receiver)
{
switch (receiver)
{
case BoundObjectOrCollectionValuePlaceholder implicitReceiver:
return CreateBoundDynamicMemberAccessOperation(implicitReceiver, typeArgumentsOpt: ImmutableArray<TypeSymbol>.Empty, memberName: "Add",
implicitReceiver.Syntax, type: null, isImplicit: true);
case BoundMethodGroup methodGroup:
return CreateBoundDynamicMemberAccessOperation(methodGroup.ReceiverOpt, TypeMap.AsTypeSymbols(methodGroup.TypeArgumentsOpt), methodGroup.Name,
methodGroup.Syntax, methodGroup.GetPublicTypeSymbol(), methodGroup.WasCompilerGenerated);
default:
return Create(receiver);
}
}
private IDynamicInvocationOperation CreateBoundDynamicInvocationExpressionOperation(BoundDynamicInvocation boundDynamicInvocation)
{
IOperation operation = CreateBoundDynamicInvocationExpressionReceiver(boundDynamicInvocation.Expression);
ImmutableArray<IOperation> arguments = CreateFromArray<BoundExpression, IOperation>(boundDynamicInvocation.Arguments);
ImmutableArray<string> argumentNames = boundDynamicInvocation.ArgumentNamesOpt.NullToEmpty();
ImmutableArray<RefKind> argumentRefKinds = boundDynamicInvocation.ArgumentRefKindsOpt.NullToEmpty();
SyntaxNode syntax = boundDynamicInvocation.Syntax;
ITypeSymbol? type = boundDynamicInvocation.GetPublicTypeSymbol();
bool isImplicit = boundDynamicInvocation.WasCompilerGenerated;
return new DynamicInvocationOperation(operation, arguments, argumentNames, argumentRefKinds, _semanticModel, syntax, type, isImplicit);
}
internal IOperation CreateBoundDynamicIndexerAccessExpressionReceiver(BoundExpression indexer)
{
switch (indexer)
{
case BoundDynamicIndexerAccess boundDynamicIndexerAccess:
return Create(boundDynamicIndexerAccess.Receiver);
case BoundObjectInitializerMember boundObjectInitializerMember:
return CreateImplicitReceiver(boundObjectInitializerMember.Syntax, boundObjectInitializerMember.ReceiverType);
default:
throw ExceptionUtilities.UnexpectedValue(indexer.Kind);
}
}
internal ImmutableArray<IOperation> CreateBoundDynamicIndexerAccessArguments(BoundExpression indexer)
{
switch (indexer)
{
case BoundDynamicIndexerAccess boundDynamicAccess:
return CreateFromArray<BoundExpression, IOperation>(boundDynamicAccess.Arguments);
case BoundObjectInitializerMember boundObjectInitializerMember:
return CreateFromArray<BoundExpression, IOperation>(boundObjectInitializerMember.Arguments);
default:
throw ExceptionUtilities.UnexpectedValue(indexer.Kind);
}
}
private IDynamicIndexerAccessOperation CreateBoundDynamicIndexerAccessExpressionOperation(BoundDynamicIndexerAccess boundDynamicIndexerAccess)
{
IOperation operation = CreateBoundDynamicIndexerAccessExpressionReceiver(boundDynamicIndexerAccess);
ImmutableArray<IOperation> arguments = CreateBoundDynamicIndexerAccessArguments(boundDynamicIndexerAccess);
ImmutableArray<string> argumentNames = boundDynamicIndexerAccess.ArgumentNamesOpt.NullToEmpty();
ImmutableArray<RefKind> argumentRefKinds = boundDynamicIndexerAccess.ArgumentRefKindsOpt.NullToEmpty();
SyntaxNode syntax = boundDynamicIndexerAccess.Syntax;
ITypeSymbol? type = boundDynamicIndexerAccess.GetPublicTypeSymbol();
bool isImplicit = boundDynamicIndexerAccess.WasCompilerGenerated;
return new DynamicIndexerAccessOperation(operation, arguments, argumentNames, argumentRefKinds, _semanticModel, syntax, type, isImplicit);
}
private IObjectOrCollectionInitializerOperation CreateBoundObjectInitializerExpressionOperation(BoundObjectInitializerExpression boundObjectInitializerExpression)
{
ImmutableArray<IOperation> initializers = CreateFromArray<BoundExpression, IOperation>(BoundObjectCreationExpression.GetChildInitializers(boundObjectInitializerExpression));
SyntaxNode syntax = boundObjectInitializerExpression.Syntax;
ITypeSymbol? type = boundObjectInitializerExpression.GetPublicTypeSymbol();
bool isImplicit = boundObjectInitializerExpression.WasCompilerGenerated;
return new ObjectOrCollectionInitializerOperation(initializers, _semanticModel, syntax, type, isImplicit);
}
private IObjectOrCollectionInitializerOperation CreateBoundCollectionInitializerExpressionOperation(BoundCollectionInitializerExpression boundCollectionInitializerExpression)
{
ImmutableArray<IOperation> initializers = CreateFromArray<BoundExpression, IOperation>(BoundObjectCreationExpression.GetChildInitializers(boundCollectionInitializerExpression));
SyntaxNode syntax = boundCollectionInitializerExpression.Syntax;
ITypeSymbol? type = boundCollectionInitializerExpression.GetPublicTypeSymbol();
bool isImplicit = boundCollectionInitializerExpression.WasCompilerGenerated;
return new ObjectOrCollectionInitializerOperation(initializers, _semanticModel, syntax, type, isImplicit);
}
private IOperation CreateBoundObjectInitializerMemberOperation(BoundObjectInitializerMember boundObjectInitializerMember, bool isObjectOrCollectionInitializer = false)
{
Symbol? memberSymbol = boundObjectInitializerMember.MemberSymbol;
SyntaxNode syntax = boundObjectInitializerMember.Syntax;
ITypeSymbol? type = boundObjectInitializerMember.GetPublicTypeSymbol();
bool isImplicit = boundObjectInitializerMember.WasCompilerGenerated;
if ((object?)memberSymbol == null)
{
Debug.Assert(boundObjectInitializerMember.Type.IsDynamic());
IOperation operation = CreateBoundDynamicIndexerAccessExpressionReceiver(boundObjectInitializerMember);
ImmutableArray<IOperation> arguments = CreateBoundDynamicIndexerAccessArguments(boundObjectInitializerMember);
ImmutableArray<string> argumentNames = boundObjectInitializerMember.ArgumentNamesOpt.NullToEmpty();
ImmutableArray<RefKind> argumentRefKinds = boundObjectInitializerMember.ArgumentRefKindsOpt.NullToEmpty();
return new DynamicIndexerAccessOperation(operation, arguments, argumentNames, argumentRefKinds, _semanticModel, syntax, type, isImplicit);
}
switch (memberSymbol.Kind)
{
case SymbolKind.Field:
var field = (FieldSymbol)memberSymbol;
bool isDeclaration = false;
return new FieldReferenceOperation(field.GetPublicSymbol(), isDeclaration, createReceiver(), _semanticModel, syntax, type, constantValue: null, isImplicit);
case SymbolKind.Event:
var eventSymbol = (EventSymbol)memberSymbol;
return new EventReferenceOperation(eventSymbol.GetPublicSymbol(), createReceiver(), _semanticModel, syntax, type, isImplicit);
case SymbolKind.Property:
var property = (PropertySymbol)memberSymbol;
ImmutableArray<IArgumentOperation> arguments;
if (!boundObjectInitializerMember.Arguments.IsEmpty)
{
// In nested member initializers, the property is not actually set. Instead, it is retrieved for a series of Add method calls or nested property setter calls,
// so we need to use the getter for this property
MethodSymbol? accessor = isObjectOrCollectionInitializer ? property.GetOwnOrInheritedGetMethod() : property.GetOwnOrInheritedSetMethod();
if (accessor == null || boundObjectInitializerMember.ResultKind == LookupResultKind.OverloadResolutionFailure || accessor.OriginalDefinition is ErrorMethodSymbol)
{
var children = CreateFromArray<BoundNode, IOperation>(((IBoundInvalidNode)boundObjectInitializerMember).InvalidNodeChildren);
return new InvalidOperation(children, _semanticModel, syntax, type, constantValue: null, isImplicit);
}
arguments = DeriveArguments(boundObjectInitializerMember, isObjectOrCollectionInitializer);
}
else
{
arguments = ImmutableArray<IArgumentOperation>.Empty;
}
return new PropertyReferenceOperation(property.GetPublicSymbol(), arguments, createReceiver(), _semanticModel, syntax, type, isImplicit);
default:
throw ExceptionUtilities.Unreachable;
}
IOperation? createReceiver() => memberSymbol?.IsStatic == true ?
null :
CreateImplicitReceiver(boundObjectInitializerMember.Syntax, boundObjectInitializerMember.ReceiverType);
}
private IOperation CreateBoundDynamicObjectInitializerMemberOperation(BoundDynamicObjectInitializerMember boundDynamicObjectInitializerMember)
{
IOperation instanceReceiver = CreateImplicitReceiver(boundDynamicObjectInitializerMember.Syntax, boundDynamicObjectInitializerMember.ReceiverType);
string memberName = boundDynamicObjectInitializerMember.MemberName;
ImmutableArray<ITypeSymbol> typeArguments = ImmutableArray<ITypeSymbol>.Empty;
ITypeSymbol containingType = boundDynamicObjectInitializerMember.ReceiverType.GetPublicSymbol();
SyntaxNode syntax = boundDynamicObjectInitializerMember.Syntax;
ITypeSymbol? type = boundDynamicObjectInitializerMember.GetPublicTypeSymbol();
bool isImplicit = boundDynamicObjectInitializerMember.WasCompilerGenerated;
return new DynamicMemberReferenceOperation(instanceReceiver, memberName, typeArguments, containingType, _semanticModel, syntax, type, isImplicit);
}
private IOperation CreateBoundCollectionElementInitializerOperation(BoundCollectionElementInitializer boundCollectionElementInitializer)
{
MethodSymbol addMethod = boundCollectionElementInitializer.AddMethod;
IOperation? receiver = CreateReceiverOperation(boundCollectionElementInitializer.ImplicitReceiverOpt, addMethod);
ImmutableArray<IArgumentOperation> arguments = DeriveArguments(boundCollectionElementInitializer);
SyntaxNode syntax = boundCollectionElementInitializer.Syntax;
ITypeSymbol? type = boundCollectionElementInitializer.GetPublicTypeSymbol();
ConstantValue? constantValue = boundCollectionElementInitializer.ConstantValue;
bool isImplicit = boundCollectionElementInitializer.WasCompilerGenerated;
if (IsMethodInvalid(boundCollectionElementInitializer.ResultKind, addMethod))
{
var children = CreateFromArray<BoundNode, IOperation>(((IBoundInvalidNode)boundCollectionElementInitializer).InvalidNodeChildren);
return new InvalidOperation(children, _semanticModel, syntax, type, constantValue, isImplicit);
}
bool isVirtual = IsCallVirtual(addMethod, boundCollectionElementInitializer.ImplicitReceiverOpt);
return new InvocationOperation(addMethod.GetPublicSymbol(), receiver, isVirtual, arguments, _semanticModel, syntax, type, isImplicit);
}
private IDynamicMemberReferenceOperation CreateBoundDynamicMemberAccessOperation(BoundDynamicMemberAccess boundDynamicMemberAccess)
{
return CreateBoundDynamicMemberAccessOperation(boundDynamicMemberAccess.Receiver, TypeMap.AsTypeSymbols(boundDynamicMemberAccess.TypeArgumentsOpt), boundDynamicMemberAccess.Name,
boundDynamicMemberAccess.Syntax, boundDynamicMemberAccess.GetPublicTypeSymbol(), boundDynamicMemberAccess.WasCompilerGenerated);
}
private IDynamicMemberReferenceOperation CreateBoundDynamicMemberAccessOperation(
BoundExpression? receiver,
ImmutableArray<TypeSymbol> typeArgumentsOpt,
string memberName,
SyntaxNode syntaxNode,
ITypeSymbol? type,
bool isImplicit)
{
ITypeSymbol? containingType = null;
if (receiver?.Kind == BoundKind.TypeExpression)
{
containingType = receiver.GetPublicTypeSymbol();
receiver = null;
}
ImmutableArray<ITypeSymbol> typeArguments = ImmutableArray<ITypeSymbol>.Empty;
if (!typeArgumentsOpt.IsDefault)
{
typeArguments = typeArgumentsOpt.GetPublicSymbols();
}
IOperation? instance = Create(receiver);
return new DynamicMemberReferenceOperation(instance, memberName, typeArguments, containingType, _semanticModel, syntaxNode, type, isImplicit);
}
private IDynamicInvocationOperation CreateBoundDynamicCollectionElementInitializerOperation(BoundDynamicCollectionElementInitializer boundCollectionElementInitializer)
{
IOperation operation = CreateBoundDynamicInvocationExpressionReceiver(boundCollectionElementInitializer.Expression);
ImmutableArray<IOperation> arguments = CreateFromArray<BoundExpression, IOperation>(boundCollectionElementInitializer.Arguments);
SyntaxNode syntax = boundCollectionElementInitializer.Syntax;
ITypeSymbol? type = boundCollectionElementInitializer.GetPublicTypeSymbol();
bool isImplicit = boundCollectionElementInitializer.WasCompilerGenerated;
return new DynamicInvocationOperation(operation, arguments, argumentNames: ImmutableArray<string>.Empty, argumentRefKinds: ImmutableArray<RefKind>.Empty, _semanticModel, syntax, type, isImplicit);
}
private IOperation CreateUnboundLambdaOperation(UnboundLambda unboundLambda)
{
// We want to ensure that we never see the UnboundLambda node, and that we don't end up having two different IOperation
// nodes for the lambda expression. So, we ask the semantic model for the IOperation node for the unbound lambda syntax.
// We are counting on the fact that will do the error recovery and actually create the BoundLambda node appropriate for
// this syntax node.
BoundLambda boundLambda = unboundLambda.BindForErrorRecovery();
return Create(boundLambda);
}
private IAnonymousFunctionOperation CreateBoundLambdaOperation(BoundLambda boundLambda)
{
IMethodSymbol symbol = boundLambda.Symbol.GetPublicSymbol();
IBlockOperation body = (IBlockOperation)Create(boundLambda.Body);
SyntaxNode syntax = boundLambda.Syntax;
bool isImplicit = boundLambda.WasCompilerGenerated;
return new AnonymousFunctionOperation(symbol, body, _semanticModel, syntax, isImplicit);
}
private ILocalFunctionOperation CreateBoundLocalFunctionStatementOperation(BoundLocalFunctionStatement boundLocalFunctionStatement)
{
IBlockOperation? body = (IBlockOperation?)Create(boundLocalFunctionStatement.Body);
IBlockOperation? ignoredBody = boundLocalFunctionStatement is { BlockBody: { }, ExpressionBody: { } exprBody }
? (IBlockOperation?)Create(exprBody)
: null;
IMethodSymbol symbol = boundLocalFunctionStatement.Symbol.GetPublicSymbol();
SyntaxNode syntax = boundLocalFunctionStatement.Syntax;
bool isImplicit = boundLocalFunctionStatement.WasCompilerGenerated;
return new LocalFunctionOperation(symbol, body, ignoredBody, _semanticModel, syntax, isImplicit);
}
private IOperation CreateBoundConversionOperation(BoundConversion boundConversion)
{
bool isImplicit = boundConversion.WasCompilerGenerated || !boundConversion.ExplicitCastInCode;
BoundExpression boundOperand = boundConversion.Operand;
if (boundConversion.ConversionKind == CSharp.ConversionKind.MethodGroup)
{
SyntaxNode syntax = boundConversion.Syntax;
ITypeSymbol? type = boundConversion.GetPublicTypeSymbol();
ConstantValue? constantValue = boundConversion.ConstantValue;
if (boundConversion.Type is FunctionPointerTypeSymbol)
{
Debug.Assert(boundConversion.SymbolOpt is object);
return new AddressOfOperation(
CreateBoundMethodGroupSingleMethodOperation((BoundMethodGroup)boundConversion.Operand, boundConversion.SymbolOpt, suppressVirtualCalls: false),
_semanticModel, syntax, type, boundConversion.WasCompilerGenerated);
}
// We don't check HasErrors on the conversion here because if we actually have a MethodGroup conversion,
// overload resolution succeeded. The resulting method could be invalid for other reasons, but we don't
// hide the resolved method.
IOperation target = CreateDelegateTargetOperation(boundConversion);
return new DelegateCreationOperation(target, _semanticModel, syntax, type, isImplicit);
}
else
{
SyntaxNode syntax = boundConversion.Syntax;
if (syntax.IsMissing)
{
// If the underlying syntax IsMissing, then that means we're in case where the compiler generated a piece of syntax to fill in for
// an error, such as this case:
//
// int i = ;
//
// Semantic model has a special case here that we match: if the underlying syntax is missing, don't create a conversion expression,
// and instead directly return the operand, which will be a BoundBadExpression. When we generate a node for the BoundBadExpression,
// the resulting IOperation will also have a null Type.
Debug.Assert(boundOperand.Kind == BoundKind.BadExpression ||
((boundOperand as BoundLambda)?.Body.Statements.SingleOrDefault() as BoundReturnStatement)?.
ExpressionOpt?.Kind == BoundKind.BadExpression);
return Create(boundOperand);
}
BoundConversion correctedConversionNode = boundConversion;
Conversion conversion = boundConversion.Conversion;
if (boundOperand.Syntax == boundConversion.Syntax)
{
if (boundOperand.Kind == BoundKind.ConvertedTupleLiteral && TypeSymbol.Equals(boundOperand.Type, boundConversion.Type, TypeCompareKind.ConsiderEverything2))
{