Skip to content

Commit

Permalink
evaluator: Fixed evaluation of bitfields
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Jan 16, 2025
1 parent 7c71d30 commit db61966
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions lib/source/pl/core/ast/ast_node_bitfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ namespace pl::core::ast {

auto position = evaluator->getBitwiseReadOffset();
auto bitfieldPattern = std::make_shared<ptrn::PatternBitfield>(evaluator, position.byteOffset, position.bitOffset, 0, getLocation().line);
ON_SCOPE_EXIT {
resultPatterns = hlp::moveToVector<std::shared_ptr<ptrn::Pattern>>(std::move(bitfieldPattern));
};

bitfieldPattern->setSection(evaluator->getSectionId());

Expand Down Expand Up @@ -93,13 +90,24 @@ namespace pl::core::ast {

std::vector<std::shared_ptr<ptrn::Pattern>> fields;
std::vector<std::shared_ptr<ptrn::Pattern>> potentialPatterns;
auto initialPosition = evaluator->getBitwiseReadOffset();

evaluator->pushScope(bitfieldPattern, potentialPatterns);

ON_SCOPE_EXIT {
evaluator->popScope();
};
bitfieldPattern->setReversed(evaluator->isReadOrderReversed());
if (reversedChanged)
evaluator->setBitwiseReadOffset(initialPosition);
bitfieldPattern->setFields(fields);

applyTypeAttributes(evaluator, this, bitfieldPattern);

resultPatterns = hlp::moveToVector<std::shared_ptr<ptrn::Pattern>>(std::move(bitfieldPattern));

evaluator->setReadOrderReversed(prevReversed);
evaluator->popScope();
};

auto initialPosition = evaluator->getBitwiseReadOffset();
auto setSize = [&](ASTNode *node) {
auto endPosition = evaluator->getBitwiseReadOffset();
auto startOffset = (initialPosition.byteOffset * 8) + initialPosition.bitOffset;
Expand All @@ -114,16 +122,17 @@ namespace pl::core::ast {
};

for (auto &entry : this->m_entries) {
entry->createPatterns(evaluator, potentialPatterns);
std::vector<std::shared_ptr<ptrn::Pattern>> patterns;
entry->createPatterns(evaluator, patterns);
setSize(entry.get());

if (evaluator->getCurrentControlFlowStatement() == ControlFlowStatement::Return)
if (evaluator->getCurrentControlFlowStatement() == ControlFlowStatement::Continue) {
break;
}

if (evaluator->getCurrentControlFlowStatement() == ControlFlowStatement::Break) {
break;
} else if (evaluator->getCurrentControlFlowStatement() == ControlFlowStatement::Continue) {
potentialPatterns.clear();
std::move(patterns.begin(), patterns.end(), std::back_inserter(potentialPatterns));

if (evaluator->getCurrentControlFlowStatement() == ControlFlowStatement::Return || evaluator->getCurrentControlFlowStatement() == ControlFlowStatement::Break) {
break;
}
}
Expand All @@ -137,15 +146,6 @@ namespace pl::core::ast {
fields.push_back(pattern);
}
}

bitfieldPattern->setReversed(evaluator->isReadOrderReversed());
if (reversedChanged)
evaluator->setBitwiseReadOffset(initialPosition);
bitfieldPattern->setFields(fields);

applyTypeAttributes(evaluator, this, bitfieldPattern);

evaluator->setReadOrderReversed(prevReversed);
}

}

0 comments on commit db61966

Please sign in to comment.