renderPtrType
Function parameters
Parameters
Type definitions in this namespace
Types
Functions in this namespace
Functions
Error sets in this namespace
Error Sets
Source
Implementation
fn renderPtrType(r: *Render, ptr_type: Ast.full.PtrType, space: Space) Error!void {
const tree = r.tree;
const main_token = ptr_type.ast.main_token;
switch (ptr_type.size) {
.one => {
// Since ** tokens exist and the same token is shared by two
// nested pointer types, we check to see if we are the parent
// in such a relationship. If so, skip rendering anything for
// this pointer type and rely on the child to render our asterisk
// as well when it renders the ** token.
if (tree.tokenTag(main_token) == .asterisk_asterisk and
main_token == tree.nodeMainToken(ptr_type.ast.child_type))
{
return renderExpression(r, ptr_type.ast.child_type, space);
}
try renderToken(r, main_token, .none); // asterisk
},
.many => {
if (ptr_type.ast.sentinel.unwrap()) |sentinel| {
try renderToken(r, main_token, .none); // lbracket
try renderToken(r, main_token + 1, .none); // asterisk
try renderToken(r, main_token + 2, .none); // colon
try renderExpression(r, sentinel, .none);
try renderToken(r, tree.lastToken(sentinel) + 1, .none); // rbracket
} else {
try renderToken(r, main_token, .none); // lbracket
try renderToken(r, main_token + 1, .none); // asterisk
try renderToken(r, main_token + 2, .none); // rbracket
}
},
.c => {
try renderToken(r, main_token, .none); // lbracket
try renderToken(r, main_token + 1, .none); // asterisk
try renderToken(r, main_token + 2, .none); // c
try renderToken(r, main_token + 3, .none); // rbracket
},
.slice => {
if (ptr_type.ast.sentinel.unwrap()) |sentinel| {
try renderToken(r, main_token, .none); // lbracket
try renderToken(r, main_token + 1, .none); // colon
try renderExpression(r, sentinel, .none);
try renderToken(r, tree.lastToken(sentinel) + 1, .none); // rbracket
} else {
try renderToken(r, main_token, .none); // lbracket
try renderToken(r, main_token + 1, .none); // rbracket
}
},
}
if (ptr_type.allowzero_token) |allowzero_token| {
try renderToken(r, allowzero_token, .space);
}
if (ptr_type.ast.align_node.unwrap()) |align_node| {
const align_first = tree.firstToken(align_node);
try renderToken(r, align_first - 2, .none); // align
try renderToken(r, align_first - 1, .none); // lparen
try renderExpression(r, align_node, .none);
if (ptr_type.ast.bit_range_start.unwrap()) |bit_range_start| {
const bit_range_end = ptr_type.ast.bit_range_end.unwrap().?;
try renderToken(r, tree.firstToken(bit_range_start) - 1, .none); // colon
try renderExpression(r, bit_range_start, .none);
try renderToken(r, tree.firstToken(bit_range_end) - 1, .none); // colon
try renderExpression(r, bit_range_end, .none);
try renderToken(r, tree.lastToken(bit_range_end) + 1, .space); // rparen
} else {
try renderToken(r, tree.lastToken(align_node) + 1, .space); // rparen
}
}
if (ptr_type.ast.addrspace_node.unwrap()) |addrspace_node| {
const addrspace_first = tree.firstToken(addrspace_node);
try renderToken(r, addrspace_first - 2, .none); // addrspace
try renderToken(r, addrspace_first - 1, .none); // lparen
try renderExpression(r, addrspace_node, .none);
try renderToken(r, tree.lastToken(addrspace_node) + 1, .space); // rparen
}
if (ptr_type.const_token) |const_token| {
try renderToken(r, const_token, .space);
}
if (ptr_type.volatile_token) |volatile_token| {
try renderToken(r, volatile_token, .space);
}
try renderExpression(r, ptr_type.ast.child_type, space);
}