]> git.draconx.ca Git - upkg.git/commitdiff
libupkg: Kill upkg_export_class.
authorNick Bowler <nbowler@draconx.ca>
Fri, 13 Jul 2012 14:22:43 +0000 (10:22 -0400)
committerNick Bowler <nbowler@draconx.ca>
Fri, 13 Jul 2012 14:23:37 +0000 (10:23 -0400)
This function was quite broken, and crapped out on a number of the
objects in Engine.u.  Kill it off because we now have the machinery
to do this more properly.

src/libupkg.c
src/upkg.c
src/upkg.h

index d4978a39bd89adabcb06d31ae412f479be13d7fb..c87f66887a0c95ad071b328953a535a480c79699 100644 (file)
@@ -542,49 +542,6 @@ const struct upkg_import *upkg_get_import(struct upkg *pub, unsigned long idx)
        return NULL;
 }
 
-const char *upkg_export_class(struct upkg *pub, unsigned long idx,
-                              const char **package)
-{
-       struct upkg_priv *pkg = (struct upkg_priv *)pub;
-       const struct upkg_import *iclass, *ipackage;
-       struct upkg_export_priv *export;
-       unsigned long pkg_idx;
-
-       if (idx >= pkg->pub.export_count)
-               return NULL;
-
-       export = &pkg->exports[idx];
-
-       /* Assumption: class references are always imports. */
-       format_assert(export->pub.class <= 0, return NULL);
-
-       /* Get the class. */
-       if (export->pub.class == 0) {
-               if (package) *package = "Core";
-               return "Class";
-       }
-
-       pkg_idx = -(export->pub.class + 1);
-       if (pkg_idx >= pkg->pub.import_count)
-               return NULL;
-       iclass = &pkg->imports[pkg_idx];
-
-       /* Assumption: class references are always Core.Class. */
-       format_assert(!strcmp(iclass->class_package, "Core"), return NULL);
-       format_assert(!strcmp(iclass->class_name, "Class"), return NULL);
-
-       ipackage = iclass->parent;
-       if (!ipackage)
-               return NULL;
-
-       /* Assumption: package references are always Core.Package. */
-       format_assert(!strcmp(ipackage->class_package, "Core"), return NULL);
-       format_assert(!strcmp(ipackage->class_name, "Package"), return NULL);
-
-       if (package) *package = ipackage->name;
-       return iclass->name;
-}
-
 struct upkg_file *upkg_export_open(struct upkg *pub, unsigned long idx)
 {
        struct upkg_priv *pkg = (struct upkg_priv *)pub;
index 2b26aa460da470de9ee70124b6a5e8aebdcf9cee..55d13f8f37f71c1c0d7449ed3bb259f2edfbe9c2 100644 (file)
@@ -206,18 +206,39 @@ static void import_print_fullname(const struct upkg_import *import)
        }
 }
 
-void print_upkg_exports(struct upkg *pkg)
+static void
+export_print_class(GTypeModule *pkg, const struct upkg_export *export)
 {
-       for (unsigned i = 0; i < pkg->export_count; i++) {
-               const struct upkg_export *export = upkg_get_export(pkg, i);
-               const char *package, *class;
+       struct upkg *upkg = U_PKG(pkg)->pkg;
 
-               class = upkg_export_class(pkg, i, &package);
+       if (export->class < 0) {
+               const struct upkg_import *class;
 
-               if (!class)
-                       continue;
+               class = upkg_get_import(upkg, -(export->class+1));
+               import_print_fullname(class);
+       } else if (export->class > 0) {
+               const struct upkg_export *class;
+
+               class = upkg_get_export(upkg, export->class-1);
+               export_print_fullname(pkg, class);
+       } else {
+               printf("Core.Class");
+       }
+}
+
+void print_upkg_exports(GTypeModule *pkg)
+{
+       struct upkg *upkg = U_PKG(pkg)->pkg;
+
+       for (unsigned i = 0; i < upkg->export_count; i++) {
+               const struct upkg_export *export = upkg_get_export(upkg, i);
+
+               printf("%u - ", i+1);
+               export_print_fullname(pkg, export);
+               printf(" (");
+               export_print_class(pkg, export);
+               printf(")\n");
 
-               printf("%u - %s (%s.%s)\n", i+1, export->name, package, class);
                printf("  Flags: %lx\n", export->flags);
                if (verbose >= 2) {
                        print_upkg_object_flags("    ", export->flags);
@@ -258,7 +279,7 @@ int package_info(GTypeModule *pkg)
        }
 
        printf("Exports: %lu\n", upkg->export_count);
-       if (verbose >= 1) print_upkg_exports(upkg);
+       if (verbose >= 1) print_upkg_exports(pkg);
        printf("Imports: %lu\n", upkg->import_count);
        if (verbose >= 1) print_upkg_imports(upkg);
 
@@ -284,10 +305,9 @@ static int package_list(GTypeModule *pkg, long current)
                export_print_fullname(pkg, export);
 
                if (verbose >= 1) {
-                       const char *class, *package;
-
-                       class = upkg_export_class(upkg, i, &package);
-                       printf(" (%s.%s)", package, class);
+                       printf(" (");
+                       export_print_class(pkg, export);
+                       printf(")");
                }
 
                putchar('\n');
@@ -361,17 +381,14 @@ static int object_info(GTypeModule *pkg, unsigned long idx)
 {
        struct upkg *upkg = U_PKG(pkg)->pkg;
        const struct upkg_export *export;
-       const char *class, *package;
        int ret = 0;
 
        export = upkg_get_export(upkg, idx);
        export_print_fullname(pkg, export);
 
-       class = upkg_export_class(upkg, idx, &package);
-       if (class)
-               printf(" (%s.%s)\n", package, class);
-       else
-               printf(" (failed to get class)\n");
+       printf(" (");
+       export_print_class(pkg, export);
+       printf(")\n");
 
        if (verbose >= 1 && object_dump_properties(pkg, idx) != 0)
                ret = -1;
index d236714f091b0e165d44c91de9ce687cab04ff2c..da85a268382cc5473d39a3b9ab1e244eabacff4b 100644 (file)
@@ -115,9 +115,6 @@ const struct upkg_import *upkg_get_import(struct upkg *pkg, unsigned long idx);
 
 long upkg_export_find(struct upkg *pkg, long parent, const char *name);
 
-const char *upkg_export_class(struct upkg *pkg, unsigned long idx,
-                              const char **package);
-
 struct upkg_file *upkg_export_open(struct upkg *pkg, unsigned long idx);
 size_t upkg_export_read(struct upkg_file *f, void *buf, size_t n);
 int    upkg_export_seek(struct upkg_file *f, long offset, int whence);