Fix logic fail and unsets in DefineConstant()
If we infer the type, then we already know its integer type ID. Trying to then parse that type leads to "Undefined type" errors (but it still functions due to the fallthrough). This diff skips trying to parse a known type and thus avoids the misleading error message. Also guard against missing funcs/consts elements in global scope and classes.
Esse commit está contido em:
+13
-8
@@ -280,12 +280,13 @@ function idl_infer_type($v) {
|
||||
|
||||
function DefineConstant($const) {
|
||||
global $constants, $classes, $current_class;
|
||||
|
||||
if (!isset($const['type']) && array_key_exists('value', $const)) {
|
||||
$const['type'] = idl_infer_type($const['value']);
|
||||
} else {
|
||||
$const['type'] = idl_parse_type($const['type']);
|
||||
}
|
||||
|
||||
$const['type'] = idl_parse_type($const['type']);
|
||||
|
||||
if (empty($current_class)) {
|
||||
$constants[] = $const;
|
||||
} else {
|
||||
@@ -370,17 +371,21 @@ function DefineFunction($func) {
|
||||
function ReadIDLFile($path) {
|
||||
$entries = json_decode(file_get_contents($path), /* use arrays */ true);
|
||||
|
||||
foreach ($entries['funcs'] as $func) {
|
||||
DefineFunction($func);
|
||||
if (!empty($entries['funcs'])) {
|
||||
foreach ($entries['funcs'] as $func) {
|
||||
DefineFunction($func);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($entries['consts'] as $const) {
|
||||
DefineConstant($const);
|
||||
if (!empty($entries['consts'])) {
|
||||
foreach ($entries['consts'] as $const) {
|
||||
DefineConstant($const);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($entries['classes'] as $class) {
|
||||
$methods = $class['funcs'];
|
||||
$consts = $class['consts'];
|
||||
$methods = isset($class['funcs']) ? $class['funcs'] : array();
|
||||
$consts = isset($class['consts']) ? $class['consts'] : array();
|
||||
unset($class['funcs']);
|
||||
unset($class['consts']);
|
||||
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário