authorgravatar for codroid@gmail.comhryx <codroid@gmail.com> 2019-06-08 15:54:15-07:00
committergravatar for codroid@gmail.comhryx <codroid@gmail.com> 2019-06-08 15:54:15-07:00
log1f82c7ba2243bb16a5036a22d34e9762302303de
tree28210fb1fb68186cdc5d721a78a2ab2cee789ffc
parent3e14f86f9e703a4d189aab5e2f27c1029927c9e9
signaturelock-open Commit is signed but in an unrecognized format.

transCStyleCastExpr


4 files changed, 53 insertions(+), 9 deletions(-)

src-self-hosted/clang.zig+4
......@@ -894,3 +894,7 @@ pub extern fn ZigClangParenType_getInnerType(*const ZigClangParenType) ZigClangQ
894894pub extern fn ZigClangElaboratedType_getNamedType(*const ZigClangElaboratedType) ZigClangQualType;
895895
896896pub extern fn ZigClangAttributedType_getEquivalentType(*const ZigClangAttributedType) ZigClangQualType;
897
898pub extern fn ZigClangCStyleCastExpr_getBeginLoc(*const ZigClangCStyleCastExpr) ZigClangSourceLocation;
899pub extern fn ZigClangCStyleCastExpr_getSubExpr(*const ZigClangCStyleCastExpr) *const ZigClangExpr;
900pub extern fn ZigClangCStyleCastExpr_getType(*const ZigClangCStyleCastExpr) ZigClangQualType;
src-self-hosted/translate_c.zig+30-9
......@@ -329,9 +329,10 @@ fn transStmt(
329329 const sc = ZigClangStmt_getStmtClass(stmt);
330330 switch (sc) {
331331 .CompoundStmtClass => return transCompoundStmt(rp, scope, @ptrCast(*const ZigClangCompoundStmt, stmt)),
332 .CStyleCastExprClass => return transCStyleCastExprClass(rp, scope, @ptrCast(*const ZigClangCStyleCastExpr, stmt), result_used, lrvalue),
332333 .DeclStmtClass => return transDeclStmt(rp, scope, @ptrCast(*const ZigClangDeclStmt, stmt)),
333334 .DeclRefExprClass => return transDeclRefExpr(rp, scope, @ptrCast(*const ZigClangDeclRefExpr, stmt), lrvalue),
334 .ImplicitCastExprClass => return transImplicitCastExpr(rp, scope, @ptrCast(*const ZigClangImplicitCastExpr, stmt)),
335 .ImplicitCastExprClass => return transImplicitCastExpr(rp, scope, @ptrCast(*const ZigClangImplicitCastExpr, stmt), result_used),
335336 else => {
336337 return revertAndWarn(
337338 rp,
......@@ -377,6 +378,30 @@ fn transCompoundStmt(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangCompo
377378 };
378379}
379380
381fn transCStyleCastExprClass(
382 rp: RestorePoint,
383 scope: *Scope,
384 stmt: *const ZigClangCStyleCastExpr,
385 result_used: ResultUsed,
386 lrvalue: LRValue,
387) !TransResult {
388 const sub_expr = ZigClangCStyleCastExpr_getSubExpr(stmt);
389 const cast_node = (try transCCast(
390 rp,
391 scope,
392 ZigClangCStyleCastExpr_getBeginLoc(stmt),
393 ZigClangCStyleCastExpr_getType(stmt),
394 ZigClangExpr_getType(sub_expr),
395 (try transExpr(rp, scope, sub_expr, .used, lrvalue)).node,
396 ));
397 const cast_res = TransResult{
398 .node = cast_node,
399 .child_scope = scope,
400 .node_scope = scope,
401 };
402 return maybeSuppressResult(rp, scope, result_used, cast_res);
403}
404
380405fn transDeclStmt(rp: RestorePoint, parent_scope: *Scope, stmt: *const ZigClangDeclStmt) !TransResult {
381406 const c = rp.c;
382407 const block_scope = findBlockScope(parent_scope);
......@@ -478,27 +503,23 @@ fn transImplicitCastExpr(
478503 rp: RestorePoint,
479504 scope: *Scope,
480505 expr: *const ZigClangImplicitCastExpr,
506 result_used: ResultUsed,
481507) !TransResult {
482508 const c = rp.c;
483509 const sub_expr = ZigClangImplicitCastExpr_getSubExpr(expr);
510 const sub_expr_node = try transExpr(rp, scope, @ptrCast(*const ZigClangExpr, sub_expr), .used, .r_value);
484511 switch (ZigClangImplicitCastExpr_getCastKind(expr)) {
485512 .BitCast => {
486 const node = try transExpr(rp, scope, @ptrCast(*const ZigClangExpr, sub_expr), .used, .r_value);
487513 const dest_type = getExprQualType(c, @ptrCast(*const ZigClangExpr, expr));
488514 const src_type = getExprQualType(c, sub_expr);
489515 return TransResult{
490 .node = try transCCast(rp, scope, ZigClangImplicitCastExpr_getBeginLoc(expr), dest_type, src_type, node.node),
516 .node = try transCCast(rp, scope, ZigClangImplicitCastExpr_getBeginLoc(expr), dest_type, src_type, sub_expr_node.node),
491517 .node_scope = scope,
492518 .child_scope = scope,
493519 };
494520 },
495521 .FunctionToPointerDecay, .ArrayToPointerDecay => {
496 return maybeSuppressResult(
497 rp,
498 scope,
499 .used,
500 try transExpr(rp, scope, @ptrCast(*const ZigClangExpr, sub_expr), .used, .r_value),
501 );
522 return maybeSuppressResult(rp, scope, result_used, sub_expr_node);
502523 },
503524 else => |kind| return revertAndWarn(
504525 rp,
src/zig_clang.cpp+15
......@@ -1964,3 +1964,18 @@ struct ZigClangQualType ZigClangElaboratedType_getNamedType(const struct ZigClan
19641964 auto casted = reinterpret_cast<const clang::ElaboratedType *>(self);
19651965 return bitcast(casted->getNamedType());
19661966}
1967
1968struct ZigClangSourceLocation ZigClangCStyleCastExpr_getBeginLoc(const struct ZigClangCStyleCastExpr *self) {
1969 auto casted = reinterpret_cast<const clang::CStyleCastExpr *>(self);
1970 return bitcast(casted->getBeginLoc());
1971}
1972
1973const struct ZigClangExpr *ZigClangCStyleCastExpr_getSubExpr(const struct ZigClangCStyleCastExpr *self) {
1974 auto casted = reinterpret_cast<const clang::CStyleCastExpr *>(self);
1975 return reinterpret_cast<const struct ZigClangExpr *>(casted->getSubExpr());
1976}
1977
1978struct ZigClangQualType ZigClangCStyleCastExpr_getType(const struct ZigClangCStyleCastExpr *self) {
1979 auto casted = reinterpret_cast<const clang::CStyleCastExpr *>(self);
1980 return bitcast(casted->getType());
1981}
src/zig_clang.h+4
......@@ -885,4 +885,8 @@ ZIG_EXTERN_C struct ZigClangQualType ZigClangAttributedType_getEquivalentType(co
885885
886886ZIG_EXTERN_C struct ZigClangQualType ZigClangElaboratedType_getNamedType(const struct ZigClangElaboratedType *);
887887
888ZIG_EXTERN_C struct ZigClangSourceLocation ZigClangCStyleCastExpr_getBeginLoc(const struct ZigClangCStyleCastExpr *);
889ZIG_EXTERN_C const struct ZigClangExpr *ZigClangCStyleCastExpr_getSubExpr(const struct ZigClangCStyleCastExpr *);
890ZIG_EXTERN_C struct ZigClangQualType ZigClangCStyleCastExpr_getType(const struct ZigClangCStyleCastExpr *);
891
888892#endif