diff --git a/ast/always_inline_attr_test.go b/ast/always_inline_attr_test.go new file mode 100644 index 000000000..9576e5821 --- /dev/null +++ b/ast/always_inline_attr_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestAlwaysInlineAttr(t *testing.T) { + nodes := map[string]Node{ + `0x7fce780f5018 always_inline`: &AlwaysInlineAttr{ + Address: "0x7fce780f5018", + Position: "/usr/include/sys/cdefs.h:313:68", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/array_subscript_expr_test.go b/ast/array_subscript_expr_test.go new file mode 100644 index 000000000..85e149b4a --- /dev/null +++ b/ast/array_subscript_expr_test.go @@ -0,0 +1,19 @@ +package ast + +import ( + "testing" +) + +func TestArraySubscriptExpr(t *testing.T) { + nodes := map[string]Node{ + `0x7fe35b85d180 'char *' lvalue`: &ArraySubscriptExpr{ + Address: "0x7fe35b85d180", + Position: "col:63, col:69", + Type: "char *", + Kind: "lvalue", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/asm_label_attr_test.go b/ast/asm_label_attr_test.go new file mode 100644 index 000000000..5893d52e1 --- /dev/null +++ b/ast/asm_label_attr_test.go @@ -0,0 +1,18 @@ +package ast + +import ( + "testing" +) + +func TestAsmLabelAttr(t *testing.T) { + nodes := map[string]Node{ + `0x7ff26d8224e8 "_fopen"`: &AsmLabelAttr{ + Address: "0x7ff26d8224e8", + Position: "/usr/include/sys/cdefs.h:569:36", + FunctionName: "_fopen", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/ast_test.go b/ast/ast_test.go index 29fdcb57e..d7666e142 100644 --- a/ast/ast_test.go +++ b/ast/ast_test.go @@ -1,1097 +1,27 @@ package ast import ( + "fmt" "reflect" "testing" ) -var nodes = map[string]Node{ - // AlwaysInlineAttr - `0x7fce780f5018 always_inline`: &AlwaysInlineAttr{ - Address: "0x7fce780f5018", - Position: "/usr/include/sys/cdefs.h:313:68", - Children: []Node{}, - }, - - // ArraySubscriptExpr - `0x7fe35b85d180 'char *' lvalue`: &ArraySubscriptExpr{ - Address: "0x7fe35b85d180", - Position: "col:63, col:69", - Type: "char *", - Kind: "lvalue", - Children: []Node{}, - }, - - // AsmLabelAttr - `0x7ff26d8224e8 "_fopen"`: &AsmLabelAttr{ - Address: "0x7ff26d8224e8", - Position: "/usr/include/sys/cdefs.h:569:36", - FunctionName: "_fopen", - Children: []Node{}, - }, - - // AvailabilityAttr - `0x7fc5ff8e5d18 macos 10.10 0 0 "" ""`: &AvailabilityAttr{ - Address: "0x7fc5ff8e5d18", - Position: "/usr/include/AvailabilityInternal.h:21697:88, col:124", - OS: "macos", - Version: "10.10", - Unknown1: 0, - Unknown2: 0, - Unavailable: false, - Message1: "", - Message2: "", - Children: []Node{}, - }, - `0x7fc5ff8e60d0 watchos 3.0 0 0 "" ""`: &AvailabilityAttr{ - Address: "0x7fc5ff8e60d0", - Position: "/usr/include/Availability.h:215:81, col:115", - OS: "watchos", - Version: "3.0", - Unknown1: 0, - Unknown2: 0, - Unavailable: false, - Message1: "", - Message2: "", - Children: []Node{}, - }, - `0x7fc5ff8e6170 tvos 10.0 0 0 "" ""`: &AvailabilityAttr{ - Address: "0x7fc5ff8e6170", - Position: "col:81, col:115", - OS: "tvos", - Version: "10.0", - Unknown1: 0, - Unknown2: 0, - Unavailable: false, - Message1: "", - Message2: "", - Children: []Node{}, - }, - `0x7fc5ff8e61d8 ios 10.0 0 0 "" ""`: &AvailabilityAttr{ - Address: "0x7fc5ff8e61d8", - Position: "col:81, col:115", - OS: "ios", - Version: "10.0", - Unknown1: 0, - Unknown2: 0, - Unavailable: false, - Message1: "", - Message2: "", - Children: []Node{}, - }, - `0x7fc5ff8f0e18 swift 0 0 0 Unavailable "Use snprintf instead." ""`: &AvailabilityAttr{ - Address: "0x7fc5ff8f0e18", - Position: "/usr/include/sys/cdefs.h:275:50, col:99", - OS: "swift", - Version: "0", - Unknown1: 0, - Unknown2: 0, - Unavailable: true, - Message1: "Use snprintf instead.", - Message2: "", - Children: []Node{}, - }, - `0x7fc5ff8f1988 swift 0 0 0 Unavailable "Use mkstemp(3) instead." ""`: &AvailabilityAttr{ - Address: "0x7fc5ff8f1988", - Position: "line:275:50, col:99", - OS: "swift", - Version: "0", - Unknown1: 0, - Unknown2: 0, - Unavailable: true, - Message1: "Use mkstemp(3) instead.", - Message2: "", - Children: []Node{}, - }, - `0x104035438 macosx 10.10 0 0 ""`: &AvailabilityAttr{ - Address: "0x104035438", - Position: "/usr/include/AvailabilityInternal.h:14571:88, col:124", - OS: "macosx", - Version: "10.10", - Unknown1: 0, - Unknown2: 0, - Unavailable: false, - Message1: "", - Message2: "", - Children: []Node{}, - }, - - // BinaryOperator - `0x7fca2d8070e0 'unsigned char' '='`: &BinaryOperator{ - Address: "0x7fca2d8070e0", - Position: "col:11, col:23", - Type: "unsigned char", - Operator: "=", - Children: []Node{}, - }, - - // BreakStmt - `0x7fca2d8070e0 `: &BreakStmt{ - Address: "0x7fca2d8070e0", - Position: "col:11, col:23", - Children: []Node{}, - }, - - // BuiltinType - `0x7f8a43023f40 '__int128'`: &BuiltinType{ - Address: "0x7f8a43023f40", - Type: "__int128", - Children: []Node{}, - }, - `0x7f8a43023ea0 'unsigned long long'`: &BuiltinType{ - Address: "0x7f8a43023ea0", - Type: "unsigned long long", - Children: []Node{}, - }, - - // CallExpr - `0x7f9bf3033240 'int'`: &CallExpr{ - Address: "0x7f9bf3033240", - Position: "col:11, col:25", - Type: "int", - Children: []Node{}, - }, - `0x7f9bf3035c20 'int'`: &CallExpr{ - Address: "0x7f9bf3035c20", - Position: "line:7:4, col:64", - Type: "int", - Children: []Node{}, - }, - - // CaseStmt - `0x7fc8b5094688 `: &CaseStmt{ - Address: "0x7fc8b5094688", - Position: "line:11:5, line:12:21", - Children: []Node{}, - }, - - // CharacterLiteral - `0x7f980b858308 'int' 10`: &CharacterLiteral{ - Address: "0x7f980b858308", - Position: "col:62", - Type: "int", - Value: 10, - Children: []Node{}, - }, - - // CompoundStmt - `0x7fbd0f014f18 `: &CompoundStmt{ - Address: "0x7fbd0f014f18", - Position: "col:54, line:358:1", - Children: []Node{}, - }, - `0x7fbd0f8360b8 `: &CompoundStmt{ - Address: "0x7fbd0f8360b8", - Position: "line:4:1, line:13:1", - Children: []Node{}, - }, - - // ConditionalOperator - `0x7fc6ae0bc678 'void'`: &ConditionalOperator{ - Address: "0x7fc6ae0bc678", - Position: "col:6, col:89", - Type: "void", - Children: []Node{}, - }, - - // ConstAttr - `0x7fa3b88bbb38 foo`: &ConstAttr{ - Address: "0x7fa3b88bbb38", - Position: "line:4:1, line:13:1", - Tags: "foo", - Children: []Node{}, - }, - - // ConstantArrayType - `0x7f94ad016a40 'struct __va_list_tag [1]' 1`: &ConstantArrayType{ - Address: "0x7f94ad016a40", - Type: "struct __va_list_tag [1]", - Size: 1, - Children: []Node{}, - }, - `0x7f8c5f059d20 'char [37]' 37`: &ConstantArrayType{ - Address: "0x7f8c5f059d20", - Type: "char [37]", - Size: 37, - Children: []Node{}, - }, - - // CStyleCastExpr - `0x7fddc18fb2e0 'char' `: &CStyleCastExpr{ - Address: "0x7fddc18fb2e0", - Position: "col:50, col:56", - Type: "char", - Kind: "IntegralCast", - Children: []Node{}, - }, - - // DeclRefExpr - `0x7fc972064460 'FILE *' lvalue ParmVar 0x7fc9720642d0 '_p' 'FILE *'`: &DeclRefExpr{ - Address: "0x7fc972064460", - Position: "col:8", - Type: "FILE *", - Lvalue: true, - For: "ParmVar", - Address2: "0x7fc9720642d0", - Name: "_p", - Type2: "FILE *", - Children: []Node{}, - }, - `0x7fc97206a958 'int (int, FILE *)' Function 0x7fc972064198 '__swbuf' 'int (int, FILE *)'`: &DeclRefExpr{ - Address: "0x7fc97206a958", - Position: "col:11", - Type: "int (int, FILE *)", - Lvalue: false, - For: "Function", - Address2: "0x7fc972064198", - Name: "__swbuf", - Type2: "int (int, FILE *)", - Children: []Node{}, - }, - `0x7fa36680f170 'struct programming':'struct programming' lvalue Var 0x7fa36680dc20 'variable' 'struct programming':'struct programming'`: &DeclRefExpr{ - Address: "0x7fa36680f170", - Position: "col:19", - Type: "struct programming", - Lvalue: true, - For: "Var", - Address2: "0x7fa36680dc20", - Name: "variable", - Type2: "struct programming", - Children: []Node{}, - }, - - // DeclStmt - `0x7fb791846e80 `: &DeclStmt{ - Address: "0x7fb791846e80", - Position: "line:11:4, col:31", - Children: []Node{}, - }, - - // DefaultStmt - `0x7f951308bfb0 `: &DefaultStmt{ - Address: "0x7f951308bfb0", - Position: "line:17:5, line:18:34", - Children: []Node{}, - }, - - // DeprecatedAttr - `0x7fec4b0ab9c0 "This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tempnam(3), it is highly recommended that you use mkstemp(3) instead." ""`: &DeprecatedAttr{ - Address: "0x7fec4b0ab9c0", - Position: "line:180:48, col:63", - Message1: "This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tempnam(3), it is highly recommended that you use mkstemp(3) instead.", - Message2: "", - Children: []Node{}, - }, - - // DoStmt - `0x7ff36d0a0938 `: &DoStmt{ - Address: "0x7ff36d0a0938", - Position: "line:11:5, line:14:23", - Children: []interface{}{}, - }, - - // ElaboratedType - `0x7f873686c120 'union __mbstate_t' sugar`: &ElaboratedType{ - Address: "0x7f873686c120", - Type: "union __mbstate_t", - Tags: "sugar", - Children: []Node{}, - }, - - // Enum - `0x7f980b858308 'foo'`: &Enum{ - Address: "0x7f980b858308", - Name: "foo", - Children: []Node{}, - }, - - // EnumDecl - `0x22a6c80 __codecvt_result`: &EnumDecl{ - Address: "0x22a6c80", - Position: "line:180:1, line:186:1", - Position2: "", - Name: "__codecvt_result", - Children: []Node{}, - }, - - // EnumConstantDecl - `0x1660db0 __codecvt_noconv 'int'`: &EnumConstantDecl{ - Address: "0x1660db0", - Position: "line:185:3", - Position2: "", - Name: "__codecvt_noconv", - Type: "int", - Children: []Node{}, - }, - - // EnumType - `0x7f980b858309 'foo'`: &EnumType{ - Address: "0x7f980b858309", - Name: "foo", - Children: []Node{}, - }, - - // FieldDecl - `0x7fef510c4848 col:6 _ur 'int'`: &FieldDecl{ - Address: "0x7fef510c4848", - Position: "line:141:2, col:6", - Position2: "col:6", - Name: "_ur", - Type: "int", - Referenced: false, - Children: []Node{}, - }, - `0x7fef510c46f8 col:16 _ub 'struct __sbuf':'struct __sbuf'`: &FieldDecl{ - Address: "0x7fef510c46f8", - Position: "line:139:2, col:16", - Position2: "col:16", - Name: "_ub", - Type: "struct __sbuf", - Referenced: false, - Children: []Node{}, - }, - `0x7fef510c3fe0 col:19 _read 'int (* _Nullable)(void *, char *, int)':'int (*)(void *, char *, int)'`: &FieldDecl{ - Address: "0x7fef510c3fe0", - Position: "line:134:2, col:19", - Position2: "col:19", - Name: "_read", - Type: "int (* _Nullable)(void *, char *, int)", - Referenced: false, - Children: []Node{}, - }, - `0x7fef51073a60 col:40 __cleanup_stack 'struct __darwin_pthread_handler_rec *'`: &FieldDecl{ - Address: "0x7fef51073a60", - Position: "line:105:2, col:40", - Position2: "col:40", - Name: "__cleanup_stack", - Type: "struct __darwin_pthread_handler_rec *", - Referenced: false, - Children: []Node{}, - }, - `0x7fef510738e8 col:7 __opaque 'char [16]'`: &FieldDecl{ - Address: "0x7fef510738e8", - Position: "line:100:2, col:43", - Position2: "col:7", - Name: "__opaque", - Type: "char [16]", - Referenced: false, - Children: []Node{}, - }, - `0x7fe9f5072268 col:6 referenced _lbfsize 'int'`: &FieldDecl{ - Address: "0x7fe9f5072268", - Position: "line:129:2, col:6", - Position2: "col:6", - Name: "_lbfsize", - Type: "int", - Referenced: true, - Children: []Node{}, - }, - `0x7f9bc9083d00 line:91:5 'unsigned short'`: &FieldDecl{ - Address: "0x7f9bc9083d00", - Position: "line:91:5, line:97:8", - Position2: "line:91:5", - Name: "", - Type: "unsigned short", - Referenced: false, - Children: []Node{}, - }, - `0x30363a0 __val 'int [2]'`: &FieldDecl{ - Address: "0x30363a0", - Position: "col:18, col:29", - Position2: "", - Name: "__val", - Type: "int [2]", - Referenced: false, - Children: []Node{}, - }, - - // FloatingLiteral - `0x7febe106f5e8 'double' 1.230000e+00`: &FloatingLiteral{ - Address: "0x7febe106f5e8", - Position: "col:24", - Type: "double", - Value: 1.23, - Children: []Node{}, - }, - - // FormatAttr - `0x7fcc8d8ecee8 Implicit printf 2 3`: &FormatAttr{ - Address: "0x7fcc8d8ecee8", - Position: "col:6", - Implicit: true, - Inherited: false, - FunctionName: "printf", - Unknown1: 2, - Unknown2: 3, - Children: []Node{}, - }, - `0x7fcc8d8ecff8 printf 2 3`: &FormatAttr{ - Address: "0x7fcc8d8ecff8", - Position: "/usr/include/sys/cdefs.h:351:18, col:61", - Implicit: false, - Inherited: false, - FunctionName: "printf", - Unknown1: 2, - Unknown2: 3, - Children: []Node{}, - }, - `0x273b4d0 Inherited printf 2 3`: &FormatAttr{ - Address: "0x273b4d0", - Position: "line:357:12", - Implicit: false, - Inherited: true, - FunctionName: "printf", - Unknown1: 2, - Unknown2: 3, - Children: []Node{}, - }, - - // FunctionDecl - `0x7fb5a90e60d0 col:7 clearerr 'void (FILE *)'`: &FunctionDecl{ - Address: "0x7fb5a90e60d0", - Position: "line:231:1, col:22", - Prev: "", - Position2: "col:7", - Name: "clearerr", - Type: "void (FILE *)", - IsExtern: false, - IsImplicit: false, - IsUsed: false, - Children: []Node{}, - }, - `0x7fb5a90e2a50 /usr/include/sys/stdio.h:39:5 renameat 'int (int, const char *, int, const char *)'`: &FunctionDecl{ - Address: "0x7fb5a90e2a50", - Position: "/usr/include/sys/stdio.h:39:1, /usr/include/AvailabilityInternal.h:21697:126", - Prev: "", - Position2: "/usr/include/sys/stdio.h:39:5", - Name: "renameat", - Type: "int (int, const char *, int, const char *)", - IsExtern: false, - IsImplicit: false, - IsUsed: false, - Children: []Node{}, - }, - `0x7fb5a90e9b70 col:6 implicit fprintf 'int (FILE *, const char *, ...)' extern`: &FunctionDecl{ - Address: "0x7fb5a90e9b70", - Position: "/usr/include/stdio.h:244:6", - Prev: "", - Position2: "col:6", - Name: "fprintf", - Type: "int (FILE *, const char *, ...)", - IsExtern: true, - IsImplicit: true, - IsUsed: false, - Children: []Node{}, - }, - `0x7fb5a90e9d40 prev 0x7fb5a90e9b70 /usr/include/stdio.h:244:6 fprintf 'int (FILE *, const char *, ...)'`: &FunctionDecl{ - Address: "0x7fb5a90e9d40", - Position: "col:1, /usr/include/sys/cdefs.h:351:63", - Prev: "0x7fb5a90e9b70", - Position2: "/usr/include/stdio.h:244:6", - Name: "fprintf", - Type: "int (FILE *, const char *, ...)", - IsExtern: false, - IsImplicit: false, - IsUsed: false, - Children: []Node{}, - }, - `0x7fb5a90ec210 col:6 implicit used printf 'int (const char *, ...)' extern`: &FunctionDecl{ - Address: "0x7fb5a90ec210", - Position: "line:259:6", - Prev: "", - Position2: "col:6", - Name: "printf", - Type: "int (const char *, ...)", - IsExtern: true, - IsImplicit: true, - IsUsed: true, - Children: []Node{}, - }, - `0x2ae30d8 :17:1 __acos 'double (double)' extern`: &FunctionDecl{ - Address: "0x2ae30d8", - Position: "/usr/include/math.h:65:3, /usr/include/x86_64-linux-gnu/sys/cdefs.h:57:54", - Prev: "", - Position2: ":17:1", - Name: "__acos", - Type: "double (double)", - IsExtern: true, - IsImplicit: false, - IsUsed: false, - Children: []Node{}, - }, - - // FunctionProtoType - `0x7fa3b88bbb30 'struct _opaque_pthread_t *' foo`: &FunctionProtoType{ - Address: "0x7fa3b88bbb30", - Type: "struct _opaque_pthread_t *", - Kind: "foo", - Children: []Node{}, - }, - - // ForStmt - `0x7f961e018848 `: &ForStmt{ - Address: "0x7f961e018848", - Position: "line:9:4, line:10:70", - Children: []Node{}, - }, - - // IfStmt - `0x7fc0a69091d0 `: &IfStmt{ - Address: "0x7fc0a69091d0", - Position: "line:11:7, line:18:7", - Children: []Node{}, - }, - - // ImplicitCastExpr - `0x7f9f5b0a1288 'FILE *' `: &ImplicitCastExpr{ - Address: "0x7f9f5b0a1288", - Position: "col:8", - Type: "FILE *", - Kind: "LValueToRValue", - Children: []Node{}, - }, - `0x7f9f5b0a7828 'int (*)(int, FILE *)' `: &ImplicitCastExpr{ - Address: "0x7f9f5b0a7828", - Position: "col:11", - Type: "int (*)(int, FILE *)", - Kind: "FunctionToPointerDecay", - Children: []Node{}, - }, - - // IntegerLiteral - `0x7fbe9804bcc8 'int' 1`: &IntegerLiteral{ - Address: "0x7fbe9804bcc8", - Position: "col:14", - Type: "int", - Value: 1, - Children: []Node{}, - }, - - // MallocAttr - `0x7fc0a69091d1 `: &MallocAttr{ - Address: "0x7fc0a69091d1", - Position: "line:11:7, line:18:7", - Children: []Node{}, - }, - - // MemberExpr - `0x7fcc758e34a0 'int' lvalue ->_w 0x7fcc758d60c8`: &MemberExpr{ - Address: "0x7fcc758e34a0", - Position: "col:8, col:12", - Type: "int", - Lvalue: true, - Name: "_w", - Address2: "0x7fcc758d60c8", - Children: []Node{}, - }, - `0x7fcc76004210 'unsigned char *' lvalue ->_p 0x7fcc758d6018`: &MemberExpr{ - Address: "0x7fcc76004210", - Position: "col:12, col:16", - Type: "unsigned char *", - Lvalue: true, - Name: "_p", - Address2: "0x7fcc758d6018", - Children: []Node{}, - }, - `0x7f85338325b0 'float' lvalue .constant 0x7f8533832260`: &MemberExpr{ - Address: "0x7f85338325b0", - Position: "col:4, col:13", - Type: "float", - Lvalue: true, - Name: "constant", - Address2: "0x7f8533832260", - Children: []Node{}, - }, - `0x7f8533832670 'char *' lvalue .pointer 0x7f85338322b8`: &MemberExpr{ - Address: "0x7f8533832670", - Position: "col:4, col:13", - Type: "char *", - Lvalue: true, - Name: "pointer", - Address2: "0x7f85338322b8", - Children: []Node{}, - }, - - // ModeAttr - `0x7f980b858309 foo`: &ModeAttr{ - Address: "0x7f980b858309", - Position: "line:11:7, line:18:7", - Name: "foo", - Children: []Node{}, - }, - - // NoThrowAttr - `0x7fa1488273a0 `: &NoThrowAttr{ - Address: "0x7fa1488273a0", - Position: "line:7:4, line:11:4", - Children: []Node{}, - }, - - // NonNullAttr - `0x7fa1488273b0 1`: &NonNullAttr{ - Address: "0x7fa1488273b0", - Position: "line:7:4, line:11:4", - A: 1, - B: 0, - Children: []Node{}, - }, - `0x2cce280 1`: &NonNullAttr{ - Address: "0x2cce280", - Position: "/sys/cdefs.h:286:44, /bits/mathcalls.h:115:69", - A: 1, - B: 0, - Children: []Node{}, - }, - `0x201ede0 0`: &NonNullAttr{ - Address: "0x201ede0", - Position: "line:145:79, col:93", - A: 0, - B: 0, - Children: []Node{}, - }, - `0x1b89b20 2 3`: &NonNullAttr{ - Address: "0x1b89b20", - Position: "col:76, col:93", - A: 2, - B: 3, - Children: []Node{}, - }, - - // ParenExpr - `0x7fb0bc8b2308 'unsigned char'`: &ParenExpr{ - Address: "0x7fb0bc8b2308", - Position: "col:10, col:25", - Type: "unsigned char", - Children: []Node{}, - }, - - // ParenType - `0x7faf820a4c60 'void (int)' sugar`: &ParenType{ - Address: "0x7faf820a4c60", - Type: "void (int)", - Sugar: true, - Children: []interface{}{}, - }, - - // ParmVarDecl - `0x7f973380f000 col:17 'int'`: &ParmVarDecl{ - Address: "0x7f973380f000", - Position: "col:14", - Position2: "col:17", - Type: "int", - Name: "", - Type2: "", - IsUsed: false, - Children: []Node{}, - }, - `0x7f973380f070 col:31 'const char *'`: &ParmVarDecl{ - Address: "0x7f973380f070", - Position: "col:19, col:30", - Position2: "col:31", - Type: "const char *", - Name: "", - Type2: "", - IsUsed: false, - Children: []Node{}, - }, - `0x7f9733816e50 col:37 __filename 'const char *__restrict'`: &ParmVarDecl{ - Address: "0x7f9733816e50", - Position: "col:13, col:37", - Position2: "col:37", - Type: "const char *__restrict", - Name: "__filename", - Type2: "", - IsUsed: false, - Children: []Node{}, - }, - `0x7f9733817418 <> 'FILE *'`: &ParmVarDecl{ - Address: "0x7f9733817418", - Position: "", - Position2: "", - Type: "FILE *", - Name: "", - Type2: "", - IsUsed: false, - Children: []Node{}, - }, - `0x7f9733817c30 col:47 __size 'size_t':'unsigned long'`: &ParmVarDecl{ - Address: "0x7f9733817c30", - Position: "col:40, col:47", - Position2: "col:47", - Type: "size_t", - Name: "__size", - Type2: "unsigned long", - IsUsed: false, - Children: []Node{}, - }, - `0x7f973382fa10 col:34 'int (* _Nullable)(void *, char *, int)':'int (*)(void *, char *, int)'`: &ParmVarDecl{ - Address: "0x7f973382fa10", - Position: "line:476:18, col:25", - Position2: "col:34", - Type: "int (* _Nullable)(void *, char *, int)", - Name: "", - Type2: "int (*)(void *, char *, int)", - IsUsed: false, - Children: []Node{}, - }, - `0x7f97338355b8 col:14 used argc 'int'`: &ParmVarDecl{ - Address: "0x7f97338355b8", - Position: "col:10, col:14", - Position2: "col:14", - Type: "int", - Name: "argc", - Type2: "", - IsUsed: true, - Children: []Node{}, - }, - - // PointerType - `0x7fa3b88bbb30 'struct _opaque_pthread_t *'`: &PointerType{ - Address: "0x7fa3b88bbb30", - Type: "struct _opaque_pthread_t *", - Children: []Node{}, - }, - - // PredefinedExpr - `0x33d6e08 'const char [25]' lvalue __PRETTY_FUNCTION__`: &PredefinedExpr{ - Address: "0x33d6e08", - Position: "col:30", - Type: "const char [25]", - Lvalue: true, - Name: "__PRETTY_FUNCTION__", - Children: []Node{}, - }, - - // PureAttr - `0x7fe9eb899198 Implicit`: &PureAttr{ - Address: "0x7fe9eb899198", - Position: "col:1", - Implicit: true, - Inherited: false, - Children: []interface{}{}, - }, - `0x7fe8d60992a0 Inherited Implicit`: &PureAttr{ - Address: "0x7fe8d60992a0", - Position: "col:1", - Implicit: true, - Inherited: true, - Children: []interface{}{}, - }, - - // QualType - `0x7fa3b88bbb31 'struct _opaque_pthread_t *' foo`: &QualType{ - Address: "0x7fa3b88bbb31", - Type: "struct _opaque_pthread_t *", - Kind: "foo", - Children: []Node{}, - }, - - // Record - `0x7fd3ab857950 '__sFILE'`: &Record{ - Address: "0x7fd3ab857950", - Type: "__sFILE", - Children: []Node{}, - }, - - // RecordDecl - `0x7f913c0dbb50 line:76:9 union definition`: &RecordDecl{ - Address: "0x7f913c0dbb50", - Position: "line:76:9, line:79:1", - Prev: "", - Position2: "line:76:9", - Kind: "union", - Name: "", - Definition: true, - Children: []Node{}, - }, - `0x7f85360285c8 line:57:8 struct __darwin_pthread_handler_rec definition`: &RecordDecl{ - Address: "0x7f85360285c8", - Position: "/usr/include/sys/_pthread/_pthread_types.h:57:1, line:61:1", - Prev: "", - Position2: "line:57:8", - Kind: "struct", - Name: "__darwin_pthread_handler_rec", - Definition: true, - Children: []Node{}, - }, - `0x7f85370248a0 col:8 struct __sFILEX`: &RecordDecl{ - Address: "0x7f85370248a0", - Position: "line:94:1, col:8", - Prev: "", - Position2: "col:8", - Kind: "struct", - Name: "__sFILEX", - Definition: false, - Children: []Node{}, - }, - - // RecordType - `0x7fd3ab84dda0 'struct _opaque_pthread_condattr_t'`: &RecordType{ - Address: "0x7fd3ab84dda0", - Type: "struct _opaque_pthread_condattr_t", - Children: []Node{}, - }, - - // RestrictAttr - `0x7f980b858305 foo`: &RestrictAttr{ - Address: "0x7f980b858305", - Position: "line:11:7, line:18:7", - Name: "foo", - Children: []Node{}, - }, - - // ReturnStmt - `0x7fbb7a8325e0 `: &ReturnStmt{ - Address: "0x7fbb7a8325e0", - Position: "line:13:4, col:11", - Children: []Node{}, - }, - - // StringLiteral - `0x7fe16f0b4d58 'char [45]' lvalue "Number of command line arguments passed: %d\n"`: &StringLiteral{ - Address: "0x7fe16f0b4d58", - Position: "col:11", - Type: "char [45]", - Lvalue: true, - Value: "Number of command line arguments passed: %d\n", - Children: []Node{}, - }, - - // SwitchStmt - `0x7fbca3894638 `: &SwitchStmt{ - Address: "0x7fbca3894638", - Position: "line:9:5, line:20:5", - Children: []Node{}, - }, - - // TranslationUnitDecl - `0x7fe78a815ed0 <> `: &TranslationUnitDecl{ - Address: "0x7fe78a815ed0", - Children: []Node{}, - }, - - // TransparentUnionAttr - `0x304f700 `: &TransparentUnionAttr{ - Address: "0x304f700", - Position: "col:35", - Children: []Node{}, - }, - - // Typedef - `0x7f84d10dc1d0 '__darwin_ssize_t'`: &Typedef{ - Address: "0x7f84d10dc1d0", - Type: "__darwin_ssize_t", - Children: []Node{}, - }, - - // TypedefDecl - `0x7fdef0862430 col:16`: &TypedefDecl{ - Address: "0x7fdef0862430", - Position: "line:120:1, col:16", - Position2: "col:16", - Name: "", - Type: "", - Type2: "", - IsImplicit: false, - IsReferenced: false, - Children: []Node{}, - }, - `0x7ffb9f824278 <> implicit __uint128_t 'unsigned __int128'`: &TypedefDecl{ - Address: "0x7ffb9f824278", - Position: "", - Position2: "", - Name: "__uint128_t", - Type: "unsigned __int128", - Type2: "", - IsImplicit: true, - IsReferenced: false, - Children: []Node{}, - }, - `0x7ffb9f824898 <> implicit referenced __builtin_va_list 'struct __va_list_tag [1]'`: &TypedefDecl{ - Address: "0x7ffb9f824898", - Position: "", - Position2: "", - Name: "__builtin_va_list", - Type: "struct __va_list_tag [1]", - Type2: "", - IsImplicit: true, - IsReferenced: true, - Children: []Node{}, - }, - `0x7ffb9f8248f8 col:24 __int8_t 'signed char'`: &TypedefDecl{ - Address: "0x7ffb9f8248f8", - Position: "/usr/include/i386/_types.h:37:1, col:24", - Position2: "col:24", - Name: "__int8_t", - Type: "signed char", - Type2: "", - IsImplicit: false, - IsReferenced: false, - Children: []Node{}, - }, - `0x7ffb9f8dbf50 col:27 referenced __darwin_va_list '__builtin_va_list':'struct __va_list_tag [1]'`: &TypedefDecl{ - Address: "0x7ffb9f8dbf50", - Position: "line:98:1, col:27", - Position2: "col:27", - Name: "__darwin_va_list", - Type: "__builtin_va_list", - Type2: "struct __va_list_tag [1]", - IsImplicit: false, - IsReferenced: true, - Children: []Node{}, - }, - `0x34461f0 __io_read_fn '__ssize_t (void *, char *, size_t)'`: &TypedefDecl{ - Address: "0x34461f0", - Position: "line:338:1, col:77", - Position2: "", - Name: "__io_read_fn", - Type: "__ssize_t (void *, char *, size_t)", - Type2: "", - IsImplicit: false, - IsReferenced: false, - Children: []Node{}, - }, - `0x55b9da8784b0 line:341:19 __io_write_fn '__ssize_t (void *, const char *, size_t)'`: &TypedefDecl{ - Address: "0x55b9da8784b0", - Position: "line:341:1, line:342:16", - Position2: "line:341:19", - Name: "__io_write_fn", - Type: "__ssize_t (void *, const char *, size_t)", - Type2: "", - IsImplicit: false, - IsReferenced: false, - Children: []Node{}, - }, - - // TypedefType - `0x7f887a0dc760 '__uint16_t' sugar`: &TypedefType{ - Address: "0x7f887a0dc760", - Type: "__uint16_t", - Tags: "sugar", - Children: []Node{}, - }, - - // UnaryOperator - `0x7fe0260f50d8 'int' prefix '--'`: &UnaryOperator{ - Address: "0x7fe0260f50d8", - Position: "col:6, col:12", - Type: "int", - IsLvalue: false, - IsPrefix: true, - Operator: "--", - Children: []Node{}, - }, - `0x7fe0260fb468 'unsigned char' lvalue prefix '*'`: &UnaryOperator{ - Address: "0x7fe0260fb468", - Position: "col:11, col:18", - Type: "unsigned char", - IsLvalue: true, - IsPrefix: true, - Operator: "*", - Children: []Node{}, - }, - `0x7fe0260fb448 'unsigned char *' postfix '++'`: &UnaryOperator{ - Address: "0x7fe0260fb448", - Position: "col:12, col:18", - Type: "unsigned char *", - IsLvalue: false, - IsPrefix: false, - Operator: "++", - Children: []Node{}, - }, - - // VarDecl - `0x7fd5e90e5a00 col:17 'int'`: &VarDecl{ - Address: "0x7fd5e90e5a00", - Position: "col:14", - Position2: "col:17", - Name: "", - Type: "int", - Type2: "", - IsExtern: false, - IsUsed: false, - IsCInit: false, - Children: []Node{}, - }, - `0x7fd5e90e9078 col:14 __stdinp 'FILE *' extern`: &VarDecl{ - Address: "0x7fd5e90e9078", - Position: "line:156:1, col:14", - Position2: "col:14", - Name: "__stdinp", - Type: "FILE *", - Type2: "", - IsExtern: true, - IsUsed: false, - IsCInit: false, - Children: []Node{}, - }, - `0x7fd5e90ed630 col:47 __size 'size_t':'unsigned long'`: &VarDecl{ - Address: "0x7fd5e90ed630", - Position: "col:40, col:47", - Position2: "col:47", - Name: "__size", - Type: "size_t", - Type2: "unsigned long", - IsExtern: false, - IsUsed: false, - IsCInit: false, - Children: []Node{}, - }, - `0x7fee35907a78 col:8 used c 'int'`: &VarDecl{ - Address: "0x7fee35907a78", - Position: "col:4, col:8", - Position2: "col:8", - Name: "c", - Type: "int", - Type2: "", - IsExtern: false, - IsUsed: true, - IsCInit: false, - Children: []Node{}, - }, - `0x7fb0fd90ba30 tests/assert/assert.c:13:9 used b 'int *' cinit`: &VarDecl{ - Address: "0x7fb0fd90ba30", - Position: "col:3, /usr/include/sys/_types.h:52:33", - Position2: "tests/assert/assert.c:13:9", - Name: "b", - Type: "int *", - Type2: "", - IsExtern: false, - IsUsed: true, - IsCInit: true, - Children: []Node{}, - }, - - // WarnUnusedResultAttr - `0x7fa1d704d420 warn_unused_result`: &WarnUnusedResultAttr{ - Address: "0x7fa1d704d420", - Position: "col:60", - Children: []interface{}{}, - }, - `0x1fac810 `: &WarnUnusedResultAttr{ - Address: "0x1fac810", - Position: "line:481:52", - Children: []interface{}{}, - }, - - // WhileStmt - `0x7fa1478273a0 `: &WhileStmt{ - Address: "0x7fa1478273a0", - Position: "line:7:4, line:11:4", - Children: []Node{}, - }, -} - -func TestNodes(t *testing.T) { - for line, expected := range nodes { - // Append the name of the struct onto the front. This would make - // the complete line it would normally be parsing. - actual := Parse( - reflect.TypeOf(expected).Elem().Name() + " " + line) - - if !reflect.DeepEqual(expected, actual) { - t.Errorf("\nexpected: %#v\n got: %#v\n\n", - expected, actual) - } +func runNodeTests(t *testing.T, tests map[string]Node) { + i := 1 + for line, expected := range tests { + testName := fmt.Sprintf("Example%d", i) + i++ + + t.Run(testName, func(t *testing.T) { + // Append the name of the struct onto the front. This would make the + // complete line it would normally be parsing. + name := reflect.TypeOf(expected).Elem().Name() + actual := Parse(name + " " + line) + + if !reflect.DeepEqual(expected, actual) { + t.Errorf("\nexpected: %#v\n got: %#v\n\n", + expected, actual) + } + }) } } diff --git a/ast/availability_attr_test.go b/ast/availability_attr_test.go new file mode 100644 index 000000000..7d8f3d9b3 --- /dev/null +++ b/ast/availability_attr_test.go @@ -0,0 +1,96 @@ +package ast + +import ( + "testing" +) + +func TestAvailabilityAttr(t *testing.T) { + nodes := map[string]Node{ + `0x7fc5ff8e5d18 macos 10.10 0 0 "" ""`: &AvailabilityAttr{ + Address: "0x7fc5ff8e5d18", + Position: "/usr/include/AvailabilityInternal.h:21697:88, col:124", + OS: "macos", + Version: "10.10", + Unknown1: 0, + Unknown2: 0, + Unavailable: false, + Message1: "", + Message2: "", + Children: []Node{}, + }, + `0x7fc5ff8e60d0 watchos 3.0 0 0 "" ""`: &AvailabilityAttr{ + Address: "0x7fc5ff8e60d0", + Position: "/usr/include/Availability.h:215:81, col:115", + OS: "watchos", + Version: "3.0", + Unknown1: 0, + Unknown2: 0, + Unavailable: false, + Message1: "", + Message2: "", + Children: []Node{}, + }, + `0x7fc5ff8e6170 tvos 10.0 0 0 "" ""`: &AvailabilityAttr{ + Address: "0x7fc5ff8e6170", + Position: "col:81, col:115", + OS: "tvos", + Version: "10.0", + Unknown1: 0, + Unknown2: 0, + Unavailable: false, + Message1: "", + Message2: "", + Children: []Node{}, + }, + `0x7fc5ff8e61d8 ios 10.0 0 0 "" ""`: &AvailabilityAttr{ + Address: "0x7fc5ff8e61d8", + Position: "col:81, col:115", + OS: "ios", + Version: "10.0", + Unknown1: 0, + Unknown2: 0, + Unavailable: false, + Message1: "", + Message2: "", + Children: []Node{}, + }, + `0x7fc5ff8f0e18 swift 0 0 0 Unavailable "Use snprintf instead." ""`: &AvailabilityAttr{ + Address: "0x7fc5ff8f0e18", + Position: "/usr/include/sys/cdefs.h:275:50, col:99", + OS: "swift", + Version: "0", + Unknown1: 0, + Unknown2: 0, + Unavailable: true, + Message1: "Use snprintf instead.", + Message2: "", + Children: []Node{}, + }, + `0x7fc5ff8f1988 swift 0 0 0 Unavailable "Use mkstemp(3) instead." ""`: &AvailabilityAttr{ + Address: "0x7fc5ff8f1988", + Position: "line:275:50, col:99", + OS: "swift", + Version: "0", + Unknown1: 0, + Unknown2: 0, + Unavailable: true, + Message1: "Use mkstemp(3) instead.", + Message2: "", + Children: []Node{}, + }, + `0x104035438 macosx 10.10 0 0 ""`: &AvailabilityAttr{ + Address: "0x104035438", + Position: "/usr/include/AvailabilityInternal.h:14571:88, col:124", + OS: "macosx", + Version: "10.10", + Unknown1: 0, + Unknown2: 0, + Unavailable: false, + Message1: "", + Message2: "", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/binary_operator_test.go b/ast/binary_operator_test.go new file mode 100644 index 000000000..acf9e706b --- /dev/null +++ b/ast/binary_operator_test.go @@ -0,0 +1,19 @@ +package ast + +import ( + "testing" +) + +func TestBinaryOperator(t *testing.T) { + nodes := map[string]Node{ + `0x7fca2d8070e0 'unsigned char' '='`: &BinaryOperator{ + Address: "0x7fca2d8070e0", + Position: "col:11, col:23", + Type: "unsigned char", + Operator: "=", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/break_stmt_test.go b/ast/break_stmt_test.go new file mode 100644 index 000000000..2bfa5f128 --- /dev/null +++ b/ast/break_stmt_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestBreakStmt(t *testing.T) { + nodes := map[string]Node{ + `0x7fca2d8070e0 `: &BreakStmt{ + Address: "0x7fca2d8070e0", + Position: "col:11, col:23", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/builtin_type_test.go b/ast/builtin_type_test.go new file mode 100644 index 000000000..ad7c35956 --- /dev/null +++ b/ast/builtin_type_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestBuiltinType(t *testing.T) { + nodes := map[string]Node{ + `0x7f8a43023f40 '__int128'`: &BuiltinType{ + Address: "0x7f8a43023f40", + Type: "__int128", + Children: []Node{}, + }, + `0x7f8a43023ea0 'unsigned long long'`: &BuiltinType{ + Address: "0x7f8a43023ea0", + Type: "unsigned long long", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/c_style_cast_expr_test.go b/ast/c_style_cast_expr_test.go new file mode 100644 index 000000000..987e32236 --- /dev/null +++ b/ast/c_style_cast_expr_test.go @@ -0,0 +1,19 @@ +package ast + +import ( + "testing" +) + +func TestCStyleCastExpr(t *testing.T) { + nodes := map[string]Node{ + `0x7fddc18fb2e0 'char' `: &CStyleCastExpr{ + Address: "0x7fddc18fb2e0", + Position: "col:50, col:56", + Type: "char", + Kind: "IntegralCast", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/call_expr.go b/ast/call_expr.go index 0368af2fa..ec5706c78 100644 --- a/ast/call_expr.go +++ b/ast/call_expr.go @@ -29,10 +29,10 @@ func parseCallExpr(line string) *CallExpr { } } -func (n *CallExpr) render(program *program.Program) (string, string) { +func (n *CallExpr) render(p *program.Program) (string, string) { children := n.Children - functionName, _ := renderExpression(program, children[0]) - functionDef := getFunctionDefinition(functionName) + functionName, _ := renderExpression(p, children[0]) + functionDef := program.GetFunctionDefinition(functionName) if functionDef == nil { panic(fmt.Sprintf("unknown function: %s", functionName)) @@ -40,7 +40,7 @@ func (n *CallExpr) render(program *program.Program) (string, string) { if functionDef.Substitution != "" { parts := strings.Split(functionDef.Substitution, ".") - program.AddImport(strings.Join(parts[:len(parts)-1], ".")) + p.AddImport(strings.Join(parts[:len(parts)-1], ".")) parts2 := strings.Split(functionDef.Substitution, "/") functionName = parts2[len(parts2)-1] @@ -49,7 +49,7 @@ func (n *CallExpr) render(program *program.Program) (string, string) { args := []string{} i := 0 for _, arg := range children[1:] { - e, eType := renderExpression(program, arg) + e, eType := renderExpression(p, arg) if i > len(functionDef.ArgumentTypes)-1 { // This means the argument is one of the varargs @@ -57,7 +57,7 @@ func (n *CallExpr) render(program *program.Program) (string, string) { // cast to. args = append(args, e) } else { - args = append(args, types.Cast(program, e, eType, functionDef.ArgumentTypes[i])) + args = append(args, types.Cast(p, e, eType, functionDef.ArgumentTypes[i])) } i++ diff --git a/ast/call_expr_test.go b/ast/call_expr_test.go new file mode 100644 index 000000000..63a1a2008 --- /dev/null +++ b/ast/call_expr_test.go @@ -0,0 +1,24 @@ +package ast + +import ( + "testing" +) + +func TestCallExpr(t *testing.T) { + nodes := map[string]Node{ + `0x7f9bf3033240 'int'`: &CallExpr{ + Address: "0x7f9bf3033240", + Position: "col:11, col:25", + Type: "int", + Children: []Node{}, + }, + `0x7f9bf3035c20 'int'`: &CallExpr{ + Address: "0x7f9bf3035c20", + Position: "line:7:4, col:64", + Type: "int", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/case_stmt_test.go b/ast/case_stmt_test.go new file mode 100644 index 000000000..0aeb295f5 --- /dev/null +++ b/ast/case_stmt_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestCaseStmt(t *testing.T) { + nodes := map[string]Node{ + `0x7fc8b5094688 `: &CaseStmt{ + Address: "0x7fc8b5094688", + Position: "line:11:5, line:12:21", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/character_literal_test.go b/ast/character_literal_test.go new file mode 100644 index 000000000..08a96044f --- /dev/null +++ b/ast/character_literal_test.go @@ -0,0 +1,19 @@ +package ast + +import ( + "testing" +) + +func TestCharacterLiteral(t *testing.T) { + nodes := map[string]Node{ + `0x7f980b858308 'int' 10`: &CharacterLiteral{ + Address: "0x7f980b858308", + Position: "col:62", + Type: "int", + Value: 10, + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/compound_stmt_test.go b/ast/compound_stmt_test.go new file mode 100644 index 000000000..2eeb24afd --- /dev/null +++ b/ast/compound_stmt_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestCompoundStmt(t *testing.T) { + nodes := map[string]Node{ + `0x7fbd0f014f18 `: &CompoundStmt{ + Address: "0x7fbd0f014f18", + Position: "col:54, line:358:1", + Children: []Node{}, + }, + `0x7fbd0f8360b8 `: &CompoundStmt{ + Address: "0x7fbd0f8360b8", + Position: "line:4:1, line:13:1", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/conditional_operator_test.go b/ast/conditional_operator_test.go new file mode 100644 index 000000000..e74e7738f --- /dev/null +++ b/ast/conditional_operator_test.go @@ -0,0 +1,18 @@ +package ast + +import ( + "testing" +) + +func TestConditionalOperator(t *testing.T) { + nodes := map[string]Node{ + `0x7fc6ae0bc678 'void'`: &ConditionalOperator{ + Address: "0x7fc6ae0bc678", + Position: "col:6, col:89", + Type: "void", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/const_attr_test.go b/ast/const_attr_test.go new file mode 100644 index 000000000..ae0a984c7 --- /dev/null +++ b/ast/const_attr_test.go @@ -0,0 +1,18 @@ +package ast + +import ( + "testing" +) + +func TestConstAttr(t *testing.T) { + nodes := map[string]Node{ + `0x7fa3b88bbb38 foo`: &ConstAttr{ + Address: "0x7fa3b88bbb38", + Position: "line:4:1, line:13:1", + Tags: "foo", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/constant_array_type_test.go b/ast/constant_array_type_test.go new file mode 100644 index 000000000..aeee8b49d --- /dev/null +++ b/ast/constant_array_type_test.go @@ -0,0 +1,24 @@ +package ast + +import ( + "testing" +) + +func TestConstantArrayType(t *testing.T) { + nodes := map[string]Node{ + `0x7f94ad016a40 'struct __va_list_tag [1]' 1`: &ConstantArrayType{ + Address: "0x7f94ad016a40", + Type: "struct __va_list_tag [1]", + Size: 1, + Children: []Node{}, + }, + `0x7f8c5f059d20 'char [37]' 37`: &ConstantArrayType{ + Address: "0x7f8c5f059d20", + Type: "char [37]", + Size: 37, + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/decl_ref_expr_test.go b/ast/decl_ref_expr_test.go new file mode 100644 index 000000000..975ff0060 --- /dev/null +++ b/ast/decl_ref_expr_test.go @@ -0,0 +1,45 @@ +package ast + +import ( + "testing" +) + +func TestDeclRefExpr(t *testing.T) { + nodes := map[string]Node{ + `0x7fc972064460 'FILE *' lvalue ParmVar 0x7fc9720642d0 '_p' 'FILE *'`: &DeclRefExpr{ + Address: "0x7fc972064460", + Position: "col:8", + Type: "FILE *", + Lvalue: true, + For: "ParmVar", + Address2: "0x7fc9720642d0", + Name: "_p", + Type2: "FILE *", + Children: []Node{}, + }, + `0x7fc97206a958 'int (int, FILE *)' Function 0x7fc972064198 '__swbuf' 'int (int, FILE *)'`: &DeclRefExpr{ + Address: "0x7fc97206a958", + Position: "col:11", + Type: "int (int, FILE *)", + Lvalue: false, + For: "Function", + Address2: "0x7fc972064198", + Name: "__swbuf", + Type2: "int (int, FILE *)", + Children: []Node{}, + }, + `0x7fa36680f170 'struct programming':'struct programming' lvalue Var 0x7fa36680dc20 'variable' 'struct programming':'struct programming'`: &DeclRefExpr{ + Address: "0x7fa36680f170", + Position: "col:19", + Type: "struct programming", + Lvalue: true, + For: "Var", + Address2: "0x7fa36680dc20", + Name: "variable", + Type2: "struct programming", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/decl_stmt_test.go b/ast/decl_stmt_test.go new file mode 100644 index 000000000..91725888b --- /dev/null +++ b/ast/decl_stmt_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestDeclStmt(t *testing.T) { + nodes := map[string]Node{ + `0x7fb791846e80 `: &DeclStmt{ + Address: "0x7fb791846e80", + Position: "line:11:4, col:31", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/default_stmt_test.go b/ast/default_stmt_test.go new file mode 100644 index 000000000..28a8e2e44 --- /dev/null +++ b/ast/default_stmt_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestDefaultStmt(t *testing.T) { + nodes := map[string]Node{ + `0x7f951308bfb0 `: &DefaultStmt{ + Address: "0x7f951308bfb0", + Position: "line:17:5, line:18:34", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/deprecated_attr_test.go b/ast/deprecated_attr_test.go new file mode 100644 index 000000000..d1f4a0a9f --- /dev/null +++ b/ast/deprecated_attr_test.go @@ -0,0 +1,19 @@ +package ast + +import ( + "testing" +) + +func TestDeprecatedAttr(t *testing.T) { + nodes := map[string]Node{ + `0x7fec4b0ab9c0 "This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tempnam(3), it is highly recommended that you use mkstemp(3) instead." ""`: &DeprecatedAttr{ + Address: "0x7fec4b0ab9c0", + Position: "line:180:48, col:63", + Message1: "This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tempnam(3), it is highly recommended that you use mkstemp(3) instead.", + Message2: "", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/do_stmt_test.go b/ast/do_stmt_test.go new file mode 100644 index 000000000..6d5bb9eb5 --- /dev/null +++ b/ast/do_stmt_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestDoStmt(t *testing.T) { + nodes := map[string]Node{ + `0x7ff36d0a0938 `: &DoStmt{ + Address: "0x7ff36d0a0938", + Position: "line:11:5, line:14:23", + Children: []interface{}{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/elaborated_type_test.go b/ast/elaborated_type_test.go new file mode 100644 index 000000000..88ce071aa --- /dev/null +++ b/ast/elaborated_type_test.go @@ -0,0 +1,18 @@ +package ast + +import ( + "testing" +) + +func TestElaboratedType(t *testing.T) { + nodes := map[string]Node{ + `0x7f873686c120 'union __mbstate_t' sugar`: &ElaboratedType{ + Address: "0x7f873686c120", + Type: "union __mbstate_t", + Tags: "sugar", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/enum_constant_decl_test.go b/ast/enum_constant_decl_test.go new file mode 100644 index 000000000..e6d1ac81a --- /dev/null +++ b/ast/enum_constant_decl_test.go @@ -0,0 +1,20 @@ +package ast + +import ( + "testing" +) + +func TestEnumConstantDecl(t *testing.T) { + nodes := map[string]Node{ + `0x1660db0 __codecvt_noconv 'int'`: &EnumConstantDecl{ + Address: "0x1660db0", + Position: "line:185:3", + Position2: "", + Name: "__codecvt_noconv", + Type: "int", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/enum_decl_test.go b/ast/enum_decl_test.go new file mode 100644 index 000000000..d5faa25f2 --- /dev/null +++ b/ast/enum_decl_test.go @@ -0,0 +1,19 @@ +package ast + +import ( + "testing" +) + +func TestEnumDecl(t *testing.T) { + nodes := map[string]Node{ + `0x22a6c80 __codecvt_result`: &EnumDecl{ + Address: "0x22a6c80", + Position: "line:180:1, line:186:1", + Position2: "", + Name: "__codecvt_result", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/enum_test.go b/ast/enum_test.go new file mode 100644 index 000000000..a261ebfc2 --- /dev/null +++ b/ast/enum_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestEnum(t *testing.T) { + nodes := map[string]Node{ + `0x7f980b858308 'foo'`: &Enum{ + Address: "0x7f980b858308", + Name: "foo", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/enum_type_test.go b/ast/enum_type_test.go new file mode 100644 index 000000000..da7982dd2 --- /dev/null +++ b/ast/enum_type_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestEnumType(t *testing.T) { + nodes := map[string]Node{ + `0x7f980b858309 'foo'`: &EnumType{ + Address: "0x7f980b858309", + Name: "foo", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/field_decl_test.go b/ast/field_decl_test.go new file mode 100644 index 000000000..9893b5c0e --- /dev/null +++ b/ast/field_decl_test.go @@ -0,0 +1,84 @@ +package ast + +import ( + "testing" +) + +func TestFieldDecl(t *testing.T) { + nodes := map[string]Node{ + `0x7fef510c4848 col:6 _ur 'int'`: &FieldDecl{ + Address: "0x7fef510c4848", + Position: "line:141:2, col:6", + Position2: "col:6", + Name: "_ur", + Type: "int", + Referenced: false, + Children: []Node{}, + }, + `0x7fef510c46f8 col:16 _ub 'struct __sbuf':'struct __sbuf'`: &FieldDecl{ + Address: "0x7fef510c46f8", + Position: "line:139:2, col:16", + Position2: "col:16", + Name: "_ub", + Type: "struct __sbuf", + Referenced: false, + Children: []Node{}, + }, + `0x7fef510c3fe0 col:19 _read 'int (* _Nullable)(void *, char *, int)':'int (*)(void *, char *, int)'`: &FieldDecl{ + Address: "0x7fef510c3fe0", + Position: "line:134:2, col:19", + Position2: "col:19", + Name: "_read", + Type: "int (* _Nullable)(void *, char *, int)", + Referenced: false, + Children: []Node{}, + }, + `0x7fef51073a60 col:40 __cleanup_stack 'struct __darwin_pthread_handler_rec *'`: &FieldDecl{ + Address: "0x7fef51073a60", + Position: "line:105:2, col:40", + Position2: "col:40", + Name: "__cleanup_stack", + Type: "struct __darwin_pthread_handler_rec *", + Referenced: false, + Children: []Node{}, + }, + `0x7fef510738e8 col:7 __opaque 'char [16]'`: &FieldDecl{ + Address: "0x7fef510738e8", + Position: "line:100:2, col:43", + Position2: "col:7", + Name: "__opaque", + Type: "char [16]", + Referenced: false, + Children: []Node{}, + }, + `0x7fe9f5072268 col:6 referenced _lbfsize 'int'`: &FieldDecl{ + Address: "0x7fe9f5072268", + Position: "line:129:2, col:6", + Position2: "col:6", + Name: "_lbfsize", + Type: "int", + Referenced: true, + Children: []Node{}, + }, + `0x7f9bc9083d00 line:91:5 'unsigned short'`: &FieldDecl{ + Address: "0x7f9bc9083d00", + Position: "line:91:5, line:97:8", + Position2: "line:91:5", + Name: "", + Type: "unsigned short", + Referenced: false, + Children: []Node{}, + }, + `0x30363a0 __val 'int [2]'`: &FieldDecl{ + Address: "0x30363a0", + Position: "col:18, col:29", + Position2: "", + Name: "__val", + Type: "int [2]", + Referenced: false, + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/floating_literal_test.go b/ast/floating_literal_test.go new file mode 100644 index 000000000..3a7a25be7 --- /dev/null +++ b/ast/floating_literal_test.go @@ -0,0 +1,19 @@ +package ast + +import ( + "testing" +) + +func TestFloatingLiteral(t *testing.T) { + nodes := map[string]Node{ + `0x7febe106f5e8 'double' 1.230000e+00`: &FloatingLiteral{ + Address: "0x7febe106f5e8", + Position: "col:24", + Type: "double", + Value: 1.23, + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/for_stmt_test.go b/ast/for_stmt_test.go new file mode 100644 index 000000000..386d37055 --- /dev/null +++ b/ast/for_stmt_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestForStmt(t *testing.T) { + nodes := map[string]Node{ + `0x7f961e018848 `: &ForStmt{ + Address: "0x7f961e018848", + Position: "line:9:4, line:10:70", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/format_attr_test.go b/ast/format_attr_test.go new file mode 100644 index 000000000..8885efb94 --- /dev/null +++ b/ast/format_attr_test.go @@ -0,0 +1,42 @@ +package ast + +import ( + "testing" +) + +func TestFormatAttr(t *testing.T) { + nodes := map[string]Node{ + `0x7fcc8d8ecee8 Implicit printf 2 3`: &FormatAttr{ + Address: "0x7fcc8d8ecee8", + Position: "col:6", + Implicit: true, + Inherited: false, + FunctionName: "printf", + Unknown1: 2, + Unknown2: 3, + Children: []Node{}, + }, + `0x7fcc8d8ecff8 printf 2 3`: &FormatAttr{ + Address: "0x7fcc8d8ecff8", + Position: "/usr/include/sys/cdefs.h:351:18, col:61", + Implicit: false, + Inherited: false, + FunctionName: "printf", + Unknown1: 2, + Unknown2: 3, + Children: []Node{}, + }, + `0x273b4d0 Inherited printf 2 3`: &FormatAttr{ + Address: "0x273b4d0", + Position: "line:357:12", + Implicit: false, + Inherited: true, + FunctionName: "printf", + Unknown1: 2, + Unknown2: 3, + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/function_decl.go b/ast/function_decl.go index 9b318cbe7..a1780f017 100644 --- a/ast/function_decl.go +++ b/ast/function_decl.go @@ -54,14 +54,14 @@ func parseFunctionDecl(line string) *FunctionDecl { } } -func (n *FunctionDecl) render(program *program.Program) (string, string) { +func (n *FunctionDecl) render(p *program.Program) (string, string) { out := bytes.NewBuffer([]byte{}) - program.FunctionName = n.Name + p.FunctionName = n.Name // Always register the new function. Only from this point onwards will // we be allowed to refer to the function. - if getFunctionDefinition(program.FunctionName) == nil { - addFunctionDefinition(FunctionDefinition{ + if program.GetFunctionDefinition(p.FunctionName) == nil { + program.AddFunctionDefinition(program.FunctionDefinition{ Name: n.Name, ReturnType: getFunctionReturnType(n.Type), // FIXME @@ -72,18 +72,18 @@ func (n *FunctionDecl) render(program *program.Program) (string, string) { // If the function has a direct substitute in Go we do not want to // output the C definition of it. - if f := getFunctionDefinition(program.FunctionName); f != nil && + if f := program.GetFunctionDefinition(p.FunctionName); f != nil && f.Substitution != "" { return "", "" } - if program.FunctionName == "__istype" || - program.FunctionName == "__isctype" || - program.FunctionName == "__wcwidth" || - program.FunctionName == "__sputc" || - program.FunctionName == "__inline_signbitf" || - program.FunctionName == "__inline_signbitd" || - program.FunctionName == "__inline_signbitl" { + if p.FunctionName == "__istype" || + p.FunctionName == "__isctype" || + p.FunctionName == "__wcwidth" || + p.FunctionName == "__sputc" || + p.FunctionName == "__inline_signbitf" || + p.FunctionName == "__inline_signbitd" || + p.FunctionName == "__inline_signbitl" { return "", "" } @@ -98,35 +98,35 @@ func (n *FunctionDecl) render(program *program.Program) (string, string) { args := []string{} for _, a := range getFunctionParams(n) { - args = append(args, fmt.Sprintf("%s %s", a.Name, types.ResolveType(program, a.Type))) + args = append(args, fmt.Sprintf("%s %s", a.Name, types.ResolveType(p, a.Type))) } if hasBody { returnType := getFunctionReturnType(n.Type) - if program.FunctionName == "main" { - printLine(out, "func main() {", program.Indent) + if p.FunctionName == "main" { + printLine(out, "func main() {", p.Indent) } else { printLine(out, fmt.Sprintf("func %s(%s) %s {", - program.FunctionName, strings.Join(args, ", "), - types.ResolveType(program, returnType)), program.Indent) + p.FunctionName, strings.Join(args, ", "), + types.ResolveType(p, returnType)), p.Indent) } for _, c := range n.Children { if _, ok := c.(*CompoundStmt); ok { - src, _ := renderExpression(program, c) - printLine(out, src, program.Indent+1) + src, _ := renderExpression(p, c) + printLine(out, src, p.Indent+1) } } - printLine(out, "}\n", program.Indent) + printLine(out, "}\n", p.Indent) params := []string{} for _, v := range getFunctionParams(n) { params = append(params, v.Type) } - addFunctionDefinition(FunctionDefinition{ + program.AddFunctionDefinition(program.FunctionDefinition{ Name: n.Name, ReturnType: getFunctionReturnType(n.Type), ArgumentTypes: params, diff --git a/ast/function_decl_test.go b/ast/function_decl_test.go new file mode 100644 index 000000000..c02c26241 --- /dev/null +++ b/ast/function_decl_test.go @@ -0,0 +1,84 @@ +package ast + +import ( + "testing" +) + +func TestFunctionDecl(t *testing.T) { + nodes := map[string]Node{ + `0x7fb5a90e60d0 col:7 clearerr 'void (FILE *)'`: &FunctionDecl{ + Address: "0x7fb5a90e60d0", + Position: "line:231:1, col:22", + Prev: "", + Position2: "col:7", + Name: "clearerr", + Type: "void (FILE *)", + IsExtern: false, + IsImplicit: false, + IsUsed: false, + Children: []Node{}, + }, + `0x7fb5a90e2a50 /usr/include/sys/stdio.h:39:5 renameat 'int (int, const char *, int, const char *)'`: &FunctionDecl{ + Address: "0x7fb5a90e2a50", + Position: "/usr/include/sys/stdio.h:39:1, /usr/include/AvailabilityInternal.h:21697:126", + Prev: "", + Position2: "/usr/include/sys/stdio.h:39:5", + Name: "renameat", + Type: "int (int, const char *, int, const char *)", + IsExtern: false, + IsImplicit: false, + IsUsed: false, + Children: []Node{}, + }, + `0x7fb5a90e9b70 col:6 implicit fprintf 'int (FILE *, const char *, ...)' extern`: &FunctionDecl{ + Address: "0x7fb5a90e9b70", + Position: "/usr/include/stdio.h:244:6", + Prev: "", + Position2: "col:6", + Name: "fprintf", + Type: "int (FILE *, const char *, ...)", + IsExtern: true, + IsImplicit: true, + IsUsed: false, + Children: []Node{}, + }, + `0x7fb5a90e9d40 prev 0x7fb5a90e9b70 /usr/include/stdio.h:244:6 fprintf 'int (FILE *, const char *, ...)'`: &FunctionDecl{ + Address: "0x7fb5a90e9d40", + Position: "col:1, /usr/include/sys/cdefs.h:351:63", + Prev: "0x7fb5a90e9b70", + Position2: "/usr/include/stdio.h:244:6", + Name: "fprintf", + Type: "int (FILE *, const char *, ...)", + IsExtern: false, + IsImplicit: false, + IsUsed: false, + Children: []Node{}, + }, + `0x7fb5a90ec210 col:6 implicit used printf 'int (const char *, ...)' extern`: &FunctionDecl{ + Address: "0x7fb5a90ec210", + Position: "line:259:6", + Prev: "", + Position2: "col:6", + Name: "printf", + Type: "int (const char *, ...)", + IsExtern: true, + IsImplicit: true, + IsUsed: true, + Children: []Node{}, + }, + `0x2ae30d8 :17:1 __acos 'double (double)' extern`: &FunctionDecl{ + Address: "0x2ae30d8", + Position: "/usr/include/math.h:65:3, /usr/include/x86_64-linux-gnu/sys/cdefs.h:57:54", + Prev: "", + Position2: ":17:1", + Name: "__acos", + Type: "double (double)", + IsExtern: true, + IsImplicit: false, + IsUsed: false, + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/function_proto_type_test.go b/ast/function_proto_type_test.go new file mode 100644 index 000000000..c3002bd1f --- /dev/null +++ b/ast/function_proto_type_test.go @@ -0,0 +1,18 @@ +package ast + +import ( + "testing" +) + +func TestFunctionProtoType(t *testing.T) { + nodes := map[string]Node{ + `0x7fa3b88bbb30 'struct _opaque_pthread_t *' foo`: &FunctionProtoType{ + Address: "0x7fa3b88bbb30", + Type: "struct _opaque_pthread_t *", + Kind: "foo", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/if_stmt_test.go b/ast/if_stmt_test.go new file mode 100644 index 000000000..47fc512bc --- /dev/null +++ b/ast/if_stmt_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestIfStmt(t *testing.T) { + nodes := map[string]Node{ + `0x7fc0a69091d0 `: &IfStmt{ + Address: "0x7fc0a69091d0", + Position: "line:11:7, line:18:7", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/implicit_cast_expr_test.go b/ast/implicit_cast_expr_test.go new file mode 100644 index 000000000..3b98545f0 --- /dev/null +++ b/ast/implicit_cast_expr_test.go @@ -0,0 +1,26 @@ +package ast + +import ( + "testing" +) + +func TestImplicitCastExpr(t *testing.T) { + nodes := map[string]Node{ + `0x7f9f5b0a1288 'FILE *' `: &ImplicitCastExpr{ + Address: "0x7f9f5b0a1288", + Position: "col:8", + Type: "FILE *", + Kind: "LValueToRValue", + Children: []Node{}, + }, + `0x7f9f5b0a7828 'int (*)(int, FILE *)' `: &ImplicitCastExpr{ + Address: "0x7f9f5b0a7828", + Position: "col:11", + Type: "int (*)(int, FILE *)", + Kind: "FunctionToPointerDecay", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/integer_literal_test.go b/ast/integer_literal_test.go new file mode 100644 index 000000000..9e5c600f8 --- /dev/null +++ b/ast/integer_literal_test.go @@ -0,0 +1,19 @@ +package ast + +import ( + "testing" +) + +func TestIntegerLiteral(t *testing.T) { + nodes := map[string]Node{ + `0x7fbe9804bcc8 'int' 1`: &IntegerLiteral{ + Address: "0x7fbe9804bcc8", + Position: "col:14", + Type: "int", + Value: 1, + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/malloc_attr_test.go b/ast/malloc_attr_test.go new file mode 100644 index 000000000..7d756afdc --- /dev/null +++ b/ast/malloc_attr_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestMallocAttr(t *testing.T) { + nodes := map[string]Node{ + `0x7fc0a69091d1 `: &MallocAttr{ + Address: "0x7fc0a69091d1", + Position: "line:11:7, line:18:7", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/member_expr_test.go b/ast/member_expr_test.go new file mode 100644 index 000000000..702c50242 --- /dev/null +++ b/ast/member_expr_test.go @@ -0,0 +1,48 @@ +package ast + +import ( + "testing" +) + +func TestMemberExpr(t *testing.T) { + nodes := map[string]Node{ + `0x7fcc758e34a0 'int' lvalue ->_w 0x7fcc758d60c8`: &MemberExpr{ + Address: "0x7fcc758e34a0", + Position: "col:8, col:12", + Type: "int", + Lvalue: true, + Name: "_w", + Address2: "0x7fcc758d60c8", + Children: []Node{}, + }, + `0x7fcc76004210 'unsigned char *' lvalue ->_p 0x7fcc758d6018`: &MemberExpr{ + Address: "0x7fcc76004210", + Position: "col:12, col:16", + Type: "unsigned char *", + Lvalue: true, + Name: "_p", + Address2: "0x7fcc758d6018", + Children: []Node{}, + }, + `0x7f85338325b0 'float' lvalue .constant 0x7f8533832260`: &MemberExpr{ + Address: "0x7f85338325b0", + Position: "col:4, col:13", + Type: "float", + Lvalue: true, + Name: "constant", + Address2: "0x7f8533832260", + Children: []Node{}, + }, + `0x7f8533832670 'char *' lvalue .pointer 0x7f85338322b8`: &MemberExpr{ + Address: "0x7f8533832670", + Position: "col:4, col:13", + Type: "char *", + Lvalue: true, + Name: "pointer", + Address2: "0x7f85338322b8", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/mode_attr_test.go b/ast/mode_attr_test.go new file mode 100644 index 000000000..77896fa7c --- /dev/null +++ b/ast/mode_attr_test.go @@ -0,0 +1,18 @@ +package ast + +import ( + "testing" +) + +func Test(t *testing.T) { + nodes := map[string]Node{ + `0x7f980b858309 foo`: &ModeAttr{ + Address: "0x7f980b858309", + Position: "line:11:7, line:18:7", + Name: "foo", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/no_throw_attr_test.go b/ast/no_throw_attr_test.go new file mode 100644 index 000000000..7d15d413f --- /dev/null +++ b/ast/no_throw_attr_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestNoThrowAttr(t *testing.T) { + nodes := map[string]Node{ + `0x7fa1488273a0 `: &NoThrowAttr{ + Address: "0x7fa1488273a0", + Position: "line:7:4, line:11:4", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/non_null_attr_test.go b/ast/non_null_attr_test.go new file mode 100644 index 000000000..e7949ec54 --- /dev/null +++ b/ast/non_null_attr_test.go @@ -0,0 +1,40 @@ +package ast + +import ( + "testing" +) + +func TestNonNullAttr(t *testing.T) { + nodes := map[string]Node{ + `0x7fa1488273b0 1`: &NonNullAttr{ + Address: "0x7fa1488273b0", + Position: "line:7:4, line:11:4", + A: 1, + B: 0, + Children: []Node{}, + }, + `0x2cce280 1`: &NonNullAttr{ + Address: "0x2cce280", + Position: "/sys/cdefs.h:286:44, /bits/mathcalls.h:115:69", + A: 1, + B: 0, + Children: []Node{}, + }, + `0x201ede0 0`: &NonNullAttr{ + Address: "0x201ede0", + Position: "line:145:79, col:93", + A: 0, + B: 0, + Children: []Node{}, + }, + `0x1b89b20 2 3`: &NonNullAttr{ + Address: "0x1b89b20", + Position: "col:76, col:93", + A: 2, + B: 3, + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/paren_expr_test.go b/ast/paren_expr_test.go new file mode 100644 index 000000000..7921bcdf3 --- /dev/null +++ b/ast/paren_expr_test.go @@ -0,0 +1,18 @@ +package ast + +import ( + "testing" +) + +func TestParenExpr(t *testing.T) { + nodes := map[string]Node{ + `0x7fb0bc8b2308 'unsigned char'`: &ParenExpr{ + Address: "0x7fb0bc8b2308", + Position: "col:10, col:25", + Type: "unsigned char", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/paren_type_test.go b/ast/paren_type_test.go new file mode 100644 index 000000000..c694dbeab --- /dev/null +++ b/ast/paren_type_test.go @@ -0,0 +1,18 @@ +package ast + +import ( + "testing" +) + +func TestParenType(t *testing.T) { + nodes := map[string]Node{ + `0x7faf820a4c60 'void (int)' sugar`: &ParenType{ + Address: "0x7faf820a4c60", + Type: "void (int)", + Sugar: true, + Children: []interface{}{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/parm_var_decl_test.go b/ast/parm_var_decl_test.go new file mode 100644 index 000000000..0a53fef73 --- /dev/null +++ b/ast/parm_var_decl_test.go @@ -0,0 +1,82 @@ +package ast + +import ( + "testing" +) + +func TestParmVarDecl(t *testing.T) { + nodes := map[string]Node{ + `0x7f973380f000 col:17 'int'`: &ParmVarDecl{ + Address: "0x7f973380f000", + Position: "col:14", + Position2: "col:17", + Type: "int", + Name: "", + Type2: "", + IsUsed: false, + Children: []Node{}, + }, + `0x7f973380f070 col:31 'const char *'`: &ParmVarDecl{ + Address: "0x7f973380f070", + Position: "col:19, col:30", + Position2: "col:31", + Type: "const char *", + Name: "", + Type2: "", + IsUsed: false, + Children: []Node{}, + }, + `0x7f9733816e50 col:37 __filename 'const char *__restrict'`: &ParmVarDecl{ + Address: "0x7f9733816e50", + Position: "col:13, col:37", + Position2: "col:37", + Type: "const char *__restrict", + Name: "__filename", + Type2: "", + IsUsed: false, + Children: []Node{}, + }, + `0x7f9733817418 <> 'FILE *'`: &ParmVarDecl{ + Address: "0x7f9733817418", + Position: "", + Position2: "", + Type: "FILE *", + Name: "", + Type2: "", + IsUsed: false, + Children: []Node{}, + }, + `0x7f9733817c30 col:47 __size 'size_t':'unsigned long'`: &ParmVarDecl{ + Address: "0x7f9733817c30", + Position: "col:40, col:47", + Position2: "col:47", + Type: "size_t", + Name: "__size", + Type2: "unsigned long", + IsUsed: false, + Children: []Node{}, + }, + `0x7f973382fa10 col:34 'int (* _Nullable)(void *, char *, int)':'int (*)(void *, char *, int)'`: &ParmVarDecl{ + Address: "0x7f973382fa10", + Position: "line:476:18, col:25", + Position2: "col:34", + Type: "int (* _Nullable)(void *, char *, int)", + Name: "", + Type2: "int (*)(void *, char *, int)", + IsUsed: false, + Children: []Node{}, + }, + `0x7f97338355b8 col:14 used argc 'int'`: &ParmVarDecl{ + Address: "0x7f97338355b8", + Position: "col:10, col:14", + Position2: "col:14", + Type: "int", + Name: "argc", + Type2: "", + IsUsed: true, + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/pointer_type_test.go b/ast/pointer_type_test.go new file mode 100644 index 000000000..a3a7295ca --- /dev/null +++ b/ast/pointer_type_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestPointerType(t *testing.T) { + nodes := map[string]Node{ + `0x7fa3b88bbb30 'struct _opaque_pthread_t *'`: &PointerType{ + Address: "0x7fa3b88bbb30", + Type: "struct _opaque_pthread_t *", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/predefined_expr_test.go b/ast/predefined_expr_test.go new file mode 100644 index 000000000..6651b30af --- /dev/null +++ b/ast/predefined_expr_test.go @@ -0,0 +1,20 @@ +package ast + +import ( + "testing" +) + +func TestPredefinedExpr(t *testing.T) { + nodes := map[string]Node{ + `0x33d6e08 'const char [25]' lvalue __PRETTY_FUNCTION__`: &PredefinedExpr{ + Address: "0x33d6e08", + Position: "col:30", + Type: "const char [25]", + Lvalue: true, + Name: "__PRETTY_FUNCTION__", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/pure_attr_test.go b/ast/pure_attr_test.go new file mode 100644 index 000000000..3bce63928 --- /dev/null +++ b/ast/pure_attr_test.go @@ -0,0 +1,26 @@ +package ast + +import ( + "testing" +) + +func TestPureAttr(t *testing.T) { + nodes := map[string]Node{ + `0x7fe9eb899198 Implicit`: &PureAttr{ + Address: "0x7fe9eb899198", + Position: "col:1", + Implicit: true, + Inherited: false, + Children: []interface{}{}, + }, + `0x7fe8d60992a0 Inherited Implicit`: &PureAttr{ + Address: "0x7fe8d60992a0", + Position: "col:1", + Implicit: true, + Inherited: true, + Children: []interface{}{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/qual_type_test.go b/ast/qual_type_test.go new file mode 100644 index 000000000..1425d6a08 --- /dev/null +++ b/ast/qual_type_test.go @@ -0,0 +1,18 @@ +package ast + +import ( + "testing" +) + +func TestQualType(t *testing.T) { + nodes := map[string]Node{ + `0x7fa3b88bbb31 'struct _opaque_pthread_t *' foo`: &QualType{ + Address: "0x7fa3b88bbb31", + Type: "struct _opaque_pthread_t *", + Kind: "foo", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/record_decl_test.go b/ast/record_decl_test.go new file mode 100644 index 000000000..3821d159f --- /dev/null +++ b/ast/record_decl_test.go @@ -0,0 +1,42 @@ +package ast + +import ( + "testing" +) + +func TestRecordDecl(t *testing.T) { + nodes := map[string]Node{ + `0x7f913c0dbb50 line:76:9 union definition`: &RecordDecl{ + Address: "0x7f913c0dbb50", + Position: "line:76:9, line:79:1", + Prev: "", + Position2: "line:76:9", + Kind: "union", + Name: "", + Definition: true, + Children: []Node{}, + }, + `0x7f85360285c8 line:57:8 struct __darwin_pthread_handler_rec definition`: &RecordDecl{ + Address: "0x7f85360285c8", + Position: "/usr/include/sys/_pthread/_pthread_types.h:57:1, line:61:1", + Prev: "", + Position2: "line:57:8", + Kind: "struct", + Name: "__darwin_pthread_handler_rec", + Definition: true, + Children: []Node{}, + }, + `0x7f85370248a0 col:8 struct __sFILEX`: &RecordDecl{ + Address: "0x7f85370248a0", + Position: "line:94:1, col:8", + Prev: "", + Position2: "col:8", + Kind: "struct", + Name: "__sFILEX", + Definition: false, + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/record_test.go b/ast/record_test.go new file mode 100644 index 000000000..16ff1672a --- /dev/null +++ b/ast/record_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestRecord(t *testing.T) { + nodes := map[string]Node{ + `0x7fd3ab857950 '__sFILE'`: &Record{ + Address: "0x7fd3ab857950", + Type: "__sFILE", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/record_type_test.go b/ast/record_type_test.go new file mode 100644 index 000000000..58806c36c --- /dev/null +++ b/ast/record_type_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestRecordType(t *testing.T) { + nodes := map[string]Node{ + `0x7fd3ab84dda0 'struct _opaque_pthread_condattr_t'`: &RecordType{ + Address: "0x7fd3ab84dda0", + Type: "struct _opaque_pthread_condattr_t", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/restrict_attr_test.go b/ast/restrict_attr_test.go new file mode 100644 index 000000000..8bc5387b6 --- /dev/null +++ b/ast/restrict_attr_test.go @@ -0,0 +1,18 @@ +package ast + +import ( + "testing" +) + +func TestRestrictAttr(t *testing.T) { + nodes := map[string]Node{ + `0x7f980b858305 foo`: &RestrictAttr{ + Address: "0x7f980b858305", + Position: "line:11:7, line:18:7", + Name: "foo", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/return_stmt.go b/ast/return_stmt.go index b939fb229..932b2576c 100644 --- a/ast/return_stmt.go +++ b/ast/return_stmt.go @@ -26,17 +26,17 @@ func parseReturnStmt(line string) *ReturnStmt { } } -func (n *ReturnStmt) render(program *program.Program) (string, string) { +func (n *ReturnStmt) render(p *program.Program) (string, string) { out := bytes.NewBuffer([]byte{}) r := "return" - if len(n.Children) > 0 && program.FunctionName != "main" { - re, reType := renderExpression(program, n.Children[0]) - funcDef := getFunctionDefinition(program.FunctionName) - r = "return " + types.Cast(program, re, reType, funcDef.ReturnType) + if len(n.Children) > 0 && p.FunctionName != "main" { + re, reType := renderExpression(p, n.Children[0]) + funcDef := program.GetFunctionDefinition(p.FunctionName) + r = "return " + types.Cast(p, re, reType, funcDef.ReturnType) } - printLine(out, r, program.Indent) + printLine(out, r, p.Indent) return out.String(), "" } diff --git a/ast/return_stmt_test.go b/ast/return_stmt_test.go new file mode 100644 index 000000000..b3c03e13b --- /dev/null +++ b/ast/return_stmt_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestReturnStmt(t *testing.T) { + nodes := map[string]Node{ + `0x7fbb7a8325e0 `: &ReturnStmt{ + Address: "0x7fbb7a8325e0", + Position: "line:13:4, col:11", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/string_literal_test.go b/ast/string_literal_test.go new file mode 100644 index 000000000..98ee4b33a --- /dev/null +++ b/ast/string_literal_test.go @@ -0,0 +1,20 @@ +package ast + +import ( + "testing" +) + +func TestStringLiteral(t *testing.T) { + nodes := map[string]Node{ + `0x7fe16f0b4d58 'char [45]' lvalue "Number of command line arguments passed: %d\n"`: &StringLiteral{ + Address: "0x7fe16f0b4d58", + Position: "col:11", + Type: "char [45]", + Lvalue: true, + Value: "Number of command line arguments passed: %d\n", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/switch_stmt.go b/ast/switch_stmt.go index 6338dac43..b0c605564 100644 --- a/ast/switch_stmt.go +++ b/ast/switch_stmt.go @@ -24,18 +24,18 @@ func parseSwitchStmt(line string) *SwitchStmt { func (n *SwitchStmt) render(program *program.Program) (string, string) { // The first two children are nil. I don't know what they are supposed to be - // for. Raise an error so we can work it out. - if n.Children[0] != nil { - panic(fmt.Sprintf("SwitchStmt 0: %#v", n.Children[0])) - } - if n.Children[1] != nil { - panic(fmt.Sprintf("SwitchStmt 1: %#v", n.Children[1])) + // for. It looks like the number of children is also not reliable, but we + // know that we need the last two. + + if len(n.Children) < 2 { + // I don't know what causes this condition. Need to investigate. + return "", "" } - condition, _ := n.Children[2].render(program) + condition, _ := n.Children[len(n.Children)-2].render(program) - n.Children[3].(*CompoundStmt).belongsToSwitch = true - body, _ := n.Children[3].render(program) + n.Children[len(n.Children)-1].(*CompoundStmt).belongsToSwitch = true + body, _ := n.Children[len(n.Children)-1].render(program) out := fmt.Sprintf("switch %s {\n%s\n}\n", condition, body) diff --git a/ast/switch_stmt_test.go b/ast/switch_stmt_test.go new file mode 100644 index 000000000..dcc4b85f7 --- /dev/null +++ b/ast/switch_stmt_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestSwitchStmt(t *testing.T) { + nodes := map[string]Node{ + `0x7fbca3894638 `: &SwitchStmt{ + Address: "0x7fbca3894638", + Position: "line:9:5, line:20:5", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/translation_unit_decl_test.go b/ast/translation_unit_decl_test.go new file mode 100644 index 000000000..9eddad189 --- /dev/null +++ b/ast/translation_unit_decl_test.go @@ -0,0 +1,16 @@ +package ast + +import ( + "testing" +) + +func TestTranslationUnitDecl(t *testing.T) { + nodes := map[string]Node{ + `0x7fe78a815ed0 <> `: &TranslationUnitDecl{ + Address: "0x7fe78a815ed0", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/transparent_union_attr_test.go b/ast/transparent_union_attr_test.go new file mode 100644 index 000000000..9c36c7bd9 --- /dev/null +++ b/ast/transparent_union_attr_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestTransparentUnionAttr(t *testing.T) { + nodes := map[string]Node{ + `0x304f700 `: &TransparentUnionAttr{ + Address: "0x304f700", + Position: "col:35", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/typedef_decl_test.go b/ast/typedef_decl_test.go new file mode 100644 index 000000000..e5add7254 --- /dev/null +++ b/ast/typedef_decl_test.go @@ -0,0 +1,89 @@ +package ast + +import ( + "testing" +) + +func TestTypedefDecl(t *testing.T) { + nodes := map[string]Node{ + `0x7fdef0862430 col:16`: &TypedefDecl{ + Address: "0x7fdef0862430", + Position: "line:120:1, col:16", + Position2: "col:16", + Name: "", + Type: "", + Type2: "", + IsImplicit: false, + IsReferenced: false, + Children: []Node{}, + }, + `0x7ffb9f824278 <> implicit __uint128_t 'unsigned __int128'`: &TypedefDecl{ + Address: "0x7ffb9f824278", + Position: "", + Position2: "", + Name: "__uint128_t", + Type: "unsigned __int128", + Type2: "", + IsImplicit: true, + IsReferenced: false, + Children: []Node{}, + }, + `0x7ffb9f824898 <> implicit referenced __builtin_va_list 'struct __va_list_tag [1]'`: &TypedefDecl{ + Address: "0x7ffb9f824898", + Position: "", + Position2: "", + Name: "__builtin_va_list", + Type: "struct __va_list_tag [1]", + Type2: "", + IsImplicit: true, + IsReferenced: true, + Children: []Node{}, + }, + `0x7ffb9f8248f8 col:24 __int8_t 'signed char'`: &TypedefDecl{ + Address: "0x7ffb9f8248f8", + Position: "/usr/include/i386/_types.h:37:1, col:24", + Position2: "col:24", + Name: "__int8_t", + Type: "signed char", + Type2: "", + IsImplicit: false, + IsReferenced: false, + Children: []Node{}, + }, + `0x7ffb9f8dbf50 col:27 referenced __darwin_va_list '__builtin_va_list':'struct __va_list_tag [1]'`: &TypedefDecl{ + Address: "0x7ffb9f8dbf50", + Position: "line:98:1, col:27", + Position2: "col:27", + Name: "__darwin_va_list", + Type: "__builtin_va_list", + Type2: "struct __va_list_tag [1]", + IsImplicit: false, + IsReferenced: true, + Children: []Node{}, + }, + `0x34461f0 __io_read_fn '__ssize_t (void *, char *, size_t)'`: &TypedefDecl{ + Address: "0x34461f0", + Position: "line:338:1, col:77", + Position2: "", + Name: "__io_read_fn", + Type: "__ssize_t (void *, char *, size_t)", + Type2: "", + IsImplicit: false, + IsReferenced: false, + Children: []Node{}, + }, + `0x55b9da8784b0 line:341:19 __io_write_fn '__ssize_t (void *, const char *, size_t)'`: &TypedefDecl{ + Address: "0x55b9da8784b0", + Position: "line:341:1, line:342:16", + Position2: "line:341:19", + Name: "__io_write_fn", + Type: "__ssize_t (void *, const char *, size_t)", + Type2: "", + IsImplicit: false, + IsReferenced: false, + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/typedef_test.go b/ast/typedef_test.go new file mode 100644 index 000000000..c097fe051 --- /dev/null +++ b/ast/typedef_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestTypedef(t *testing.T) { + nodes := map[string]Node{ + `0x7f84d10dc1d0 '__darwin_ssize_t'`: &Typedef{ + Address: "0x7f84d10dc1d0", + Type: "__darwin_ssize_t", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/typedef_type_test.go b/ast/typedef_type_test.go new file mode 100644 index 000000000..c2166aa2e --- /dev/null +++ b/ast/typedef_type_test.go @@ -0,0 +1,18 @@ +package ast + +import ( + "testing" +) + +func TestTypedefType(t *testing.T) { + nodes := map[string]Node{ + `0x7f887a0dc760 '__uint16_t' sugar`: &TypedefType{ + Address: "0x7f887a0dc760", + Type: "__uint16_t", + Tags: "sugar", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/unary_operator_test.go b/ast/unary_operator_test.go new file mode 100644 index 000000000..7a5519ad4 --- /dev/null +++ b/ast/unary_operator_test.go @@ -0,0 +1,39 @@ +package ast + +import ( + "testing" +) + +func TestUnaryOperator(t *testing.T) { + nodes := map[string]Node{ + `0x7fe0260f50d8 'int' prefix '--'`: &UnaryOperator{ + Address: "0x7fe0260f50d8", + Position: "col:6, col:12", + Type: "int", + IsLvalue: false, + IsPrefix: true, + Operator: "--", + Children: []Node{}, + }, + `0x7fe0260fb468 'unsigned char' lvalue prefix '*'`: &UnaryOperator{ + Address: "0x7fe0260fb468", + Position: "col:11, col:18", + Type: "unsigned char", + IsLvalue: true, + IsPrefix: true, + Operator: "*", + Children: []Node{}, + }, + `0x7fe0260fb448 'unsigned char *' postfix '++'`: &UnaryOperator{ + Address: "0x7fe0260fb448", + Position: "col:12, col:18", + Type: "unsigned char *", + IsLvalue: false, + IsPrefix: false, + Operator: "++", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/var_decl_test.go b/ast/var_decl_test.go new file mode 100644 index 000000000..8d21e6000 --- /dev/null +++ b/ast/var_decl_test.go @@ -0,0 +1,72 @@ +package ast + +import ( + "testing" +) + +func TestVarDecl(t *testing.T) { + nodes := map[string]Node{ + `0x7fd5e90e5a00 col:17 'int'`: &VarDecl{ + Address: "0x7fd5e90e5a00", + Position: "col:14", + Position2: "col:17", + Name: "", + Type: "int", + Type2: "", + IsExtern: false, + IsUsed: false, + IsCInit: false, + Children: []Node{}, + }, + `0x7fd5e90e9078 col:14 __stdinp 'FILE *' extern`: &VarDecl{ + Address: "0x7fd5e90e9078", + Position: "line:156:1, col:14", + Position2: "col:14", + Name: "__stdinp", + Type: "FILE *", + Type2: "", + IsExtern: true, + IsUsed: false, + IsCInit: false, + Children: []Node{}, + }, + `0x7fd5e90ed630 col:47 __size 'size_t':'unsigned long'`: &VarDecl{ + Address: "0x7fd5e90ed630", + Position: "col:40, col:47", + Position2: "col:47", + Name: "__size", + Type: "size_t", + Type2: "unsigned long", + IsExtern: false, + IsUsed: false, + IsCInit: false, + Children: []Node{}, + }, + `0x7fee35907a78 col:8 used c 'int'`: &VarDecl{ + Address: "0x7fee35907a78", + Position: "col:4, col:8", + Position2: "col:8", + Name: "c", + Type: "int", + Type2: "", + IsExtern: false, + IsUsed: true, + IsCInit: false, + Children: []Node{}, + }, + `0x7fb0fd90ba30 tests/assert/assert.c:13:9 used b 'int *' cinit`: &VarDecl{ + Address: "0x7fb0fd90ba30", + Position: "col:3, /usr/include/sys/_types.h:52:33", + Position2: "tests/assert/assert.c:13:9", + Name: "b", + Type: "int *", + Type2: "", + IsExtern: false, + IsUsed: true, + IsCInit: true, + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/warn_unused_result_attr_test.go b/ast/warn_unused_result_attr_test.go new file mode 100644 index 000000000..707476f4e --- /dev/null +++ b/ast/warn_unused_result_attr_test.go @@ -0,0 +1,22 @@ +package ast + +import ( + "testing" +) + +func TestWarnUnusedResultAttr(t *testing.T) { + nodes := map[string]Node{ + `0x7fa1d704d420 warn_unused_result`: &WarnUnusedResultAttr{ + Address: "0x7fa1d704d420", + Position: "col:60", + Children: []interface{}{}, + }, + `0x1fac810 `: &WarnUnusedResultAttr{ + Address: "0x1fac810", + Position: "line:481:52", + Children: []interface{}{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/while_stmt_test.go b/ast/while_stmt_test.go new file mode 100644 index 000000000..7f07bf843 --- /dev/null +++ b/ast/while_stmt_test.go @@ -0,0 +1,17 @@ +package ast + +import ( + "testing" +) + +func TestWhileStmt(t *testing.T) { + nodes := map[string]Node{ + `0x7fa1478273a0 `: &WhileStmt{ + Address: "0x7fa1478273a0", + Position: "line:7:4, line:11:4", + Children: []Node{}, + }, + } + + runNodeTests(t, nodes) +} diff --git a/ast/function_definition.go b/program/function_definition.go similarity index 96% rename from ast/function_definition.go rename to program/function_definition.go index c54fadb32..a0cadd883 100644 --- a/ast/function_definition.go +++ b/program/function_definition.go @@ -1,4 +1,4 @@ -package ast +package program import ( "regexp" @@ -112,7 +112,7 @@ var builtInFunctionDefinitions = []string{ // getFunctionDefinition will return nil if the function does not exist (is not // registered). -func getFunctionDefinition(functionName string) *FunctionDefinition { +func GetFunctionDefinition(functionName string) *FunctionDefinition { loadFunctionDefinitions() if f, ok := functionDefinitions[functionName]; ok { @@ -124,7 +124,7 @@ func getFunctionDefinition(functionName string) *FunctionDefinition { // addFunctionDefinition registers a function definition. If the definition // already exists it will be replaced. -func addFunctionDefinition(f FunctionDefinition) { +func AddFunctionDefinition(f FunctionDefinition) { loadFunctionDefinitions() functionDefinitions[f.Name] = f @@ -162,7 +162,7 @@ func loadFunctionDefinitions() { substitution = "github.com/elliotchance/c2go/" + substitution } - addFunctionDefinition(FunctionDefinition{ + AddFunctionDefinition(FunctionDefinition{ Name: match[2], ReturnType: match[1], ArgumentTypes: argumentTypes, diff --git a/tests/stdbool/stdbool.c b/tests/stdbool.c similarity index 100% rename from tests/stdbool/stdbool.c rename to tests/stdbool.c diff --git a/tests/misc/switch.c b/tests/switch.c similarity index 100% rename from tests/misc/switch.c rename to tests/switch.c