-
Notifications
You must be signed in to change notification settings - Fork 19
Verilog: add a class for exceptions in the preprocessor #70
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving, but I'd appreciate adjusting the interface as suggested below.
src/verilog/verilog_preprocessor.cpp
Outdated
error().source_location = source_location; | ||
error() << "unknown preprocessor directive \"" << text << "\"" << eom; | ||
throw 0; | ||
throw verilog_preprocessor_errort() << "unknown preprocessor directive \"" << text << "\""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd have a preference towards RAII: could the constructor please require (!) a string to be passed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class meets the RAII criteria; in particular, all invariants are satisfied. It's like a container, and as such may be constructed empty.
This adds a class for exceptions in the Verilog preprocessor, as opposed to throwing the integer 0.
a3d783f
to
b581a03
Compare
throw verilog_preprocessor_errort() | ||
<< "unknown preprocessor directive \"" << text << "\""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I accept that this satisfies RAII, but I am still wondering whether a constructor that takes a std::string
wouldn't be the better way forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be a bit weird, e.g., in this case you would have
throw verilog_preprocessor_errort("unknown preprocessor directive \"") << text << "\"";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Looks" wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have used + instead of << and have passed the entire string to the constructor. But it’s just a matter of taste, no big deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but then you'll want numbers, tokens (which have a << operator, but no +), etc.
Verilog: add a class for exceptions in the preprocessor
This adds a class for exceptions in the Verilog preprocessor, as opposed to throwing the integer 0.