Commit 9a0983ec authored by Stefan Behnel's avatar Stefan Behnel

remove "is_reference" flags from C++ class type added in last pull request

parent 24992169
...@@ -2868,11 +2868,10 @@ class IndexNode(ExprNode): ...@@ -2868,11 +2868,10 @@ class IndexNode(ExprNode):
else: else:
template_values = [self.index] template_values = [self.index]
type_node = Nodes.TemplatedTypeNode( type_node = Nodes.TemplatedTypeNode(
pos = self.pos, pos=self.pos,
positional_args = template_values, positional_args=template_values,
keyword_args = None, keyword_args=None)
is_reference = False) return type_node.analyse(env, base_type=base_type)
return type_node.analyse(env, base_type = base_type)
else: else:
index = self.index.compile_time_value(env) index = self.index.compile_time_value(env)
if index is not None: if index is not None:
...@@ -11377,11 +11376,6 @@ class CoerceFromPyTypeNode(CoercionNode): ...@@ -11377,11 +11376,6 @@ class CoerceFromPyTypeNode(CoercionNode):
if not result_type.create_from_py_utility_code(env): if not result_type.create_from_py_utility_code(env):
error(arg.pos, error(arg.pos,
"Cannot convert Python object to '%s'" % result_type) "Cannot convert Python object to '%s'" % result_type)
elif result_type.is_reference:
warning(arg.pos,
"Cannot pass Python object as C++ data structure "
"reference (%s &), will pass by copy." % result_type,
level=1)
if self.type.is_string or self.type.is_pyunicode_ptr: if self.type.is_string or self.type.is_pyunicode_ptr:
if self.arg.is_name and self.arg.entry and self.arg.entry.is_pyglobal: if self.arg.is_name and self.arg.entry and self.arg.entry.is_pyglobal:
warning(arg.pos, warning(arg.pos,
......
...@@ -1110,7 +1110,7 @@ class TemplatedTypeNode(CBaseTypeNode): ...@@ -1110,7 +1110,7 @@ class TemplatedTypeNode(CBaseTypeNode):
error(template_node.pos, "unknown type in template argument") error(template_node.pos, "unknown type in template argument")
return error_type return error_type
template_types.append(type) template_types.append(type)
self.type = base_type.specialize_here(self.pos, template_types, is_reference=self.is_reference) self.type = base_type.specialize_here(self.pos, template_types)
elif base_type.is_pyobject: elif base_type.is_pyobject:
# Buffer # Buffer
......
...@@ -2168,8 +2168,7 @@ def p_buffer_or_template(s, base_type_node, templates): ...@@ -2168,8 +2168,7 @@ def p_buffer_or_template(s, base_type_node, templates):
result = Nodes.TemplatedTypeNode(pos, result = Nodes.TemplatedTypeNode(pos,
positional_args = positional_args, positional_args = positional_args,
keyword_args = keyword_dict, keyword_args = keyword_dict,
base_type_node = base_type_node, base_type_node = base_type_node)
is_reference = (s.sy == '&'))
return result return result
def p_bracketed_base_type(s, base_type_node, nonempty, empty): def p_bracketed_base_type(s, base_type_node, nonempty, empty):
......
...@@ -3198,6 +3198,7 @@ builtin_cpp_conversions = ("std::pair", ...@@ -3198,6 +3198,7 @@ builtin_cpp_conversions = ("std::pair",
"std::set", "std::unordered_set", "std::set", "std::unordered_set",
"std::map", "std::unordered_map") "std::map", "std::unordered_map")
class CppClassType(CType): class CppClassType(CType):
# name string # name string
# cname string # cname string
...@@ -3216,7 +3217,7 @@ class CppClassType(CType): ...@@ -3216,7 +3217,7 @@ class CppClassType(CType):
subtypes = ['templates'] subtypes = ['templates']
def __init__(self, name, scope, cname, base_classes, templates = None, template_type = None, is_reference = False): def __init__(self, name, scope, cname, base_classes, templates=None, template_type=None):
self.name = name self.name = name
self.cname = cname self.cname = cname
self.scope = scope self.scope = scope
...@@ -3226,7 +3227,6 @@ class CppClassType(CType): ...@@ -3226,7 +3227,6 @@ class CppClassType(CType):
self.template_type = template_type self.template_type = template_type
self.specializations = {} self.specializations = {}
self.is_cpp_string = cname in cpp_string_conversions self.is_cpp_string = cname in cpp_string_conversions
self.is_reference = is_reference
def use_conversion_utility(self, from_or_to): def use_conversion_utility(self, from_or_to):
pass pass
...@@ -3350,7 +3350,7 @@ class CppClassType(CType): ...@@ -3350,7 +3350,7 @@ class CppClassType(CType):
T.get_fused_types(result, seen) T.get_fused_types(result, seen)
return result return result
def specialize_here(self, pos, template_values = None, is_reference = False): def specialize_here(self, pos, template_values=None):
if not self.is_template_type(): if not self.is_template_type():
error(pos, "'%s' type is not a template" % self) error(pos, "'%s' type is not a template" % self)
return error_type return error_type
...@@ -3366,19 +3366,19 @@ class CppClassType(CType): ...@@ -3366,19 +3366,19 @@ class CppClassType(CType):
"Python object type '%s' cannot be used as a template argument" % value) "Python object type '%s' cannot be used as a template argument" % value)
if has_object_template_param: if has_object_template_param:
return error_type return error_type
return self.specialize(dict(zip(self.templates, template_values)), is_reference) return self.specialize(dict(zip(self.templates, template_values)))
def specialize(self, values, is_reference = False): def specialize(self, values):
if not self.templates and not self.namespace: if not self.templates and not self.namespace:
return self return self
if self.templates is None: if self.templates is None:
self.templates = [] self.templates = []
key = tuple(values.items()) + (is_reference,) key = tuple(values.items())
if key in self.specializations: if key in self.specializations:
return self.specializations[key] return self.specializations[key]
template_values = [t.specialize(values) for t in self.templates] template_values = [t.specialize(values) for t in self.templates]
specialized = self.specializations[key] = \ specialized = self.specializations[key] = \
CppClassType(self.name, None, self.cname, [], template_values, template_type=self, is_reference=is_reference) CppClassType(self.name, None, self.cname, [], template_values, template_type=self)
# Need to do these *after* self.specializations[key] is set # Need to do these *after* self.specializations[key] is set
# to avoid infinite recursion on circular references. # to avoid infinite recursion on circular references.
specialized.base_classes = [b.specialize(values) for b in self.base_classes] specialized.base_classes = [b.specialize(values) for b in self.base_classes]
...@@ -3394,7 +3394,8 @@ class CppClassType(CType): ...@@ -3394,7 +3394,8 @@ class CppClassType(CType):
elif self.empty_declaration_code() == actual.template_type.empty_declaration_code(): elif self.empty_declaration_code() == actual.template_type.empty_declaration_code():
return reduce( return reduce(
merge_template_deductions, merge_template_deductions,
[formal_param.deduce_template_params(actual_param) for (formal_param, actual_param) in zip(self.templates, actual.templates)], [formal_param.deduce_template_params(actual_param)
for (formal_param, actual_param) in zip(self.templates, actual.templates)],
{}) {})
else: else:
return None return None
......
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