From 710360fe24736a57e1f2bbf93aedeb4171716650 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Fri, 8 Aug 2008 01:46:23 -0700 Subject: [PATCH] Sage compiles. --- Cython/Compiler/Nodes.py | 2 +- Cython/Compiler/Optimize.py | 4 +++- Cython/Compiler/Symtab.py | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index a17463a9..5d43e81f 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -771,7 +771,7 @@ class CEnumDefItemNode(StatNode): else: value = self.name entry = env.declare_const(self.name, enum_entry.type, - value, self.pos, cname = self.cname) + value, self.pos, cname = self.cname, visibility = enum_entry.visibility) enum_entry.enum_values.append(entry) diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index eb4195a1..6036a5ad 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -22,7 +22,7 @@ class SwitchTransform(Visitor.VisitorTransform): """ This transformation tries to turn long if statements into C switch statements. The requirement is that every clause be an (or of) var == value, where the var - is common among all clauses and both var and value are not Python objects. + is common among all clauses and both var and value are ints. """ def extract_conditions(self, cond): @@ -66,6 +66,8 @@ class SwitchTransform(Visitor.VisitorTransform): return node elif common_var is not None and not is_common_value(var, common_var): return node + elif not var.type.is_int or sum([not cond.type.is_int for cond in conditions]): + return node else: common_var = var cases.append(Nodes.SwitchCaseNode(pos = if_clause.pos, diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 69b12d79..062ba696 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -286,14 +286,14 @@ class Scope: def qualify_name(self, name): return "%s.%s" % (self.qualified_name, name) - def declare_const(self, name, type, value, pos, cname = None): + def declare_const(self, name, type, value, pos, cname = None, visibility = 'private'): # Add an entry for a named constant. if not cname: if self.in_cinclude: cname = name else: cname = self.mangle(Naming.enum_prefix, name) - entry = self.declare(name, cname, type, pos, 'private') + entry = self.declare(name, cname, type, pos, visibility) entry.is_const = 1 entry.value = value return entry -- 2.26.2