Skip to content

Commit

Permalink
[Parser] Const-ify ParseParams and provide convenience constructors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud-de-Grandmaison-ARM committed Feb 6, 2024
1 parent c634f10 commit 59d93f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
11 changes: 8 additions & 3 deletions include/libtarmac/parser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ struct TarmacEvent {
enum ISet { ARM, THUMB, A64 };

struct ParseParams {
bool bigend = false;
bool bigend;

// In C++17 we could replace these two fields with a std::optional<ISet>
bool iset_specified = false;
bool iset_specified;
ISet iset; // only meaningful if specified_iset is True

ParseParams() : bigend(false), iset_specified(false) {}
ParseParams(bool bigend) : bigend(bigend), iset_specified(false) {}
ParseParams(bool bigend, ISet iset)
: bigend(bigend), iset_specified(true), iset(iset) {}
};

enum HighlightClass {
Expand Down Expand Up @@ -147,7 +152,7 @@ class TarmacLineParser {
TarmacLineParserImpl *pImpl;

public:
TarmacLineParser(ParseParams params, ParseReceiver &);
TarmacLineParser(const ParseParams &params, ParseReceiver &);
~TarmacLineParser();
void parse(const std::string &s) const;
};
Expand Down
14 changes: 9 additions & 5 deletions lib/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class TarmacLineParserImpl {

string line;
size_t pos, size;
ParseParams params;
const ParseParams &params;
set<string> unrecognised_registers_already_reported;
set<string> unrecognised_system_operations_reported;
set<string> unrecognised_tarmac_events_reported;
Expand All @@ -212,6 +212,11 @@ class TarmacLineParserImpl {

static set<string> known_timestamp_units;

TarmacLineParserImpl(const ParseParams &params, ParseReceiver *receiver)
: params(params), receiver(receiver)
{
}

inline bool iswordchr(char c)
{
return isalnum((unsigned char)c) || c == '_' || c == '-' || c == '.' ||
Expand Down Expand Up @@ -1188,11 +1193,10 @@ class TarmacLineParserImpl {
}
};

TarmacLineParser::TarmacLineParser(ParseParams params, ParseReceiver &rec)
: pImpl(new TarmacLineParserImpl)
TarmacLineParser::TarmacLineParser(const ParseParams &params,
ParseReceiver &rec)
: pImpl(new TarmacLineParserImpl(params, &rec))
{
pImpl->params = params;
pImpl->receiver = &rec;
}

TarmacLineParser::~TarmacLineParser() { delete pImpl; }
Expand Down

0 comments on commit 59d93f7

Please sign in to comment.