~ubuntu-branches/ubuntu/oneiric/haxe/oneiric

« back to all changes in this revision

Viewing changes to haxe/std/Type.hx

  • Committer: Bazaar Package Importer
  • Author(s): Jens Peter Secher
  • Date: 2009-08-03 21:29:45 UTC
  • mfrom: (5.1.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090803212945-hy4s0okm36gtqzz5
Tags: 1:2.4-1
* New upstream version (CVS 2009-08-01).
* Removed obsolete parts of the copyright file now that ExtLib is 
  not included anymore.
* Included patch for Ubuntu location of zlib, thanks to Alessio Treglia.
  (Closes: #533159)
* Removed haxe-mode to get it into its own package.
  (Closes: #521222)
* Included new commands in bash_completion.
* Removed obsolete Lintian overrides.
* Bumped Standards-Version to 3.8.2, no change.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
        TObject;
11
11
        TFunction;
12
12
        TClass( c : Class<Dynamic> );
13
 
        TEnum( e : Enum );
 
13
        TEnum( e : Enum<Dynamic> );
14
14
        TUnknown;
15
15
}
16
16
 
76
76
        /**
77
77
                Returns the enum of a value or [null] if this value is not an Enum instance.
78
78
        **/
79
 
        public static function getEnum( o : Dynamic ) : Enum untyped {
 
79
        public static function getEnum( o : Dynamic ) : Enum<Dynamic> untyped {
80
80
                #if flash9
81
81
                        var cname = __global__["flash.utils.getQualifiedClassName"](o);
82
82
                        if( cname == "null" || cname.substr(0,8) == "builtin." )
164
164
        /**
165
165
                Returns the complete name of an enum.
166
166
        **/
167
 
        public static function getEnumName( e : Enum ) : String {
 
167
        public static function getEnumName( e : Enum<Dynamic> ) : String {
168
168
                #if flash9
169
169
                        return getClassName(cast e);
170
170
                #elseif php
236
236
                Evaluates an enum from a name. The enum must have been compiled
237
237
                to be accessible.
238
238
        **/
239
 
        public static function resolveEnum( name : String ) : Enum untyped {
 
239
        public static function resolveEnum( name : String ) : Enum<Dynamic> untyped {
240
240
                #if php
241
241
                        var e = untyped __call__("_hx_qtype", name);
242
242
                        if(untyped __php__("$e instanceof _hx_enum"))
298
298
                        case 6: __new__(cl,args[0],args[1],args[2],args[3],args[4],args[5]);
299
299
                        case 7: __new__(cl,args[0],args[1],args[2],args[3],args[4],args[5],args[6]);
300
300
                        case 8: __new__(cl,args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]);
 
301
                        case 9: __new__(cl,args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8]);
 
302
                        case 10: __new__(cl,args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9]);
 
303
                        case 11: __new__(cl,args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10]);
 
304
                        case 12: __new__(cl,args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11]);
 
305
                        case 13: __new__(cl,args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11],args[12]);
 
306
                        case 14: __new__(cl,args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11],args[12],args[13]);
301
307
                        default: throw "Too many arguments";
302
308
                        }
303
309
                #elseif flash
318
324
                        if(cl.__qname__ == 'String') return args[0];
319
325
                        var c = cl.__rfl__();
320
326
                        if(c == null) return null;
321
 
                        return __php__("$inst = $c->getConstructor() ? $c->newInstanceArgs($args->__a) : $c->newInstanceArgs()");
 
327
                        return __php__("$inst = $c->getConstructor() ? $c->newInstanceArgs($args->�a) : $c->newInstanceArgs()");
322
328
                #elseif cpp
323
329
                        if (cl!=null)
324
330
                                return cl.mConstructArgs(args);
388
394
        /**
389
395
                Create an instance of an enum by using a constructor name and parameters.
390
396
        **/
