parsh understands constant sized arrays
parent
ed3117a77f
commit
13220ccb51
|
@ -587,7 +587,15 @@ static void render_node(AstRender *ar, AstNode *node) {
|
|||
case NodeTypeUnwrapErrorExpr:
|
||||
zig_panic("TODO");
|
||||
case NodeTypeNumberLiteral:
|
||||
zig_panic("TODO");
|
||||
switch (node->data.number_literal.kind) {
|
||||
case NumLitUInt:
|
||||
fprintf(ar->f, "%" PRIu64, node->data.number_literal.data.x_uint);
|
||||
break;
|
||||
case NumLitFloat:
|
||||
fprintf(ar->f, "%f", node->data.number_literal.data.x_float);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case NodeTypeStringLiteral:
|
||||
zig_panic("TODO");
|
||||
case NodeTypeCharLiteral:
|
||||
|
@ -682,7 +690,18 @@ static void render_node(AstRender *ar, AstNode *node) {
|
|||
case NodeTypeStructValueField:
|
||||
zig_panic("TODO");
|
||||
case NodeTypeArrayType:
|
||||
zig_panic("TODO");
|
||||
{
|
||||
fprintf(ar->f, "[");
|
||||
if (node->data.array_type.size) {
|
||||
render_node(ar, node->data.array_type.size);
|
||||
}
|
||||
fprintf(ar->f, "]");
|
||||
if (node->data.array_type.is_const) {
|
||||
fprintf(ar->f, "const ");
|
||||
}
|
||||
render_node(ar, node->data.array_type.child_type);
|
||||
break;
|
||||
}
|
||||
case NodeTypeErrorType:
|
||||
zig_panic("TODO");
|
||||
}
|
||||
|
|
|
@ -121,6 +121,25 @@ static AstNode *create_struct_field_node(Context *c, const char *name, AstNode *
|
|||
return node;
|
||||
}
|
||||
|
||||
static AstNode *create_num_lit_unsigned(Context *c, uint64_t x) {
|
||||
AstNode *node = create_node(c, NodeTypeNumberLiteral);
|
||||
node->data.number_literal.kind = NumLitUInt;
|
||||
node->data.number_literal.data.x_uint = x;
|
||||
|
||||
normalize_parent_ptrs(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
static AstNode *create_array_type_node(Context *c, AstNode *child_type_node, uint64_t size, bool is_const) {
|
||||
AstNode *node = create_node(c, NodeTypeArrayType);
|
||||
node->data.array_type.size = create_num_lit_unsigned(c, size);
|
||||
node->data.array_type.child_type = child_type_node;
|
||||
node->data.array_type.is_const = is_const;
|
||||
|
||||
normalize_parent_ptrs(node);
|
||||
return node;
|
||||
}
|
||||
|
||||
static const char *decl_name(const Decl *decl) {
|
||||
const NamedDecl *named_decl = static_cast<const NamedDecl *>(decl);
|
||||
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,
|
|||
return nullptr;
|
||||
}
|
||||
}
|
||||
case Type::ConstantArray:
|
||||
{
|
||||
const ConstantArrayType *const_arr_ty = static_cast<const ConstantArrayType *>(ty);
|
||||
AstNode *child_type_node = make_qual_type_node(c, const_arr_ty->getElementType(), decl);
|
||||
uint64_t size = const_arr_ty->getSize().getLimitedValue();
|
||||
return create_array_type_node(c, child_type_node, size, false);
|
||||
}
|
||||
case Type::BlockPointer:
|
||||
case Type::LValueReference:
|
||||
case Type::RValueReference:
|
||||
case Type::MemberPointer:
|
||||
case Type::ConstantArray:
|
||||
case Type::IncompleteArray:
|
||||
case Type::VariableArray:
|
||||
case Type::DependentSizedArray:
|
||||
|
|
|
@ -1863,6 +1863,10 @@ pub const BarB = enum_Bar.B;
|
|||
pub extern fn func(a: ?&struct_Foo, b: ?&?&enum_Bar);
|
||||
pub const Foo = struct_Foo;
|
||||
pub const Bar = enum_Bar;)OUTPUT");
|
||||
|
||||
add_parseh_case("constant size array", R"SOURCE(
|
||||
void func(int array[20]);
|
||||
)SOURCE", R"OUTPUT(pub extern fn func(array: [20]c_int);)OUTPUT");
|
||||
}
|
||||
|
||||
static void print_compiler_invocation(TestCase *test_case) {
|
||||
|
|
Loading…
Reference in New Issue