| ... | ... | @@ -107,6 +107,7 @@ const Context = struct { |
| 107 | 107 | decl_table: DeclTable, |
| 108 | 108 | global_scope: *Scope.Root, |
| 109 | 109 | mode: Mode, |
| 110 | ptr_params: std.BufSet, |
| 110 | 111 | clang_context: *ZigClangASTContext, |
| 111 | 112 | |
| 112 | 113 | fn a(c: *Context) *std.mem.Allocator { |
| ... | ... | @@ -184,6 +185,7 @@ pub fn translate( |
| 184 | 185 | .decl_table = DeclTable.init(arena), |
| 185 | 186 | .global_scope = try arena.create(Scope.Root), |
| 186 | 187 | .mode = mode, |
| 188 | .ptr_params = std.BufSet.init(arena), |
| 187 | 189 | .clang_context = ZigClangASTUnit_getASTContext(ast_unit).?, |
| 188 | 190 | }; |
| 189 | 191 | context.global_scope.* = Scope.Root{ |
| ... | ... | @@ -326,6 +328,7 @@ fn transStmt( |
| 326 | 328 | switch (sc) { |
| 327 | 329 | .CompoundStmtClass => return transCompoundStmt(rp, scope, @ptrCast(*const ZigClangCompoundStmt, stmt)), |
| 328 | 330 | .DeclStmtClass => return transDeclStmt(rp, scope, @ptrCast(*const ZigClangDeclStmt, stmt)), |
| 331 | .DeclRefExprClass => return transDeclRefExpr(rp, scope, @ptrCast(*const ZigClangDeclRefExpr, stmt), lrvalue), |
| 329 | 332 | .ImplicitCastExprClass => return transImplicitCastExpr(rp, scope, @ptrCast(*const ZigClangImplicitCastExpr, stmt)), |
| 330 | 333 | else => { |
| 331 | 334 | return revertAndWarn( |
| ... | ... | @@ -451,6 +454,24 @@ fn transDeclStmt(rp: RestorePoint, parent_scope: *Scope, stmt: *const ZigClangDe |
| 451 | 454 | }; |
| 452 | 455 | } |
| 453 | 456 | |
| 457 | fn transDeclRefExpr( |
| 458 | rp: RestorePoint, |
| 459 | scope: *Scope, |
| 460 | expr: *const ZigClangDeclRefExpr, |
| 461 | lrvalue: LRValue, |
| 462 | ) !TransResult { |
| 463 | const value_decl = ZigClangDeclRefExpr_getDecl(expr); |
| 464 | const c_name = try rp.c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, value_decl))); |
| 465 | const zig_name = transLookupZigIdentifier(scope, c_name); |
| 466 | if (lrvalue == .l_value) try rp.c.ptr_params.put(zig_name); |
| 467 | const node = try appendIdentifier(rp.c, zig_name); |
| 468 | return TransResult{ |
| 469 | .node = node, |
| 470 | .node_scope = scope, |
| 471 | .child_scope = scope, |
| 472 | }; |
| 473 | } |
| 474 | |
| 454 | 475 | fn transImplicitCastExpr( |
| 455 | 476 | rp: RestorePoint, |
| 456 | 477 | scope: *Scope, |
| ... | ... | @@ -511,6 +532,16 @@ fn findBlockScope(inner: *Scope) *Scope.Block { |
| 511 | 532 | } |
| 512 | 533 | } |
| 513 | 534 | |
| 535 | fn transLookupZigIdentifier(inner: *Scope, c_name: []const u8) []const u8 { |
| 536 | var scope = inner; |
| 537 | while (true) : (scope = scope.parent orelse return c_name) { |
| 538 | if (scope.id == .Var) { |
| 539 | const var_scope = @ptrCast(*const Scope.Var, scope); |
| 540 | if (std.mem.eql(u8, var_scope.c_name, c_name)) return var_scope.zig_name; |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | |
| 514 | 545 | fn maybeSuppressResult( |
| 515 | 546 | rp: RestorePoint, |
| 516 | 547 | scope: *Scope, |