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...@@ -894,3 +894,7 @@ pub extern fn ZigClangParenType_getInnerType(*const ZigClangParenType) ZigClangQ
894pub extern fn ZigClangElaboratedType_getNamedType(*const ZigClangElaboratedType) ZigClangQualType;894pub extern fn ZigClangElaboratedType_getNamedType(*const ZigClangElaboratedType) ZigClangQualType;
895895
896pub extern fn ZigClangAttributedType_getEquivalentType(*const ZigClangAttributedType) ZigClangQualType;896pub 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(...@@ -329,9 +329,10 @@ fn transStmt(
329 const sc = ZigClangStmt_getStmtClass(stmt);329 const sc = ZigClangStmt_getStmtClass(stmt);
330 switch (sc) {330 switch (sc) {
331 .CompoundStmtClass => return transCompoundStmt(rp, scope, @ptrCast(*const ZigClangCompoundStmt, stmt)),331 .CompoundStmtClass => return transCompoundStmt(rp, scope, @ptrCast(*const ZigClangCompoundStmt, stmt)),
332 .CStyleCastExprClass => return transCStyleCastExprClass(rp, scope, @ptrCast(*const ZigClangCStyleCastExpr, stmt), result_used, lrvalue),
332 .DeclStmtClass => return transDeclStmt(rp, scope, @ptrCast(*const ZigClangDeclStmt, stmt)),333 .DeclStmtClass => return transDeclStmt(rp, scope, @ptrCast(*const ZigClangDeclStmt, stmt)),
333 .DeclRefExprClass => return transDeclRefExpr(rp, scope, @ptrCast(*const ZigClangDeclRefExpr, stmt), lrvalue),334 .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),
335 else => {336 else => {
336 return revertAndWarn(337 return revertAndWarn(
337 rp,338 rp,
...@@ -377,6 +378,30 @@ fn transCompoundStmt(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangCompo...@@ -377,6 +378,30 @@ fn transCompoundStmt(rp: RestorePoint, scope: *Scope, stmt: *const ZigClangCompo
377 };378 };
378}379}
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
380fn transDeclStmt(rp: RestorePoint, parent_scope: *Scope, stmt: *const ZigClangDeclStmt) !TransResult {405fn transDeclStmt(rp: RestorePoint, parent_scope: *Scope, stmt: *const ZigClangDeclStmt) !TransResult {
381 const c = rp.c;406 const c = rp.c;
382 const block_scope = findBlockScope(parent_scope);407 const block_scope = findBlockScope(parent_scope);
...@@ -478,27 +503,23 @@ fn transImplicitCastExpr(...@@ -478,27 +503,23 @@ fn transImplicitCastExpr(
478 rp: RestorePoint,503 rp: RestorePoint,
479 scope: *Scope,504 scope: *Scope,
480 expr: *const ZigClangImplicitCastExpr,505 expr: *const ZigClangImplicitCastExpr,
506 result_used: ResultUsed,
481) !TransResult {507) !TransResult {
482 const c = rp.c;508 const c = rp.c;
483 const sub_expr = ZigClangImplicitCastExpr_getSubExpr(expr);509 const sub_expr = ZigClangImplicitCastExpr_getSubExpr(expr);
510 const sub_expr_node = try transExpr(rp, scope, @ptrCast(*const ZigClangExpr, sub_expr), .used, .r_value);
484 switch (ZigClangImplicitCastExpr_getCastKind(expr)) {511 switch (ZigClangImplicitCastExpr_getCastKind(expr)) {
485 .BitCast => {512 .BitCast => {
486 const node = try transExpr(rp, scope, @ptrCast(*const ZigClangExpr, sub_expr), .used, .r_value);
487 const dest_type = getExprQualType(c, @ptrCast(*const ZigClangExpr, expr));513 const dest_type = getExprQualType(c, @ptrCast(*const ZigClangExpr, expr));
488 const src_type = getExprQualType(c, sub_expr);514 const src_type = getExprQualType(c, sub_expr);
489 return TransResult{515 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),
491 .node_scope = scope,517 .node_scope = scope,
492 .child_scope = scope,518 .child_scope = scope,
493 };519 };
494 },520 },
495 .FunctionToPointerDecay, .ArrayToPointerDecay => {521 .FunctionToPointerDecay, .ArrayToPointerDecay => {
496 return maybeSuppressResult(522 return maybeSuppressResult(rp, scope, result_used, sub_expr_node);
497 rp,
498 scope,
499 .used,
500 try transExpr(rp, scope, @ptrCast(*const ZigClangExpr, sub_expr), .used, .r_value),
501 );
502 },523 },
503 else => |kind| return revertAndWarn(524 else => |kind| return revertAndWarn(
504 rp,525 rp,
src/zig_clang.cpp+15
...@@ -1964,3 +1964,18 @@ struct ZigClangQualType ZigClangElaboratedType_getNamedType(const struct ZigClan...@@ -1964,3 +1964,18 @@ struct ZigClangQualType ZigClangElaboratedType_getNamedType(const struct ZigClan
1964 auto casted = reinterpret_cast<const clang::ElaboratedType *>(self);1964 auto casted = reinterpret_cast<const clang::ElaboratedType *>(self);
1965 return bitcast(casted->getNamedType());1965 return bitcast(casted->getNamedType());
1966}1966}
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...@@ -885,4 +885,8 @@ ZIG_EXTERN_C struct ZigClangQualType ZigClangAttributedType_getEquivalentType(co
885885
886ZIG_EXTERN_C struct ZigClangQualType ZigClangElaboratedType_getNamedType(const struct ZigClangElaboratedType *);886ZIG_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
888#endif892#endif