comparison gcc/c-parser.c @ 80:d8bf5c8fdea8

fix comments
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 24 Sep 2011 02:41:02 +0900
parents 6381ea127240
children dbfc0d2dde36 895e19fe9c22
comparison
equal deleted inserted replaced
79:b0f061ae1da0 80:d8bf5c8fdea8
6177 static tree 6177 static tree
6178 cbc_finish_nested_function (location_t loc, tree label, tree retval_decl) 6178 cbc_finish_nested_function (location_t loc, tree label, tree retval_decl)
6179 { 6179 {
6180 6180
6181 /* add statement below. 6181 /* add statement below.
6182 * void __return_func(int _retval, void *_envp){ 6182 * void ___cbc_internal_return(int _retval, void *_envp){
6183 * retval = _retval; 6183 * retval = _retval;
6184 * goto exit0; 6184 * goto exit0;
6185 * } 6185 * }
6186 */ 6186 */
6187 /* TODO: 6187 /* TODO:
6204 _retval_decl = build_decl (loc, PARM_DECL, get_identifier ("_retval"), TREE_TYPE(retval_decl)); 6204 _retval_decl = build_decl (loc, PARM_DECL, get_identifier ("_retval"), TREE_TYPE(retval_decl));
6205 DECL_SOURCE_LOCATION (_retval_decl) = loc; 6205 DECL_SOURCE_LOCATION (_retval_decl) = loc;
6206 DECL_ARTIFICIAL (_retval_decl) = 1; 6206 DECL_ARTIFICIAL (_retval_decl) = 1;
6207 DECL_ARG_TYPE (_retval_decl) = TREE_TYPE(retval_decl); 6207 DECL_ARG_TYPE (_retval_decl) = TREE_TYPE(retval_decl);
6208 pushdecl (_retval_decl); 6208 pushdecl (_retval_decl);
6209 finish_decl (_retval_decl, loc, NULL_TREE, NULL_TREE, NULL_TREE); 6209 finish_decl (_retval_decl, loc, NULL_TREE, NULL_TREE, NULL_TREE);
6210
6211 _envp_decl = build_decl (loc, PARM_DECL, get_identifier ("_envp"), ptr_type_node); 6210 _envp_decl = build_decl (loc, PARM_DECL, get_identifier ("_envp"), ptr_type_node);
6212 DECL_SOURCE_LOCATION (_envp_decl) = loc; 6211 DECL_SOURCE_LOCATION (_envp_decl) = loc;
6213 DECL_ARTIFICIAL (_envp_decl) = 1; 6212 DECL_ARTIFICIAL (_envp_decl) = 1;
6214 DECL_ARG_TYPE (_envp_decl) = ptr_type_node; 6213 DECL_ARG_TYPE (_envp_decl) = ptr_type_node;
6215 pushdecl (_envp_decl); 6214 pushdecl (_envp_decl);
6705 } 6704 }
6706 break; 6705 break;
6707 case RID_CbC_RET: 6706 case RID_CbC_RET:
6708 case RID_RETURN: 6707 case RID_RETURN:
6709 6708
6710 #if 0
6711 if (cbc_return_f==0)
6712 { tree retval;
6713
6714 /*
6715 Generates something like...
6716
6717 int retval = 1;
6718 void (*ret)(int retval_,void *fp) ;
6719
6720 ret = ({
6721 __label__ exit0;
6722 volatile static flag = 0;
6723 void __return_func(int retval_,void *fp) {
6724 retval = retval_;
6725 goto exit0;
6726 }
6727 if (flag) {
6728 exit0:
6729 printf("f1: fp = 0x%x\n",__builtin_frame_address(0));
6730 return retval;
6731 }
6732 __return_func;
6733 });
6734
6735 */
6736
6737 tree stmt = c_begin_stmt_expr ();
6738 cbc_return_f = c_parser_peek_token (parser)->value;
6739 cbc_return = c_parser_peek_token (parser)->location;
6740 c_parser_consume_token (parser);
6741 location_t next = c_parser_peek_token (parser)->location;
6742
6743 // dummy variable for hidden condition
6744 struct c_expr cexpr;
6745 tree cond;
6746 location_t loc;
6747 loc = next;
6748 tree decl_cond =
6749 build_decl (VAR_DECL, get_identifier ("__return"),
6750 intHI_type_node);
6751 TREE_STATIC (decl_cond) = 1;
6752 cexpr.value = lang_hooks.decls.pushdecl(decl_cond);
6753
6754 cexpr.original_code = ERROR_MARK;
6755 cond = c_objc_common_truthvalue_conversion(loc, cexpr.value);
6756 if (EXPR_P (cond))
6757 SET_EXPR_LOCATION (cond, loc);
6758
6759
6760
6761
6762 tree fwlabel = create_artificial_label ();
6763 //TREE_USED(fwlabel) = 1;
6764
6765 //add_stmt (build1 (GOTO_EXPR, void_type_node, fwlabel));
6766 tree block = c_begin_compound_stmt (flag_isoc99);
6767
6768 tree tlab = lookup_label(cbc_return_f);
6769
6770 tree decl= build_stmt (LABEL_EXPR, tlab);
6771 //TREE_USED(decl) = 1;
6772 add_stmt(decl);
6773
6774 //tree hoge = build_int_cst(NULL_TREE,55);
6775 retval = build_component_ref (cbc_env, get_identifier("retval"));
6776 tree ret = c_finish_return (retval);
6777 TREE_USED(ret) = 1;
6778 tree first_body = c_end_compound_stmt (block, flag_isoc99);
6779
6780 c_finish_if_stmt (loc, cond, first_body, NULL_TREE, false);
6781
6782 // define_label(EXPR_LOCATION(decl) ,cbc_return_f);
6783 return_label1 =
6784 define_label(cbc_return ,cbc_return_f);
6785 tree fwdef= build_stmt (LABEL_EXPR, fwlabel);
6786
6787 //TREE_USED(fwdef) = 1;
6788 add_stmt(fwdef);
6789 TREE_SIDE_EFFECTS (block) = 1;
6790
6791 // tree label = lookup_label(c_parser_peek_token (parser)->value);
6792 //TREE_USED(label) = 1;
6793
6794 tree value = build1(ADDR_EXPR, ptr_type_node, return_label1);
6795 SET_EXPR_LOCATION (value, next);
6796 TREE_SIDE_EFFECTS (value) = 1;
6797 add_stmt(value);
6798
6799 TREE_SIDE_EFFECTS (stmt) = 1;
6800 expr.value = c_finish_stmt_expr (stmt);
6801 expr.original_code = ERROR_MARK;
6802
6803
6804 }
6805 else
6806 {
6807 //tree label = lookup_label(c_parser_peek_token (parser)->value);
6808 //TREE_USED(label) = 1;
6809 //expr.value = build1(ADDR_EXPR, ptr_type_node, label);
6810 expr.value = build1(ADDR_EXPR, ptr_type_node, return_label1);
6811 c_parser_consume_token (parser);
6812 }
6813 #else //by KENT.
6814 { 6709 {
6815 /* 6710 /*
6816 ({ 6711 ({
6817 __label__ _cbc_exit0; 6712 __label__ _cbc_exit0;
6818 void __return_func(int retval_, void *_envp){ 6713 int retval; // should be thread local
6819 retval = retval_; 6714 void _cbc_internal_return(int retval_, void *_envp){
6820 goto exit0; 6715 retval = retval_;
6716 goto _cbc_exit0;
6821 } 6717 }
6822 if (0) { 6718 if (0) {
6823 _cbc_exit0: 6719 _cbc_exit0:
6824 return retval; 6720 return retval;
6825 } 6721 }
6826 __return_func; 6722 __return_func;
6827 }); 6723 });
6828 */ 6724 */
6829 tree value, stmt, label, tlab, decl; 6725 tree value, stmt, label, tlab, decl;
6856 6752
6857 /* get pointer to nested function. */ 6753 /* get pointer to nested function. */
6858 value = build_addr (decl , current_function_decl); 6754 value = build_addr (decl , current_function_decl);
6859 SET_EXPR_LOCATION (value, location); 6755 SET_EXPR_LOCATION (value, location);
6860 add_stmt (value); 6756 add_stmt (value);
6861 /*value = build_external_ref (get_identifier("_cbc_internal_return"), false, location);*/
6862 /*value = build_unary_op (location, ADDR_EXPR, value, 0);*/
6863 /*add_stmt (value);*/
6864 6757
6865 TREE_SIDE_EFFECTS (stmt) = 1; 6758 TREE_SIDE_EFFECTS (stmt) = 1;
6866 expr.value = c_finish_stmt_expr (location, stmt); 6759 expr.value = c_finish_stmt_expr (location, stmt);
6867 expr.original_code = ERROR_MARK; 6760 expr.original_code = ERROR_MARK;
6868 } 6761 }
6869 6762
6870 #endif //0
6871 break; 6763 break;
6872 #endif //noCbC 6764 #endif //noCbC
6873 6765
6874 default: 6766 default:
6875 c_parser_error (parser, "expected expression"); 6767 c_parser_error (parser, "expected expression");