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 : 140 : dwarf_default_lower_bound (int lang, Dwarf_Sword *result) 41 : : { 42 [ + + + + ]: 140 : switch (lang) 43 : : { 44 : 98 : 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 : 98 : *result = 0; 94 : 98 : return 0; 95 : : 96 : 38 : case DW_LANG_Ada83: 97 : : case DW_LANG_Ada95: 98 : : case DW_LANG_Cobol74: 99 : : case DW_LANG_Cobol85: 100 : : case DW_LANG_Fortran77: 101 : : case DW_LANG_Fortran90: 102 : : case DW_LANG_Fortran95: 103 : : case DW_LANG_Fortran03: 104 : : case DW_LANG_Fortran08: 105 : : case DW_LANG_Pascal83: 106 : : case DW_LANG_Modula2: 107 : : case DW_LANG_Modula3: 108 : : case DW_LANG_PLI: 109 : : case DW_LANG_Julia: 110 : : case DW_LANG_Fortran18: 111 : : case DW_LANG_Ada2005: 112 : : case DW_LANG_Ada2012: 113 : : case DW_LANG_Fortran23: 114 : : case DW_LANG_Algol68: 115 : 38 : *result = 1; 116 : 38 : return 0; 117 : : 118 : : /* Special case vendor Assembly variant. */ 119 : 2 : case DW_LANG_Mips_Assembler: 120 : 2 : *result = 0; 121 : 2 : return 0; 122 : : 123 : 2 : default: 124 : 2 : __libdw_seterrno (DWARF_E_UNKNOWN_LANGUAGE); 125 : 2 : return -1; 126 : : } 127 : : } 128 : : INTDEF (dwarf_default_lower_bound) 129 : : 130 : : /* Determine default lower bound from language, as per the DWARF6 131 : : https://dwarfstd.org/languages-v6.html table. */ 132 : : int 133 : 550 : dwarf_language_lower_bound (Dwarf_Word lang, Dwarf_Sword *result) 134 : : { 135 [ + + + ]: 550 : switch (lang) 136 : : { 137 : 530 : case DW_LNAME_BLISS: 138 : : case DW_LNAME_C: 139 : : case DW_LNAME_C_plus_plus: 140 : : case DW_LNAME_Crystal: 141 : : case DW_LNAME_D: 142 : : case DW_LNAME_Dylan: 143 : : case DW_LNAME_Go: 144 : : case DW_LNAME_Haskell: 145 : : case DW_LNAME_Java: 146 : : case DW_LNAME_Kotlin: 147 : : case DW_LNAME_ObjC: 148 : : case DW_LNAME_ObjC_plus_plus: 149 : : case DW_LNAME_OCaml: 150 : : case DW_LNAME_OpenCL_C: 151 : : case DW_LNAME_Python: 152 : : case DW_LNAME_RenderScript: 153 : : case DW_LNAME_Rust: 154 : : case DW_LNAME_Swift: 155 : : case DW_LNAME_UPC: 156 : : case DW_LNAME_Zig: 157 : : case DW_LNAME_Assembly: 158 : : case DW_LNAME_C_sharp: 159 : : case DW_LNAME_Mojo: 160 : : case DW_LNAME_GLSL: 161 : : case DW_LNAME_GLSL_ES: 162 : : case DW_LNAME_HLSL: 163 : : case DW_LNAME_OpenCL_CPP: 164 : : case DW_LNAME_CPP_for_OpenCL: 165 : : case DW_LNAME_SYCL: 166 : : case DW_LNAME_Ruby: 167 : : case DW_LNAME_Move: 168 : : case DW_LNAME_Hylo: 169 : : case DW_LNAME_HIP: 170 : : case DW_LNAME_Odin: 171 : : case DW_LNAME_P4: 172 : : case DW_LNAME_Metal: 173 : : case DW_LNAME_V: 174 : : case DW_LNAME_Nim: 175 : 530 : *result = 0; 176 : 530 : return 0; 177 : : 178 : 18 : case DW_LNAME_Ada: 179 : : case DW_LNAME_Cobol: 180 : : case DW_LNAME_Fortran: 181 : : case DW_LNAME_Julia: 182 : : case DW_LNAME_Modula2: 183 : : case DW_LNAME_Modula3: 184 : : case DW_LNAME_Pascal: 185 : : case DW_LNAME_PLI: 186 : : case DW_LNAME_Algol68: 187 : 18 : *result = 1; 188 : 18 : return 0; 189 : : 190 : 2 : default: 191 : 2 : __libdw_seterrno (DWARF_E_UNKNOWN_LANGUAGE); 192 : 2 : return -1; 193 : : } 194 : : } 195 : : INTDEF (dwarf_language_lower_bound)