Commit dc8be518 authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

IDL compiler: Forbid nullable dictionary as argument and dict member

IDL nullable dictionaries are forbidden as argument type and
dictionary member type.  Adds a validator of the rule.

Bug: 997708
Change-Id: I4b3f922ac77c8c6de949b7098b5096759c83f00b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2379337Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802541}
parent 6753c40b
......@@ -2,10 +2,13 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import itertools
from .ir_map import IRMap
def validate_after_resolve_references(ir_map):
_validate_forbidden_nullable_dictionary_type(ir_map)
_validate_literal_constant_type(ir_map)
......@@ -14,8 +17,9 @@ def _all_constants(ir_map):
irs = ir_map.irs_of_kinds(IRMap.IR.Kind.CALLBACK_INTERFACE,
IRMap.IR.Kind.INTERFACE, IRMap.IR.Kind.NAMESPACE)
for ir in irs:
accumulated.extend(ir.constants)
return accumulated
if ir.constants:
accumulated.append(ir.constants)
return itertools.chain(*accumulated)
def _all_function_likes(ir_map):
......@@ -23,11 +27,34 @@ def _all_function_likes(ir_map):
irs = ir_map.irs_of_kinds(IRMap.IR.Kind.CALLBACK_INTERFACE,
IRMap.IR.Kind.INTERFACE, IRMap.IR.Kind.NAMESPACE)
for ir in irs:
accumulated.extend(ir.constructors)
accumulated.extend(ir.named_constructors)
accumulated.extend(ir.operations)
accumulated.extend(ir_map.irs_of_kinds(IRMap.IR.Kind.CALLBACK_FUNCTION))
return accumulated
if ir.constructors:
accumulated.append(ir.constructors)
if ir.named_constructors:
accumulated.append(ir.named_constructors)
if ir.operations:
accumulated.append(ir.operations)
accumulated.append(ir_map.irs_of_kinds(IRMap.IR.Kind.CALLBACK_FUNCTION))
return itertools.chain(*accumulated)
def _validate_forbidden_nullable_dictionary_type(ir_map):
for function in _all_function_likes(ir_map):
for argument in function.arguments:
assert (not (argument.idl_type.is_nullable
and argument.idl_type.unwrap().is_dictionary)
), ("{}: {}, {}: Nullable dictionary type is forbidden as "
"an argument type.".format(
function.debug_info.location, function.identifier,
argument.identifier))
for dictionary in ir_map.irs_of_kind(IRMap.IR.Kind.DICTIONARY):
for dict_member in dictionary.own_members:
assert (not (dict_member.idl_type.is_nullable
and dict_member.idl_type.unwrap().is_dictionary)
), ("{}: {}, {}: Nullable dictionary type is forbidden as "
"a dictionary member type.".format(
dict_member.debug_info.location,
dictionary.identifier, dict_member.identifier))
def _validate_literal_constant_type(ir_map):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment