75 } else if (decl instanceof StructTree) { 76 StructTree s = (StructTree)decl; 77 if (s.isAnonymous()) { 78 fields.addAll(s.fields()); 79 } 80 } 81 } 82 return Collections.unmodifiableList(fields); 83 } 84 85 public List<Tree> nestedTypes() { 86 // C structs and unions can have nested structs, unions and enums. 87 // And (even deeply) nested types are hoisted to the containing scope. 88 // i.e., nested structs/unions/enums are not scoped. 89 List<Tree> nested = new ArrayList<>(); 90 for (Tree decl : declarations) { 91 if (decl instanceof EnumTree) { 92 nested.add(decl); 93 } else if (decl instanceof StructTree) { 94 StructTree s = (StructTree)decl; 95 if (!s.isAnonymous()) { 96 nested.add(s); 97 } 98 nested.addAll(s.nestedTypes()); 99 } 100 } 101 return Collections.unmodifiableList(nested); 102 } 103 104 @Override 105 public <R,D> R accept(TreeVisitor<R,D> visitor, D data) { 106 return visitor.visitStruct(this, data); 107 } 108 109 public boolean isUnion() { 110 return cursor().kind() == CursorKind.UnionDecl; 111 } 112 113 114 /** 115 * Is this struct/union declared as anonymous member of another struct/union? 116 * 117 * Example: 118 * 119 * struct X { | 75 } else if (decl instanceof StructTree) { 76 StructTree s = (StructTree)decl; 77 if (s.isAnonymous()) { 78 fields.addAll(s.fields()); 79 } 80 } 81 } 82 return Collections.unmodifiableList(fields); 83 } 84 85 public List<Tree> nestedTypes() { 86 // C structs and unions can have nested structs, unions and enums. 87 // And (even deeply) nested types are hoisted to the containing scope. 88 // i.e., nested structs/unions/enums are not scoped. 89 List<Tree> nested = new ArrayList<>(); 90 for (Tree decl : declarations) { 91 if (decl instanceof EnumTree) { 92 nested.add(decl); 93 } else if (decl instanceof StructTree) { 94 StructTree s = (StructTree)decl; 95 nested.add(s); 96 } 97 } 98 return Collections.unmodifiableList(nested); 99 } 100 101 @Override 102 public <R,D> R accept(TreeVisitor<R,D> visitor, D data) { 103 return visitor.visitStruct(this, data); 104 } 105 106 public boolean isUnion() { 107 return cursor().kind() == CursorKind.UnionDecl; 108 } 109 110 111 /** 112 * Is this struct/union declared as anonymous member of another struct/union? 113 * 114 * Example: 115 * 116 * struct X { |