translate-c: add framework for special-casing macros

Some macros (for example any macro that uses token pasting) cannot be
directly translated to Zig, but may nevertheless still admit a Zig
implementation. This provides a mechanism for matching macros against
templates and mapping them to functions implemented in c_translation.zig.

A macro matches a template if it contains the same sequence of tokens, except
that the name and parameters may be renamed. No attempt is made to
semantically analyze the macro. For example the following two macros are
considered equivalent:

```C
```

But the following two are not:

```C
```
This commit is contained in:
Evan Haas
2021-06-17 17:52:26 -07:00
parent 18b8738069
commit dc4fa83dd7
4 changed files with 354 additions and 15 deletions

View File

@@ -3624,4 +3624,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
,
\\pub export var @"_": c_int = 42;
});
cases.add("Macro matching",
\\#define FOO(X) (X ## U)
, &[_][]const u8{
\\pub const FOO = @import("std").zig.c_translation.Macros.U_SUFFIX;
});
}