~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Source/Swig/naming.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-09-01 18:35:55 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050901183555-eq59uwhq8b62e44c
Tags: 1.3.24-1ubuntu4
* Use php5-dev instead of php4-dev, to kick php4 out of main.
* Drop support for generation of pike bindings, as nothing uses it,
  and swig is the only thing keeping pike7.6 in main (Ubuntu #13796)

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 * See the file LICENSE for information on usage and redistribution.    
10
10
 * ----------------------------------------------------------------------------- */
11
11
 
12
 
char cvsroot_naming_c[] = "$Header: /cvsroot/swig/SWIG/Source/Swig/naming.c,v 1.12 2004/06/27 20:53:22 wsfulton Exp $";
 
12
char cvsroot_naming_c[] = "$Header: /cvsroot/swig/SWIG/Source/Swig/naming.c,v 1.17 2004/11/03 00:58:48 marcelomatus Exp $";
13
13
 
14
14
#include "swig.h"
15
15
#include <ctype.h>
18
18
 
19
19
static Hash *naming_hash = 0;
20
20
 
 
21
/* #define SWIG_DEBUG */
21
22
/* -----------------------------------------------------------------------------
22
23
 * Swig_name_register()
23
24
 *
206
207
  String *r;
207
208
  String *f;
208
209
 
 
210
#ifdef SWIG_DEBUG
 
211
  Printf(stdout,"name get:  '%s'\n", vname); 
 
212
#endif
 
213
 
209
214
  r = NewString("");
210
215
  if (!naming_hash) naming_hash = NewHash();
211
216
  f = Getattr(naming_hash,"get");
389
394
Swig_name_object_set(Hash *namehash, String *name, SwigType *decl, DOH *object) {
390
395
  DOH *n;
391
396
 
392
 
  /*  Printf(stdout,"name:  '%s', '%s'\n", name, decl);*/
 
397
#ifdef SWIG_DEBUG
 
398
  Printf(stdout,"name set:  '%s', '%s'\n", name, decl); 
 
399
#endif
393
400
  n = Getattr(namehash,name);
394
401
  if (!n) {
395
402
    n = NewHash();
422
429
  return rn;
423
430
}
424
431
 
 
432
static
 
433
DOH *
 
434
name_object_get(Hash *namehash, String *tname, SwigType *decl, SwigType *ncdecl) {
 
435
  DOH* rn = 0;
 
436
  Hash   *n = Getattr(namehash,tname);
 
437
  if (n) {
 
438
    rn = get_object(n,decl);
 
439
    if ((!rn) && ncdecl) rn = get_object(n,ncdecl);
 
440
    if (!rn) rn = get_object(n,0);
 
441
  }
 
442
  return rn;
 
443
}
 
444
 
425
445
DOH *
426
446
Swig_name_object_get(Hash *namehash, String *prefix, String *name, SwigType *decl) {
427
447
  String *tname;
428
448
  DOH    *rn = 0;
429
 
  Hash   *n;
430
449
  char   *ncdecl = 0;
431
450
 
432
451
  if (!namehash) return 0;
442
461
  if (prefix) {
443
462
    if (Len(prefix)) {
444
463
      tname = NewStringf("%s::%s",prefix,name);
445
 
      n = Getattr(namehash,tname);
446
 
      rn = get_object(n,decl);
447
 
      if ((!rn) && ncdecl) rn = get_object(n,ncdecl);
448
 
      if (!rn) rn = get_object(n,0);
 
464
      rn = name_object_get(namehash, tname, decl, ncdecl);
449
465
      Delete(tname);
 
466
      /* A template-based class lookup */
 
467
      if (!rn && SwigType_istemplate(prefix)) {
 
468
        String *tprefix = SwigType_templateprefix(prefix);
 
469
        tname = NewStringf("%s::%s",tprefix,name);
 
470
        rn = name_object_get(namehash, tname, decl, ncdecl);
 
471
        Delete(tname);
 
472
        Delete(tprefix);
 
473
      }
450
474
    }
451
475
    /* A wildcard-based class lookup */
452
476
    if (!rn) {
453
477
      tname = NewStringf("*::%s",name);
454
 
      n = Getattr(namehash,tname);
455
 
      rn = get_object(n,decl);
456
 
      if ((!rn) && ncdecl) rn = get_object(n,ncdecl);
457
 
      if (!rn) rn = get_object(n,0);
 
478
      rn = name_object_get(namehash, tname, decl, ncdecl);
458
479
      Delete(tname);
459
480
    }
460
481
  } else {
461
482
    /* Lookup in the global namespace only */
462
483
    tname = NewStringf("::%s",name);
463
 
    n = Getattr(namehash,tname);
464
 
    rn = get_object(n,decl);
465
 
    if ((!rn) && ncdecl) rn = get_object(n,ncdecl);
466
 
    if (!rn) rn = get_object(n,0);
 
484
    rn = name_object_get(namehash, tname, decl, ncdecl);
467
485
    Delete(tname);
468
486
  }
469
487
  /* Catch-all */
470
488
  if (!rn) {
471
 
    n = Getattr(namehash,name);
472
 
    rn = get_object(n,decl);
473
 
    if ((!rn) && ncdecl) rn = get_object(n,ncdecl);
474
 
    if (!rn) rn = get_object(n,0);
 
489
    rn = name_object_get(namehash, name, decl, ncdecl);
475
490
  }
476
491
  return rn;
477
492
}
530
545
 
531
546
  if (!features) return;
532
547
  for (ki = First(features); ki.key; ki = Next(ki)) {
533
 
    if (Getattr(n,ki.key)) {
534
 
      continue;
535
 
    }
536
548
    Setattr(n,ki.key,Copy(ki.item));
537
549
  }
538
550
}
544
556
 * the declaration, decl.
