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

Refactor code to be more readable #3863

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ expression
@after {
<AssertIsList("$args")>
}
: op=NOT args+=expression
| args+=expression (op=AND args+=expression)+
| args+=expression (op=OR args+=expression)+
: args+=expression (op=AND args+=expression)+
| IDENTIFIER
;

Expand All @@ -28,6 +26,3 @@ expression

[input]
a and b

[skip]
Cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
*
* In test dir with generated test code:
*
* clang++ -g -std=c++17 -I /Users/parrt/antlr/code/antlr4/runtime/Cpp/runtime/src -L. -lantlr4-runtime *.cpp
* clang++ -g -std=c++17 -I /Users/parrt/antlr/code/antlr4/runtime/Cpp/runtime/src \
* -L/Users/parrt/antlr/code/antlr4/runtime/Cpp/dist -lantlr4-runtime *.cpp
* ./a.out input
*
* $ lldb ./a.out input
Expand Down
16 changes: 11 additions & 5 deletions runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,17 @@ bool ArrayPredictionContext::equals(const PredictionContext &other) const {
return false;
}
const auto &array = downCast<const ArrayPredictionContext&>(other);
return returnStates.size() == array.returnStates.size() &&
parents.size() == array.parents.size() &&
cachedHashCodeEqual(cachedHashCode(), array.cachedHashCode()) &&
std::memcmp(returnStates.data(), array.returnStates.data(), returnStates.size() * sizeof(decltype(returnStates)::value_type)) == 0 &&
std::equal(parents.begin(), parents.end(), array.parents.begin(), predictionContextEqual);
const bool sameSize = returnStates.size() == array.returnStates.size() &&
parents.size() == array.parents.size();
const bool sameHash = cachedHashCodeEqual(cachedHashCode(), array.cachedHashCode());
const size_t stateSizeBytes = sizeof(decltype(returnStates)::value_type);
const bool stateArraysEqual =
std::memcmp(returnStates.data(), array.returnStates.data(),
returnStates.size() * stateSizeBytes) == 0;
// stack of contexts is the same
const bool parentCtxEqual = std::equal(parents.begin(), parents.end(), array.parents.begin(),
predictionContextEqual);
return sameSize && sameHash && stateArraysEqual && parentCtxEqual;
}

std::string ArrayPredictionContext::toString() const {
Expand Down