391
 
        public static function createEnum( e : Enum, constr : String, ?params : Array<Dynamic> ) : Dynamic {
 
397
        public static function createEnum<T>( e : Enum<T>, constr : String, ?params : Array<Dynamic> ) : T {
392
398
                #if cpp
393
399
                if (untyped e.mConstructEnum != null)
394
400
                        return untyped e.mConstructEnum(constr,params);
406
412
                #end
407
413
        }
408
414
 
 
415
        /**
 
416
                Create an instance of an enum by using a constructor index and parameters.
 
417
        **/
 
418
        public static function createEnumIndex<T>( e : Enum<T>, index : Int, ?params : Array<Dynamic> ) : T {
 
419
                var c = Type.getEnumConstructs(e)[index];
 
420
                if( c == null ) throw index+" is not a valid enum constructor index";
 
421
                return createEnum(e,c,params);
 
422
        }
 
423
 
409
424
        #if flash9
410
425
        static function describe( t : Dynamic, fact : Bool ) untyped {
411
426
                var fields = new Array();
434
449
                        untyped __php__("
435
450
                        $rfl = $c->__rfl__();
436
451
                        if($rfl === null) return new _hx_array(array());
437
 
                        $ms = $rfl->getMethods();
438
 
                        $ps = $rfl->getProperties();
439
452
                        $r = array();
440
453
                        $internals = array('__construct', '__call', '__get', '__set', '__isset', '__unset', '__toString');
441
 
                        foreach($ms as $m) {
 
454
                        $ms = $rfl->getMethods();
 
455
                        while(list(, $m) = each($ms)) {
442
456
                                $n = $m->getName();
443
457
                                if(!$m->isStatic() && ! in_array($n, $internals)) $r[] = $n;
444
458
                        }
445
 
                        foreach($ps as $p)
446
 
                                if(!$p->isStatic()) $r[] = $p->getName();
447
 
                        ");
 
459
                        $ps = $rfl->getProperties();
 
460
                        while(list(, $p) = each($ps))
 
461
                                if(!$p->isStatic()) $r[] = $p->getName()");
448
462
                        return untyped __php__("new _hx_array(array_values(array_unique($r)))");
449
463
                #elseif cpp
450
464
                        return untyped c.GetInstanceFields();
487
501
                        $rfl = $c->__rfl__();
488
502
                        if($rfl === null) return new _hx_array(array());
489
503
                        $ms = $rfl->getMethods();
490
 
                        $ps = $rfl->getProperties();
491
504
                        $r = array();
492
 
                        foreach($ms as $m)
 
505
                        while(list(, $m) = each($ms))
493
506
                                if($m->isStatic()) $r[] = $m->getName();
494
 
                        foreach($ps as $p)
 
507
                        $ps = $rfl->getProperties();
 
508
                        while(list(, $p) = each($ps))
495
509
                                if($p->isStatic()) $r[] = $p->getName();
496
510
                        ");
497
511
                        return untyped __php__("new _hx_array($r)");
506
520
                        a.remove("prototype");
507
521
                        #end
508
522
                        #if neko
 
523
                        a.remove("__string");
509
524
                        a.remove("__construct__");
510
525
                        a.remove("prototype");
511
526
                        a.remove("new");
517
532
        /**
518
533
                Returns all the available constructor names for an enum.
519
534
        **/
520
 
        public static function getEnumConstructs( e : Enum ) : Array<String> untyped {
 
535
        public static function getEnumConstructs( e : Enum<Dynamic> ) : Array<String> untyped {
521
536
                #if php
522
537
                        if(__php__("$e->__tname__ == 'Bool'")) return ['true', 'false'];
523
538
                        if(__php__("$e->__tname__ == 'Void'")) return [];
524
539
                        var rfl = __php__("new ReflectionClass($e->__tname__)");
525
540
                        var sps : ArrayAccess<Dynamic> = rfl.getStaticProperties();
526
541
//                      var r : ArrayAccess<String> = __call__('array');
527
 
                        __php__("$r = array(); foreach($sps as $k => $v) $r[] = $k");
 
542
                        __php__("$r = array(); while(list($k) = each($sps)) $r[] = $k");
528
543
                        sps = rfl.getMethods();
529
 
                        __php__("foreach($sps as $m) { $n = $m->getName(); if($n != '__construct' && $n != '__toString') $r[] = $n; }");
 
544
                        __php__("while(list(, $m) = each($sps)) { $n = $m->getName(); if($n != '__construct' && $n != '__toString') $r[] = $n; }");
530
545
                        return __php__("new _hx_array($r)");
531
546
                #elseif cpp
532
547
                        return untyped e.GetClassFields();