Commit 34f0cb9d authored by Hitoshi Yoshida's avatar Hitoshi Yoshida Committed by Commit Bot

CodeGen: Introduce const_ref_t in blink_type_info

const_ref_t provides a type similar to ref_t with its constantness.


Bug: 839389
Change-Id: I4d654a483401fba5885da2cf3214bbe9674a869d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1994549
Commit-Queue: Hitoshi Yoshida <peria@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#730080}
parent d08e75a3
...@@ -47,6 +47,7 @@ def blink_type_info(idl_type): ...@@ -47,6 +47,7 @@ def blink_type_info(idl_type):
member_t: The type of a member variable. E.g. T => Member<T> member_t: The type of a member variable. E.g. T => Member<T>
ref_t: The type of a local variable that references to an already-existing ref_t: The type of a local variable that references to an already-existing
value. E.g. String => String& value. E.g. String => String&
const_ref_t: A const-qualified reference type.
value_t: The type of a variable that behaves as a value. E.g. String => value_t: The type of a variable that behaves as a value. E.g. String =>
String String
is_nullable: True if the Blink implementation type can represent IDL null is_nullable: True if the Blink implementation type can represent IDL null
...@@ -59,6 +60,7 @@ def blink_type_info(idl_type): ...@@ -59,6 +60,7 @@ def blink_type_info(idl_type):
typename, typename,
member_fmt="{}", member_fmt="{}",
ref_fmt="{}", ref_fmt="{}",
const_ref_fmt="{}",
value_fmt="{}", value_fmt="{}",
is_nullable=False): is_nullable=False):
self.member_t = member_fmt.format(typename) self.member_t = member_fmt.format(typename)
...@@ -87,14 +89,19 @@ def blink_type_info(idl_type): ...@@ -87,14 +89,19 @@ def blink_type_info(idl_type):
} }
return TypeInfo(cxx_type[real_type.keyword_typename]) return TypeInfo(cxx_type[real_type.keyword_typename])
if real_type.is_string: if real_type.is_string or real_type.is_enumeration:
return TypeInfo("String", ref_fmt="{}&", is_nullable=True) return TypeInfo(
"String",
ref_fmt="{}&",
const_ref_fmt="const {}&",
is_nullable=True)
if real_type.is_buffer_source_type: if real_type.is_buffer_source_type:
return TypeInfo( return TypeInfo(
'DOM{}'.format(real_type.keyword_typename), 'DOM{}'.format(real_type.keyword_typename),
member_fmt="Member<{}>", member_fmt="Member<{}>",
ref_fmt="{}*", ref_fmt="{}*",
const_ref_fmt="const {}*",
value_fmt="{}*", value_fmt="{}*",
is_nullable=True) is_nullable=True)
...@@ -102,7 +109,11 @@ def blink_type_info(idl_type): ...@@ -102,7 +109,11 @@ def blink_type_info(idl_type):
assert False, "Blink does not support/accept IDL symbol type." assert False, "Blink does not support/accept IDL symbol type."
if real_type.is_any or real_type.is_object: if real_type.is_any or real_type.is_object:
return TypeInfo("ScriptValue", ref_fmt="{}&", is_nullable=True) return TypeInfo(
"ScriptValue",
ref_fmt="{}&",
const_ref_fmt="const {}&",
is_nullable=True)
if real_type.is_void: if real_type.is_void:
assert False, "Blink does not support/accept IDL void type." assert False, "Blink does not support/accept IDL void type."
...@@ -113,6 +124,7 @@ def blink_type_info(idl_type): ...@@ -113,6 +124,7 @@ def blink_type_info(idl_type):
blink_impl_type, blink_impl_type,
member_fmt="Member<{}>", member_fmt="Member<{}>",
ref_fmt="{}*", ref_fmt="{}*",
const_ref_fmt="const {}*",
value_fmt="{}*", value_fmt="{}*",
is_nullable=True) is_nullable=True)
...@@ -120,7 +132,9 @@ def blink_type_info(idl_type): ...@@ -120,7 +132,9 @@ def blink_type_info(idl_type):
or real_type.is_variadic): or real_type.is_variadic):
element_type = blink_type_info(real_type.element_type) element_type = blink_type_info(real_type.element_type)
return TypeInfo( return TypeInfo(
"VectorOf<{}>".format(element_type.value_t), ref_fmt="{}&") "VectorOf<{}>".format(element_type.value_t),
ref_fmt="{}&",
const_ref_fmt="const {}&")
if real_type.is_record: if real_type.is_record:
key_type = blink_type_info(real_type.key_type) key_type = blink_type_info(real_type.key_type)
...@@ -128,10 +142,12 @@ def blink_type_info(idl_type): ...@@ -128,10 +142,12 @@ def blink_type_info(idl_type):
return TypeInfo( return TypeInfo(
"VectorOfPairs<{}, {}>".format(key_type.value_t, "VectorOfPairs<{}, {}>".format(key_type.value_t,
value_type.value_t), value_type.value_t),
ref_fmt="{}&") ref_fmt="{}&",
const_ref_fmt="const {}&")
if real_type.is_promise: if real_type.is_promise:
return TypeInfo("ScriptPromise", ref_fmt="{}&") return TypeInfo(
"ScriptPromise", ref_fmt="{}&", const_ref_fmt="const {}&")
if real_type.is_union: if real_type.is_union:
def_obj = real_type.union_definition_object def_obj = real_type.union_definition_object
...@@ -139,6 +155,7 @@ def blink_type_info(idl_type): ...@@ -139,6 +155,7 @@ def blink_type_info(idl_type):
return TypeInfo( return TypeInfo(
blink_impl_type, blink_impl_type,
ref_fmt="{}&", ref_fmt="{}&",
const_ref_fmt="const {}&",
is_nullable=def_obj.does_include_nullable_type) is_nullable=def_obj.does_include_nullable_type)
if real_type.is_nullable: if real_type.is_nullable:
...@@ -146,7 +163,9 @@ def blink_type_info(idl_type): ...@@ -146,7 +163,9 @@ def blink_type_info(idl_type):
if inner_type.is_nullable: if inner_type.is_nullable:
return inner_type return inner_type
return TypeInfo( return TypeInfo(
"base::Optional<{}>".format(inner_type.value_t), ref_fmt="{}&") "base::Optional<{}>".format(inner_type.value_t),
ref_fmt="{}&",
const_ref_fmt="const {}&")
assert False, "Unknown type: {}".format(idl_type.syntactic_form) assert False, "Unknown type: {}".format(idl_type.syntactic_form)
......
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