Overview

Namespaces

  • None
  • Peg
    • Cli
      • Commands
    • Config
    • Custom
      • Command
        • Action
          • Generate
          • Parse
      • CommandLine
      • Config
      • Localization
      • Utilities
    • Lib
      • Definitions
        • Element
      • Generator
      • Lexers
      • Plugins
      • Signals
        • Data
          • Definitions
          • Lexers
        • Type
  • PHP

Classes

  • Exporter
  • Importer
  • StandardType
  • Symbols
  • Type
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
   1: <?php
   2: /**
   3:  * @author Jefferson González
   4:  * @license MIT
   5:  * @link http://github.com/peg-org/peg-src Source code.
   6:  */
   7: 
   8: namespace Peg\Lib\Definitions;
   9: 
  10: /**
  11:  * Represents a symbols table with all the definitions required to generate
  12:  * a PHP extension.
  13:  */
  14: class Symbols
  15: {
  16: 
  17:     /**
  18:      * List of header files (#include)
  19:      * @var \Peg\Lib\Definitions\Element\Header[]
  20:      */
  21:     public $headers;
  22: 
  23:     /**
  24:      * Default constructor.
  25:      */
  26:     public function __construct()
  27:     {
  28:         $this->headers = array();
  29:     }
  30: 
  31:     /**
  32:      * Removes all the symbols stored on the container.
  33:      */
  34:     public function Clear()
  35:     {
  36:         unset($this->headers);
  37: 
  38:         $this->headers = array();
  39:     }
  40: 
  41:     /**
  42:      * Add a header file.
  43:      * @param string $name  Name of header file.
  44:      * @param bool $enabled Flag to inidicate if the header should be included
  45:      * as part of the code generation.
  46:      */
  47:     public function AddHeader($name, $enabled=true)
  48:     {
  49:         if(!isset($this->headers[$name]))
  50:         {
  51:             $header = new Element\Header($name, $enabled);
  52: 
  53:             $this->headers[$name] = $header;
  54:         }
  55:     }
  56: 
  57:     /**
  58:      * Adds a constant to the symbols table.
  59:      * @param \Peg\Lib\Definitions\Element\Constant $constant
  60:      * @param string $header Name of header file where the constant resides.
  61:      * @param string $namespace If omitted the constant is added at a global scope.
  62:      */
  63:     public function AddConstant(
  64:         \Peg\Lib\Definitions\Element\Constant $constant,
  65:         $header,
  66:         $namespace="\\"
  67:     )
  68:     {
  69:         $this->AddHeader($header);
  70: 
  71:         $this->headers[$header]->AddConstant($constant, $namespace);
  72:     }
  73: 
  74:     /**
  75:      * Adds an enumeration to the symbols table.
  76:      * @param \Peg\Lib\Definitions\Element\Enumeration $enumeration
  77:      * @param string $header Name of header file where the constant resides.
  78:      * @param string $namespace If omitted the constant is added at a global scope.
  79:      */
  80:     public function AddEnumeration(
  81:         \Peg\Lib\Definitions\Element\Enumeration $enumeration,
  82:         $header,
  83:         $namespace="\\"
  84:     )
  85:     {
  86:         $this->AddHeader($header);
  87: 
  88:         $this->headers[$header]->AddEnumeration($enumeration, $namespace);
  89:     }
  90: 
  91:     /**
  92:      * Adds a type definition to the symbols table.
  93:      * @param \Peg\Lib\Definitions\Element\TypeDef $typedef
  94:      * @param string $header Name of header file where the constant resides.
  95:      * @param string $namespace If omitted the constant is added at a global scope.
  96:      */
  97:     public function AddTypeDef(
  98:         \Peg\Lib\Definitions\Element\TypeDef $typedef,
  99:         $header,
 100:         $namespace="\\"
 101:     )
 102:     {
 103:         $this->AddHeader($header);
 104: 
 105:         $this->headers[$header]->AddTypeDef($typedef, $namespace);
 106:     }
 107: 
 108:     /**
 109:      * Adds a global variable to the symbols table.
 110:      * @param \Peg\Lib\Definitions\Element\GlobalVariable $global_variable
 111:      * @param string $header Name of header file where the constant resides.
 112:      * @param string $namespace If omitted the constant is added at a global scope.
 113:      */
 114:     public function AddGlobalVar(
 115:         \Peg\Lib\Definitions\Element\GlobalVariable $global_variable,
 116:         $header,
 117:         $namespace="\\"
 118:     )
 119:     {
 120:         $this->AddHeader($header);
 121: 
 122:         $this->headers[$header]->AddGlobalVariable($global_variable, $namespace);
 123:     }
 124: 
 125:     /**
 126:      * Adds a function to the symbols table.
 127:      * @param \Peg\Lib\Definitions\Element\FunctionElement $function
 128:      * @param string $header Name of header file where the constant resides.
 129:      * @param string $namespace If omitted the constant is added at a global scope.
 130:      */
 131:     public function AddFunction(
 132:         \Peg\Lib\Definitions\Element\FunctionElement $function,
 133:         $header,
 134:         $namespace="\\"
 135:     )
 136:     {
 137:         $this->AddHeader($header);
 138: 
 139:         $this->headers[$header]->AddFunction($function, $namespace);
 140:     }
 141: 
 142:     /**
 143:      * Adds a class to the symbols table.
 144:      * @param \Peg\Lib\Definitions\Element\ClassElement $class
 145:      * @param string $header Name of header file where the class resides.
 146:      * @param string $namespace If omitted the class is added at a global scope.
 147:      */
 148:     public function AddClass(
 149:         \Peg\Lib\Definitions\Element\ClassElement $class,
 150:         $header,
 151:         $namespace="\\"
 152:     )
 153:     {
 154:         $this->AddHeader($header);
 155: 
 156:         $this->headers[$header]->AddClass($class, $namespace);
 157:     }
 158:     
 159:     /**
 160:      * Checks if a class has properties.
 161:      * @param string $class_name
 162:      * @return bool True if has properties, otherwise false.
 163:      */
 164:     public function ClassHasProperties($class_name)
 165:     {   
 166:         $class = $this->HasClass($class_name);
 167:         
 168:         if($class)
 169:         {
 170:             if(count($class->variables) > 0)
 171:                 return true;
 172:         }
 173:         
 174:         return false;
 175:     }
 176: 
 177:     /**
 178:      * Gets a standard type identifier for a variable type.
 179:      * @todo Add hook|signal so a plugin can modify the returned type.
 180:      * @param \Peg\Lib\Definitions\Element\VariableType $type
 181:      */
 182:     public function GetStandardType(
 183:         \Peg\Lib\Definitions\Element\VariableType $type
 184:     )
 185:     {
 186:         $standard_type = "";
 187: 
 188:         switch($type->type)
 189:         {
 190:             case    "bool":
 191:                 $standard_type = StandardType::BOOLEAN;
 192:                 break;
 193: 
 194:             case    "unsigned int":
 195:             case    "unsigned long":
 196:             case    "long":
 197:             case    "long int":
 198:             case    "int":
 199:             case    "size_t":
 200:             case    "unsigned":
 201:             case    "unsigned short":
 202:             case    "unsigned char":
 203:                 $standard_type = StandardType::INTEGER;
 204:                 break;
 205: 
 206:             case    "float":
 207:             case    "double":
 208:                 $standard_type = StandardType::REAL;
 209:                 break;
 210: 
 211:             case    "char":
 212:                 $standard_type = StandardType::CHARACTER;
 213:                 break;
 214: 
 215:             case    "void":
 216:                 $standard_type = StandardType::VOID;
 217:                 break;
 218: 
 219:             default:
 220:                 //Match object or const object
 221:                 if($this->HasClass($type->type))
 222:                 {
 223:                     $standard_type = StandardType::OBJECT;
 224:                 }
 225:                 //Check if enumartion of class
 226:                 elseif($this->HasClassEnum($type->type))
 227:                 {
 228:                     $standard_type = StandardType::CLASS_ENUM;
 229:                 }
 230:                 //Check if global enumertion
 231:                 elseif($this->HasEnumeration($type->type))
 232:                 {
 233:                     $standard_type = StandardType::ENUM;
 234:                 }
 235:                 //Check if typedef
 236:                 elseif($typedef = $this->HasTypeDef($type->type))
 237:                 {
 238:                     $standard_type = $this->GetStandardType($typedef);
 239:                 }
 240:                 else
 241:                 {
 242:                     $standard_type = StandardType::UNKNOWN;
 243:                 }
 244:         }
 245:         
 246:         return $standard_type;
 247:     }
 248:     
 249:     /**
 250:      * Gets the php standard type identifier for a variable type.
 251:      * @todo Add hook|signal so a plugin can modify the returned type.
 252:      * @param \Peg\Lib\Definitions\Element\VariableType $type
 253:      */
 254:     public function GetPHPStandardType(
 255:         \Peg\Lib\Definitions\Element\VariableType $type
 256:     )
 257:     {
 258:         $standard_type = $this->GetStandardType($type);
 259:         $php_type = "";
 260: 
 261:         switch($standard_type)
 262:         {
 263:             case StandardType::BOOLEAN:
 264:                 $php_type .= "bool";
 265:                 break;
 266: 
 267:             case StandardType::INTEGER:
 268:                 $php_type .= "int";
 269:                 break;
 270: 
 271:             case StandardType::REAL:
 272:                 $php_type .= "float";
 273:                 break;
 274: 
 275:             case StandardType::CHARACTER:
 276:                 $php_type .= "string";
 277:                 break;
 278: 
 279:             case StandardType::VOID:
 280:                 $php_type .= "void";
 281:                 break;
 282: 
 283:             case StandardType::OBJECT:
 284:                 $php_type .= $type->type;
 285:                 break;
 286:             
 287:             case StandardType::CLASS_ENUM:
 288:                 $php_type .= $type->type . "| int";
 289:                 break;
 290:             
 291:             case StandardType::ENUM:
 292:                 $php_type .= "int";
 293:                 break;
 294:             
 295:             case StandardType::UNKNOWN:
 296:                 $php_type .= "unknown";
 297:                 break;
 298:         }
 299:         
 300:         return $php_type;
 301:     }
 302:     
 303:     /**
 304:      * Get the components of a variable type as namespace and class by
 305:      * checking the whole symbols object for matches.
 306:      * @param string $type A plain variable type 
 307:      * eg: somens::sometype, somens::someclass::sometype.
 308:      * @return \Peg\Lib\Definitions\Element\TypeComponents
 309:      */
 310:     public function GetComponents($type)
 311:     {
 312:         $type = trim(str_replace("::", "\\", $type));
 313:         
 314:         $type_elements = explode("\\", $type);
 315:         
 316:         $components = new Element\TypeComponents();
 317:         
 318:         if(count($type_elements) > 1)
 319:         {
 320:             $last_element = $type_elements[count($type_elements)-1];
 321:             unset($type_elements[count($type_elements)-1]);
 322:             
 323:             $prelast_element = $type_elements[count($type_elements)-1];
 324:             
 325:             $last_element_index = count($type_elements)-1;
 326:             
 327:             $namespace = "";
 328:             
 329:             for($ri=$last_element_index; $ri>=0; $ri--)
 330:             {
 331:                 $namespace = implode("\\", $type_elements);
 332:                 
 333:                 if($this->HasNamespace($namespace))
 334:                 {
 335:                     break;
 336:                 }
 337:                 
 338:                 $namespace = "";
 339:                 
 340:                 unset($type_elements[count($type_elements)-1]);
 341:             }
 342:             
 343:             if($namespace)
 344:                 $components->namespace = $namespace;
 345:             
 346:             // If pre-last component isn't part of the namespace then
 347:             // it must be a class.
 348:             if(strstr($namespace, "\\$prelast_element") === false)
 349:                 $components->class = $prelast_element;
 350:             
 351:             $components->type = $last_element;
 352:         }
 353:         else
 354:         {
 355:             $components->type = $type;
 356:         }
 357:         
 358:         return $components;
 359:     }
 360:     
 361:     /**
 362:      * Gets a list of child classes that inherit from the given class.
 363:      * @param string $class_name
 364:      * @return \Peg\Lib\Definitions\Element\ClassElement[]
 365:      */
 366:     public function GetClassChilds($class_name, $namespace="")
 367:     {   
 368:         $childs = array();
 369:         
 370:         if(!$namespace)
 371:         {
 372:             $components = $this->GetComponents($class_name);
 373:             
 374:             if($components->HasNamespace())
 375:             {
 376:                 $namespace = $components->namespace;
 377:                 $class_name = $components->type;
 378:             }
 379:             else
 380:             {
 381:                 $namespace = "\\";
 382:             }
 383:         }
 384:         
 385:         $parent_class = "";
 386:         
 387:         if($namespace != "\\")
 388:             $parent_class .= $namespace . "\\" . $class_name;
 389:         else
 390:             $parent_class .= $class_name;
 391:         
 392:         foreach($this->headers as $header_object)
 393:         {
 394:             foreach($header_object->namespaces as $namespace_object)
 395:             {
 396:                 foreach($namespace_object->classes as $class_object)
 397:                 {
 398:                     if(in_array($parent_class, $class_object->parents))
 399:                     {
 400:                         $childs[$class_object->name] = $class_object;
 401:                         
 402:                         $childs += $this->GetClassChilds(
 403:                             $class_object->name,
 404:                             $class_object->namespace->name
 405:                         );
 406:                     }
 407:                 }
 408:             }
 409:         }
 410:         
 411:         return $childs;
 412:     }
 413:     
 414:     /**
 415:      * Check if the symbols object has a given namespace.
 416:      * @param string $namespace
 417:      * @param string $header A specific header to search in.
 418:      * @return \Peg\Lib\Definitions\Element\NamespaceElement or null if nothing found.
 419:      */
 420:     public function HasNamespace($namespace, $header="")
 421:     {
 422:         if($header)
 423:         {
 424:             if(isset($this->headers[$header]->namespaces[$namespace]))
 425:             {
 426:                 return $this->headers[$header]->namespaces[$namespace];
 427:             }
 428:         }
 429:         else
 430:         {
 431:             foreach($this->headers as $header_object)
 432:             {
 433:                 if(isset($header_object->namespaces[$namespace]))
 434:                 {
 435:                     return $header_object->namespaces[$namespace];
 436:                 }
 437:             }
 438:         }
 439:         
 440:         return null;
 441:     }
 442:     
 443:     /**
 444:      * Check if the symbols object has a constant.
 445:      * @param string $name Name of the constant can include 
 446:      * namespace separated by the :: operator or \.
 447:      * @param string $header A specific header to search in.
 448:      * @param string $namespace A specific namespace to search in.
 449:      * @return \Peg\Lib\Definitions\Element\Constant or null if nothing found.
 450:      */
 451:     public function HasConstant($name, $header="", $namespace="")
 452:     {
 453:         if(!$namespace)
 454:         {
 455:             $components = $this->GetComponents($name);
 456:             
 457:             if($components->HasNamespace())
 458:             {
 459:                 $namespace = $components->namespace;
 460:                 $name = $components->type;
 461:             }
 462:         }
 463:         
 464:         if($header)
 465:         {
 466:             if($namespace)
 467:             {
 468:                 if(isset($this->headers[$header]->namespaces[$namespace]->constants[$name]))
 469:                 {
 470:                     return $this->headers[$header]->namespaces[$namespace]->constants[$name];
 471:                 }
 472:             }
 473:             else
 474:             {
 475:                 foreach($this->headers[$header]->namespaces as $namespace_object)
 476:                 {
 477:                     if(isset($namespace_object->constants[$name]))
 478:                     {
 479:                         return $namespace_object->constants[$name];
 480:                     }
 481:                 }
 482:             }
 483:         }
 484:         elseif($namespace)
 485:         {
 486:             foreach($this->headers as $header_object)
 487:             {
 488:                 if(isset($header_object->namespaces[$namespace]->constants[$name]))
 489:                 {
 490:                     return $header_object->namespaces[$namespace]->constants[$name];
 491:                 }
 492:             }
 493:         }
 494:         else
 495:         {
 496:             foreach($this->headers as $header_object)
 497:             {
 498:                 foreach($header_object->namespaces as $namespace_object)
 499:                 {
 500:                     if(isset($namespace_object->constants[$name]))
 501:                     {
 502:                         return $namespace_object->constants[$name];
 503:                     }
 504:                 }
 505:             }
 506:         }
 507:         
 508:         return null;
 509:     }
 510:     
 511:     /**
 512:      * Check if the symbols object has an enumeration.
 513:      * @param string $name Name of the enumeration can include 
 514:      * namespace separated by the :: operator or \.
 515:      * @param string $header A specific header to search in.
 516:      * @param string $namespace A specific namespace to search in.
 517:      * @return \Peg\Lib\Definitions\Element\Enumeration or null if nothing found.
 518:      */
 519:     public function HasEnumeration($name, $header="", $namespace="")
 520:     {
 521:         if(!$namespace)
 522:         {
 523:             $components = $this->GetComponents($name);
 524:             
 525:             if($components->HasNamespace())
 526:             {
 527:                 $namespace = $components->namespace;
 528:                 $name = $components->type;
 529:             }
 530:         }
 531:         
 532:         if($header)
 533:         {
 534:             if($namespace)
 535:             {
 536:                 if(isset($this->headers[$header]->namespaces[$namespace]->enumerations[$name]))
 537:                 {
 538:                     return $this->headers[$header]->namespaces[$namespace]->enumerations[$name];
 539:                 }
 540:             }
 541:             else
 542:             {
 543:                 foreach($this->headers[$header]->namespaces as $namespace_object)
 544:                 {
 545:                     if(isset($namespace_object->enumerations[$name]))
 546:                     {
 547:                         return $namespace_object->enumerations[$name];
 548:                     }
 549:                 }
 550:             }
 551:         }
 552:         elseif($namespace)
 553:         {
 554:             foreach($this->headers as $header_object)
 555:             {
 556:                 if(isset($header_object->namespaces[$namespace]->enumerations[$name]))
 557:                 {
 558:                     return $header_object->namespaces[$namespace]->enumerations[$name];
 559:                 }
 560:             }
 561:         }
 562:         else
 563:         {
 564:             foreach($this->headers as $header_object)
 565:             {
 566:                 foreach($header_object->namespaces as $namespace_object)
 567:                 {
 568:                     if(isset($namespace_object->enumerations[$name]))
 569:                     {
 570:                         return $namespace_object->enumerations[$name];
 571:                     }
 572:                 }
 573:             }
 574:         }
 575:         
 576:         return null;
 577:     }
 578:     
 579:     /**
 580:      * Check if the symbols object has a typedef.
 581:      * @todo Resolve classes that are part of the name.
 582:      * @param string $name Name of the typedef can include 
 583:      * namespace separated by the :: operator or \.
 584:      * @param string $header A specific header to search in.
 585:      * @param string $namespace A specific namespace to search in.
 586:      * @return \Peg\Lib\Definitions\Element\TypeDef or null if nothing found.
 587:      */
 588:     public function HasTypeDef($name, $header="", $namespace="")
 589:     {
 590:         if(!$namespace)
 591:         {
 592:             $components = $this->GetComponents($name);
 593:             
 594:             if($components->HasNamespace())
 595:             {
 596:                 $namespace = $components->namespace;
 597:                 $name = $components->type;
 598:             }
 599:         }
 600:         
 601:         if($header)
 602:         {
 603:             if($namespace)
 604:             {
 605:                 if(isset($this->headers[$header]->namespaces[$namespace]->type_definitions[$name]))
 606:                 {
 607:                     return $this->headers[$header]->namespaces[$namespace]->type_definitions[$name];
 608:                 }
 609:             }
 610:             else
 611:             {
 612:                 foreach($this->headers[$header]->namespaces as $namespace_object)
 613:                 {
 614:                     if(isset($namespace_object->type_definitions[$name]))
 615:                     {
 616:                         return $namespace_object->type_definitions[$name];
 617:                     }
 618:                 }
 619:             }
 620:         }
 621:         elseif($namespace)
 622:         {
 623:             foreach($this->headers as $header_object)
 624:             {
 625:                 if(isset($header_object->namespaces[$namespace]->type_definitions[$name]))
 626:                 {
 627:                     return $header_object->namespaces[$namespace]->type_definitions[$name];
 628:                 }
 629:             }
 630:         }
 631:         else
 632:         {
 633:             foreach($this->headers as $header_object)
 634:             {
 635:                 foreach($header_object->namespaces as $namespace_object)
 636:                 {
 637:                     if(isset($namespace_object->type_definitions[$name]))
 638:                     {
 639:                         return $namespace_object->type_definitions[$name];
 640:                     }
 641:                 }
 642:             }
 643:         }
 644:         
 645:         return null;
 646:     }
 647:     
 648:     /**
 649:      * Check if the symbols object has a global variable.
 650:      * @param string $name Name of the global variable can include 
 651:      * namespace separated by the :: operator or \.
 652:      * @param string $header A specific header to search in.
 653:      * @param string $namespace A specific namespace to search in.
 654:      * @return \Peg\Lib\Definitions\Element\GlobalVariable or null if nothing found.
 655:      */
 656:     public function HasGlobalVariable($name, $header="", $namespace="")
 657:     {
 658:         if(!$namespace)
 659:         {
 660:             $components = $this->GetComponents($name);
 661:             
 662:             if($components->HasNamespace())
 663:             {
 664:                 $namespace = $components->namespace;
 665:                 $name = $components->type;
 666:             }
 667:         }
 668:         
 669:         if($header)
 670:         {
 671:             if($namespace)
 672:             {
 673:                 if(isset($this->headers[$header]->namespaces[$namespace]->global_variables[$name]))
 674:                 {
 675:                     return $this->headers[$header]->namespaces[$namespace]->global_variables[$name];
 676:                 }
 677:             }
 678:             else
 679:             {
 680:                 foreach($this->headers[$header]->namespaces as $namespace_object)
 681:                 {
 682:                     if(isset($namespace_object->global_variables[$name]))
 683:                     {
 684:                         return $namespace_object->global_variables[$name];
 685:                     }
 686:                 }
 687:             }
 688:         }
 689:         elseif($namespace)
 690:         {
 691:             foreach($this->headers as $header_object)
 692:             {
 693:                 if(isset($header_object->namespaces[$namespace]->global_variables[$name]))
 694:                 {
 695:                     return $header_object->namespaces[$namespace]->global_variables[$name];
 696:                 }
 697:             }
 698:         }
 699:         else
 700:         {
 701:             foreach($this->headers as $header_object)
 702:             {
 703:                 foreach($header_object->namespaces as $namespace_object)
 704:                 {
 705:                     if(isset($namespace_object->global_variables[$name]))
 706:                     {
 707:                         return $namespace_object->global_variables[$name];
 708:                     }
 709:                 }
 710:             }
 711:         }
 712:         
 713:         return null;
 714:     }
 715:     
 716:     /**
 717:      * Check if the symbols object has a function.
 718:      * @param string $name Name of the function can include 
 719:      * namespace separated by the :: operator or \.
 720:      * @param string $header A specific header to search in.
 721:      * @param string $namespace A specific namespace to search in.
 722:      * @return \Peg\Lib\Definitions\Element\FunctionElement or null if nothing found.
 723:      */
 724:     public function HasFunction($name, $header="", $namespace="")
 725:     {
 726:         if(!$namespace)
 727:         {
 728:             $components = $this->GetComponents($name);
 729:             
 730:             if($components->HasNamespace())
 731:             {
 732:                 $namespace = $components->namespace;
 733:                 $name = $components->type;
 734:             }
 735:         }
 736:         
 737:         if($header)
 738:         {
 739:             if($namespace)
 740:             {
 741:                 if(isset($this->headers[$header]->namespaces[$namespace]->functions[$name]))
 742:                 {
 743:                     return $this->headers[$header]->namespaces[$namespace]->functions[$name];
 744:                 }
 745:             }
 746:             else
 747:             {
 748:                 foreach($this->headers[$header]->namespaces as $namespace_object)
 749:                 {
 750:                     if(isset($namespace_object->functions[$name]))
 751:                     {
 752:                         return $namespace_object->functions[$name];
 753:                     }
 754:                 }
 755:             }
 756:         }
 757:         elseif($namespace)
 758:         {
 759:             foreach($this->headers as $header_object)
 760:             {
 761:                 if(isset($header_object->namespaces[$namespace]->functions[$name]))
 762:                 {
 763:                     return $header_object->namespaces[$namespace]->functions[$name];
 764:                 }
 765:             }
 766:         }
 767:         else
 768:         {
 769:             foreach($this->headers as $header_object)
 770:             {
 771:                 foreach($header_object->namespaces as $namespace_object)
 772:                 {
 773:                     if(isset($namespace_object->functions[$name]))
 774:                     {
 775:                         return $namespace_object->functions[$name];
 776:                     }
 777:                 }
 778:             }
 779:         }
 780:         
 781:         return null;
 782:     }
 783:     
 784:     /**
 785:      * Check if the symbols object has a class.
 786:      * @todo Resolve classes that are part of the name.
 787:      * @param string $name Name of the class can include 
 788:      * namespace separated by the :: operator or \.
 789:      * @param string $header A specific header to search in.
 790:      * @param string $namespace A specific namespace to search in.
 791:      * @return \Peg\Lib\Definitions\Element\ClassElement or null if nothing found.
 792:      */
 793:     public function HasClass($name, $header="", $namespace="")
 794:     {
 795:         if(!$namespace)
 796:         {
 797:             $components = $this->GetComponents($name);
 798:             
 799:             if($components->HasNamespace())
 800:             {
 801:                 $namespace = $components->namespace;
 802:                 $name = $components->type;
 803:             }
 804:         }
 805:         
 806:         if($header)
 807:         {
 808:             if($namespace)
 809:             {
 810:                 if(isset($this->headers[$header]->namespaces[$namespace]->classes[$name]))
 811:                 {
 812:                     return $this->headers[$header]->namespaces[$namespace]->classes[$name];
 813:                 }
 814:             }
 815:             else
 816:             {
 817:                 foreach($this->headers[$header]->namespaces as $namespace_object)
 818:                 {
 819:                     if(isset($namespace_object->classes[$name]))
 820:                     {
 821:                         return $namespace_object->classes[$name];
 822:                     }
 823:                 }
 824:             }
 825:         }
 826:         elseif($namespace)
 827:         {
 828:             foreach($this->headers as $header_object)
 829:             {
 830:                 if(isset($header_object->namespaces[$namespace]->classes[$name]))
 831:                 {
 832:                     return $header_object->namespaces[$namespace]->classes[$name];
 833:                 }
 834:             }
 835:         }
 836:         else
 837:         {
 838:             foreach($this->headers as $header_object)
 839:             {
 840:                 foreach($header_object->namespaces as $namespace_object)
 841:                 {
 842:                     if(isset($namespace_object->classes[$name]))
 843:                     {
 844:                         return $namespace_object->classes[$name];
 845:                     }
 846:                 }
 847:             }
 848:         }
 849:         
 850:         return null;
 851:     }
 852:     
 853:     /**
 854:      * Checks if a given type is a class enumeration.
 855:      * and class names separated by the :: operator or \.
 856:      * @param string $type
 857:      * @return \Peg\Lib\Definitions\Element\Enumeration or null if nothing found.
 858:      */
 859:     public function HasClassEnum($type)
 860:     {   
 861:         $components = $this->GetComponents($type);
 862:         
 863:         if($components->HasClass())
 864:         {
 865:             foreach($this->headers as $header_object)
 866:             {
 867:                 if($components->HasNamespace())
 868:                 {
 869:                     if(
 870:                         isset(
 871:                             $header_object->namespaces[$components->namespace]
 872:                                 ->classes[$components->class]
 873:                                 ->enumerations[$components->type]
 874:                         )
 875:                     )
 876:                         return $header_object->namespaces[$components->namespace]
 877:                             ->classes[$components->class]
 878:                             ->enumerations[$components->type]
 879:                         ;
 880:                 }
 881:                 else
 882:                 {
 883:                     if(
 884:                         isset(
 885:                             $header_object->namespaces["\\"]
 886:                                 ->classes[$components->class]
 887:                                 ->enumerations[$components->type]
 888:                         )
 889:                     )
 890:                         return $header_object->namespaces["\\"]
 891:                             ->classes[$components->class]
 892:                             ->enumerations[$components->type]
 893:                         ;
 894:                 }
 895:             }
 896:         }
 897:         
 898:         return null;
 899:     }
 900:     
 901:     /**
 902:      * Removes a header from the symbols object.
 903:      * @param string $name
 904:      * @param string $header A specific header.
 905:      */
 906:     public function RemoveHeader($name)
 907:     {
 908:         unset($this->headers[$name]);
 909:     }
 910:     
 911:     /**
 912:      * Removes a namespace from the symbols object.
 913:      * @param string $name
 914:      * @param string $header A specific header.
 915:      */
 916:     public function RemoveNamespace($name, $header="")
 917:     {
 918:         if($header)
 919:         {
 920:             unset($this->headers[$header]->namespaces[$name]);
 921:         }
 922:         else
 923:         {
 924:             foreach($this->headers as $header_object)
 925:             {
 926:                 unset($header_object->namespaces[$name]);
 927:             }
 928:         }
 929:     }
 930:     
 931:     /**
 932:      * Removes a constant from the symbols object.
 933:      * @param string $name
 934:      * @param string $namespace A specific namespace.
 935:      * @param string $header A specific header.
 936:      */
 937:     public function RemoveConstant($name, $namespace="", $header="")
 938:     {
 939:         if($header)
 940:         {
 941:             if($namespace)
 942:             {
 943:                 unset($this->headers[$header]->namespaces[$namespace]->constants[$name]);
 944:             }
 945:             else
 946:             {
 947:                 foreach($this->headers[$header]->namespaces as $namespace_object)
 948:                 {
 949:                     unset($namespace_object->constants[$name]);
 950:                 }
 951:             }
 952:         }
 953:         elseif($namespace)
 954:         {
 955:             foreach($this->headers as $header_object)
 956:             {
 957:                 unset($header_object->namespaces[$namespace]->constants[$name]);
 958:             }
 959:         }
 960:         else
 961:         {
 962:             foreach($this->headers as $header_object)
 963:             {
 964:                 foreach($header_object->namespaces as $namespace_object)
 965:                 {
 966:                     unset($namespace_object->constants[$name]);
 967:                 }
 968:             }
 969:         }
 970:     }
 971:     
 972:     /**
 973:      * Removes an enumeration from the symbols object.
 974:      * @param string $name
 975:      * @param string $namespace A specific namespace.
 976:      * @param string $header A specific header.
 977:      */
 978:     public function RemoveEnumeration($name, $namespace="", $header="")
 979:     {
 980:         if($header)
 981:         {
 982:             if($namespace)
 983:             {
 984:                 unset($this->headers[$header]->namespaces[$namespace]->enumerations[$name]);
 985:             }
 986:             else
 987:             {
 988:                 foreach($this->headers[$header]->namespaces as $namespace_object)
 989:                 {
 990:                     unset($namespace_object->enumerations[$name]);
 991:                 }
 992:             }
 993:         }
 994:         elseif($namespace)
 995:         {
 996:             foreach($this->headers as $header_object)
 997:             {
 998:                 unset($header_object->namespaces[$namespace]->enumerations[$name]);
 999:             }
1000:         }
1001:         else
1002:         {
1003:             foreach($this->headers as $header_object)
1004:             {
1005:                 foreach($header_object->namespaces as $namespace_object)
1006:                 {
1007:                     unset($namespace_object->enumerations[$name]);
1008:                 }
1009:             }
1010:         }
1011:     }
1012:     
1013:     /**
1014:      * Removes a typedef from the symbols object.
1015:      * @param string $name
1016:      * @param string $namespace A specific namespace.
1017:      * @param string $header A specific header.
1018:      */
1019:     public function RemoveTypeDef($name, $namespace="", $header="")
1020:     {
1021:         if($header)
1022:         {
1023:             if($namespace)
1024:             {
1025:                 unset($this->headers[$header]->namespaces[$namespace]->type_definitions[$name]);
1026:             }
1027:             else
1028:             {
1029:                 foreach($this->headers[$header]->namespaces as $namespace_object)
1030:                 {
1031:                     unset($namespace_object->type_definitions[$name]);
1032:                 }
1033:             }
1034:         }
1035:         elseif($namespace)
1036:         {
1037:             foreach($this->headers as $header_object)
1038:             {
1039:                 unset($header_object->namespaces[$namespace]->type_definitions[$name]);
1040:             }
1041:         }
1042:         else
1043:         {
1044:             foreach($this->headers as $header_object)
1045:             {
1046:                 foreach($header_object->namespaces as $namespace_object)
1047:                 {
1048:                     unset($namespace_object->type_definitions[$name]);
1049:                 }
1050:             }
1051:         }
1052:     }
1053:     
1054:     /**
1055:      * Removes a global variable from the symbols object.
1056:      * @param string $name
1057:      * @param string $namespace A specific namespace.
1058:      * @param string $header A specific header.
1059:      */
1060:     public function RemoveGlobalVariable($name, $namespace="", $header="")
1061:     {
1062:         if($header)
1063:         {
1064:             if($namespace)
1065:             {
1066:                 unset($this->headers[$header]->namespaces[$namespace]->global_variables[$name]);
1067:             }
1068:             else
1069:             {
1070:                 foreach($this->headers[$header]->namespaces as $namespace_object)
1071:                 {
1072:                     unset($namespace_object->global_variables[$name]);
1073:                 }
1074:             }
1075:         }
1076:         elseif($namespace)
1077:         {
1078:             foreach($this->headers as $header_object)
1079:             {
1080:                 unset($header_object->namespaces[$namespace]->global_variables[$name]);
1081:             }
1082:         }
1083:         else
1084:         {
1085:             foreach($this->headers as $header_object)
1086:             {
1087:                 foreach($header_object->namespaces as $namespace_object)
1088:                 {
1089:                     unset($namespace_object->global_variables[$name]);
1090:                 }
1091:             }
1092:         }
1093:         
1094:         return false;
1095:     }
1096:     
1097:     /**
1098:      * Removes a function from the symbols object.
1099:      * @param string $name
1100:      * @param string $namespace A specific namespace.
1101:      * @param string $header A specific header.
1102:      */
1103:     public function RemoveFunction($name, $namespace="", $header="")
1104:     {
1105:         if($header)
1106:         {
1107:             if($namespace)
1108:             {
1109:                 unset($this->headers[$header]->namespaces[$namespace]->functions[$name]);
1110:             }
1111:             else
1112:             {
1113:                 foreach($this->headers[$header]->namespaces as $namespace_object)
1114:                 {
1115:                     unset($namespace_object->functions[$name]);
1116:                 }
1117:             }
1118:         }
1119:         elseif($namespace)
1120:         {
1121:             foreach($this->headers as $header_object)
1122:             {
1123:                 unset($header_object->namespaces[$namespace]->functions[$name]);
1124:             }
1125:         }
1126:         else
1127:         {
1128:             foreach($this->headers as $header_object)
1129:             {
1130:                 foreach($header_object->namespaces as $namespace_object)
1131:                 {
1132:                     unset($namespace_object->functions[$name]);
1133:                 }
1134:             }
1135:         }
1136:     }
1137:     
1138:     /**
1139:      * Removes a class from the symbols object.
1140:      * @param string $name
1141:      * @param string $namespace A specific namespace.
1142:      * @param string $header A specific header.
1143:      */
1144:     public function RemoveClass($name, $namespace="", $header="")
1145:     {
1146:         if($header)
1147:         {
1148:             if($namespace)
1149:             {
1150:                 unset($this->headers[$header]->namespaces[$namespace]->classes[$name]);
1151:             }
1152:             else
1153:             {
1154:                 foreach($this->headers[$header]->namespaces as $namespace_object)
1155:                 {
1156:                     unset($namespace_object->classes[$name]);
1157:                 }
1158:             }
1159:         }
1160:         elseif($namespace)
1161:         {
1162:             foreach($this->headers as $header_object)
1163:             {
1164:                 unset($header_object->namespaces[$namespace]->classes[$name]);
1165:             }
1166:         }
1167:         else
1168:         {
1169:             foreach($this->headers as $header_object)
1170:             {
1171:                 foreach($header_object->namespaces as $namespace_object)
1172:                 {
1173:                     unset($namespace_object->classes[$name]);
1174:                 }
1175:             }
1176:         }
1177:     }
1178:     
1179: }
1180: 
PEG Api API documentation generated by ApiGen 2.8.0