2017-02-16 5 views
0

두 개 이상의 유사한 액세스 지정자가 클래스에있는 경우 C++ 코드에서 대문자를 알아야합니다. 의이 클래스 A와 일치하는 방법 두 클래스ASTMatcher로 최소한 두 개의 동일한 액세스 지정자가있는 클래스 가져 오기

class A{ 
public: 
    int b; 
public: 
    int a; 
} 

class B{ 
public: 
    int a; 
} 

가 있다고 가정 해 봅시다 ASTMatcher와 아닌 클래스 B (이 두 개의 '공공의이 있기 때문에)? std::map<string,int>

콜백 클래스에서
accessSpecDecl(
    isPublic(), 
    hasAncestor(cxxRecordDecl().bind("crd"))).bind("asd") 

, 당신은 정규 주어진 구조체 선언 얻는다 히트 수를 추적 할 수 있습니다 예를 들면 다음과 같습니다 :

답변

0

이 정규 표현은 '공개'선언을 잡고

struct report_public : public MatchCallback{ 
    using map_t = std::map<string,int>; 
    using map_it = map_t::iterator; 

    map_t count; 

    void run(MatchResult const & result){ 
    AccessSpecDecl const * asd = result.Nodes.getNodeAs<AccessSpecDecl>("asd"); 
    CXXRecordDecl const * crd = result.Nodes.getNodeAs<CXXRecordDecl>("crd"); 
    if(asd && crd){ 
     string const struct_name = crd->getNameAsString(); 
     map_it it = count.find(struct_name); 
     if(it != count.end()) count[struct_name]++; 
     else count[struct_name] = 1; 
    } 
    else { /* error handling */} 
    return; 
    } // run 
}; // report_public 
+0

알다시피, 이해할 수 있듯이 Matcher만으로는이를 달성 할 수 없습니까? – igagis

+0

"이 노드 중 하나 이상"을 말하는 법을 모르겠습니다. –