-
Notifications
You must be signed in to change notification settings - Fork 445
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
Add checks to annotation getters. #5052
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Signed-off-by: fruffy <fruffy@nyu.edu>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -332,17 +332,36 @@ class Annotation { | |||||
Vector<Expression>, | ||||||
IndexedVector<NamedExpression>> body; | ||||||
|
||||||
inline auto &getUnparsed() { return std::get<UnparsedAnnotation>(body); } | ||||||
inline const auto &getUnparsed() const { return std::get<UnparsedAnnotation>(body); } | ||||||
inline auto &getExpr() { return std::get<ExpressionAnnotation>(body); } | ||||||
inline const auto &getExpr() const { return std::get<ExpressionAnnotation>(body); } | ||||||
inline auto &getUnparsed() { | ||||||
BUG_CHECK(annotationKind() == Kind::Unparsed, "Annotation has been parsed already."); | ||||||
return std::get<UnparsedAnnotation>(body); | ||||||
} | ||||||
inline const auto &getUnparsed() const { | ||||||
BUG_CHECK(annotationKind() == Kind::Unparsed, "Annotation has been parsed already."); | ||||||
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.
Suggested change
|
||||||
return std::get<UnparsedAnnotation>(body); | ||||||
} | ||||||
inline auto &getExpr() { | ||||||
BUG_CHECK(annotationKind() == Kind::Unstructured || annotationKind() == Kind::StructuredExpressionList, "Annotation does not contain an expression list."); | ||||||
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.
Suggested change
|
||||||
return std::get<ExpressionAnnotation>(body); | ||||||
} | ||||||
inline const auto &getExpr() const { | ||||||
BUG_CHECK(annotationKind() == Kind::Unstructured || annotationKind() == Kind::StructuredExpressionList, "Annotation does not contain an expression list."); | ||||||
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.
Suggested change
|
||||||
return std::get<ExpressionAnnotation>(body); | ||||||
} | ||||||
inline Expression getExpr(size_t idx) const { | ||||||
BUG_CHECK(annotationKind() == Kind::Unstructured || annotationKind() == Kind::StructuredExpressionList, "Annotation does not contain an expression list."); | ||||||
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.
Suggested change
|
||||||
const auto &expr = getExpr(); | ||||||
BUG_CHECK(idx < expr.size(), "invalid annotation expression index"); | ||||||
return expr[idx]; | ||||||
} | ||||||
inline auto &getKV() { return std::get<KVAnnotation>(body); } | ||||||
inline const auto &getKV() const { return std::get<KVAnnotation>(body); } | ||||||
inline auto &getKV() { | ||||||
BUG_CHECK(annotationKind() == Kind::StructuredKVList, "Annotation does not contain a key-value list."); | ||||||
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. What if the annotation is an unstructured kv-list (an unstructured annotation with 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. Will add this. Are these all possible combinations? 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. When an unstructured annotation is parsed, it might be parsed into either the 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. When do we generate a
and it is a little misleading because an annotation can be both a 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. Looking at https://p4.org/p4-spec/docs/P4-16-working-spec.html#sec-annotations it is possible that a compiler developers tries to parse an unstructured annotation as a KV-annotation. We do not restrict that, right? 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. Looks like with Anton's change, one needs to check 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. The 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.
Yes, I was pretty confused by this distinction. Even more, it seems to be used just in one place – somewhere around p4 control plane. Overall, the things are multimensional:
I think it would be better to factor out everything in such way. I just do not know if there are any out of tree uses of structured annotations to get rid of |
||||||
return std::get<KVAnnotation>(body); | ||||||
} | ||||||
inline const auto &getKV() const { | ||||||
BUG_CHECK(annotationKind() == Kind::StructuredKVList, "Annotation does not contain a key-value list."); | ||||||
return std::get<KVAnnotation>(body); | ||||||
} | ||||||
|
||||||
/// If this is true this is a structured annotation, and there are some | ||||||
/// constraints on its contents. | ||||||
|
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.