545
557
 * ----------------------------------------------------------------------------- */
546
558
 
 
559
static 
 
560
void features_get(Hash *features, String *tname, SwigType *decl, SwigType *ncdecl, Node *node)
 
561
{
 
562
  Node *n = Getattr(features,tname);
 
563
#ifdef SWIG_DEBUG
 
564
  Printf(stdout,"  feature_get: %s\n", tname);
 
565
#endif
 
566
  if (n) {
 
567
    merge_features(get_object(n,0),node);
 
568
    if (ncdecl) merge_features(get_object(n,ncdecl),node);
 
569
    merge_features(get_object(n,decl),node);
 
570
  }
 
571
}
 
572
 
547
573
void
548
574
Swig_features_get(Hash *features, String *prefix, String *name, SwigType *decl, Node *node) {
549
575
  String *tname;
550
 
  DOH    *rn = 0;
551
 
  Hash   *n;
552
576
  char   *ncdecl = 0;
 
577
  String *rdecl = 0;
553
578
  SwigType *rname = 0;
554
579
  if (!features) return;
555
580
 
 
581
  /* MM: This removed to more tightly control feature/name matching */
 
582
  /*
556
583
  if ((decl) && (SwigType_isqualifier(decl))) {
557
584
    ncdecl = strchr(Char(decl),'.');
558
585
    ncdecl++;
559
586
  }
560
 
  
 
587
  */
 
588
 
561
589
  /* very specific hack for template constructors/destructors */
562
590
  if (name && SwigType_istemplate(name) &&
563
591
      ((Strcmp(nodeType(node),"constructor") == 0)
564
592
        || (Strcmp(nodeType(node),"destructor") == 0))) {
565
593
    rname = SwigType_templateprefix(name);
 
594
    rdecl = Copy(decl);
 
595
    Replaceall(rdecl,name,rname);
 
596
    decl = rdecl;
566
597
    name = rname;
567
 
  }  
 
598
  }
 
599
  
 
600
#ifdef SWIG_DEBUG
 
601
  Printf(stdout,"feature_get: %s %s %s\n", prefix, name, decl);
 
602
#endif
568
603
 
 
604
  /* Global features */
 
605
  features_get(features, "", 0, 0, node);
