Skip to content

Commit

Permalink
*wip* continue token stream conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas committed Jan 21, 2024
1 parent ff3f80b commit 057699b
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 337 deletions.
23 changes: 11 additions & 12 deletions src/aro/Attribute.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const Diagnostics = @import("Diagnostics.zig");
const Parser = @import("Parser.zig");
const Tree = @import("Tree.zig");
const NodeIndex = Tree.NodeIndex;
const TokenIndex = Tree.TokenIndex;
const Type = @import("Type.zig");
const Value = @import("Value.zig");

Expand Down Expand Up @@ -329,7 +328,7 @@ pub const Alignment = struct {
requested: u29,
};
pub const Identifier = struct {
tok: TokenIndex = 0,
tok: Tree.Token = Tree.Token.invalid,
};

const attributes = struct {
Expand All @@ -352,7 +351,7 @@ const attributes = struct {
};
pub const aligned = struct {
alignment: ?Alignment = null,
__name_tok: TokenIndex,
__name_tok: Tree.Token,
};
pub const alloc_align = struct {
position: u32,
Expand Down Expand Up @@ -389,7 +388,7 @@ const attributes = struct {
};
pub const deprecated = struct {
msg: ?Value = null,
__name_tok: TokenIndex,
__name_tok: Tree.Token,
};
pub const designated_init = struct {};
pub const destructor = struct {
Expand All @@ -399,7 +398,7 @@ const attributes = struct {
pub const dllimport = struct {};
pub const @"error" = struct {
msg: Value,
__name_tok: TokenIndex,
__name_tok: Tree.Token,
};
pub const externally_visible = struct {};
pub const fallthrough = struct {};
Expand Down Expand Up @@ -576,7 +575,7 @@ const attributes = struct {
pub const transparent_union = struct {};
pub const unavailable = struct {
msg: ?Value = null,
__name_tok: TokenIndex,
__name_tok: Tree.Token,
};
pub const uninitialized = struct {};
pub const unsequenced = struct {};
Expand Down Expand Up @@ -607,7 +606,7 @@ const attributes = struct {
pub const warn_unused_result = struct {};
pub const warning = struct {
msg: Value,
__name_tok: TokenIndex,
__name_tok: Tree.Token,
};
pub const weak = struct {};
pub const weakref = struct {
Expand Down Expand Up @@ -666,7 +665,7 @@ pub fn ArgumentsForTag(comptime tag: Tag) type {
return @field(attributes, decl.name);
}

pub fn initArguments(tag: Tag, name_tok: TokenIndex) Arguments {
pub fn initArguments(tag: Tag, name_tok: Tree.Token) Arguments {
switch (tag) {
inline else => |arg_tag| {
const union_element = @field(attributes, @tagName(arg_tag));
Expand Down Expand Up @@ -715,7 +714,7 @@ pub fn normalize(name: []const u8) []const u8 {
return name;
}

fn ignoredAttrErr(p: *Parser, tok: TokenIndex, attr: Attribute.Tag, context: []const u8) !void {
fn ignoredAttrErr(p: *Parser, tok: Tree.Token, attr: Attribute.Tag, context: []const u8) !void {
const strings_top = p.strings.items.len;
defer p.strings.items.len = strings_top;

Expand Down Expand Up @@ -968,7 +967,7 @@ pub fn applyLabelAttributes(p: *Parser, ty: Type, attr_buf_start: usize) !Type {
return ty.withAttributes(p.arena, p.attr_application_buf.items);
}

pub fn applyStatementAttributes(p: *Parser, ty: Type, expr_start: TokenIndex, attr_buf_start: usize) !Type {
pub fn applyStatementAttributes(p: *Parser, ty: Type, expr_start: Tree.Token, attr_buf_start: usize) !Type {
const attrs = p.attr_buf.items(.attr)[attr_buf_start..];
const toks = p.attr_buf.items(.tok)[attr_buf_start..];
p.attr_application_buf.items.len = 0;
Expand Down Expand Up @@ -1015,7 +1014,7 @@ fn applyAligned(attr: Attribute, p: *Parser, ty: Type, tag: ?Diagnostics.Tag) !v
try p.attr_application_buf.append(p.gpa, attr);
}

fn applyTransparentUnion(attr: Attribute, p: *Parser, tok: TokenIndex, ty: Type) !void {
fn applyTransparentUnion(attr: Attribute, p: *Parser, tok: Tree.Token, ty: Type) !void {
const union_ty = ty.get(.@"union") orelse {
return p.errTok(.transparent_union_wrong_type, tok);
};
Expand All @@ -1042,7 +1041,7 @@ fn applyTransparentUnion(attr: Attribute, p: *Parser, tok: TokenIndex, ty: Type)
try p.attr_application_buf.append(p.gpa, attr);
}

fn applyVectorSize(attr: Attribute, p: *Parser, tok: TokenIndex, ty: *Type) !void {
fn applyVectorSize(attr: Attribute, p: *Parser, tok: Tree.Token, ty: *Type) !void {
if (!(ty.isInt() or ty.isFloat()) or !ty.isReal()) {
const orig_ty = try p.typeStr(ty.*);
ty.* = Type.invalid;
Expand Down
41 changes: 21 additions & 20 deletions src/aro/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1514,26 +1514,27 @@ pub fn addPragmaHandler(comp: *Compilation, name: []const u8, handler: *Pragma)
}

pub fn addDefaultPragmaHandlers(comp: *Compilation) Allocator.Error!void {
const GCC = @import("pragmas/gcc.zig");
var gcc = try GCC.init(comp.gpa);
errdefer gcc.deinit(gcc, comp);

const Once = @import("pragmas/once.zig");
var once = try Once.init(comp.gpa);
errdefer once.deinit(once, comp);

const Message = @import("pragmas/message.zig");
var message = try Message.init(comp.gpa);
errdefer message.deinit(message, comp);

const Pack = @import("pragmas/pack.zig");
var pack = try Pack.init(comp.gpa);
errdefer pack.deinit(pack, comp);

try comp.addPragmaHandler("GCC", gcc);
try comp.addPragmaHandler("once", once);
try comp.addPragmaHandler("message", message);
try comp.addPragmaHandler("pack", pack);
_ = comp;
// const GCC = @import("pragmas/gcc.zig");
// var gcc = try GCC.init(comp.gpa);
// errdefer gcc.deinit(gcc, comp);

// const Once = @import("pragmas/once.zig");
// var once = try Once.init(comp.gpa);
// errdefer once.deinit(once, comp);

// const Message = @import("pragmas/message.zig");
// var message = try Message.init(comp.gpa);
// errdefer message.deinit(message, comp);

// const Pack = @import("pragmas/pack.zig");
// var pack = try Pack.init(comp.gpa);
// errdefer pack.deinit(pack, comp);

// try comp.addPragmaHandler("GCC", gcc);
// try comp.addPragmaHandler("once", once);
// try comp.addPragmaHandler("message", message);
// try comp.addPragmaHandler("pack", pack);
}

pub fn getPragma(comp: *Compilation, name: []const u8) ?*Pragma {
Expand Down
Loading

0 comments on commit 057699b

Please sign in to comment.