From 3002dcf6c49afd3bdea13ec23e40549aff4a034d Mon Sep 17 00:00:00 2001 From: Boris Batkin Date: Tue, 28 Oct 2025 11:22:13 -0700 Subject: [PATCH 1/2] better bitmap locations, also alias types --- src/ast/ast_infer_type.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/ast/ast_infer_type.cpp b/src/ast/ast_infer_type.cpp index 015061e4dd..c2ab2ac705 100644 --- a/src/ast/ast_infer_type.cpp +++ b/src/ast/ast_infer_type.cpp @@ -5817,6 +5817,13 @@ namespace das { return nullptr; } + LineInfo makeConstAt ( ExprField * expr ) const { + LineInfo constAt = expr->value->at; + constAt.last_column = expr->atField.last_column; + constAt.last_line = expr->atField.last_line; + return constAt; + } + virtual ExpressionPtr visit ( ExprField * expr ) override { if ( expr->value->rtti_isVar() && !expr->value->type ) { // if its a var expression, but it did not infer auto var = static_cast(expr->value.get()); @@ -5847,7 +5854,7 @@ namespace das { reportAstChanged(); auto td = make_smart(possibleEnums.back()); td->constant = true; - auto res = make_smart(expr->at, expr->name, td); + auto res = make_smart(makeConstAt(expr), expr->name, td); bool infE = false; res->value = getEnumerationValue(res.get(), infE); if ( infE ) res->type = td; @@ -5859,7 +5866,7 @@ namespace das { reportAstChanged(); auto td = make_smart(*alias); td->ref = false; - auto bitConst = new ExprConstBitfield(expr->at, 1ull << uint64_t(bit)); + auto bitConst = new ExprConstBitfield(makeConstAt(expr), 1ull << uint64_t(bit)); bitConst->bitfieldType = make_smart(*alias); bitConst->type = td; return bitConst; @@ -6358,6 +6365,12 @@ namespace das { return Visitor::visit(expr); } // ExprOp1 + bool isBitfieldOp ( const Function * fnc ) const { + if ( fnc->module->name=="$" && fnc->arguments[0]->type->isBitfield() ) { + return true; + } + return false; + } virtual ExpressionPtr visit ( ExprOp1 * expr ) override { if ( !expr->subexpr->type || expr->subexpr->type->isAliasOrExpr() ) return Visitor::visit(expr); // failed to infer // pointer arithmetics @@ -6414,7 +6427,7 @@ namespace das { return opCall; } if ( expr->func ) { - if ( expr->func->firstArgReturnType ) { + if ( expr->func->firstArgReturnType || isBitfieldOp(expr->func) ) { TypeDecl::clone(expr->type,expr->arguments[0]->type); expr->type->ref = false; } else { @@ -6632,6 +6645,13 @@ namespace das { if ( expr->func->firstArgReturnType ) { TypeDecl::clone(expr->type,expr->arguments[0]->type); expr->type->ref = false; + } else if ( isBitfieldOp(expr->func) ) { + TypeDecl::clone(expr->type,expr->func->result); + if ( !expr->left->type->alias.empty() ) { + expr->type->alias = expr->left->type->alias; + } else if ( !expr->right->type->alias.empty() ) { + expr->type->alias = expr->right->type->alias; + } } else { TypeDecl::clone(expr->type,expr->func->result); } From fa6b62e98a49da11776df709ca62576b16354ff8 Mon Sep 17 00:00:00 2001 From: Boris Batkin Date: Tue, 28 Oct 2025 11:37:39 -0700 Subject: [PATCH 2/2] upsie --- src/ast/ast_infer_type.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ast/ast_infer_type.cpp b/src/ast/ast_infer_type.cpp index c2ab2ac705..79537d0995 100644 --- a/src/ast/ast_infer_type.cpp +++ b/src/ast/ast_infer_type.cpp @@ -6428,7 +6428,7 @@ namespace das { } if ( expr->func ) { if ( expr->func->firstArgReturnType || isBitfieldOp(expr->func) ) { - TypeDecl::clone(expr->type,expr->arguments[0]->type); + TypeDecl::clone(expr->type,expr->subexpr->type); expr->type->ref = false; } else { TypeDecl::clone(expr->type,expr->func->result); @@ -6643,7 +6643,7 @@ namespace das { } if ( expr->func ) { if ( expr->func->firstArgReturnType ) { - TypeDecl::clone(expr->type,expr->arguments[0]->type); + TypeDecl::clone(expr->type,expr->left->type); expr->type->ref = false; } else if ( isBitfieldOp(expr->func) ) { TypeDecl::clone(expr->type,expr->func->result);