-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate UIDs for AST nodes with Expression base class (#218)
* Generate UIDs for AST nodes with Expression base class * Add expression uid tests * Reset UID generator when finding a new condition, add python bindings * Use std::uint64_t, add documentation for the uid, change the uid python binding to be a property instead of method. * Use the function address directly without lambda
- Loading branch information
Showing
8 changed files
with
180 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @file src/parser/uid_generator.h | ||
* @brief Declaration of class UidGenerator. | ||
* @copyright (c) 2022 Avast Software, licensed under the MIT license | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
namespace yaramod { | ||
|
||
/** | ||
* Class that deterministically generates | ||
* up to 2^64 unique IDs for AST nodes | ||
* | ||
* The IDs are unique for a given input | ||
* so only pair (input; node) has a UID | ||
* This means UidGenerator has to be reset | ||
* For every new input | ||
*/ | ||
class UidGenerator | ||
{ | ||
public: | ||
std::uint64_t next() { return _counter++; } | ||
void reset() { _counter = 0; } | ||
|
||
private: | ||
std::uint64_t _counter = 0; | ||
}; | ||
|
||
} // namespace yaramod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.