Generate code calling a replacement method with arguments.

@param string $typeName
@param \ReflectionFunction $ref
@param integer $num
@param array<string> $prepend
@return string

@throws \RuntimeException When a param value could not be populated.
960886
protected function generateCallCode($typeName, \ReflectionFunction $ref, $num, array $prepend = [], array $resolvers = NULL)
	{
		$code = '$this->call_' . $num . '(';
		
		foreach($ref->getParameters() as $i => $param)
		{
			if($i != 0)
			{
				$code .= ', ';
			}
			
			if(array_key_exists($i, $prepend))
			{
				$code .= $prepend[$i];
				
				continue;
			}
			
			if($resolvers !== NULL && array_key_exists($param->name, $resolvers))
			{
				$resolver = $resolvers[$param->name];
				
				if($resolver instanceof \Closure)
				{
					$num = count($this->methods);
						
					$ref = new \ReflectionFunction($resolver);
					$sig = $this->generateReplacementMethodSignature($ref, $num);
					$body = $this->extractClosureCode($ref);
					
					$this->methods[] = "\t\t" . $sig . " {\n" . $body . "\n\t\t}";
					
					$code .= $this->generateCallCode($typeName, $ref, $num);
					
					continue;
				}
				elseif($resolver instanceof CompiledCodeFragment)
				{
					$code .= $resolver;
					
					continue;
				}
				
				$code .= var_export($resolver, true);
				
				continue;
			}
			
			if(NULL !== ($ptype = $this->getParamType($param)))
			{
				if($ptype === InjectionPointInterface::class)
				{
					$code .= '$point';
					
					continue;
				}
				
				$code .= '$this->get(' . var_export($ptype, true) . ', isset($point) ? $point : NULL)';
				
				continue;
			}
			
			if($param->isOptional())
			{
				$code .= $param->isDefaultValueAvailable() ? var_export($param->getDefaultValue(), true) : 'NULL';
				
				continue;
			}
			
			throw new TypeNotFoundException(sprintf('Cannot populate closure param "%s" without type hint or resolver', $param->name));
		}
		
		return $code . ')';
	}
519232
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
    {
        $params = $compiler->getCompiledParams($params);

        $mode = trim($params['mode'], '"\'');
        switch ($mode) {
            case 'js':
            case 'javascript':
                $content = preg_replace('#(?<!:)//\s[^\r\n]*|/\*.*?\*/#s', '', $content);

            case 'default':
            default:
        }
        $content = preg_replace(array(
            "/\n/",
            "/\r/",
            '/(<\?(?:php)?|<%)\s*/'
        ), array(
            '',
            '',
            '$1 '
        ), preg_replace('#^\s*(.+?)\s*$#m', '$1', $content));

        return $content;
    }
551871
static function name($ref) {
		return implode("_", array_map(function($ck, $cr) {
			return preg_replace("/_$cr\$/", "", $ck);
		}, $ref["foreignColumns"], $ref["referencedColumns"]));
	}
1037080
protected function parseDefer($methodName, ...$args)
    {
        $innerMethodName = '__' . $methodName;
        $instance = $this->getInstance();
        if(method_exists($instance, 'setDefer'))
        {
            $instance->setDefer(true);
            $generate = $this->$innerMethodName(...$args);
            $generate->next();
            $callable = function() use($instance, $generate){
                $result = $instance->recv();
                $generate->send($result);
                return $generate->getReturn();
            };
        }
        else
        {
            $callable = function() use ($methodName, $args){
                return $this->$methodName(...$args);
            };
        }
        return new Defer($callable);
    }
