- 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];
-
- if (validate_decl_struct(source, dstruct)) {
- if (dest) {
- dest->structs = add_decl_struct(dest->structs, dstruct);
- }
- } else {
- ++errors;
- }
- }
-
- if (source->unions) for (i = 0; i < source->unions->count; ++i) {
- decl_union *dunion = source->unions->list[i];
-
- if (validate_decl_union(source, dunion)) {
- if (dest) {
- dest->unions = add_decl_union(dest->unions, dunion);
- }
- } else {
- ++errors;
- }
- }
-
- if (source->enums) for (i = 0; i < source->enums->count; ++i) {
- decl_enum *denum = source->enums->list[i];
-
- if (validate_decl_enum(source, denum)) {
- if (dest) {
- dest->enums = add_decl_enum(dest->enums, denum);
- }
- } else {
- ++errors;
- }
- }
-
- if (source->decls) for (i = 0; i < source->decls->count; ++i) {
- decl *decl = source->decls->list[i];
-
- if (validate_decl(source, NULL, decl)) {
- if (dest) {
- dest->decls = add_decl(dest->decls, decl);
- }
- } else {
- ++errors;
- }
- }
-
- if (source->impls) for (i = 0; i < source->impls->count; ++i) {
- impl *impl = source->impls->list[i];
-
- if (validate_impl(source, impl)) {
- if (dest) {
- dest->impls = add_impl(dest->impls, impl);
- }
- } else {
- ++errors;
- }
- }
-
- return errors;
-}
-
-static inline void dump_data(int fd, struct psi_data *D) {
- if (D->psi.file.fn) {
- dprintf(fd, "// psi.filename=%s\n", D->psi.file.fn);
- if (D->psi.file.ln) {
- dprintf(fd, "lib \"%s\";\n", D->psi.file.ln);
- }
- } else {
- dprintf(fd, "// builtin predef\n");
- }
- if (D->defs) {
- dump_decl_typedefs(fd, D->defs);
- dprintf(fd, "\n");
- }
- if (D->unions) {
- dump_decl_unions(fd, D->unions);
- dprintf(fd, "\n");
- }
- if (D->structs) {
- dump_decl_structs(fd, D->structs);
- dprintf(fd, "\n");
- }
- if (D->enums) {
- dump_decl_enums(fd, D->enums);
- dprintf(fd, "\n");
- }
- if (D->consts) {
- dump_constants(fd, D->consts);
- dprintf(fd, "\n");
- }
- if (D->decls) {
- dump_decls(fd, D->decls);
- dprintf(fd, "\n");
- }
- if (D->impls) {
- dump_impls(fd, D->impls);
- dprintf(fd, "\n");
- }