Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

checkTranslatableMacro

Translator.checkTranslatableMacro
fn checkTranslatableMacro(t: *Translator, tokens: []const CToken, params: []const []const u8) ?MacroTranslateError

File

lib/compiler/translate-c/Translator.zig:4328

Code

fn checkTranslatableMacro(t: *Translator, tokens: []const CToken, params: []const []const u8) ?MacroTranslateError {
    var last_is_type_kw = false;
    var i: usize = 0;
    while (i < tokens.len) : (i += 1) {
        const token = tokens[i];
        switch (token.id) {
            .period, .arrow => i += 1, // skip next token since field identifiers can be unknown
            .keyword_struct, .keyword_union, .keyword_enum => if (!last_is_type_kw) {
                last_is_type_kw = true;
                continue;
            },
            .macro_param, .macro_param_no_expand => {
                if (last_is_type_kw) {
                    return .{ .invalid_arg_usage = params[token.end] };
                }
            },
            .identifier, .extended_identifier => {
                const identifier = t.pp.tokSlice(token);
                if (!t.global_scope.contains(identifier) and !builtins.map.has(identifier)) {
                    return .{ .undefined_identifier = identifier };
                }
            },
            else => {},
        }
        last_is_type_kw = false;
    }
    return null;
}