mirror of
https://github.com/roc-lang/roc.git
synced 2025-12-23 08:48:03 +00:00
WIP
This commit is contained in:
parent
8174e2b7a8
commit
5b739ad2d7
11 changed files with 200 additions and 170 deletions
|
|
@ -90,9 +90,13 @@ fn benchParseOrTokenize(comptime is_parse: bool, gpa: Allocator, path: []const u
|
|||
|
||||
// ModuleEnv takes ownership of the source code, so we need to dupe it each iteration
|
||||
const source_copy = try gpa.dupe(u8, roc_file.content);
|
||||
var parse_env = try ModuleEnv.init(gpa, source_copy);
|
||||
|
||||
var ir = try parse.parse(&parse_env);
|
||||
var common_env1 = try CommonEnv.init(gpa, source_copy);
|
||||
defer common_env1.deinit(gpa);
|
||||
|
||||
var parse_env = try ModuleEnv.init(gpa, &common_env1);
|
||||
|
||||
var ir = try parse.parse(&common_env1, gpa);
|
||||
iteration_tokens += ir.tokens.tokens.len;
|
||||
ir.deinit(gpa);
|
||||
parse_env.deinit();
|
||||
|
|
@ -101,11 +105,11 @@ fn benchParseOrTokenize(comptime is_parse: bool, gpa: Allocator, path: []const u
|
|||
var messages: [128]tokenize.Diagnostic = undefined;
|
||||
const msg_slice = messages[0..];
|
||||
|
||||
var tokenizer = try tokenize.Tokenizer.init(&env.?, roc_file.content, msg_slice);
|
||||
try tokenizer.tokenize();
|
||||
var result = tokenizer.finishAndDeinit();
|
||||
var tokenizer = try tokenize.Tokenizer.init(env.?.common, gpa, roc_file.content, msg_slice);
|
||||
try tokenizer.tokenize(gpa);
|
||||
var result = tokenizer.finishAndDeinit(gpa);
|
||||
iteration_tokens += result.tokens.tokens.len;
|
||||
result.tokens.deinit();
|
||||
result.tokens.deinit(gpa);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1827,3 +1827,7 @@ pub fn initTypeWriter(self: *Self) std.mem.Allocator.Error!TypeWriter {
|
|||
pub fn insertIdent(self: *Self, ident: Ident) std.mem.Allocator.Error!Ident.Idx {
|
||||
return try self.common.insertIdent(self.gpa, ident);
|
||||
}
|
||||
|
||||
pub fn getLineStarts(self: *const Self) []const u32 {
|
||||
return self.common.getLineStartsAll();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ pub const problem = @import("problem.zig");
|
|||
|
||||
pub const Check = @import("Check.zig");
|
||||
|
||||
pub const ReportBuilder = problem.ReportBuilder;
|
||||
|
||||
test "check tests" {
|
||||
std.testing.refAllDecls(@import("Check.zig"));
|
||||
std.testing.refAllDecls(@import("copy_import.zig"));
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ pub const ReportBuilder = struct {
|
|||
|
||||
gpa: Allocator,
|
||||
buf: std.ArrayList(u8),
|
||||
module_env: *const ModuleEnv,
|
||||
module_env: *ModuleEnv,
|
||||
can_ir: *const ModuleEnv,
|
||||
snapshots: *const snapshot.Store,
|
||||
source: []const u8,
|
||||
|
|
@ -190,7 +190,7 @@ pub const ReportBuilder = struct {
|
|||
/// Only owned field is `buf`
|
||||
pub fn init(
|
||||
gpa: Allocator,
|
||||
module_env: *const ModuleEnv,
|
||||
module_env: *ModuleEnv,
|
||||
can_ir: *const ModuleEnv,
|
||||
snapshots: *const snapshot.Store,
|
||||
filename: []const u8,
|
||||
|
|
@ -202,7 +202,7 @@ pub const ReportBuilder = struct {
|
|||
.module_env = module_env,
|
||||
.can_ir = can_ir,
|
||||
.snapshots = snapshots,
|
||||
.source = module_env.source,
|
||||
.source = module_env.common.source,
|
||||
.filename = filename,
|
||||
.other_modules = other_modules,
|
||||
};
|
||||
|
|
@ -225,7 +225,7 @@ pub const ReportBuilder = struct {
|
|||
var snapshot_writer = snapshot.SnapshotWriter.initWithContext(
|
||||
self.buf.writer(),
|
||||
self.snapshots,
|
||||
&self.module_env.idents,
|
||||
self.module_env.getIdentStore(),
|
||||
self.can_ir.module_name,
|
||||
self.can_ir,
|
||||
self.other_modules,
|
||||
|
|
@ -316,7 +316,7 @@ pub const ReportBuilder = struct {
|
|||
.error_highlight,
|
||||
self.filename,
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
);
|
||||
try report.document.addLineBreak();
|
||||
|
||||
|
|
@ -408,7 +408,7 @@ pub const ReportBuilder = struct {
|
|||
|
||||
const overall_region_info = base.RegionInfo.position(
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
overall_start_offset,
|
||||
overall_end_offset,
|
||||
) catch return report;
|
||||
|
|
@ -416,21 +416,21 @@ pub const ReportBuilder = struct {
|
|||
// Get region info for both elements
|
||||
const actual_region_info = base.RegionInfo.position(
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
actual_region.start.offset,
|
||||
actual_region.end.offset,
|
||||
) catch return report;
|
||||
|
||||
const expected_region_info = base.RegionInfo.position(
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
expected_region.start.offset,
|
||||
expected_region.end.offset,
|
||||
) catch return report;
|
||||
|
||||
// Create the display region
|
||||
const display_region = SourceCodeDisplayRegion{
|
||||
.line_text = self.gpa.dupe(u8, overall_region_info.calculateLineText(self.source, self.module_env.line_starts.items.items)) catch return report,
|
||||
.line_text = self.gpa.dupe(u8, overall_region_info.calculateLineText(self.source, self.module_env.getLineStarts())) catch return report,
|
||||
.start_line = overall_region_info.start_line_idx + 1,
|
||||
.start_column = overall_region_info.start_col_idx + 1,
|
||||
.end_line = overall_region_info.end_line_idx + 1,
|
||||
|
|
@ -518,14 +518,14 @@ pub const ReportBuilder = struct {
|
|||
const actual_region = self.can_ir.store.regions.get(@enumFromInt(@intFromEnum(types.actual_var)));
|
||||
const actual_region_info = base.RegionInfo.position(
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
actual_region.start.offset,
|
||||
actual_region.end.offset,
|
||||
) catch return report;
|
||||
|
||||
// Create the display region
|
||||
const display_region = SourceCodeDisplayRegion{
|
||||
.line_text = self.gpa.dupe(u8, actual_region_info.calculateLineText(self.source, self.module_env.line_starts.items.items)) catch return report,
|
||||
.line_text = self.gpa.dupe(u8, actual_region_info.calculateLineText(self.source, self.module_env.getLineStarts())) catch return report,
|
||||
.start_line = actual_region_info.start_line_idx + 1,
|
||||
.start_column = actual_region_info.start_col_idx + 1,
|
||||
.end_line = actual_region_info.end_line_idx + 1,
|
||||
|
|
@ -630,7 +630,7 @@ pub const ReportBuilder = struct {
|
|||
|
||||
const overall_region_info = base.RegionInfo.position(
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
overall_start_offset,
|
||||
overall_end_offset,
|
||||
) catch return report;
|
||||
|
|
@ -638,14 +638,14 @@ pub const ReportBuilder = struct {
|
|||
// Get region info for invalid branch
|
||||
const actual_region_info = base.RegionInfo.position(
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
actual_region.start.offset,
|
||||
actual_region.end.offset,
|
||||
) catch return report;
|
||||
|
||||
// Create the display region
|
||||
const display_region = SourceCodeDisplayRegion{
|
||||
.line_text = self.gpa.dupe(u8, overall_region_info.calculateLineText(self.source, self.module_env.line_starts.items.items)) catch return report,
|
||||
.line_text = self.gpa.dupe(u8, overall_region_info.calculateLineText(self.source, self.module_env.getLineStarts())) catch return report,
|
||||
.start_line = overall_region_info.start_line_idx + 1,
|
||||
.start_column = overall_region_info.start_col_idx + 1,
|
||||
.end_line = overall_region_info.end_line_idx + 1,
|
||||
|
|
@ -765,7 +765,7 @@ pub const ReportBuilder = struct {
|
|||
const match_expr_region = self.can_ir.store.regions.get(@enumFromInt(@intFromEnum(data.match_expr)));
|
||||
const overall_region_info = base.RegionInfo.position(
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
match_expr_region.start.offset,
|
||||
match_expr_region.end.offset,
|
||||
) catch return report;
|
||||
|
|
@ -774,14 +774,14 @@ pub const ReportBuilder = struct {
|
|||
const invalid_var_region = self.can_ir.store.regions.get(@enumFromInt(@intFromEnum(types.actual_var)));
|
||||
const invalid_var_region_info = base.RegionInfo.position(
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
invalid_var_region.start.offset,
|
||||
invalid_var_region.end.offset,
|
||||
) catch return report;
|
||||
|
||||
// Create the display region
|
||||
const display_region = SourceCodeDisplayRegion{
|
||||
.line_text = self.gpa.dupe(u8, overall_region_info.calculateLineText(self.source, self.module_env.line_starts.items.items)) catch return report,
|
||||
.line_text = self.gpa.dupe(u8, overall_region_info.calculateLineText(self.source, self.module_env.getLineStarts())) catch return report,
|
||||
.start_line = overall_region_info.start_line_idx + 1,
|
||||
.start_column = overall_region_info.start_col_idx + 1,
|
||||
.end_line = overall_region_info.end_line_idx + 1,
|
||||
|
|
@ -887,14 +887,14 @@ pub const ReportBuilder = struct {
|
|||
|
||||
const overall_region_info = base.RegionInfo.position(
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
overall_start_offset,
|
||||
overall_end_offset,
|
||||
) catch return report;
|
||||
|
||||
// Create the display region
|
||||
const display_region = SourceCodeDisplayRegion{
|
||||
.line_text = self.gpa.dupe(u8, overall_region_info.calculateLineText(self.source, self.module_env.line_starts.items.items)) catch return report,
|
||||
.line_text = self.gpa.dupe(u8, overall_region_info.calculateLineText(self.source, self.module_env.getLineStarts())) catch return report,
|
||||
.start_line = overall_region_info.start_line_idx + 1,
|
||||
.start_column = overall_region_info.start_col_idx + 1,
|
||||
.end_line = overall_region_info.end_line_idx + 1,
|
||||
|
|
@ -906,7 +906,7 @@ pub const ReportBuilder = struct {
|
|||
// Create underline regions
|
||||
const this_branch_region_info = base.RegionInfo.position(
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
this_branch_region.start.offset,
|
||||
this_branch_region.end.offset,
|
||||
) catch return report;
|
||||
|
|
@ -989,14 +989,14 @@ pub const ReportBuilder = struct {
|
|||
|
||||
const overall_region_info = base.RegionInfo.position(
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
overall_start_offset,
|
||||
overall_end_offset,
|
||||
) catch return report;
|
||||
|
||||
// Create the display region
|
||||
const display_region = SourceCodeDisplayRegion{
|
||||
.line_text = self.gpa.dupe(u8, overall_region_info.calculateLineText(self.source, self.module_env.line_starts.items.items)) catch return report,
|
||||
.line_text = self.gpa.dupe(u8, overall_region_info.calculateLineText(self.source, self.module_env.getLineStarts())) catch return report,
|
||||
.start_line = overall_region_info.start_line_idx + 1,
|
||||
.start_column = overall_region_info.start_col_idx + 1,
|
||||
.end_line = overall_region_info.end_line_idx + 1,
|
||||
|
|
@ -1008,7 +1008,7 @@ pub const ReportBuilder = struct {
|
|||
// Create underline regions
|
||||
const this_branch_region_info = base.RegionInfo.position(
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
problem_side_region.start.offset,
|
||||
problem_side_region.end.offset,
|
||||
) catch return report;
|
||||
|
|
@ -1088,7 +1088,7 @@ pub const ReportBuilder = struct {
|
|||
.error_highlight,
|
||||
self.filename,
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
);
|
||||
try report.document.addLineBreak();
|
||||
|
||||
|
|
@ -1186,7 +1186,7 @@ pub const ReportBuilder = struct {
|
|||
.error_highlight,
|
||||
self.filename,
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
);
|
||||
try report.document.addLineBreak();
|
||||
|
||||
|
|
@ -1263,7 +1263,7 @@ pub const ReportBuilder = struct {
|
|||
.error_highlight,
|
||||
self.filename,
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
);
|
||||
try report.document.addLineBreak();
|
||||
|
||||
|
|
@ -1300,7 +1300,7 @@ pub const ReportBuilder = struct {
|
|||
.error_highlight,
|
||||
self.filename,
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
);
|
||||
try report.document.addLineBreak();
|
||||
|
||||
|
|
@ -1342,7 +1342,7 @@ pub const ReportBuilder = struct {
|
|||
.error_highlight,
|
||||
self.filename,
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
);
|
||||
try report.document.addLineBreak();
|
||||
|
||||
|
|
@ -1378,14 +1378,14 @@ pub const ReportBuilder = struct {
|
|||
// Get region info for the import
|
||||
const import_region_info = base.RegionInfo.position(
|
||||
self.source,
|
||||
self.module_env.line_starts.items.items,
|
||||
self.module_env.getLineStarts(),
|
||||
import_region.start.offset,
|
||||
import_region.end.offset,
|
||||
) catch return report;
|
||||
|
||||
// Create the display region
|
||||
const display_region = SourceCodeDisplayRegion{
|
||||
.line_text = self.gpa.dupe(u8, import_region_info.calculateLineText(self.source, self.module_env.line_starts.items.items)) catch return report,
|
||||
.line_text = self.gpa.dupe(u8, import_region_info.calculateLineText(self.source, self.module_env.getLineStarts())) catch return report,
|
||||
.start_line = import_region_info.start_line_idx + 1,
|
||||
.start_column = import_region_info.start_col_idx + 1,
|
||||
.end_line = import_region_info.end_line_idx + 1,
|
||||
|
|
@ -1412,7 +1412,7 @@ pub const ReportBuilder = struct {
|
|||
const module_idx = @intFromEnum(data.module_idx);
|
||||
const module_name = if (module_idx < self.can_ir.imports.imports.len()) blk: {
|
||||
const import_string_idx = self.can_ir.imports.imports.items.items[module_idx];
|
||||
const import_name = self.can_ir.strings.get(import_string_idx);
|
||||
const import_name = self.can_ir.getString(import_string_idx);
|
||||
break :blk import_name;
|
||||
} else null;
|
||||
|
||||
|
|
|
|||
|
|
@ -753,7 +753,7 @@ pub const SnapshotWriter = struct {
|
|||
switch (content) {
|
||||
.flex_var => |mb_ident_idx| {
|
||||
if (mb_ident_idx) |ident_idx| {
|
||||
_ = try self.writer.write(self.getIdent(ident_idx));
|
||||
_ = try self.writer.write(self.idents.getText(ident_idx));
|
||||
} else {
|
||||
// Check if this variable appears multiple times
|
||||
const occurrences = self.countOccurrences(current_idx, root_idx);
|
||||
|
|
@ -764,7 +764,7 @@ pub const SnapshotWriter = struct {
|
|||
}
|
||||
},
|
||||
.rigid_var => |ident_idx| {
|
||||
_ = try self.writer.write(self.getIdent(ident_idx));
|
||||
_ = try self.writer.write(self.idents.getText(ident_idx));
|
||||
},
|
||||
.alias => |alias| {
|
||||
try self.writeAlias(alias, root_idx);
|
||||
|
|
@ -780,7 +780,7 @@ pub const SnapshotWriter = struct {
|
|||
|
||||
/// Write an alias type
|
||||
pub fn writeAlias(self: *Self, alias: SnapshotAlias, root_idx: SnapshotContentIdx) Allocator.Error!void {
|
||||
_ = try self.writer.write(self.getIdent(alias.ident.ident_idx));
|
||||
_ = try self.writer.write(self.idents.getText(alias.ident.ident_idx));
|
||||
|
||||
// The 1st var is the alias type's backing var, so we skip it
|
||||
var vars = self.snapshots.sliceVars(alias.vars);
|
||||
|
|
@ -871,7 +871,7 @@ pub const SnapshotWriter = struct {
|
|||
|
||||
/// Write a nominal type
|
||||
pub fn writeNominalType(self: *Self, nominal_type: SnapshotNominalType, root_idx: SnapshotContentIdx) Allocator.Error!void {
|
||||
_ = try self.writer.write(self.getIdent(nominal_type.ident.ident_idx));
|
||||
_ = try self.writer.write(self.idents.getText(nominal_type.ident.ident_idx));
|
||||
|
||||
// The 1st var is the nominal type's backing var, so we skip it
|
||||
var vars = self.snapshots.sliceVars(nominal_type.vars);
|
||||
|
|
@ -889,7 +889,7 @@ pub const SnapshotWriter = struct {
|
|||
|
||||
// Add origin information if it's from a different module
|
||||
if (self.current_module_name) |current_module| {
|
||||
const origin_module_name = self.getIdent(nominal_type.origin_module);
|
||||
const origin_module_name = self.idents.getText(nominal_type.origin_module);
|
||||
|
||||
// Only show origin if it's different from the current module
|
||||
if (!std.mem.eql(u8, origin_module_name, current_module)) {
|
||||
|
|
@ -934,14 +934,14 @@ pub const SnapshotWriter = struct {
|
|||
|
||||
if (fields_slice.len > 0) {
|
||||
// Write first field
|
||||
_ = try self.writer.write(self.getIdent(fields_slice.items(.name)[0]));
|
||||
_ = try self.writer.write(self.idents.getText(fields_slice.items(.name)[0]));
|
||||
_ = try self.writer.write(": ");
|
||||
try self.writeWithContext(fields_slice.items(.content)[0], .RecordFieldContent, root_idx);
|
||||
|
||||
// Write remaining fields
|
||||
for (fields_slice.items(.name)[1..], fields_slice.items(.content)[1..]) |name, content| {
|
||||
_ = try self.writer.write(", ");
|
||||
_ = try self.writer.write(self.getIdent(name));
|
||||
_ = try self.writer.write(self.idents.getText(name));
|
||||
_ = try self.writer.write(": ");
|
||||
try self.writeWithContext(content, .RecordFieldContent, root_idx);
|
||||
}
|
||||
|
|
@ -977,14 +977,14 @@ pub const SnapshotWriter = struct {
|
|||
_ = try self.writer.write("{ ");
|
||||
|
||||
// Write first field - we already verified that there is at least one field.
|
||||
_ = try self.writer.write(self.getIdent(fields_slice.items(.name)[0]));
|
||||
_ = try self.writer.write(self.idents.getText(fields_slice.items(.name)[0]));
|
||||
_ = try self.writer.write(": ");
|
||||
try self.writeWithContext(fields_slice.items(.content)[0], .RecordFieldContent, root_idx);
|
||||
|
||||
// Write remaining fields
|
||||
for (fields_slice.items(.name)[1..], fields_slice.items(.content)[1..]) |name, content| {
|
||||
_ = try self.writer.write(", ");
|
||||
_ = try self.writer.write(self.getIdent(name));
|
||||
_ = try self.writer.write(self.idents.getText(name));
|
||||
_ = try self.writer.write(": ");
|
||||
try self.writeWithContext(content, .RecordFieldContent, root_idx);
|
||||
}
|
||||
|
|
@ -1011,7 +1011,7 @@ pub const SnapshotWriter = struct {
|
|||
switch (self.snapshots.contents.get(tag_union.ext).*) {
|
||||
.flex_var => |mb_ident| {
|
||||
if (mb_ident) |ident_idx| {
|
||||
_ = try self.writer.write(self.getIdent(ident_idx));
|
||||
_ = try self.writer.write(self.idents.getText(ident_idx));
|
||||
} else {
|
||||
// Check if this variable appears multiple times
|
||||
const occurrences = self.countOccurrences(tag_union.ext, root_idx);
|
||||
|
|
@ -1028,7 +1028,7 @@ pub const SnapshotWriter = struct {
|
|||
},
|
||||
},
|
||||
.rigid_var => |ident_idx| {
|
||||
_ = try self.writer.write(self.getIdent(ident_idx));
|
||||
_ = try self.writer.write(self.idents.getText(ident_idx));
|
||||
},
|
||||
else => {
|
||||
try self.writeWithContext(tag_union.ext, .TagUnionExtension, root_idx);
|
||||
|
|
@ -1038,7 +1038,7 @@ pub const SnapshotWriter = struct {
|
|||
|
||||
/// Write a single tag
|
||||
pub fn writeTag(self: *Self, tag: SnapshotTag, root_idx: SnapshotContentIdx) Allocator.Error!void {
|
||||
_ = try self.writer.write(self.getIdent(tag.name));
|
||||
_ = try self.writer.write(self.idents.getText(tag.name));
|
||||
const args = self.snapshots.sliceVars(tag.args);
|
||||
if (args.len > 0) {
|
||||
_ = try self.writer.write("(");
|
||||
|
|
|
|||
|
|
@ -76,8 +76,17 @@ pub fn writeGather(
|
|||
// Skip iovecs that have no remaining data
|
||||
if (iovec.iov_len <= offset) continue;
|
||||
|
||||
// Handle potential null pointer when adding offset
|
||||
const base_addr = @intFromPtr(iovec.iov_base);
|
||||
const new_base = if (base_addr == 0 and offset == 0)
|
||||
iovec.iov_base // Keep null if already null
|
||||
else if (base_addr == 0)
|
||||
@as([*]const u8, @ptrFromInt(offset)) // This shouldn't happen, but handle it
|
||||
else
|
||||
@as([*]const u8, @ptrFromInt(base_addr + offset));
|
||||
|
||||
adjusted_iovecs[adjusted_index] = .{
|
||||
.base = @ptrFromInt(@intFromPtr(iovec.iov_base) + offset),
|
||||
.base = new_base,
|
||||
.len = iovec.iov_len - offset,
|
||||
};
|
||||
adjusted_index += 1;
|
||||
|
|
|
|||
|
|
@ -729,7 +729,7 @@ pub const BuildEnv = struct {
|
|||
var env = try ModuleEnv.init(self.gpa, &common_env);
|
||||
defer env.deinit();
|
||||
|
||||
var ast = try parse.parse(&env);
|
||||
var ast = try parse.parse(&common_env, self.gpa);
|
||||
defer ast.deinit(self.gpa);
|
||||
|
||||
const file = ast.store.getFile();
|
||||
|
|
|
|||
|
|
@ -17,13 +17,14 @@ const std = @import("std");
|
|||
const base = @import("base");
|
||||
const parse = @import("parse");
|
||||
const can = @import("can");
|
||||
const Check = @import("check").Check;
|
||||
const check = @import("check");
|
||||
const reporting = @import("reporting");
|
||||
|
||||
const Check = check.Check;
|
||||
const Can = can.Can;
|
||||
const Report = reporting.Report;
|
||||
const ModuleEnv = can.ModuleEnv;
|
||||
const problem = Check.problem;
|
||||
const ReportBuilder = check.ReportBuilder;
|
||||
|
||||
/// Timing information for different phases
|
||||
pub const TimingInfo = struct {
|
||||
|
|
@ -477,9 +478,13 @@ pub const PackageEnv = struct {
|
|||
var st = &self.modules.items[module_id];
|
||||
const src = try std.fs.cwd().readFileAlloc(self.gpa, st.path, std.math.maxInt(usize));
|
||||
|
||||
var env = try ModuleEnv.init(self.gpa, src);
|
||||
var common_env = try base.CommonEnv.init(self.gpa, src);
|
||||
defer common_env.deinit(self.gpa);
|
||||
|
||||
// line starts for diagnostics and consistent positions
|
||||
try env.calcLineStarts();
|
||||
try common_env.calcLineStarts(self.gpa);
|
||||
|
||||
var env = try ModuleEnv.init(self.gpa, &common_env);
|
||||
// init CIR fields
|
||||
try env.initCIRFields(self.gpa, st.name);
|
||||
|
||||
|
|
@ -497,7 +502,7 @@ pub const PackageEnv = struct {
|
|||
|
||||
// Parse and canonicalize in one step to avoid double parsing
|
||||
const parse_start = if (@import("builtin").target.cpu.arch != .wasm32) std.time.nanoTimestamp() else 0;
|
||||
var parse_ast = try parse.parse(&env);
|
||||
var parse_ast = try parse.parse(env.common, self.gpa);
|
||||
defer parse_ast.deinit(self.gpa);
|
||||
parse_ast.store.emptyScratch();
|
||||
const parse_end = if (@import("builtin").target.cpu.arch != .wasm32) std.time.nanoTimestamp() else 0;
|
||||
|
|
@ -534,7 +539,7 @@ pub const PackageEnv = struct {
|
|||
// Mark current node as visiting (gray) before exploring imports
|
||||
st.visit_color = 1;
|
||||
for (env.imports.imports.items.items[0..import_count]) |str_idx| {
|
||||
const mod_name = env.strings.get(str_idx);
|
||||
const mod_name = env.getString(str_idx);
|
||||
|
||||
// Use CIR qualifier metadata instead of heuristic; this allocates nothing and scans only once
|
||||
const qualified = hadQualifiedImport(&env, mod_name);
|
||||
|
|
@ -681,7 +686,7 @@ pub const PackageEnv = struct {
|
|||
var others = try std.ArrayList(*ModuleEnv).initCapacity(self.gpa, import_count);
|
||||
defer others.deinit();
|
||||
for (env.imports.imports.items.items[0..import_count]) |str_idx| {
|
||||
const import_name = env.strings.get(str_idx);
|
||||
const import_name = env.getString(str_idx);
|
||||
// Determine external vs local from CIR s_import qualifier metadata directly
|
||||
const is_ext = hadQualifiedImport(&env, import_name);
|
||||
|
||||
|
|
@ -718,7 +723,7 @@ pub const PackageEnv = struct {
|
|||
|
||||
// Build reports from problems
|
||||
const check_diag_start = if (@import("builtin").target.cpu.arch != .wasm32) std.time.nanoTimestamp() else 0;
|
||||
var rb = problem.ReportBuilder.init(self.gpa, &env, &env, &checker.snapshots, st.path, others.items);
|
||||
var rb = ReportBuilder.init(self.gpa, &env, &env, &checker.snapshots, st.path, others.items);
|
||||
defer rb.deinit();
|
||||
for (checker.problems.problems.items) |prob| {
|
||||
const rep = rb.build(prob) catch continue;
|
||||
|
|
|
|||
20
src/fmt.zig
20
src/fmt.zig
|
|
@ -17,6 +17,7 @@ const AST = parse.AST;
|
|||
const Node = parse.Node;
|
||||
const NodeStore = parse.NodeStore;
|
||||
const SafeList = collections.SafeList;
|
||||
const CommonEnv = base.CommonEnv;
|
||||
|
||||
const tokenize = parse.tokenize;
|
||||
const fatal = collections.utils.fatal;
|
||||
|
|
@ -162,16 +163,19 @@ pub fn formatFilePath(gpa: std.mem.Allocator, base_dir: std.fs.Dir, path: []cons
|
|||
}
|
||||
};
|
||||
|
||||
var module_env = try ModuleEnv.init(gpa, contents);
|
||||
var common_env = try CommonEnv.init(gpa, contents);
|
||||
defer common_env.deinit(gpa);
|
||||
|
||||
var module_env = try ModuleEnv.init(gpa, &common_env);
|
||||
defer module_env.deinit();
|
||||
|
||||
var parse_ast: AST = try parse.parse(&module_env);
|
||||
var parse_ast: AST = try parse.parse(&common_env, gpa);
|
||||
defer parse_ast.deinit(gpa);
|
||||
|
||||
// If there are any parsing problems, print them to stderr
|
||||
if (parse_ast.parse_diagnostics.items.len > 0) {
|
||||
parse_ast.toSExprStr(&module_env, std.io.getStdErr().writer().any()) catch @panic("Failed to print SExpr");
|
||||
try printParseErrors(gpa, module_env.source, parse_ast);
|
||||
parse_ast.toSExprStr(gpa, &common_env, std.io.getStdErr().writer().any()) catch @panic("Failed to print SExpr");
|
||||
try printParseErrors(gpa, common_env.source, parse_ast);
|
||||
return error.ParsingFailed;
|
||||
}
|
||||
|
||||
|
|
@ -180,7 +184,7 @@ pub fn formatFilePath(gpa: std.mem.Allocator, base_dir: std.fs.Dir, path: []cons
|
|||
var formatted = std.ArrayList(u8).init(gpa);
|
||||
defer formatted.deinit();
|
||||
try formatAst(parse_ast, formatted.writer().any());
|
||||
if (!std.mem.eql(u8, formatted.items, module_env.source)) {
|
||||
if (!std.mem.eql(u8, formatted.items, common_env.source)) {
|
||||
try unformatted_files.?.append(path);
|
||||
}
|
||||
} else { // Otherwise actually format it
|
||||
|
|
@ -202,13 +206,13 @@ pub fn formatStdin(gpa: std.mem.Allocator) !void {
|
|||
var module_env = try ModuleEnv.init(gpa, &common_env);
|
||||
defer module_env.deinit();
|
||||
|
||||
var parse_ast: AST = try parse.parse(&module_env);
|
||||
var parse_ast: AST = try parse.parse(&common_env, gpa);
|
||||
defer parse_ast.deinit(gpa);
|
||||
|
||||
// If there are any parsing problems, print them to stderr
|
||||
if (parse_ast.parse_diagnostics.items.len > 0) {
|
||||
parse_ast.toSExprStr(&module_env, std.io.getStdErr().writer().any()) catch @panic("Failed to print SExpr");
|
||||
try printParseErrors(gpa, module_env.source, parse_ast);
|
||||
parse_ast.toSExprStr(gpa, &common_env, std.io.getStdErr().writer().any()) catch @panic("Failed to print SExpr");
|
||||
try printParseErrors(gpa, common_env.source, parse_ast);
|
||||
return error.ParsingFailed;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -747,7 +747,7 @@ fn writeToWindowsSharedMemory(data: []const u8, total_size: usize) !SharedMemory
|
|||
/// Set up shared memory with a compiled ModuleEnv from a Roc file.
|
||||
/// This parses, canonicalizes, and type-checks the Roc file, with the resulting ModuleEnv
|
||||
/// ending up in shared memory because all allocations were done into shared memory.
|
||||
pub fn setupSharedMemoryWithModuleEnv(_: std.mem.Allocator, roc_file_path: []const u8) !SharedMemoryHandle {
|
||||
pub fn setupSharedMemoryWithModuleEnv(gpa: std.mem.Allocator, roc_file_path: []const u8) !SharedMemoryHandle {
|
||||
// Create shared memory with SharedMemoryAllocator
|
||||
const page_size = try SharedMemoryAllocator.getSystemPageSize();
|
||||
var shm = try SharedMemoryAllocator.create(SHARED_MEMORY_SIZE, page_size);
|
||||
|
|
@ -794,7 +794,7 @@ pub fn setupSharedMemoryWithModuleEnv(_: std.mem.Allocator, roc_file_path: []con
|
|||
env.module_name = module_name;
|
||||
|
||||
// Parse the source code as a full module
|
||||
var parse_ast = try parse.parse(&common_env);
|
||||
var parse_ast = try parse.parse(&common_env, gpa);
|
||||
|
||||
// Empty scratch space (required before canonicalization)
|
||||
parse_ast.store.emptyScratch();
|
||||
|
|
@ -817,7 +817,7 @@ pub fn setupSharedMemoryWithModuleEnv(_: std.mem.Allocator, roc_file_path: []con
|
|||
const pattern = env.store.getPattern(def.pattern);
|
||||
if (pattern == .assign) {
|
||||
const ident_idx = pattern.assign.ident;
|
||||
const ident_text = env.idents.getText(ident_idx);
|
||||
const ident_text = env.getIdent(ident_idx);
|
||||
if (std.mem.eql(u8, ident_text, "main")) {
|
||||
main_expr_idx = @intFromEnum(def.expr);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ pub fn appendRegionInfoToSexprTree(self: *const AST, env: *const CommonEnv, tree
|
|||
}
|
||||
|
||||
pub fn deinit(self: *AST, gpa: std.mem.Allocator) void {
|
||||
defer self.tokens.deinit();
|
||||
defer self.tokens.deinit(gpa);
|
||||
defer self.store.deinit();
|
||||
defer self.tokenize_diagnostics.deinit(gpa);
|
||||
defer self.parse_diagnostics.deinit(gpa);
|
||||
|
|
@ -696,13 +696,13 @@ test {
|
|||
}
|
||||
|
||||
/// Helper function to convert the AST to a human friendly representation in S-expression format
|
||||
pub fn toSExprStr(ast: *@This(), env: *const CommonEnv, writer: std.io.AnyWriter) !void {
|
||||
pub fn toSExprStr(ast: *@This(), gpa: std.mem.Allocator, env: *const CommonEnv, writer: std.io.AnyWriter) !void {
|
||||
const file = ast.store.getFile();
|
||||
|
||||
var tree = SExprTree.init(env.gpa);
|
||||
var tree = SExprTree.init(gpa);
|
||||
defer tree.deinit();
|
||||
|
||||
try file.pushToSExprTree(env, ast, &tree);
|
||||
try file.pushToSExprTree(gpa, env, ast, &tree);
|
||||
|
||||
try tree.toStringPretty(writer);
|
||||
}
|
||||
|
|
@ -785,7 +785,7 @@ pub const Statement = union(enum) {
|
|||
};
|
||||
|
||||
/// Push this Statement to the SExprTree stack
|
||||
pub fn pushToSExprTree(self: @This(), env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
pub fn pushToSExprTree(self: @This(), gpa: std.mem.Allocator, env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
switch (self) {
|
||||
.decl => |decl| {
|
||||
const begin = tree.beginNode();
|
||||
|
|
@ -794,10 +794,10 @@ pub const Statement = union(enum) {
|
|||
const attrs = tree.beginNode();
|
||||
|
||||
// pattern
|
||||
try ast.store.getPattern(decl.pattern).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getPattern(decl.pattern).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
// body
|
||||
try ast.store.getExpr(decl.body).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(decl.body).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
|
|
@ -810,12 +810,12 @@ pub const Statement = union(enum) {
|
|||
try tree.pushStringPair("name", name_str);
|
||||
const attrs = tree.beginNode();
|
||||
|
||||
try ast.store.getExpr(v.body).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(v.body).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
.expr => |expr| {
|
||||
try ast.store.getExpr(expr.expr).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(expr.expr).pushToSExprTree(gpa, env, ast, tree);
|
||||
},
|
||||
.import => |import| {
|
||||
const begin = tree.beginNode();
|
||||
|
|
@ -833,8 +833,8 @@ pub const Statement = union(enum) {
|
|||
module_name_raw;
|
||||
|
||||
// Combine qualifier and module name
|
||||
const full_module_name = try std.fmt.allocPrint(env.gpa, "{s}.{s}", .{ qualifier_str, module_name_clean });
|
||||
defer env.gpa.free(full_module_name);
|
||||
const full_module_name = try std.fmt.allocPrint(gpa, "{s}.{s}", .{ qualifier_str, module_name_clean });
|
||||
defer gpa.free(full_module_name);
|
||||
try tree.pushStringPair("raw", full_module_name);
|
||||
} else {
|
||||
try tree.pushStringPair("raw", module_name_raw);
|
||||
|
|
@ -855,7 +855,7 @@ pub const Statement = union(enum) {
|
|||
try tree.pushStaticAtom("exposing");
|
||||
const attrs2 = tree.beginNode();
|
||||
for (ast.store.exposedItemSlice(import.exposes)) |e| {
|
||||
try ast.store.getExposedItem(e).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExposedItem(e).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(exposed, attrs2);
|
||||
}
|
||||
|
|
@ -895,14 +895,14 @@ pub const Statement = union(enum) {
|
|||
|
||||
for (ast.store.typeAnnoSlice(ty_header.args)) |b| {
|
||||
const anno = ast.store.getTypeAnno(b);
|
||||
try anno.pushToSExprTree(env, ast, tree);
|
||||
try anno.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(args_begin, args_node);
|
||||
try tree.endNode(header, attrs2);
|
||||
}
|
||||
}
|
||||
|
||||
try ast.store.getTypeAnno(a.anno).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getTypeAnno(a.anno).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
if (a.where) |where_coll| {
|
||||
const where_node = tree.beginNode();
|
||||
|
|
@ -910,7 +910,7 @@ pub const Statement = union(enum) {
|
|||
const attrs2 = tree.beginNode();
|
||||
for (ast.store.whereClauseSlice(.{ .span = ast.store.getCollection(where_coll).span })) |clause_idx| {
|
||||
const clause_child = ast.store.getWhereClause(clause_idx);
|
||||
try clause_child.pushToSExprTree(env, ast, tree);
|
||||
try clause_child.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(where_node, attrs2);
|
||||
}
|
||||
|
|
@ -923,7 +923,7 @@ pub const Statement = union(enum) {
|
|||
try ast.appendRegionInfoToSexprTree(env, tree, a.region);
|
||||
const attrs = tree.beginNode();
|
||||
|
||||
try ast.store.getExpr(a.expr).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(a.expr).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
|
|
@ -933,7 +933,7 @@ pub const Statement = union(enum) {
|
|||
try ast.appendRegionInfoToSexprTree(env, tree, a.region);
|
||||
const attrs = tree.beginNode();
|
||||
|
||||
try ast.store.getExpr(a.expr).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(a.expr).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
|
|
@ -943,7 +943,7 @@ pub const Statement = union(enum) {
|
|||
try ast.appendRegionInfoToSexprTree(env, tree, a.region);
|
||||
const attrs = tree.beginNode();
|
||||
|
||||
try ast.store.getExpr(a.body).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(a.body).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
|
|
@ -954,13 +954,13 @@ pub const Statement = union(enum) {
|
|||
const attrs = tree.beginNode();
|
||||
|
||||
// pattern
|
||||
try ast.store.getPattern(a.patt).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getPattern(a.patt).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
// expr
|
||||
try ast.store.getExpr(a.expr).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(a.expr).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
// body
|
||||
try ast.store.getExpr(a.body).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(a.body).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
|
|
@ -970,7 +970,7 @@ pub const Statement = union(enum) {
|
|||
try ast.appendRegionInfoToSexprTree(env, tree, a.region);
|
||||
const attrs = tree.beginNode();
|
||||
|
||||
try ast.store.getExpr(a.expr).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(a.expr).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
|
|
@ -981,7 +981,7 @@ pub const Statement = union(enum) {
|
|||
try tree.pushStringPair("name", ast.resolve(a.name));
|
||||
const attrs = tree.beginNode();
|
||||
|
||||
try ast.store.getTypeAnno(a.anno).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getTypeAnno(a.anno).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
if (a.where) |where_coll| {
|
||||
const where_node = tree.beginNode();
|
||||
|
|
@ -989,7 +989,7 @@ pub const Statement = union(enum) {
|
|||
const attrs2 = tree.beginNode();
|
||||
for (ast.store.whereClauseSlice(.{ .span = ast.store.getCollection(where_coll).span })) |clause_idx| {
|
||||
const clause_child = ast.store.getWhereClause(clause_idx);
|
||||
try clause_child.pushToSExprTree(env, ast, tree);
|
||||
try clause_child.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(where_node, attrs2);
|
||||
}
|
||||
|
|
@ -1032,7 +1032,7 @@ pub const Block = struct {
|
|||
region: TokenizedRegion,
|
||||
|
||||
/// Push this Block to the SExprTree stack
|
||||
pub fn pushToSExprTree(self: @This(), env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
pub fn pushToSExprTree(self: @This(), gpa: std.mem.Allocator, env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
const begin = tree.beginNode();
|
||||
try tree.pushStaticAtom("e-block");
|
||||
try ast.appendRegionInfoToSexprTree(env, tree, self.region);
|
||||
|
|
@ -1044,7 +1044,7 @@ pub const Block = struct {
|
|||
// Push all statements
|
||||
for (ast.store.statementSlice(self.statements)) |stmt_idx| {
|
||||
const stmt = ast.store.getStatement(stmt_idx);
|
||||
try stmt.pushToSExprTree(env, ast, tree);
|
||||
try stmt.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(statements, attrs2);
|
||||
|
||||
|
|
@ -1138,7 +1138,7 @@ pub const Pattern = union(enum) {
|
|||
}
|
||||
|
||||
/// Push this Pattern to the SExprTree stack
|
||||
pub fn pushToSExprTree(self: @This(), env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
pub fn pushToSExprTree(self: @This(), gpa: std.mem.Allocator, env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
switch (self) {
|
||||
.ident => |ident| {
|
||||
const begin = tree.beginNode();
|
||||
|
|
@ -1164,7 +1164,7 @@ pub const Pattern = union(enum) {
|
|||
|
||||
// Add arguments if there are any
|
||||
for (ast.store.patternSlice(tag.args)) |arg| {
|
||||
try ast.store.getPattern(arg).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getPattern(arg).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
|
|
@ -1217,7 +1217,7 @@ pub const Pattern = union(enum) {
|
|||
const attrs2 = tree.beginNode();
|
||||
|
||||
if (field.value) |value| {
|
||||
try ast.store.getPattern(value).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getPattern(value).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
|
||||
try tree.endNode(field_begin, attrs2);
|
||||
|
|
@ -1232,7 +1232,7 @@ pub const Pattern = union(enum) {
|
|||
const attrs = tree.beginNode();
|
||||
|
||||
for (ast.store.patternSlice(list.patterns)) |pat| {
|
||||
try ast.store.getPattern(pat).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getPattern(pat).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
|
|
@ -1256,7 +1256,7 @@ pub const Pattern = union(enum) {
|
|||
const attrs = tree.beginNode();
|
||||
|
||||
for (ast.store.patternSlice(tuple.patterns)) |pat| {
|
||||
try ast.store.getPattern(pat).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getPattern(pat).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
|
|
@ -1273,7 +1273,7 @@ pub const Pattern = union(enum) {
|
|||
const attrs = tree.beginNode();
|
||||
|
||||
for (ast.store.patternSlice(a.patterns)) |pat| {
|
||||
try ast.store.getPattern(pat).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getPattern(pat).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
|
|
@ -1285,7 +1285,7 @@ pub const Pattern = union(enum) {
|
|||
try tree.pushStringPair("name", ast.resolve(a.name));
|
||||
const attrs = tree.beginNode();
|
||||
|
||||
try ast.store.getPattern(a.pattern).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getPattern(a.pattern).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
|
|
@ -1309,7 +1309,7 @@ pub const BinOp = struct {
|
|||
region: TokenizedRegion,
|
||||
|
||||
/// (binop <op> <left> <right>) e.g. (binop '+' 1 2)
|
||||
pub fn pushToSExprTree(self: *const @This(), env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
pub fn pushToSExprTree(self: *const @This(), gpa: std.mem.Allocator, env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
const begin = tree.beginNode();
|
||||
|
||||
// Push the node name
|
||||
|
|
@ -1325,10 +1325,10 @@ pub const BinOp = struct {
|
|||
const attrs = tree.beginNode();
|
||||
|
||||
// Push left operand
|
||||
try ast.store.getExpr(self.left).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(self.left).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
// Push right operand
|
||||
try ast.store.getExpr(self.right).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(self.right).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
}
|
||||
|
|
@ -1341,13 +1341,13 @@ pub const Unary = struct {
|
|||
region: TokenizedRegion,
|
||||
|
||||
/// Push this Unary to the SExprTree stack
|
||||
pub fn pushToSExprTree(self: *const @This(), env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
pub fn pushToSExprTree(self: *const @This(), gpa: std.mem.Allocator, env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
const begin = tree.beginNode();
|
||||
try tree.pushStaticAtom("unary");
|
||||
try tree.pushString(ast.resolve(self.operator));
|
||||
const attrs = tree.beginNode();
|
||||
|
||||
try ast.store.getExpr(self.expr).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(self.expr).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
}
|
||||
|
|
@ -1368,7 +1368,7 @@ pub const File = struct {
|
|||
region: TokenizedRegion,
|
||||
|
||||
/// Push this File to the SExprTree stack
|
||||
pub fn pushToSExprTree(self: @This(), env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
pub fn pushToSExprTree(self: @This(), gpa: std.mem.Allocator, env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
const begin = tree.beginNode();
|
||||
try tree.pushStaticAtom("file");
|
||||
try ast.appendRegionInfoToSexprTree(env, tree, self.region);
|
||||
|
|
@ -1376,14 +1376,14 @@ pub const File = struct {
|
|||
|
||||
// Push header
|
||||
const header = ast.store.getHeader(self.header);
|
||||
try header.pushToSExprTree(env, ast, tree);
|
||||
try header.pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
const begin2 = tree.beginNode();
|
||||
try tree.pushStaticAtom("statements");
|
||||
const attrs2 = tree.beginNode();
|
||||
for (ast.store.statementSlice(self.statements)) |stmt_id| {
|
||||
const stmt = ast.store.getStatement(stmt_id);
|
||||
try stmt.pushToSExprTree(env, ast, tree);
|
||||
try stmt.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(begin2, attrs2);
|
||||
|
||||
|
|
@ -1431,7 +1431,7 @@ pub const Header = union(enum) {
|
|||
|
||||
pub const AppHeaderRhs = packed struct { num_packages: u10, num_provides: u22 };
|
||||
|
||||
pub fn pushToSExprTree(self: @This(), env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
pub fn pushToSExprTree(self: @This(), gpa: std.mem.Allocator, env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
switch (self) {
|
||||
.app => |a| {
|
||||
const begin = tree.beginNode();
|
||||
|
|
@ -1449,13 +1449,13 @@ pub const Header = union(enum) {
|
|||
// Could push region info for provides_coll here if desired
|
||||
for (provides_items) |item_idx| {
|
||||
const item = ast.store.getExposedItem(item_idx);
|
||||
try item.pushToSExprTree(env, ast, tree);
|
||||
try item.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(provides_begin, attrs2);
|
||||
|
||||
// Platform
|
||||
const platform = ast.store.getRecordField(a.platform_idx);
|
||||
try platform.pushToSExprTree(env, ast, tree);
|
||||
try platform.pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
// Packages
|
||||
const packages_coll = ast.store.getCollection(a.packages);
|
||||
|
|
@ -1466,7 +1466,7 @@ pub const Header = union(enum) {
|
|||
const attrs3 = tree.beginNode();
|
||||
for (packages_items) |item_idx| {
|
||||
const item = ast.store.getRecordField(item_idx);
|
||||
try item.pushToSExprTree(env, ast, tree);
|
||||
try item.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(packages_begin, attrs3);
|
||||
|
||||
|
|
@ -1485,7 +1485,7 @@ pub const Header = union(enum) {
|
|||
const attrs2 = tree.beginNode();
|
||||
for (ast.store.exposedItemSlice(.{ .span = exposes.span })) |exposed| {
|
||||
const item = ast.store.getExposedItem(exposed);
|
||||
try item.pushToSExprTree(env, ast, tree);
|
||||
try item.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(exposes_begin, attrs2);
|
||||
|
||||
|
|
@ -1505,7 +1505,7 @@ pub const Header = union(enum) {
|
|||
const attrs2 = tree.beginNode();
|
||||
for (ast.store.exposedItemSlice(.{ .span = exposes.span })) |exposed| {
|
||||
const item = ast.store.getExposedItem(exposed);
|
||||
try item.pushToSExprTree(env, ast, tree);
|
||||
try item.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(exposes_begin, attrs2);
|
||||
|
||||
|
|
@ -1518,7 +1518,7 @@ pub const Header = union(enum) {
|
|||
const attrs3 = tree.beginNode();
|
||||
for (packages_items) |item_idx| {
|
||||
const item = ast.store.getRecordField(item_idx);
|
||||
try item.pushToSExprTree(env, ast, tree);
|
||||
try item.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(packages_begin, attrs3);
|
||||
|
||||
|
|
@ -1540,13 +1540,13 @@ pub const Header = union(enum) {
|
|||
// Could push region info for rigids here if desired
|
||||
for (ast.store.exposedItemSlice(.{ .span = rigids.span })) |exposed| {
|
||||
const item = ast.store.getExposedItem(exposed);
|
||||
try item.pushToSExprTree(env, ast, tree);
|
||||
try item.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(rigids_begin, attrs3);
|
||||
|
||||
// Requires Signatures
|
||||
const signatures = ast.store.getTypeAnno(a.requires_signatures);
|
||||
try signatures.pushToSExprTree(env, ast, tree);
|
||||
try signatures.pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
// Exposes
|
||||
const exposes = ast.store.getCollection(a.exposes);
|
||||
|
|
@ -1556,7 +1556,7 @@ pub const Header = union(enum) {
|
|||
const attrs4 = tree.beginNode();
|
||||
for (ast.store.exposedItemSlice(.{ .span = exposes.span })) |exposed| {
|
||||
const item = ast.store.getExposedItem(exposed);
|
||||
try item.pushToSExprTree(env, ast, tree);
|
||||
try item.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(exposes_begin, attrs4);
|
||||
|
||||
|
|
@ -1569,7 +1569,7 @@ pub const Header = union(enum) {
|
|||
const attrs5 = tree.beginNode();
|
||||
for (packages_items) |item_idx| {
|
||||
const item = ast.store.getRecordField(item_idx);
|
||||
try item.pushToSExprTree(env, ast, tree);
|
||||
try item.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(packages_begin, attrs5);
|
||||
|
||||
|
|
@ -1581,7 +1581,7 @@ pub const Header = union(enum) {
|
|||
const attrs6 = tree.beginNode();
|
||||
for (ast.store.exposedItemSlice(.{ .span = provides.span })) |exposed| {
|
||||
const item = ast.store.getExposedItem(exposed);
|
||||
try item.pushToSExprTree(env, ast, tree);
|
||||
try item.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(provides_begin, attrs6);
|
||||
|
||||
|
|
@ -1600,7 +1600,7 @@ pub const Header = union(enum) {
|
|||
const attrs2 = tree.beginNode();
|
||||
for (ast.store.exposedItemSlice(.{ .span = exposes.span })) |exposed| {
|
||||
const item = ast.store.getExposedItem(exposed);
|
||||
try item.pushToSExprTree(env, ast, tree);
|
||||
try item.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(exposes_begin, attrs2);
|
||||
|
||||
|
|
@ -1654,7 +1654,9 @@ pub const ExposedItem = union(enum) {
|
|||
pub const Idx = enum(u32) { _ };
|
||||
pub const Span = struct { span: base.DataSpan };
|
||||
|
||||
pub fn pushToSExprTree(self: @This(), env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
pub fn pushToSExprTree(self: @This(), gpa: std.mem.Allocator, env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
_ = gpa;
|
||||
|
||||
switch (self) {
|
||||
.lower_ident => |i| {
|
||||
const begin = tree.beginNode();
|
||||
|
|
@ -1838,7 +1840,7 @@ pub const TypeAnno = union(enum) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn pushToSExprTree(self: @This(), env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
pub fn pushToSExprTree(self: @This(), gpa: std.mem.Allocator, env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
switch (self) {
|
||||
.apply => |a| {
|
||||
const begin = tree.beginNode();
|
||||
|
|
@ -1847,7 +1849,7 @@ pub const TypeAnno = union(enum) {
|
|||
const attrs = tree.beginNode();
|
||||
|
||||
for (ast.store.typeAnnoSlice(a.args)) |b| {
|
||||
try ast.store.getTypeAnno(b).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getTypeAnno(b).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
|
|
@ -1898,12 +1900,12 @@ pub const TypeAnno = union(enum) {
|
|||
try tree.pushStaticAtom("tags");
|
||||
const attrs2 = tree.beginNode();
|
||||
for (tags) |tag_idx| {
|
||||
try ast.store.getTypeAnno(tag_idx).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getTypeAnno(tag_idx).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(tags_begin, attrs2);
|
||||
|
||||
if (a.open_anno) |anno_idx| {
|
||||
try ast.store.getTypeAnno(anno_idx).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getTypeAnno(anno_idx).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
|
|
@ -1915,7 +1917,7 @@ pub const TypeAnno = union(enum) {
|
|||
const attrs = tree.beginNode();
|
||||
|
||||
for (ast.store.typeAnnoSlice(a.annos)) |b| {
|
||||
try ast.store.getTypeAnno(b).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getTypeAnno(b).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
|
|
@ -1937,7 +1939,7 @@ pub const TypeAnno = union(enum) {
|
|||
continue;
|
||||
},
|
||||
};
|
||||
try field.pushToSExprTree(env, ast, tree);
|
||||
try field.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
|
|
@ -1950,17 +1952,17 @@ pub const TypeAnno = union(enum) {
|
|||
|
||||
// arguments
|
||||
for (ast.store.typeAnnoSlice(a.args)) |b| {
|
||||
try ast.store.getTypeAnno(b).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getTypeAnno(b).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
|
||||
// return value
|
||||
try ast.store.getTypeAnno(a.ret).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getTypeAnno(a.ret).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
.parens => |a| {
|
||||
// Ignore parens, use inner
|
||||
try ast.store.getTypeAnno(a.anno).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getTypeAnno(a.anno).pushToSExprTree(gpa, env, ast, tree);
|
||||
},
|
||||
.malformed => |a| {
|
||||
const begin = tree.beginNode();
|
||||
|
|
@ -1983,7 +1985,7 @@ pub const AnnoRecordField = struct {
|
|||
pub const Idx = enum(u32) { _ };
|
||||
pub const Span = struct { span: base.DataSpan };
|
||||
|
||||
pub fn pushToSExprTree(self: @This(), env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
pub fn pushToSExprTree(self: @This(), gpa: std.mem.Allocator, env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
const begin = tree.beginNode();
|
||||
try tree.pushStaticAtom("anno-record-field");
|
||||
try ast.appendRegionInfoToSexprTree(env, tree, self.region);
|
||||
|
|
@ -1991,7 +1993,7 @@ pub const AnnoRecordField = struct {
|
|||
const attrs = tree.beginNode();
|
||||
|
||||
const anno = ast.store.getTypeAnno(self.ty);
|
||||
try anno.pushToSExprTree(env, ast, tree);
|
||||
try anno.pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
}
|
||||
|
|
@ -2046,7 +2048,7 @@ pub const WhereClause = union(enum) {
|
|||
reason: Diagnostic.Tag,
|
||||
region: TokenizedRegion,
|
||||
},
|
||||
pub fn pushToSExprTree(self: @This(), env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
pub fn pushToSExprTree(self: @This(), gpa: std.mem.Allocator, env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
switch (self) {
|
||||
.mod_method => |m| {
|
||||
const begin = tree.beginNode();
|
||||
|
|
@ -2065,11 +2067,11 @@ pub const WhereClause = union(enum) {
|
|||
const attrs2 = tree.beginNode();
|
||||
const args = ast.store.typeAnnoSlice(.{ .span = ast.store.getCollection(m.args).span });
|
||||
for (args) |arg| {
|
||||
try ast.store.getTypeAnno(arg).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getTypeAnno(arg).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(args_begin, attrs2);
|
||||
|
||||
try ast.store.getTypeAnno(m.ret_anno).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getTypeAnno(m.ret_anno).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
|
|
@ -2243,7 +2245,7 @@ pub const Expr = union(enum) {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn pushToSExprTree(self: @This(), env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
pub fn pushToSExprTree(self: @This(), gpa: std.mem.Allocator, env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
switch (self) {
|
||||
.int => |int| {
|
||||
const begin = tree.beginNode();
|
||||
|
|
@ -2296,7 +2298,7 @@ pub const Expr = union(enum) {
|
|||
|
||||
for (ast.store.exprSlice(str.parts)) |part_id| {
|
||||
const part_expr = ast.store.getExpr(part_id);
|
||||
try part_expr.pushToSExprTree(env, ast, tree);
|
||||
try part_expr.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
|
|
@ -2308,7 +2310,7 @@ pub const Expr = union(enum) {
|
|||
const attrs = tree.beginNode();
|
||||
|
||||
for (ast.store.exprSlice(a.items)) |b| {
|
||||
try ast.store.getExpr(b).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(b).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
|
|
@ -2320,7 +2322,7 @@ pub const Expr = union(enum) {
|
|||
const attrs = tree.beginNode();
|
||||
|
||||
for (ast.store.exprSlice(a.items)) |b| {
|
||||
try ast.store.getExpr(b).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(b).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
|
|
@ -2335,7 +2337,7 @@ pub const Expr = union(enum) {
|
|||
if (a.ext) |ext_idx| {
|
||||
const ext_wrapper = tree.beginNode();
|
||||
try tree.pushStaticAtom("ext");
|
||||
try ast.store.getExpr(ext_idx).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(ext_idx).pushToSExprTree(gpa, env, ast, tree);
|
||||
try tree.endNode(ext_wrapper, attrs);
|
||||
}
|
||||
|
||||
|
|
@ -2346,7 +2348,7 @@ pub const Expr = union(enum) {
|
|||
try tree.pushStringPair("field", ast.resolve(record_field.name));
|
||||
const attrs2 = tree.beginNode();
|
||||
if (record_field.value) |value_id| {
|
||||
try ast.store.getExpr(value_id).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(value_id).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(field_node, attrs2);
|
||||
}
|
||||
|
|
@ -2377,12 +2379,12 @@ pub const Expr = union(enum) {
|
|||
const attrs2 = tree.beginNode();
|
||||
// Push args (patterns)
|
||||
for (ast.store.patternSlice(a.args)) |pat| {
|
||||
try ast.store.getPattern(pat).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getPattern(pat).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(args, attrs2);
|
||||
|
||||
// Push body
|
||||
try ast.store.getExpr(a.body).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(a.body).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
|
|
@ -2393,11 +2395,11 @@ pub const Expr = union(enum) {
|
|||
const attrs = tree.beginNode();
|
||||
|
||||
// Push function
|
||||
try ast.store.getExpr(a.@"fn").pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(a.@"fn").pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
// Push arguments
|
||||
for (ast.store.exprSlice(a.args)) |arg_id| {
|
||||
try ast.store.getExpr(arg_id).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(arg_id).pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
|
|
@ -2415,9 +2417,9 @@ pub const Expr = union(enum) {
|
|||
try ast.appendRegionInfoToSexprTree(env, tree, stmt.region);
|
||||
const attrs = tree.beginNode();
|
||||
|
||||
try ast.store.getExpr(stmt.condition).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(stmt.then).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(stmt.@"else").pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(stmt.condition).pushToSExprTree(gpa, env, ast, tree);
|
||||
try ast.store.getExpr(stmt.then).pushToSExprTree(gpa, env, ast, tree);
|
||||
try ast.store.getExpr(stmt.@"else").pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
|
|
@ -2426,7 +2428,7 @@ pub const Expr = union(enum) {
|
|||
try tree.pushStaticAtom("e-match");
|
||||
const attrs = tree.beginNode();
|
||||
|
||||
try ast.store.getExpr(a.expr).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(a.expr).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
const branches = tree.beginNode();
|
||||
try tree.pushStaticAtom("branches");
|
||||
|
|
@ -2434,7 +2436,7 @@ pub const Expr = union(enum) {
|
|||
|
||||
for (ast.store.matchBranchSlice(a.branches)) |branch_idx| {
|
||||
const branch = ast.store.getBranch(branch_idx);
|
||||
try branch.pushToSExprTree(env, ast, tree);
|
||||
try branch.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
try tree.endNode(branches, attrs2);
|
||||
|
||||
|
|
@ -2464,7 +2466,7 @@ pub const Expr = union(enum) {
|
|||
try tree.pushStaticAtom("e-dbg");
|
||||
const attrs = tree.beginNode();
|
||||
|
||||
try ast.store.getExpr(a.expr).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(a.expr).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
|
|
@ -2474,11 +2476,11 @@ pub const Expr = union(enum) {
|
|||
const attrs = tree.beginNode();
|
||||
|
||||
// Push mapper
|
||||
try ast.store.getExpr(a.mapper).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(a.mapper).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
// Push single field (not a collection)
|
||||
const field = ast.store.getRecordField(a.fields);
|
||||
try field.pushToSExprTree(env, ast, tree);
|
||||
try field.pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
|
|
@ -2490,10 +2492,10 @@ pub const Expr = union(enum) {
|
|||
},
|
||||
.block => |block| {
|
||||
// Delegate to Block.pushToSExprTree
|
||||
try block.pushToSExprTree(env, ast, tree);
|
||||
try block.pushToSExprTree(gpa, env, ast, tree);
|
||||
},
|
||||
.bin_op => |a| {
|
||||
try a.pushToSExprTree(env, ast, tree);
|
||||
try a.pushToSExprTree(gpa, env, ast, tree);
|
||||
},
|
||||
.field_access => |a| {
|
||||
const begin = tree.beginNode();
|
||||
|
|
@ -2502,10 +2504,10 @@ pub const Expr = union(enum) {
|
|||
const attrs = tree.beginNode();
|
||||
|
||||
// Push left expression
|
||||
try ast.store.getExpr(a.left).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(a.left).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
// Push right expression
|
||||
try ast.store.getExpr(a.right).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(a.right).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
|
|
@ -2516,15 +2518,15 @@ pub const Expr = union(enum) {
|
|||
const attrs = tree.beginNode();
|
||||
|
||||
// Push left expression
|
||||
try ast.store.getExpr(a.left).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(a.left).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
// Push right expression
|
||||
try ast.store.getExpr(a.right).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(a.right).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
.unary_op => |a| {
|
||||
try a.pushToSExprTree(env, ast, tree);
|
||||
try a.pushToSExprTree(gpa, env, ast, tree);
|
||||
},
|
||||
.malformed => |a| {
|
||||
const begin = tree.beginNode();
|
||||
|
|
@ -2541,7 +2543,7 @@ pub const Expr = union(enum) {
|
|||
const attrs = tree.beginNode();
|
||||
|
||||
// Push child expression
|
||||
try ast.store.getExpr(a.expr).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(a.expr).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
},
|
||||
|
|
@ -2569,7 +2571,7 @@ pub const RecordField = struct {
|
|||
pub const Idx = enum(u32) { _ };
|
||||
pub const Span = struct { span: base.DataSpan };
|
||||
|
||||
pub fn pushToSExprTree(self: @This(), env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
pub fn pushToSExprTree(self: @This(), gpa: std.mem.Allocator, env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
const begin = tree.beginNode();
|
||||
try tree.pushStaticAtom("record-field");
|
||||
try ast.appendRegionInfoToSexprTree(env, tree, self.region);
|
||||
|
|
@ -2582,7 +2584,7 @@ pub const RecordField = struct {
|
|||
|
||||
if (self.value) |idx| {
|
||||
const value = ast.store.getExpr(idx);
|
||||
try value.pushToSExprTree(env, ast, tree);
|
||||
try value.pushToSExprTree(gpa, env, ast, tree);
|
||||
}
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
|
|
@ -2615,14 +2617,14 @@ pub const MatchBranch = struct {
|
|||
pub const Idx = enum(u32) { _ };
|
||||
pub const Span = struct { span: base.DataSpan };
|
||||
|
||||
pub fn pushToSExprTree(self: @This(), env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
pub fn pushToSExprTree(self: @This(), gpa: std.mem.Allocator, env: *const CommonEnv, ast: *const AST, tree: *SExprTree) std.mem.Allocator.Error!void {
|
||||
const begin = tree.beginNode();
|
||||
try tree.pushStaticAtom("branch");
|
||||
try ast.appendRegionInfoToSexprTree(env, tree, self.region);
|
||||
const attrs = tree.beginNode();
|
||||
|
||||
try ast.store.getPattern(self.pattern).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getExpr(self.body).pushToSExprTree(env, ast, tree);
|
||||
try ast.store.getPattern(self.pattern).pushToSExprTree(gpa, env, ast, tree);
|
||||
try ast.store.getExpr(self.body).pushToSExprTree(gpa, env, ast, tree);
|
||||
|
||||
try tree.endNode(begin, attrs);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue