Roslyn数据流分析-WrittenInside和Locations字段的值不明确

本文关键字:不明确 字段 Locations 数据流分析 -WrittenInside Roslyn | 更新日期: 2023-09-27 18:20:26

我最近开始使用Roslyn提供的数据流分析API,发现WrittenInside字段和Locations字段中的值有点模糊。

考虑主方法中的以下代码片段

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. }
  1. 如果我对循环节点执行DFA,则生成的Data Flow Analysis对象在WrittenInside字段中永远不会将lcolSample[]显示为循环内部写入的符号。原因是它是在执行数据流分析的节点外部声明的。但是,ReadInside字段显示了这个符号。是否有任何方法可以知道在给定节点内修改/写入的所有符号,即使它们是在执行DFA的节点外声明的?

  2. 变量lintCount1写入两次(语句2和7),读取两次。lintCount1上的Locations属性只显示声明它的位置(语句2)。有没有办法找到写lintCount1的所有位置?查找该符号的所有引用将给出该符号使用的所有位置,但我需要它被写入但未被读取的位置。

这是我在这个论坛上的第一个问题。如果上述信息不足,请询问其他详细信息。提前谢谢。。

Roslyn数据流分析-WrittenInside和Locations字段的值不明确

数据流分析对象从不将WrittenInside字段中的lcolSample[]显示为写入循环内部的符号

是的,因为该符号没有写在循环内部(即没有lcolSample = whatever)。由lcolSample符号表示的数组中的一个元素被写入循环中,这是非常不同的。我不知道如何使用Roslyn的数据流分析来找到这样的写入。

lintCount1上的Locations属性只显示声明它的位置(语句2)。有没有办法找到写lintCount1的所有位置?

DataFlowAnalysis对象只提供符号,访问它们的Location没有多大意义(因为该位置与数据流分析无关)。

对我来说,你的两个问题听起来都是合理的功能请求,你可能想在Roslyn回购中提出。