From 365e185606a8bb14841e7d21c7855deaaf35693f Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 18 Dec 2023 00:06:18 +0100 Subject: [PATCH] docs: document header structure Reference: https://github.com/neovim/neovim/issues/6371 --- runtime/doc/dev_style.txt | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/runtime/doc/dev_style.txt b/runtime/doc/dev_style.txt index ee8a2a3c3b..05dc727130 100644 --- a/runtime/doc/dev_style.txt +++ b/runtime/doc/dev_style.txt @@ -41,6 +41,43 @@ All header files should start with `#pragma once` to prevent multiple inclusion. #pragma once < +Headers system ~ + +Nvim uses two types of headers. There are "normal" headers and "defs" headers. +Typically, each normal header will have a corresponding defs header, e.g. +`fileio.h` and `fileio_defs.h`. This distinction is done to minimize +recompilation on change. The goal is to achieve the following: + +- All headers (defs and normal) must include only defs headers, system + headers, and generated declarations. In other words, headers must not + include normal headers. + +- Source (.c) files may include all headers, but should only include normal + headers if they need symbols and not types. + +Use the following guideline to determine what to put where: + +Symbols: + - regular function declarations + - `extern` variables (including the `EXTERN` macro) + +Non-symbols: + - macros, i.e. `#define`. + - static inline functions, but only if its function declaration has a + `REAL_FATTR_ALWAYS_INLINE` attribute. + - typedefs + - structs + - enums + + +- All symbols must be moved to normal headers. + +- Non-symbols used by multiple headers should be moved to defs headers. This + is to ensure headers only include defs headers. Conversely, non-symbols used + by only a single header should be moved to that header. + +- EXCEPTION: if the macro calls a function, then it must be moved to a normal + header. Constants ~