Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed structs size calculating in arrays #389

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions project/src/transpiler/transpile_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -932,10 +932,24 @@ std::pair<uint64_t, EOObject> 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<clang::ConstantArrayType>(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) {
Expand Down
15 changes: 15 additions & 0 deletions project/tests/main/types/type_formats/formats1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>

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;
}