getId() -> getMetaId(); Adding support for class id overriding via class_id token

This commit is contained in:
Pavel Shevaev 2023-08-16 14:16:13 +03:00
parent 40fd5cc0a1
commit f93d46ad5e
2 changed files with 48 additions and 27 deletions

View File

@ -1,7 +1,9 @@
<?php
interface mtgType
{}
{
function getName();
}
class mtgTypeRef implements mtgType
{
@ -36,6 +38,14 @@ class mtgTypeRef implements mtgType
}
function getName()
{
if($this->resolved)
return ''.$this->resolved;
else
return $this->name;
}
static function checkAllResolved()
{
while(sizeof(self::$unresolved) > 0)
@ -62,17 +72,14 @@ class mtgTypeRef implements mtgType
function __toString()
{
if($this->resolved)
return ''.$this->resolved;
else
return $this->name;
return $this->getName();
}
}
class mtgMetaInfoUnit
{
public $file;
public $object;
public string $file;
public mtgMetaUnit $object;
function __construct($f, mtgMetaUnit $o)
{
@ -92,10 +99,10 @@ class mtgMetaInfo
function addUnit(mtgMetaInfoUnit $unit)
{
if(isset($this->units[$unit->object->getId()]))
throw new Exception("Meta info unit '{$unit->object->getId()}' already defined in file '{$this->units[$unit->object->getId()]->file}'");
if(isset($this->units[$unit->object->getMetaId()]))
throw new Exception("Meta info unit '{$unit->object->getMetaId()}' already defined in file '{$this->units[$unit->object->getMetaId()]->file}'");
$this->units[$unit->object->getId()] = $unit;
$this->units[$unit->object->getMetaId()] = $unit;
}
function getUnits()
@ -120,7 +127,7 @@ class mtgMetaInfo
abstract class mtgMetaUnit
{
abstract function getId();
abstract function getMetaId();
protected $tokens = array();
@ -159,6 +166,11 @@ class mtgUserType extends mtgMetaUnit implements mtgType
$this->name = $name;
}
function getMetaId()
{
return $this->name;
}
function getName()
{
return $this->name;
@ -169,13 +181,11 @@ class mtgUserType extends mtgMetaUnit implements mtgType
$this->name = $name;
}
function getId()
{
return $this->name;
}
function getClassId()
{
if($this->hasToken('class_id'))
return $this->getToken('class_id');
//TODO: use more flexible schema, maybe get rid of this method
//NOTE: using crc28 actually, leaving some extra reserved space
return crc32($this->name) & 0xFFFFFFF;
@ -353,6 +363,11 @@ class mtgMetaFunc extends mtgMetaUnit implements mtgType
$this->name = $name;
}
function getMetaId()
{
return $this->name;
}
function __toString()
{
$str = "func ";
@ -382,11 +397,6 @@ class mtgMetaFunc extends mtgMetaUnit implements mtgType
return $this->name;
}
function getId()
{
return $this->name;
}
function getArgs()
{
return $this->args;
@ -435,7 +445,7 @@ class mtgMetaRPC extends mtgMetaUnit
$this->tokens = $tokens;
}
function getId()
function getMetaId()
{
return $this->code;
}
@ -593,13 +603,18 @@ class mtgMultiType implements mtgType
return $vals;
}
function __toString()
function getName()
{
$str = '';
foreach($this->getValues() as $val)
$str .= $val . ';';
return $str;
}
function __toString()
{
return $this->getName();
}
}
class mtgArrType implements mtgType
@ -611,11 +626,16 @@ class mtgArrType implements mtgType
$this->value = $value;
}
function __toString()
function getName()
{
return $this->getValue() . '[]';
}
function __toString()
{
return $this->getName();
}
function getValue()
{
return $this->value->resolve();

View File

@ -91,6 +91,7 @@ class mtgMetaInfoParser
if(!isset($config['valid_tokens']))
$config['valid_tokens'] = array();
$config['valid_tokens'][] = 'class_id';
$config['valid_tokens'][] = 'shared_tokens';
$config['valid_tokens'][] = 'enum_override';
}
@ -369,7 +370,7 @@ class mtgMetaInfoParser
// with additional values
if($enum->hasToken('enum_override'))
{
$existing = $this->current_meta->findUnit($enum->getId());
$existing = $this->current_meta->findUnit($enum->getMetaId());
if(!$existing)
throw new Exception("Not found '{$name}' enum to override");
if(!($existing->object instanceof mtgMetaEnum))
@ -718,7 +719,7 @@ class mtgMetaInfoParser
$this->attribute = "";
while($this->_symbol() != '"')
{
if(ord($this->_symbol()) < ord(' ') && ord($this->_symbol()) >= 0)
if(ord($this->_symbol()) < ord(' '))
$this->_error("illegal character in string constant");
if($this->_symbol() == '\\')
{
@ -890,7 +891,7 @@ class mtgMetaParsedModule
function addUnit(mtgMetaInfoUnit $unit)
{
$this->units[$unit->object->getId()] = $unit;
$this->units[$unit->object->getMetaId()] = $unit;
}
function findUnit($id)