Commit 7269d7b6 authored by Robert Bradshaw's avatar Robert Bradshaw

C++ cleanup.

parent 44adaf70
......@@ -3811,7 +3811,7 @@ class UnopNode(ExprNode):
if type.is_ptr:
type = type.base_type
entry = env.lookup(type.name)
function = entry.type.scope.lookup(self.operators[self.operator])
function = entry.type.scope.lookup("operator%s" % self.operator)
if not function:
error(self.pos, "'%s' operator not defined for %s"
% (self.operator, type))
......@@ -3819,13 +3819,6 @@ class UnopNode(ExprNode):
return
self.type = function.type.return_type
operators = {
"++": u"__inc__",
"--": u"__dec__",
"*": u"__deref__",
"not": u"__not__" # TODO(danilo): Also handle in NotNode.
}
class NotNode(ExprNode):
......@@ -4347,21 +4340,6 @@ class NumBinopNode(BinopNode):
"**": "PyNumber_Power"
}
operators = {
"+": u"__add__",
"-": u"__sub__",
"*": u"__mul__",
"/": u"__div__",
"%": u"__mod__",
"<<": u"__lshift__",
">>": u"__rshift__",
"&": u"__and__",
"|": u"__or__",
"^": u"__xor__",
}
class IntBinopNode(NumBinopNode):
# Binary operation taking integer arguments.
......@@ -5001,7 +4979,7 @@ class PrimaryCmpNode(NewTempExprNode, CmpNode):
if type2.is_ptr:
type2 = type2.base_type
entry = env.lookup(type1.name)
function = entry.type.scope.lookup(self.operators[self.operator])
function = entry.type.scope.lookup("operator%s" % self.operator)
if not function:
error(self.pos, "'%s' operator not defined for '%s %s %s'"
% (self.operator, type1, self.operator, type2))
......@@ -5113,16 +5091,6 @@ class PrimaryCmpNode(NewTempExprNode, CmpNode):
if self.cascade:
self.cascade.annotate(code)
operators = {
"<": u"__le__",
">": u"__gt__",
"==": u"__eq__",
"<=": u"__le__",
">=": u"__ge__",
"!=": u"__ne__",
"<>": u"__ne__"
}
class CascadedCmpNode(Node, CmpNode):
# A CascadedCmpNode is not a complete expression node. It
......
......@@ -390,8 +390,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_typedef(entry, code)
elif type.is_struct_or_union:
self.generate_struct_union_definition(entry, code)
elif type.is_cpp_class:
self.generate_cpp_class_definition(entry, code)
elif type.is_enum:
self.generate_enum_definition(entry, code)
elif type.is_extension_type and entry not in vtabslot_entries:
......@@ -639,8 +637,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_typedef(entry, code)
elif type.is_struct_or_union:
self.generate_struct_union_definition(entry, code)
elif type.is_cpp_class:
self.generate_cpp_class_definition(entry, code)
elif type.is_enum:
self.generate_enum_definition(entry, code)
elif type.is_extension_type:
......@@ -707,35 +703,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("#pragma pack(pop)")
code.putln("#endif")
def generate_cpp_class_definition(self, entry, code):
code.mark_pos(entry.pos)
type = entry.type
scope = type.scope
if scope:
kind = type.kind
packed = type.is_cpp_class and type.packed
if packed:
kind = "%s %s" % (type.kind, "__Pyx_PACKED")
code.globalstate.use_utility_code(packed_struct_utility_code)
header, footer = \
self.sue_header_footer(type, kind, type.cname)
code.putln("")
if packed:
code.putln("#if !defined(__GNUC__)")
code.putln("#pragma pack(push, 1)")
code.putln("#endif")
code.putln(header)
var_entries = scope.var_entries
for attr in var_entries:
code.putln(
"%s;" %
attr.type.declaration_code(attr.cname))
code.putln(footer)
if packed:
code.putln("#if !defined(__GNUC__)")
code.putln("#pragma pack(pop)")
code.putln("#endif")
def generate_enum_definition(self, entry, code):
code.mark_pos(entry.pos)
type = entry.type
......
......@@ -1825,6 +1825,9 @@ def best_match(args, functions, pos):
error_str = "Call with wrong number of arguments (expected %s, got %s)" \
% (expectation, actual_nargs)
continue
if len(functions) == 1:
# Optimize the most common case of no overloading...
return func
score = [0,0,0]
for i in range(min(len(args), len(func_type.args))):
src_type = args[i].type
......
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