Developers relax restrictions on a type to reuse methods with other types. While type casts are prevalent, in weakly typed languages such as C++, they are also extremely permissive. If type conversions are performed without care, they can lead to software bugs. Therefore, there is a clear need to check whether a type conversion is essential and used adequately according to the developer's intent. In this paper, we propose a technique to judge the fidelity of type conversions from an explicit cast operation, using the identifiers in an assignment. We measure accord in the identifiers using entropy and use it to check if the semantics of the source expression in the cast match the semantics of the variable it is being assigned. We present the results of running our tool on 34 components of the Chromium project, which collectively account for 27MLOC. Our tool identified 1,368 cases of discord indicating potential anti-patterns in the usage of explicit casts. We performed a manual evaluation of a random-uniform sample of these cases. Our evaluation shows that our tool identified 25.6% cases representing incorrect implementations of named casts and 28.04% cases representing imprecise names of identifiers.
翻译:开发者放松对类型的限制, 使用其他类型的再利用方法。 类型投影很普遍, 使用C++ 等类型类型语言, 类型投影也很普遍, 也非常允许。 如果类型转换不小心地进行, 可能会导致软件错误。 因此, 显然需要检查类型转换是否必要, 并且是否按照开发者的意图适当使用。 在本文中, 我们提出一种方法, 用任务中的标识符来判断类型转换的准确性。 我们使用一个任务中的标识符来测量标识符中的匹配性。 我们使用 entropy 来测量标识符中的匹配性, 并使用它来检查投影中源表达的语义是否匹配所指派变量的语义。 我们展示了在铬项目的34个组成部分上运行我们工具的结果, 共算出 27MLOC 。 我们的工具确定了1, 368个在使用明确投影器时可能出现反模式的不匹配情况。 我们用手评估了这些案例的随机不统一样本。 我们的评估显示, 我们的工具确定了25. 6% 代表不正确执行定模和28.04 % 标识符号的案例 。