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

verilog/analysis: Add ParsedVerilogSourceFile class #745

Merged
merged 2 commits into from
Apr 13, 2021

Conversation

ghost
Copy link

@ghost ghost commented Apr 5, 2021

This class is an extended version of InMemoryVerilogSourceFile.
It wraps a TextStructureView object and allows to skip loading and
parsing phase.

@google-cla google-cla bot added the cla: yes All contributors in pull request have signed the CLA with Google. label Apr 5, 2021
@ghost ghost force-pushed the parsed-verilog-source-file branch from b798442 to 47e9bf0 Compare April 5, 2021 16:56
ghost pushed a commit to antmicro/verible that referenced this pull request Apr 5, 2021
@ghost ghost requested a review from hzeller April 5, 2021 18:39
Copy link
Collaborator

@hzeller hzeller left a comment

Choose a reason for hiding this comment

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

(This looks like a preparatory change for some other change. What are you going to use it for ?)

Looks mostly good, but I think using a const reference in the constructor and holding on to it might need either some specific explanation or, better, passing a pointer to keep the reader on the right track.

public:
// filename can be fake, it is not used to open any file.
ParsedVerilogSourceFile(absl::string_view filename,
const verible::TextStructureView& text_structure,
Copy link
Collaborator

Choose a reason for hiding this comment

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

the ownership of this probably needs to be described in the constructor description, as this expects the text_structure be available for the lifetime of this object.

I'd suggest to make this a const verible::TextStructuredView*, also text_structure_. Passing a pointer makes it more obvious that the object is keeping a reference to it.

(usually, when we pass const references in constructors, a copy is made, so this is what the programmer expects. If we keep a reference to the thing we can make it more visible by passing a pointer)

Copy link
Author

Choose a reason for hiding this comment

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

Done, done & done

text_structure_(text_structure) {}

// Do nothing (file contents already loaded)
absl::Status Open() override;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that we don't expect to derive further, we can make the override a final (same below; same in InMemoryVerilogSourceFile). Might need a class ParsedVerilogSourceFile final : ... above.

Copy link
Author

Choose a reason for hiding this comment

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

I made the whole class final (same with InMemoryVerilogSourceFile class).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice. At that point, the compiler knows that once it can proof that there can only be a ParsedVerilogSourceFile in a particular instance, it can replace calls to the virtual methods with direkt calls and does not have to go through the virtual method table. While here the performance win is probably not noticeable, it is a win for the reader of the code.

So for readability, I'd then also suggest to replace override with final in all the methods so that it is easier to see for the reader at first glance without having looked at the class declaration above.

Not critical for this review, can be changed later.

Lukasz Dalek added 2 commits April 13, 2021 12:50
This class is an extended version of InMemoryVerilogSourceFile.
It wraps a TextStructureView object and allows to skip loading and
parsing phase.

This class may be used in e.g. TextStructureLinterRules.

Signed-off-by: Lukasz Dalek <[email protected]>
InMemoryVerilogSourceFile class is implemented for testing purposes.
Marking it final as we don't expect to derive it further.

Signed-off-by: Lukasz Dalek <[email protected]>
@ghost ghost force-pushed the parsed-verilog-source-file branch from 47e9bf0 to 82d56e3 Compare April 13, 2021 10:53
ghost pushed a commit to antmicro/verible that referenced this pull request Apr 13, 2021
@ghost
Copy link
Author

ghost commented Apr 13, 2021

(This looks like a preparatory change for some other change. What are you going to use it for ?)

It is used in #217 (forbid implicit declarations, PR: #244).

@ghost ghost requested a review from hzeller April 13, 2021 11:33
Copy link
Collaborator

@hzeller hzeller left a comment

Choose a reason for hiding this comment

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

LGTM

@hzeller hzeller merged commit 826998c into chipsalliance:master Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes All contributors in pull request have signed the CLA with Google.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant