| ... | ... | @@ -796,34 +796,33 @@ static Token *ast_eat_token(ParseContext *pc, int *token_index, TokenId token_id |
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | |
| 799 | | static AstNode *ast_parse_directive(ParseContext *pc, int token_index, int *new_token_index) { |
| 800 | | Token *number_sign = &pc->tokens->at(token_index); |
| 801 | | token_index += 1; |
| 799 | static AstNode *ast_parse_directive(ParseContext *pc, int *token_index) { |
| 800 | Token *number_sign = &pc->tokens->at(*token_index); |
| 801 | *token_index += 1; |
| 802 | 802 | ast_expect_token(pc, number_sign, TokenIdNumberSign); |
| 803 | 803 | |
| 804 | 804 | AstNode *node = ast_create_node(pc, NodeTypeDirective, number_sign); |
| 805 | 805 | |
| 806 | | Token *name_symbol = &pc->tokens->at(token_index); |
| 807 | | token_index += 1; |
| 806 | Token *name_symbol = &pc->tokens->at(*token_index); |
| 807 | *token_index += 1; |
| 808 | 808 | ast_expect_token(pc, name_symbol, TokenIdSymbol); |
| 809 | 809 | |
| 810 | 810 | ast_buf_from_token(pc, name_symbol, &node->data.directive.name); |
| 811 | 811 | |
| 812 | | Token *l_paren = &pc->tokens->at(token_index); |
| 813 | | token_index += 1; |
| 812 | Token *l_paren = &pc->tokens->at(*token_index); |
| 813 | *token_index += 1; |
| 814 | 814 | ast_expect_token(pc, l_paren, TokenIdLParen); |
| 815 | 815 | |
| 816 | | Token *param_str = &pc->tokens->at(token_index); |
| 817 | | token_index += 1; |
| 816 | Token *param_str = &pc->tokens->at(*token_index); |
| 817 | *token_index += 1; |
| 818 | 818 | ast_expect_token(pc, param_str, TokenIdStringLiteral); |
| 819 | 819 | |
| 820 | 820 | parse_string_literal(pc, param_str, &node->data.directive.param, nullptr, nullptr); |
| 821 | 821 | |
| 822 | | Token *r_paren = &pc->tokens->at(token_index); |
| 823 | | token_index += 1; |
| 822 | Token *r_paren = &pc->tokens->at(*token_index); |
| 823 | *token_index += 1; |
| 824 | 824 | ast_expect_token(pc, r_paren, TokenIdRParen); |
| 825 | 825 | |
| 826 | | *new_token_index = token_index; |
| 827 | 826 | return node; |
| 828 | 827 | } |
| 829 | 828 | |
| ... | ... | @@ -833,7 +832,7 @@ static void ast_parse_directives(ParseContext *pc, int *token_index, |
| 833 | 832 | for (;;) { |
| 834 | 833 | Token *token = &pc->tokens->at(*token_index); |
| 835 | 834 | if (token->id == TokenIdNumberSign) { |
| 836 | | AstNode *directive_node = ast_parse_directive(pc, *token_index, token_index); |
| 835 | AstNode *directive_node = ast_parse_directive(pc, token_index); |
| 837 | 836 | directives->append(directive_node); |
| 838 | 837 | } else { |
| 839 | 838 | return; |
| ... | ... | @@ -848,9 +847,9 @@ Type : token(Symbol) | token(Unreachable) | token(Void) | PointerType | ArrayTyp |
| 848 | 847 | PointerType : token(Star) (token(Const) | token(Mut)) Type |
| 849 | 848 | ArrayType : token(LBracket) Type token(Semicolon) token(Number) token(RBracket) |
| 850 | 849 | */ |
| 851 | | static AstNode *ast_parse_type(ParseContext *pc, int token_index, int *new_token_index) { |
| 852 | | Token *token = &pc->tokens->at(token_index); |
| 853 | | token_index += 1; |
| 850 | static AstNode *ast_parse_type(ParseContext *pc, int *token_index) { |
| 851 | Token *token = &pc->tokens->at(*token_index); |
| 852 | *token_index += 1; |
| 854 | 853 | |
| 855 | 854 | AstNode *node = ast_create_node(pc, NodeTypeType, token); |
| 856 | 855 | |
| ... | ... | @@ -865,8 +864,8 @@ static AstNode *ast_parse_type(ParseContext *pc, int token_index, int *new_token |
| 865 | 864 | ast_buf_from_token(pc, token, &node->data.type.primitive_name); |
| 866 | 865 | } else if (token->id == TokenIdStar) { |
| 867 | 866 | node->data.type.type = AstNodeTypeTypePointer; |
| 868 | | Token *const_or_mut = &pc->tokens->at(token_index); |
| 869 | | token_index += 1; |
| 867 | Token *const_or_mut = &pc->tokens->at(*token_index); |
| 868 | *token_index += 1; |
| 870 | 869 | if (const_or_mut->id == TokenIdKeywordMut) { |
| 871 | 870 | node->data.type.is_const = false; |
| 872 | 871 | } else if (const_or_mut->id == TokenIdKeywordConst) { |
| ... | ... | @@ -875,51 +874,48 @@ static AstNode *ast_parse_type(ParseContext *pc, int token_index, int *new_token |
| 875 | 874 | ast_invalid_token_error(pc, const_or_mut); |
| 876 | 875 | } |
| 877 | 876 | |
| 878 | | node->data.type.child_type = ast_parse_type(pc, token_index, &token_index); |
| 877 | node->data.type.child_type = ast_parse_type(pc, token_index); |
| 879 | 878 | } else if (token->id == TokenIdLBracket) { |
| 880 | 879 | node->data.type.type = AstNodeTypeTypeArray; |
| 881 | 880 | |
| 882 | | node->data.type.child_type = ast_parse_type(pc, token_index, &token_index); |
| 881 | node->data.type.child_type = ast_parse_type(pc, token_index); |
| 883 | 882 | |
| 884 | | Token *semicolon_token = &pc->tokens->at(token_index); |
| 885 | | token_index += 1; |
| 883 | Token *semicolon_token = &pc->tokens->at(*token_index); |
| 884 | *token_index += 1; |
| 886 | 885 | ast_expect_token(pc, semicolon_token, TokenIdSemicolon); |
| 887 | 886 | |
| 888 | | node->data.type.array_size = ast_parse_expression(pc, &token_index, true); |
| 887 | node->data.type.array_size = ast_parse_expression(pc, token_index, true); |
| 889 | 888 | |
| 890 | | Token *rbracket_token = &pc->tokens->at(token_index); |
| 891 | | token_index += 1; |
| 889 | Token *rbracket_token = &pc->tokens->at(*token_index); |
| 890 | *token_index += 1; |
| 892 | 891 | ast_expect_token(pc, rbracket_token, TokenIdRBracket); |
| 893 | 892 | } else { |
| 894 | 893 | ast_invalid_token_error(pc, token); |
| 895 | 894 | } |
| 896 | 895 | |
| 897 | | *new_token_index = token_index; |
| 898 | 896 | return node; |
| 899 | 897 | } |
| 900 | 898 | |
| 901 | 899 | /* |
| 902 | 900 | ParamDecl : token(Symbol) token(Colon) Type | token(Ellipsis) |
| 903 | 901 | */ |
| 904 | | static AstNode *ast_parse_param_decl(ParseContext *pc, int token_index, int *new_token_index) { |
| 905 | | Token *param_name = &pc->tokens->at(token_index); |
| 906 | | token_index += 1; |
| 902 | static AstNode *ast_parse_param_decl(ParseContext *pc, int *token_index) { |
| 903 | Token *param_name = &pc->tokens->at(*token_index); |
| 904 | *token_index += 1; |
| 907 | 905 | |
| 908 | 906 | if (param_name->id == TokenIdSymbol) { |
| 909 | 907 | AstNode *node = ast_create_node(pc, NodeTypeParamDecl, param_name); |
| 910 | 908 | |
| 911 | 909 | ast_buf_from_token(pc, param_name, &node->data.param_decl.name); |
| 912 | 910 | |
| 913 | | Token *colon = &pc->tokens->at(token_index); |
| 914 | | token_index += 1; |
| 911 | Token *colon = &pc->tokens->at(*token_index); |
| 912 | *token_index += 1; |
| 915 | 913 | ast_expect_token(pc, colon, TokenIdColon); |
| 916 | 914 | |
| 917 | | node->data.param_decl.type = ast_parse_type(pc, token_index, &token_index); |
| 915 | node->data.param_decl.type = ast_parse_type(pc, token_index); |
| 918 | 916 | |
| 919 | | *new_token_index = token_index; |
| 920 | 917 | return node; |
| 921 | 918 | } else if (param_name->id == TokenIdEllipsis) { |
| 922 | | *new_token_index = token_index; |
| 923 | 919 | return nullptr; |
| 924 | 920 | } else { |
| 925 | 921 | ast_invalid_token_error(pc, param_name); |
| ... | ... | @@ -927,24 +923,23 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, int token_index, int *new |
| 927 | 923 | } |
| 928 | 924 | |
| 929 | 925 | |
| 930 | | static void ast_parse_param_decl_list(ParseContext *pc, int token_index, int *new_token_index, |
| 926 | static void ast_parse_param_decl_list(ParseContext *pc, int *token_index, |
| 931 | 927 | ZigList<AstNode *> *params, bool *is_var_args) |
| 932 | 928 | { |
| 933 | 929 | *is_var_args = false; |
| 934 | 930 | |
| 935 | | Token *l_paren = &pc->tokens->at(token_index); |
| 936 | | token_index += 1; |
| 931 | Token *l_paren = &pc->tokens->at(*token_index); |
| 932 | *token_index += 1; |
| 937 | 933 | ast_expect_token(pc, l_paren, TokenIdLParen); |
| 938 | 934 | |
| 939 | | Token *token = &pc->tokens->at(token_index); |
| 935 | Token *token = &pc->tokens->at(*token_index); |
| 940 | 936 | if (token->id == TokenIdRParen) { |
| 941 | | token_index += 1; |
| 942 | | *new_token_index = token_index; |
| 937 | *token_index += 1; |
| 943 | 938 | return; |
| 944 | 939 | } |
| 945 | 940 | |
| 946 | 941 | for (;;) { |
| 947 | | AstNode *param_decl_node = ast_parse_param_decl(pc, token_index, &token_index); |
| 942 | AstNode *param_decl_node = ast_parse_param_decl(pc, token_index); |
| 948 | 943 | bool expect_end = false; |
| 949 | 944 | if (param_decl_node) { |
| 950 | 945 | params->append(param_decl_node); |
| ... | ... | @@ -953,10 +948,9 @@ static void ast_parse_param_decl_list(ParseContext *pc, int token_index, int *ne |
| 953 | 948 | expect_end = true; |
| 954 | 949 | } |
| 955 | 950 | |
| 956 | | Token *token = &pc->tokens->at(token_index); |
| 957 | | token_index += 1; |
| 951 | Token *token = &pc->tokens->at(*token_index); |
| 952 | *token_index += 1; |
| 958 | 953 | if (token->id == TokenIdRParen) { |
| 959 | | *new_token_index = token_index; |
| 960 | 954 | return; |
| 961 | 955 | } else if (expect_end) { |
| 962 | 956 | ast_invalid_token_error(pc, token); |
| ... | ... | @@ -967,24 +961,20 @@ static void ast_parse_param_decl_list(ParseContext *pc, int token_index, int *ne |
| 967 | 961 | zig_unreachable(); |
| 968 | 962 | } |
| 969 | 963 | |
| 970 | | static void ast_parse_fn_call_param_list(ParseContext *pc, int token_index, int *new_token_index, |
| 971 | | ZigList<AstNode*> *params) |
| 972 | | { |
| 973 | | Token *token = &pc->tokens->at(token_index); |
| 964 | static void ast_parse_fn_call_param_list(ParseContext *pc, int *token_index, ZigList<AstNode*> *params) { |
| 965 | Token *token = &pc->tokens->at(*token_index); |
| 974 | 966 | if (token->id == TokenIdRParen) { |
| 975 | | token_index += 1; |
| 976 | | *new_token_index = token_index; |
| 967 | *token_index += 1; |
| 977 | 968 | return; |
| 978 | 969 | } |
| 979 | 970 | |
| 980 | 971 | for (;;) { |
| 981 | | AstNode *expr = ast_parse_expression(pc, &token_index, true); |
| 972 | AstNode *expr = ast_parse_expression(pc, token_index, true); |
| 982 | 973 | params->append(expr); |
| 983 | 974 | |
| 984 | | Token *token = &pc->tokens->at(token_index); |
| 985 | | token_index += 1; |
| 975 | Token *token = &pc->tokens->at(*token_index); |
| 976 | *token_index += 1; |
| 986 | 977 | if (token->id == TokenIdRParen) { |
| 987 | | *new_token_index = token_index; |
| 988 | 978 | return; |
| 989 | 979 | } else { |
| 990 | 980 | ast_expect_token(pc, token, TokenIdComma); |
| ... | ... | @@ -1102,7 +1092,7 @@ static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, int *token_index, boo |
| 1102 | 1092 | |
| 1103 | 1093 | AstNode *node = ast_create_node(pc, NodeTypeFnCallExpr, token); |
| 1104 | 1094 | node->data.fn_call_expr.fn_ref_expr = primary_expr; |
| 1105 | | ast_parse_fn_call_param_list(pc, *token_index, token_index, &node->data.fn_call_expr.params); |
| 1095 | ast_parse_fn_call_param_list(pc, token_index, &node->data.fn_call_expr.params); |
| 1106 | 1096 | return node; |
| 1107 | 1097 | } else if (token->id == TokenIdLBracket) { |
| 1108 | 1098 | *token_index += 1; |
| ... | ... | @@ -1192,7 +1182,7 @@ static AstNode *ast_parse_cast_expression(ParseContext *pc, int *token_index, bo |
| 1192 | 1182 | AstNode *node = ast_create_node(pc, NodeTypeCastExpr, as_kw); |
| 1193 | 1183 | node->data.cast_expr.expr = operand_1; |
| 1194 | 1184 | |
| 1195 | | node->data.cast_expr.type = ast_parse_type(pc, *token_index, token_index); |
| 1185 | node->data.cast_expr.type = ast_parse_type(pc, token_index); |
| 1196 | 1186 | |
| 1197 | 1187 | operand_1 = node; |
| 1198 | 1188 | } |
| ... | ... | @@ -1592,7 +1582,7 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, int *token |
| 1592 | 1582 | node->data.variable_declaration.expr = ast_parse_expression(pc, token_index, true); |
| 1593 | 1583 | return node; |
| 1594 | 1584 | } else if (eq_or_colon->id == TokenIdColon) { |
| 1595 | | node->data.variable_declaration.type = ast_parse_type(pc, *token_index, token_index); |
| 1585 | node->data.variable_declaration.type = ast_parse_type(pc, token_index); |
| 1596 | 1586 | |
| 1597 | 1587 | Token *eq_token = &pc->tokens->at(*token_index); |
| 1598 | 1588 | if (eq_token->id == TokenIdEq) { |
| ... | ... | @@ -2065,13 +2055,12 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mand |
| 2065 | 2055 | ast_buf_from_token(pc, fn_name, &node->data.fn_proto.name); |
| 2066 | 2056 | |
| 2067 | 2057 | |
| 2068 | | ast_parse_param_decl_list(pc, *token_index, token_index, |
| 2069 | | &node->data.fn_proto.params, &node->data.fn_proto.is_var_args); |
| 2058 | ast_parse_param_decl_list(pc, token_index, &node->data.fn_proto.params, &node->data.fn_proto.is_var_args); |
| 2070 | 2059 | |
| 2071 | 2060 | Token *arrow = &pc->tokens->at(*token_index); |
| 2072 | 2061 | if (arrow->id == TokenIdArrow) { |
| 2073 | 2062 | *token_index += 1; |
| 2074 | | node->data.fn_proto.return_type = ast_parse_type(pc, *token_index, token_index); |
| 2063 | node->data.fn_proto.return_type = ast_parse_type(pc, token_index); |
| 2075 | 2064 | } else { |
| 2076 | 2065 | node->data.fn_proto.return_type = ast_create_void_type_node(pc, arrow); |
| 2077 | 2066 | } |
| ... | ... | @@ -2097,17 +2086,16 @@ static AstNode *ast_parse_fn_def(ParseContext *pc, int *token_index, bool mandat |
| 2097 | 2086 | /* |
| 2098 | 2087 | FnDecl : FnProto token(Semicolon) |
| 2099 | 2088 | */ |
| 2100 | | static AstNode *ast_parse_fn_decl(ParseContext *pc, int token_index, int *new_token_index) { |
| 2101 | | AstNode *fn_proto = ast_parse_fn_proto(pc, &token_index, true); |
| 2089 | static AstNode *ast_parse_fn_decl(ParseContext *pc, int *token_index) { |
| 2090 | AstNode *fn_proto = ast_parse_fn_proto(pc, token_index, true); |
| 2102 | 2091 | AstNode *node = ast_create_node_with_node(pc, NodeTypeFnDecl, fn_proto); |
| 2103 | 2092 | |
| 2104 | 2093 | node->data.fn_decl.fn_proto = fn_proto; |
| 2105 | 2094 | |
| 2106 | | Token *semicolon = &pc->tokens->at(token_index); |
| 2107 | | token_index += 1; |
| 2095 | Token *semicolon = &pc->tokens->at(*token_index); |
| 2096 | *token_index += 1; |
| 2108 | 2097 | ast_expect_token(pc, semicolon, TokenIdSemicolon); |
| 2109 | 2098 | |
| 2110 | | *new_token_index = token_index; |
| 2111 | 2099 | return node; |
| 2112 | 2100 | } |
| 2113 | 2101 | |
| ... | ... | @@ -2152,7 +2140,7 @@ static AstNode *ast_parse_extern_block(ParseContext *pc, int *token_index, bool |
| 2152 | 2140 | *token_index += 1; |
| 2153 | 2141 | return node; |
| 2154 | 2142 | } else { |
| 2155 | | AstNode *child = ast_parse_fn_decl(pc, *token_index, token_index); |
| 2143 | AstNode *child = ast_parse_fn_decl(pc, token_index); |
| 2156 | 2144 | node->data.extern_block.fn_decls.append(child); |
| 2157 | 2145 | } |
| 2158 | 2146 | } |
| ... | ... | @@ -2256,7 +2244,7 @@ static AstNode *ast_parse_struct_decl(ParseContext *pc, int *token_index) { |
| 2256 | 2244 | |
| 2257 | 2245 | ast_eat_token(pc, token_index, TokenIdColon); |
| 2258 | 2246 | |
| 2259 | | field_node->data.struct_field.type = ast_parse_type(pc, *token_index, token_index); |
| 2247 | field_node->data.struct_field.type = ast_parse_type(pc, token_index); |
| 2260 | 2248 | |
| 2261 | 2249 | ast_eat_token(pc, token_index, TokenIdComma); |
| 2262 | 2250 | |