Mercurial > hg > CbC > CbC_gcc
comparison gcc/c/c-parser.c @ 114:e234ee7b7292
fix c-parser.c
author | mir3636 |
---|---|
date | Fri, 17 Nov 2017 19:25:43 +0900 |
parents | bdf41c9fa0b7 |
children | 4cb7a319550d |
comparison
equal
deleted
inserted
replaced
113:bdf41c9fa0b7 | 114:e234ee7b7292 |
---|---|
2769 t.spec = c_parser_peek_token (parser)->value; | 2769 t.spec = c_parser_peek_token (parser)->value; |
2770 declspecs_add_type (loc, specs, t); | 2770 declspecs_add_type (loc, specs, t); |
2771 | 2771 |
2772 if(!TARGET_64BIT) { | 2772 if(!TARGET_64BIT) { |
2773 attrs = build_tree_list (get_identifier("fastcall"), NULL_TREE); | 2773 attrs = build_tree_list (get_identifier("fastcall"), NULL_TREE); |
2774 declspecs_add_attrs(specs, attrs); | 2774 declspecs_add_attrs(loc, specs, attrs); |
2775 } | 2775 } |
2776 | 2776 |
2777 c_parser_consume_token (parser); | 2777 c_parser_consume_token (parser); |
2778 break; | 2778 break; |
2779 #endif | 2779 #endif |
5495 | 5495 |
5496 IF_P is used to track whether there's a (possibly labeled) if statement | 5496 IF_P is used to track whether there's a (possibly labeled) if statement |
5497 which is not enclosed in braces and has an else clause. This is used to | 5497 which is not enclosed in braces and has an else clause. This is used to |
5498 implement -Wparentheses. */ | 5498 implement -Wparentheses. */ |
5499 | 5499 |
5500 static tree | |
5501 cbc_replace_arguments (location_t loc, tree call) | |
5502 { | |
5503 tree arg; | |
5504 tree fn; | |
5505 tree tmp_decl; | |
5506 int i=0; | |
5507 call_expr_arg_iterator iter; | |
5508 | |
5509 fn = CALL_EXPR_FN (call); | |
5510 if ( TREE_CODE (fn)==PARM_DECL || !TREE_CONSTANT (fn) ) | |
5511 { | |
5512 tmp_decl = build_decl (loc, VAR_DECL, NULL_TREE, TREE_TYPE(fn)); | |
5513 pushdecl (tmp_decl); | |
5514 | |
5515 add_stmt (build_modify_expr (loc, tmp_decl, NULL_TREE, NOP_EXPR, loc, fn, NULL_TREE)); | |
5516 CALL_EXPR_FN (call) = tmp_decl; | |
5517 } | |
5518 | |
5519 FOR_EACH_CALL_EXPR_ARG (arg, iter, call) | |
5520 { | |
5521 /* if ( !CONSTANT_CLASS_P (arg) && !VAR_OR_FUNCTION_DECL_P (arg) ) */ | |
5522 if ( TREE_CODE (arg)==PARM_DECL || !TREE_CONSTANT (arg) ) | |
5523 { | |
5524 tmp_decl = build_decl (loc, VAR_DECL, NULL_TREE, TREE_TYPE(arg)); | |
5525 pushdecl (tmp_decl); | |
5526 | |
5527 add_stmt (build_modify_expr (loc, tmp_decl, NULL_TREE, NOP_EXPR, loc, arg, NULL_TREE)); | |
5528 CALL_EXPR_ARG (call, i) = tmp_decl; | |
5529 } | |
5530 i++; | |
5531 } | |
5532 | |
5533 return call; | |
5534 } | |
5535 | |
5500 static void | 5536 static void |
5501 c_parser_statement_after_labels (c_parser *parser, bool *if_p, | 5537 c_parser_statement_after_labels (c_parser *parser, bool *if_p, |
5502 vec<tree> *chain) | 5538 vec<tree> *chain) |
5503 { | 5539 { |
5540 #ifndef noCbC | |
5541 struct c_expr expr; | |
5542 #endif | |
5504 location_t loc = c_parser_peek_token (parser)->location; | 5543 location_t loc = c_parser_peek_token (parser)->location; |
5505 tree stmt = NULL_TREE; | 5544 tree stmt = NULL_TREE; |
5506 bool in_if_block = parser->in_if_block; | 5545 bool in_if_block = parser->in_if_block; |
5507 parser->in_if_block = false; | 5546 parser->in_if_block = false; |
5508 if (if_p != NULL) | 5547 if (if_p != NULL) |
7948 @protocol ( identifier ) | 7987 @protocol ( identifier ) |
7949 @encode ( type-name ) | 7988 @encode ( type-name ) |
7950 objc-string-literal | 7989 objc-string-literal |
7951 Classname . identifier | 7990 Classname . identifier |
7952 */ | 7991 */ |
7992 | |
7993 static void | |
7994 cbc_finish_labeled_goto (location_t loc, tree label, tree retval) | |
7995 { | |
7996 /* add statement below. | |
7997 * | |
7998 * if (0) { | |
7999 * _cbc_exit0: | |
8000 * return retval; | |
8001 * } | |
8002 */ | |
8003 tree tlab; | |
8004 tree cond; | |
8005 | |
8006 cond = integer_zero_node; | |
8007 tree block_outside = c_begin_compound_stmt (false); | |
8008 tree block_inside = c_begin_compound_stmt (false); | |
8009 | |
8010 tree stmt = c_begin_compound_stmt (true); | |
8011 tlab = define_label (loc, label); | |
8012 gcc_assert (tlab); | |
8013 decl_attributes (&tlab, NULL_TREE, 0); | |
8014 TREE_USED (tlab) = 1; | |
8015 /* add_stmt (LABEL_EXPR) */ | |
8016 add_stmt (build_stmt (loc, LABEL_EXPR, tlab)); | |
8017 | |
8018 /* add_stmt (RETURN_EXPR) */ | |
8019 tree ret = c_finish_return (loc, retval, retval); | |
8020 DECL_READ_P(retval) = 1; // (NODE)->decl_common.decl_read_flag = 1; | |
8021 // TREE_USED(ret) = 1; | |
8022 tree stmt_body = c_end_compound_stmt (loc, stmt, true); | |
8023 | |
8024 /* add_stmt (STATEMENT_LIST) : STATEMENT_LIST -> LABEL_EXPR -> RETURN_EXPR */ | |
8025 add_stmt (stmt_body); | |
8026 | |
8027 tree body = c_end_compound_stmt (loc, block_inside, false); | |
8028 | |
8029 /* add_stmt (COND_EXPR) */ | |
8030 c_finish_if_stmt (loc, cond, body, NULL_TREE); | |
8031 | |
8032 /* add_stmt (BIND_EXPR) : BIND_EXPR -> COND_EXPR -> STATEMENT_LIST */ | |
8033 tree bind = c_end_compound_stmt (loc, block_outside, false); | |
8034 TREE_SIDE_EFFECTS (bind) = 1; | |
8035 add_stmt (bind); | |
8036 | |
8037 TREE_USED (retval) = 1; | |
8038 | |
8039 } | |
8040 static tree | |
8041 cbc_finish_nested_function (location_t loc, tree label, tree retval_decl) | |
8042 { | |
8043 | |
8044 /* add statement below. | |
8045 * void ___cbc_internal_return(int _retval, void *_envp){ | |
8046 * retval = _retval; | |
8047 * goto exit0; | |
8048 * } | |
8049 */ | |
8050 /* TODO: | |
8051 * retval(lhs)のTREE_DECLを引数から取得するように | |
8052 * int _retvalパラメータのタイプはretvalに合わせる | |
8053 */ | |
8054 | |
8055 tree fnbody; | |
8056 tree _retval_decl, _envp_decl; | |
8057 struct c_declarator *declarator; | |
8058 //tree ident; | |
8059 struct c_arg_info *args; | |
8060 struct c_declspecs *specs; | |
8061 struct c_typespec t; | |
8062 { | |
8063 tree expr; | |
8064 push_scope (); | |
8065 declare_parm_level (); | |
8066 /*tree retval_type = TREE_TYPE(retval_decl);*/ | |
8067 | |
8068 _retval_decl = build_decl (loc, PARM_DECL, get_identifier ("_retval"), TREE_TYPE(retval_decl)); | |
8069 DECL_SOURCE_LOCATION (_retval_decl) = loc; | |
8070 DECL_ARTIFICIAL (_retval_decl) = 1; | |
8071 DECL_ARG_TYPE (_retval_decl) = TREE_TYPE(retval_decl); | |
8072 pushdecl (_retval_decl); | |
8073 finish_decl (_retval_decl, loc, NULL_TREE, NULL_TREE, NULL_TREE); | |
8074 _envp_decl = build_decl (loc, PARM_DECL, get_identifier ("_envp"), ptr_type_node); | |
8075 DECL_SOURCE_LOCATION (_envp_decl) = loc; | |
8076 DECL_ARTIFICIAL (_envp_decl) = 1; | |
8077 DECL_ARG_TYPE (_envp_decl) = ptr_type_node; | |
8078 pushdecl (_envp_decl); | |
8079 finish_decl (_envp_decl, loc, NULL_TREE, NULL_TREE, NULL_TREE); | |
8080 struct c_declarator declarator; | |
8081 struct c_parm* parm; | |
8082 struct c_declspecs *specs_parm = build_null_declspecs(); | |
8083 declspecs_add_type (loc, specs_parm, TREE_TYPE(retval_decl)); | |
8084 finish_declspecs (specs_parm); | |
8085 parm = build_c_parm (specs_parm, NULL_TREE, | |
8086 &declarator, loc); | |
8087 | |
8088 args = get_parm_info(false, expr); | |
8089 pop_scope(); | |
8090 } | |
8091 | |
8092 t.kind = ctsk_resword; | |
8093 t.spec = get_identifier("void"); | |
8094 specs = build_null_declspecs(); | |
8095 declspecs_add_type (loc, specs, t); | |
8096 finish_declspecs (specs); | |
8097 | |
8098 /* make nested function. */ | |
8099 declarator = build_id_declarator (get_identifier ("_cbc_internal_return")); | |
8100 declarator = build_function_declarator (args, declarator); | |
8101 | |
8102 c_push_function_context (); | |
8103 | |
8104 if (!start_function (specs, declarator, NULL_TREE)) | |
8105 { | |
8106 c_pop_function_context(); | |
8107 gcc_assert (0); | |
8108 } | |
8109 store_parm_decls (); | |
8110 | |
8111 | |
8112 /* start compound statement. */ | |
8113 tree cstmt = c_begin_compound_stmt (true); | |
8114 | |
8115 add_stmt (build_modify_expr (loc, retval_decl, NULL_TREE, NOP_EXPR, loc, _retval_decl, NULL_TREE)); | |
8116 tree stmt = c_finish_goto_label (loc, label); | |
8117 | |
8118 /* end compound statement. */ | |
8119 fnbody = c_end_compound_stmt (loc, cstmt, true); | |
8120 TREE_SIDE_EFFECTS (cstmt) = 1; | |
8121 | |
8122 /* finish declaration of nested function. */ | |
8123 tree decl = current_function_decl; | |
8124 add_stmt (fnbody); | |
8125 finish_function (); | |
8126 c_pop_function_context (); | |
8127 | |
8128 add_stmt (build_stmt (loc, DECL_EXPR, decl)); | |
8129 return decl; | |
8130 | |
8131 } | |
7953 | 8132 |
7954 static struct c_expr | 8133 static struct c_expr |
7955 c_parser_postfix_expression (c_parser *parser) | 8134 c_parser_postfix_expression (c_parser *parser) |
7956 { | 8135 { |
7957 struct c_expr expr, e1; | 8136 struct c_expr expr, e1; |
8624 TREE_TYPE (TREE_TYPE (current_function_decl))); | 8803 TREE_TYPE (TREE_TYPE (current_function_decl))); |
8625 TREE_STATIC (decl_cond) = 1; | 8804 TREE_STATIC (decl_cond) = 1; |
8626 TREE_USED (decl_cond) = 1; | 8805 TREE_USED (decl_cond) = 1; |
8627 | 8806 |
8628 /* Use thread-local */ | 8807 /* Use thread-local */ |
8629 DECL_TLS_MODEL (decl_cond) = decl_default_tls_model (decl_cond); | 8808 //DECL_TLS_MODEL (decl_cond) = decl_default_tls_model (decl_cond); |
8809 set_decl_tls_model (decl_cond, decl_default_tls_model (decl_cond)); | |
8630 DECL_NONLOCAL (decl_cond) = 1; | 8810 DECL_NONLOCAL (decl_cond) = 1; |
8631 DECL_ARTIFICIAL (decl_cond) = 1; | 8811 DECL_ARTIFICIAL (decl_cond) = 1; |
8632 add_stmt (build_stmt(location, DECL_EXPR, pushdecl (decl_cond))); | 8812 add_stmt (build_stmt(location, DECL_EXPR, pushdecl (decl_cond))); |
8633 | 8813 |
8634 /* define nested function. */ | 8814 /* define nested function. */ |
8639 | 8819 |
8640 /* define if-ed goto label and return statement. */ | 8820 /* define if-ed goto label and return statement. */ |
8641 cbc_finish_labeled_goto (location, label, decl_cond); | 8821 cbc_finish_labeled_goto (location, label, decl_cond); |
8642 | 8822 |
8643 /* get pointer to nested function. */ | 8823 /* get pointer to nested function. */ |
8644 value = build_addr (decl , current_function_decl); | 8824 //value = build_addr (decl , current_function_decl); |
8825 value = build_addr (decl); | |
8645 TREE_USED (current_function_decl) = 1; | 8826 TREE_USED (current_function_decl) = 1; |
8646 SET_EXPR_LOCATION (value, location); | 8827 SET_EXPR_LOCATION (value, location); |
8647 add_stmt (value); | 8828 add_stmt (value); |
8648 | 8829 |
8649 TREE_SIDE_EFFECTS (stmt) = 1; | 8830 TREE_SIDE_EFFECTS (stmt) = 1; |