Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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 standard library. Private Function

fullPtrTypeComponents

Private Function
std.zig.Ast.fullPtrTypeComponents
fn fullPtrTypeComponents(tree: Ast, info: full.PtrType.Components) full.PtrType

Params

File

zig/Ast.zig:2095
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
fn fullPtrTypeComponents(tree: Ast, info: full.PtrType.Components) full.PtrType {
    const size: std.lang.Type.Pointer.Size = switch (tree.tokenTag(info.main_token)) {
        .asterisk => .one,
        .l_bracket => switch (tree.tokenTag(info.main_token + 1)) {
            .asterisk => if (tree.tokenTag(info.main_token + 2) == .identifier) .c else .many,
            else => .slice,
        },
        else => unreachable,
    };
    var result: full.PtrType = .{
        .size = size,
        .allowzero_token = null,
        .const_token = null,
        .volatile_token = null,
        .duplicate_token = null,
        .ast = info,
    };
    // We need to be careful that we don't iterate over any sub-expressions
    // here while looking for modifiers as that could result in false
    // positives. Therefore, start after a sentinel if there is one and
    // skip over any align node and bit range nodes.
    var i = (if (info.sentinel.unwrap()) |sentinel| tree.lastToken(sentinel) + 1 else switch (size) {
        .one => info.main_token,
        .slice => info.main_token + 1,
        .many => info.main_token + 2,
        .c => info.main_token + 3,
    }) + 1;
    const end = tree.firstToken(info.child_type);
    while (i < end) : (i += 1) {
        switch (tree.tokenTag(i)) {
            .keyword_allowzero => {
                if (result.allowzero_token != null) {
                    result.duplicate_token = i;
                }
                result.allowzero_token = i;
            },
            .keyword_const => {
                if (result.const_token != null) {
                    result.duplicate_token = i;
                }
                result.const_token = i;
            },
            .keyword_volatile => {
                if (result.volatile_token != null) {
                    result.duplicate_token = i;
                }
                result.volatile_token = i;
            },
            .keyword_align => {
                if (info.bit_range_end.unwrap()) |bit_range_end| {
                    assert(info.bit_range_start != .none);
                    i = tree.lastToken(bit_range_end) + 1;
                } else if (info.align_node.unwrap()) |align_node| {
                    i = tree.lastToken(align_node) + 1;
                } else unreachable;
            },
            .keyword_addrspace => i = tree.lastToken(info.addrspace_node.unwrap().?) + 1,
            else => unreachable,
        }
    }
    return result;
}