<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Hello, <br>I'm making an operator that adds attributes of a base class into a derived one, hidding the base class attribute, but when i run it I get the following error:<br><br><blockquote>IHI_operator: /home/daniel/llvm/tools/clang/lib/AST/DeclBase.cpp:1094: void clang::DeclContext::addHiddenDecl(clang::Decl*): Assertion `D->getLexicalDeclContext() == this && "Decl inserted into wrong lexical context"' failed.<br>Stack dump:<br>0. <eof> parser at end of file<br><br></blockquote><br>My code for the matcher is:<br><br><blockquote>DeclarationMatcher IHI_Matcher = recordDecl(<br> isDerivedFrom(<br> recordDecl(<br> forEach(<br> fieldDecl(<br> anyOf(<br> isPublic(),<br> isProtected()<br> ),<br> unless(<br> hasType(<br> isConstQualified()<br> )<br> )<br> ).bind("ParentVar")<br> )<br> )<br> )<br> ).bind("ChildClass");<br><br></blockquote>And this is the run function:<br><br><blockquote>virtual void run(const MatchFinder::MatchResult &Result) {<br> ASTContext *Context = Result.Context;<br> Rewriter Rewrite;<br> Rewrite.setSourceMgr(Context->getSourceManager(), Context->getLangOpts());<br><br> RecordDecl *FS;<br> const FieldDecl *FS1;<br> <br> if ((FS = const_cast<RecordDecl*>(Result.Nodes.getNodeAs<clang::RecordDecl>("ChildClass")))<br> && (FS1 = Result.Nodes.getNodeAs<clang::FieldDecl>("ParentVar"))){ <br> <br> FullSourceLoc FullLocation = Context->getFullLoc(FS->getLocStart());<br> FullSourceLoc FullLocation1 = Context->getFullLoc(FS1->getLocStart());<br> <br> if ((FullLocation.isValid())){<br> <br> <br> FieldDecl* field = const_cast<FieldDecl*>(FS1);<br> <br> if (FS->hasAttrs()){<br> for(RecordDecl::field_iterator i = FS->field_begin(); i != FS->field_end(); i++){<br> if ((field->getName() != (*i)->getName()) && (field->getType() != (*i)->getType())){<br> FS->dump();<br> llvm::outs() << "Found declaration at "<br> << FullLocation1.getSpellingLineNumber() << ":"<br> << FullLocation1.getSpellingColumnNumber() << "\n";<br> FS->addDecl(field);<br> const RewriteBuffer *RewriteBuf = Rewrite.getRewriteBufferFor(FullLocation.getFileID());<br> llvm::outs() << std::string(RewriteBuf->begin(), RewriteBuf->end());<br> }<br> }<br> }<br> else {<br> FS->dump();<br> llvm::outs() << "Found declaration at "<br> << FullLocation1.getSpellingLineNumber() << ":"<br> << FullLocation1.getSpellingColumnNumber() << "\n";<br> FS->addDecl(field);<br> const RewriteBuffer *RewriteBuf = Rewrite.getRewriteBufferFor(FullLocation.getFileID());<br> llvm::outs() << std::string(RewriteBuf->begin(), RewriteBuf->end());<br> }<br> }<br> }<br> <br> }<br>};<br></blockquote><br>I'm not quite sure about what is happening here, can someone help me? Thank you.<br> </div></body>
</html>