Skip to content

Commit

Permalink
Checked all redeclarations when parsing function bodies which is back…
Browse files Browse the repository at this point in the history
… on.
  • Loading branch information
ddobrev committed Feb 1, 2017
1 parent ac6be2e commit fc7452b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
28 changes: 18 additions & 10 deletions src/CppParser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2844,6 +2844,22 @@ Parameter* Parser::WalkParameter(const clang::ParmVarDecl* PVD,
return P;
}

void Parser::SetBodyIfInline(const clang::FunctionDecl* FD, Function* F)
{
F->isInline = FD->isInlined();
F->Body = GetFunctionBody(FD);
if (F->isInline && !F->Body.empty())
return;
for (const auto& R : FD->redecls())
{
F->isInline |= R->isInlined();
if (F->Body.empty())
F->Body = GetFunctionBody(R);
if (F->isInline && !F->Body.empty())
break;
}
}

void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F,
bool IsDependent)
{
Expand All @@ -2859,18 +2875,10 @@ void Parser::WalkFunction(const clang::FunctionDecl* FD, Function* F,
F->_namespace = NS;
F->isConstExpr = FD->isConstexpr();
F->isVariadic = FD->isVariadic();
F->isInline = FD->isInlined();
for (const auto& R : FD->redecls())
{
if (R->isInlined())
{
F->isInline = true;
break;
}
}
F->isDependent = FD->isDependentContext();
F->isPure = FD->isPure();
F->isDeleted = FD->isDeleted();
SetBodyIfInline(FD, F);
if (auto InstantiatedFrom = FD->getTemplateInstantiationPattern())
F->instantiatedFrom = static_cast<Function*>(WalkDeclaration(InstantiatedFrom));

Expand Down Expand Up @@ -3920,7 +3928,7 @@ ParserResult* Parser::ParseHeader(const std::vector<std::string>& SourceFiles, P
clang::DiagnosticConsumer* client = c->getDiagnostics().getClient();
client->BeginSourceFile(c->getLangOpts(), &c->getPreprocessor());

ParseAST(c->getSema(), /*PrintStats=*/false, /*SkipFunctionBodies=*/true);
ParseAST(c->getSema());

client->EndSourceFile();

Expand Down
1 change: 1 addition & 0 deletions src/CppParser/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Parser
bool CanCheckCodeGenInfo(clang::Sema & S, const clang::Type * Ty);
Parameter* WalkParameter(const clang::ParmVarDecl* PVD,
const clang::SourceLocation& ParamStartLoc);
void SetBodyIfInline(const clang::FunctionDecl* FD, Function* F);
void WalkFunction(const clang::FunctionDecl* FD, Function* F,
bool IsDependent = false);
void HandlePreprocessedEntities(Declaration* Decl);
Expand Down
2 changes: 1 addition & 1 deletion src/Generator.Tests/AST/TestAST.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public void TestLineNumberOfFriend()
public void TestSignature()
{
Assert.AreEqual("void testSignature()", AstContext.FindFunction("testSignature").Single().Signature);
Assert.AreEqual("void testImpl()", AstContext.FindFunction("testImpl").Single().Signature);
Assert.AreEqual("void testImpl()\r\n{\r\n}", AstContext.FindFunction("testImpl").Single().Signature);
Assert.AreEqual("void testConstSignature() const",
AstContext.FindClass("HasConstFunction").Single().FindMethod("testConstSignature").Signature);
Assert.AreEqual("void testConstSignatureWithTrailingMacro() const",
Expand Down

0 comments on commit fc7452b

Please sign in to comment.