1 /** 2 Member pointers 3 */ 4 module contract.member; 5 6 7 import contract; 8 9 10 @Tags("contract") 11 @("member object pointer") 12 @safe unittest { 13 const tu = parse( 14 Cpp( 15 q{ 16 struct Struct { int i; }; 17 int Struct::* globalStructInt; 18 } 19 ) 20 ); 21 22 tu.children.length.shouldEqual(2); 23 24 const struct_ = tu.children[0]; 25 struct_.kind.should == Cursor.Kind.StructDecl; 26 27 const global = tu.children[1]; 28 global.kind.should == Cursor.Kind.VarDecl; 29 30 const globalType = global.type; 31 globalType.kind.should == Type.Kind.MemberPointer; 32 33 const pointee = globalType.pointee; 34 pointee.kind.should == Type.Kind.Int; 35 } 36 37 38 39 @Tags("contract") 40 @("private") 41 @safe unittest { 42 import clang: AccessSpecifier; 43 44 const tu = parse( 45 Cpp( 46 q{ 47 struct Struct { 48 private: 49 int i; 50 public: 51 int j; 52 }; 53 } 54 ) 55 ); 56 57 tu.children.length.should == 1; 58 const struct_ = tu.child(0); 59 printChildren(struct_); 60 struct_.children.length.should == 4; 61 62 const private_ = struct_.child(0); 63 private_.shouldMatch(Cursor.Kind.CXXAccessSpecifier, ""); 64 private_.type.shouldMatch(Type.Kind.Invalid, ""); 65 private_.children.length.should == 0; 66 private_.accessSpecifier.should == AccessSpecifier.Private; 67 68 const i = struct_.child(1); 69 i.shouldMatch(Cursor.Kind.FieldDecl, "i"); 70 i.type.shouldMatch(Type.Kind.Int, "int"); 71 72 const public_ = struct_.child(2); 73 public_.shouldMatch(Cursor.Kind.CXXAccessSpecifier, ""); 74 public_.type.shouldMatch(Type.Kind.Invalid, ""); 75 public_.children.length.should == 0; 76 public_.accessSpecifier.should == AccessSpecifier.Public; 77 78 const j = struct_.child(3); 79 j.shouldMatch(Cursor.Kind.FieldDecl, "j"); 80 j.type.shouldMatch(Type.Kind.Int, "int"); 81 }