Skip to content

Commit

Permalink
Limit search for duplicate names to actions, tables, or "other objects"
Browse files Browse the repository at this point in the history
Explicitly allow a table and action to have the same name, since there
is a test case that was written explicitly to test that this is permitted.

Signed-off-by: Andy Fingerhut <[email protected]>
  • Loading branch information
jafingerhut committed Oct 8, 2024
1 parent b9a383d commit bfa62ff
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
30 changes: 26 additions & 4 deletions frontends/p4/duplicateHierarchicalNameCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,33 @@ const IR::Node *DuplicateHierarchicalNameCheck::postorder(IR::Annotation *annota
if (annotatedNode->is<IR::Declaration_Variable>()) {
return annotation;
}
if (annotatedNodes.count(name)) {
error(ErrorType::ERR_DUPLICATE, "%1%: " ERR_STR_DUPLICATED_NAME ": %2%", annotatedNode,
annotatedNodes[name]);
bool foundDuplicate = false;
auto *otherNode = annotatedNode;
if (annotatedNode->is<IR::P4Table>()) {
if (annotatedTables.count(name)) {
foundDuplicate = true;
otherNode = annotatedTables[name];
} else {
annotatedTables[name] = annotatedNode;
}
} else if (annotatedNode->is<IR::P4Action>()) {
if (annotatedActions.count(name)) {
foundDuplicate = true;
otherNode = annotatedActions[name];
} else {
annotatedActions[name] = annotatedNode;
}
} else {
annotatedNodes[name] = annotatedNode;
if (annotatedOthers.count(name)) {
foundDuplicate = true;
otherNode = annotatedOthers[name];
} else {
annotatedOthers[name] = annotatedNode;
}
}
if (foundDuplicate) {
error(ErrorType::ERR_DUPLICATE, "%1%: " ERR_STR_DUPLICATED_NAME ": %2%", annotatedNode,
otherNode);
}
return annotation;
}
Expand Down
9 changes: 7 additions & 2 deletions frontends/p4/duplicateHierarchicalNameCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ namespace P4 {
*/
class DuplicateHierarchicalNameCheck : public Transform {
std::vector<cstring> stack;
/// Used for detection of conflicting control plane names
std::map<cstring, const IR::Node *> annotatedNodes;
/// Used for detection of conflicting control plane names among actions.
std::map<cstring, const IR::Node *> annotatedActions;
/// Used for detection of conflicting control plane names among tables.
std::map<cstring, const IR::Node *> annotatedTables;
/// Used for detection of conflicting control plane names among
/// objects other than actions and tables.
std::map<cstring, const IR::Node *> annotatedOthers;

public:
cstring getName(const IR::IDeclaration *decl);
Expand Down

0 comments on commit bfa62ff

Please sign in to comment.