| ... | @@ -224,6 +224,7 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, Buf *var_n | ... | @@ -224,6 +224,7 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, Buf *var_n |
| 224 | for (size_t i = 0; i < src_proto_node->data.fn_proto.params.length; i += 1) { | 224 | for (size_t i = 0; i < src_proto_node->data.fn_proto.params.length; i += 1) { |
| 225 | AstNode *src_param_node = src_proto_node->data.fn_proto.params.at(i); | 225 | AstNode *src_param_node = src_proto_node->data.fn_proto.params.at(i); |
| 226 | Buf *param_name = src_param_node->data.param_decl.name; | 226 | Buf *param_name = src_param_node->data.param_decl.name; |
| | 227 | if (!param_name) param_name = buf_sprintf("arg%" ZIG_PRI_usize "", i); |
| 227 | | 228 | |
| 228 | AstNode *dest_param_node = trans_create_node(c, NodeTypeParamDecl); | 229 | AstNode *dest_param_node = trans_create_node(c, NodeTypeParamDecl); |
| 229 | dest_param_node->data.param_decl.name = param_name; | 230 | dest_param_node->data.param_decl.name = param_name; |
| ... | @@ -238,6 +239,7 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, Buf *var_n | ... | @@ -238,6 +239,7 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, Buf *var_n |
| 238 | AstNode *block = trans_create_node(c, NodeTypeBlock); | 239 | AstNode *block = trans_create_node(c, NodeTypeBlock); |
| 239 | block->data.block.statements.resize(1); | 240 | block->data.block.statements.resize(1); |
| 240 | block->data.block.statements.items[0] = fn_call_node; | 241 | block->data.block.statements.items[0] = fn_call_node; |
| | 242 | block->data.block.last_statement_is_result_expression = true; |
| 241 | | 243 | |
| 242 | fn_def->data.fn_def.body = block; | 244 | fn_def->data.fn_def.body = block; |
| 243 | return fn_def; | 245 | return fn_def; |
| ... | @@ -2075,7 +2077,12 @@ static void render_macros(Context *c) { | ... | @@ -2075,7 +2077,12 @@ static void render_macros(Context *c) { |
| 2075 | if (!entry) | 2077 | if (!entry) |
| 2076 | break; | 2078 | break; |
| 2077 | | 2079 | |
| 2078 | add_global_var(c, entry->key, entry->value); | 2080 | AstNode *value_node = entry->value; |
| | 2081 | if (value_node->type == NodeTypeFnDef) { |
| | 2082 | c->root->data.root.top_level_decls.append(value_node); |
| | 2083 | } else { |
| | 2084 | add_global_var(c, entry->key, value_node); |
| | 2085 | } |
| 2079 | } | 2086 | } |
| 2080 | } | 2087 | } |
| 2081 | | 2088 | |
| ... | @@ -2170,18 +2177,18 @@ static void process_symbol_macros(Context *c) { | ... | @@ -2170,18 +2177,18 @@ static void process_symbol_macros(Context *c) { |
| 2170 | | 2177 | |
| 2171 | // Check if this macro aliases another top level declaration | 2178 | // Check if this macro aliases another top level declaration |
| 2172 | AstNode *existing_node = get_global(c, ms.value); | 2179 | AstNode *existing_node = get_global(c, ms.value); |
| 2173 | if (!existing_node || name_exists(c, ms.name)) | 2180 | if (!existing_node) |
| 2174 | continue; | 2181 | continue; |
| 2175 | | 2182 | |
| 2176 | // If a macro aliases a global variable which is a function pointer, we conclude that | 2183 | // If a macro aliases a global variable which is a function pointer, we conclude that |
| 2177 | // the macro is intended to represent a function that assumes the function pointer | 2184 | // the macro is intended to represent a function that assumes the function pointer |
| 2178 | // variable is non-null and calls it. | 2185 | // variable is non-null and calls it. |
| 2179 | if (existing_node->type == NodeTypeVariableDeclaration) { | 2186 | if (existing_node->type == NodeTypeVariableDeclaration) { |
| 2180 | AstNode *var_expr = existing_node->data.variable_declaration.expr; | 2187 | AstNode *var_type = existing_node->data.variable_declaration.type; |
| 2181 | if (var_expr != nullptr && var_expr->type == NodeTypePrefixOpExpr && | 2188 | if (var_type != nullptr && var_type->type == NodeTypePrefixOpExpr && |
| 2182 | var_expr->data.prefix_op_expr.prefix_op == PrefixOpMaybe) | 2189 | var_type->data.prefix_op_expr.prefix_op == PrefixOpMaybe) |
| 2183 | { | 2190 | { |
| 2184 | AstNode *fn_proto_node = var_expr->data.prefix_op_expr.primary_expr; | 2191 | AstNode *fn_proto_node = var_type->data.prefix_op_expr.primary_expr; |
| 2185 | if (fn_proto_node->type == NodeTypeFnProto) { | 2192 | if (fn_proto_node->type == NodeTypeFnProto) { |
| 2186 | AstNode *inline_fn_node = trans_create_node_inline_fn(c, ms.name, ms.value, fn_proto_node); | 2193 | AstNode *inline_fn_node = trans_create_node_inline_fn(c, ms.name, ms.value, fn_proto_node); |
| 2187 | c->macro_table.put(ms.name, inline_fn_node); | 2194 | c->macro_table.put(ms.name, inline_fn_node); |
| ... | @@ -2396,8 +2403,8 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch | ... | @@ -2396,8 +2403,8 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch |
| 2396 | | 2403 | |
| 2397 | process_preprocessor_entities(c, *ast_unit); | 2404 | process_preprocessor_entities(c, *ast_unit); |
| 2398 | | 2405 | |
| 2399 | render_macros(c); | | |
| 2400 | process_symbol_macros(c); | 2406 | process_symbol_macros(c); |
| | 2407 | render_macros(c); |
| 2401 | render_aliases(c); | 2408 | render_aliases(c); |
| 2402 | | 2409 | |
| 2403 | import->root = c->root; | 2410 | import->root = c->root; |