Skip to main content
Glama

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
NameRequiredDescriptionDefault
codeYes

Implementation Reference

  • 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
  • Import of the checker factory required for the tool's operation.
    from cpp_style.tools.const_checker import get_checker as get_const_checker

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/SongJiangzhou/cpp_guidelines'

If you have feedback or need assistance with the MCP directory API, please join our Discord server