From 68898b4327595dfec216ed523208f5d3ea736aa7 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Tue, 23 May 2023 13:38:16 +0300 Subject: [PATCH] Adding initial support for 'implements' and interfaces --- metagen.inc.php | 15 ++++++++++++++- parser.inc.php | 30 ++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/metagen.inc.php b/metagen.inc.php index 6e05614..993e77d 100644 --- a/metagen.inc.php +++ b/metagen.inc.php @@ -172,14 +172,16 @@ class mtgMetaStruct extends mtgUserType protected $fields = array(); protected $funcs = array(); protected $parent = null; + protected $implements = array(); - function __construct($name, $fields = array(), mtgTypeRef $parent = null, $tokens = array()) + function __construct($name, array $fields = array(), mtgTypeRef $parent = null, array $tokens = array(), array $implements = array()) { parent::__construct($name); $this->setFields($fields); $this->parent = $parent; $this->tokens = $tokens; + $this->implements = $implements; } function getParent() @@ -187,6 +189,17 @@ class mtgMetaStruct extends mtgUserType return $this->parent ? $this->parent->resolve() : null; } + function getImplements() + { + if(!$this->implements) + return array(); + + $imps = array(); + foreach($this->implements as $imp) + $imps[] = $imp->resolve(); + return $imps; + } + function getFields() { return $this->fields; diff --git a/parser.inc.php b/parser.inc.php index 307c8cf..077b880 100644 --- a/parser.inc.php +++ b/parser.inc.php @@ -29,6 +29,7 @@ class mtgMetaInfoParser const T_Func = 1012; const T_RawStringConstant = 1013; const T_Interface = 1014; + const T_Implements = 1015; const T_string = 1020; const T_uint32 = 1021; const T_int32 = 1022; @@ -77,6 +78,7 @@ class mtgMetaInfoParser $this->token_strs[self::T_Interface] = ''; $this->token_strs[self::T_Prop] = '<@prop>'; $this->token_strs[self::T_Extends] = ''; + $this->token_strs[self::T_Implements] = ''; $this->token_strs[self::T_Func] = ''; } @@ -463,7 +465,18 @@ class mtgMetaInfoParser $parent = new mtgTypeRef($parent_name, $this->current_meta, $this->file, $this->line); } - $s = new mtgMetaStruct($name, array(), $parent); + $implements = array(); + if($this->token == self::T_Implements) + { + do + { + $this->_next(); + $if_name = $this->_checkThenNext(self::T_Identifier); + $implements[] = new mtgTypeRef($if_name, $this->current_meta, $this->file, $this->line); + } while($this->token == ord(',')); + } + + $s = new mtgMetaStruct($name, array(), $parent, array(), $implements); $this->current_meta->addUnit(new mtgMetaInfoUnit($this->file, $s)); if($this->token == self::T_Prop) @@ -726,13 +739,14 @@ class mtgMetaInfoParser } //check for declaration keywords: - if($this->attribute == "struct") { $this->token = self::T_Struct; return; } - if($this->attribute == "interface") { $this->token = self::T_Interface; return; } - if($this->attribute == "enum") { $this->token = self::T_Enum; return; } - if($this->attribute == "RPC") { $this->token = self::T_RPC; return; } - if($this->attribute == "end") { $this->token = self::T_End; return; } - if($this->attribute == "extends") { $this->token = self::T_Extends; return; } - if($this->attribute == "func") { $this->token = self::T_Func; return; } + if($this->attribute == "struct") { $this->token = self::T_Struct; return; } + if($this->attribute == "interface") { $this->token = self::T_Interface; return; } + if($this->attribute == "enum") { $this->token = self::T_Enum; return; } + if($this->attribute == "RPC") { $this->token = self::T_RPC; return; } + if($this->attribute == "end") { $this->token = self::T_End; return; } + if($this->attribute == "extends") { $this->token = self::T_Extends; return; } + if($this->attribute == "implements") { $this->token = self::T_Implements; return; } + if($this->attribute == "func") { $this->token = self::T_Func; return; } //if not it's a user defined identifier $this->token = self::T_Identifier;