add functions to blueprints
This commit is contained in:
parent
622b0d51b0
commit
87d657593a
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,6 @@
|
|||
pub mod definitions;
|
||||
pub mod error;
|
||||
pub mod function;
|
||||
pub mod parameter;
|
||||
pub mod schema;
|
||||
pub mod validator;
|
||||
|
@ -8,6 +9,7 @@ use crate::{config::Config, module::CheckedModules};
|
|||
use aiken_lang::gen_uplc::CodeGenerator;
|
||||
use definitions::Definitions;
|
||||
use error::Error;
|
||||
use function::Function;
|
||||
use schema::{Annotated, Schema};
|
||||
use std::fmt::Debug;
|
||||
use validator::Validator;
|
||||
|
@ -18,6 +20,7 @@ pub struct Blueprint {
|
|||
pub validators: Vec<Validator>,
|
||||
#[serde(skip_serializing_if = "Definitions::is_empty", default)]
|
||||
pub definitions: Definitions<Annotated<Schema>>,
|
||||
pub functions: Vec<Function>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
|
||||
|
@ -75,9 +78,19 @@ impl Blueprint {
|
|||
})
|
||||
.collect();
|
||||
|
||||
let functions: Result<Vec<_>, Error> = modules
|
||||
.functions()
|
||||
.map(|(func, def)| {
|
||||
let mut f = Function::from_checked_module(modules, generator, func, def)?;
|
||||
definitions.merge(&mut f.definitions);
|
||||
f.definitions = Definitions::new();
|
||||
Ok(f)
|
||||
})
|
||||
.collect();
|
||||
Ok(Blueprint {
|
||||
preamble,
|
||||
validators: validators?,
|
||||
functions: functions?,
|
||||
definitions,
|
||||
})
|
||||
}
|
||||
|
@ -159,6 +172,7 @@ mod tests {
|
|||
},
|
||||
validators: vec![],
|
||||
definitions: Definitions::new(),
|
||||
functions: vec![],
|
||||
};
|
||||
assert_eq!(
|
||||
serde_json::to_value(&blueprint).unwrap(),
|
||||
|
@ -186,6 +200,7 @@ mod tests {
|
|||
},
|
||||
validators: vec![],
|
||||
definitions: Definitions::new(),
|
||||
functions: vec![],
|
||||
};
|
||||
assert_eq!(
|
||||
serde_json::to_value(&blueprint).unwrap(),
|
||||
|
@ -237,6 +252,7 @@ mod tests {
|
|||
},
|
||||
validators: vec![],
|
||||
definitions,
|
||||
functions: vec![],
|
||||
};
|
||||
assert_eq!(
|
||||
serde_json::to_value(&blueprint).unwrap(),
|
||||
|
|
|
@ -286,6 +286,29 @@ impl CheckedModules {
|
|||
items.into_iter()
|
||||
}
|
||||
|
||||
pub fn functions(&self) -> impl Iterator<Item = (&CheckedModule, &TypedFunction)> {
|
||||
let mut items = vec![];
|
||||
|
||||
for validator_module in self.0.values() {
|
||||
for some_definition in validator_module.ast.definitions() {
|
||||
if let Definition::Fn(def) = some_definition {
|
||||
if let Some(doc) = def.doc.clone() {
|
||||
if doc.contains("PUB") {
|
||||
items.push((validator_module, def));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
items.sort_by(|left, right| {
|
||||
(left.0.package.to_string(), left.0.name.to_string())
|
||||
.cmp(&(right.0.package.to_string(), right.0.name.to_string()))
|
||||
});
|
||||
|
||||
items.into_iter()
|
||||
}
|
||||
|
||||
pub fn into_validators(self) -> impl Iterator<Item = CheckedModule> {
|
||||
self.0
|
||||
.into_values()
|
||||
|
|
Loading…
Reference in New Issue