Ejemplo n.º 1
0
 /**
  * Retrieve the template path for return, also checks
  * if a valid override exists and returns that instead.
  * @param \Peg\Lib\Definitions\Element\ReturnType $return
  * @param string $namespace
  * @param string $type Can be function, method or static_method.
  * @return string Path to template file.
  */
 public function GetReturnTemplate(\Peg\Lib\Definitions\Element\ReturnType $return, $namespace = "", $type = "function")
 {
     if (!$this->generator_name) {
         throw new \Exception(t("The generator name wasn't set."));
     }
     if ($namespace) {
         $namespace = str_replace(array("\\", "::"), "_", $namespace) . "_";
     }
     $function_name = strtolower($return->overload->function->name);
     $return_type = strtolower($return->type);
     $const = "";
     if ($return->is_const) {
         $const .= "_const";
     }
     $ptr = "";
     if ($return->is_pointer) {
         for ($i = 0; $i < $return->indirection_level; $i++) {
             $ptr .= "_ptr";
         }
     }
     $ref = "";
     if ($return->is_reference) {
         $ref .= "_ref";
     }
     $array = "";
     if ($return->is_array) {
         $array .= "_arr";
     }
     $override_function = $this->templates_path . "return/{$type}/overrides/" . $function_name . "_" . $return_type . $const . $ptr . $ref . $array . ".php";
     if (file_exists($override_function)) {
         return $override_function;
     }
     $override = $this->templates_path . "return/{$type}/overrides/" . $return_type . $const . $ptr . $ref . $array . ".php";
     if (file_exists($override)) {
         return $override;
     }
     $standard_type = $this->symbols->GetStandardType($return);
     $template = $this->templates_path . "return/{$type}/" . $standard_type . $const . $ptr . $ref . $array . ".php";
     if (!file_exists($template)) {
         return $this->templates_path . "return/{$type}/" . "default.php";
     }
     return $template;
 }
Ejemplo n.º 2
0
 /**
  * Load all class symbols from classes.json, its enumerations from
  * class_enumerations.json and variables from class_variables.json.
  */
 private function LoadClassesFromJson()
 {
     $classes_def = Json::Decode(file_get_contents($this->definitions_path . "classes.json"));
     $enumerations_def = array();
     if (file_exists($this->definitions_path . "class_enumerations.json")) {
         $enumerations_def = Json::Decode(file_get_contents($this->definitions_path . "class_enumerations.json"));
     }
     $variables_def = array();
     if (file_exists($this->definitions_path . "class_variables.json")) {
         $variables_def = Json::Decode(file_get_contents($this->definitions_path . "class_variables.json"));
     }
     foreach ($classes_def as $header => $namespaces) {
         $this->symbols->AddHeader($header);
         foreach ($namespaces as $namespace => $classes) {
             foreach ($classes as $class_name => $methods) {
                 $class = new Element\ClassElement($class_name);
                 // Set class details
                 if (isset($methods["_description"])) {
                     $class->description = $methods["_description"];
                     unset($methods["_description"]);
                 }
                 if (isset($methods["_parents"])) {
                     $class->AddParents($methods["_parents"]);
                     unset($methods["_parents"]);
                 }
                 if (isset($methods["_struct"])) {
                     $class->struct = true;
                     unset($methods["_struct"]);
                 }
                 if (isset($methods["_forward_declaration"])) {
                     $class->forward_declaration = true;
                     unset($methods["_forward_declaration"]);
                 }
                 if (isset($methods["_platforms"])) {
                     $class->platforms = $methods["_platforms"];
                     unset($methods["_platforms"]);
                 }
                 // Add methods
                 foreach ($methods as $method_name => $method_overloads) {
                     $method = new Element\FunctionElement($method_name);
                     foreach ($method_overloads as $method_overload) {
                         $overload = new Element\Overload($method_overload["description"]);
                         $overload->SetReturnType(new Element\ReturnType($method_overload["return_type"]));
                         if (isset($method_overload["constant"])) {
                             $overload->constant = $method_overload["constant"];
                         }
                         if (isset($method_overload["static"])) {
                             $overload->static = $method_overload["static"];
                         }
                         if (isset($method_overload["virtual"])) {
                             $overload->virtual = $method_overload["virtual"];
                         }
                         if (isset($method_overload["pure_virtual"])) {
                             $overload->pure_virtual = $method_overload["pure_virtual"];
                         }
                         if (isset($method_overload["protected"])) {
                             $overload->protected = $method_overload["protected"];
                         }
                         if (isset($method_overload["parameters"])) {
                             foreach ($method_overload["parameters"] as $parameter) {
                                 if (!isset($parameter["value"])) {
                                     $parameter["value"] = "";
                                 }
                                 if (!isset($parameter["description"])) {
                                     $parameter["description"] = "";
                                 }
                                 $param = new Element\Parameter($parameter["name"], $parameter["type"], $parameter["value"], $parameter["description"]);
                                 if (isset($parameter["is_array"])) {
                                     $param->is_array = true;
                                 }
                                 $overload->AddParameter($param);
                             }
                         }
                         $method->AddOverload($overload);
                     }
                     $class->AddMethod($method);
                 }
                 // Add enumerations
                 if (isset($enumerations_def[$header][$namespace][$class_name])) {
                     foreach ($enumerations_def[$header][$namespace][$class_name] as $enumeration_name => $enumeration_data) {
                         if (!isset($enumeration_data["description"])) {
                             $enumeration_data["description"] = "";
                         }
                         $class->AddEnumeration(new Element\Enumeration($enumeration_name, $enumeration_data["options"], $enumeration_data["description"]));
                     }
                 }
                 // Add variables
                 if (isset($variables_def[$header][$namespace][$class_name])) {
                     foreach ($variables_def[$header][$namespace][$class_name] as $variable_name => $variable_options) {
                         $variable = new Element\ClassVariable($variable_name, $variable_options["type"]);
                         if (isset($variable_options["static"])) {
                             $variable->static = $variable_options["static"];
                         }
                         if (isset($variable_options["mutable"])) {
                             $variable->mutable = $variable_options["mutable"];
                         }
                         if (isset($variable_options["protected"])) {
                             $variable->protected = $variable_options["protected"];
                         }
                         if (isset($variable_options["public"])) {
                             $variable->public = $variable_options["public"];
                         }
                         if (isset($variable_options["description"])) {
                             $variable->description = $variable_options["description"];
                         }
                         $class->AddVariable($variable);
                     }
                 }
                 $this->symbols->headers[$header]->AddClass($class, $namespace);
             }
         }
     }
     unset($classes_def);
     unset($enumerations_def);
     unset($variables_def);
 }