authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-05 00:21:02-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-09-05 00:21:02-04:00
logcc621cdee3da956e0976e656d4d310fcad441dad
tree9c1e5b68b205ba67db9f0548d652d0858795010f
parente1d5da20a5d5e54b9dba6031c97fe232192e69cd

fix parseh bugs


5 files changed, 100 insertions(+), 80 deletions(-)

src/ast_render.cpp+6-3
...@@ -412,14 +412,17 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {...@@ -412,14 +412,17 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
412 const char *pub_str = visib_mod_string(node->data.fn_proto.visib_mod);412 const char *pub_str = visib_mod_string(node->data.fn_proto.visib_mod);
413 const char *extern_str = extern_string(node->data.fn_proto.is_extern);413 const char *extern_str = extern_string(node->data.fn_proto.is_extern);
414 const char *inline_str = inline_string(node->data.fn_proto.is_inline);414 const char *inline_str = inline_string(node->data.fn_proto.is_inline);
415 fprintf(ar->f, "%s%s%sfn ", pub_str, inline_str, extern_str);415 fprintf(ar->f, "%s%s%sfn", pub_str, inline_str, extern_str);
416 print_symbol(ar, node->data.fn_proto.name);416 if (node->data.fn_proto.name != nullptr) {
417 fprintf(ar->f, " ");
418 print_symbol(ar, node->data.fn_proto.name);
419 }
417 fprintf(ar->f, "(");420 fprintf(ar->f, "(");
418 size_t arg_count = node->data.fn_proto.params.length;421 size_t arg_count = node->data.fn_proto.params.length;
419 for (size_t arg_i = 0; arg_i < arg_count; arg_i += 1) {422 for (size_t arg_i = 0; arg_i < arg_count; arg_i += 1) {
420 AstNode *param_decl = node->data.fn_proto.params.at(arg_i);423 AstNode *param_decl = node->data.fn_proto.params.at(arg_i);
421 assert(param_decl->type == NodeTypeParamDecl);424 assert(param_decl->type == NodeTypeParamDecl);
422 if (buf_len(param_decl->data.param_decl.name) > 0) {425 if (param_decl->data.param_decl.name != nullptr) {
423 const char *noalias_str = param_decl->data.param_decl.is_noalias ? "noalias " : "";426 const char *noalias_str = param_decl->data.param_decl.is_noalias ? "noalias " : "";
424 const char *inline_str = param_decl->data.param_decl.is_inline ? "inline " : "";427 const char *inline_str = param_decl->data.param_decl.is_inline ? "inline " : "";
425 fprintf(ar->f, "%s%s", noalias_str, inline_str);428 fprintf(ar->f, "%s%s", noalias_str, inline_str);
src/errmsg.cpp+5-2
...@@ -79,11 +79,14 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, size_t line, size_t column, size...@@ -79,11 +79,14 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, size_t line, size_t column, size
79 for (;;) {79 for (;;) {
80 if (line_start_offset == 0) {80 if (line_start_offset == 0) {
81 break;81 break;
82 } else if (source[line_start_offset] == '\n') {82 }
83
84 line_start_offset -= 1;
85
86 if (source[line_start_offset] == '\n') {
83 line_start_offset += 1;87 line_start_offset += 1;
84 break;88 break;
85 }89 }
86 line_start_offset -= 1;
87 }90 }
8891
89 size_t line_end_offset = offset;92 size_t line_end_offset = offset;
src/parseh.cpp+82-66
...@@ -30,8 +30,8 @@ struct MacroSymbol {...@@ -30,8 +30,8 @@ struct MacroSymbol {
30};30};
3131
32struct Alias {32struct Alias {
33 Buf *name;33 Buf *new_name;
34 AstNode *node;34 Buf *canon_name;
35};35};
3636
37struct Context {37struct Context {
...@@ -85,10 +85,10 @@ static void emit_warning(Context *c, const SourceLocation &sl, const char *forma...@@ -85,10 +85,10 @@ static void emit_warning(Context *c, const SourceLocation &sl, const char *forma
85 fprintf(stderr, "%s:%u:%u: warning: %s\n", buf_ptr(path), line, column, buf_ptr(msg));85 fprintf(stderr, "%s:%u:%u: warning: %s\n", buf_ptr(path), line, column, buf_ptr(msg));
86}86}
8787
88static void add_global_weak_alias(Context *c, Buf *name, AstNode *node) {88static void add_global_weak_alias(Context *c, Buf *new_name, Buf *canon_name) {
89 Alias *alias = c->aliases.add_one();89 Alias *alias = c->aliases.add_one();
90 alias->name = name;90 alias->new_name = new_name;
91 alias->node = node;91 alias->canon_name = canon_name;
92}92}
9393
94static AstNode * trans_create_node(Context *c, NodeType id) {94static AstNode * trans_create_node(Context *c, NodeType id) {
...@@ -128,7 +128,7 @@ static AstNode *trans_create_node_builtin_fn_call_str(Context *c, const char *na...@@ -128,7 +128,7 @@ static AstNode *trans_create_node_builtin_fn_call_str(Context *c, const char *na
128}128}
129129
130static AstNode *trans_create_node_opaque(Context *c) {130static AstNode *trans_create_node_opaque(Context *c) {
131 return trans_create_node_builtin_fn_call_str(c, "opaque");131 return trans_create_node_builtin_fn_call_str(c, "OpaqueType");
132}132}
133133
134static AstNode *trans_create_node_field_access(Context *c, AstNode *container, Buf *field_name) {134static AstNode *trans_create_node_field_access(Context *c, AstNode *container, Buf *field_name) {
...@@ -209,7 +209,7 @@ static AstNode *trans_create_node_var_decl(Context *c, bool is_const, Buf *var_n...@@ -209,7 +209,7 @@ static AstNode *trans_create_node_var_decl(Context *c, bool is_const, Buf *var_n
209static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, Buf *var_name, AstNode *src_proto_node) {209static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, Buf *var_name, AstNode *src_proto_node) {
210 AstNode *fn_def = trans_create_node(c, NodeTypeFnDef);210 AstNode *fn_def = trans_create_node(c, NodeTypeFnDef);
211 AstNode *fn_proto = trans_create_node(c, NodeTypeFnProto);211 AstNode *fn_proto = trans_create_node(c, NodeTypeFnProto);
212 fn_proto->data.fn_proto.visib_mod = c->visib_mod;;212 fn_proto->data.fn_proto.visib_mod = c->visib_mod;
213 fn_proto->data.fn_proto.name = fn_name;213 fn_proto->data.fn_proto.name = fn_name;
214 fn_proto->data.fn_proto.is_inline = true;214 fn_proto->data.fn_proto.is_inline = true;
215 fn_proto->data.fn_proto.return_type = src_proto_node->data.fn_proto.return_type; // TODO ok for these to alias?215 fn_proto->data.fn_proto.return_type = src_proto_node->data.fn_proto.return_type; // TODO ok for these to alias?
...@@ -559,6 +559,7 @@ static AstNode *trans_type_with_table(Context *c, const Type *ty, const SourceLo...@@ -559,6 +559,7 @@ static AstNode *trans_type_with_table(Context *c, const Type *ty, const SourceLo
559 switch (fn_proto_ty->getCallConv()) {559 switch (fn_proto_ty->getCallConv()) {
560 case CC_C: // __attribute__((cdecl))560 case CC_C: // __attribute__((cdecl))
561 proto_node->data.fn_proto.cc = CallingConventionC;561 proto_node->data.fn_proto.cc = CallingConventionC;
562 proto_node->data.fn_proto.is_extern = true;
562 break;563 break;
563 case CC_X86StdCall: // __attribute__((stdcall))564 case CC_X86StdCall: // __attribute__((stdcall))
564 proto_node->data.fn_proto.cc = CallingConventionStdcall;565 proto_node->data.fn_proto.cc = CallingConventionStdcall;
...@@ -646,9 +647,7 @@ static AstNode *trans_type_with_table(Context *c, const Type *ty, const SourceLo...@@ -646,9 +647,7 @@ static AstNode *trans_type_with_table(Context *c, const Type *ty, const SourceLo
646 AstNode *param_node = trans_create_node(c, NodeTypeParamDecl);647 AstNode *param_node = trans_create_node(c, NodeTypeParamDecl);
647 //emit_warning(c, source_loc, "TODO figure out fn prototype param name");648 //emit_warning(c, source_loc, "TODO figure out fn prototype param name");
648 const char *param_name = nullptr;649 const char *param_name = nullptr;
649 if (param_name == nullptr) {650 if (param_name != nullptr) {
650 param_node->data.param_decl.name = buf_sprintf("arg%" ZIG_PRI_usize "", i);
651 } else {
652 param_node->data.param_decl.name = buf_create_from_str(param_name);651 param_node->data.param_decl.name = buf_create_from_str(param_name);
653 }652 }
654 param_node->data.param_decl.is_noalias = qt.isRestrictQualified();653 param_node->data.param_decl.is_noalias = qt.isRestrictQualified();
...@@ -1662,7 +1661,14 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {...@@ -1662,7 +1661,14 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {
1662 AstNode *param_node = proto_node->data.fn_proto.params.at(i);1661 AstNode *param_node = proto_node->data.fn_proto.params.at(i);
1663 const ParmVarDecl *param = fn_decl->getParamDecl(i);1662 const ParmVarDecl *param = fn_decl->getParamDecl(i);
1664 const char *name = decl_name(param);1663 const char *name = decl_name(param);
1665 if (strlen(name) != 0) {1664 if (strlen(name) == 0) {
1665 Buf *proto_param_name = param_node->data.param_decl.name;
1666 if (proto_param_name == nullptr) {
1667 param_node->data.param_decl.name = buf_sprintf("arg%" ZIG_PRI_usize "", i);
1668 } else {
1669 param_node->data.param_decl.name = proto_param_name;
1670 }
1671 } else {
1666 param_node->data.param_decl.name = buf_create_from_str(name);1672 param_node->data.param_decl.name = buf_create_from_str(name);
1667 }1673 }
1668 }1674 }
...@@ -1714,6 +1720,22 @@ static void visit_typedef_decl(Context *c, const TypedefNameDecl *typedef_decl)...@@ -1714,6 +1720,22 @@ static void visit_typedef_decl(Context *c, const TypedefNameDecl *typedef_decl)
1714 c->global_type_table.put(type_name, type_node);1720 c->global_type_table.put(type_name, type_node);
1715}1721}
17161722
1723struct AstNode *demote_enum_to_opaque(Context *c, const EnumDecl *enum_decl,
1724 Buf *full_type_name, Buf *bare_name)
1725{
1726 AstNode *opaque_node = trans_create_node_opaque(c);
1727 if (full_type_name == nullptr) {
1728 c->decl_table.put(enum_decl, opaque_node);
1729 return opaque_node;
1730 }
1731 AstNode *symbol_node = trans_create_node_symbol(c, full_type_name);
1732 c->enum_type_table.put(bare_name, symbol_node);
1733 add_global_weak_alias(c, bare_name, full_type_name);
1734 add_global_var(c, full_type_name, opaque_node);
1735 c->decl_table.put(enum_decl, symbol_node);
1736 return symbol_node;
1737}
1738
1717static AstNode *resolve_enum_decl(Context *c, const EnumDecl *enum_decl) {1739static AstNode *resolve_enum_decl(Context *c, const EnumDecl *enum_decl) {
1718 auto existing_entry = c->decl_table.maybe_get((void*)enum_decl);1740 auto existing_entry = c->decl_table.maybe_get((void*)enum_decl);
1719 if (existing_entry) {1741 if (existing_entry) {
...@@ -1727,14 +1749,7 @@ static AstNode *resolve_enum_decl(Context *c, const EnumDecl *enum_decl) {...@@ -1727,14 +1749,7 @@ static AstNode *resolve_enum_decl(Context *c, const EnumDecl *enum_decl) {
17271749
1728 const EnumDecl *enum_def = enum_decl->getDefinition();1750 const EnumDecl *enum_def = enum_decl->getDefinition();
1729 if (!enum_def) {1751 if (!enum_def) {
1730 AstNode *opaque_node = trans_create_node_opaque(c);1752 return demote_enum_to_opaque(c, enum_decl, full_type_name, bare_name);
1731 if (!is_anonymous) {
1732 c->enum_type_table.put(bare_name, opaque_node);
1733 add_global_weak_alias(c, bare_name, opaque_node);
1734 add_global_var(c, full_type_name, opaque_node);
1735 }
1736 c->decl_table.put(enum_decl, opaque_node);
1737 return opaque_node;
1738 }1753 }
17391754
1740 bool pure_enum = true;1755 bool pure_enum = true;
...@@ -1786,14 +1801,17 @@ static AstNode *resolve_enum_decl(Context *c, const EnumDecl *enum_decl) {...@@ -1786,14 +1801,17 @@ static AstNode *resolve_enum_decl(Context *c, const EnumDecl *enum_decl) {
1786 add_global_var(c, enum_val_name, field_access_node);1801 add_global_var(c, enum_val_name, field_access_node);
1787 }1802 }
17881803
1789 if (!is_anonymous) {1804 if (is_anonymous) {
1790 c->enum_type_table.put(bare_name, enum_node);1805 c->decl_table.put(enum_decl, enum_node);
1791 add_global_weak_alias(c, bare_name, enum_node);1806 return enum_node;
1807 } else {
1808 AstNode *symbol_node = trans_create_node_symbol(c, full_type_name);
1809 c->enum_type_table.put(bare_name, symbol_node);
1810 add_global_weak_alias(c, bare_name, full_type_name);
1792 add_global_var(c, full_type_name, enum_node);1811 add_global_var(c, full_type_name, enum_node);
1812 c->decl_table.put(enum_decl, symbol_node);
1813 return enum_node;
1793 }1814 }
1794 c->decl_table.put(enum_decl, enum_node);
1795
1796 return enum_node;
1797 }1815 }
17981816
1799 // TODO after issue #305 is solved, make this be an enum with tag_int_type1817 // TODO after issue #305 is solved, make this be an enum with tag_int_type
...@@ -1814,14 +1832,32 @@ static AstNode *resolve_enum_decl(Context *c, const EnumDecl *enum_decl) {...@@ -1814,14 +1832,32 @@ static AstNode *resolve_enum_decl(Context *c, const EnumDecl *enum_decl) {
1814 var_node->data.variable_declaration.type = tag_int_type;1832 var_node->data.variable_declaration.type = tag_int_type;
1815 }1833 }
18161834
1817 if (!is_anonymous) {1835 if (is_anonymous) {
1818 c->enum_type_table.put(bare_name, enum_node);1836 c->decl_table.put(enum_decl, enum_node);
1819 add_global_weak_alias(c, bare_name, enum_node);1837 return enum_node;
1838 } else {
1839 AstNode *symbol_node = trans_create_node_symbol(c, full_type_name);
1840 c->enum_type_table.put(bare_name, symbol_node);
1841 add_global_weak_alias(c, bare_name, full_type_name);
1820 add_global_var(c, full_type_name, enum_node);1842 add_global_var(c, full_type_name, enum_node);
1843 return symbol_node;
1821 }1844 }
1822 c->decl_table.put(enum_decl, enum_node);1845}
18231846
1824 return enum_node;1847static AstNode *demote_struct_to_opaque(Context *c, const RecordDecl *record_decl,
1848 Buf *full_type_name, Buf *bare_name)
1849{
1850 AstNode *opaque_node = trans_create_node_opaque(c);
1851 if (full_type_name == nullptr) {
1852 c->decl_table.put(record_decl, opaque_node);
1853 return opaque_node;
1854 }
1855 AstNode *symbol_node = trans_create_node_symbol(c, full_type_name);
1856 c->struct_type_table.put(bare_name, symbol_node);
1857 add_global_weak_alias(c, bare_name, full_type_name);
1858 add_global_var(c, full_type_name, opaque_node);
1859 c->decl_table.put(record_decl, symbol_node);
1860 return symbol_node;
1825}1861}
18261862
1827static AstNode *resolve_record_decl(Context *c, const RecordDecl *record_decl) {1863static AstNode *resolve_record_decl(Context *c, const RecordDecl *record_decl) {
...@@ -1834,7 +1870,6 @@ static AstNode *resolve_record_decl(Context *c, const RecordDecl *record_decl) {...@@ -1834,7 +1870,6 @@ static AstNode *resolve_record_decl(Context *c, const RecordDecl *record_decl) {
18341870
1835 if (!record_decl->isStruct()) {1871 if (!record_decl->isStruct()) {
1836 emit_warning(c, record_decl->getLocation(), "skipping record %s, not a struct", raw_name);1872 emit_warning(c, record_decl->getLocation(), "skipping record %s, not a struct", raw_name);
1837 c->decl_table.put(record_decl, nullptr);
1838 return nullptr;1873 return nullptr;
1839 }1874 }
18401875
...@@ -1844,14 +1879,7 @@ static AstNode *resolve_record_decl(Context *c, const RecordDecl *record_decl) {...@@ -1844,14 +1879,7 @@ static AstNode *resolve_record_decl(Context *c, const RecordDecl *record_decl) {
18441879
1845 RecordDecl *record_def = record_decl->getDefinition();1880 RecordDecl *record_def = record_decl->getDefinition();
1846 if (record_def == nullptr) {1881 if (record_def == nullptr) {
1847 AstNode *opaque_node = trans_create_node_opaque(c);1882 return demote_struct_to_opaque(c, record_decl, full_type_name, bare_name);
1848 if (!is_anonymous) {
1849 c->struct_type_table.put(bare_name, opaque_node);
1850 add_global_weak_alias(c, bare_name, opaque_node);
1851 add_global_var(c, full_type_name, opaque_node);
1852 }
1853 c->decl_table.put(record_decl, opaque_node);
1854 return opaque_node;
1855 }1883 }
18561884
1857 // count fields and validate1885 // count fields and validate
...@@ -1865,16 +1893,7 @@ static AstNode *resolve_record_decl(Context *c, const RecordDecl *record_decl) {...@@ -1865,16 +1893,7 @@ static AstNode *resolve_record_decl(Context *c, const RecordDecl *record_decl) {
1865 if (field_decl->isBitField()) {1893 if (field_decl->isBitField()) {
1866 emit_warning(c, field_decl->getLocation(), "struct %s demoted to opaque type - has bitfield",1894 emit_warning(c, field_decl->getLocation(), "struct %s demoted to opaque type - has bitfield",
1867 is_anonymous ? "(anon)" : buf_ptr(bare_name));1895 is_anonymous ? "(anon)" : buf_ptr(bare_name));
18681896 return demote_struct_to_opaque(c, record_decl, full_type_name, bare_name);
1869 AstNode *opaque_node = trans_create_node_opaque(c);
1870
1871 if (!is_anonymous) {
1872 c->struct_type_table.put(bare_name, opaque_node);
1873 add_global_weak_alias(c, bare_name, opaque_node);
1874 add_global_var(c, full_type_name, opaque_node);
1875 }
1876 c->decl_table.put(record_decl, opaque_node);
1877 return opaque_node;;
1878 }1897 }
1879 }1898 }
18801899
...@@ -1887,12 +1906,14 @@ static AstNode *resolve_record_decl(Context *c, const RecordDecl *record_decl) {...@@ -1887,12 +1906,14 @@ static AstNode *resolve_record_decl(Context *c, const RecordDecl *record_decl) {
1887 struct_node->data.container_decl.fields.resize(field_count);1906 struct_node->data.container_decl.fields.resize(field_count);
18881907
1889 // must be before fields in case a circular reference happens1908 // must be before fields in case a circular reference happens
1890 if (!is_anonymous) {1909 if (is_anonymous) {
1910 c->decl_table.put(record_decl, struct_node);
1911 } else {
1891 c->struct_type_table.put(bare_name, struct_node);1912 c->struct_type_table.put(bare_name, struct_node);
1892 add_global_weak_alias(c, bare_name, struct_node);1913 add_global_weak_alias(c, bare_name, full_type_name);
1893 add_global_var(c, full_type_name, struct_node);1914 add_global_var(c, full_type_name, struct_node);
1915 c->decl_table.put(record_decl, trans_create_node_symbol(c, full_type_name));
1894 }1916 }
1895 c->decl_table.put(record_decl, struct_node);
18961917
1897 uint32_t i = 0;1918 uint32_t i = 0;
1898 for (auto it = record_def->field_begin(),1919 for (auto it = record_def->field_begin(),
...@@ -1910,22 +1931,17 @@ static AstNode *resolve_record_decl(Context *c, const RecordDecl *record_decl) {...@@ -1910,22 +1931,17 @@ static AstNode *resolve_record_decl(Context *c, const RecordDecl *record_decl) {
1910 "struct %s demoted to opaque type - unresolved type",1931 "struct %s demoted to opaque type - unresolved type",
1911 is_anonymous ? "(anon)" : buf_ptr(bare_name));1932 is_anonymous ? "(anon)" : buf_ptr(bare_name));
19121933
1913 AstNode *opaque_node = trans_create_node_opaque(c);1934 return demote_struct_to_opaque(c, record_decl, full_type_name, bare_name);
1914 if (!is_anonymous) {
1915 c->struct_type_table.put(bare_name, opaque_node);
1916 add_global_weak_alias(c, bare_name, opaque_node);
1917 add_global_var(c, full_type_name, opaque_node);
1918 }
1919 c->decl_table.put(record_decl, opaque_node);
1920
1921 return opaque_node;
1922 }1935 }
19231936
1924 struct_node->data.container_decl.fields.items[i] = field_node;1937 struct_node->data.container_decl.fields.items[i] = field_node;
1925 }1938 }
19261939
19271940 if (is_anonymous) {
1928 return struct_node;1941 return struct_node;
1942 } else {
1943 return trans_create_node_symbol(c, full_type_name);
1944 }
1929}1945}
19301946
1931static void visit_var_decl(Context *c, const VarDecl *var_decl) {1947static void visit_var_decl(Context *c, const VarDecl *var_decl) {
...@@ -2045,10 +2061,10 @@ static bool name_exists(Context *c, Buf *name) {...@@ -2045,10 +2061,10 @@ static bool name_exists(Context *c, Buf *name) {
2045static void render_aliases(Context *c) {2061static void render_aliases(Context *c) {
2046 for (size_t i = 0; i < c->aliases.length; i += 1) {2062 for (size_t i = 0; i < c->aliases.length; i += 1) {
2047 Alias *alias = &c->aliases.at(i);2063 Alias *alias = &c->aliases.at(i);
2048 if (name_exists(c, alias->name))2064 if (name_exists(c, alias->new_name))
2049 continue;2065 continue;
20502066
2051 add_global_var(c, alias->name, alias->node);2067 add_global_var(c, alias->new_name, trans_create_node_symbol(c, alias->canon_name));
2052 }2068 }
2053}2069}
20542070
...@@ -2174,7 +2190,7 @@ static void process_symbol_macros(Context *c) {...@@ -2174,7 +2190,7 @@ static void process_symbol_macros(Context *c) {
2174 }2190 }
2175 }2191 }
21762192
2177 add_global_var(c, ms.name, existing_node);2193 add_global_var(c, ms.name, trans_create_node_symbol(c, ms.value));
2178 }2194 }
2179}2195}
21802196
src/parser.cpp+2-4
...@@ -22,7 +22,6 @@ struct ParseContext {...@@ -22,7 +22,6 @@ struct ParseContext {
22 ErrColor err_color;22 ErrColor err_color;
23 // These buffers are used freqently so we preallocate them once here.23 // These buffers are used freqently so we preallocate them once here.
24 Buf *void_buf;24 Buf *void_buf;
25 Buf *empty_buf;
26};25};
2726
28__attribute__ ((format (printf, 4, 5)))27__attribute__ ((format (printf, 4, 5)))
...@@ -276,7 +275,7 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) {...@@ -276,7 +275,7 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) {
276 token = &pc->tokens->at(*token_index);275 token = &pc->tokens->at(*token_index);
277 }276 }
278277
279 node->data.param_decl.name = pc->empty_buf;278 node->data.param_decl.name = nullptr;
280279
281 if (token->id == TokenIdSymbol) {280 if (token->id == TokenIdSymbol) {
282 Token *next_token = &pc->tokens->at(*token_index + 1);281 Token *next_token = &pc->tokens->at(*token_index + 1);
...@@ -2246,7 +2245,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool m...@@ -2246,7 +2245,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool m
2246 *token_index += 1;2245 *token_index += 1;
2247 node->data.fn_proto.name = token_buf(fn_name);2246 node->data.fn_proto.name = token_buf(fn_name);
2248 } else {2247 } else {
2249 node->data.fn_proto.name = pc->empty_buf;2248 node->data.fn_proto.name = nullptr;
2250 }2249 }
22512250
2252 ast_parse_param_decl_list(pc, token_index, &node->data.fn_proto.params, &node->data.fn_proto.is_var_args);2251 ast_parse_param_decl_list(pc, token_index, &node->data.fn_proto.params, &node->data.fn_proto.is_var_args);
...@@ -2612,7 +2611,6 @@ AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens, ImportTableEntry *owner,...@@ -2612,7 +2611,6 @@ AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens, ImportTableEntry *owner,
2612{2611{
2613 ParseContext pc = {0};2612 ParseContext pc = {0};
2614 pc.void_buf = buf_create_from_str("void");2613 pc.void_buf = buf_create_from_str("void");
2615 pc.empty_buf = buf_create_from_str("");
2616 pc.err_color = err_color;2614 pc.err_color = err_color;
2617 pc.owner = owner;2615 pc.owner = owner;
2618 pc.buf = buf;2616 pc.buf = buf;
test/parseh.zig+5-5
...@@ -44,11 +44,11 @@ pub fn addCases(cases: &tests.ParseHContext) {...@@ -44,11 +44,11 @@ pub fn addCases(cases: &tests.ParseHContext) {
44 \\ @"1",44 \\ @"1",
45 \\};45 \\};
46 ,46 ,
47 \\pub const FooA = Foo.A;47 \\pub const FooA = enum_Foo.A;
48 ,48 ,
49 \\pub const FooB = Foo.B;49 \\pub const FooB = enum_Foo.B;
50 ,50 ,
51 \\pub const Foo1 = Foo.1;51 \\pub const Foo1 = enum_Foo.@"1";
52 ,52 ,
53 \\pub const Foo = enum_Foo;53 \\pub const Foo = enum_Foo;
54 );54 );
...@@ -94,9 +94,9 @@ pub fn addCases(cases: &tests.ParseHContext) {...@@ -94,9 +94,9 @@ pub fn addCases(cases: &tests.ParseHContext) {
94 \\ B,94 \\ B,
95 \\};95 \\};
96 ,96 ,
97 \\pub const BarA = 0;97 \\pub const BarA = enum_Bar.A;
98 ,98 ,
99 \\pub const BarB = 1;99 \\pub const BarB = enum_Bar.B;
100 ,100 ,
101 \\pub extern fn func(a: ?&struct_Foo, b: ?&?&enum_Bar);101 \\pub extern fn func(a: ?&struct_Foo, b: ?&?&enum_Bar);
102 ,102 ,