authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-27 16:00:43-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-27 16:00:43-07:00
log75cab48c1e88b32c0fea5905761bf0adf7a87101
tree9035a6bd868d38f17db280fcbb539e0dbc912e2b
parentb50844185991a86bac462346413341b87eda14cd

parseh: recognize typedef types

and fix const qualifier on pointers

2 files changed, 25 insertions(+), 6 deletions(-)

src/main.cpp+4-1
......@@ -175,8 +175,11 @@ static Buf *type_node_to_name(AstNode *type_node) {
175175 return &type_node->data.symbol_expr.symbol;
176176 } else if (type_node->type == NodeTypePrefixOpExpr) {
177177 PrefixOp op = type_node->data.prefix_op_expr.prefix_op;
178 const char *child_type_str = buf_ptr(type_node_to_name(type_node->data.prefix_op_expr.primary_expr));
178179 if (op == PrefixOpAddressOf) {
179 return buf_sprintf("&%s", buf_ptr(type_node_to_name(type_node->data.prefix_op_expr.primary_expr)));
180 return buf_sprintf("&%s", child_type_str);
181 } else if (op == PrefixOpConstAddressOf) {
182 return buf_sprintf("&const %s", child_type_str);
180183 } else {
181184 zig_unreachable();
182185 }
src/parseh.cpp+21-5
......@@ -49,7 +49,7 @@ static AstNode *pointer_to_type(Context *c, AstNode *type_node, bool is_const) {
4949 return node;
5050}
5151
52static AstNode *type_node(Context *c, const Type *ty, bool is_const) {
52static AstNode *type_node(Context *c, const Type *ty) {
5353 switch (ty->getTypeClass()) {
5454 case Type::Builtin:
5555 {
......@@ -120,10 +120,17 @@ static AstNode *type_node(Context *c, const Type *ty, bool is_const) {
120120 case Type::Pointer:
121121 {
122122 const PointerType *pointer_ty = static_cast<const PointerType*>(ty);
123 AstNode *type_node = type_node_from_qual_type(c, pointer_ty->getPointeeType());
124 return pointer_to_type(c, type_node, is_const);
123 QualType child_qt = pointer_ty->getPointeeType();
124 AstNode *type_node = type_node_from_qual_type(c, child_qt);
125 return pointer_to_type(c, type_node, child_qt.isConstQualified());
125126 }
126127 case Type::Typedef:
128 {
129 const TypedefType *typedef_ty = static_cast<const TypedefType*>(ty);
130 const TypedefNameDecl *typedef_decl = typedef_ty->getDecl();
131 const char *type_name = buf_ptr(buf_create_from_str(decl_name(typedef_decl)));
132 return simple_type_node(c, type_name);
133 }
127134 case Type::FunctionProto:
128135 case Type::Record:
129136 case Type::Enum:
......@@ -168,8 +175,7 @@ static AstNode *type_node(Context *c, const Type *ty, bool is_const) {
168175}
169176
170177static AstNode *type_node_from_qual_type(Context *c, QualType qt) {
171 bool is_const = qt.isConstQualified();
172 return type_node(c, qt.getTypePtr(), is_const);
178 return type_node(c, qt.getTypePtr());
173179}
174180
175181static bool decl_visitor(void *context, const Decl *decl) {
......@@ -210,6 +216,16 @@ static bool decl_visitor(void *context, const Decl *decl) {
210216
211217 break;
212218 }
219 /*
220 case Decl::Typedef:
221 {
222 AstNode *node = create_node(c, NodeTypeVariableDeclaration);
223 node->data.variable_declaration.is_const = true;
224 buf_init_from_str(&node->data.variable_declaration.symbol, decl_name(decl));
225
226 break;
227 }
228 */
213229 default:
214230 if (c->warnings_on) {
215231 fprintf(stderr, "ignoring %s\n", decl->getDeclKindName());