| author | |
| committer | |
| log | 46e1c34fcfe0973735c75a0c210db314030798f0 |
| tree | 85d3b12619d3621ba7924537cf2f96b5ecfb4715 |
| parent | 9bbd71c9ab3915b8bd8619a319a0eb6de2e2d152 |
| signature | Commit is signed but in an unrecognized format. |
See #19646 files changed, 102 insertions(+), 27 deletions(-)
src-self-hosted/clang.zig+18-5| ... | @@ -806,13 +806,13 @@ pub const enum_ZigClangAPValueKind = extern enum { | ... | @@ -806,13 +806,13 @@ pub const enum_ZigClangAPValueKind = extern enum { |
| 806 | ZigClangAPValueAddrLabelDiff, | 806 | ZigClangAPValueAddrLabelDiff, |
| 807 | }; | 807 | }; |
| 808 | pub extern fn ZigClangSourceManager_getSpellingLoc(arg0: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) struct_ZigClangSourceLocation; | 808 | pub extern fn ZigClangSourceManager_getSpellingLoc(arg0: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) struct_ZigClangSourceLocation; |
| 809 | pub extern fn ZigClangSourceManager_getFilename(arg0: ?*const struct_ZigClangSourceManager, SpellingLoc: struct_ZigClangSourceLocation) [*c]const u8; | 809 | pub extern fn ZigClangSourceManager_getFilename(self: *const struct_ZigClangSourceManager, SpellingLoc: struct_ZigClangSourceLocation) ?[*]const u8; |
| 810 | pub extern fn ZigClangSourceManager_getSpellingLineNumber(arg0: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint; | 810 | pub extern fn ZigClangSourceManager_getSpellingLineNumber(arg0: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint; |
| 811 | pub extern fn ZigClangSourceManager_getSpellingColumnNumber(arg0: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint; | 811 | pub extern fn ZigClangSourceManager_getSpellingColumnNumber(arg0: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint; |
| 812 | pub extern fn ZigClangSourceManager_getCharacterData(arg0: ?*const struct_ZigClangSourceManager, SL: struct_ZigClangSourceLocation) [*c]const u8; | 812 | pub extern fn ZigClangSourceManager_getCharacterData(arg0: ?*const struct_ZigClangSourceManager, SL: struct_ZigClangSourceLocation) [*c]const u8; |
| 813 | pub extern fn ZigClangASTContext_getPointerType(arg0: ?*const struct_ZigClangASTContext, T: struct_ZigClangQualType) struct_ZigClangQualType; | 813 | pub extern fn ZigClangASTContext_getPointerType(arg0: ?*const struct_ZigClangASTContext, T: struct_ZigClangQualType) struct_ZigClangQualType; |
| 814 | pub extern fn ZigClangASTUnit_getASTContext(arg0: ?*struct_ZigClangASTUnit) ?*struct_ZigClangASTContext; | 814 | pub extern fn ZigClangASTUnit_getASTContext(arg0: ?*struct_ZigClangASTUnit) ?*struct_ZigClangASTContext; |
| 815 | pub extern fn ZigClangASTUnit_getSourceManager(arg0: ?*struct_ZigClangASTUnit) ?*struct_ZigClangSourceManager; | 815 | pub extern fn ZigClangASTUnit_getSourceManager(self: *struct_ZigClangASTUnit) *struct_ZigClangSourceManager; |
| 816 | pub extern fn ZigClangASTUnit_visitLocalTopLevelDecls(self: *struct_ZigClangASTUnit, context: ?*c_void, Fn: ?extern fn (?*c_void, *const struct_ZigClangDecl) bool) bool; | 816 | pub extern fn ZigClangASTUnit_visitLocalTopLevelDecls(self: *struct_ZigClangASTUnit, context: ?*c_void, Fn: ?extern fn (?*c_void, *const struct_ZigClangDecl) bool) bool; |
| 817 | pub extern fn ZigClangRecordType_getDecl(record_ty: ?*const struct_ZigClangRecordType) ?*const struct_ZigClangRecordDecl; | 817 | pub extern fn ZigClangRecordType_getDecl(record_ty: ?*const struct_ZigClangRecordType) ?*const struct_ZigClangRecordDecl; |
| 818 | pub extern fn ZigClangEnumType_getDecl(record_ty: ?*const struct_ZigClangEnumType) ?*const struct_ZigClangEnumDecl; | 818 | pub extern fn ZigClangEnumType_getDecl(record_ty: ?*const struct_ZigClangEnumType) ?*const struct_ZigClangEnumDecl; |
| ... | @@ -824,6 +824,7 @@ pub extern fn ZigClangEnumDecl_getDefinition(arg0: ?*const struct_ZigClangEnumDe | ... | @@ -824,6 +824,7 @@ pub extern fn ZigClangEnumDecl_getDefinition(arg0: ?*const struct_ZigClangEnumDe |
| 824 | pub extern fn ZigClangRecordDecl_getLocation(arg0: ?*const struct_ZigClangRecordDecl) struct_ZigClangSourceLocation; | 824 | pub extern fn ZigClangRecordDecl_getLocation(arg0: ?*const struct_ZigClangRecordDecl) struct_ZigClangSourceLocation; |
| 825 | pub extern fn ZigClangEnumDecl_getLocation(arg0: ?*const struct_ZigClangEnumDecl) struct_ZigClangSourceLocation; | 825 | pub extern fn ZigClangEnumDecl_getLocation(arg0: ?*const struct_ZigClangEnumDecl) struct_ZigClangSourceLocation; |
| 826 | pub extern fn ZigClangTypedefNameDecl_getLocation(arg0: ?*const struct_ZigClangTypedefNameDecl) struct_ZigClangSourceLocation; | 826 | pub extern fn ZigClangTypedefNameDecl_getLocation(arg0: ?*const struct_ZigClangTypedefNameDecl) struct_ZigClangSourceLocation; |
| 827 | pub extern fn ZigClangDecl_getLocation(self: *const ZigClangDecl) ZigClangSourceLocation; | ||
| 827 | pub extern fn ZigClangRecordDecl_isUnion(record_decl: ?*const struct_ZigClangRecordDecl) bool; | 828 | pub extern fn ZigClangRecordDecl_isUnion(record_decl: ?*const struct_ZigClangRecordDecl) bool; |
| 828 | pub extern fn ZigClangRecordDecl_isStruct(record_decl: ?*const struct_ZigClangRecordDecl) bool; | 829 | pub extern fn ZigClangRecordDecl_isStruct(record_decl: ?*const struct_ZigClangRecordDecl) bool; |
| 829 | pub extern fn ZigClangRecordDecl_isAnonymousStructOrUnion(record_decl: ?*const struct_ZigClangRecordDecl) bool; | 830 | pub extern fn ZigClangRecordDecl_isAnonymousStructOrUnion(record_decl: ?*const struct_ZigClangRecordDecl) bool; |
| ... | @@ -833,7 +834,7 @@ pub extern fn ZigClangSourceLocation_eq(a: struct_ZigClangSourceLocation, b: str | ... | @@ -833,7 +834,7 @@ pub extern fn ZigClangSourceLocation_eq(a: struct_ZigClangSourceLocation, b: str |
| 833 | pub extern fn ZigClangTypedefType_getDecl(arg0: ?*const struct_ZigClangTypedefType) ?*const struct_ZigClangTypedefNameDecl; | 834 | pub extern fn ZigClangTypedefType_getDecl(arg0: ?*const struct_ZigClangTypedefType) ?*const struct_ZigClangTypedefNameDecl; |
| 834 | pub extern fn ZigClangTypedefNameDecl_getUnderlyingType(arg0: ?*const struct_ZigClangTypedefNameDecl) struct_ZigClangQualType; | 835 | pub extern fn ZigClangTypedefNameDecl_getUnderlyingType(arg0: ?*const struct_ZigClangTypedefNameDecl) struct_ZigClangQualType; |
| 835 | pub extern fn ZigClangQualType_getCanonicalType(arg0: struct_ZigClangQualType) struct_ZigClangQualType; | 836 | pub extern fn ZigClangQualType_getCanonicalType(arg0: struct_ZigClangQualType) struct_ZigClangQualType; |
| 836 | pub extern fn ZigClangQualType_getTypePtr(arg0: struct_ZigClangQualType) ?*const struct_ZigClangType; | 837 | pub extern fn ZigClangQualType_getTypePtr(self: struct_ZigClangQualType) *const struct_ZigClangType; |
| 837 | pub extern fn ZigClangQualType_addConst(arg0: [*c]struct_ZigClangQualType) void; | 838 | pub extern fn ZigClangQualType_addConst(arg0: [*c]struct_ZigClangQualType) void; |
| 838 | pub extern fn ZigClangQualType_eq(arg0: struct_ZigClangQualType, arg1: struct_ZigClangQualType) bool; | 839 | pub extern fn ZigClangQualType_eq(arg0: struct_ZigClangQualType, arg1: struct_ZigClangQualType) bool; |
| 839 | pub extern fn ZigClangQualType_isConstQualified(arg0: struct_ZigClangQualType) bool; | 840 | pub extern fn ZigClangQualType_isConstQualified(arg0: struct_ZigClangQualType) bool; |
| ... | @@ -841,7 +842,7 @@ pub extern fn ZigClangQualType_isVolatileQualified(arg0: struct_ZigClangQualType | ... | @@ -841,7 +842,7 @@ pub extern fn ZigClangQualType_isVolatileQualified(arg0: struct_ZigClangQualType |
| 841 | pub extern fn ZigClangQualType_isRestrictQualified(arg0: struct_ZigClangQualType) bool; | 842 | pub extern fn ZigClangQualType_isRestrictQualified(arg0: struct_ZigClangQualType) bool; |
| 842 | pub extern fn ZigClangType_getTypeClass(self: ?*const struct_ZigClangType) enum_ZigClangTypeClass; | 843 | pub extern fn ZigClangType_getTypeClass(self: ?*const struct_ZigClangType) enum_ZigClangTypeClass; |
| 843 | pub extern fn ZigClangType_isVoidType(self: ?*const struct_ZigClangType) bool; | 844 | pub extern fn ZigClangType_isVoidType(self: ?*const struct_ZigClangType) bool; |
| 844 | pub extern fn ZigClangType_getTypeClassName(self: ?*const struct_ZigClangType) [*c]const u8; | 845 | pub extern fn ZigClangType_getTypeClassName(self: *const struct_ZigClangType) [*]const u8; |
| 845 | pub extern fn ZigClangStmt_getBeginLoc(self: ?*const struct_ZigClangStmt) struct_ZigClangSourceLocation; | 846 | pub extern fn ZigClangStmt_getBeginLoc(self: ?*const struct_ZigClangStmt) struct_ZigClangSourceLocation; |
| 846 | pub extern fn ZigClangStmt_getStmtClass(self: ?*const struct_ZigClangStmt) enum_ZigClangStmtClass; | 847 | pub extern fn ZigClangStmt_getStmtClass(self: ?*const struct_ZigClangStmt) enum_ZigClangStmtClass; |
| 847 | pub extern fn ZigClangStmt_classof_Expr(self: ?*const struct_ZigClangStmt) bool; | 848 | pub extern fn ZigClangStmt_classof_Expr(self: ?*const struct_ZigClangStmt) bool; |
| ... | @@ -863,6 +864,10 @@ pub extern fn ZigClangAPSInt_getRawData(self: ?*const struct_ZigClangAPSInt) [*c | ... | @@ -863,6 +864,10 @@ pub extern fn ZigClangAPSInt_getRawData(self: ?*const struct_ZigClangAPSInt) [*c |
| 863 | pub extern fn ZigClangAPSInt_getNumWords(self: ?*const struct_ZigClangAPSInt) c_uint; | 864 | pub extern fn ZigClangAPSInt_getNumWords(self: ?*const struct_ZigClangAPSInt) c_uint; |
| 864 | pub extern fn ZigClangAPValueLValueBase_dyn_cast_Expr(self: struct_ZigClangAPValueLValueBase) ?*const struct_ZigClangExpr; | 865 | pub extern fn ZigClangAPValueLValueBase_dyn_cast_Expr(self: struct_ZigClangAPValueLValueBase) ?*const struct_ZigClangExpr; |
| 865 | pub extern fn ZigClangASTUnit_delete(arg0: ?*struct_ZigClangASTUnit) void; | 866 | pub extern fn ZigClangASTUnit_delete(arg0: ?*struct_ZigClangASTUnit) void; |
| 867 | |||
| 868 | pub extern fn ZigClangFunctionDecl_getType(self: *const struct_ZigClangFunctionDecl) struct_ZigClangQualType; | ||
| 869 | pub extern fn ZigClangFunctionDecl_getLocation(self: *const struct_ZigClangFunctionDecl) struct_ZigClangSourceLocation; | ||
| 870 | |||
| 866 | pub const ZigClangSourceLocation = struct_ZigClangSourceLocation; | 871 | pub const ZigClangSourceLocation = struct_ZigClangSourceLocation; |
| 867 | pub const ZigClangQualType = struct_ZigClangQualType; | 872 | pub const ZigClangQualType = struct_ZigClangQualType; |
| 868 | pub const ZigClangAPValueLValueBase = struct_ZigClangAPValueLValueBase; | 873 | pub const ZigClangAPValueLValueBase = struct_ZigClangAPValueLValueBase; |
| ... | @@ -944,6 +949,10 @@ pub const ZigClangStmtClass = enum_ZigClangStmtClass; | ... | @@ -944,6 +949,10 @@ pub const ZigClangStmtClass = enum_ZigClangStmtClass; |
| 944 | pub const ZigClangCK = enum_ZigClangCK; | 949 | pub const ZigClangCK = enum_ZigClangCK; |
| 945 | pub const ZigClangAPValueKind = enum_ZigClangAPValueKind; | 950 | pub const ZigClangAPValueKind = enum_ZigClangAPValueKind; |
| 946 | 951 | ||
| 952 | pub const struct_ZigClangSourceLocation = extern struct { | ||
| 953 | ID: c_uint, | ||
| 954 | }; | ||
| 955 | |||
| 947 | pub const Stage2ErrorMsg = extern struct { | 956 | pub const Stage2ErrorMsg = extern struct { |
| 948 | filename_ptr: ?[*]const u8, | 957 | filename_ptr: ?[*]const u8, |
| 949 | filename_len: usize, | 958 | filename_len: usize, |
| ... | @@ -968,8 +977,8 @@ pub extern fn ZigClangLoadFromCommandLine( | ... | @@ -968,8 +977,8 @@ pub extern fn ZigClangLoadFromCommandLine( |
| 968 | resources_path: [*c]const u8, | 977 | resources_path: [*c]const u8, |
| 969 | ) ?*ZigClangASTUnit; | 978 | ) ?*ZigClangASTUnit; |
| 970 | 979 | ||
| 971 | |||
| 972 | pub extern fn ZigClangDecl_getKind(decl: *const ZigClangDecl) ZigClangDeclKind; | 980 | pub extern fn ZigClangDecl_getKind(decl: *const ZigClangDecl) ZigClangDeclKind; |
| 981 | pub extern fn ZigClangDecl_getDeclKindName(decl: *const struct_ZigClangDecl) [*]const u8; | ||
| 973 | 982 | ||
| 974 | pub const ZigClangDeclKind = extern enum { | 983 | pub const ZigClangDeclKind = extern enum { |
| 975 | AccessSpec, | 984 | AccessSpec, |
| ... | @@ -1047,3 +1056,7 @@ pub const ZigClangDeclKind = extern enum { | ... | @@ -1047,3 +1056,7 @@ pub const ZigClangDeclKind = extern enum { |
| 1047 | StaticAssert, | 1056 | StaticAssert, |
| 1048 | TranslationUnit, | 1057 | TranslationUnit, |
| 1049 | }; | 1058 | }; |
| 1059 | |||
| 1060 | pub const struct_ZigClangQualType = extern struct { | ||
| 1061 | ptr: ?*c_void, | ||
| 1062 | }; |
src-self-hosted/stage1.zig+2-1| ... | @@ -90,7 +90,8 @@ export fn stage2_translate_c( | ... | @@ -90,7 +90,8 @@ export fn stage2_translate_c( |
| 90 | .import => translate_c.Mode.import, | 90 | .import => translate_c.Mode.import, |
| 91 | .translate => translate_c.Mode.translate, | 91 | .translate => translate_c.Mode.translate, |
| 92 | }, &errors, resources_path) catch |err| switch (err) { | 92 | }, &errors, resources_path) catch |err| switch (err) { |
| 93 | error.SemanticAnalyzeFail => { | 93 | // TODO after https://github.com/ziglang/zig/issues/769 we can remove error.UnsupportedType |
| 94 | error.SemanticAnalyzeFail, error.UnsupportedType => { | ||
| 94 | out_errors_ptr.* = errors.ptr; | 95 | out_errors_ptr.* = errors.ptr; |
| 95 | out_errors_len.* = errors.len; | 96 | out_errors_len.* = errors.len; |
| 96 | return Error.CCompileErrors; | 97 | return Error.CCompileErrors; |
src-self-hosted/translate_c.zig+54-8| ... | @@ -13,12 +13,16 @@ pub const Mode = enum { | ... | @@ -13,12 +13,16 @@ pub const Mode = enum { |
| 13 | 13 | ||
| 14 | pub const ClangErrMsg = Stage2ErrorMsg; | 14 | pub const ClangErrMsg = Stage2ErrorMsg; |
| 15 | 15 | ||
| 16 | pub const Error = error{OutOfMemory}; | 16 | pub const Error = error{ |
| 17 | OutOfMemory, | ||
| 18 | UnsupportedType, | ||
| 19 | }; | ||
| 17 | 20 | ||
| 18 | const Context = struct { | 21 | const Context = struct { |
| 19 | tree: *ast.Tree, | 22 | tree: *ast.Tree, |
| 20 | source_buffer: *std.Buffer, | 23 | source_buffer: *std.Buffer, |
| 21 | err: Error, | 24 | err: Error, |
| 25 | source_manager: *ZigClangSourceManager, | ||
| 22 | 26 | ||
| 23 | fn a(c: *Context) *std.mem.Allocator { | 27 | fn a(c: *Context) *std.mem.Allocator { |
| 24 | return &c.tree.arena_allocator.allocator; | 28 | return &c.tree.arena_allocator.allocator; |
| ... | @@ -28,6 +32,17 @@ const Context = struct { | ... | @@ -28,6 +32,17 @@ const Context = struct { |
| 28 | fn str(c: *Context, s: [*]const u8) ![]u8 { | 32 | fn str(c: *Context, s: [*]const u8) ![]u8 { |
| 29 | return std.mem.dupe(c.a(), u8, std.mem.toSliceConst(u8, s)); | 33 | return std.mem.dupe(c.a(), u8, std.mem.toSliceConst(u8, s)); |
| 30 | } | 34 | } |
| 35 | |||
| 36 | /// Convert a clang source location to a file:line:column string | ||
| 37 | fn locStr(c: *Context, loc: ZigClangSourceLocation) ![]u8 { | ||
| 38 | const spelling_loc = ZigClangSourceManager_getSpellingLoc(c.source_manager, loc); | ||
| 39 | const filename_c = ZigClangSourceManager_getFilename(c.source_manager, spelling_loc); | ||
| 40 | const filename = if (filename_c) |s| try c.str(s) else ([]const u8)("(no file)"); | ||
| 41 | |||
| 42 | const line = ZigClangSourceManager_getSpellingLineNumber(c.source_manager, spelling_loc); | ||
| 43 | const column = ZigClangSourceManager_getSpellingColumnNumber(c.source_manager, spelling_loc); | ||
| 44 | return std.fmt.allocPrint(c.a(), "{}:{}:{}", filename, line, column); | ||
| 45 | } | ||
| 31 | }; | 46 | }; |
| 32 | 47 | ||
| 33 | pub fn translate( | 48 | pub fn translate( |
| ... | @@ -78,6 +93,7 @@ pub fn translate( | ... | @@ -78,6 +93,7 @@ pub fn translate( |
| 78 | var context = Context{ | 93 | var context = Context{ |
| 79 | .tree = tree, | 94 | .tree = tree, |
| 80 | .source_buffer = &source_buffer, | 95 | .source_buffer = &source_buffer, |
| 96 | .source_manager = ZigClangASTUnit_getSourceManager(ast_unit), | ||
| 81 | .err = undefined, | 97 | .err = undefined, |
| 82 | }; | 98 | }; |
| 83 | 99 | ||
| ... | @@ -105,27 +121,57 @@ fn declVisitor(c: *Context, decl: *const ZigClangDecl) Error!void { | ... | @@ -105,27 +121,57 @@ fn declVisitor(c: *Context, decl: *const ZigClangDecl) Error!void { |
| 105 | return visitFnDecl(c, @ptrCast(*const ZigClangFunctionDecl, decl)); | 121 | return visitFnDecl(c, @ptrCast(*const ZigClangFunctionDecl, decl)); |
| 106 | }, | 122 | }, |
| 107 | .Typedef => { | 123 | .Typedef => { |
| 108 | try appendToken(c, .LineComment, "// TODO translate typedef"); | 124 | try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for typedefs"); |
| 109 | }, | 125 | }, |
| 110 | .Enum => { | 126 | .Enum => { |
| 111 | try appendToken(c, .LineComment, "// TODO translate enum"); | 127 | try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for enums"); |
| 112 | }, | 128 | }, |
| 113 | .Record => { | 129 | .Record => { |
| 114 | try appendToken(c, .LineComment, "// TODO translate struct"); | 130 | try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for structs"); |
| 115 | }, | 131 | }, |
| 116 | .Var => { | 132 | .Var => { |
| 117 | try appendToken(c, .LineComment, "// TODO translate variable"); | 133 | try emitWarning(c, ZigClangDecl_getLocation(decl), "TODO implement translate-c for variables"); |
| 118 | }, | 134 | }, |
| 119 | else => { | 135 | else => { |
| 120 | // TODO emit_warning(c, bitcast(decl->getLocation()), "ignoring %s decl", decl->getDeclKindName()); | 136 | const decl_name = try c.str(ZigClangDecl_getDeclKindName(decl)); |
| 121 | try appendToken(c, .LineComment, "// TODO translate unknown decl"); | 137 | try emitWarning(c, ZigClangDecl_getLocation(decl), "ignoring {} declaration", decl_name); |
| 122 | }, | 138 | }, |
| 123 | } | 139 | } |
| 124 | } | 140 | } |
| 125 | 141 | ||
| 126 | fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { | 142 | fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { |
| 127 | const fn_name = c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, fn_decl))); | 143 | const fn_name = c.str(ZigClangDecl_getName_bytes_begin(@ptrCast(*const ZigClangDecl, fn_decl))); |
| 128 | try appendToken(c, .LineComment, "// TODO translate function '{}'", fn_name); | 144 | |
| 145 | // TODO The C++ code has this: | ||
| 146 | //if (get_global(c, fn_name)) { | ||
| 147 | // // we already saw this function | ||
| 148 | // return; | ||
| 149 | //} | ||
| 150 | |||
| 151 | const fn_decl_loc = ZigClangFunctionDecl_getLocation(fn_decl); | ||
| 152 | const proto_node = transQualType(c, ZigClangFunctionDecl_getType(fn_decl), fn_decl_loc) catch |e| switch (e) { | ||
| 153 | error.UnsupportedType => { | ||
| 154 | try emitWarning(c, fn_decl_loc, "unable to resolve prototype of function '{}'", fn_name); | ||
| 155 | return; | ||
| 156 | }, | ||
| 157 | else => return e, | ||
| 158 | }; | ||
| 159 | |||
| 160 | try emitWarning(c, fn_decl_loc, "TODO implement translate-c for function decls"); | ||
| 161 | } | ||
| 162 | |||
| 163 | fn transQualType(c: *Context, qt: ZigClangQualType, source_loc: ZigClangSourceLocation) !*ast.Node { | ||
| 164 | return transType(c, ZigClangQualType_getTypePtr(qt), source_loc); | ||
| 165 | } | ||
| 166 | |||
| 167 | fn transType(c: *Context, ty: *const ZigClangType, source_loc: ZigClangSourceLocation) !*ast.Node { | ||
| 168 | const type_name = c.str(ZigClangType_getTypeClassName(ty)); | ||
| 169 | try emitWarning(c, source_loc, "unsupported type: '{}'", type_name); | ||
| 170 | return error.UnsupportedType; | ||
| 171 | } | ||
| 172 | |||
| 173 | fn emitWarning(c: *Context, loc: ZigClangSourceLocation, comptime format: []const u8, args: ...) !void { | ||
| 174 | try appendToken(c, .LineComment, "// {}: warning: " ++ format, c.locStr(loc), args); | ||
| 129 | } | 175 | } |
| 130 | 176 | ||
| 131 | fn appendToken(c: *Context, token_id: Token.Id, comptime format: []const u8, args: ...) !void { | 177 | fn appendToken(c: *Context, token_id: Token.Id, comptime format: []const u8, args: ...) !void { |
src/translate_c.cpp+15-13| ... | @@ -4009,7 +4009,7 @@ static TransScope *trans_stmt(Context *c, TransScope *scope, const ZigClangStmt | ... | @@ -4009,7 +4009,7 @@ static TransScope *trans_stmt(Context *c, TransScope *scope, const ZigClangStmt |
| 4009 | return child_scope; | 4009 | return child_scope; |
| 4010 | } | 4010 | } |
| 4011 | 4011 | ||
| 4012 | static void visit_fn_decl(Context *c, const clang::FunctionDecl *fn_decl) { | 4012 | static void visit_fn_decl(Context *c, const ZigClangFunctionDecl *fn_decl) { |
| 4013 | Buf *fn_name = buf_create_from_str(ZigClangDecl_getName_bytes_begin((const ZigClangDecl *)fn_decl)); | 4013 | Buf *fn_name = buf_create_from_str(ZigClangDecl_getName_bytes_begin((const ZigClangDecl *)fn_decl)); |
| 4014 | 4014 | ||
| 4015 | if (get_global(c, fn_name)) { | 4015 | if (get_global(c, fn_name)) { |
| ... | @@ -4017,26 +4017,28 @@ static void visit_fn_decl(Context *c, const clang::FunctionDecl *fn_decl) { | ... | @@ -4017,26 +4017,28 @@ static void visit_fn_decl(Context *c, const clang::FunctionDecl *fn_decl) { |
| 4017 | return; | 4017 | return; |
| 4018 | } | 4018 | } |
| 4019 | 4019 | ||
| 4020 | AstNode *proto_node = trans_qual_type(c, bitcast(fn_decl->getType()), bitcast(fn_decl->getLocation())); | 4020 | AstNode *proto_node = trans_qual_type(c, ZigClangFunctionDecl_getType(fn_decl), |
| 4021 | ZigClangFunctionDecl_getLocation(fn_decl)); | ||
| 4021 | if (proto_node == nullptr) { | 4022 | if (proto_node == nullptr) { |
| 4022 | emit_warning(c, bitcast(fn_decl->getLocation()), "unable to resolve prototype of function '%s'", buf_ptr(fn_name)); | 4023 | emit_warning(c, ZigClangFunctionDecl_getLocation(fn_decl), |
| 4024 | "unable to resolve prototype of function '%s'", buf_ptr(fn_name)); | ||
| 4023 | return; | 4025 | return; |
| 4024 | } | 4026 | } |
| 4025 | 4027 | ||
| 4026 | proto_node->data.fn_proto.name = fn_name; | 4028 | proto_node->data.fn_proto.name = fn_name; |
| 4027 | proto_node->data.fn_proto.is_extern = !fn_decl->hasBody(); | 4029 | proto_node->data.fn_proto.is_extern = !((const clang::FunctionDecl*)fn_decl)->hasBody(); |
| 4028 | 4030 | ||
| 4029 | clang::StorageClass sc = fn_decl->getStorageClass(); | 4031 | clang::StorageClass sc = ((const clang::FunctionDecl*)fn_decl)->getStorageClass(); |
| 4030 | if (sc == clang::SC_None) { | 4032 | if (sc == clang::SC_None) { |
| 4031 | proto_node->data.fn_proto.visib_mod = c->visib_mod; | 4033 | proto_node->data.fn_proto.visib_mod = c->visib_mod; |
| 4032 | proto_node->data.fn_proto.is_export = fn_decl->hasBody() ? c->want_export : false; | 4034 | proto_node->data.fn_proto.is_export = ((const clang::FunctionDecl*)fn_decl)->hasBody() ? c->want_export : false; |
| 4033 | } else if (sc == clang::SC_Extern || sc == clang::SC_Static) { | 4035 | } else if (sc == clang::SC_Extern || sc == clang::SC_Static) { |
| 4034 | proto_node->data.fn_proto.visib_mod = c->visib_mod; | 4036 | proto_node->data.fn_proto.visib_mod = c->visib_mod; |
| 4035 | } else if (sc == clang::SC_PrivateExtern) { | 4037 | } else if (sc == clang::SC_PrivateExtern) { |
| 4036 | emit_warning(c, bitcast(fn_decl->getLocation()), "unsupported storage class: private extern"); | 4038 | emit_warning(c, ZigClangFunctionDecl_getLocation(fn_decl), "unsupported storage class: private extern"); |
| 4037 | return; | 4039 | return; |
| 4038 | } else { | 4040 | } else { |
| 4039 | emit_warning(c, bitcast(fn_decl->getLocation()), "unsupported storage class: unknown"); | 4041 | emit_warning(c, ZigClangFunctionDecl_getLocation(fn_decl), "unsupported storage class: unknown"); |
| 4040 | return; | 4042 | return; |
| 4041 | } | 4043 | } |
| 4042 | 4044 | ||
| ... | @@ -4044,7 +4046,7 @@ static void visit_fn_decl(Context *c, const clang::FunctionDecl *fn_decl) { | ... | @@ -4044,7 +4046,7 @@ static void visit_fn_decl(Context *c, const clang::FunctionDecl *fn_decl) { |
| 4044 | 4046 | ||
| 4045 | for (size_t i = 0; i < proto_node->data.fn_proto.params.length; i += 1) { | 4047 | for (size_t i = 0; i < proto_node->data.fn_proto.params.length; i += 1) { |
| 4046 | AstNode *param_node = proto_node->data.fn_proto.params.at(i); | 4048 | AstNode *param_node = proto_node->data.fn_proto.params.at(i); |
| 4047 | const clang::ParmVarDecl *param = fn_decl->getParamDecl(i); | 4049 | const clang::ParmVarDecl *param = ((const clang::FunctionDecl*)fn_decl)->getParamDecl(i); |
| 4048 | const char *name = ZigClangDecl_getName_bytes_begin((const ZigClangDecl *)param); | 4050 | const char *name = ZigClangDecl_getName_bytes_begin((const ZigClangDecl *)param); |
| 4049 | 4051 | ||
| 4050 | Buf *proto_param_name; | 4052 | Buf *proto_param_name; |
| ... | @@ -4063,7 +4065,7 @@ static void visit_fn_decl(Context *c, const clang::FunctionDecl *fn_decl) { | ... | @@ -4063,7 +4065,7 @@ static void visit_fn_decl(Context *c, const clang::FunctionDecl *fn_decl) { |
| 4063 | param_node->data.param_decl.name = scope_var->zig_name; | 4065 | param_node->data.param_decl.name = scope_var->zig_name; |
| 4064 | } | 4066 | } |
| 4065 | 4067 | ||
| 4066 | if (!fn_decl->hasBody()) { | 4068 | if (!((const clang::FunctionDecl*)fn_decl)->hasBody()) { |
| 4067 | // just a prototype | 4069 | // just a prototype |
| 4068 | add_top_level_decl(c, proto_node->data.fn_proto.name, proto_node); | 4070 | add_top_level_decl(c, proto_node->data.fn_proto.name, proto_node); |
| 4069 | return; | 4071 | return; |
| ... | @@ -4071,11 +4073,11 @@ static void visit_fn_decl(Context *c, const clang::FunctionDecl *fn_decl) { | ... | @@ -4071,11 +4073,11 @@ static void visit_fn_decl(Context *c, const clang::FunctionDecl *fn_decl) { |
| 4071 | 4073 | ||
| 4072 | // actual function definition with body | 4074 | // actual function definition with body |
| 4073 | c->ptr_params.clear(); | 4075 | c->ptr_params.clear(); |
| 4074 | const ZigClangStmt *body = bitcast(fn_decl->getBody()); | 4076 | const ZigClangStmt *body = bitcast(((const clang::FunctionDecl*)fn_decl)->getBody()); |
| 4075 | AstNode *actual_body_node; | 4077 | AstNode *actual_body_node; |
| 4076 | TransScope *result_scope = trans_stmt(c, scope, body, &actual_body_node); | 4078 | TransScope *result_scope = trans_stmt(c, scope, body, &actual_body_node); |
| 4077 | if (result_scope == nullptr) { | 4079 | if (result_scope == nullptr) { |
| 4078 | emit_warning(c, bitcast(fn_decl->getLocation()), "unable to translate function"); | 4080 | emit_warning(c, ZigClangFunctionDecl_getLocation(fn_decl), "unable to translate function"); |
| 4079 | return; | 4081 | return; |
| 4080 | } | 4082 | } |
| 4081 | assert(actual_body_node != nullptr); | 4083 | assert(actual_body_node != nullptr); |
| ... | @@ -4558,7 +4560,7 @@ static bool decl_visitor(void *context, const ZigClangDecl *decl) { | ... | @@ -4558,7 +4560,7 @@ static bool decl_visitor(void *context, const ZigClangDecl *decl) { |
| 4558 | 4560 | ||
| 4559 | switch (ZigClangDecl_getKind(decl)) { | 4561 | switch (ZigClangDecl_getKind(decl)) { |
| 4560 | case ZigClangDeclFunction: | 4562 | case ZigClangDeclFunction: |
| 4561 | visit_fn_decl(c, reinterpret_cast<const clang::FunctionDecl*>(decl)); | 4563 | visit_fn_decl(c, reinterpret_cast<const ZigClangFunctionDecl*>(decl)); |
| 4562 | break; | 4564 | break; |
| 4563 | case ZigClangDeclTypedef: | 4565 | case ZigClangDeclTypedef: |
| 4564 | resolve_typedef_decl(c, reinterpret_cast<const ZigClangTypedefNameDecl *>(decl)); | 4566 | resolve_typedef_decl(c, reinterpret_cast<const ZigClangTypedefNameDecl *>(decl)); |
src/zig_clang.cpp+10| ... | @@ -1142,6 +1142,16 @@ ZigClangQualType ZigClangEnumDecl_getIntegerType(const ZigClangEnumDecl *self) { | ... | @@ -1142,6 +1142,16 @@ ZigClangQualType ZigClangEnumDecl_getIntegerType(const ZigClangEnumDecl *self) { |
| 1142 | return bitcast(reinterpret_cast<const clang::EnumDecl *>(self)->getIntegerType()); | 1142 | return bitcast(reinterpret_cast<const clang::EnumDecl *>(self)->getIntegerType()); |
| 1143 | } | 1143 | } |
| 1144 | 1144 | ||
| 1145 | struct ZigClangQualType ZigClangFunctionDecl_getType(const struct ZigClangFunctionDecl *self) { | ||
| 1146 | auto casted = reinterpret_cast<const clang::FunctionDecl *>(self); | ||
| 1147 | return bitcast(casted->getType()); | ||
| 1148 | } | ||
| 1149 | |||
| 1150 | struct ZigClangSourceLocation ZigClangFunctionDecl_getLocation(const struct ZigClangFunctionDecl *self) { | ||
| 1151 | auto casted = reinterpret_cast<const clang::FunctionDecl *>(self); | ||
| 1152 | return bitcast(casted->getLocation()); | ||
| 1153 | } | ||
| 1154 | |||
| 1145 | const ZigClangTypedefNameDecl *ZigClangTypedefType_getDecl(const ZigClangTypedefType *self) { | 1155 | const ZigClangTypedefNameDecl *ZigClangTypedefType_getDecl(const ZigClangTypedefType *self) { |
| 1146 | auto casted = reinterpret_cast<const clang::TypedefType *>(self); | 1156 | auto casted = reinterpret_cast<const clang::TypedefType *>(self); |
| 1147 | const clang::TypedefNameDecl *name_decl = casted->getDecl(); | 1157 | const clang::TypedefNameDecl *name_decl = casted->getDecl(); |
src/zig_clang.h+3| ... | @@ -599,6 +599,9 @@ ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangEnumDecl_getLocation(const st | ... | @@ -599,6 +599,9 @@ ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangEnumDecl_getLocation(const st |
| 599 | ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangTypedefNameDecl_getLocation(const struct ZigClangTypedefNameDecl *); | 599 | ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangTypedefNameDecl_getLocation(const struct ZigClangTypedefNameDecl *); |
| 600 | ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangDecl_getLocation(const struct ZigClangDecl *); | 600 | ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangDecl_getLocation(const struct ZigClangDecl *); |
| 601 | 601 | ||
| 602 | ZIG_EXTERN_C struct ZigClangQualType ZigClangFunctionDecl_getType(const struct ZigClangFunctionDecl *); | ||
| 603 | ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangFunctionDecl_getLocation(const struct ZigClangFunctionDecl *); | ||
| 604 | |||
| 602 | ZIG_EXTERN_C bool ZigClangRecordDecl_isUnion(const struct ZigClangRecordDecl *record_decl); | 605 | ZIG_EXTERN_C bool ZigClangRecordDecl_isUnion(const struct ZigClangRecordDecl *record_decl); |
| 603 | ZIG_EXTERN_C bool ZigClangRecordDecl_isStruct(const struct ZigClangRecordDecl *record_decl); | 606 | ZIG_EXTERN_C bool ZigClangRecordDecl_isStruct(const struct ZigClangRecordDecl *record_decl); |
| 604 | ZIG_EXTERN_C bool ZigClangRecordDecl_isAnonymousStructOrUnion(const struct ZigClangRecordDecl *record_decl); | 607 | ZIG_EXTERN_C bool ZigClangRecordDecl_isAnonymousStructOrUnion(const struct ZigClangRecordDecl *record_decl); |