1134290
protected function extractClosureCode(\ReflectionFunction $ref)
	{
		$file = $ref->getFileName();
		$lines = file($file, FILE_IGNORE_NEW_LINES);
		
		if(isset($this->namespaceContextCache[$file]))
		{
			$namespaceContext = $this->namespaceContextCache[$file];
		}
		else
		{
			$tokens = token_get_all(implode("\n", $lines));
			$namespaceContext = $this->namespaceContextCache[$file] = $this->generateNamespaceContext($tokens);
		}
		
		// Extract closure code from file source.
		$funcLines = array_slice($lines, $ref->getStartLine() - 1, $ref->getEndLine() - $ref->getStartLine() + 1);
		$snippet = implode("\n", array_map('trim', $funcLines));
		$snippet = preg_replace("'^.*\{'", '', $snippet);
		$snippet = preg_replace("'\}.*$'", '', $snippet);
		
		// Parse closure code snippet and expand unqualified names.
		$tokens = array_slice(token_get_all('<?php ' . $snippet), 1);
		$buffer = $this->expandNames($tokens, $namespaceContext);
		
		return str_replace("\n", "\n\t\t", "\n" . trim($buffer));
	}
1283281
public function prependScript($script, $type = 'text/javascript', array $params = [], $conditional = '')
    {
        return $this->setScript($script, $type, $params, true, $conditional);
    }
776441
public function prependFile($src, $type = 'text/javascript', array $params = [], $conditional = '')
    {
        return $this->setFile($src, $type, $params, true, $conditional);
    }
18139
private function createParam(Param $param, RefComment $comment = null)
    {
        $ref       = new RefParam();
        $ref->name = $param->var->name;

        if ($comment !== null) {
            $name = preg_quote($param->var->name, '/');
            if (preg_match('/@param\s+([^\s]+)\s+\$' . $name . '(?:\s*$|\s+(.*)$)/m', $comment->text, $matches)) {
                $ref->type        = $matches[1];
                $ref->description = isset($matches[2]) ? $matches[2] : null;
            }
        }

        if (!$ref->type) {
            $ref->type = $this->getTypeName($param->type);
        }

        $ref->byRef      = $param->byRef;
        $ref->isVariadic = $param->variadic;

        $ref->hasDefault = $param->default !== null;
        $ref->default    = $this->getValue($param->default);

        return $ref;
    }
367442
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
    {
        try {
            $compiler->findBlock('dynamic');

            return $content;
        }
        catch (CompilationException $e) {
        }
        $output = Compiler::PHP_OPEN . 'if($doCache) {' . "\n\t" . 'echo \'<dwoo:dynamic_\'.$dynamicId.\'>' . str_replace('\'', '\\\'', $content) . '</dwoo:dynamic_\'.$dynamicId.\'>\';' . "\n} else {\n\t";
        if (substr($content, 0, strlen(Compiler::PHP_OPEN)) == Compiler::PHP_OPEN) {
            $output .= substr($content, strlen(Compiler::PHP_OPEN));
        } else {
            $output .= Compiler::PHP_CLOSE . $content;
        }
        if (substr($output, - strlen(Compiler::PHP_CLOSE)) == Compiler::PHP_CLOSE) {
            $output = substr($output, 0, - strlen(Compiler::PHP_CLOSE));
        } else {
            $output .= Compiler::PHP_OPEN;
        }
        $output .= "\n}" . Compiler::PHP_CLOSE;

        return $output;
    }
1321215
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
    {
        $params     = $compiler->getCompiledParams($params);
        $func       = $params['__funcname'];
        $pluginType = $params['__functype'];
        $params     = $params['*'];

        if ($pluginType & Core::CUSTOM_PLUGIN) {
            $customPlugins = $compiler->getCore()->getCustomPlugins();
            $callback      = $customPlugins[$func]['callback'];
            if (is_array($callback)) {
                if (is_object($callback[0])) {
                    $callback = '$this->customPlugins[\'' . $func . '\'][0]->' . $callback[1] . '(';
                } else {
                    $callback = '' . $callback[0] . '::' . $callback[1] . '(';
                }
            } else {
                $callback = $callback . '(';
            }
        } else {
            $callback = 'smarty_block_' . $func . '(';
        }

        $paramsOut = '';
        foreach ($params as $i => $p) {
            $paramsOut .= var_export($i, true) . ' => ' . $p . ',';
        }

        $curBlock                      = &$compiler->getCurrentBlock();
        $curBlock['params']['postOut'] = Compiler::PHP_OPEN . ' $_block_content = ob_get_clean(); $_block_repeat=false; echo ' . $callback . '$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);' . Compiler::PHP_CLOSE;

        return Compiler::PHP_OPEN . $prepend . ' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array(' . $paramsOut . '); $_block_repeat=true; ' . $callback . '$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();' . Compiler::PHP_CLOSE;
    }
