示例#1
0
文件: Base.php 项目: peg-org/peg-src
 /**
  * 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;
 }