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

search for interface files when using -y #752

Merged
merged 9 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ cmake-build-*/
prefix/
CMakeLists.txt.user
CMakeUserPresets.json
.ccls
3 changes: 3 additions & 0 deletions include/slang/parsing/ParserMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ struct SLANG_EXPORT ParserMetadata {
/// A list of all class declarations parsed.
std::vector<const syntax::ClassDeclarationSyntax*> classDecls;

/// A list of all interface port headers parsed.
std::vector<const syntax::InterfacePortHeaderSyntax*> interfacePorts;
AndrewNolte marked this conversation as resolved.
Show resolved Hide resolved

/// The EOF token, if one has already been consumed by the parser.
/// Otherwise an empty token.
Token eofToken;
Expand Down
6 changes: 6 additions & 0 deletions source/driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,12 @@ bool Driver::parseAllSources() {
missing.emplace(name);
}
}

for (auto intf : meta.interfacePorts) {
std::string_view name = intf->nameOrKeyword.valueText();
if (knownNames.find(name) == knownNames.end())
Copy link
Owner

Choose a reason for hiding this comment

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

You should check that name is not empty here. Also I think you need to check that the name token is not actually the interface keyword, since that's not actually the name of an interface to load.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took out the interface keyword check bc of the Parser change. I don't think the name will every be empty right?

Copy link
Owner

Choose a reason for hiding this comment

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

I think you still need those checks because of the reconstruction case in ParserMetadata.cpp, which will apply to all InterfacePortHeaders and not just the specific code path in parsePortHeader. That check can either be here or in ParserMetadata.cpp.

missing.emplace(name);
}
};

for (auto& tree : syntaxTrees)
Expand Down
5 changes: 4 additions & 1 deletion source/parsing/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ PortHeaderSyntax& Parser::parsePortHeader(Token constKeyword, Token direction) {
if (!constKeyword && peek(1).kind == TokenKind::Dot &&
peek(2).kind == TokenKind::Identifier && peek(3).kind == TokenKind::Identifier) {
auto name = consume();
return factory.interfacePortHeader(name, parseDotMemberClause());
InterfacePortHeaderSyntax* header =
&factory.interfacePortHeader(name, parseDotMemberClause());
meta.interfacePorts.push_back(header);
return *header;
}

DataTypeSyntax* type;
Expand Down
5 changes: 5 additions & 0 deletions source/parsing/ParserMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class MetadataVisitor : public SyntaxVisitor<MetadataVisitor> {
visitDefault(syntax);
}

void handle(const InterfacePortHeaderSyntax& syntax) {
meta.interfacePorts.push_back(&syntax);
visitDefault(syntax);
}

void handle(const DefParamSyntax& syntax) {
meta.hasDefparams = true;
visitDefault(syntax);
Expand Down