OpenSTA/.cursor/rules/cpp-coding-standards.mdc

67 lines
3.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
description: C++ coding standards and formatting for OpenSTA
globs: ["**/*.cc", "**/*.hh", "**/*.h"]
alwaysApply: true
---
# C++ Coding Standards
## File-internal helpers (translation-unit local)
- For helpers used only in one `.cc` file, put them in the **same namespace** as the rest of the implementation (e.g. `namespace sta { ... }`).
- Mark them **`static`** at namespace scope so they have internal linkage.
- **Do not** wrap them in an **anonymous namespace** in this project (no `namespace { ... }` file-static helpers). The user preference is `static` inside the real namespace, not a nested anonymous namespace inside `sta` or at file scope before `sta`.
## Line Width
- **Keep lines under 90 characters** to match `.clang-format` (ColumnLimit: 90).
- Only break a line when it would exceed 90 characters. Do not introduce unnecessary line breaks when the expression fits on one line.
- When a break is needed, break at logical points: after commas, before operators. Keep the first argument on the same line as the opening paren (do not break immediately after an opening paren).
## Naming Conventions
- **Classes**: Upper camel case (`ClassName`)
- **Member functions**: Lower camel case (`memberFunction`)
- **Member variables**: Snake case with trailing underscore (`member_variable_`)
- **Functions**: Lower camel case (`functionName`)
- **Variables**: Snake case
## Code Style
- Use `#pragma once` for header guards.
- Return type on the line before the function name; arguments on separate lines when long.
- No braces for single-line if/for; use braces for multi-line bodies.
- Prefer `std::string` over `char*` for string members.
- Prefer pass-by-value and move for sink parameters (parameters that get stored).
## File Extensions
- C++ source: `.cc`
- C++ headers: `.hh`
## Include order
Sort `#include` lines **lexicographically by the path inside** `<>`
or `""` (case-sensitive). Separate **groups** with a single blank line.
### Translation units (`*.cc`)
1. **Primary header(s)** for this file only:
- `#include "Stem.hh"` where `Stem` matches the basename of the `.cc` file (e.g. `Foo.cc` → `Foo.hh`).
- If the file uses a paired private header, include `#include "StemPvt.hh"` **immediately after** `Stem.hh` (e.g. `MakeTimingModel.cc` → `MakeTimingModel.hh` then `MakeTimingModelPvt.hh`).
- Do **not** pull in other headers just because their names share a prefix with `Stem` (e.g. `SearchClass.hh` is not a “primary” include for `Search.cc`; it belongs in the project group below).
2. **System / standard library** headers: `#include <...>` lines, sorted alphabetically.
3. **All other project** headers: `#include "..."` lines, sorted alphabetically (including `search/Crpr.hh`-style paths and includes from `liberty/`, etc.).
If a **comment or special block** intentionally splits the include list (e.g. a third-party note before `#include "cudd.h"`), keep that structure; sort only within each contiguous run of `#include` lines unless merging groups is clearly safe.
### Headers (`*.hh`)
After `#pragma once` (and the files license block, if present):
1. **System** `#include <...>` lines, sorted alphabetically.
2. **Project** `#include "..."` lines, sorted alphabetically.