Mercurial > hg > CbC > CbC_gcc
comparison gcc/c-parser.c @ 15:11a6cbe2d14c
The configure script which is produced from configure.ac was changed.
but this script cannot be generated in this repository.
You can use GCC's original subversion repository to generate it.
See CbC-memo.ja.
And _CbC_return's nested function was made supporting any
return type.
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 24 Sep 2009 12:44:28 +0900 |
parents | be566c4d18c5 |
children | 9de9dad105d4 |
comparison
equal
deleted
inserted
replaced
14:b95e5760e707 | 15:11a6cbe2d14c |
---|---|
57 #include "vec.h" | 57 #include "vec.h" |
58 #include "target.h" | 58 #include "target.h" |
59 #include "cgraph.h" | 59 #include "cgraph.h" |
60 #ifndef noCbC | 60 #ifndef noCbC |
61 #include "cbc-tree.h" | 61 #include "cbc-tree.h" |
62 static tree cbc_finish_nested_function (location_t, tree); | |
63 static void cbc_finish_labeled_goto (location_t, tree); | |
64 #endif | 62 #endif |
65 | 63 |
66 | 64 |
67 /* Initialization routine for this file. */ | 65 /* Initialization routine for this file. */ |
68 | 66 |
5186 @protocol ( identifier ) | 5184 @protocol ( identifier ) |
5187 @encode ( type-name ) | 5185 @encode ( type-name ) |
5188 objc-string-literal | 5186 objc-string-literal |
5189 */ | 5187 */ |
5190 | 5188 |
5189 static void | |
5190 cbc_finish_labeled_goto (location_t loc, tree label) | |
5191 { | |
5192 /* add statement below. | |
5193 * | |
5194 * if (0) { | |
5195 * _cbc_exit0: | |
5196 * return retval; | |
5197 * } | |
5198 */ | |
5199 tree name; | |
5200 tree tlab; | |
5201 tree cond; | |
5202 tree retval; | |
5203 | |
5204 tree cstmt = c_begin_compound_stmt (true); | |
5205 | |
5206 tlab = define_label (loc, label); | |
5207 gcc_assert (tlab); | |
5208 decl_attributes (&tlab, NULL_TREE, 0); | |
5209 add_stmt (build_stmt (LABEL_EXPR, tlab)); | |
5210 | |
5211 retval = build_external_ref (get_identifier("retval"), false, loc); | |
5212 tree ret = c_finish_return (retval); | |
5213 TREE_USED(ret) = 1; | |
5214 | |
5215 cond = integer_zero_node; | |
5216 tree if_body = c_end_compound_stmt (cstmt, true); | |
5217 TREE_SIDE_EFFECTS (cstmt) = 1; | |
5218 c_finish_if_stmt (loc, cond, if_body, NULL_TREE, false); | |
5219 } | |
5220 | |
5221 static tree | |
5222 cbc_finish_nested_function (location_t loc, tree label, tree retval_decl) | |
5223 { | |
5224 | |
5225 /* add statement below. | |
5226 * void __return_func(int _retval, void *_envp){ | |
5227 * retval = _retval; | |
5228 * goto exit0; | |
5229 * } | |
5230 */ | |
5231 /* TODO: | |
5232 * retval(lhs)のTREE_DECLを引数から取得するように | |
5233 * int _retvalパラメータのタイプはretvalに合わせる | |
5234 */ | |
5235 | |
5236 tree fnbody; | |
5237 struct c_declarator *declarator; | |
5238 tree ident; | |
5239 struct c_arg_info *args; | |
5240 struct c_declspecs *specs; | |
5241 struct c_typespec t; | |
5242 { | |
5243 tree _retval_decl, _envp_decl; | |
5244 push_scope (); | |
5245 declare_parm_level (); | |
5246 //tree retval_type = TREE_TYPE(retval_decl); | |
5247 | |
5248 _retval_decl = build_decl (PARM_DECL, get_identifier ("_retval"), TREE_TYPE(retval_decl)); | |
5249 DECL_SOURCE_LOCATION (_retval_decl) = loc; | |
5250 DECL_ARG_TYPE (_retval_decl) = TREE_TYPE(retval_decl); | |
5251 pushdecl (_retval_decl); | |
5252 finish_decl (_retval_decl, NULL_TREE, NULL_TREE); | |
5253 | |
5254 _envp_decl = build_decl (PARM_DECL, get_identifier ("_envp"), ptr_type_node); | |
5255 DECL_SOURCE_LOCATION (_envp_decl) = loc; | |
5256 DECL_ARG_TYPE (_envp_decl) = ptr_type_node; | |
5257 pushdecl (_envp_decl); | |
5258 finish_decl (_envp_decl, NULL_TREE, NULL_TREE); | |
5259 | |
5260 args = get_parm_info(false); | |
5261 pop_scope(); | |
5262 } | |
5263 | |
5264 t.kind = ctsk_resword; | |
5265 t.spec = get_identifier("void"); | |
5266 specs = build_null_declspecs(); | |
5267 declspecs_add_type (specs, t); | |
5268 finish_declspecs (specs); | |
5269 | |
5270 /* make nested function. */ | |
5271 //ident = build_decl (/*TODO:*/VAR_DECL, get_identifier ("_cbc_internal_return"), specs->type); | |
5272 declarator = build_id_declarator (get_identifier ("_cbc_internal_return")); | |
5273 //declarator->id_loc = ; | |
5274 declarator = build_function_declarator (args, declarator); | |
5275 | |
5276 c_push_function_context (); | |
5277 | |
5278 if (!start_function (specs, declarator, NULL_TREE)) | |
5279 { | |
5280 c_pop_function_context(); | |
5281 gcc_assert (0); | |
5282 } | |
5283 store_parm_decls (); | |
5284 | |
5285 | |
5286 /* start compound statement. */ | |
5287 tree cstmt = c_begin_compound_stmt (true); | |
5288 | |
5289 //tree lhs = build_external_ref (get_identifier("retval"), false, loc); | |
5290 tree rhs = build_external_ref (get_identifier("_retval"), false, loc); | |
5291 add_stmt (build_modify_expr (loc, retval_decl, NOP_EXPR, rhs)); | |
5292 tree stmt = c_finish_goto_label (label); | |
5293 | |
5294 /* end compound statement. */ | |
5295 fnbody = c_end_compound_stmt (cstmt, true); | |
5296 TREE_SIDE_EFFECTS (cstmt) = 1; | |
5297 | |
5298 /* finish declaration of nested function. */ | |
5299 tree decl = current_function_decl; | |
5300 add_stmt (fnbody); | |
5301 finish_function (); | |
5302 c_pop_function_context (); | |
5303 | |
5304 add_stmt (build_stmt (DECL_EXPR, decl)); | |
5305 return decl; | |
5306 | |
5307 } | |
5308 | |
5191 static struct c_expr | 5309 static struct c_expr |
5192 c_parser_postfix_expression (c_parser *parser) | 5310 c_parser_postfix_expression (c_parser *parser) |
5193 { | 5311 { |
5194 struct c_expr expr, e1, e2, e3; | 5312 struct c_expr expr, e1, e2, e3; |
5195 struct c_type_name *t1, *t2; | 5313 struct c_type_name *t1, *t2; |
5741 add_stmt (build_stmt (DECL_EXPR, tlab)); | 5859 add_stmt (build_stmt (DECL_EXPR, tlab)); |
5742 | 5860 |
5743 /* declare retval. (int retval;) */ | 5861 /* declare retval. (int retval;) */ |
5744 tree decl_cond = | 5862 tree decl_cond = |
5745 build_decl (VAR_DECL, get_identifier ("retval"), | 5863 build_decl (VAR_DECL, get_identifier ("retval"), |
5746 intHI_type_node); | 5864 TREE_TYPE (TREE_TYPE (current_function_decl))); |
5747 TREE_STATIC (decl_cond) = 1; | 5865 TREE_STATIC (decl_cond) = 1; |
5748 pushdecl (decl_cond); | 5866 pushdecl (decl_cond); |
5749 | 5867 |
5750 /* define nested function. */ | 5868 /* define nested function. */ |
5751 decl = | 5869 decl = |
5752 cbc_finish_nested_function (location, label); | 5870 cbc_finish_nested_function (location, label, decl_cond); |
5753 //tree nested_func = cbc_make_nested_function (location); | 5871 //tree nested_func = cbc_make_nested_function (location); |
5754 | 5872 |
5755 /* define if-ed goto label and return statement. */ | 5873 /* define if-ed goto label and return statement. */ |
5756 cbc_finish_labeled_goto (location, label); | 5874 cbc_finish_labeled_goto (location, label); |
5757 | 5875 |
5798 expr.value = error_mark_node; | 5916 expr.value = error_mark_node; |
5799 expr.original_code = ERROR_MARK; | 5917 expr.original_code = ERROR_MARK; |
5800 break; | 5918 break; |
5801 } | 5919 } |
5802 return c_parser_postfix_expression_after_primary (parser, expr); | 5920 return c_parser_postfix_expression_after_primary (parser, expr); |
5803 } | |
5804 | |
5805 static void | |
5806 cbc_finish_labeled_goto (location_t loc, tree label) | |
5807 { | |
5808 /* add statement below. | |
5809 * | |
5810 * if (0) { | |
5811 * _cbc_exit0: | |
5812 * return retval; | |
5813 * } | |
5814 */ | |
5815 tree name; | |
5816 tree tlab; | |
5817 tree cond; | |
5818 tree retval; | |
5819 | |
5820 tree cstmt = c_begin_compound_stmt (true); | |
5821 | |
5822 tlab = define_label (loc, label); | |
5823 gcc_assert (tlab); | |
5824 decl_attributes (&tlab, NULL_TREE, 0); | |
5825 add_stmt (build_stmt (LABEL_EXPR, tlab)); | |
5826 | |
5827 retval = build_external_ref (get_identifier("retval"), false, loc); | |
5828 tree ret = c_finish_return (retval); | |
5829 TREE_USED(ret) = 1; | |
5830 | |
5831 cond = integer_zero_node; | |
5832 tree if_body = c_end_compound_stmt (cstmt, true); | |
5833 TREE_SIDE_EFFECTS (cstmt) = 1; | |
5834 c_finish_if_stmt (loc, cond, if_body, NULL_TREE, false); | |
5835 } | |
5836 | |
5837 static tree | |
5838 cbc_finish_nested_function (location_t loc, tree label) | |
5839 { | |
5840 | |
5841 /* add statement below. | |
5842 * void __return_func(int _retval, void *_envp){ | |
5843 * retval = _retval; | |
5844 * goto exit0; | |
5845 * } | |
5846 */ | |
5847 | |
5848 tree fnbody; | |
5849 struct c_declarator *declarator; | |
5850 tree ident; | |
5851 struct c_arg_info *args; | |
5852 struct c_declspecs *specs; | |
5853 struct c_typespec t; | |
5854 { | |
5855 tree _retval_decl, _envp_decl; | |
5856 push_scope (); | |
5857 declare_parm_level (); | |
5858 | |
5859 _retval_decl = build_decl (PARM_DECL, get_identifier ("_retval"), integer_type_node); | |
5860 DECL_SOURCE_LOCATION (_retval_decl) = loc; | |
5861 DECL_ARG_TYPE (_retval_decl) = integer_type_node; | |
5862 pushdecl (_retval_decl); | |
5863 finish_decl (_retval_decl, NULL_TREE, NULL_TREE); | |
5864 | |
5865 _envp_decl = build_decl (PARM_DECL, get_identifier ("_envp"), ptr_type_node); | |
5866 DECL_SOURCE_LOCATION (_envp_decl) = loc; | |
5867 DECL_ARG_TYPE (_envp_decl) = ptr_type_node; | |
5868 pushdecl (_envp_decl); | |
5869 finish_decl (_envp_decl, NULL_TREE, NULL_TREE); | |
5870 | |
5871 args = get_parm_info(false); | |
5872 pop_scope(); | |
5873 } | |
5874 | |
5875 t.kind = ctsk_resword; | |
5876 t.spec = get_identifier("void"); | |
5877 specs = build_null_declspecs(); | |
5878 declspecs_add_type (specs, t); | |
5879 finish_declspecs (specs); | |
5880 | |
5881 /* make nested function. */ | |
5882 //ident = build_decl (/*TODO:*/VAR_DECL, get_identifier ("_cbc_internal_return"), specs->type); | |
5883 declarator = build_id_declarator (get_identifier ("_cbc_internal_return")); | |
5884 //declarator->id_loc = ; | |
5885 declarator = build_function_declarator (args, declarator); | |
5886 | |
5887 c_push_function_context (); | |
5888 | |
5889 if (!start_function (specs, declarator, NULL_TREE)) | |
5890 { | |
5891 c_pop_function_context(); | |
5892 gcc_assert (0); | |
5893 } | |
5894 store_parm_decls (); | |
5895 | |
5896 | |
5897 /* start compound statement. */ | |
5898 tree cstmt = c_begin_compound_stmt (true); | |
5899 | |
5900 tree lhs = build_external_ref (get_identifier("retval"), false, loc); | |
5901 tree rhs = build_external_ref (get_identifier("_retval"), false, loc); | |
5902 add_stmt (build_modify_expr (loc, lhs, NOP_EXPR, rhs)); | |
5903 tree stmt = c_finish_goto_label (label); | |
5904 | |
5905 /* end compound statement. */ | |
5906 fnbody = c_end_compound_stmt (cstmt, true); | |
5907 TREE_SIDE_EFFECTS (cstmt) = 1; | |
5908 | |
5909 /* finish declaration of nested function. */ | |
5910 tree decl = current_function_decl; | |
5911 add_stmt (fnbody); | |
5912 finish_function (); | |
5913 c_pop_function_context (); | |
5914 | |
5915 add_stmt (build_stmt (DECL_EXPR, decl)); | |
5916 return decl; | |
5917 | |
5918 } | 5921 } |
5919 | 5922 |
5920 /* Parse a postfix expression after a parenthesized type name: the | 5923 /* Parse a postfix expression after a parenthesized type name: the |
5921 brace-enclosed initializer of a compound literal, possibly followed | 5924 brace-enclosed initializer of a compound literal, possibly followed |
5922 by some postfix operators. This is separate because it is not | 5925 by some postfix operators. This is separate because it is not |