comparison gcc/fortran/misc.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* Miscellaneous stuff that doesn't fit anywhere else. 1 /* Miscellaneous stuff that doesn't fit anywhere else.
2 Copyright (C) 2000-2017 Free Software Foundation, Inc. 2 Copyright (C) 2000-2018 Free Software Foundation, Inc.
3 Contributed by Andy Vaught 3 Contributed by Andy Vaught
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
21 #include "config.h" 21 #include "config.h"
22 #include "system.h" 22 #include "system.h"
23 #include "coretypes.h" 23 #include "coretypes.h"
24 #include "gfortran.h" 24 #include "gfortran.h"
25 #include "spellcheck.h" 25 #include "spellcheck.h"
26 #include "tree.h"
26 27
27 28
28 /* Initialize a typespec to unknown. */ 29 /* Initialize a typespec to unknown. */
29 30
30 void 31 void
153 break; 154 break;
154 case BT_DERIVED: 155 case BT_DERIVED:
155 sprintf (buffer, "TYPE(%s)", ts->u.derived->name); 156 sprintf (buffer, "TYPE(%s)", ts->u.derived->name);
156 break; 157 break;
157 case BT_CLASS: 158 case BT_CLASS:
158 ts = &ts->u.derived->components->ts; 159 if (ts->u.derived->components)
160 ts = &ts->u.derived->components->ts;
159 if (ts->u.derived->attr.unlimited_polymorphic) 161 if (ts->u.derived->attr.unlimited_polymorphic)
160 sprintf (buffer, "CLASS(*)"); 162 sprintf (buffer, "CLASS(*)");
161 else 163 else
162 sprintf (buffer, "CLASS(%s)", ts->u.derived->name); 164 sprintf (buffer, "CLASS(%s)", ts->u.derived->name);
163 break; 165 break;
282 return ISOCBINDING_INVALID; 284 return ISOCBINDING_INVALID;
283 } 285 }
284 286
285 287
286 /* For a given name TYPO, determine the best candidate from CANDIDATES 288 /* For a given name TYPO, determine the best candidate from CANDIDATES
287 perusing Levenshtein distance. Frees CANDIDATES before returning. */ 289 using get_edit_distance. Frees CANDIDATES before returning. */
288 290
289 const char * 291 const char *
290 gfc_closest_fuzzy_match (const char *typo, char **candidates) 292 gfc_closest_fuzzy_match (const char *typo, char **candidates)
291 { 293 {
292 /* Determine closest match. */ 294 /* Determine closest match. */
295 edit_distance_t best_distance = MAX_EDIT_DISTANCE; 297 edit_distance_t best_distance = MAX_EDIT_DISTANCE;
296 const size_t tl = strlen (typo); 298 const size_t tl = strlen (typo);
297 299
298 while (cand && *cand) 300 while (cand && *cand)
299 { 301 {
300 edit_distance_t dist = levenshtein_distance (typo, tl, *cand, 302 edit_distance_t dist = get_edit_distance (typo, tl, *cand,
301 strlen (*cand)); 303 strlen (*cand));
302 if (dist < best_distance) 304 if (dist < best_distance)
303 { 305 {
304 best_distance = dist; 306 best_distance = dist;
305 best = *cand; 307 best = *cand;
319 } 321 }
320 XDELETEVEC (candidates); 322 XDELETEVEC (candidates);
321 } 323 }
322 return best; 324 return best;
323 } 325 }
326
327 /* Convert between GMP integers (mpz_t) and HOST_WIDE_INT. */
328
329 HOST_WIDE_INT
330 gfc_mpz_get_hwi (mpz_t op)
331 {
332 /* Using long_long_integer_type_node as that is the integer type
333 node that closest matches HOST_WIDE_INT; both are guaranteed to
334 be at least 64 bits. */
335 const wide_int w = wi::from_mpz (long_long_integer_type_node, op, true);
336 return w.to_shwi ();
337 }
338
339
340 void
341 gfc_mpz_set_hwi (mpz_t rop, const HOST_WIDE_INT op)
342 {
343 const wide_int w = wi::shwi (op, HOST_BITS_PER_WIDE_INT);
344 wi::to_mpz (w, rop, SIGNED);
345 }