From 4499ce0eaa4442e5b258c11299e95b02cca617f7 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Thu, 30 Nov 2023 18:48:28 +0300 Subject: [PATCH] Storing mtgMetaParsedModule as module in mtgMetaInfoUnit --- metagen.inc.php | 20 +++++++++++++++++--- parser.inc.php | 10 +++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/metagen.inc.php b/metagen.inc.php index 1ebb08e..d6686a3 100644 --- a/metagen.inc.php +++ b/metagen.inc.php @@ -76,13 +76,27 @@ class mtgTypeRef implements mtgType class mtgMetaInfoUnit { + public ?mtgMetaParsedModule $module = null; public string $file; public mtgMetaUnit $object; - function __construct($f, mtgMetaUnit $o) + /** + * @param string|mtgMetaParsedModule $file_or_module + */ + function __construct($file_or_module, mtgMetaUnit $obj) { - $this->file = $f; - $this->object = $o; + if($file_or_module instanceof mtgMetaParsedModule) + { + $this->module = $file_or_module; + $this->file = $file_or_module->file; + } + else if(is_string($file_or_module)) + { + $this->module = null; + $this->file = $file_or_module; + } + + $this->object = $obj; } } diff --git a/parser.inc.php b/parser.inc.php index ceb58c5..1316154 100644 --- a/parser.inc.php +++ b/parser.inc.php @@ -409,7 +409,7 @@ class mtgMetaInfoParser $existing->object->replace($enum); } else - $this->_addUnit(new mtgMetaInfoUnit($this->file, $enum)); + $this->_addUnit(new mtgMetaInfoUnit($this->module, $enum)); } static private function _isBuiltinType(int $t) : bool @@ -540,7 +540,7 @@ class mtgMetaInfoParser $this->_nextT(); $fn = $this->_parseFunc(); $fn->setTokens(array_merge($this->shared_tokens, $fn->getTokens())); - $this->_addUnit(new mtgMetaInfoUnit($this->file, $fn)); + $this->_addUnit(new mtgMetaInfoUnit($this->module, $fn)); } private function _parseStruct() @@ -572,7 +572,7 @@ class mtgMetaInfoParser $s = new mtgMetaStruct($name, array(), $parent, array(), $implements); $s->setOrigin($struct_origin); - $this->_addUnit(new mtgMetaInfoUnit($this->file, $s)); + $this->_addUnit(new mtgMetaInfoUnit($this->module, $s)); $tokens = $this->shared_tokens; if($this->T == self::T_Prop) @@ -609,7 +609,7 @@ class mtgMetaInfoParser $name = $this->_parseDotName(); $s = new mtgMetaInterface($name); - $this->_addUnit(new mtgMetaInfoUnit($this->file, $s)); + $this->_addUnit(new mtgMetaInfoUnit($this->module, $s)); $tokens = $this->shared_tokens; if($this->T == self::T_Prop) @@ -652,7 +652,7 @@ class mtgMetaInfoParser $rsp->setFields($rsp_fields); $rpc = new mtgMetaRPC("RPC_$name", $code, $req, $rsp, $tokens); - $this->_addUnit(new mtgMetaInfoUnit($this->file, $rpc)); + $this->_addUnit(new mtgMetaInfoUnit($this->module, $rpc)); } private function _parsePropTokens()