Skip to content

Commit d1b17a3

Browse files
committed
Manual: macro terminology
A first foray into recording terminology related to macros (and reparsing).
1 parent 1f1d6b2 commit d1b17a3

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

manual/low-level/terminology.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ for packing and [padding][t:padding].
5454
A [field][t:field] is declared inside a struct/union definition. This parent
5555
definition is called the *enclosing struct/union*.
5656

57+
### Expression macro
58+
59+
See [macro expression][t:macro_expr].
60+
5761
### Field
5862
[t:field]: #field
5963

@@ -66,6 +70,13 @@ declarations.
6670

6771
<https://en.cppreference.com/w/c/language/scope.html#File_scope>
6872

73+
### Function-like macro
74+
[t:function_like]: #function-like-macro
75+
76+
A *function-like* macro replaces each occurrence of that macro's name with its
77+
definition, additionally taking a list of named arguments, which replace
78+
corresponding occurrences of the argument name in the definition.
79+
6980
### Indirect field
7081

7182
[Fields][t:field] of an [anonymous struct/union][t:anon] can be accessed as if
@@ -81,6 +92,45 @@ struct/union][t:anon] rather than for the indirect fields.
8192

8293
</details>
8394

95+
### Macro
96+
[t:macro]: #macro
97+
98+
A (text) macro is a name associated with a replacement text.
99+
100+
### Macro definition
101+
[t:macro_def]: #macro-definition
102+
103+
A macro *definition* declares a name in the macro namespace with a replacement
104+
text. A macro can be [object-like][t:object_like] or
105+
[function-like][t:function_like]. Macro definitions might be
106+
[parsable][t:parsable_macro].
107+
108+
### Macro expansion
109+
[t:macro_expansion]: #macro-expansion
110+
111+
A C preprocessor *expands* macro [invocations][t:macro_inv], replacing
112+
invocations by their definition, which may be processed additionally depending
113+
on the type of the macro [definition][t:macro_def].
114+
115+
### Macro expression
116+
[t:macro_expr]: #macro-expression
117+
118+
A [macro][t:macro] that is parsed by `hs-bindgen` as a Haskell expression.
119+
120+
### Macro invocation
121+
[t:macro_inv]: #macro-invocation
122+
123+
A macro *invocation* references a macro definition by name so that it can be
124+
replaced by its definition. Macro invocations are [expanded][t:macro_expansion]
125+
by a C preprocessor. An [object-like][t:object_like] macro is invoked by
126+
referencing the macro's name. A [function-like][t:function_like] macro is
127+
invoked as if it is a function call.
128+
129+
### Macro type
130+
[t:macro_type]: #macro-type
131+
132+
A [macro][t:macro] that is parsed by `hs-bindgen` as a Haskell type.
133+
84134
### Named field
85135
[t:named_field]: #named-field
86136

@@ -96,6 +146,12 @@ called a *nested struct/union*. The nested struct/union can be
96146
scope][t:file_scope] as long as its [enclosing struct/union][t:enclosing] has
97147
file scope, which is usually if not always the case.
98148

149+
### Object-like macro
150+
[t:object_like]: #object-like-macro
151+
152+
An *object-like* macro replaces each occurrence of that macro's name with its
153+
definition.
154+
99155
### Padding
100156
[t:padding]: #padding
101157

@@ -110,6 +166,20 @@ Unnamed bit-fields are not translated to fields in the corresponding Haskell
110166
record in the generated Haskell bindings.
111167
</details>
112168

169+
### Parsable macro
170+
[t:parsable_macro]: #parsable-macro
171+
172+
A *parsable* macro is a macro definition that can be parsed as a [macro
173+
type][t:macro_type] or as a [macro expression][t:macro_expr].
174+
175+
### Reparsing
176+
[t:reparsing]: #reparsing
177+
178+
`hs-bindgen` parses headers once, and a subset of the headers is parsed a second
179+
time (those declarations that contain macro expansions). The second *reparse*
180+
inspects the source C code to augment the Haskell bindings with [macro
181+
types][t:macro_type].
182+
113183
### Tag
114184
[t:tag]: #tag
115185

@@ -120,6 +190,10 @@ to this name as a *tag*.
120190

121191
A struct or union or enum with a [tag][t:tag] is called *tagged*.
122192

193+
### Type macro
194+
195+
See [macro type][t:macro_type].
196+
123197
### Unnamed field
124198
[t:unnamed_field]: #unnamed-field
125199

0 commit comments

Comments
 (0)