Skip to content

Implement identifier namespacing. #128

@xlauko

Description

@xlauko

Given code:

struct v {
   union { // anonymous union
      struct { int i, j; }; // anonymous structure
      struct { long k, l; } w;
   };
   int m;
} v1;

v1.w.k = 5;

generates:

    hl.record "struct v" : {
      hl.union "union anonymous.0" : {
        hl.record "struct anonymous.1" : {
          hl.field "i" : !hl.int
          hl.field "j" : !hl.int
        }
        hl.field "anonymous::0" : !hl.named_type<"struct anonymous.1">
        hl.record "struct anonymous.2" : {
          hl.field "k" : !hl.long
          hl.field "l" : !hl.long
        }
        hl.field "w" : !hl.named_type<"struct anonymous.2">
      }
      hl.field "anonymous.0" : !hl.named_type<"union anonymous.0">
      hl.field "m" : !hl.int
    }

...

%9 = hl.decl.ref %8 : !hl.lvalue<!hl.named_type<"struct v">>
      %10 = hl.member %9 at "anonymous::0" : !hl.lvalue<!hl.named_type<"struct v">> -> !hl.lvalue<!hl.named_type<"union anonymous.0">>
      %11 = hl.member %10 at "w" : !hl.lvalue<!hl.named_type<"union anonymous.0">> -> !hl.lvalue<!hl.named_type<"struct anonymous.2">>
      %12 = hl.member %11 at "k" : !hl.lvalue<!hl.named_type<"struct anonymous.2">> -> !hl.lvalue<!hl.long>

we want to store namespaces in the named_types:

%9 = hl.decl.ref %8 : !hl.lvalue<!hl.named_type<"struct v">>
      %10 = hl.member %9 at "anonymous.0" : !hl.lvalue<!hl.named_type<"struct v">> -> !hl.lvalue<!hl.named_type<"struct v::union anonymous.0">>
      %11 = hl.member %10 at "w" : !hl.lvalue<!hl.named_type<"struct v::union anonymous.0">> -> !hl.lvalue<!hl.named_type<"struct v::union anonymous.0::struct anonymous.2">>
      %12 = hl.member %11 at "k" : !hl.lvalue<!hl.named_type<"struct v::union anonymous.0::struct anonymous.2">> -> !hl.lvalue<!hl.long>

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions