- void *dlopened = NULL;
- size_t i, count = C->count++, check_round, check_count;
- decl_typedefs *check_defs = P->defs;
- decl_structs *check_structs = P->structs;
- decl_unions *check_unions = P->unions;
- decl_enums *check_enums = P->enums;
- unsigned flags = C->flags;
-
- C->data = realloc(C->data, C->count * sizeof(*C->data));
- D = psi_data_exchange(&C->data[count], PSI_DATA(P));
-
-#define REVALIDATE(what) do { \
- if (check_round && check_ ##what) { \
- free(check_ ##what->list); \
- free(check_ ##what); \
- } \
- check_ ##what = recheck_ ##what; \
-} while (0)
-#define CHECK_TOTAL (CHECK_COUNT(defs) + CHECK_COUNT(structs) + CHECK_COUNT(enums))
-#define CHECK_COUNT(of) (check_ ##of ? check_ ##of->count : 0)
-
- if (!(flags & PSI_PARSER_SILENT)) {
- /* no warnings on first round */
- C->flags |= PSI_PARSER_SILENT;
- }
- for (check_round = 0, check_count = 0; CHECK_TOTAL && check_count != CHECK_TOTAL; ++check_round) {
- decl_typedefs *recheck_defs = NULL;
- decl_structs *recheck_structs = NULL;
- decl_unions *recheck_unions = NULL;
- decl_enums *recheck_enums = NULL;
-
- check_count = CHECK_TOTAL;
-
- for (i = 0; i < CHECK_COUNT(defs); ++i) {
- if (validate_decl_typedef(PSI_DATA(C), check_defs->list[i])) {
- C->defs = add_decl_typedef(C->defs, check_defs->list[i]);
- } else {
- recheck_defs = add_decl_typedef(recheck_defs, check_defs->list[i]);
- }
- }
- for (i = 0; i < CHECK_COUNT(structs); ++i) {
- if (validate_decl_struct(PSI_DATA(C), check_structs->list[i])) {
- C->structs = add_decl_struct(C->structs, check_structs->list[i]);
- } else {
- recheck_structs = add_decl_struct(recheck_structs, check_structs->list[i]);
- }
- }
- for (i = 0; i < CHECK_COUNT(unions); ++i) {
- if (validate_decl_union(PSI_DATA(C), check_unions->list[i])) {
- C->unions = add_decl_union(C->unions, check_unions->list[i]);
- } else {
- recheck_unions = add_decl_union(recheck_unions, check_unions->list[i]);
- }
- }
- for (i = 0; i < CHECK_COUNT(enums); ++i) {
- if (validate_decl_enum(PSI_DATA(C), check_enums->list[i])) {
- C->enums = add_decl_enum(C->enums, check_enums->list[i]);
- } else {
- recheck_enums = add_decl_enum(recheck_enums, check_enums->list[i]);
- }
- }
-
- REVALIDATE(defs);
- REVALIDATE(structs);
- REVALIDATE(unions);
- REVALIDATE(enums);
-
- if (check_round == 0 && !(flags & PSI_PARSER_SILENT)) {
- C->flags ^= PSI_PARSER_SILENT;
- }
- }
-
- C->flags = flags;
-
- if (D->consts) {
- for (i = 0; i < D->consts->count; ++i) {
- if (validate_constant(PSI_DATA(C), D->consts->list[i])) {
- C->consts = add_constant(C->consts, D->consts->list[i]);
- }
- }
- }
-
- if (!validate_file(D, &dlopened)) {
- return 0;
- }
-
- add_decl_lib(&C->psi.libs, dlopened);
-
- if (D->decls) {
- for (i = 0; i < D->decls->count; ++i) {
- if (validate_decl(PSI_DATA(C), dlopened, D->decls->list[i])) {
- C->decls = add_decl(C->decls, D->decls->list[i]);
- }
- }
- }
- if (D->impls) {
- for (i = 0; i < D->impls->count; ++i) {
- if (validate_impl(PSI_DATA(C), D->impls->list[i])) {
- C->impls = add_impl(C->impls, D->impls->list[i]);
- }
- }
- }
-
- return 1;
-}
-
-int psi_context_validate_data(struct psi_data *dest, struct psi_data *source)
-{
- size_t i;
- int errors = 0;
-
- if (source->defs) for (i = 0; i < source->defs->count; ++i) {
- decl_arg *def = source->defs->list[i];
-
- if (validate_decl_typedef(source, def)) {
- if (dest) {
- dest->defs = add_decl_typedef(dest->defs, def);
- }
- } else {
- ++errors;
- }
- }
-
- if (source->consts) for (i = 0; i < source->consts->count; ++i) {
- constant *constant = source->consts->list[i];
-
- if (validate_constant(source, constant)) {
- if (dest) {
- dest->consts = add_constant(dest->consts, constant);
- }
- } else {
- ++errors;
- }
- }
-
- if (source->structs) for (i = 0; i < source->structs->count; ++i) {
- decl_struct *dstruct = source->structs->list[i];