百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
F

fccf

> 编程语言
开源

fccf: 这是一个命令行工具,可根据搜索字符串快速搜索目录中的 C/C++ 源代码,并打印与之匹配的相关代码片段。

388 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

fccf: 这是一个命令行工具,可根据搜索字符串快速搜索目录中的 C/C++ 源代码,并打印与之匹配的相关代码片段。

fccf: Fast C/C++ Code Finder

fccf is a command-line tool that quickly searches through C/C++ source code in a directory based on a search string and prints relevant code snippets that match the query.

Highlights

  • Quickly identifies source files that contain a search string.
  • For each candidate source file, builds an abstract syntax tree (AST).
  • Visits the nodes in the AST, looking for function declarations, classes, enums, variables etc., that match the user's request.
  • Pretty-prints the identified snippet of source code to the terminal.
  • MIT License

Searching the Linux kernel source tree

The following video shows fccf searching and finding snippets of code in torvalds/linux.

https://user-images.githubusercontent.com/8450091/165400381-9ba49a62-97fb-4f4a-890a-0dc9b20dfe75.mp4

Searching the fccf source tree (Modern C++)

The following video shows fccf searching the fccf C++ source code.

Note that search results here include:

  1. Class declaration
  2. Functions and function templates
  3. Variable declarations, including lambda functions

https://user-images.githubusercontent.com/8450091/165402206-65d9ed43-b9dd-4528-92bd-0b4ce76b6468.mp4

Search for any of --flag that matches

Provide an empty query to match any --flag, e.g., any enum declaration.

... or any class constructor

Searching a for statement

Use --for-statement to search for statements. fccf will try to find for statements (including C++ ranged for) that contain the query string.

Searching expressions

Use the --include-expressions option to find expressions that match the query.

The following example shows fccf find calls to isdigit().

The following example shows fccf finding references to the clang_options variable.

Searching for using declarations

Use the --using-declaration option to find using declarations, using directives, and type alias declarations.

Searching for namespace aliases

Use the --namespace-alias option to find namespace aliases.

Searching for throw expressions

Use --throw-expression with a query to search for specific throw expressions that contain the query string.

As presented earlier, an empty query here will attempt to match any throw expression in the code base:

Build Instructions

Build fccf using CMake. For more details, see BUILDING.md.

NOTE: fccf requires libclang and LLVM installed.

bash
# Install libclang and LLVM
# sudo apt install libclang-dev llvm

git clone https://github.com/p-ranav/fccf
cd fccf

# Build
cmake -S . -B build -D CMAKE_BUILD_TYPE=Release
cmake --build build

# Install
sudo cmake --install build

fccf Usage

…

How it works

  1. fccf does a recursive directory search for a needle in a haystack - like grep or ripgrep - It uses an SSE2 strstr SIMD algorithm (modified Rabin-Karp SIMD search; see here) if possible to quickly find, in multiple threads, a subset of the source files in the directory that contain a needle.
  2. For each candidate source file, it uses libclang to parse the translation unit (build an abstract syntax tree).
  3. Then it visits each child node in the AST, looking for specific node types, e.g., CXCursor_FunctionDecl for function declarations.
  4. Once the relevant nodes are identified, if the node's "spelling" (libclang name for the node) matches the search query, then the source range of the AST node is identified - source range is the start and end index of the snippet of code in the buffer
  5. Then, it pretty-prints this snippet of code. I have a simple lexer that tokenizes this code and prints colored output.

Note on include_directories

For all this to work, fccf first identifies candidate directories that contain header files, e.g., paths that end with include/. It then adds these paths to the clang options (before parsing the translation unit) as -Ifoo -Ibar/baz etc. Additionally, for each translation unit, the parent and grandparent paths are also added to the include directories for that unit in order to increase the likelihood of successful parsing.

Additional include directories can also be provided to fccf using the -I or --include-dir option. Using verbose output (--verbose), errors in the libclang parsing can be identified and fixes can be attempted (e.g., adding the right include directories so that libclang is happy).

To run fccf on the fccf source code without any libclang errors, I had to explicitly provide the include path from LLVM-12 like so:

…

References

  1. SIMD-friendly algorithms for substring searching
  2. libclang: C Interface to Clang

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++abstract-syntax-treec-languagec-programmingclang

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言