569
606
  if (name) {
 
607
    /* Catch-all */
 
608
    features_get(features, name, decl, ncdecl, node);
570
609
    /* Perform a class-based lookup (if class prefix supplied) */
571
610
    if (prefix) {
572
 
      if (Len(prefix)) {
573
 
        tname = NewStringf("%s::%s",prefix,name);
574
 
        n = Getattr(features,tname);
575
 
        rn = get_object(n,decl);
576
 
        merge_features(rn,node);
577
 
        if (ncdecl) {
578
 
          rn = get_object(n,ncdecl);
579
 
          merge_features(rn,node);
580
 
        }
581
 
        rn = get_object(n,0);
582
 
        merge_features(rn,node);
583
 
        Delete(tname);
584
 
      }
585
 
      /* A wildcard-based class lookup */
586
 
      tname = NewStringf("*::%s",name);
587
 
      n = Getattr(features,tname);
588
 
      rn = get_object(n,decl);
589
 
      merge_features(rn,node);
590
 
      if (ncdecl) {
591
 
        rn = get_object(n,ncdecl);
592
 
        merge_features(rn,node);
593
 
      }
594
 
      rn = get_object(n,0);
595
 
      merge_features(rn,node);
596
 
      Delete(tname);
597
 
      
598
611
      /* A class-generic feature */
599
612
      if (Len(prefix)) {
600
613
        tname = NewStringf("%s::",prefix);
601
 
        n = Getattr(features,tname);
602
 
        rn = get_object(n,0);
603
 
        merge_features(rn,node);
604
 
        Delete(tname);
605
 
      }
606
 
      
 
614
        features_get(features, tname, decl, ncdecl, node);
 
615
        Delete(tname);
 
616
      }
 
617
      /* A wildcard-based class lookup */
 
618
      tname = NewStringf("*::%s",name);
 
619
      features_get(features, tname, decl, ncdecl, node);
 
620
      Delete(tname);      
 
621
      /* A specific class lookup */
 
622
      if (Len(prefix)) {
 
623
        /* A template-based class lookup */
 
624
        if (SwigType_istemplate(prefix)) {
 
625
          String *tprefix = SwigType_templateprefix(prefix);
 
626
          tname = NewStringf("%s::%s",tprefix,name);
 
627
          features_get(features, tname, decl, ncdecl, node);
 
628
          Delete(tname);
 
629
          Delete(tprefix);
 
630
        }
 
631
        tname = NewStringf("%s::%s",prefix,name);
 
632
        features_get(features, tname, decl, ncdecl, node);
 
633
        Delete(tname);
 
634
      }
607
635
    } else {
608
636
      /* Lookup in the global namespace only */
609
637
      tname = NewStringf("::%s",name);
610
 
      n = Getattr(features,tname);
611
 
      rn = get_object(n,decl);
612
 
      merge_features(rn,node);
613
 
      if (ncdecl) {
614
 
        rn = get_object(n,ncdecl);
615
 
        merge_features(rn,node);
616
 
      }
617
 
      rn = get_object(n,0);
618
 
      merge_features(rn,node);
 
638
      features_get(features, tname, decl, ncdecl, node);
619
639
      Delete(tname);
620
640
    }
621
 
    /* Catch-all */
622
 
    n = Getattr(features,name);
623
 
    rn = get_object(n,decl);
624
 
    merge_features(rn,node);
625
 
    if (ncdecl) {
626
 
      rn = get_object(n,ncdecl);
627
 
      merge_features(rn,node);
628
 
    }
629
 
    rn = get_object(n,0);
630
 
    merge_features(rn,node);
631
641
  }
632
 
  /* Global features */
633
 
  n = Getattr(features,"");
634
 
  rn = get_object(n,0);
635
 
  merge_features(rn,node);
636
 
 
637
642
  Delete(rname);
 
643
  Delete(rdecl);
638
644
}
639
645
 
640
646
 
650
656
Swig_feature_set(Hash *features, const String_or_char *name, SwigType *decl, const String_or_char *featurename, String *value, Hash *featureattribs) {
651
657
  Hash *n;
652
658
  Hash *fhash;
653
 
  /*  Printf(stdout,"feature: %s %s %s %s\n", name, decl, featurename, value);*/
 
659
 
 
660
#ifdef SWIG_DEBUG
 
661
  Printf(stdout,"feature_set: %s %s %s %s\n", name, decl, featurename,value);  
 
662
#endif
654
663
 
655
664
  n = Getattr(features,name);
656
665
  if (!n) {