Skip to content

gen_stub: various simplifications and clean up (5) #18665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
gen_stub: add SimpleType::toTypeInfo()
Simplifies the implementation of `::toTypeCode()` and `::toTypeMask()` by
combining the `switch` blocks.
  • Loading branch information
DanielEScherzer committed May 29, 2025
commit 9847938d10f544a33a8c66f73cd00754ac16f34a
74 changes: 23 additions & 51 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,79 +361,51 @@ public function isMixed(): bool {
return $this->isBuiltin && $this->name === 'mixed';
}

public function toTypeCode(): string {
assert($this->isBuiltin);
switch ($this->name) {
case "bool":
return "_IS_BOOL";
case "int":
return "IS_LONG";
case "float":
return "IS_DOUBLE";
case "string":
return "IS_STRING";
case "array":
return "IS_ARRAY";
case "object":
return "IS_OBJECT";
case "void":
return "IS_VOID";
case "callable":
return "IS_CALLABLE";
case "mixed":
return "IS_MIXED";
case "static":
return "IS_STATIC";
case "never":
return "IS_NEVER";
case "null":
return "IS_NULL";
case "false":
return "IS_FALSE";
case "true":
return "IS_TRUE";
default:
throw new Exception("Not implemented: $this->name");
}
}

public function toTypeMask(): string {
private function toTypeInfo(): array {
assert($this->isBuiltin);

switch ($this->name) {
case "null":
return "MAY_BE_NULL";
return ["IS_NULL", "MAY_BE_NULL"];
case "false":
return "MAY_BE_FALSE";
return ["IS_FALSE", "MAY_BE_FALSE"];
case "true":
return "MAY_BE_TRUE";
return ["IS_TRUE", "MAY_BE_TRUE"];
case "bool":
return "MAY_BE_BOOL";
return ["_IS_BOOL", "MAY_BE_BOOL"];
case "int":
return "MAY_BE_LONG";
return ["IS_LONG", "MAY_BE_LONG"];
case "float":
return "MAY_BE_DOUBLE";
return ["IS_DOUBLE", "MAY_BE_DOUBLE"];
case "string":
return "MAY_BE_STRING";
return ["IS_STRING", "MAY_BE_STRING"];
case "array":
return "MAY_BE_ARRAY";
return ["IS_ARRAY", "MAY_BE_ARRAY"];
case "object":
return "MAY_BE_OBJECT";
return ["IS_OBJECT", "MAY_BE_OBJECT"];
case "callable":
return "MAY_BE_CALLABLE";
return ["IS_CALLABLE", "MAY_BE_CALLABLE"];
case "mixed":
return "MAY_BE_ANY";
return ["IS_MIXED", "MAY_BE_ANY"];
case "void":
return "MAY_BE_VOID";
return ["IS_VOID", "MAY_BE_VOID"];
case "static":
return "MAY_BE_STATIC";
return ["IS_STATIC", "MAY_BE_STATIC"];
case "never":
return "MAY_BE_NEVER";
return ["IS_NEVER", "MAY_BE_NEVER"];
default:
throw new Exception("Not implemented: $this->name");
}
}

public function toTypeCode(): string {
return $this->toTypeInfo()[0];
}

public function toTypeMask(): string {
return $this->toTypeInfo()[1];
}

public function toOptimizerTypeMaskForArrayKey(): string {
assert($this->isBuiltin);

Expand Down