I had to verify that it really worked for me before I did reply…
Here are the steps:
1 - Define the new node accordingly in the file
CLANG_DIR/include/clang/Basic/DeclNodes.td
e.g. def Concept : DDecl, DeclContext;
2 - Implement a class for the corresponding declaration,
specifying Concept as the declaration’s kind.
e.g.
class ConceptDecl : public TemplateDecl, public DeclContext {
…
ConceptDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
TemplateParameterList *ParamList, …)
: TemplateDecl(Concept, DC, L, Id, ParamList), DeclContext(Concept), … { }
…
}
3 - Verify that the appropriate Visit*() and Visit*Decl() methods
are implemented for every class that inherits from the DeclVisitor Class.
e.g. ASTImporter, DeclPrinter, ASTReaderDecl, ASTWriterDecl, RecursiveASTVisitor, etc…
At the very least, allow the declaration to adopt the default behavior…
Foremost, update your included libraries appropriately (making sure that ConceptDecl is visible within those files).
If anything was forgotten, the generated clang compilation errors should indicate which file needs to be updated…
4 - There a few other minor hick-ups which one should be able to figure out from observing other implementations, such as
adding block of codes such as these to the implementation of the ConceptDecl class.
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classof(const ConceptDecl *D) { return true; }
static bool classofKind(Kind K) { return K == Concept; }
static DeclContext *castToDeclContext(const ConceptDecl *D) {
return static_cast<DeclContext >(const_cast<ConceptDecl>(D));
}
static ConceptDecl *castFromDeclContext(const DeclContext *DC) {
return static_cast<ConceptDecl >(const_cast<DeclContext>(DC));
}
There may other other stuff I missed. But then again, I’m very new to this… So, any comment/question can only help.
Cheers,
– Larisse.