Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-sheets committed Mar 16, 2023
1 parent 39bbcf3 commit e70e8c4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 41 deletions.
2 changes: 2 additions & 0 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ impl Statement {

// The function will take a vector of statements and reduce them down
// to only their function calls.
// Note: This will expand out all possible function calls regardless
// of boolean & optional block state.
pub fn get_all_func_calls(statements: Vec<Statement>) -> Vec<FuncCall> {
let mut ret_vec: Vec<FuncCall> = Vec::new();
for call in statements {
Expand Down
16 changes: 0 additions & 16 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,22 +489,6 @@ pub fn prevalidate_functions(

let (mut terminated_functions, mut nonterm_functions) = initialize_terminated(functions);

if terminated_functions.is_empty() && !nonterm_functions.is_empty() {
let mut error: Option<CompileError> = None;

for func in functions.values() {
error = Some(add_or_create_compile_error(
error,
"No terminating call found",
func.declaration_file,
func.get_declaration_range().unwrap_or_default(),
"All function calls found in possible recursive loop",
));
}
// Unwrap is safe since we need to go through the loop above at least once
return Err(CascadeErrors::from(error.unwrap()));
}

search_for_recursion(&mut terminated_functions, &mut nonterm_functions, functions)?;

Ok(())
Expand Down
37 changes: 12 additions & 25 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,8 @@ fn validate_cast(
// Initial type we are casting from
start_type: &CascadeString,
// Type Info for what we are casting to
// If cast_ti is Some() func_call and func_info
// must also be Some()
cast_ti: Option<&TypeInfo>,
// Function call we are trying to use
// the cast version of a function.
Expand Down Expand Up @@ -1876,18 +1878,8 @@ fn validate_cast(
Ok(())
}
}
(Some(_), Some(_), None) => Err(ErrorItem::make_compile_or_internal_error(
"Func Call was given with no Func Info",
file,
None,
"If you are casting a function you must provide both the call and it's info",
)),
(Some(_), None, Some(_)) => Err(ErrorItem::make_compile_or_internal_error(
"Func Info was given with no Func Call",
file,
None,
"If you are casting a function you must provide both the call and it's info",
)),
(Some(_), Some(_), None) => Err(ErrorItem::Internal(InternalError::new())),
(Some(_), None, Some(_)) => Err(ErrorItem::Internal(InternalError::new())),
(None, _, _) => Err(err_ret(start_type.get_range())),
(_, _, _) => Ok(()),
}
Expand Down Expand Up @@ -2775,14 +2767,9 @@ pub fn initialize_terminated<'a>(functions: &'a FunctionMap<'a>) -> (Vec<String>
let func_calls = get_all_func_calls(func.original_body.to_vec());

for call in func_calls {
match call.check_builtin() {
Some(_) => {
continue;
}
None => {
is_term = false;
break;
}
if call.check_builtin().is_none() {
is_term = false;
break;
}
}
if is_term {
Expand All @@ -2804,14 +2791,14 @@ pub fn search_for_recursion(
while removed > 0 {
removed = 0;
for func in functions.clone().iter() {
let mut is_term = false;
let mut is_term = true;
if let Some(function_info) = function_map.get(func) {
let func_calls = get_all_func_calls(function_info.original_body.to_vec());
for call in func_calls {
let mut call_cil_name = call.get_cil_name();
// If we are calling something with this it must be in the same class
// so hand place the class name
if call_cil_name.contains("this-") {
if call.class_name.as_ref() == Some(&CascadeString::from("this")) {
if let FunctionClass::Type(class) = function_info.class {
call_cil_name = get_cil_name(Some(&class.name), &call.name)
} else {
Expand All @@ -2826,8 +2813,8 @@ pub fn search_for_recursion(
}
}

if terminated_list.contains(&call_cil_name) {
is_term = true;
if !terminated_list.contains(&call_cil_name) {
is_term = false;
break;
}
}
Expand All @@ -2854,7 +2841,7 @@ pub fn search_for_recursion(
"Recursive Function call found",
function_info.declaration_file,
function_info.get_declaration_range().unwrap_or_default(),
"Calls cannot recursively call each other",
"These calls have been found in a recursive loop. There may be more than one recursive loop.",
));
}
}
Expand Down

0 comments on commit e70e8c4

Please sign in to comment.