{"id":24746553,"url":"https://github.com/samuelmarks/cdd-c","last_synced_at":"2026-06-07T03:01:36.736Z","repository":{"id":64136568,"uuid":"475630178","full_name":"SamuelMarks/cdd-c","owner":"SamuelMarks","description":"Frontend for C, concentrating on: generation from code; single-file analysis; modification; and emission (prettyprinting).","archived":false,"fork":false,"pushed_at":"2024-12-27T04:51:55.000Z","size":534,"stargazers_count":1,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-27T05:24:32.584Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SamuelMarks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-29T21:49:12.000Z","updated_at":"2024-12-27T04:51:59.000Z","dependencies_parsed_at":"2024-05-22T04:45:53.497Z","dependency_job_id":null,"html_url":"https://github.com/SamuelMarks/cdd-c","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelMarks%2Fcdd-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelMarks%2Fcdd-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelMarks%2Fcdd-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamuelMarks%2Fcdd-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SamuelMarks","download_url":"https://codeload.github.com/SamuelMarks/cdd-c/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235964702,"owners_count":19073476,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-28T04:29:15.796Z","updated_at":"2026-06-07T03:01:36.727Z","avatar_url":"https://github.com/SamuelMarks.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"cdd-c\n=====\n[![License](https://img.shields.io/badge/license-Apache--2.0%20OR%20MIT-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n[![interactive WASM web demo](https://img.shields.io/badge/interactive-WASM_web_demo-blue.svg)](https://offscale.io/wasm_web_demo)\n[![CI](https://github.com/SamuelMarks/cdd-c/actions/workflows/ci.yml/badge.svg)](https://github.com/SamuelMarks/cdd-c/actions)\n[![Test Coverage](https://img.shields.io/badge/test_coverage-100%25-brightgreen.svg)](#)\n[![Doc Coverage](https://img.shields.io/badge/doc_coverage-100%25-brightgreen.svg)](#)\n\n----\n\nOpenAPI ↔ C. This is one compiler in a suite, all focussed on the same task: Compiler Driven Development (CDD).\n\nEach compiler is written in its target language, is whitespace and comment sensitive, and has both an SDK and CLI.\n\nThe core philosophy of Compiler Driven Development (CDD) is synchronization without compromise. Where traditional generators silo your API boundaries into read-only files, this compiler natively merges changes into your codebase via a robust, [whitespace and comment aware] Abstract Syntax Tree (AST) driven parser \u0026 emitter. It bridges the gap between design and implementation, allowing you to seamlessly generate SDKs from a spec or extract a spec from existing code. By keeping your APIs, SDKs, and tests in continuous, automated alignment, it drastically improves both delivery speed and software reliability.\n\nThe CLI—at a minimum—has:\n\n- `cdd-c --help`\n- `cdd-c --version`\n- `cdd-c from_openapi to_sdk_cli -i spec.json`\n- `cdd-c from_openapi to_sdk -i spec.json`\n- `cdd-c from_openapi to_server -i spec.json`\n- `cdd-c to_openapi -f path/to/code`\n- `cdd-c to_docs_json --no-imports --no-wrapping -i spec.json`\n- `cdd-c serve_json_rpc --port 8080 --listen 127.0.0.1`\n\n## SDK Example\n\n```c\n#include \"cdd_api.h\"\n#include \u003cstdio.h\u003e\n\nint main() {\n    cdd_config config = {\n        .input_path = \"spec.json\",\n        .output_dir = \"src/models\"\n    };\n    cdd_generate_sdk(\u0026config);\n    printf(\"SDK generation complete.\\n\");\n    return 0;\n}\n```\n\n## Installation\n\n```bash\ncmake -B build \u0026\u0026 cmake --build build\n```\n\n## Development\n\nYou can use standard tooling commands or the included cross-platform Makefiles to fetch dependencies, build, and test:\n\n```bash\ncmake -B build \u0026\u0026 cmake --build build\nctest --test-dir build\n# or\nmake deps\nmake build\nmake test\n# or on Windows\n.\\make.bat deps\n.\\make.bat build\n.\\make.bat test\n```\n\nSee [PUBLISH.md](PUBLISH.md) for packaging and releasing.\n\n## Features\n\nThe `cdd-c` compiler leverages a unified architecture to support various facets of API and code lifecycle management. For a deep dive into the compiler's design, see [ARCHITECTURE.md](ARCHITECTURE.md).\n\n- **Compilation**:\n    - **OpenAPI → `C`**: Generate idiomatic native models, network routes, client SDKs, and boilerplate directly from OpenAPI (`.json` / `.yaml`) specifications.\n    - **`C` → OpenAPI**: Statically parse existing `C` source code and emit compliant OpenAPI specifications.\n- **Model Context Protocol (MCP)**: Run `cdd-c serve_json_rpc` to expose an MCP-compliant server via stdio or HTTP, allowing LLMs to seamlessly interface with your C codebase, understand types, and interact with the compiler.\n- **AST-Driven \u0026 Safe**: Employs static analysis instead of unsafe dynamic execution or reflection, allowing it to safely parse and emit code even for incomplete or un-compilable project states.\n- **Seamless Sync**: Keep your docs, tests, database, clients, and routing in perfect harmony. Update your code, and generate the docs; or update the docs, and generate the code.\n\n**Uncommon Features:**\n\n`cdd-c` is strictly a **superset** of the standard `cdd-${LANGUAGE}` features. In addition to standard OpenAPI code generation, it features a native, lossless C AST/CST framework. This enables powerful code transformations (like standardizing GNU extensions, porting to MSVC, and safe CRT rewriting) and memory safety auditing natively.\n\n- **Lossless AST Manipulation (Zero-Destruction Rule):** Perfectly captures and preserves \"trivia\"—inline comments, block comments, and exact whitespace (indentation, newlines).\n- **Built-in Security \u0026 Auditing:** Utilize the built-in `audit` command to run static analysis directly over your C directories. Detect dangerous CRT functions (`strcpy`, `sprintf`), dangling pointer risks, and missing initializations before they hit production.\n- **Safe CRT Transformation:** Automatically enforce safety by running the `safe_crt` transformer, which intelligently rewrites legacy string and memory operations to use bounds-checked equivalents (e.g., `strcpy_s`, `sprintf_s`).\n\n---\n\n## CLI Options\n\nUsage: `cdd-c \u003ccommand\u003e [args]`\n\n### `from_openapi`\n\nGenerate C SDK, Server, and optionally CLI from OpenAPI spec.\n\n```shell\ncdd-c from_openapi to_sdk -i \u003cspec.json\u003e [-o \u003cdir\u003e]\ncdd-c from_openapi to_sdk --input-dir \u003cspecs_dir\u003e [-o \u003cdir\u003e]\ncdd-c from_openapi to_sdk_cli -i \u003cspec.json\u003e [-o \u003cdir\u003e]\ncdd-c from_openapi to_sdk_cli --input-dir \u003cspecs_dir\u003e [-o \u003cdir\u003e]\ncdd-c from_openapi to_server -i \u003cspec.json\u003e [-o \u003cdir\u003e]\ncdd-c from_openapi to_server --input-dir \u003cspecs_dir\u003e [-o \u003cdir\u003e]\n```\n\n### `to_openapi`\n\nGenerate OpenAPI spec from C source code.\n\n```shell\ncdd-c to_openapi -i \u003cdir\u003e [-o \u003cout.json\u003e]\n```\n\n### `to_docs_json`\n\nGenerate JSON code examples for doc sites.\n\n```shell\ncdd-c to_docs_json [--no-imports] [--no-wrapping] -i|--input \u003cspec.json\u003e\n```\n\n### `audit`\n\nScan directory for memory safety issues.\n\n```shell\ncdd-c audit \u003cdirectory\u003e\n```\n\n### `c2openapi`\n\nGenerate OpenAPI spec from C source code.\n\n```shell\ncdd-c c2openapi \u003cdir\u003e \u003cout.json\u003e\n```\n\n### `transformer`\n\nRun syntax tree transformations.\n\n```shell\ncdd-c transformer \u003ctoolname\u003e [--audit|--fix] [--dry-run] \u003cfiles...\u003e\n```\n\n### `code2schema`\n\nConvert C header to JSON Schema.\n\n```shell\ncdd-c code2schema \u003cheader.h\u003e \u003cschema.json\u003e\n```\n\n### `generate_build_system`\n\nGenerate build system files.\n\n```shell\ncdd-c generate_build_system \u003ctype\u003e \u003cout_dir\u003e \u003cname\u003e [test_file]\n```\n\n### `schema2code`\n\nGenerate C code from JSON schema.\n\n```shell\ncdd-c schema2code \u003cschema.json\u003e \u003cout_dir\u003e\n```\n\n## Extensive Features \u0026 Functionality\n\n`cdd-c` is not just a standard parser; it is a full-fledged **Compiler Driven Development (CDD)** suite tailored specifically for `C` (strictly targeting ISO C90 compliance). It deeply understands C down to its comments and whitespace, treating codebase refactoring, code generation, and API alignment as first-class, lossless operations.\n\n### 1. Lossless AST Manipulation (Zero-Destruction Rule)\nUnlike standard preprocessors or regex-based refactoring tools, `cdd-c` uses a custom, highly robust **Concrete Syntax Tree (CST)** and **Abstract Syntax Tree (AST)** pipeline.\n- **Trivia Preservation:** It perfectly captures and preserves \"trivia\"—inline comments, block comments, and exact whitespace (indentation, newlines).\n- **Format-Safe Rewrites:** When you mutate a tree (for instance, converting a GNU compiler extension into a standard C89 equivalent), `cdd-c` applies the change surgically. Your code does not get butchered, formatted entirely differently, or stripped of its documentation. The generated ISO C code is meant for human developers, not just compilers.\n\n### 2. Multi-Directional Code Generation\n`cdd-c` acts as the master sync tool between your abstractions:\n- **API to Native C (SDK \u0026 Server):** Generate production-ready, memory-safe C clients, routing servers, and CLI argument parsers straight from OpenAPI JSON/YAML.\n- **Native C to OpenAPI:** Write your C functions, document them with standard block comments, and let `cdd-c` statically analyze the types and routes to reverse-engineer a perfectly compliant OpenAPI 3.x spec.\n- **SQL / JSON Schema Sync:** Seamlessly sync SQL DDL statements to C ORM layers, or JSON schemas directly into C structs and validation logic.\n\n### 3. Built-in Security \u0026 Auditing\n- **Memory Safety Audits:** Utilize the built-in `audit` command to run static analysis directly over your C directories. Detect dangerous CRT functions (`strcpy`, `sprintf`), dangling pointer risks, and missing initializations before they hit production.\n- **Safe CRT Transformation:** Automatically enforce safety by running the `safe_crt` transformer, which intelligently rewrites legacy string and memory operations to use bounds-checked equivalents (e.g., `strcpy_s`, `sprintf_s`).\n\n---\n\n## License\n\nLicensed under either of\n\n- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or \u003chttps://www.apache.org/licenses/LICENSE-2.0\u003e)\n- MIT license ([LICENSE-MIT](LICENSE-MIT) or \u003chttps://opensource.org/licenses/MIT\u003e)\n\nat your option.\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamuelmarks%2Fcdd-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamuelmarks%2Fcdd-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamuelmarks%2Fcdd-c/lists"}