Commit 2984ce16 authored by Robert Bradshaw's avatar Robert Bradshaw

public enum

parent 5ac3fb63
...@@ -757,10 +757,23 @@ class CEnumDefNode(StatNode): ...@@ -757,10 +757,23 @@ class CEnumDefNode(StatNode):
item.analyse_declarations(env, self.entry) item.analyse_declarations(env, self.entry)
def analyse_expressions(self, env): def analyse_expressions(self, env):
pass if self.visibility == 'public':
self.temp = env.allocate_temp_pyobject()
env.release_temp(self.temp)
def generate_execution_code(self, code): def generate_execution_code(self, code):
pass if self.visibility == 'public':
for item in self.entry.enum_values:
code.putln("%s = PyInt_FromLong(%s); %s" % (
self.temp,
item.cname,
code.error_goto_if_null(self.temp, item.pos)))
code.putln('if (PyObject_SetAttrString(%s, "%s", %s) < 0) %s' % (
Naming.module_cname,
item.name,
self.temp,
code.error_goto(item.pos)))
code.putln("%s = 0;" % self.temp)
class CEnumDefItemNode(StatNode): class CEnumDefItemNode(StatNode):
......
...@@ -1090,6 +1090,8 @@ def p_for_bounds(s): ...@@ -1090,6 +1090,8 @@ def p_for_bounds(s):
'relation2': rel2, 'relation2': rel2,
'bound2': bound2, 'bound2': bound2,
'step': step } 'step': step }
else:
s.error("Expected 'in' or 'from'")
def p_for_from_relation(s): def p_for_from_relation(s):
if s.sy in inequality_relations: if s.sy in inequality_relations:
......
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