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..
Data Flow Analysis object never shows lcolSample[] in WrittenInside field as symbol that is written inside for loop
Yes, because that symbol is not written inside the loop (i.e. there is no lcolSample = whatever
there). An element of the array represented by the lcolSample
symbol is written in the loop, which is very different. I don't know how to find such writes using Roslyn's data flow analysis.
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?
The DataFlowAnalysis
object only gives you the symbols, accessing their Location
s doesn't make much sense (because that location has nothing to do with the data flow analysis).
To me, both your questions sound like reasonable feature requests, you might want to make them on the Roslyn repo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With