From f7d46752cfc920359dea113ef6f2555db1bfd3a9 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Tue, 9 Jun 2009 12:10:47 -0400 Subject: [PATCH] compile: New function is_valid_variable Used to improve ensure_var and compile_expr. Signed-off-by: Jean Privat --- src/compiling/compiling_methods.nit | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/compiling/compiling_methods.nit b/src/compiling/compiling_methods.nit index 3e20f95..6ec048a 100644 --- a/src/compiling/compiling_methods.nit +++ b/src/compiling/compiling_methods.nit @@ -38,7 +38,7 @@ redef class CompilerVisitor var i = cfc._variable_index var s = n.compile_expr(self) cfc._variable_index = i - if s[0] == ' ' then + if s[0] == ' ' or cfc.is_valid_variable(s) then return s end var v = cfc.get_var("Result for expr {n.locate}") @@ -49,7 +49,8 @@ redef class CompilerVisitor # Ensure that a c expression is a var meth ensure_var(s: String, comment: String): String do - if s.substring(0,3) == "variable" then + if cfc.is_valid_variable(s) then + add_instr("/* Ensure var {s}: {comment}*/") return s end var v = cfc.get_var(null) @@ -235,6 +236,15 @@ class CFunctionContext end end + # Is s a valid variable + protected meth is_valid_variable(s: String): Bool + do + for i in [0.._variable_index[ do + if s == variable(i) then return true + end + return false + end + # Mark the variable available meth free_var(v: String) do -- 1.7.9.5