Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-nested-maps.c
CommitLineData
2e62ab40
AB
1/* This testcase is part of GDB, the GNU debugger.
2
88b9d363 3 Copyright 2019-2022 Free Software Foundation, Inc.
2e62ab40
AB
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18#include <stdlib.h>
19#include <string.h>
20
21#define FIXED_MAP_SIZE 10
22
a83cdcb6 23struct my_key_t
2e62ab40
AB
24{
25 int a;
26 int b;
27};
28
a83cdcb6 29struct my_value_t
2e62ab40
AB
30{
31 int x;
32 int y;
33 int z;
34};
35
36struct map_t
37{
38 const char *name;
39 int length;
a83cdcb6
PA
40 struct my_key_t *keys;
41 struct my_value_t *values;
2e62ab40
AB
42
43 /* This field is used only by the pretty printer. */
44 int show_header;
45};
46
47struct map_map_t
48{
49 int length;
50 struct map_t **values;
51
52 /* This field is used only by the pretty printer. */
53 int show_header;
54};
55
56struct map_t *
57create_map (const char *name)
58{
a83cdcb6 59 struct map_t *m = (struct map_t *) malloc (sizeof (struct map_t));
2e62ab40
AB
60 m->name = strdup (name);
61 m->length = 0;
62 m->keys = NULL;
63 m->values = NULL;
64 m->show_header = 0;
c802e8a7 65 return m;
2e62ab40
AB
66}
67
68void
a83cdcb6 69add_map_element (struct map_t *m, struct my_key_t k, struct my_value_t v)
2e62ab40
AB
70{
71 if (m->length == 0)
72 {
a83cdcb6
PA
73 m->keys = (struct my_key_t *) malloc (sizeof (struct my_key_t) * FIXED_MAP_SIZE);
74 m->values = (struct my_value_t *) malloc (sizeof (struct my_value_t) * FIXED_MAP_SIZE);
2e62ab40
AB
75 }
76
77 m->keys[m->length] = k;
78 m->values[m->length] = v;
79 m->length++;
80}
81
82struct map_map_t *
83create_map_map (void)
84{
a83cdcb6 85 struct map_map_t *mm = (struct map_map_t *) malloc (sizeof (struct map_map_t));
2e62ab40
AB
86 mm->length = 0;
87 mm->values = NULL;
88 mm->show_header = 0;
c802e8a7 89 return mm;
2e62ab40
AB
90}
91
92void
93add_map_map_element (struct map_map_t *mm, struct map_t *map)
94{
95 if (mm->length == 0)
a83cdcb6 96 mm->values = (struct map_t **) malloc (sizeof (struct map_t *) * FIXED_MAP_SIZE);
2e62ab40
AB
97
98 mm->values[mm->length] = map;
99 mm->length++;
100}
101
102int
103main (void)
104{
105 struct map_t *m1 = create_map ("m1");
a83cdcb6
PA
106 struct my_key_t k1 = {3, 4};
107 struct my_key_t k2 = {4, 5};
108 struct my_key_t k3 = {5, 6};
109 struct my_key_t k4 = {6, 7};
110 struct my_key_t k5 = {7, 8};
111 struct my_key_t k6 = {8, 9};
112 struct my_value_t v1 = {0, 1, 2};
113 struct my_value_t v2 = {3, 4, 5};
114 struct my_value_t v3 = {6, 7, 8};
115 struct my_value_t v4 = {9, 0, 1};
116 struct my_value_t v5 = {2, 3, 4};
117 struct my_value_t v6 = {5, 6, 7};
2e62ab40
AB
118 add_map_element (m1, k1, v1);
119 add_map_element (m1, k2, v2);
120 add_map_element (m1, k3, v3);
121
122 struct map_t *m2 = create_map ("m2");
123 add_map_element (m2, k4, v4);
124 add_map_element (m2, k5, v5);
125 add_map_element (m2, k6, v6);
126
127 struct map_map_t *mm = create_map_map ();
128 add_map_map_element (mm, m1);
129 add_map_map_element (mm, m2);
130
131 return 0; /* Break here. */
132}
This page took 0.381709 seconds and 4 git commands to generate.