C++ cleanup.
authorRobert Bradshaw <robertwb@math.washington.edu>
Tue, 15 Dec 2009 02:21:13 +0000 (18:21 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Tue, 15 Dec 2009 02:21:13 +0000 (18:21 -0800)
Cython/Compiler/ExprNodes.py
Cython/Compiler/ModuleNode.py
Cython/Compiler/PyrexTypes.py

index 1ff7504a7d4225046f1e33a09c38d0e42ed9b382..96c251c43e76c10aa20eac70cc8a141438d2539e 100755 (executable)
@@ -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 
index 2f28f4e2446b41884b208e29237929ba017ad595..32be4c715e26ea1f2c0345ffdc7960d0f949cf10 100644 (file)
@@ -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
index 01d8c6af6dfb234e76060bbc1afb4f9856c65220..f536ffb5df0fdbf429e09c3cc17a80d6a951fc33 100755 (executable)
@@ -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