clang-tidy изолирует несколько объявлений полей - PullRequest
2 голосов
/ 08 января 2020

В clang-tidy есть проверка читаемости-объявления-изолята. Я пытаюсь сделать что-то подобное для объявлений полей.

Допустим, у нас есть следующее

typedef struct s{
    int x,y;
}s;

Если мы проверим приведенный выше пример в clang-query, мы получим что-то вроде

CXXRecordDecl 0x555e28564740 <<source>:1:9, line:4:1> line:1:16 struct s definition

|-DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal

| |-DefaultConstructor exists trivial needs_implicit

| |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param

| |-MoveConstructor exists simple trivial needs_implicit

| |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param

| |-MoveAssignment exists simple trivial needs_implicit

| `-Destructor simple irrelevant trivial needs_implicit

|-CXXRecordDecl 0x555e28564858 <col:9, col:16> col:16 implicit struct s

|-FieldDecl 0x555e28564900 <line:2:5, col:9> col:9 x 'int'

 -FieldDecl 0x555e28564968 <col:5, col:11> col:11 y 'int'

Здесь я получаю 2 разных FieldDecls для x и y. Я также получаю 2 FieldDecls в следующем случае

typedef struct s{
    int x;
    int y;
}s;
CXXRecordDecl 0x5648bcf47740 <<source>:1:9, line:5:1> line:1:16 struct s definition

|-DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal

| |-DefaultConstructor exists trivial needs_implicit

| |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param

| |-MoveConstructor exists simple trivial needs_implicit

| |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param

| |-MoveAssignment exists simple trivial needs_implicit

| `-Destructor simple irrelevant trivial needs_implicit

|-CXXRecordDecl 0x5648bcf47858 <col:9, col:16> col:16 implicit struct s

|-FieldDecl 0x5648bcf47900 <line:2:5, col:9> col:9 x 'int'

`-FieldDecl 0x5648bcf47968 <line:3:5, col:9> col:9 y 'int'

Это почти идентично. Как кто-то может различить guish между двумя случаями, основанными на AST?

...