# C type of the result_code expression).
return self.result_ctype or self.type
+ def get_constant_result_code(self):
+ # Return the constant value of this node as a result code
+ # string, or None if the node is not constant.
+ return None
+
def calculate_constant_result(self):
# Calculate the constant result of this expression and store
# it in ``self.constant_result``. Does nothing by default,
def check_const(self):
pass
+ def get_constant_result_code(self):
+ return self.calculate_result_code()
+
def calculate_result_code(self):
return str(self.value)
value = "NULL"
constant_result = 0
+ def get_constant_result_code(self):
+ return self.value
+
class CharNode(ConstNode):
type = PyrexTypes.c_char_type
if self.type.is_pyobject:
self.result_code = code.get_py_num(self.value, self.longness)
else:
- self.result_code = str(self.value) + self.unsigned + self.longness
+ self.result_code = self.get_constant_result_code()
+
+ def get_constant_result_code(self):
+ return str(self.value) + self.unsigned + self.longness
def calculate_result_code(self):
return self.result_code
self.result_code = code.get_py_string_const(self.value)
else:
self.result_code = code.get_string_const(self.value)
+
+ def get_constant_result_code(self):
+ return None # FIXME
def calculate_result_code(self):
return self.result_code
else:
self.result_code = code.get_string_const(self.value)
+ def get_constant_result_code(self):
+ return None
+
def calculate_result_code(self):
return self.result_code
self.dimension.analyse_const_expression(env)
if not self.dimension.type.is_int:
error(self.dimension.pos, "Array dimension not integer")
- size = self.dimension.compile_time_value(env)
+ size = self.dimension.get_constant_result_code()
try:
size = int(size)
except ValueError:
else:
if self.exception_value:
self.exception_value.analyse_const_expression(env)
+ exc_val = self.exception_value.get_constant_result_code()
if self.exception_check == '+':
exc_val_type = self.exception_value.type
if not exc_val_type.is_error and \
not (exc_val_type.is_cfunction and not exc_val_type.return_type.is_pyobject and len(exc_val_type.args)==0):
error(self.exception_value.pos,
"Exception value must be a Python exception or cdef function with no arguments.")
- exc_val = self.exception_value
else:
- exc_val = self.exception_value.compile_time_value(env)
if not return_type.assignable_from(self.exception_value.type):
error(self.exception_value.pos,
- "Exception value incompatible with function return type")
+ "Exception value incompatible with function return type")
exc_check = self.exception_check
if return_type.is_array:
error(self.pos,
if not self.value.type.is_int:
self.value = self.value.coerce_to(PyrexTypes.c_int_type, env)
self.value.analyse_const_expression(env)
- value = self.value.compile_time_value(env)
+ value = self.value.get_constant_result_code()
else:
value = self.name
entry = env.declare_const(self.name, enum_entry.type,
# body StatNode
child_attrs = ['conditions', 'body']
-
+
def generate_execution_code(self, code):
for cond in self.conditions:
code.mark_pos(cond.pos)
- code.putln("case %s:" % cond.calculate_result_code())
+ cond.generate_evaluation_code(code)
+ code.putln("case %s:" % cond.result())
self.body.generate_execution_code(code)
code.putln("break;")
child_attrs = ['test', 'cases', 'else_clause']
def generate_execution_code(self, code):
- code.putln("switch (%s) {" % self.test.calculate_result_code())
+ code.putln("switch (%s) {" % self.test.result())
for case in self.cases:
case.generate_execution_code(code)
if self.else_clause is not None: