From 180b49bf956f7943f3d82384ca422eb1ae0c028c Mon Sep 17 00:00:00 2001 From: LeDron12 Date: Sun, 11 Sep 2022 17:45:17 +0300 Subject: [PATCH 1/3] formats tests --- .../main/types/type_formats/char_print.c | 52 +++++++++++++++++++ .../tests/main/types/type_formats/formats1.c | 15 ++++++ 2 files changed, 67 insertions(+) create mode 100644 project/tests/main/types/type_formats/char_print.c create mode 100644 project/tests/main/types/type_formats/formats1.c diff --git a/project/tests/main/types/type_formats/char_print.c b/project/tests/main/types/type_formats/char_print.c new file mode 100644 index 00000000..e74f2a19 --- /dev/null +++ b/project/tests/main/types/type_formats/char_print.c @@ -0,0 +1,52 @@ +#include + +void charfunc(char a) +{ + printf("char: %c\n", a); +} + +void intfunc(int a) +{ + printf("int: %d\n", a); +} + +void floatfunc(float a) +{ + printf("float: %f\n", a); +} + +int main() +{ + charfunc('a'); +// charfunc(98); +// charfunc(99.0); +// +// intfunc('a'); +// intfunc(98); +// intfunc(99.0); +// +// floatfunc('a'); +// floatfunc(98); +// floatfunc(99.0); + + /* printf("%c %d %f\n", 'a', 'b', 'c'); */ + /* printf("%c %d %f\n", 97, 98, 99); */ + /* printf("%c %d %f\n", 97.0, 98.0, 99.0); */ + +// char b = 97; +// char c = 97.0; +// +// printf("%d %d\n", b, c); +// +// int d = 'a'; +// int e = 97.0; +// +// printf("%d %d\n", d, e); +// +// float f = 'a'; +// float g = 97; +// +// printf("%f %f\n", f, g); + + return 0; +} \ No newline at end of file diff --git a/project/tests/main/types/type_formats/formats1.c b/project/tests/main/types/type_formats/formats1.c new file mode 100644 index 00000000..278b1469 --- /dev/null +++ b/project/tests/main/types/type_formats/formats1.c @@ -0,0 +1,15 @@ +#include + +int i1 = 555, i2 = 32; +unsigned int ui1 = 1111; +long long ll1 = 2222; + +int main() { + printf("%d\n", i1); + printf("%u\n", ui1); + printf("%lld\n", ll1); + printf("%o\n", i2); + printf("%x\n", i2); + return 0; +} + From cfd7a2232961c1d53f69036df6b2a270dc2e218a Mon Sep 17 00:00:00 2001 From: LeDron12 Date: Wed, 14 Sep 2022 19:53:05 +0300 Subject: [PATCH 2/3] fixed struct size in array --- project/src/transpiler/transpile_helper.cpp | 18 +++++-- .../main/types/type_formats/char_print.c | 52 ------------------- 2 files changed, 14 insertions(+), 56 deletions(-) delete mode 100644 project/tests/main/types/type_formats/char_print.c diff --git a/project/src/transpiler/transpile_helper.cpp b/project/src/transpiler/transpile_helper.cpp index 6b958fc1..45d3773c 100644 --- a/project/src/transpiler/transpile_helper.cpp +++ b/project/src/transpiler/transpile_helper.cpp @@ -537,7 +537,7 @@ EOObject GetInitListEOObject(const clang::InitListExpr *list) { ->getElementType(); } elementTypeName = GetTypeName(elementQualType); - elementSize *= context->getTypeInfo(elementQualType).Align / byte_size; + elementSize *= context->getTypeInfo(elementQualType).Width / byte_size; } else if (qualType->isRecordType()) { auto *recordType = transpiler.record_manager_.GetById( qualType->getAsRecordDecl()->getID()); @@ -932,10 +932,20 @@ std::pair getMultiDimArrayTypeSize( continue; } auto qt = decl_ref_expr->getType(); + auto n = decl_ref_expr->getStmtClassName(); EOObject arr_name = GetStmtEOObject(op->getBase()); - size_t sz = - decl_ref_expr->getDecl()->getASTContext().getTypeInfo(qt).Align / - byte_size; + size_t sz; + if (qt->isArrayType()) { + const auto *arr = qt->getAsArrayTypeUnsafe(); + if (arr->isConstantArrayType()) { + const auto *const_arr = dyn_cast(qt); + auto qelem_qt = const_arr->getElementType(); + sz = decl_ref_expr->getDecl()->getASTContext().getTypeInfo(qelem_qt).Width / byte_size; + } + } else { + sz = decl_ref_expr->getDecl()->getASTContext().getTypeInfo(qt).Align / + byte_size; + } return std::make_pair(sz, arr_name); } if (stmt_class == Stmt::ArraySubscriptExprClass) { diff --git a/project/tests/main/types/type_formats/char_print.c b/project/tests/main/types/type_formats/char_print.c deleted file mode 100644 index e74f2a19..00000000 --- a/project/tests/main/types/type_formats/char_print.c +++ /dev/null @@ -1,52 +0,0 @@ -#include - -void charfunc(char a) -{ - printf("char: %c\n", a); -} - -void intfunc(int a) -{ - printf("int: %d\n", a); -} - -void floatfunc(float a) -{ - printf("float: %f\n", a); -} - -int main() -{ - charfunc('a'); -// charfunc(98); -// charfunc(99.0); -// -// intfunc('a'); -// intfunc(98); -// intfunc(99.0); -// -// floatfunc('a'); -// floatfunc(98); -// floatfunc(99.0); - - /* printf("%c %d %f\n", 'a', 'b', 'c'); */ - /* printf("%c %d %f\n", 97, 98, 99); */ - /* printf("%c %d %f\n", 97.0, 98.0, 99.0); */ - -// char b = 97; -// char c = 97.0; -// -// printf("%d %d\n", b, c); -// -// int d = 'a'; -// int e = 97.0; -// -// printf("%d %d\n", d, e); -// -// float f = 'a'; -// float g = 97; -// -// printf("%f %f\n", f, g); - - return 0; -} \ No newline at end of file From 8b2ec3d2db37b6fbea6330c81789e7b5226d552e Mon Sep 17 00:00:00 2001 From: LeDron12 Date: Wed, 14 Sep 2022 19:54:13 +0300 Subject: [PATCH 3/3] fixed struct size in array --- project/src/transpiler/transpile_helper.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/project/src/transpiler/transpile_helper.cpp b/project/src/transpiler/transpile_helper.cpp index 45d3773c..335b3771 100644 --- a/project/src/transpiler/transpile_helper.cpp +++ b/project/src/transpiler/transpile_helper.cpp @@ -940,7 +940,11 @@ std::pair getMultiDimArrayTypeSize( if (arr->isConstantArrayType()) { const auto *const_arr = dyn_cast(qt); auto qelem_qt = const_arr->getElementType(); - sz = decl_ref_expr->getDecl()->getASTContext().getTypeInfo(qelem_qt).Width / byte_size; + sz = decl_ref_expr->getDecl() + ->getASTContext() + .getTypeInfo(qelem_qt) + .Width / + byte_size; } } else { sz = decl_ref_expr->getDecl()->getASTContext().getTypeInfo(qt).Align /