Branch data Line data Source code
1 : : /* Get the default subrange lower bound for a given language.
2 : : Copyright (C) 2016 Red Hat, Inc.
3 : : Copyright (C) 2024, 2025 Mark J. Wielaard <mark@klomp.org>
4 : : This file is part of elfutils.
5 : :
6 : : This file is free software; you can redistribute it and/or modify
7 : : it under the terms of either
8 : :
9 : : * the GNU Lesser General Public License as published by the Free
10 : : Software Foundation; either version 3 of the License, or (at
11 : : your option) any later version
12 : :
13 : : or
14 : :
15 : : * the GNU General Public License as published by the Free
16 : : Software Foundation; either version 2 of the License, or (at
17 : : your option) any later version
18 : :
19 : : or both in parallel, as here.
20 : :
21 : : elfutils is distributed in the hope that it will be useful, but
22 : : WITHOUT ANY WARRANTY; without even the implied warranty of
23 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 : : General Public License for more details.
25 : :
26 : : You should have received copies of the GNU General Public License and
27 : : the GNU Lesser General Public License along with this program. If
28 : : not, see <http://www.gnu.org/licenses/>. */
29 : :
30 : : #ifdef HAVE_CONFIG_H
31 : : # include <config.h>
32 : : #endif
33 : :
34 : : #include <dwarf.h>
35 : : #include "libdwP.h"
36 : :
37 : : /* Determine default lower bound from language, as per the DWARF5
38 : : "Subrange Type Entries" table. */
39 : : int
40 : 146 : dwarf_default_lower_bound (int lang, Dwarf_Sword *result)
41 : : {
42 [ + + + + ]: 146 : switch (lang)
43 : : {
44 : 100 : case DW_LANG_C:
45 : : case DW_LANG_C89:
46 : : case DW_LANG_C99:
47 : : case DW_LANG_C11:
48 : : case DW_LANG_C_plus_plus:
49 : : case DW_LANG_C_plus_plus_03:
50 : : case DW_LANG_C_plus_plus_11:
51 : : case DW_LANG_C_plus_plus_14:
52 : : case DW_LANG_ObjC:
53 : : case DW_LANG_ObjC_plus_plus:
54 : : case DW_LANG_Java:
55 : : case DW_LANG_D:
56 : : case DW_LANG_Python:
57 : : case DW_LANG_UPC:
58 : : case DW_LANG_OpenCL:
59 : : case DW_LANG_Go:
60 : : case DW_LANG_Haskell:
61 : : case DW_LANG_OCaml:
62 : : case DW_LANG_Rust:
63 : : case DW_LANG_Swift:
64 : : case DW_LANG_Dylan:
65 : : case DW_LANG_RenderScript:
66 : : case DW_LANG_BLISS:
67 : : case DW_LANG_Kotlin:
68 : : case DW_LANG_Zig:
69 : : case DW_LANG_Crystal:
70 : : case DW_LANG_C_plus_plus_17:
71 : : case DW_LANG_C_plus_plus_20:
72 : : case DW_LANG_C17:
73 : : case DW_LANG_HIP:
74 : : case DW_LANG_Assembly:
75 : : case DW_LANG_C_sharp:
76 : : case DW_LANG_Mojo:
77 : : case DW_LANG_GLSL:
78 : : case DW_LANG_GLSL_ES:
79 : : case DW_LANG_HLSL:
80 : : case DW_LANG_OpenCL_CPP:
81 : : case DW_LANG_CPP_for_OpenCL:
82 : : case DW_LANG_SYCL:
83 : : case DW_LANG_C_plus_plus_23:
84 : : case DW_LANG_Odin:
85 : : case DW_LANG_P4:
86 : : case DW_LANG_Metal:
87 : : case DW_LANG_C23:
88 : : case DW_LANG_Ruby:
89 : : case DW_LANG_Move:
90 : : case DW_LANG_Hylo:
91 : : case DW_LANG_V:
92 : : case DW_LANG_Nim:
93 : : case DW_LANG_Gleam:
94 : 100 : *result = 0;
95 : 100 : return 0;
96 : :
97 : 42 : case DW_LANG_Ada83:
98 : : case DW_LANG_Ada95:
99 : : case DW_LANG_Cobol74:
100 : : case DW_LANG_Cobol85:
101 : : case DW_LANG_Fortran77:
102 : : case DW_LANG_Fortran90:
103 : : case DW_LANG_Fortran95:
104 : : case DW_LANG_Fortran03:
105 : : case DW_LANG_Fortran08:
106 : : case DW_LANG_Pascal83:
107 : : case DW_LANG_Modula2:
108 : : case DW_LANG_Modula3:
109 : : case DW_LANG_PLI:
110 : : case DW_LANG_Julia:
111 : : case DW_LANG_Fortran18:
112 : : case DW_LANG_Ada2005:
113 : : case DW_LANG_Ada2012:
114 : : case DW_LANG_Fortran23:
115 : : case DW_LANG_Algol68:
116 : : case DW_LANG_Erlang:
117 : : case DW_LANG_Elixir:
118 : 42 : *result = 1;
119 : 42 : return 0;
120 : :
121 : : /* Special case vendor Assembly variant. */
122 : 2 : case DW_LANG_Mips_Assembler:
123 : 2 : *result = 0;
124 : 2 : return 0;
125 : :
126 : 2 : default:
127 : 2 : __libdw_seterrno (DWARF_E_UNKNOWN_LANGUAGE);
128 : 2 : return -1;
129 : : }
130 : : }
131 : : INTDEF (dwarf_default_lower_bound)
132 : :
133 : : /* Determine default lower bound from language, as per the DWARF6
134 : : https://dwarfstd.org/languages-v6.html table. */
135 : : int
136 : 536 : dwarf_language_lower_bound (Dwarf_Word lang, Dwarf_Sword *result)
137 : : {
138 [ + + + ]: 536 : switch (lang)
139 : : {
140 : 512 : case DW_LNAME_BLISS:
141 : : case DW_LNAME_C:
142 : : case DW_LNAME_C_plus_plus:
143 : : case DW_LNAME_Crystal:
144 : : case DW_LNAME_D:
145 : : case DW_LNAME_Dylan:
146 : : case DW_LNAME_Go:
147 : : case DW_LNAME_Haskell:
148 : : case DW_LNAME_Java:
149 : : case DW_LNAME_Kotlin:
150 : : case DW_LNAME_ObjC:
151 : : case DW_LNAME_ObjC_plus_plus:
152 : : case DW_LNAME_OCaml:
153 : : case DW_LNAME_OpenCL_C:
154 : : case DW_LNAME_Python:
155 : : case DW_LNAME_RenderScript:
156 : : case DW_LNAME_Rust:
157 : : case DW_LNAME_Swift:
158 : : case DW_LNAME_UPC:
159 : : case DW_LNAME_Zig:
160 : : case DW_LNAME_Assembly:
161 : : case DW_LNAME_C_sharp:
162 : : case DW_LNAME_Mojo:
163 : : case DW_LNAME_GLSL:
164 : : case DW_LNAME_GLSL_ES:
165 : : case DW_LNAME_HLSL:
166 : : case DW_LNAME_OpenCL_CPP:
167 : : case DW_LNAME_CPP_for_OpenCL:
168 : : case DW_LNAME_SYCL:
169 : : case DW_LNAME_Ruby:
170 : : case DW_LNAME_Move:
171 : : case DW_LNAME_Hylo:
172 : : case DW_LNAME_HIP:
173 : : case DW_LNAME_Odin:
174 : : case DW_LNAME_P4:
175 : : case DW_LNAME_Metal:
176 : : case DW_LNAME_V:
177 : : case DW_LNAME_Nim:
178 : : case DW_LNAME_Gleam:
179 : 512 : *result = 0;
180 : 512 : return 0;
181 : :
182 : 22 : case DW_LNAME_Ada:
183 : : case DW_LNAME_Cobol:
184 : : case DW_LNAME_Fortran:
185 : : case DW_LNAME_Julia:
186 : : case DW_LNAME_Modula2:
187 : : case DW_LNAME_Modula3:
188 : : case DW_LNAME_Pascal:
189 : : case DW_LNAME_PLI:
190 : : case DW_LNAME_Algol68:
191 : : case DW_LNAME_Erlang:
192 : : case DW_LNAME_Elixir:
193 : 22 : *result = 1;
194 : 22 : return 0;
195 : :
196 : 2 : default:
197 : 2 : __libdw_seterrno (DWARF_E_UNKNOWN_LANGUAGE);
198 : 2 : return -1;
199 : : }
200 : : }
201 : : INTDEF (dwarf_language_lower_bound)
|