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) {...@@ -175,8 +175,11 @@ static Buf *type_node_to_name(AstNode *type_node) {
175 return &type_node->data.symbol_expr.symbol;175 return &type_node->data.symbol_expr.symbol;
176 } else if (type_node->type == NodeTypePrefixOpExpr) {176 } else if (type_node->type == NodeTypePrefixOpExpr) {
177 PrefixOp op = type_node->data.prefix_op_expr.prefix_op;177 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));
178 if (op == PrefixOpAddressOf) {179 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);
180 } else {183 } else {
181 zig_unreachable();184 zig_unreachable();
182 }185 }
src/parseh.cpp+21-5
...@@ -49,7 +49,7 @@ static AstNode *pointer_to_type(Context *c, AstNode *type_node, bool is_const) {...@@ -49,7 +49,7 @@ static AstNode *pointer_to_type(Context *c, AstNode *type_node, bool is_const) {
49 return node;49 return node;
50}50}
5151
52static AstNode *type_node(Context *c, const Type *ty, bool is_const) {52static AstNode *type_node(Context *c, const Type *ty) {
53 switch (ty->getTypeClass()) {53 switch (ty->getTypeClass()) {
54 case Type::Builtin:54 case Type::Builtin:
55 {55 {
...@@ -120,10 +120,17 @@ static AstNode *type_node(Context *c, const Type *ty, bool is_const) {...@@ -120,10 +120,17 @@ static AstNode *type_node(Context *c, const Type *ty, bool is_const) {
120 case Type::Pointer:120 case Type::Pointer:
121 {121 {
122 const PointerType *pointer_ty = static_cast<const PointerType*>(ty);122 const PointerType *pointer_ty = static_cast<const PointerType*>(ty);
123 AstNode *type_node = type_node_from_qual_type(c, pointer_ty->getPointeeType());123 QualType child_qt = pointer_ty->getPointeeType();
124 return pointer_to_type(c, type_node, is_const);124 AstNode *type_node = type_node_from_qual_type(c, child_qt);
125 return pointer_to_type(c, type_node, child_qt.isConstQualified());
125 }126 }
126 case Type::Typedef:127 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 }
127 case Type::FunctionProto:134 case Type::FunctionProto:
128 case Type::Record:135 case Type::Record:
129 case Type::Enum:136 case Type::Enum:
...@@ -168,8 +175,7 @@ static AstNode *type_node(Context *c, const Type *ty, bool is_const) {...@@ -168,8 +175,7 @@ static AstNode *type_node(Context *c, const Type *ty, bool is_const) {
168}175}
169176
170static AstNode *type_node_from_qual_type(Context *c, QualType qt) {177static AstNode *type_node_from_qual_type(Context *c, QualType qt) {
171 bool is_const = qt.isConstQualified();178 return type_node(c, qt.getTypePtr());
172 return type_node(c, qt.getTypePtr(), is_const);
173}179}
174180
175static bool decl_visitor(void *context, const Decl *decl) {181static bool decl_visitor(void *context, const Decl *decl) {
...@@ -210,6 +216,16 @@ static bool decl_visitor(void *context, const Decl *decl) {...@@ -210,6 +216,16 @@ static bool decl_visitor(void *context, const Decl *decl) {
210216
211 break;217 break;
212 }218 }
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 */
213 default:229 default:
214 if (c->warnings_on) {230 if (c->warnings_on) {
215 fprintf(stderr, "ignoring %s\n", decl->getDeclKindName());231 fprintf(stderr, "ignoring %s\n", decl->getDeclKindName());