Skip to content

Commit

Permalink
Merge pull request #307 from EPashkin/nullable_for_error_result
Browse files Browse the repository at this point in the history
Apply configured return.nullable to out parameters
  • Loading branch information
EPashkin committed Jan 18, 2017
2 parents 1644ef1 + 1ec7e91 commit 0b20667
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/analysis/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn analyze_function(env: &Env, name: String, func: &library::Function, type_tid:
}
}

let (outs, unsupported_outs) = out_parameters::analyze(env, func);
let (outs, unsupported_outs) = out_parameters::analyze(env, func, configured_functions);
if unsupported_outs {
warn!("Function {} has unsupported outs", func.c_identifier.as_ref().unwrap_or(&func.name));
commented = true;
Expand Down
14 changes: 12 additions & 2 deletions src/analysis/out_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::vec::Vec;

use analysis::imports::Imports;
use analysis::ref_mode::RefMode;
use config;
use env::Env;
use library::*;
use super::conversion_type::ConversionType;
Expand Down Expand Up @@ -44,7 +45,8 @@ impl Info {
}
}

pub fn analyze(env: &Env, func: &Function) -> (Info, bool) {
pub fn analyze(env: &Env, func: &Function,
configured_functions: &[&config::functions::Function]) -> (Info, bool) {
let mut info: Info = Default::default();
let mut unsupported_outs = false;

Expand Down Expand Up @@ -72,7 +74,15 @@ pub fn analyze(env: &Env, func: &Function) -> (Info, bool) {
info.mode = Mode::None;
}
if info.mode == Mode::Combined || info.mode == Mode::Throws(true) {
info.params.insert(0, func.ret.clone());
let mut ret = func.ret.clone();
//TODO: switch to use analyzed returns (it add too many Return<Option<>>)
let nullable_override = configured_functions.iter()
.filter_map(|f| f.ret.nullable)
.next();
if let Some(val) = nullable_override {
ret.nullable = val;
}
info.params.insert(0, ret);
}

(info, unsupported_outs)
Expand Down

0 comments on commit 0b20667

Please sign in to comment.