Skip to content

Commit

Permalink
review comments -wip
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-sheets committed Mar 6, 2023
1 parent decd8e2 commit e6a92a6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 36 deletions.
2 changes: 1 addition & 1 deletion data/error_policies/call_casting.cas
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ domain asd {
asd<boo>.read_boo_tmp(this); // Function is not castable
asd<boo>.read_boo_tmp_again(this); // Function is not castable
asd<boo>.read_boo_tmp_more(this); // Function is not castable
asd<boo>.some_function(foo); // TODO this should break?
asd<boo>.some_function(foo);
}

virtual resource tmp {
Expand Down
87 changes: 52 additions & 35 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::convert::TryFrom;
use std::ops::Range;

use crate::ast::{
Argument, CascadeString, Declaration, Expression, FuncCall, LetBinding, Machine, Module,
PolicyFile, Statement,
get_cil_name, Argument, CascadeString, Declaration, Expression, FuncCall, LetBinding, Machine,
Module, PolicyFile, Statement,
};
use crate::constants;
use crate::context::{BindableObject, BlockType, Context as BlockContext};
Expand Down Expand Up @@ -510,23 +510,21 @@ pub fn determine_castable(functions: &mut FunctionMap, types: &TypeMap) -> u64 {
func.is_castable = false;
continue 'outer;
}
// The call may be a built-in so check the args
} else {
for arg in &call.args {
if let Argument::Var(arg) = &arg.0 {
// Need to special case this.*
if arg.to_string().contains("this.") {
}
for arg in &call.args {
if let Argument::Var(arg) = &arg.0 {
// Need to special case this.*
if arg.to_string().contains("this.") {
num_changed += 1;
func.is_castable = false;
continue 'outer;
}
if let Some(ti) = types.get(arg.as_ref()) {
if ti.is_associated_resource(types) {
num_changed += 1;
func.is_castable = false;
continue 'outer;
}
if let Some(ti) = types.get(arg.as_ref()) {
if ti.is_associated_resource(types) {
num_changed += 1;
func.is_castable = false;
continue 'outer;
}
}
}
}
}
Expand All @@ -546,15 +544,24 @@ pub fn initialize_terminated<'a>(
let mut is_term = true;

for call in func.original_body {
if let Statement::Call(call) = call {
match call.check_builtin() {
match call {
Statement::Call(call) => match call.check_builtin() {
Some(_) => {
continue;
}
None => {
is_term = false;
break;
}
},
Statement::LetBinding(_) => {
continue;
}
Statement::IfBlock(_) => {
continue;
}
Statement::OptionalBlock(_) => {
continue;
}
}
}
Expand All @@ -576,29 +583,39 @@ pub fn search_for_recursion(
while removed > 0 {
removed = 0;
for func in functions.clone().iter_mut() {
let mut is_term = true;
let mut is_term = false;
for call in func.original_body {
if let Statement::Call(call) = call {
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 let Some(class) = func.class {
call_cil_name =
call_cil_name.replace("this-", &(class.name.to_string() + "-"))
} else {
return Err(CascadeErrors::from(ErrorItem::make_compile_or_internal_error(
"Could not determine class for 'this.' function call",
Some(func.declaration_file),
call.get_name_range(),
"Perhaps you meant to place the function in a resource or domain?")));
match call {
Statement::Call(call) => {
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 let FunctionClass::Type(class) = func.class {
call_cil_name = get_cil_name(Some(&class.name), &call.name)
} else {
return Err(CascadeErrors::from(ErrorItem::make_compile_or_internal_error(
"Could not determine class for 'this.' function call",
Some(func.declaration_file),
call.get_name_range(),
"Perhaps you meant to place the function in a resource or domain?")));
}
}
}

if terminated_list.contains(&call_cil_name) {
if terminated_list.contains(&call_cil_name) {
is_term = true;
break;
}
}
Statement::LetBinding(_) => {
continue;
}
Statement::IfBlock(_) => {
continue;
}
Statement::OptionalBlock(_) => {
continue;
}
is_term = false;
}
}
if is_term {
Expand Down
2 changes: 2 additions & 0 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,8 @@ pub struct FunctionInfo<'a> {
pub declaration_file: &'a SimpleFile<String, String>,
pub is_associated_call: bool,
pub is_derived: bool,
// This will be initialized to true and prevalidate_functions will set this
// to false if needed.
pub is_castable: bool,
decl: Option<&'a FuncDecl>,
}
Expand Down

0 comments on commit e6a92a6

Please sign in to comment.