diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-01-28 11:54:34 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-01-28 11:54:34 -0700 |
| commit | f1c5d3d3a1ffd479acecd32bbd0496824316c6a6 (patch) | |
| tree | fb591620102897312e116c3af62dc4cefcc4ab93 /src | |
| parent | 474340a0031c9b3c8ce0d97c2cc36d5327c4e304 (diff) | |
| download | zig-f1c5d3d3a1ffd479acecd32bbd0496824316c6a6.tar.gz zig-f1c5d3d3a1ffd479acecd32bbd0496824316c6a6.zip | |
add parseh tests
Diffstat (limited to 'src')
| -rw-r--r-- | src/ast_render.cpp | 2 | ||||
| -rw-r--r-- | src/parseh.cpp | 45 |
2 files changed, 45 insertions, 2 deletions
diff --git a/src/ast_render.cpp b/src/ast_render.cpp index a1043377c8..8ddfe03e34 100644 --- a/src/ast_render.cpp +++ b/src/ast_render.cpp @@ -672,7 +672,7 @@ static void render_node(AstRender *ar, AstNode *node) { } ar->indent -= ar->indent_size; - fprintf(ar->f, "}\n"); + fprintf(ar->f, "}"); break; } case NodeTypeStructField: diff --git a/src/parseh.cpp b/src/parseh.cpp index 0cf1b570c7..e0b3506e12 100644 --- a/src/parseh.cpp +++ b/src/parseh.cpp @@ -397,6 +397,9 @@ static void visit_enum_decl(Context *c, const EnumDecl *enum_decl) { if (!enum_def) { // this is a type that we can point to but that's it, same as `struct Foo;`. add_typedef_node(c, type_name, create_symbol_node(c, "u8")); + AstNode *alias_node = create_var_decl_node(c, buf_ptr(&bare_name), + create_symbol_node(c, buf_ptr(type_name))); + c->aliases.append(alias_node); return; } @@ -404,7 +407,7 @@ static void visit_enum_decl(Context *c, const EnumDecl *enum_decl) { buf_init_from_buf(&node->data.struct_decl.name, type_name); node->data.struct_decl.kind = ContainerKindEnum; - node->data.struct_decl.visib_mod = c->visib_mod; + node->data.struct_decl.visib_mod = VisibModExport; node->data.struct_decl.directives = create_empty_directives(c); ZigList<AstNode *> var_decls = {0}; @@ -465,6 +468,43 @@ static void visit_enum_decl(Context *c, const EnumDecl *enum_decl) { } +static void visit_record_decl(Context *c, const RecordDecl *record_decl) { + Buf bare_name = BUF_INIT; + buf_init_from_str(&bare_name, decl_name(record_decl)); + + Buf *type_name = buf_alloc(); + buf_appendf(type_name, "struct_%s", buf_ptr(&bare_name)); + + if (c->type_table.maybe_get(type_name)) { + // we've already seen it + return; + } + + RecordDecl *record_def = record_decl->getDefinition(); + if (!record_def) { + // this is a type that we can point to but that's it, such as `struct Foo;`. + add_typedef_node(c, type_name, create_symbol_node(c, "u8")); + AstNode *alias_node = create_var_decl_node(c, buf_ptr(&bare_name), + create_symbol_node(c, buf_ptr(type_name))); + c->aliases.append(alias_node); + return; + } + + emit_warning(c, record_decl, "skipping record %s, TODO", buf_ptr(&bare_name)); + + /* + AstNode *node = create_node(c, NodeTypeStructDecl); + buf_init_from_buf(&node->data.struct_decl.name, type_name); + + node->data.struct_decl.kind = ContainerKindStruct; + node->data.struct_decl.visib_mod = VisibModExport; + node->data.struct_decl.directives = create_empty_directives(c); + + normalize_parent_ptrs(node); + c->root->data.root.top_level_decls.append(node); + */ +} + static bool decl_visitor(void *context, const Decl *decl) { Context *c = (Context*)context; @@ -478,6 +518,9 @@ static bool decl_visitor(void *context, const Decl *decl) { case Decl::Enum: visit_enum_decl(c, static_cast<const EnumDecl *>(decl)); break; + case Decl::Record: + visit_record_decl(c, static_cast<const RecordDecl *>(decl)); + break; default: emit_warning(c, decl, "ignoring %s decl\n", decl->getDeclKindName()); } |
