fn renderPtrType(r: *Render, ptr_type: Ast.full.PtrType, space: Space) Error!void OutOfMemoryRan out of memory allocating call stack frames to complete rendering.
WriteFailedTransitive failure from
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130fn 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 => {
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
}
},
}
// .maybe_space cannot be used at the end of each qualifier since they may be reordered
const final_qual: enum {
@"volatile",
@"const",
@"addrspace",
@"align",
@"allowzero",
none,
} = if (ptr_type.volatile_token != null)
.@"volatile"
else if (ptr_type.const_token != null)
.@"const"
else if (ptr_type.ast.addrspace_node != .none)
.@"addrspace"
else if (ptr_type.ast.align_node != .none)
.@"align"
else if (ptr_type.allowzero_token != null)
.@"allowzero"
else
.none;
const final_qual_space: Space = if (tree.tokenTag(tree.firstToken(ptr_type.ast.child_type)) !=
.multiline_string_literal_line) .space else .none;
if (ptr_type.allowzero_token) |allowzero_token| {
const this_space: Space = if (final_qual == .@"allowzero") final_qual_space else .space;
try renderToken(r, allowzero_token, this_space);
}
if (ptr_type.ast.align_node.unwrap()) |align_node| {
const this_space: Space = if (final_qual == .@"align") final_qual_space else .space;
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, this_space); // rparen
} else {
try renderToken(r, tree.lastToken(align_node) + 1, this_space); // rparen
}
}
if (ptr_type.ast.addrspace_node.unwrap()) |addrspace_node| {
const this_space: Space = if (final_qual == .@"addrspace") final_qual_space else .space;
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, this_space); // rparen
}
if (ptr_type.const_token) |const_token| {
const this_space: Space = if (final_qual == .@"const") final_qual_space else .space;
try renderToken(r, const_token, this_space);
}
if (ptr_type.volatile_token) |volatile_token| {
const this_space: Space = if (final_qual == .@"volatile") final_qual_space else unreachable;
try renderToken(r, volatile_token, this_space);
}
try renderExpression(r, ptr_type.ast.child_type, space);
}