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

Make isSystemFile() part of the parser options file. #4888

Merged
merged 3 commits into from
Aug 30, 2024

Conversation

fruffy
Copy link
Collaborator

@fruffy fruffy commented Aug 28, 2024

This function is static and checks the p4IncludePath which is part of the parser options file. It should be part of this file such that it can be used in other contexts.

Among others, this call can be used by the formatter or to determine whether a particular source info objects comes from a systems file.

@fruffy fruffy added the core Topics concerning the core segments of the compiler (frontend, midend, parser) label Aug 28, 2024
@fruffy fruffy changed the title Make isSystemFile part of the parser options. Make isSystemFile() part of the parser options file. Aug 28, 2024
@fruffy fruffy requested review from vlstill and asl August 29, 2024 07:52
if (file.startsWith(p4includePath)) return true;
return false;
}

cstring ToP4::ifSystemFile(const IR::Node *node) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are touching it, maybe change it to return std::optional<std::string> (or std::optional<cstring>? The null-distinct-from-empty behavior of cstring is a bit anoying and bad design in my opinion. I'm not sure how big impact this would have though...

@@ -72,8 72,8 @@ class ToP4 : public Inspector, ResolutionContext {
BUG_CHECK(!listTerminators.empty(), "Empty listTerminators");
listTerminators.pop_back();
}
bool isSystemFile(cstring file);
cstring ifSystemFile(const IR::Node *node); // return file containing node if system file
// return file containing node if system file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// return file containing node if system file
/// @returns file containing node if system file

Signed-off-by: fruffy <[email protected]>
@fruffy fruffy added this pull request to the merge queue Aug 30, 2024
Merged via the queue into main with commit 3306162 Aug 30, 2024
18 checks passed
@fruffy fruffy deleted the fruffy/parser_options_path branch August 30, 2024 12:33
sourceFile != nullptr) {
auto sourceFileOpt = ifSystemFile(a);
// Errors can come from multiple files
if (!a->is<IR::Type_Error>() && sourceFileOpt.has_value()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a way of personal preference, I usually prefer casting optional to bool to check if there is something inside :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this lead to ambiguity if the type of sourceFileOpt changes? Main reason why I always try make this explicit with has_value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if type would be convertible to bool. Note that we need explicit conversion for std::optional (and this is better compared to boost::optional that is implicitly convertible to bool). Anyway, as I said, this is mostly within personal preference :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Topics concerning the core segments of the compiler (frontend, midend, parser)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants