github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/ast/var_decl_test.go (about)

     1  package ast
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestVarDecl(t *testing.T) {
     8  	nodes := map[string]Node{
     9  		`0x7fd5e90e5a00 <col:14> col:17 'int'`: &VarDecl{
    10  			Addr:         0x7fd5e90e5a00,
    11  			Pos:          NewPositionFromString("col:14"),
    12  			Position2:    "col:17",
    13  			Name:         "",
    14  			Type:         "int",
    15  			Type2:        "",
    16  			IsExtern:     false,
    17  			IsUsed:       false,
    18  			IsCInit:      false,
    19  			IsReferenced: false,
    20  			IsStatic:     false,
    21  			IsRegister:   false,
    22  			Parent:       0,
    23  			ChildNodes:   []Node{},
    24  		},
    25  		`0x7fd5e90e9078 <line:156:1, col:14> col:14 __stdinp 'FILE *' extern`: &VarDecl{
    26  			Addr:         0x7fd5e90e9078,
    27  			Pos:          NewPositionFromString("line:156:1, col:14"),
    28  			Position2:    "col:14",
    29  			Name:         "__stdinp",
    30  			Type:         "FILE *",
    31  			Type2:        "",
    32  			IsExtern:     true,
    33  			IsUsed:       false,
    34  			IsCInit:      false,
    35  			IsReferenced: false,
    36  			IsStatic:     false,
    37  			IsRegister:   false,
    38  			Parent:       0,
    39  			ChildNodes:   []Node{},
    40  		},
    41  		`0x7fd5e90ed630 <col:40, col:47> col:47 __size 'size_t':'unsigned long'`: &VarDecl{
    42  			Addr:         0x7fd5e90ed630,
    43  			Pos:          NewPositionFromString("col:40, col:47"),
    44  			Position2:    "col:47",
    45  			Name:         "__size",
    46  			Type:         "size_t",
    47  			Type2:        "unsigned long",
    48  			IsExtern:     false,
    49  			IsUsed:       false,
    50  			IsCInit:      false,
    51  			IsReferenced: false,
    52  			IsStatic:     false,
    53  			IsRegister:   false,
    54  			Parent:       0,
    55  			ChildNodes:   []Node{},
    56  		},
    57  		`0x7fee35907a78 <col:4, col:8> col:8 used c 'int'`: &VarDecl{
    58  			Addr:         0x7fee35907a78,
    59  			Pos:          NewPositionFromString("col:4, col:8"),
    60  			Position2:    "col:8",
    61  			Name:         "c",
    62  			Type:         "int",
    63  			Type2:        "",
    64  			IsExtern:     false,
    65  			IsUsed:       true,
    66  			IsCInit:      false,
    67  			IsReferenced: false,
    68  			IsStatic:     false,
    69  			IsRegister:   false,
    70  			Parent:       0,
    71  			ChildNodes:   []Node{},
    72  		},
    73  		`0x7fb0fd90ba30 <col:3, /usr/include/sys/_types.h:52:33> tests/assert/assert.c:13:9 used b 'int *' cinit`: &VarDecl{
    74  			Addr:         0x7fb0fd90ba30,
    75  			Pos:          NewPositionFromString("col:3, /usr/include/sys/_types.h:52:33"),
    76  			Position2:    "tests/assert/assert.c:13:9",
    77  			Name:         "b",
    78  			Type:         "int *",
    79  			Type2:        "",
    80  			IsExtern:     false,
    81  			IsUsed:       true,
    82  			IsCInit:      true,
    83  			IsReferenced: false,
    84  			IsStatic:     false,
    85  			IsRegister:   false,
    86  			Parent:       0,
    87  			ChildNodes:   []Node{},
    88  		},
    89  		`0x7fb20308bd40 <col:5, col:11> col:11 referenced a 'short'`: &VarDecl{
    90  			Addr:         0x7fb20308bd40,
    91  			Pos:          NewPositionFromString("col:5, col:11"),
    92  			Position2:    "col:11",
    93  			Name:         "a",
    94  			Type:         "short",
    95  			Type2:        "",
    96  			IsExtern:     false,
    97  			IsUsed:       false,
    98  			IsCInit:      false,
    99  			IsReferenced: true,
   100  			IsStatic:     false,
   101  			IsRegister:   false,
   102  			Parent:       0,
   103  			ChildNodes:   []Node{},
   104  		},
   105  		`0x55a040ddd798 <sqlite3.c:66:1, line:770:1> line:66:27 used sqlite3azCompileOpt 'const char *const [2]' static cinit`: &VarDecl{
   106  			Addr:         0x55a040ddd798,
   107  			Pos:          NewPositionFromString("sqlite3.c:66:1, line:770:1"),
   108  			Position2:    "line:66:27",
   109  			Name:         "sqlite3azCompileOpt",
   110  			Type:         "const char *const [2]",
   111  			Type2:        "",
   112  			IsExtern:     false,
   113  			IsUsed:       true,
   114  			IsCInit:      true,
   115  			IsReferenced: false,
   116  			IsStatic:     true,
   117  			IsRegister:   false,
   118  			Parent:       0,
   119  			ChildNodes:   []Node{},
   120  		},
   121  		`0x55772c7774d0 <col:3, col:27> col:27 used a 'unsigned char *' register`: &VarDecl{
   122  			Addr:         0x55772c7774d0,
   123  			Pos:          NewPositionFromString("col:3, col:27"),
   124  			Position2:    "col:27",
   125  			Name:         "a",
   126  			Type:         "unsigned char *",
   127  			Type2:        "",
   128  			IsExtern:     false,
   129  			IsUsed:       true,
   130  			IsCInit:      false,
   131  			IsReferenced: false,
   132  			IsStatic:     false,
   133  			IsRegister:   true,
   134  			Parent:       0,
   135  			ChildNodes:   []Node{},
   136  		},
   137  		`0x26fd180 <col:4, col:32> col:13 used aExt 'extCoord':'extCoord' cinit`: &VarDecl{
   138  			Addr:         0x26fd180,
   139  			Pos:          NewPositionFromString("col:4, col:32"),
   140  			Position2:    "col:13",
   141  			Name:         "aExt",
   142  			Type:         "extCoord",
   143  			Type2:        "extCoord",
   144  			IsExtern:     false,
   145  			IsUsed:       true,
   146  			IsCInit:      true,
   147  			IsReferenced: false,
   148  			IsStatic:     false,
   149  			IsRegister:   false,
   150  			Parent:       0,
   151  			ChildNodes:   []Node{},
   152  		},
   153  		`0x7f985e0ffb10 parent 0x7f985e0246d0 <col:3, col:20> col:20 used DEFAULT_MEM_ALLOCATOR 'cmark_mem':'struct cmark_mem' extern`: &VarDecl{
   154  			Addr:         0x7f985e0ffb10,
   155  			Pos:          NewPositionFromString("col:3, col:20"),
   156  			Position2:    "col:20",
   157  			Name:         "DEFAULT_MEM_ALLOCATOR",
   158  			Type:         "cmark_mem",
   159  			Type2:        "struct cmark_mem",
   160  			IsExtern:     true,
   161  			IsUsed:       true,
   162  			IsCInit:      false,
   163  			IsReferenced: false,
   164  			IsStatic:     false,
   165  			IsRegister:   false,
   166  			Parent:       0x7f985e0246d0,
   167  			ChildNodes:   []Node{},
   168  		},
   169  		`0x3ec9368 parent 0x3dcaaf0 prev 0x3ec4088 <col:4, col:15> col:15 used CBLAS_CallFromC 'int' extern`: &VarDecl{
   170  			Addr:         0x3ec9368,
   171  			Parent:       0x3dcaaf0,
   172  			Prev:         0x3ec4088,
   173  			Pos:          NewPositionFromString("col:4, col:15"),
   174  			Position2:    "col:15",
   175  			Name:         "CBLAS_CallFromC",
   176  			Type:         "int",
   177  			Type2:        "",
   178  			IsExtern:     true,
   179  			IsUsed:       true,
   180  			IsCInit:      false,
   181  			IsReferenced: false,
   182  			IsStatic:     false,
   183  			IsRegister:   false,
   184  			ChildNodes:   []Node{},
   185  		},
   186  		`0x28f8490 <col:3, col:43> col:19 used a 'char *' register cinit`: &VarDecl{
   187  			Addr: 0x28f8490,
   188  			// Parent:       0x3dcaaf0,
   189  			// Prev:         0x3ec4088,
   190  			Pos:          NewPositionFromString("col:3, col:43"),
   191  			Position2:    "col:19",
   192  			Name:         "a",
   193  			Type:         "char *",
   194  			Type2:        "",
   195  			IsExtern:     false,
   196  			IsUsed:       true,
   197  			IsCInit:      true,
   198  			IsReferenced: false,
   199  			IsStatic:     false,
   200  			IsRegister:   true,
   201  			ChildNodes:   []Node{},
   202  		},
   203  		`0x1fb1890 <col:2, col:9> col:9 used obj 'class person' callinit`: &VarDecl{
   204  			Addr: 0x1fb1890,
   205  			// Parent:       0x3dcaaf0,
   206  			// Prev:         0x3ec4088,
   207  			Pos:          NewPositionFromString("col:2, col:9"),
   208  			Position2:    "col:9",
   209  			Name:         "obj",
   210  			Type:         "class person",
   211  			Type2:        "",
   212  			IsExtern:     false,
   213  			IsUsed:       true,
   214  			IsCInit:      false,
   215  			IsCallInit:   true,
   216  			IsReferenced: false,
   217  			IsStatic:     false,
   218  			IsRegister:   false,
   219  			ChildNodes:   []Node{},
   220  		},
   221  		`0x55d061dfbb58 <col:5, col:19> col:19 used str 'UA_ByteString':'UA_String' nrvo`: &VarDecl{
   222  			Addr: 0x55d061dfbb58,
   223  			// Parent:       0x3dcaaf0,
   224  			// Prev:         0x3ec4088,
   225  			Pos:          NewPositionFromString("col:5, col:19"),
   226  			Position2:    "col:19",
   227  			Name:         "str",
   228  			Type:         "UA_ByteString",
   229  			Type2:        "UA_String",
   230  			IsExtern:     false,
   231  			IsUsed:       true,
   232  			IsCInit:      false,
   233  			IsCallInit:   false,
   234  			IsNrvo:       true,
   235  			IsReferenced: false,
   236  			IsStatic:     false,
   237  			IsRegister:   false,
   238  			ChildNodes:   []Node{},
   239  		},
   240  		`0x55d0620bb190 </home/ee/Downloads/open62541.c:5682:1, col:93> col:37 used UA_rng 'pcg32_random_t':'struct pcg_state_setseq_64' static tls cinit`: &VarDecl{
   241  			Addr: 0x55d0620bb190,
   242  			// Parent:       0x3dcaaf0,
   243  			// Prev:         0x3ec4088,
   244  			Pos:          NewPositionFromString("/home/ee/Downloads/open62541.c:5682:1, col:93"),
   245  			Position2:    "col:37",
   246  			Name:         "UA_rng",
   247  			Type:         "pcg32_random_t",
   248  			Type2:        "struct pcg_state_setseq_64",
   249  			IsExtern:     false,
   250  			IsUsed:       true,
   251  			IsCInit:      true,
   252  			IsCallInit:   false,
   253  			IsNrvo:       false,
   254  			IsReferenced: false,
   255  			IsStatic:     true,
   256  			IsRegister:   false,
   257  			IsTls:        true,
   258  			ChildNodes:   []Node{},
   259  		},
   260  		`0x55b0fd013750 <col:5, col:39> col:22 used range 'UA_DurationRange':'UA_DurationRange' nrvo cinit`: &VarDecl{
   261  			Addr: 0x55b0fd013750,
   262  			// Parent:       0x3dcaaf0,
   263  			// Prev:         0x3ec4088,
   264  			Pos:          NewPositionFromString("col:5, col:39"),
   265  			Position2:    "col:22",
   266  			Name:         "range",
   267  			Type:         "UA_DurationRange",
   268  			Type2:        "UA_DurationRange",
   269  			IsExtern:     false,
   270  			IsUsed:       true,
   271  			IsCInit:      true,
   272  			IsCallInit:   false,
   273  			IsNrvo:       true,
   274  			IsReferenced: false,
   275  			IsStatic:     false,
   276  			IsRegister:   false,
   277  			IsTls:        false,
   278  			ChildNodes:   []Node{},
   279  		},
   280  		`0x31ad060 <line:70:1, col:26> col:13 used restricted 'bool':'enum Bool' static cinit`: &VarDecl{
   281  			Addr:         0x31ad060,
   282  			Pos:          NewPositionFromString("line:70:1, col:26"),
   283  			Position2:    "col:13",
   284  			Name:         "restricted",
   285  			Type:         "bool",
   286  			Type2:        "enum Bool",
   287  			IsExtern:     false,
   288  			IsUsed:       true,
   289  			IsCInit:      true,
   290  			IsCallInit:   false,
   291  			IsNrvo:       false,
   292  			IsReferenced: false,
   293  			IsStatic:     true,
   294  			IsRegister:   false,
   295  			IsTls:        false,
   296  			ChildNodes:   []Node{},
   297  		},
   298  	}
   299  
   300  	runNodeTests(t, nodes)
   301  }