如何使用clang从TagDecl获取结构成员

时间:2014-06-07 08:04:09

标签: c++ c clang clang++ llvm-clang

我有一个AST使用者获得所有与

结构的TagDecl
clang::TagDecl::isStruct()

如何在类似FunctionDecl类的数组中获取结构(声明,类型)的成员:

clang::FunctionDecl::getParamDecl(unsigned i)

或以其他方式?

2 个答案:

答案 0 :(得分:3)

必须将TagDecl强制转换为具有获取成员/字段信息的方法的RecordDecl

clang::TagDecl*t;
clang::RecordDecl*r;
clang::RecordDecl::field_iterator jt;

for(jt = r->field_begin(); jt != r->field_end();++jt)
{
    std::cout << jt->getType().getAsString() << " " << jt->getNameAsString() << std::endl;
}

答案 1 :(得分:-1)

#cast int to string
adclicksDF['userId'] = adclicksDF['userId'].astype(str)
adCategoryclicks = adclicksDF[['timestamp','adId','adCategory','userId','adCount']]


agrupadoDF = adCategoryclicks.groupby(pd.Grouper(key='timestamp', freq='1H'))
                             .agg({'adCount': ['count','sum'], 
                                   'userId': ', '.join,
                                   'adCategory': ', '.join})

agrupadoDF.columns = ['adCategory','count','sum','userId']

print (agrupadoDF)
                                         adCategory  count  sum  \
timestamp                                                         
2016-05-26 15:00:00  electronics, movies, computers      3    3   
2016-05-26 16:00:00               fashion, clothing      2    2   

                              userId  
timestamp                             
2016-05-26 15:00:00  611, 1874, 2139  
2016-05-26 16:00:00        212, 1027  

您应该将此函数添加到您扩展到ASTConsumer的类中。

  

在该上下文中存储声明

     

每个声明上下文都可以包含一些声明。对于   例如,C ++类(由RecordDecl表示)包含各种   成员函数,字段,嵌套类型等。所有这些   声明将存储在DeclContext中,并且可以   通过[DeclContext :: decls_begin()迭代声明,   DeclContext :: decls_end())。这种机制提供了以源为中心的   在上下文中查看声明。

http://clang.llvm.org/docs/InternalsManual.html

相关问题