Lines 280-287
static tree any_external_decl PARAMS ((
Link Here
|
280 |
static void record_external_decl PARAMS ((tree)); |
281 |
static void record_external_decl PARAMS ((tree)); |
281 |
static void warn_if_shadowing PARAMS ((tree, tree)); |
282 |
static void warn_if_shadowing PARAMS ((tree, tree)); |
282 |
static void clone_underlying_type PARAMS ((tree)); |
283 |
static void clone_underlying_type PARAMS ((tree)); |
|
|
284 |
static int field_decl_cmp PARAMS ((const PTR, const PTR)); |
285 |
static int resort_field_decl_cmp (const void*, const void*); |
283 |
static bool flexible_array_type_p PARAMS ((tree)); |
286 |
static bool flexible_array_type_p PARAMS ((tree)); |
284 |
|
287 |
|
|
|
288 |
|
285 |
/* States indicating how grokdeclarator() should handle declspecs marked |
289 |
/* States indicating how grokdeclarator() should handle declspecs marked |
286 |
with __attribute__((deprecated)). An object declared as |
290 |
with __attribute__((deprecated)). An object declared as |
287 |
__attribute__((deprecated)) suppresses warnings of uses of other |
291 |
__attribute__((deprecated)) suppresses warnings of uses of other |
Lines 4959-4964
detect_field_duplicates (tree fieldlist)
Link Here
|
4959 |
} |
4963 |
} |
4960 |
} |
4964 |
} |
4961 |
|
4965 |
|
|
|
4966 |
/* Function to help qsort sort FIELD_DECLs by name order. */ |
4967 |
|
4968 |
|
4969 |
static int |
4970 |
field_decl_cmp (xp, yp) |
4971 |
const PTR xp; |
4972 |
const PTR yp; |
4973 |
{ |
4974 |
tree *x = (tree *)xp, *y = (tree *)yp; |
4975 |
|
4976 |
if (DECL_NAME (*x) == DECL_NAME (*y)) |
4977 |
return 0; |
4978 |
if (DECL_NAME (*x) == NULL) |
4979 |
return -1; |
4980 |
if (DECL_NAME (*y) == NULL) |
4981 |
return 1; |
4982 |
if (DECL_NAME (*x) < DECL_NAME (*y)) |
4983 |
return -1; |
4984 |
return 1; |
4985 |
} |
4986 |
|
4987 |
static struct { |
4988 |
gt_pointer_operator new_value; |
4989 |
void *cookie; |
4990 |
} resort_data; |
4991 |
|
4992 |
/* This routine compares two fields like field_decl_cmp but using the |
4993 |
pointer operator in resort_data. */ |
4994 |
|
4995 |
static int |
4996 |
resort_field_decl_cmp (const void* x_p, const void* y_p) |
4997 |
{ |
4998 |
const tree *const x = x_p; |
4999 |
const tree *const y = y_p; |
5000 |
|
5001 |
if (DECL_NAME (*x) == DECL_NAME (*y)) |
5002 |
return 0; |
5003 |
if (DECL_NAME (*x) == NULL_TREE) |
5004 |
return -1; |
5005 |
if (DECL_NAME (*y) == NULL_TREE) |
5006 |
return 1; |
5007 |
{ |
5008 |
tree d1 = DECL_NAME (*x); |
5009 |
tree d2 = DECL_NAME (*y); |
5010 |
resort_data.new_value (&d1, resort_data.cookie); |
5011 |
resort_data.new_value (&d2, resort_data.cookie); |
5012 |
if (d1 < d2) |
5013 |
return -1; |
5014 |
} |
5015 |
return 1; |
5016 |
} |
5017 |
|
5018 |
|
5019 |
/* Resort DECL_SORTED_FIELDS because pointers have been reordered. */ |
5020 |
|
5021 |
void |
5022 |
resort_sorted_fields (void* obj, |
5023 |
void* orig_obj ATTRIBUTE_UNUSED , |
5024 |
gt_pointer_operator new_value, |
5025 |
void* cookie) |
5026 |
{ |
5027 |
lang_type_s_1 sf = obj; |
5028 |
resort_data.new_value = new_value; |
5029 |
resort_data.cookie = cookie; |
5030 |
qsort (&sf->elts[0], sf->len, sizeof (tree), |
5031 |
resort_field_decl_cmp); |
5032 |
} |
5033 |
|
4962 |
/* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T. |
5034 |
/* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T. |
4963 |
FIELDLIST is a chain of FIELD_DECL nodes for the fields. |
5035 |
FIELDLIST is a chain of FIELD_DECL nodes for the fields. |
4964 |
ATTRIBUTES are attributes to be applied to the structure. */ |
5036 |
ATTRIBUTES are attributes to be applied to the structure. */ |
Lines 5162-5167
finish_struct (t, fieldlist, attributes)
Link Here
|
5162 |
|
5234 |
|
5163 |
TYPE_FIELDS (t) = fieldlist; |
5235 |
TYPE_FIELDS (t) = fieldlist; |
5164 |
|
5236 |
|
|
|
5237 |
/* If there are lots of fields, sort so we can look through them fast. |
5238 |
We arbitrarily consider 16 or more elts to be "a lot". */ |
5239 |
|
5240 |
{ |
5241 |
int len = 0; |
5242 |
|
5243 |
for (x = fieldlist; x; x = TREE_CHAIN (x)) |
5244 |
{ |
5245 |
if (len > 15 || DECL_NAME (x) == NULL) |
5246 |
break; |
5247 |
len += 1; |
5248 |
} |
5249 |
|
5250 |
if (len > 15) |
5251 |
{ |
5252 |
tree *field_array; |
5253 |
char *space; |
5254 |
char *space2; |
5255 |
|
5256 |
len += list_length (x); |
5257 |
|
5258 |
/* Use the same allocation policy here that make_node uses, to |
5259 |
ensure that this lives as long as the rest of the struct decl. |
5260 |
All decls in an inline function need to be saved. */ |
5261 |
|
5262 |
space = ggc_alloc (sizeof (struct lang_type)); |
5263 |
space2 = ggc_alloc (sizeof (struct lang_type_s) + len * sizeof (tree)); |
5264 |
|
5265 |
len = 0; |
5266 |
((struct lang_type *) space)->s = (lang_type_s_1) space2; |
5267 |
field_array = &(((struct lang_type *) space)->s->elts[0]); |
5268 |
for (x = fieldlist; x; x = TREE_CHAIN (x)) |
5269 |
{ |
5270 |
field_array[len++] = x; |
5271 |
|
5272 |
/* if there is anonymous struct or unoin break out of the loop */ |
5273 |
if (DECL_NAME (x) == NULL) |
5274 |
break; |
5275 |
} |
5276 |
/* found no anonymous struct/union add the TYPE_LANG_SPECIFIC. */ |
5277 |
if (x == NULL) |
5278 |
{ |
5279 |
TYPE_LANG_SPECIFIC (t) = (struct lang_type *) space; |
5280 |
TYPE_LANG_SPECIFIC (t)->s->len = len; |
5281 |
field_array = &TYPE_LANG_SPECIFIC (t)->s->elts[0]; |
5282 |
qsort (field_array, len, sizeof (tree), field_decl_cmp); |
5283 |
} |
5284 |
} |
5285 |
} |
5286 |
|
5165 |
for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x)) |
5287 |
for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x)) |
5166 |
{ |
5288 |
{ |
5167 |
TYPE_FIELDS (x) = TYPE_FIELDS (t); |
5289 |
TYPE_FIELDS (x) = TYPE_FIELDS (t); |