gpt4 book ai didi

c++ - 如何区分 Clang AST 访问者中的函数定义和函数声明

转载 作者:行者123 更新时间:2023-11-30 05:25:22 26 4
gpt4 key购买 nike

我使用 Clang libtooling 开发了一个 AST 访问器,我想区分函数原型(prototype)和函数声明。我的 AST 访问者将这两种情况都视为函数声明。下面你可以看到我的访问函数声明的代码:

bool VisitFunctionDecl(FunctionDecl *func)
{
if(astContext->getSourceManager().isInMainFile(func->getLocStart()) && func->hasBody()) //checks if the node is in the main (input) file.
{
FullSourceLoc FullLocation = astContext->getFullLoc(func->getLocStart());
string funcName = func->getNameInfo().getName().getAsString();
string funcType = func->getResultType().getAsString();
string srcFunc = filename + "_" + funcName;
REPORT << "Function Declaration [" << FullLocation.getSpellingLineNumber() << "," << FullLocation.getSpellingColumnNumber() << "]: " << funcName << " of type " << funcType << "\n";
if (append == 0 && numFunctions == 0)
APIs << srcFunc <<":";
else
APIs << "\n" << srcFunc <<":";
APIs <<funcType << ",";
numFunctions++;
}
return true;
}

func->hasBody() 无法区分这两者。有什么想法吗??

最佳答案

使用 FunctionDecl::isThisDeclarationADefinition()

关于c++ - 如何区分 Clang AST 访问者中的函数定义和函数声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38295521/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com