From c330fda0cfe72cc3b900b386ff68da62b45bff7a Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Mon, 20 Jan 2025 20:12:19 +0300 Subject: [PATCH] Adding initial support for services only events --- metagen.inc.php | 16 ++++++++++++++-- parser2.inc.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/metagen.inc.php b/metagen.inc.php index 0c57110..4724cde 100644 --- a/metagen.inc.php +++ b/metagen.inc.php @@ -586,6 +586,7 @@ class mtgMetaService extends mtgMetaUnit implements mtgScope private $name; private $parent_scope; private $rpcs = array(); + private $events = array(); private $user_types = array(); function __construct($name, mtgScope $parent_scope, array $tokens = array()) @@ -615,7 +616,7 @@ class mtgMetaService extends mtgMetaUnit implements mtgScope return $this->parent_scope->findSymbol($name); } - function getRPCs() + function getRPCs() : array { return $this->rpcs; } @@ -646,7 +647,7 @@ class mtgMetaService extends mtgMetaUnit implements mtgScope return $this->rpcs[$name]; } - function getUserTypes() + function getUserTypes() : array { return $this->user_types; } @@ -671,6 +672,17 @@ class mtgMetaService extends mtgMetaUnit implements mtgScope return $this->user_types[$name]; } + function addEvent(mtgMetaStruct $evt) + { + $this->events[] = $evt; + $this->addUserStruct($evt); + } + + function getEvents() : array + { + return $this->events; + } + function getClassId() { if($this->hasToken('class_id')) diff --git a/parser2.inc.php b/parser2.inc.php index 25e1ac0..5635d14 100644 --- a/parser2.inc.php +++ b/parser2.inc.php @@ -31,6 +31,7 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser const T_bool = 1030; const T_blob = 1031; const T_Service = 1032; + const T_Event = 1033; const T_MaxType = 1034; //built-in types end mark private array $config = array(); @@ -95,6 +96,7 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser "extends" => self::T_Extends, "implements" => self::T_Implements, "func" => self::T_Func, + "event" => self::T_Event, ]; $this->T2descr = array_flip($this->symbol2T); @@ -113,6 +115,7 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser $this->T2descr[self::T_Extends] = ''; $this->T2descr[self::T_Implements] = ''; $this->T2descr[self::T_Func] = ''; + $this->T2descr[self::T_Event] = ''; } private static function _addDefaultTokens(array &$config) @@ -574,6 +577,37 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser $this->_addUnit(new mtgMetaInfoUnit($this->module, $fn)); } + private function _parseEvent() : mtgMetaStruct + { + $this->_nextT(); + $struct_origin = new mtgOrigin($this->file, $this->line); + $name = $this->_parseDotName(); + + $this->_checkThenNext(ord('{')); + + $s = new mtgMetaStruct($name, array(), null, array(), array()); + $s->setOrigin($struct_origin); + + $tokens = $this->shared_tokens; + if($this->T == self::T_Prop) + $tokens = array_merge($tokens, $this->_parsePropTokens()); + $s->setTokens($tokens); + + $flds = $this->_parseFields( + function() + { + if($this->_nextIf(ord('}'))) + return true; + if($this->_nextIf(self::T_Func)) + $this->_error("Events don't support functions"); + } + ); + foreach($flds as $fld) + $s->addField($fld); + + return $s; + } + private function _parseStruct() { $this->_nextT(); @@ -719,6 +753,8 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser $service->addRPC($this->_parseRPC(false)); else if($this->T == self::T_Enum) $service->addUserType($this->_parseEnum(false)); + else if($this->T == self::T_Event) + $service->addUserType($this->_parseEvent()); else $this->_error("Unsupported type"); }