-
Notifications
You must be signed in to change notification settings - Fork 175
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
refactor all attribute functions in rust-privacy-reporter.cc #3339
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,27 +223,30 @@ check_doc_attribute (const AST::Attribute &attribute) | |
} | ||
} | ||
} | ||
|
||
static bool | ||
is_proc_macro_type (const AST::Attribute &attribute) | ||
tl::optional<std::string> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we return an enum instead of a string here ? Enums are cheap, strings are not. and if I'm reading this correctly string values are known statically. |
||
Attributes::is_proc_macro_type (const AST::Attribute &attribute) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're changing the semantic of the function, either you need a new one (two different functions) or you need to rename this one, we're not deciding if an attribute is or is not a proc macro anymore but returning the kind of proc macro with your new code. I'd keep two different functions, even if one is calling the other and simply using |
||
{ | ||
BuiltinAttrDefinition result; | ||
if (!is_builtin (attribute, result)) | ||
return false; | ||
return tl::nullopt; | ||
|
||
auto name = result.name; | ||
return name == Attrs::PROC_MACRO || name == Attrs::PROC_MACRO_DERIVE | ||
|| name == Attrs::PROC_MACRO_ATTRIBUTE; | ||
if (name == Attrs::PROC_MACRO || name == Attrs::PROC_MACRO_DERIVE | ||
|| name == Attrs::PROC_MACRO_ATTRIBUTE) | ||
{ | ||
return name; | ||
} | ||
else | ||
return tl::nullopt; | ||
} | ||
|
||
// Emit an error when one encountered attribute is either #[proc_macro], | ||
// #[proc_macro_attribute] or #[proc_macro_derive] | ||
static void | ||
check_proc_macro_non_function (const AST::AttrVec &attributes) | ||
{ | ||
for (auto &attr : attributes) | ||
{ | ||
if (is_proc_macro_type (attr)) | ||
if (Attributes::is_proc_macro_type (attr) != tl::nullopt) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this not just be if (Attributes::is_proc_macro_type (attr)) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, it could be shortened. |
||
rust_error_at ( | ||
attr.get_locus (), | ||
"the %<#[%s]%> attribute may only be used on bare functions", | ||
|
@@ -258,7 +261,7 @@ check_proc_macro_non_root (AST::AttrVec attributes, location_t loc) | |
{ | ||
for (auto &attr : attributes) | ||
{ | ||
if (is_proc_macro_type (attr)) | ||
if (Attributes::is_proc_macro_type (attr) != tl::nullopt) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
{ | ||
rust_error_at ( | ||
loc, | ||
|
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.
this seems odd i think you should be storing the result here in a variable instead of calling it twice like this