forked from jasder/antlr
Fixes ATN serialization
This commit is contained in:
parent
d089c8d864
commit
3535830c98
|
@ -135,7 +135,7 @@ std::vector<size_t> ATNSerializer::serialize() {
|
|||
int edgeType = t->getSerializationType();
|
||||
if (edgeType == Transition::SET || edgeType == Transition::NOT_SET) {
|
||||
SetTransition *st = static_cast<SetTransition *>(t);
|
||||
if (setIndices.find(st->set) != setIndices.end()) {
|
||||
if (setIndices.find(st->set) == setIndices.end()) {
|
||||
sets.push_back(st->set);
|
||||
setIndices.insert({ st->set, (int)sets.size() - 1 });
|
||||
}
|
||||
|
@ -383,7 +383,7 @@ std::vector<size_t> ATNSerializer::serialize() {
|
|||
}
|
||||
|
||||
size_t value = (data.at(i) + 2) & 0xFFFF;
|
||||
data.assign(i, value);
|
||||
data.at(i) = value;
|
||||
}
|
||||
|
||||
return data;
|
||||
|
@ -625,6 +625,19 @@ std::string ATNSerializer::getDecoded(ATN *atn, std::vector<std::string> &tokenN
|
|||
}
|
||||
|
||||
void ATNSerializer::serializeUUID(std::vector<size_t> &data, Guid uuid) {
|
||||
for (auto &entry : uuid)
|
||||
data.push_back(entry);
|
||||
unsigned int twoBytes = 0;
|
||||
bool firstByte = true;
|
||||
for( std::vector<unsigned char>::const_reverse_iterator rit = uuid.rbegin(); rit != uuid.rend(); ++rit )
|
||||
{
|
||||
if (firstByte) {
|
||||
twoBytes = *rit;
|
||||
firstByte = false;
|
||||
} else {
|
||||
twoBytes |= (*rit << 8);
|
||||
data.push_back(twoBytes);
|
||||
firstByte = true;
|
||||
}
|
||||
}
|
||||
if (!firstByte)
|
||||
throw IllegalArgumentException( "The UUID provided is not valid (odd number of bytes)." );
|
||||
}
|
||||
|
|
|
@ -70,6 +70,9 @@ public:
|
|||
const std::string toString() const;
|
||||
std::vector<unsigned char>::const_iterator begin() { return _bytes.begin(); };
|
||||
std::vector<unsigned char>::const_iterator end() { return _bytes.end(); };
|
||||
std::vector<unsigned char>::const_reverse_iterator rbegin() { return _bytes.rbegin(); };
|
||||
std::vector<unsigned char>::const_reverse_iterator rend() { return _bytes.rend(); };
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
|
Loading…
Reference in New Issue