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

  • ClassElement
  • ClassVariable
  • Constant
  • Enumeration
  • FunctionElement
  • GlobalVariable
  • Header
  • NamespaceElement
  • Overload
  • Parameter
  • ReturnType
  • TypeComponents
  • TypeDef
  • VariableType
  • 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\Element;
 9: 
10: /**
11:  * Represents a function or class method parameter.
12:  */
13: class Parameter extends VariableType
14: {
15:     
16:     /**
17:      * Holds the name of the element
18:      * @var string
19:      */
20:     public $name;
21:     
22:     /**
23:      * The default value of the parameter.
24:      * @var string 
25:      */
26:     public $default_value;
27:     
28:     /**
29:      * Reference to the overload owner.
30:      * @var \Peg\Lib\Definitions\Element\Overload
31:      */
32:     public $overload;
33:     
34:     /**
35:      * Create a parameter element from a declaration specification for the type.
36:      * @param string $name Name of the parameter.
37:      * @param string $type Parameter type by specification, eg: const int*
38:      * @param string $default_value Default value of the parameter.
39:      * @param string $description
40:      */
41:     public function __construct($name, $type, $default_value="", $description="")
42:     {
43:         parent::__construct($type, $description);
44:         
45:         $this->name = $name;
46:         
47:         $this->default_value = $default_value;
48:     }
49:     
50:     /**
51:      * Converts the parameter specifications to c/c++ code that can be 
52:      * added when generating a function/method declaration, 
53:      * eg: const int* num = 0
54:      * @return string
55:      */
56:     public function GetDeclarationCode()
57:     {
58:         $code = "";
59:         
60:         if($this->is_const)
61:             $code .= "const ";
62:         
63:         $code .= $this->type;
64:         
65:         if($this->is_reference)
66:             $code .= "&";
67:         
68:         if($this->is_pointer)
69:         {
70:             for($i=0; $i<$this->indirection_level; $i++)
71:             {
72:                 $code .= "*";
73:             }
74:         }
75:         
76:         $code .= " " . $this->name;
77:         
78:         if($this->is_array)
79:             $code .= "[]";
80:         
81:         if(trim($this->default_value) != "")
82:             $code .= " = " . $this->default_value;
83:     }
84: 
85: }
PEG Api API documentation generated by ApiGen 2.8.0