From: Robert Bradshaw Date: Tue, 15 Dec 2009 02:21:13 +0000 (-0800) Subject: C++ cleanup. X-Git-Tag: 0.13.beta0~353^2~37 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7269d7b6e722ef40cf9c9f470711b2b26da5b5f2;p=cython.git C++ cleanup. --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 1ff7504a..96c251c4 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -3811,20 +3811,13 @@ 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)) self.type_error() return self.type = function.type.return_type - - operators = { - "++": u"__inc__", - "--": u"__dec__", - "*": u"__deref__", - "not": u"__not__" # TODO(danilo): Also handle in NotNode. - } @@ -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 diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 2f28f4e2..32be4c71 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -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 diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 01d8c6af..f536ffb5 100755 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -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