check_const_correctness
Analyze C++ code to identify missing const qualifiers and provide improvement suggestions for better const correctness.
Instructions
检查 C++ 代码中的 const 正确性
参数:
code: 要检查的 C++ 代码
返回:
const 正确性检查报告,包括缺少 const 的地方和改进建议
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes |
Implementation Reference
- cpp_style_server.py:128-142 (handler)The MCP tool handler and registration for 'check_const_correctness'. It retrieves the ConstCorrectnessChecker instance and invokes its check_const_correctness method to generate the report.@mcp.tool() def check_const_correctness(code: str) -> str: """ 检查 C++ 代码中的 const 正确性 参数: code: 要检查的 C++ 代码 返回: const 正确性检查报告,包括缺少 const 的地方和改进建议 """ checker = get_const_checker() issues, report = checker.check_const_correctness(code) return report
- Core logic implementing the const correctness checks by invoking specialized helper methods for member functions, parameters, return values, variables, and pointers/references, then generating a formatted report.def check_const_correctness(self, code: str) -> Tuple[List[Dict], str]: """ 检查代码中的 const 正确性 Args: code: 要检查的 C++ 代码 Returns: (问题列表, 格式化的检查报告) """ issues = [] # 检查各种 const 使用问题 issues.extend(self._check_member_functions(code)) issues.extend(self._check_parameters(code)) issues.extend(self._check_return_values(code)) issues.extend(self._check_variables(code)) issues.extend(self._check_pointers_refs(code)) # 生成报告 report = self._generate_report(issues) return issues, report
- Singleton factory function providing the ConstCorrectnessChecker instance used by the tool handler.def get_checker() -> ConstCorrectnessChecker: """获取全局 const 正确性检查器实例""" global _checker if _checker is None: _checker = ConstCorrectnessChecker() return _checker
- cpp_style_server.py:14-14 (registration)Import of the checker factory required for the tool's operation.from cpp_style.tools.const_checker import get_checker as get_const_checker