Skip to content

Commit

Permalink
#2440 - Mass code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Dec 6, 2024
1 parent d3e9a97 commit 8ad3733
Show file tree
Hide file tree
Showing 23 changed files with 57 additions and 288 deletions.
68 changes: 2 additions & 66 deletions src/Backend/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Zephir\Backend;

use Zephir\Class\Definition\Definition;
use Zephir\Class\Method\Method;
use Zephir\Code\Printer;
use Zephir\CompilationContext;
Expand Down Expand Up @@ -512,7 +511,7 @@ public function assignArrayMulti(
): void {
[$keys, $offsetItems, $numberParams] = $this->resolveOffsetExprs($offsetExprs, $compilationContext);

$symbol = $this->resolveValue($symbolVariable, $compilationContext, true);
$symbol = $this->resolveValue($symbolVariable, $compilationContext);
$varCode = $this->getVariableCode($variable);
$compilationContext->codePrinter->output(
sprintf(
Expand Down Expand Up @@ -617,14 +616,6 @@ public function assignStaticPropertyArrayMulti(
);
}

/**
* @param Variable $variable
* @param string|Variable|null $value
* @param CompilationContext $context
* @param bool $useCodePrinter
*
* @return string
*/
public function assignString(
Variable $variable,
$value,
Expand All @@ -642,10 +633,6 @@ public function assignString(

/**
* Assigns a zval to another.
*
* @param Variable $variable
* @param string $code
* @param CompilationContext $context
*/
public function assignZval(Variable $variable, $code, CompilationContext $context): void
{
Expand Down Expand Up @@ -998,15 +985,6 @@ public function fetchGlobal(Variable $globalVar, CompilationContext $compilation
return $output;
}

/**
* @param Variable $symbolVariable
* @param Variable $variableVariable
* @param Variable|string $property
* @param bool $readOnly
* @param CompilationContext $context
*
* @return void
*/
public function fetchProperty(
Variable $symbolVariable,
Variable $variableVariable,
Expand Down Expand Up @@ -1048,12 +1026,6 @@ public function fetchProperty(
}

/**
* @param Variable $symbolVariable
* @param Definition $classDefinition
* @param $property
* @param bool $readOnly
* @param CompilationContext $context
*
* @throws Exception
*/
public function fetchStaticProperty(
Expand Down Expand Up @@ -1376,12 +1348,6 @@ public function getInternalKernelPath(): string
return $this->kernelsPath;
}

/**
* @param Method $method
* @param CompilationContext $context
*
* @return string
*/
public function getInternalSignature(Method $method, CompilationContext $context): string
{
if ($method->isInitializer() && !$method->isStatic()) {
Expand Down Expand Up @@ -1426,12 +1392,6 @@ public function getInternalSignature(Method $method, CompilationContext $context
return "void {$method->getInternalName()}({$signaturePattern})";
}

/**
* @param string $type
* @param CompilationContext $compilationContext
*
* @return Variable
*/
public function getScalarTempVariable(
string $type,
CompilationContext $compilationContext,
Expand Down Expand Up @@ -1553,12 +1513,6 @@ public function getTypeDefinition($type): array
}

/**
* @param Variable $variableVariable
* @param string $operator
* @param string $value
*
* @return string
*
* @throws CompilerException
*/
public function getTypeofCondition(
Expand Down Expand Up @@ -1763,7 +1717,7 @@ public function onPreInitVar(Method $method): string
return '';
}

public function propertyIsset(Variable $var, $key)
public function propertyIsset(Variable $var, $key): CompiledExpression
{
return new CompiledExpression(
'bool',
Expand All @@ -1773,11 +1727,6 @@ public function propertyIsset(Variable $var, $key)
}

/**
* @param $value
* @param CompilationContext $context
*
* @return bool|string|Variable
*
* @throws CompilerException
*/
public function resolveValue($value, CompilationContext $context): Variable | bool | string
Expand Down Expand Up @@ -1920,14 +1869,6 @@ public function updateArray(
}
}

/**
* @param Variable $variable
* @param string|Variable $property
* @param mixed $value
* @param CompilationContext $context
*
* @return void
*/
public function updateProperty(Variable $variable, $property, $value, CompilationContext $context): void
{
$value = $this->resolveValue($value, $context);
Expand Down Expand Up @@ -2040,11 +1981,6 @@ protected function returnHelper(
/**
* Resolve expressions.
*
* @param CompiledExpression[]|string[] $offsetExprs
* @param CompilationContext $compilationContext
*
* @return array
*
* @throws CompilerException
*/
private function resolveOffsetExprs(array $offsetExprs, CompilationContext $compilationContext): array
Expand Down
6 changes: 1 addition & 5 deletions src/Backend/FcallManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,7 @@ public function genFcallCode(): void
}

/**
* @param bool $static
* @param int $doReturn tri-state: 0 -> no return value, 1 -> do return, 2 -> do return to given variable
* @param int $paramCount
*
* @return string
* tri-state: 0 -> no return value, 1 -> do return, 2 -> do return to given variable
*/
public function getMacro(bool $static, int $doReturn, int $paramCount): string
{
Expand Down
6 changes: 0 additions & 6 deletions src/Backend/FcallManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ public function genFcallCode(): void;

/**
* Resolve internal fcall attributes to a suitable macro and ensure that it's generated during compilation.
*
* @param bool $static
* @param int $doReturn tri-state: 0 -> no return value, 1 -> do return, 2 -> do return to given variable
* @param int $paramCount
*
* @return string
*/
public function getMacro(bool $static, int $doReturn, int $paramCount): string;
}
6 changes: 0 additions & 6 deletions src/Backend/VariablesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ class VariablesManager
* Shouldn't called directly.
*
* TODO: Figure out why it never reached during generation.
*
* @param Variable $variable
* @param array $value
* @param Context $context
*
* @return void
*/
public function initializeDefaults(Variable $variable, array $value, Context $context): void
{
Expand Down
4 changes: 0 additions & 4 deletions src/Cache/SlotsCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ public static function getExistingMethodSlot(Method $method): int

/**
* Returns or creates a cache slot for a function.
*
* @param string $functionName
*
* @return int
*/
public static function getFunctionSlot(string $functionName): int
{
Expand Down
59 changes: 23 additions & 36 deletions src/Class/Definition/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,70 +58,62 @@ final class Definition extends AbstractDefinition
* Contains "abstract" in the definition
*/
protected bool $abstract = false;
/**
* @var AliasManager|null
*/

protected ?AliasManager $aliasManager = null;
/**
* @var Compiler
*/

protected Compiler $compiler;
/**
* @var Constant[]
*/
protected array $constants = [];
/**
* @var int
*/

protected int $dependencyRank = 0;
/**
* @var string
*/

protected string $docBlock = '';

/**
* Name of inherited class
*/
protected ?string $extendsClass = null;

/**
* Definition object of inherited class
*/
protected ?AbstractDefinition $extendsClassDefinition = null;

/**
* When class is from external dependency
*/
protected bool $external = false;

/**
* Contains "final" in the definition
*/
protected bool $final = false;
/**
* @var array
*/

protected array $implementedInterfaceDefinitions = [];

/**
* List of implemented interfaces of current class
*/
protected array $interfaces = [];
/**
* @var bool
*/

protected bool $isBundled = false;

/**
* @var Method[]
*/
protected array $methods = [];
/**
* @var array
*/

protected array $originalNode = [];
/**
* @var Docblock|null
*/

protected ?Docblock $parsedDocblock = null;

/**
* @var Property[]
*/
protected array $properties = [];

/**
* Class short name
*
Expand All @@ -130,14 +122,17 @@ final class Definition extends AbstractDefinition
* @see Definition::name
*/
protected string $shortName;

/**
* Definition type
*/
protected string $type = self::TYPE_CLASS;

public function __construct(protected string $namespace, string $name, ?string $shortName = null)
{
$this->name = $name;
public function __construct(
protected string $namespace,
protected string $name,
?string $shortName = null,
) {
$this->shortName = $shortName ?: $name;
}

Expand Down Expand Up @@ -888,7 +883,7 @@ public function getExtendsClass(): ?string
*/
public function getExtendsClassDefinition(): ?AbstractDefinition
{
if (!$this->extendsClassDefinition && $this->extendsClass && $this->compiler) {
if (!$this->extendsClassDefinition && $this->extendsClass) {
$this->setExtendsClassDefinition($this->compiler->getClassDefinition($this->extendsClass));
}

Expand Down Expand Up @@ -1060,10 +1055,6 @@ public function getProperties(): array

/**
* Returns a method definition by its name.
*
* @param string $propertyName
*
* @return Property|null
*/
public function getProperty(string $propertyName): ?Property
{
Expand Down Expand Up @@ -1139,10 +1130,6 @@ public function hasConstant(string $name): bool

/**
* Checks if the class implements a specific name.
*
* @param string $methodName
*
* @return bool
*/
public function hasMethod(string $methodName): bool
{
Expand Down
10 changes: 5 additions & 5 deletions src/Class/Method/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@
class Method
{
public bool $optimizable = true;

/**
* Call Gatherer Pass.
*/
protected ?CallGathererPass $callGathererPass = null;
protected ?Definition $classDefinition = null;

/**
* Whether the method is abstract or not.
*/
Expand Down Expand Up @@ -130,17 +131,16 @@ class Method
protected bool $void = false;

public function __construct(
Definition $classDefinition,
protected array $visibility,
protected string $name,
protected ?Definition $classDefinition = null,
protected array $visibility = [],
protected string $name = '',
protected ?Parameters $parameters = null,
protected ?StatementsBlock $statements = null,
protected ?string $docblock = null,
?array $returnType = null,
protected ?array $expression = [],
array $staticVariables = [],
) {
$this->classDefinition = $classDefinition;
$this->staticVariables = $staticVariables;

$this->checkVisibility($visibility, $name, $expression);
Expand Down
3 changes: 0 additions & 3 deletions src/Class/Method/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ public function __construct(private array $parameters)
}
}

/**
* @return int
*/
public function count(): int
{
return count($this->parameters);
Expand Down
Loading

0 comments on commit 8ad3733

Please sign in to comment.