Commit 710360fe authored by Robert Bradshaw's avatar Robert Bradshaw

Sage compiles.

parent ccc84a3f
......@@ -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)
......
......@@ -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,
......
......@@ -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
......
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