Adding initial support for 'implements' and interfaces

This commit is contained in:
Pavel Shevaev 2023-05-23 13:38:16 +03:00
parent 11d26bdb94
commit 68898b4327
2 changed files with 36 additions and 9 deletions

View File

@ -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;

View File

@ -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] = '<interface>';
$this->token_strs[self::T_Prop] = '<@prop>';
$this->token_strs[self::T_Extends] = '<extends>';
$this->token_strs[self::T_Implements] = '<implements>';
$this->token_strs[self::T_Func] = '<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;