improve shared symbol tables
[awesomized/ext-ion] / ion.stub.php
index f56274f9ffa6ad101253d82de5aa6d4bf91d98d3..2e3324308495335e0c612d94437dcb1b059fd14c 100644 (file)
@@ -1,6 +1,10 @@
 <?php
 
-/** @generate-class-entries */
+/**
+ * @generate-class-entries static
+ * @generate-function-entries static
+ */
+
 
 namespace ion;
 enum Type : int {
@@ -23,22 +27,6 @@ enum Type : int {
     case NONE       =-0x200;
 }
 
-enum Annotation : string {
-    case PHP            = "PHP";
-
-    case REFERENCE      = "R";
-    case BACKREF        = "r";
-
-    case OBJECT         = "o";
-    case CLASS_OBJ      = "c";
-    case MAGIC_OBJ      = "O";
-    case CUSTOM_OBJ     = "C";
-    case SERIALIZABLE   = "S";
-    case ENUM           = "E";
-
-    case FIELD_NAME_INT = "i";
-}
-
 namespace ion\Symbol;
 class ImportLocation {
     public function __construct(
@@ -48,7 +36,14 @@ class ImportLocation {
 }
 
 namespace ion\Symbol;
-enum System : string {
+interface Enum {
+    public function toSymbol() : \ion\Symbol;
+    public function toSID() : int;
+    public function toString() : string;
+}
+
+namespace ion\Symbol\Table;
+enum System : string implements \ion\Symbol\Enum {
     case Ion                = '$ion';
     case Ivm_1_0            = '$ion_1_0';
     case IonSymbolTable     = '$ion_symbol_table';
@@ -58,19 +53,34 @@ enum System : string {
     case Symbols            = 'symbols';
     case MaxId              = 'max_id';
     case SharedSymbolTable  = '$ion_shared_symbol_table';
+
+    /** @alias ion\Symbol\Enum::toSymbol */
+    public function toSymbol() : \ion\Symbol {}
+    /** @alias ion\Symbol\Enum::toSID */
+    public function toSID() : int {}
+    /** @alias ion\Symbol\Enum::toString */
+    public function toString() : string {}
 }
 
-namespace ion\Symbol\System;
-enum SID : int {
-    case Ion                = 1;
-    case Ivm_1_0            = 2;
-    case IonSymbolTable     = 3;
-    case Name               = 4;
-    case Version            = 5;
-    case Imports            = 6;
-    case Symbols            = 7;
-    case MaxId              = 8;
-    case SharedSymbolTable  = 9;
+namespace ion\Symbol\Table;
+enum PHP : string implements \ion\Symbol\Enum {
+    case PHP            = 'PHP';
+    case Reference      = 'R';
+    case Backref        = 'r';
+    case Property       = 'p';
+    case Object         = 'o';
+    case ClassObject    = 'c';
+    case MagicObject    = 'O';
+    case CustomObject   = 'C';
+    case Enum           = 'E';
+    case Serializable   = 'S';
+
+    /** @alias ion\Symbol\Enum::toSymbol */
+    public function toSymbol() : \ion\Symbol {}
+    /** @alias ion\Symbol\Enum::toSID */
+    public function toSID() : int {}
+    /** @alias ion\Symbol\Enum::toString */
+    public function toString() : string {}
 }
 
 namespace ion;
@@ -88,25 +98,110 @@ class Symbol {
 }
 
 namespace ion\Symbol;
-class Table {
+interface Table {
+    public function getMaxId() : int;
 
+    public function add(\ion\Symbol|string $symbol) : int;
+    public function find(string|int $id) : ?\ion\Symbol;
+    public function findLocal(string|int $id) : ?\ion\Symbol;
 }
 
-namespace ion;
-class Catalog {
+namespace ion\Symbol\Table;
+function PHP() : \ion\Symbol\Table {}
+function System() : \ion\Symbol\Table {}
+
+namespace ion\Symbol\Table;
+class Local implements \ion\Symbol\Table {
+    private array $imports = [];
+    private array $symbols = [];
+
+    public function __construct() {}
+    public function import(\ion\Symbol\Table $table) : void {}
+
+    /** @alias ion\Symbol\Table::getMaxId */
+    public function getMaxId() : int {}
+
+    /** @alias ion\Symbol\Table::add */
+    public function add(\ion\Symbol|string $symbol) : int {}
+    /** @alias ion\Symbol\Table::find */
+    public function find(string|int $id) : ?\ion\Symbol {}
+    /** @alias ion\Symbol\Table::findLocal */
+    public function findLocal(string|int $id) : ?\ion\Symbol {}
+}
+
+namespace ion\Symbol\Table;
+class Shared implements \ion\Symbol\Table {
+    public function __construct(
+        public readonly string $name,
+        public readonly int $version = 1,
+        ?array $symbols = null,
+    ) {}
+
+    /** Internal cache */
+    private array $symbols = [];
+
+    /** @alias ion\Symbol\Table::getMaxId */
+    public function getMaxId() : int {}
+
+    /** @alias ion\Symbol\Table::add */
+    public function add(\ion\Symbol|string $symbol) : int {}
+    /** @alias ion\Symbol\Table::find */
+    public function find(string|int $id) : ?\ion\Symbol {}
+    /** @alias ion\Symbol\Table::findLocal */
+    public function findLocal(string|int $id) : ?\ion\Symbol {}
 }
 
 namespace ion;
-class Collection {
+class Catalog implements Countable {
+    /** Internal cache */
+    private array $symbolTables = [];
+
+    public function __construct() {}
+
+    public function count() : int {}
+
+    public function add(Symbol\Table $table) : void {}
+    public function remove(Symbol\Table|string $table) : bool {}
 
+    public function find(string $name, int $version = 0) : ?Symbol\Table {}
+    public function findBest(string $name, int $version = 0) : ?Symbol\Table {}
 }
 
+namespace ion;
+class LOB {
+    public function __construct(
+        public readonly string $value,
+        public readonly Type $type = Type::CLob,
+    ) {
+    }
+}
+
+namespace ion\Decimal\Context;
+enum Rounding : int {
+    case Ceiling    = 0;
+    case Up         = 1;
+    case HalfUp     = 2;
+    case HalfEven   = 3;
+    case HalfDown   = 4;
+    case Down       = 5;
+    case Floor      = 6;
+    case Down05Up   = 7;
+}
 
 namespace ion\Decimal;
 class Context {
     public function __construct(
-        public readonly int $bits = 128
+        public readonly int $digits,
+        public readonly int $eMax,
+        public readonly int $eMin,
+        public readonly Context\Rounding|int $round,
+        public readonly bool $clamp,
     ) {}
+
+    public static function Dec32() : Context {}
+    public static function Dec64() : Context {}
+    public static function Dec128() : Context {}
+    public static function DecMax(Context\Rounding|int $round = Context\Rounding::HalfEven) : Context {}
 }
 
 namespace ion;
@@ -133,6 +228,9 @@ enum Precision : int {
     case Min            = 0x1|0x2|0x4|0x10;
     case Sec            = 0x1|0x2|0x4|0x10|0x20;
     case Frac           = 0x1|0x2|0x4|0x10|0x20|0x40;
+    case MinTZ          = 0x1|0x2|0x4|0x10|0x80;
+    case SecTZ          = 0x1|0x2|0x4|0x10|0x20|0x80;
+    case FracTZ         = 0x1|0x2|0x4|0x10|0x20|0x40|0x80;
 }
 namespace ion;
 class Timestamp extends \DateTime {
@@ -201,10 +299,10 @@ class Options {
         public readonly int $maxContainerDepth = 10,
         public readonly int $maxAnnotations = 10,
         public readonly int $maxAnnotationBuffered = 512,
-        public readonly int $symbolThreshold = 4096,
-        public readonly int $userValueThreshold = 4096,
-        public readonly int $chunkThreshold = 4096,
-        public readonly int $allocationPageSize = 4096,
+        public readonly int $symbolThreshold = 0x4000,
+        public readonly int $userValueThreshold = 0x4000,
+        public readonly int $chunkThreshold = 0x4000,
+        public readonly int $allocationPageSize = 0x10000,
         public readonly bool $skipCharacterValidation = false,
     ) {}
 }
@@ -318,11 +416,9 @@ class Options {
         public readonly bool $flushEveryValue = false,
         public readonly int $maxContainerDepth = 10,
         public readonly int $maxAnnotations = 10,
-        public readonly int $tempBufferSize = 0x400,
-        public readonly int $allocationPageSize = 0x1000,
+        public readonly int $tempBufferSize = 0x4000,
+        public readonly int $allocationPageSize = 0x10000,
     ) {}
-
-    // public function addSharedImports(\ion\Collection|\ion\Symbol\Table ...$imports) : void;
 }
 
 namespace ion;
@@ -450,6 +546,7 @@ namespace ion\Serializer;
 class PHP implements \ion\Serializer {
     public function __construct(
         public readonly ?\ion\Writer\Options $writerOptions = null,
+        public readonly bool $multiSequence = false,
         public readonly bool $callMagicSerialize = true,
         public readonly ?string $callCustomSerialize = null,
     ) {}
@@ -461,6 +558,7 @@ namespace ion\Unserializer;
 class PHP implements \ion\Unserializer {
     public function __construct(
         public readonly ?\ion\Reader\Options $readerOptions = null,
+        public readonly bool $multiSequence = true,
         public readonly bool $callMagicUnserialize = true,
         public readonly ?string $callCustomUnserialize = null,
     ){}
@@ -473,4 +571,4 @@ class PHP implements \ion\Unserializer {
 namespace ion;
 function serialize(mixed $data, ?Serializer $serializer = null) : string {}
 /** @param string|resource $data */
-function unserialize(mixed $data, ?Unserializer $unserializer = null) : mixed {}
+function unserialize($data, ?Unserializer $unserializer = null) : mixed {}