Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type: add helpers for managing typeof and attributed types #757

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/aro/Attribute.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1014,14 +1014,13 @@ pub fn applyEnumeratorAttributes(p: *Parser, ty: Type, attr_buf_start: usize) !T
}

fn applyAligned(attr: Attribute, p: *Parser, ty: Type, tag: ?Diagnostics.Tag) !void {
const base = ty.canonicalize(.standard);
if (attr.args.aligned.alignment) |alignment| alignas: {
if (attr.syntax != .keyword) break :alignas;

const align_tok = attr.args.aligned.__name_tok;
if (tag) |t| try p.errTok(t, align_tok);

const default_align = base.alignof(p.comp);
const default_align = ty.alignof(p.comp);
if (ty.isFunc()) {
try p.errTok(.alignas_on_func, align_tok);
} else if (alignment.requested < default_align) {
Expand Down
4 changes: 2 additions & 2 deletions src/aro/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ fn genType(c: *CodeGen, base_ty: Type) !Interner.Ref {

fn genFn(c: *CodeGen, decl: NodeIndex) Error!void {
const name = c.tree.tokSlice(c.node_data[@intFromEnum(decl)].decl.name);
const func_ty = c.node_ty[@intFromEnum(decl)].canonicalize(.standard);
const func_ty = c.node_ty[@intFromEnum(decl)];
c.ret_nodes.items.len = 0;

try c.builder.startFn();

for (func_ty.data.func.params) |param| {
for (func_ty.params()) |param| {
// TODO handle calling convention here
const arg = try c.builder.addArg(try c.genType(param.ty));

Expand Down
14 changes: 7 additions & 7 deletions src/aro/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ record: struct {
fn addFieldsFromAnonymous(r: @This(), p: *Parser, ty: Type) Error!void {
for (ty.getRecord().?.fields) |f| {
if (f.isAnonymousRecord()) {
try r.addFieldsFromAnonymous(p, f.ty.canonicalize(.standard));
try r.addFieldsFromAnonymous(p, f.ty);
} else if (f.name_tok != 0) {
try r.addField(p, f.name, f.name_tok);
}
Expand Down Expand Up @@ -981,7 +981,7 @@ fn decl(p: *Parser) Error!bool {
(decl_spec.ty.isRecord() and !decl_spec.ty.isAnonymousRecord(p.comp) and
!decl_spec.ty.isTypeof())) // we follow GCC and clang's behavior here
{
const specifier = decl_spec.ty.canonicalize(.standard).specifier;
const specifier = decl_spec.ty.base();
const attrs = p.attr_buf.items(.attr)[attr_buf_top..];
const toks = p.attr_buf.items(.tok)[attr_buf_top..];
for (attrs, toks) |attr, tok| {
Expand Down Expand Up @@ -1870,7 +1870,7 @@ fn initDeclarator(p: *Parser, decl_spec: *DeclSpec, attr_buf_top: usize) Error!?
init_d.d.ty = try Attribute.applyVariableAttributes(p, init_d.d.ty, attr_buf_top, null);
}
if (decl_spec.storage_class != .typedef and init_d.d.ty.hasIncompleteSize()) incomplete: {
const specifier = init_d.d.ty.canonicalize(.standard).specifier;
const specifier = init_d.d.ty.base();
if (decl_spec.storage_class == .@"extern") switch (specifier) {
.@"struct", .@"union", .@"enum" => break :incomplete,
.incomplete_array => {
Expand Down Expand Up @@ -3776,8 +3776,8 @@ fn coerceArrayInitExtra(p: *Parser, item: *Result, tok: TokenIndex, target: Type
return true; // do not do further coercion
}

const target_spec = target.elemType().canonicalize(.standard).specifier;
const item_spec = item.ty.elemType().canonicalize(.standard).specifier;
const target_spec = target.elemType().base();
const item_spec = item.ty.elemType().base();

const compatible = target.elemType().eql(item.ty.elemType(), p.comp, false) or
(is_str_lit and item_spec == .char and (target_spec == .uchar or target_spec == .schar)) or
Expand Down Expand Up @@ -5795,8 +5795,8 @@ pub const Result = struct {
.{ .invalid, .fp16 },
.{ .complex_float16, .float16 },
};
const a_spec = a.ty.canonicalize(.standard).specifier;
const b_spec = b.ty.canonicalize(.standard).specifier;
const a_spec = a.ty.base();
const b_spec = b.ty.base();
if (p.comp.target.cTypeBitSize(.longdouble) == 128) {
if (try a.floatConversion(b, a_spec, b_spec, p, float_types[0])) return;
}
Expand Down
3 changes: 1 addition & 2 deletions src/aro/Tree.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1363,12 +1363,11 @@ fn dumpNode(

var lhs_ty = tree.nodes.items(.ty)[@intFromEnum(data.member.lhs)];
if (lhs_ty.isPtr()) lhs_ty = lhs_ty.elemType();
lhs_ty = lhs_ty.canonicalize(.standard);

try w.writeByteNTimes(' ', level + 1);
try w.writeAll("name: ");
try config.setColor(w, NAME);
try w.print("{s}\n", .{mapper.lookup(lhs_ty.data.record.fields[data.member.index].name)});
try w.print("{s}\n", .{mapper.lookup(lhs_ty.getRecord().?.fields[data.member.index].name)});
try config.setColor(w, .reset);
},
.array_access_expr => {
Expand Down
Loading
Loading