From b37765c34f7abbc97a6ee7ac77e890e52d83d5c0 Mon Sep 17 00:00:00 2001 From: MatheusAN <matheus.agio@hotmail.com> Date: Fri, 24 Jun 2016 10:35:35 -0300 Subject: [PATCH] verifying function return --- verificadorTipos.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/verificadorTipos.rb b/verificadorTipos.rb index e8c2072..4e35c8b 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 && -- GitLab