projects
/
cparser
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
2 test programs I had lying around here
[cparser]
/
type.c
diff --git
a/type.c
b/type.c
index
8568ed6
..
d4ad8b9
100644
(file)
--- a/
type.c
+++ b/
type.c
@@
-47,7
+47,7
@@
void print_atomic_type(const atomic_type_t *type)
print_type_qualifiers(type->type.qualifiers);
const char *s;
print_type_qualifiers(type->type.qualifiers);
const char *s;
- switch(type->a
type
) {
+ switch(type->a
kind
) {
case ATOMIC_TYPE_INVALID: s = "INVALIDATOMIC"; break;
case ATOMIC_TYPE_VOID: s = "void"; break;
case ATOMIC_TYPE_BOOL: s = "_Bool"; break;
case ATOMIC_TYPE_INVALID: s = "INVALIDATOMIC"; break;
case ATOMIC_TYPE_VOID: s = "void"; break;
case ATOMIC_TYPE_BOOL: s = "_Bool"; break;
@@
-416,7
+416,7
@@
bool is_type_integer(const type_t *type)
if(type->kind != TYPE_ATOMIC)
return false;
if(type->kind != TYPE_ATOMIC)
return false;
- switch(type->atomic.a
type
) {
+ switch(type->atomic.a
kind
) {
case ATOMIC_TYPE_BOOL:
case ATOMIC_TYPE_CHAR:
case ATOMIC_TYPE_SCHAR:
case ATOMIC_TYPE_BOOL:
case ATOMIC_TYPE_CHAR:
case ATOMIC_TYPE_SCHAR:
@@
-442,7
+442,7
@@
bool is_type_floating(const type_t *type)
if(type->kind != TYPE_ATOMIC)
return false;
if(type->kind != TYPE_ATOMIC)
return false;
- switch(type->atomic.a
type
) {
+ switch(type->atomic.a
kind
) {
case ATOMIC_TYPE_FLOAT:
case ATOMIC_TYPE_DOUBLE:
case ATOMIC_TYPE_LONG_DOUBLE:
case ATOMIC_TYPE_FLOAT:
case ATOMIC_TYPE_DOUBLE:
case ATOMIC_TYPE_LONG_DOUBLE:
@@
-471,7
+471,7
@@
bool is_type_signed(const type_t *type)
if(type->kind != TYPE_ATOMIC)
return false;
if(type->kind != TYPE_ATOMIC)
return false;
- switch(type->atomic.a
type
) {
+ switch(type->atomic.a
kind
) {
case ATOMIC_TYPE_CHAR:
case ATOMIC_TYPE_SCHAR:
case ATOMIC_TYPE_SHORT:
case ATOMIC_TYPE_CHAR:
case ATOMIC_TYPE_SCHAR:
case ATOMIC_TYPE_SHORT:
@@
-554,7
+554,7
@@
bool is_type_incomplete(const type_t *type)
return type->array.size == NULL;
case TYPE_ATOMIC:
return type->array.size == NULL;
case TYPE_ATOMIC:
- return type->atomic.a
type
== ATOMIC_TYPE_VOID;
+ return type->atomic.a
kind
== ATOMIC_TYPE_VOID;
case TYPE_POINTER:
case TYPE_ENUM:
case TYPE_POINTER:
case TYPE_ENUM:
@@
-643,7
+643,7
@@
bool types_compatible(const type_t *type1, const type_t *type2)
case TYPE_FUNCTION:
return function_types_compatible(&type1->function, &type2->function);
case TYPE_ATOMIC:
case TYPE_FUNCTION:
return function_types_compatible(&type1->function, &type2->function);
case TYPE_ATOMIC:
- return type1->atomic.a
type == type2->atomic.atype
;
+ return type1->atomic.a
kind == type2->atomic.akind
;
case TYPE_ARRAY:
return array_types_compatible(&type1->array, &type2->array);
case TYPE_ARRAY:
return array_types_compatible(&type1->array, &type2->array);
@@
-689,7
+689,7
@@
bool pointers_compatible(const type_t *type1, const type_t *type2)
type_t *skip_typeref(type_t *type)
{
type_t *skip_typeref(type_t *type)
{
- unsigned qualifiers =
type->base.qualifiers
;
+ unsigned qualifiers =
TYPE_QUALIFIER_NONE
;
while(true) {
switch(type->kind) {
while(true) {
switch(type->kind) {
@@
-718,6
+718,16
@@
type_t *skip_typeref(type_t *type)
break;
}
break;
}
+ if (qualifiers != TYPE_QUALIFIER_NONE) {
+ type_t *const copy = duplicate_type(type);
+ copy->base.qualifiers |= qualifiers;
+
+ type = typehash_insert(copy);
+ if (type != copy) {
+ obstack_free(type_obst, copy);
+ }
+ }
+
return type;
}
return type;
}
@@
-732,14
+742,14
@@
static type_t *identify_new_type(type_t *type)
return result;
}
return result;
}
-type_t *make_atomic_type(atomic_type_
type
_t atype, type_qualifiers_t qualifiers)
+type_t *make_atomic_type(atomic_type_
kind
_t atype, type_qualifiers_t qualifiers)
{
type_t *type = obstack_alloc(type_obst, sizeof(atomic_type_t));
memset(type, 0, sizeof(atomic_type_t));
type->kind = TYPE_ATOMIC;
type->base.qualifiers = qualifiers;
{
type_t *type = obstack_alloc(type_obst, sizeof(atomic_type_t));
memset(type, 0, sizeof(atomic_type_t));
type->kind = TYPE_ATOMIC;
type->base.qualifiers = qualifiers;
- type->atomic.a
type
= atype;
+ type->atomic.a
kind
= atype;
return identify_new_type(type);
}
return identify_new_type(type);
}