| author | |
| committer | |
| log | 13220ccb51b7d2cf7b8d72a662eece95784116c3 |
| tree | 70ee2f007841b3b720d25e64ba9ecb4311080779 |
| parent | ed3117a77fffa424e7f902059a7bf3a52f758bfc |
3 files changed, 51 insertions(+), 3 deletions(-)
src/ast_render.cpp+21-2| ... | ... | @@ -587,7 +587,15 @@ static void render_node(AstRender *ar, AstNode *node) { |
| 587 | 587 | case NodeTypeUnwrapErrorExpr: |
| 588 | 588 | zig_panic("TODO"); |
| 589 | 589 | case NodeTypeNumberLiteral: |
| 590 | zig_panic("TODO"); | |
| 590 | switch (node->data.number_literal.kind) { | |
| 591 | case NumLitUInt: | |
| 592 | fprintf(ar->f, "%" PRIu64, node->data.number_literal.data.x_uint); | |
| 593 | break; | |
| 594 | case NumLitFloat: | |
| 595 | fprintf(ar->f, "%f", node->data.number_literal.data.x_float); | |
| 596 | break; | |
| 597 | } | |
| 598 | break; | |
| 591 | 599 | case NodeTypeStringLiteral: |
| 592 | 600 | zig_panic("TODO"); |
| 593 | 601 | case NodeTypeCharLiteral: |
| ... | ... | @@ -682,7 +690,18 @@ static void render_node(AstRender *ar, AstNode *node) { |
| 682 | 690 | case NodeTypeStructValueField: |
| 683 | 691 | zig_panic("TODO"); |
| 684 | 692 | case NodeTypeArrayType: |
| 685 | zig_panic("TODO"); | |
| 693 | { | |
| 694 | fprintf(ar->f, "["); | |
| 695 | if (node->data.array_type.size) { | |
| 696 | render_node(ar, node->data.array_type.size); | |
| 697 | } | |
| 698 | fprintf(ar->f, "]"); | |
| 699 | if (node->data.array_type.is_const) { | |
| 700 | fprintf(ar->f, "const "); | |
| 701 | } | |
| 702 | render_node(ar, node->data.array_type.child_type); | |
| 703 | break; | |
| 704 | } | |
| 686 | 705 | case NodeTypeErrorType: |
| 687 | 706 | zig_panic("TODO"); |
| 688 | 707 | } |
src/parseh.cpp+26-1| ... | ... | @@ -121,6 +121,25 @@ static AstNode *create_struct_field_node(Context *c, const char *name, AstNode * |
| 121 | 121 | return node; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | static AstNode *create_num_lit_unsigned(Context *c, uint64_t x) { | |
| 125 | AstNode *node = create_node(c, NodeTypeNumberLiteral); | |
| 126 | node->data.number_literal.kind = NumLitUInt; | |
| 127 | node->data.number_literal.data.x_uint = x; | |
| 128 | ||
| 129 | normalize_parent_ptrs(node); | |
| 130 | return node; | |
| 131 | } | |
| 132 | ||
| 133 | static AstNode *create_array_type_node(Context *c, AstNode *child_type_node, uint64_t size, bool is_const) { | |
| 134 | AstNode *node = create_node(c, NodeTypeArrayType); | |
| 135 | node->data.array_type.size = create_num_lit_unsigned(c, size); | |
| 136 | node->data.array_type.child_type = child_type_node; | |
| 137 | node->data.array_type.is_const = is_const; | |
| 138 | ||
| 139 | normalize_parent_ptrs(node); | |
| 140 | return node; | |
| 141 | } | |
| 142 | ||
| 124 | 143 | static const char *decl_name(const Decl *decl) { |
| 125 | 144 | const NamedDecl *named_decl = static_cast<const NamedDecl *>(decl); |
| 126 | 145 | return (const char *)named_decl->getName().bytes_begin(); |
| ... | ... | @@ -330,11 +349,17 @@ static AstNode *make_type_node(Context *c, const Type *ty, const Decl *decl, |
| 330 | 349 | return nullptr; |
| 331 | 350 | } |
| 332 | 351 | } |
| 352 | case Type::ConstantArray: | |
| 353 | { | |
| 354 | const ConstantArrayType *const_arr_ty = static_cast<const ConstantArrayType *>(ty); | |
| 355 | AstNode *child_type_node = make_qual_type_node(c, const_arr_ty->getElementType(), decl); | |
| 356 | uint64_t size = const_arr_ty->getSize().getLimitedValue(); | |
| 357 | return create_array_type_node(c, child_type_node, size, false); | |
| 358 | } | |
| 333 | 359 | case Type::BlockPointer: |
| 334 | 360 | case Type::LValueReference: |
| 335 | 361 | case Type::RValueReference: |
| 336 | 362 | case Type::MemberPointer: |
| 337 | case Type::ConstantArray: | |
| 338 | 363 | case Type::IncompleteArray: |
| 339 | 364 | case Type::VariableArray: |
| 340 | 365 | case Type::DependentSizedArray: |
test/run_tests.cpp+4| ... | ... | @@ -1863,6 +1863,10 @@ pub const BarB = enum_Bar.B; |
| 1863 | 1863 | pub extern fn func(a: ?&struct_Foo, b: ?&?&enum_Bar); |
| 1864 | 1864 | pub const Foo = struct_Foo; |
| 1865 | 1865 | pub const Bar = enum_Bar;)OUTPUT"); |
| 1866 | ||
| 1867 | add_parseh_case("constant size array", R"SOURCE( | |
| 1868 | void func(int array[20]); | |
| 1869 | )SOURCE", R"OUTPUT(pub extern fn func(array: [20]c_int);)OUTPUT"); | |
| 1866 | 1870 | } |
| 1867 | 1871 | |
| 1868 | 1872 | static void print_compiler_invocation(TestCase *test_case) { |