I recently started working with Data Flow Analysis APIs provided by Roslyn and find values presented in WrittenInside field and Locations field a bit ambiguous.
Consider below code snippet in Main method
1. int[] lcolSample = new int[10] { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4};
2. for (int lintCount1 = 0; lintCount1 < 10; lintCount1++)
3. {
4. Prog1(lintCount1);
5. int[] lcolSample1 = new int[10] { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 };
6. lintCount3 = lintCount3 + 100;
7. lintCount1 = lintCount1 + 2;
8. lcolSample[lintCount1-1] = lcolSample1[lintCount1] + 100;
9. }
If I perform DFA on for loop node, resulting Data Flow Analysis object never shows lcolSample[] in WrittenInside field as symbol that is written inside for loop. Reason being it is declared outside the node on which Dataflow analysis is performed. But, ReadInside field shows this symbol. Is there any way to know all the symbols that are modified/written inside a given node even though they are declared outside the node on which DFA is performed?
Variable lintCount1 is written twice (statement 2 and 7) and read twice. Locations property on lintCount1 shows only the place where it is declared (statement 2). Is there a way to find all the locations in which lintCount1 is written? Find all references of that symbol would give all the locations where the symbol is used, but I require the locations where it is written but not read.
This is my first question on this forum. Please ask for any other details if information provided above is not sufficient. Thanks in advance..
lcolSample
is never written inside the loop. However, it is read on line 8.