diff --git a/verificadorTipos.rb b/verificadorTipos.rb index e8c20724fc0449ca4f6b54b785b29832a64be611..4e35c8bd2f5bbf5a379805c4d09c3ec6764862d3 100644 --- a/verificadorTipos.rb +++ b/verificadorTipos.rb @@ -28,6 +28,8 @@ class VerificadorTipos return nil if attr_check(@current_elements).nil? elsif incr?(@current_elements) return nil if incr_check(@current_elements).nil? + elsif return?(@current_elements) + return nil if check_return(@current_elements).nil? end @current_elements = [] else @@ -38,6 +40,14 @@ class VerificadorTipos private + def check_return(elements) + id = elements[1][:token] + id_entry = get_entry(id) + return nil if id_entry.nil? + return nil if id_entry.type != @function_return_type + true + end + def incr_check(elements) id = elements[0][:token] id_entry = get_entry(id) @@ -99,7 +109,7 @@ class VerificadorTipos type = token[:type] type =~ types || type =~ num_types || type == 'id' || type == 'attr' || type == 'op_art' || type =~ increment || type == 'const' || - type == 'function' + type == 'function' || type == 'return' end def add_var(elements) @@ -122,6 +132,7 @@ class VerificadorTipos def add_function(elements) id = elements[2][:token] return nil if @global.key? id + @function_return_type = elements[1][:type] @global[id] = Entry.new('function', elements[1][:type]) end @@ -137,6 +148,13 @@ class VerificadorTipos /^(num_float|num_int)$/ end + def return?(elements) + return false if elements.size < 2 + return true if elements[0][:type] == 'return' && + elements[1][:type] == 'id' + false + end + def decl_var?(elements) return false if elements.size < 2 return true if elements[0][:type] =~ types &&