674516
static function gnameForRef($fname) {
		$refDefs = static::refDefs();
		$gname = $refDefs[$fname][static::GNAME];
		if ($gname === null) {
			throw new \Exception("Invalid fname `$fname` called for gnameForRef");
		}
		return $gname;
	}
1222993
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
    {
        if (!isset($params['initialized'])) {
            return '';
        }

        $block                      = &$compiler->getCurrentBlock();
        $block['params']['hasElse'] = Compiler::PHP_OPEN . "else {\n" . Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;

        return '';
    }
31147
public function compile($argumentsName, $closureName, &$initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler)
    {
        $valueVariableName = $compiler->variableName('value');
        $initializationPhpCode .= sprintf('%1$s = (%2$s[\'value\'] !== null ? %2$s[\'value\'] : %3$s());', $valueVariableName, $argumentsName, $closureName) . chr(10);
        $initializationPhpCode .= sprintf('if (!is_object(%1$s) && %1$s !== null) { throw new \Neos\FluidAdaptor\Core\ViewHelper\Exception(\'f:format.identifier expects an object, \' . gettype(%1$s) . \' given.\', 1337700024); }', $valueVariableName) . chr(10);

        return sprintf(
            '%1$s === null ? null : $renderingContext->getObjectManager()->get(\Neos\Flow\Persistence\PersistenceManagerInterface::class)->getIdentifierByObject(%1$s)',
            $valueVariableName
        );
    }
1155653
function compile($indent) {
		$function_name = $this->function_name( $this->name ) ;
		
		// Build the typestack
		$typestack = array(); $class=$this;
		do {
			$typestack[] = $this->function_name($class->name);
		}
		while($class = $class->extends);

		$typestack = "array('" . implode("','", $typestack) . "')";
		
		// Build an array of additional arguments to add to result node (if any)
		if (empty($this->arguments)) {
			$arguments = 'null';
		}
		else {
			$arguments = "array(";
			foreach ($this->arguments as $k=>$v) { $arguments .= "'$k' => '$v'"; }
			$arguments .= ")";
		}
		
		$match = PHPBuilder::build() ;
		
		$match->l("protected \$match_{$function_name}_typestack = $typestack;");

		$match->b( "function match_{$function_name} (\$stack = array())",
			'$matchrule = "'.$function_name.'"; $result = $this->construct($matchrule, $matchrule, '.$arguments.');',
			$this->parsed->compile()->replace(array(
				'MATCH' => 'return $this->finalise($result);',
				'FAIL' => 'return FALSE;'
			))
		);

		$functions = array() ;
		foreach( $this->functions as $name => $function ) {
			$function_name = $this->function_name( preg_match( '/^_/', $name ) ? $this->name.$name : $this->name.'_'.$name ) ;
			$functions[] = implode( PHP_EOL, array(
				'function ' . $function_name . ' ' . $function
			));
		}

		// print_r( $match ) ; return '' ;
		return $match->render(NULL, $indent) . PHP_EOL . PHP_EOL . implode( PHP_EOL, $functions ) ;
	}
129191
function param($param, $type = null) {
		if ($param instanceof ExpressibleInterface) {
			$param = $param->get();
		}
		if ($param instanceof Expr) {
			return (string) $param;
		}
		
		$this->params[] = $param;
		$this->types[]  = $type;
		
		return "\$".count($this->params);
	}
7846
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type)
    {
        $with = &$compiler->findBlock('for', true);

        $params['initialized'] = true;
        $compiler->injectBlock($type, $params);

        return '';
    }
265472
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content)
    {
        $tokens = $compiler->getParamTokens($params);
        $params = $compiler->getCompiledParams($params);
        $pre    = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE;

        $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE;

        if (isset($params['hasElse'])) {
            $post .= $params['hasElse'];
        }

        return $pre . $content . $post;
    }