Skip to content

Commit

Permalink
Add annotation error messages.
Browse files Browse the repository at this point in the history
Signed-off-by: fruffy <[email protected]>
  • Loading branch information
fruffy committed Dec 5, 2024
1 parent df9e3ee commit 006177f
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions ir/base.def
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
return std::get<UnparsedAnnotation>(body);
}
inline auto &getExpr() {
BUG_CHECK(annotationKind() == Kind::Unstructured || annotationKind() == Kind::StructuredExpressionList, "Annotation does not contain an expression list.");
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.");
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.");
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.");
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.
Expand Down

0 comments on commit 006177f

Please sign in to comment.