70 } else if (decl instanceof StructTree) { 71 StructTree s = (StructTree)decl; 72 if (!s.isAnonymous()) { 73 nested.add(s); 74 } 75 nested.addAll(s.nestedTypes()); 76 } 77 } 78 return Collections.unmodifiableList(nested); 79 } 80 81 @Override 82 public <R,D> R accept(TreeVisitor<R,D> visitor, D data) { 83 return visitor.visitStruct(this, data); 84 } 85 86 public boolean isUnion() { 87 return cursor().kind() == CursorKind.UnionDecl; 88 } 89 90 public boolean isAnonymous() { 91 return cursor().isAnonymousStruct(); 92 } 93 94 public Layout layout(BiFunction<FieldTree, Layout, Layout> fieldMapper) { 95 TreeMaker m = new TreeMaker(); 96 return LayoutUtils.getRecordLayout(cursor().type(), (cursor, layout) -> { 97 return fieldMapper.apply(m.createField(cursor), layout); 98 }); 99 } 100 } | 70 } else if (decl instanceof StructTree) { 71 StructTree s = (StructTree)decl; 72 if (!s.isAnonymous()) { 73 nested.add(s); 74 } 75 nested.addAll(s.nestedTypes()); 76 } 77 } 78 return Collections.unmodifiableList(nested); 79 } 80 81 @Override 82 public <R,D> R accept(TreeVisitor<R,D> visitor, D data) { 83 return visitor.visitStruct(this, data); 84 } 85 86 public boolean isUnion() { 87 return cursor().kind() == CursorKind.UnionDecl; 88 } 89 90 /** 91 * Is this struct/union declared as anonymous member of another struct/union? 92 * 93 * Example: 94 * 95 * struct X { 96 * struct { int i; int j; }; // <-- anonymous struct 97 * long l; 98 * }; 99 * 100 * Note: this is specific use of the word 'anonymous'. A struct with name() 101 * being empty is not necessarily anonymous in this usage. 102 * 103 * The structs in the following declarations are *not* anonymous eventhough 104 * the names of these structs are empty. 105 * 106 * struct { int i; int j; } thePoint; 107 * void func(struct { char* name; int len; } p1); 108 * typedef struct { int i; int j; } Point; 109 */ 110 public boolean isAnonymous() { 111 return cursor().isAnonymousStruct(); 112 } 113 114 public Layout layout(BiFunction<FieldTree, Layout, Layout> fieldMapper) { 115 TreeMaker m = new TreeMaker(); 116 return LayoutUtils.getRecordLayout(cursor().type(), (cursor, layout) -> { 117 return fieldMapper.apply(m.createField(cursor), layout); 118 }); 119 } 120 } |