Mercurial > hg > CbC > CbC_gcc
comparison gcc/fortran/cpp.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 /* Copyright (C) 2008-2018 Free Software Foundation, Inc. | 1 /* Copyright (C) 2008-2020 Free Software Foundation, Inc. |
2 | 2 |
3 This file is part of GCC. | 3 This file is part of GCC. |
4 | 4 |
5 GCC is free software; you can redistribute it and/or modify it under | 5 GCC is free software; you can redistribute it and/or modify it under |
6 the terms of the GNU General Public License as published by the Free | 6 the terms of the GNU General Public License as published by the Free |
132 | 132 |
133 /* Callback routines for the parser. Most of these are active only | 133 /* Callback routines for the parser. Most of these are active only |
134 in specific modes. */ | 134 in specific modes. */ |
135 static void cb_file_change (cpp_reader *, const line_map_ordinary *); | 135 static void cb_file_change (cpp_reader *, const line_map_ordinary *); |
136 static void cb_line_change (cpp_reader *, const cpp_token *, int); | 136 static void cb_line_change (cpp_reader *, const cpp_token *, int); |
137 static void cb_define (cpp_reader *, source_location, cpp_hashnode *); | 137 static void cb_define (cpp_reader *, location_t, cpp_hashnode *); |
138 static void cb_undef (cpp_reader *, source_location, cpp_hashnode *); | 138 static void cb_undef (cpp_reader *, location_t, cpp_hashnode *); |
139 static void cb_def_pragma (cpp_reader *, source_location); | 139 static void cb_def_pragma (cpp_reader *, location_t); |
140 static void cb_include (cpp_reader *, source_location, const unsigned char *, | 140 static void cb_include (cpp_reader *, location_t, const unsigned char *, |
141 const char *, int, const cpp_token **); | 141 const char *, int, const cpp_token **); |
142 static void cb_ident (cpp_reader *, source_location, const cpp_string *); | 142 static void cb_ident (cpp_reader *, location_t, const cpp_string *); |
143 static void cb_used_define (cpp_reader *, source_location, cpp_hashnode *); | 143 static void cb_used_define (cpp_reader *, location_t, cpp_hashnode *); |
144 static void cb_used_undef (cpp_reader *, source_location, cpp_hashnode *); | 144 static void cb_used_undef (cpp_reader *, location_t, cpp_hashnode *); |
145 static bool cb_cpp_diagnostic (cpp_reader *, enum cpp_diagnostic_level, | 145 static bool cb_cpp_diagnostic (cpp_reader *, enum cpp_diagnostic_level, |
146 enum cpp_warning_reason, rich_location *, | 146 enum cpp_warning_reason, rich_location *, |
147 const char *, va_list *) | 147 const char *, va_list *) |
148 ATTRIBUTE_GCC_DIAG(5,0); | 148 ATTRIBUTE_GCC_DIAG(5,0); |
149 void pp_dir_change (cpp_reader *, const char *); | 149 void pp_dir_change (cpp_reader *, const char *); |
164 define_language_independent_builtin_macros (pfile); | 164 define_language_independent_builtin_macros (pfile); |
165 cpp_define (pfile, "__GFORTRAN__=1"); | 165 cpp_define (pfile, "__GFORTRAN__=1"); |
166 cpp_define (pfile, "_LANGUAGE_FORTRAN=1"); | 166 cpp_define (pfile, "_LANGUAGE_FORTRAN=1"); |
167 | 167 |
168 if (flag_openacc) | 168 if (flag_openacc) |
169 cpp_define (pfile, "_OPENACC=201306"); | 169 cpp_define (pfile, "_OPENACC=201711"); |
170 | 170 |
171 if (flag_openmp) | 171 if (flag_openmp) |
172 cpp_define (pfile, "_OPENMP=201511"); | 172 cpp_define (pfile, "_OPENMP=201511"); |
173 | 173 |
174 /* The defines below are necessary for the TARGET_* macros. | 174 /* The defines below are necessary for the TARGET_* macros. |
576 | 576 |
577 cpp_change_file (cpp_in, LC_RENAME, _("<built-in>")); | 577 cpp_change_file (cpp_in, LC_RENAME, _("<built-in>")); |
578 if (!gfc_cpp_option.no_predefined) | 578 if (!gfc_cpp_option.no_predefined) |
579 { | 579 { |
580 /* Make sure all of the builtins about to be declared have | 580 /* Make sure all of the builtins about to be declared have |
581 BUILTINS_LOCATION has their source_location. */ | 581 BUILTINS_LOCATION has their location_t. */ |
582 source_location builtins_loc = BUILTINS_LOCATION; | 582 cpp_force_token_locations (cpp_in, BUILTINS_LOCATION); |
583 cpp_force_token_locations (cpp_in, &builtins_loc); | |
584 | 583 |
585 cpp_define_builtins (cpp_in); | 584 cpp_define_builtins (cpp_in); |
586 | 585 |
587 cpp_stop_forcing_token_locations (cpp_in); | 586 cpp_stop_forcing_token_locations (cpp_in); |
588 } | 587 } |
606 cpp_assert (cpp_in, opt->arg); | 605 cpp_assert (cpp_in, opt->arg); |
607 } | 606 } |
608 else if (opt->code == OPT_MT || opt->code == OPT_MQ) | 607 else if (opt->code == OPT_MT || opt->code == OPT_MQ) |
609 deps_add_target (cpp_get_deps (cpp_in), | 608 deps_add_target (cpp_get_deps (cpp_in), |
610 opt->arg, opt->code == OPT_MQ); | 609 opt->arg, opt->code == OPT_MQ); |
610 } | |
611 | |
612 /* Pre-defined macros for non-required INTEGER kind types. */ | |
613 for (gfc_integer_info *itype = gfc_integer_kinds; itype->kind != 0; itype++) | |
614 { | |
615 if (itype->kind == 1) | |
616 cpp_define (cpp_in, "__GFC_INT_1__=1"); | |
617 if (itype->kind == 2) | |
618 cpp_define (cpp_in, "__GFC_INT_2__=1"); | |
619 if (itype->kind == 8) | |
620 cpp_define (cpp_in, "__GFC_INT_8__=1"); | |
621 if (itype->kind == 16) | |
622 cpp_define (cpp_in, "__GFC_INT_16__=1"); | |
623 } | |
624 | |
625 /* Pre-defined macros for non-required REAL kind types. */ | |
626 for (gfc_real_info *rtype = gfc_real_kinds; rtype->kind != 0; rtype++) | |
627 { | |
628 if (rtype->kind == 10) | |
629 cpp_define (cpp_in, "__GFC_REAL_10__=1"); | |
630 if (rtype->kind == 16) | |
631 cpp_define (cpp_in, "__GFC_REAL_16__=1"); | |
611 } | 632 } |
612 | 633 |
613 if (gfc_cpp_option.working_directory | 634 if (gfc_cpp_option.working_directory |
614 && gfc_cpp_option.preprocess_only && !gfc_cpp_option.no_line_commands) | 635 && gfc_cpp_option.preprocess_only && !gfc_cpp_option.no_line_commands) |
615 pp_dir_change (cpp_in, get_src_pwd ()); | 636 pp_dir_change (cpp_in, get_src_pwd ()); |
708 | 729 |
709 static void scan_translation_unit_trad (cpp_reader *); | 730 static void scan_translation_unit_trad (cpp_reader *); |
710 static void account_for_newlines (const unsigned char *, size_t); | 731 static void account_for_newlines (const unsigned char *, size_t); |
711 static int dump_macro (cpp_reader *, cpp_hashnode *, void *); | 732 static int dump_macro (cpp_reader *, cpp_hashnode *, void *); |
712 | 733 |
713 static void print_line (source_location, const char *); | 734 static void print_line (location_t, const char *); |
714 static void maybe_print_line (source_location); | 735 static void maybe_print_line (location_t); |
715 | 736 |
716 | 737 |
717 /* Writes out the preprocessed file, handling spacing and paste | 738 /* Writes out the preprocessed file, handling spacing and paste |
718 avoidance issues. */ | 739 avoidance issues. */ |
719 static void | 740 static void |
789 | 810 |
790 /* If the token read on logical line LINE needs to be output on a | 811 /* If the token read on logical line LINE needs to be output on a |
791 different line to the current one, output the required newlines or | 812 different line to the current one, output the required newlines or |
792 a line marker. */ | 813 a line marker. */ |
793 static void | 814 static void |
794 maybe_print_line (source_location src_loc) | 815 maybe_print_line (location_t src_loc) |
795 { | 816 { |
796 const line_map_ordinary *map | 817 const line_map_ordinary *map |
797 = linemap_check_ordinary (linemap_lookup (line_table, src_loc)); | 818 = linemap_check_ordinary (linemap_lookup (line_table, src_loc)); |
798 int src_line = SOURCE_LINE (map, src_loc); | 819 int src_line = SOURCE_LINE (map, src_loc); |
799 | 820 |
818 } | 839 } |
819 | 840 |
820 /* Output a line marker for logical line LINE. Special flags are "1" | 841 /* Output a line marker for logical line LINE. Special flags are "1" |
821 or "2" indicating entering or leaving a file. */ | 842 or "2" indicating entering or leaving a file. */ |
822 static void | 843 static void |
823 print_line (source_location src_loc, const char *special_flags) | 844 print_line (location_t src_loc, const char *special_flags) |
824 { | 845 { |
825 /* End any previous line of text. */ | 846 /* End any previous line of text. */ |
826 if (print.printed) | 847 if (print.printed) |
827 putc ('\n', print.outf); | 848 putc ('\n', print.outf); |
828 print.printed = 0; | 849 print.printed = 0; |
896 of the line, and at end of file will be CPP_EOF. */ | 917 of the line, and at end of file will be CPP_EOF. */ |
897 static void | 918 static void |
898 cb_line_change (cpp_reader *pfile, const cpp_token *token, | 919 cb_line_change (cpp_reader *pfile, const cpp_token *token, |
899 int parsing_args) | 920 int parsing_args) |
900 { | 921 { |
901 source_location src_loc = token->src_loc; | 922 location_t src_loc = token->src_loc; |
902 | 923 |
903 if (token->type == CPP_EOF || parsing_args) | 924 if (token->type == CPP_EOF || parsing_args) |
904 return; | 925 return; |
905 | 926 |
906 maybe_print_line (src_loc); | 927 maybe_print_line (src_loc); |
923 putc (' ', print.outf); | 944 putc (' ', print.outf); |
924 } | 945 } |
925 } | 946 } |
926 | 947 |
927 static void | 948 static void |
928 cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, | 949 cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, location_t line, |
929 const cpp_string *str) | 950 const cpp_string *str) |
930 { | 951 { |
931 maybe_print_line (line); | 952 maybe_print_line (line); |
932 fprintf (print.outf, "#ident %s\n", str->text); | 953 fprintf (print.outf, "#ident %s\n", str->text); |
933 print.src_line++; | 954 print.src_line++; |
934 } | 955 } |
935 | 956 |
936 static void | 957 static void |
937 cb_define (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, | 958 cb_define (cpp_reader *pfile ATTRIBUTE_UNUSED, location_t line, |
938 cpp_hashnode *node ATTRIBUTE_UNUSED) | 959 cpp_hashnode *node ATTRIBUTE_UNUSED) |
939 { | 960 { |
940 maybe_print_line (line); | 961 maybe_print_line (line); |
941 fputs ("#define ", print.outf); | 962 fputs ("#define ", print.outf); |
942 | 963 |
951 if (LOCATION_LINE (line) != 0) | 972 if (LOCATION_LINE (line) != 0) |
952 print.src_line++; | 973 print.src_line++; |
953 } | 974 } |
954 | 975 |
955 static void | 976 static void |
956 cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, | 977 cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, location_t line, |
957 cpp_hashnode *node) | 978 cpp_hashnode *node) |
958 { | 979 { |
959 maybe_print_line (line); | 980 maybe_print_line (line); |
960 fprintf (print.outf, "#undef %s\n", NODE_NAME (node)); | 981 fprintf (print.outf, "#undef %s\n", NODE_NAME (node)); |
961 print.src_line++; | 982 print.src_line++; |
962 } | 983 } |
963 | 984 |
964 static void | 985 static void |
965 cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, | 986 cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, location_t line, |
966 const unsigned char *dir, const char *header, int angle_brackets, | 987 const unsigned char *dir, const char *header, int angle_brackets, |
967 const cpp_token **comments) | 988 const cpp_token **comments) |
968 { | 989 { |
969 maybe_print_line (line); | 990 maybe_print_line (line); |
970 if (angle_brackets) | 991 if (angle_brackets) |
1002 | 1023 |
1003 return 1; | 1024 return 1; |
1004 } | 1025 } |
1005 | 1026 |
1006 static void | 1027 static void |
1007 cb_used_define (cpp_reader *pfile, source_location line ATTRIBUTE_UNUSED, | 1028 cb_used_define (cpp_reader *pfile, location_t line ATTRIBUTE_UNUSED, |
1008 cpp_hashnode *node) | 1029 cpp_hashnode *node) |
1009 { | 1030 { |
1010 gfc_cpp_macro_queue *q; | 1031 gfc_cpp_macro_queue *q; |
1011 q = XNEW (gfc_cpp_macro_queue); | 1032 q = XNEW (gfc_cpp_macro_queue); |
1012 q->macro = xstrdup ((const char *) cpp_macro_definition (pfile, node)); | 1033 q->macro = xstrdup ((const char *) cpp_macro_definition (pfile, node)); |
1085 fprintf (print.outf, "# 1 \"%s//\"\n", to_file_quoted); | 1106 fprintf (print.outf, "# 1 \"%s//\"\n", to_file_quoted); |
1086 } | 1107 } |
1087 | 1108 |
1088 /* Copy a #pragma directive to the preprocessed output. */ | 1109 /* Copy a #pragma directive to the preprocessed output. */ |
1089 static void | 1110 static void |
1090 cb_def_pragma (cpp_reader *pfile, source_location line) | 1111 cb_def_pragma (cpp_reader *pfile, location_t line) |
1091 { | 1112 { |
1092 maybe_print_line (line); | 1113 maybe_print_line (line); |
1093 fputs ("#pragma ", print.outf); | 1114 fputs ("#pragma ", print.outf); |
1094 cpp_output_line (pfile, print.outf); | 1115 cpp_output_line (pfile, print.outf); |
1095 print.src_line++; | 1116 print.src_line++; |
1096 } | 1117 } |
1097 | 1118 |
1098 static void | 1119 static void |
1099 cb_used_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, | 1120 cb_used_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, |
1100 source_location line ATTRIBUTE_UNUSED, | 1121 location_t line ATTRIBUTE_UNUSED, |
1101 cpp_hashnode *node) | 1122 cpp_hashnode *node) |
1102 { | 1123 { |
1103 gfc_cpp_macro_queue *q; | 1124 gfc_cpp_macro_queue *q; |
1104 q = XNEW (gfc_cpp_macro_queue); | 1125 q = XNEW (gfc_cpp_macro_queue); |
1105 q->macro = xstrdup ((const char *) NODE_NAME (node)); | 1126 q->macro = xstrdup ((const char *) NODE_NAME (node)); |