【发布时间】:2016-07-10 19:05:10
【问题描述】:
我使用 Clang libtooling 开发了一个 AST 访问器,我想区分函数原型和函数声明。我的 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() 无法区分这两件事。有什么想法吗??
【问题讨论】:
-
是什么让你认为这是两个不同的东西?你能举一些例子吗?还是你的意思是函数声明和函数定义?
-
是的,我的意思是区分函数定义和声明。
-
那么请更新问题。
标签: c++ clang abstract-syntax-tree llvm-clang