comparison gcc/fortran/primary.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 /* Primary expression subroutines 1 /* Primary expression subroutines
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
860 { 860 {
861 ref = gfc_get_ref (); 861 ref = gfc_get_ref ();
862 862
863 ref->type = REF_SUBSTRING; 863 ref->type = REF_SUBSTRING;
864 if (start == NULL) 864 if (start == NULL)
865 start = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1); 865 start = gfc_get_int_expr (gfc_charlen_int_kind, NULL, 1);
866 ref->u.ss.start = start; 866 ref->u.ss.start = start;
867 if (end == NULL && cl) 867 if (end == NULL && cl)
868 end = gfc_copy_expr (cl->length); 868 end = gfc_copy_expr (cl->length);
869 ref->u.ss.end = end; 869 ref->u.ss.end = end;
870 ref->u.ss.length = cl; 870 ref->u.ss.length = cl;
1004 1004
1005 static match 1005 static match
1006 match_string_constant (gfc_expr **result) 1006 match_string_constant (gfc_expr **result)
1007 { 1007 {
1008 char name[GFC_MAX_SYMBOL_LEN + 1], peek; 1008 char name[GFC_MAX_SYMBOL_LEN + 1], peek;
1009 int i, kind, length, save_warn_ampersand, ret; 1009 size_t length;
1010 int kind,save_warn_ampersand, ret;
1010 locus old_locus, start_locus; 1011 locus old_locus, start_locus;
1011 gfc_symbol *sym; 1012 gfc_symbol *sym;
1012 gfc_expr *e; 1013 gfc_expr *e;
1013 match m; 1014 match m;
1014 gfc_char_t c, delimiter, *p; 1015 gfc_char_t c, delimiter, *p;
1123 been printed in the loop above. */ 1124 been printed in the loop above. */
1124 save_warn_ampersand = warn_ampersand; 1125 save_warn_ampersand = warn_ampersand;
1125 warn_ampersand = false; 1126 warn_ampersand = false;
1126 1127
1127 p = e->value.character.string; 1128 p = e->value.character.string;
1128 for (i = 0; i < length; i++) 1129 for (size_t i = 0; i < length; i++)
1129 { 1130 {
1130 c = next_string_char (delimiter, &ret); 1131 c = next_string_char (delimiter, &ret);
1131 1132
1132 if (!gfc_check_character_range (c, kind)) 1133 if (!gfc_check_character_range (c, kind))
1133 { 1134 {
1245 if (gfc_find_symbol (name, NULL, 1, &sym) || sym == NULL) 1246 if (gfc_find_symbol (name, NULL, 1, &sym) || sym == NULL)
1246 return MATCH_NO; 1247 return MATCH_NO;
1247 1248
1248 if (sym->attr.flavor != FL_PARAMETER) 1249 if (sym->attr.flavor != FL_PARAMETER)
1249 { 1250 {
1250 gfc_error ("Expected PARAMETER symbol in complex constant at %C"); 1251 /* Give the matcher for implied do-loops a chance to run. This yields
1251 return MATCH_ERROR; 1252 a much saner error message for "write(*,*) (i, i=1, 6" where the
1253 right parenthesis is missing. */
1254 char c;
1255 gfc_gobble_whitespace ();
1256 c = gfc_peek_ascii_char ();
1257 if (c == '=' || c == ',')
1258 {
1259 m = MATCH_NO;
1260 }
1261 else
1262 {
1263 gfc_error ("Expected PARAMETER symbol in complex constant at %C");
1264 m = MATCH_ERROR;
1265 }
1266 return m;
1252 } 1267 }
1253 1268
1254 if (!sym->value) 1269 if (!sym->value)
1255 goto error; 1270 goto error;
1256 1271
1696 if (name[0] != '\0') 1711 if (name[0] != '\0')
1697 { 1712 {
1698 switch (name[0]) 1713 switch (name[0])
1699 { 1714 {
1700 case 'l': 1715 case 'l':
1701 if (strncmp (name, "loc", 3) == 0) 1716 if (gfc_str_startswith (name, "loc"))
1702 { 1717 {
1703 result->name = "%LOC"; 1718 result->name = "%LOC";
1704 break; 1719 break;
1705 } 1720 }
1706 /* FALLTHRU */ 1721 /* FALLTHRU */
1707 case 'r': 1722 case 'r':
1708 if (strncmp (name, "ref", 3) == 0) 1723 if (gfc_str_startswith (name, "ref"))
1709 { 1724 {
1710 result->name = "%REF"; 1725 result->name = "%REF";
1711 break; 1726 break;
1712 } 1727 }
1713 /* FALLTHRU */ 1728 /* FALLTHRU */
1714 case 'v': 1729 case 'v':
1715 if (strncmp (name, "val", 3) == 0) 1730 if (gfc_str_startswith (name, "val"))
1716 { 1731 {
1717 result->name = "%VAL"; 1732 result->name = "%VAL";
1718 break; 1733 break;
1719 } 1734 }
1720 /* FALLTHRU */ 1735 /* FALLTHRU */
2079 /* See if there is a usable typespec in the "no IMPLICIT type" error. */ 2094 /* See if there is a usable typespec in the "no IMPLICIT type" error. */
2080 if (sym->ts.type == BT_UNKNOWN && m == MATCH_YES) 2095 if (sym->ts.type == BT_UNKNOWN && m == MATCH_YES)
2081 { 2096 {
2082 bool permissible; 2097 bool permissible;
2083 2098
2084 /* These target expressions can ge resolved at any time. */ 2099 /* These target expressions can be resolved at any time. */
2085 permissible = tgt_expr && tgt_expr->symtree && tgt_expr->symtree->n.sym 2100 permissible = tgt_expr && tgt_expr->symtree && tgt_expr->symtree->n.sym
2086 && (tgt_expr->symtree->n.sym->attr.use_assoc 2101 && (tgt_expr->symtree->n.sym->attr.use_assoc
2087 || tgt_expr->symtree->n.sym->attr.host_assoc 2102 || tgt_expr->symtree->n.sym->attr.host_assoc
2088 || tgt_expr->symtree->n.sym->attr.if_source 2103 || tgt_expr->symtree->n.sym->attr.if_source
2089 == IFSRC_DECL); 2104 == IFSRC_DECL);
2876 /* Here we can check if a component name is given which does not 2891 /* Here we can check if a component name is given which does not
2877 correspond to any component of the defined structure. */ 2892 correspond to any component of the defined structure. */
2878 if (!this_comp) 2893 if (!this_comp)
2879 goto cleanup; 2894 goto cleanup;
2880 2895
2896 /* For a constant string constructor, make sure the length is
2897 correct; truncate of fill with blanks if needed. */
2898 if (this_comp->ts.type == BT_CHARACTER && !this_comp->attr.allocatable
2899 && this_comp->ts.u.cl && this_comp->ts.u.cl->length
2900 && this_comp->ts.u.cl->length->expr_type == EXPR_CONSTANT
2901 && actual->expr->ts.type == BT_CHARACTER
2902 && actual->expr->expr_type == EXPR_CONSTANT)
2903 {
2904 ptrdiff_t c, e;
2905 c = gfc_mpz_get_hwi (this_comp->ts.u.cl->length->value.integer);
2906 e = actual->expr->value.character.length;
2907
2908 if (c != e)
2909 {
2910 ptrdiff_t i, to;
2911 gfc_char_t *dest;
2912 dest = gfc_get_wide_string (c + 1);
2913
2914 to = e < c ? e : c;
2915 for (i = 0; i < to; i++)
2916 dest[i] = actual->expr->value.character.string[i];
2917
2918 for (i = e; i < c; i++)
2919 dest[i] = ' ';
2920
2921 dest[c] = '\0';
2922 free (actual->expr->value.character.string);
2923
2924 actual->expr->value.character.length = c;
2925 actual->expr->value.character.string = dest;
2926 }
2927 }
2928
2881 comp_tail->val = actual->expr; 2929 comp_tail->val = actual->expr;
2882 if (actual->expr != NULL) 2930 if (actual->expr != NULL)
2883 comp_tail->where = actual->expr->where; 2931 comp_tail->where = actual->expr->where;
2884 actual->expr = NULL; 2932 actual->expr = NULL;
2885 2933