2017-11-05 3 views

답변

1

물론 있습니다. 그냥 FuncDef 노드의 방문자를 작성하고 싶습니다.

에는 Decl이 있고 그 유형 하위는 FuncDecl입니다. 이 FuncDecl은 해당 형식 하위로 반환 형식을가집니다.

는 반환 유형이 경우 타입 식별자 는 하위 유형, 또는 그것의 타입 아이 형 자식 타입 식별자 인 TypeDecl, 어떤 경우에 PtrDecl를이다, 중 어느 하나 TypeDecl이다.

알았습니까?

hash_func: ['unsigned', 'int'] 
HashCreate: ['ReturnCode'] 
HashInsert: ['ReturnCode'] 
HashFind: ['Entry'] 
HashRemove: ['ReturnCode'] 
HashPrint: ['void'] 
HashDestroy: ['void'] 

지금 당신은 필요 Heres는 모든 함수의 이름과 반환 형식 출력 예 FuncDef 방문자 다음 cparser 분배에되는 hash.c 예제 파일을 구문 분석 할 때 다음

class FuncDefVisitor(c_ast.NodeVisitor): 
""" 
A simple visitor for FuncDef nodes that prints the names and 
return types of definitions. 
""" 
def visit_FuncDef(self, node): 
    return_type = node.decl.type.type 
    if type(return_type) == c_ast.TypeDecl: 
     identifier = return_type.type 
    else: # type(return_type) == c_ast.PtrDecl 
     identifier = return_type.type.type 
    print("{}: {}".format(node.decl.name, identifier.names)) 

출력입니다 내장 유형을 필터링하거나 관심있는 UDT를 필터링하십시오.