Add methods for AST annotation implementation

This commit is contained in:
Jason Cobb
2020-01-09 08:37:32 -05:00
parent 00699c444e
commit dc6c19cafa
2 changed files with 45 additions and 76 deletions
+21 -2
View File
@@ -108,10 +108,29 @@ public:
protected:
size_t const m_id = 0;
/// Annotation - is specialised in derived classes, is created upon request (because of polymorphism).
mutable std::unique_ptr<ASTAnnotation> m_annotation;
template <class T>
T& initAnnotation() const
{
if (!m_annotation)
m_annotation = std::make_unique<T>();
return dynamic_cast<T&>(*m_annotation);
}
template <class T>
T& abstractAnnotation(std::string _className) const
{
solAssert(
m_annotation,
_className + " is an abstract base, need to call annotation on the concrete class first."
);
return dynamic_cast<T&>(*m_annotation);
}
private:
/// Annotation - is specialised in derived classes, is created upon request (because of polymorphism).
mutable std::unique_ptr<ASTAnnotation> m_annotation;
SourceLocation m_location;
};