[cfe-dev] Wrong lexical context
Daniel QuiƱones Lopez
kaos09 at hotmail.com
Tue Oct 22 04:26:07 PDT 2013
Hello,
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:
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.
Stack dump:
0. <eof> parser at end of file
My code for the matcher is:
DeclarationMatcher IHI_Matcher = recordDecl(
isDerivedFrom(
recordDecl(
forEach(
fieldDecl(
anyOf(
isPublic(),
isProtected()
),
unless(
hasType(
isConstQualified()
)
)
).bind("ParentVar")
)
)
)
).bind("ChildClass");
And this is the run function:
virtual void run(const MatchFinder::MatchResult &Result) {
ASTContext *Context = Result.Context;
Rewriter Rewrite;
Rewrite.setSourceMgr(Context->getSourceManager(), Context->getLangOpts());
RecordDecl *FS;
const FieldDecl *FS1;
if ((FS = const_cast<RecordDecl*>(Result.Nodes.getNodeAs<clang::RecordDecl>("ChildClass")))
&& (FS1 = Result.Nodes.getNodeAs<clang::FieldDecl>("ParentVar"))){
FullSourceLoc FullLocation = Context->getFullLoc(FS->getLocStart());
FullSourceLoc FullLocation1 = Context->getFullLoc(FS1->getLocStart());
if ((FullLocation.isValid())){
FieldDecl* field = const_cast<FieldDecl*>(FS1);
if (FS->hasAttrs()){
for(RecordDecl::field_iterator i = FS->field_begin(); i != FS->field_end(); i++){
if ((field->getName() != (*i)->getName()) && (field->getType() != (*i)->getType())){
FS->dump();
llvm::outs() << "Found declaration at "
<< FullLocation1.getSpellingLineNumber() << ":"
<< FullLocation1.getSpellingColumnNumber() << "\n";
FS->addDecl(field);
const RewriteBuffer *RewriteBuf = Rewrite.getRewriteBufferFor(FullLocation.getFileID());
llvm::outs() << std::string(RewriteBuf->begin(), RewriteBuf->end());
}
}
}
else {
FS->dump();
llvm::outs() << "Found declaration at "
<< FullLocation1.getSpellingLineNumber() << ":"
<< FullLocation1.getSpellingColumnNumber() << "\n";
FS->addDecl(field);
const RewriteBuffer *RewriteBuf = Rewrite.getRewriteBufferFor(FullLocation.getFileID());
llvm::outs() << std::string(RewriteBuf->begin(), RewriteBuf->end());
}
}
}
}
};
I'm not quite sure about what is happening here, can someone help me? Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131022/38d6b3e6/attachment.html>
More information about the cfe-dev
mailing list