Commits

camlspotter  committed 23d0583

class dependency

  • Participants
  • Parent commits fc3eacd
  • Branches dev

Comments (0)

Files changed (3)

 ^auto\.(idl|ml|mli)$
 ^.*\.idl$
 ^auto_stubs\.c$
+autoapi\.mlp$
 autoapi\.ml$
 autoclasses.*$
 test$
 #!/usr/bin/perl
 
+get_class_deps();
 get_comments();
 filter();
 
+%deps;
+
+# obtain class dependency from type.ml
+sub get_class_deps {
+    open(IN, "type.ml");
+    while(<IN>){
+	if( /type\s+(_[A-Z][a-z0-9]+)\s*=\s*\[([^\]]+)\]/ ){
+	    my $cls = $1;
+	    my $deps = $2;
+	    $cls =~ s/^_//;
+	    $deps =~ s/`_[A-Z][a-z]+//g;
+	    $deps =~ s/\(\*.*\*\)//g;
+	    $deps =~ s/_([A-Z])/$1/g;
+	    my @deps = split(/\s|\|/, $deps);
+	    $deps{$cls} = \@deps;
+	    printf STDERR "$cls: %s\n", join(' ', @{$deps{$cls}});
+	}
+    }
+    close(IN);
+}
+
+
 sub get_comments {
     for $i (@ARGV){
 	open(IN, "$i");
     }
 }
 
+%printed_module;
+
+sub print_module {
+    my $k = $_[0];
+
+    if( $printed_module{$k} ){ return; }
+    
+    for my $kk (@{$deps{$k}}) {
+	print_module($kk);
+    }
+
+    print STDERR "printing $k\n";
+    $printed_module{$k} = 1;
+
+    print "module $k = struct\n";
+    print $mod{$k};
+    if( $mod{$k} =~ /external check +: \[>_Object\] t -> bool/ ){
+        print 
+"  (** coercion to [_$k t]. Raises Coercion when impossible *)
+  let coerce : [>_Object] t -> _$k t = fun t ->
+    if check t then unsafe_coerce t else raise Coercion
+  ;;
+
+  (** coercion to [_$k t]. Return None when impossible *)
+  let coerce_opt : [>_Object] t -> _$k t option = fun t ->
+    if check t then Some (unsafe_coerce t) else None
+  ;;
+";
+    }
+    print "end\n\n";
+}
+
 sub filter {
     open(IN, "auto.ml");
     while(<IN>){
 
     print "open Type\n\n";
     for $k (keys %mod){
-        print "module $k = struct\n";
-        print $mod{$k};
-	if( $mod{$k} =~ /external check +: \[>_Object\] t -> bool/ ){
-	    print 
-"  (** coercion to [_$k t]. Raises Coercion when impossible *)
-  let coerce : [>_Object] t -> _$k t = fun t ->
-    if check t then unsafe_coerce t else raise Coercion
-  ;;
-
-  (** coercion to [_$k t]. Return None when impossible *)
-  let coerce_opt : [>_Object] t -> _$k t option = fun t ->
-    if check t then Some (unsafe_coerce t) else None
-  ;;
-";
-	}
-        print "end\n\n";
+	print_module($k);
     }
 }
 
 type _String = [_Sequence | `_String]
 type _Unicode = [_String (* ? *) | `_Unicode]
 type _Tuple = [_Sequence | `_Tuple]
-type _Mutable = [_Sequence | `Mutable]
+type _Mutable = [_Sequence | `_Mutable]
 type _List = [_Mutable | `_List]
 type _ByteArray = [_Mutable | `_ByteArray]
 (* _Set