Advertisement

このページを編集する際は,編集に関する方針に従ってください.

概要

コメント GENERICへの遠い道のり

finish_functionを呼び出し、そのなかで、c-genericizeを呼ぶ

引数

実装

1128 static void
1129 c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok,
1130                                bool nested, bool start_attr_ok)
1131 {
1132   struct c_declspecs *specs;
1133   tree prefix_attrs;
1134   tree all_prefix_attrs;
1135   bool diagnosed_no_specs = false;
1136   specs = build_null_declspecs ();
1137   c_parser_declspecs (parser, specs, true, true, start_attr_ok);
1138   if (parser->error)
1139     {
1140       c_parser_skip_to_end_of_block_or_statement (parser);
1141       return;
1142     }
1143   if (nested && !specs->declspecs_seen_p)
1144     {
1145       c_parser_error (parser, "expected declaration specifiers");
1146       c_parser_skip_to_end_of_block_or_statement (parser);
1147       return;
1148     }
1149   finish_declspecs (specs);
1150   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1151     {
1152       if (empty_ok)
1153         shadow_tag (specs);
1154       else
1155         {
1156           shadow_tag_warned (specs, 1);
1157           pedwarn ("empty declaration");
1158         }
1159       c_parser_consume_token (parser);
1160       return;
1161     }
1162   pending_xref_error ();
1163   prefix_attrs = specs->attrs;
1164   all_prefix_attrs = prefix_attrs;
1165   specs->attrs = NULL_TREE;
1166   while (true)
1167     {
1168       struct c_declarator *declarator;
1169       bool dummy = false;
1170       tree fnbody;
1171       /* Declaring either one or more declarators (in which case we
1172          should diagnose if there were no declaration specifiers) or a
1173          function definition (in which case the diagnostic for
1174          implicit int suffices).  */
1175       declarator = c_parser_declarator (parser, specs->type_seen_p,
1176                                         C_DTR_NORMAL, &dummy);
1177       if (declarator == NULL)
1178         {
1179           c_parser_skip_to_end_of_block_or_statement (parser);
1180           return;
1181         }
1182       if (c_parser_next_token_is (parser, CPP_EQ)
1183           || c_parser_next_token_is (parser, CPP_COMMA)
1184           || c_parser_next_token_is (parser, CPP_SEMICOLON)
1185           || c_parser_next_token_is_keyword (parser, RID_ASM)
1186           || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1187         {
1188           tree asm_name = NULL_TREE;
1189           tree postfix_attrs = NULL_TREE;
1190           if (!diagnosed_no_specs && !specs->declspecs_seen_p)
1191             {
1192               diagnosed_no_specs = true;
1193               pedwarn ("data definition has no type or storage class");
1194             }
1195           /* Having seen a data definition, there cannot now be a
1196              function definition.  */
1197           fndef_ok = false;
1198           if (c_parser_next_token_is_keyword (parser, RID_ASM))
1199             asm_name = c_parser_simple_asm_expr (parser);
1200           if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1201             postfix_attrs = c_parser_attributes (parser);
1202           if (c_parser_next_token_is (parser, CPP_EQ))
1203             {
1204               tree d;
1205               struct c_expr init;
1206               c_parser_consume_token (parser);
1207               /* The declaration of the variable is in effect while
1208                  its initializer is parsed.  */
1209               d = start_decl (declarator, specs, true,
1210                               chainon (postfix_attrs, all_prefix_attrs));
1211               if (!d)
1212                 d = error_mark_node;
1213               start_init (d, asm_name, global_bindings_p ());
1214               init = c_parser_initializer (parser);
1215               finish_init ();
1216               if (d != error_mark_node)
1217                 {
1218                   maybe_warn_string_init (TREE_TYPE (d), init);
1219                   finish_decl (d, init.value, asm_name);
1220                 }
1221             }
1222           else
1223             {
1224               tree d = start_decl (declarator, specs, false,
1225                                    chainon (postfix_attrs,
1226                                             all_prefix_attrs));
1227               if (d)
1228                 finish_decl (d, NULL_TREE, asm_name);
1229             }
1230           if (c_parser_next_token_is (parser, CPP_COMMA))
1231             {
1232               c_parser_consume_token (parser);
1233               if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
1234                 all_prefix_attrs = chainon (c_parser_attributes (parser),
1235                                             prefix_attrs);
1236               else
1237                 all_prefix_attrs = prefix_attrs;
1238               continue;
1239             }
1240           else if (c_parser_next_token_is (parser, CPP_SEMICOLON))
1241             {
1242               c_parser_consume_token (parser);
1243               return;
1244             }
1245           else
1246             {
1247               c_parser_error (parser, "expected %<,%> or %<;%>");
1248               c_parser_skip_to_end_of_block_or_statement (parser);
1249               return;
1250             }
1251         }
1252       else if (!fndef_ok)
1253         {
1254           c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, "
1255                           "%<asm%> or %<__attribute__%>");
1256           c_parser_skip_to_end_of_block_or_statement (parser);
1257           return;
1258         }
1259       /* Function definition (nested or otherwise).  */
1260       if (nested)
1261         {
1262           if (pedantic)
1263             pedwarn ("ISO C forbids nested functions");
1264           push_function_context ();
1265         }
1266       if (!start_function (specs, declarator, all_prefix_attrs))
1267         {
1268           /* This can appear in many cases looking nothing like a
1269              function definition, so we don't give a more specific
1270              error suggesting there was one.  */
1271           c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
1272                           "or %<__attribute__%>");
1273           if (nested)
1274             pop_function_context ();
1275           break;
1276         }
1277       /* Parse old-style parameter declarations.  ??? Attributes are
1278          not allowed to start declaration specifiers here because of a
1279          syntax conflict between a function declaration with attribute
1280          suffix and a function definition with an attribute prefix on
1281          first old-style parameter declaration.  Following the old
1282          parser, they are not accepted on subsequent old-style
1283          parameter declarations either.  However, there is no
1284          ambiguity after the first declaration, nor indeed on the
1285          first as long as we don't allow postfix attributes after a
1286          declarator with a nonempty identifier list in a definition;
1287          and postfix attributes have never been accepted here in
1288          function definitions either.  */
1289       while (c_parser_next_token_is_not (parser, CPP_EOF)
1290              && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE))
1291         c_parser_declaration_or_fndef (parser, false, false, true, false);
1292       DECL_SOURCE_LOCATION (current_function_decl)
1293         = c_parser_peek_token (parser)->location;
1294       store_parm_decls ();
1295       fnbody = c_parser_compound_statement (parser);
1296       if (nested)
1297         {
1298           tree decl = current_function_decl;
1299           add_stmt (fnbody);
1300           finish_function ();
1301           pop_function_context ();
1302           add_stmt (build_stmt (DECL_EXPR, decl));
1303         }
1304       else
1305         {
1306           add_stmt (fnbody);
1307           finish_function ();
1308         }
1309       break;
1310     }
1311 }
1312 



リンク元

特に記載のない限り、コミュニティのコンテンツはCC-BY-SAライセンスの下で利用可能です。