mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-22 07:28:11 +08:00
Fold attribute names through monitors and skip coercing name inputs
This commit is contained in:
@@ -1,11 +1,42 @@
|
||||
use crate::document::NodeNetwork;
|
||||
use crate::proto::{ProtoNetwork, Registry};
|
||||
use crate::proto::{GraphErrors, ProtoNetwork, Registry};
|
||||
use std::error::Error;
|
||||
|
||||
/// Why a network failed to compile: a structural message, or errors the
|
||||
/// editor can pin to their nodes in the graph.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum CompileError {
|
||||
Message(String),
|
||||
Graph(GraphErrors),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for CompileError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
CompileError::Message(message) => write!(f, "{message}"),
|
||||
CompileError::Graph(errors) => write!(f, "{errors:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for CompileError {}
|
||||
|
||||
impl From<String> for CompileError {
|
||||
fn from(message: String) -> Self {
|
||||
CompileError::Message(message)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CompileError> for String {
|
||||
fn from(error: CompileError) -> Self {
|
||||
error.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Compiler {}
|
||||
|
||||
impl Compiler {
|
||||
pub fn compile<'r>(&self, mut network: NodeNetwork, registry: &'r Registry) -> impl Iterator<Item = Result<ProtoNetwork, String>> + 'r {
|
||||
pub fn compile<'r>(&self, mut network: NodeNetwork, registry: &'r Registry) -> impl Iterator<Item = Result<ProtoNetwork, CompileError>> + 'r {
|
||||
network.resolve_scope_inputs();
|
||||
network.generate_node_paths(&[]);
|
||||
let node_ids = network.nodes.keys().copied().collect::<Vec<_>>();
|
||||
@@ -20,17 +51,15 @@ impl Compiler {
|
||||
proto_networks.map(move |mut proto_network| {
|
||||
proto_network.insert_context_nullification_nodes()?;
|
||||
let _ = proto_network.resolve_types(registry);
|
||||
proto_network
|
||||
.compute_layouts()
|
||||
.map_err(|errors| errors.iter().map(|error| format!("{:?}", error.error)).collect::<Vec<_>>().join("\n"))?;
|
||||
proto_network.compute_layouts().map_err(CompileError::Graph)?;
|
||||
proto_network.generate_stable_node_ids();
|
||||
Ok(proto_network)
|
||||
})
|
||||
}
|
||||
pub fn compile_single(&self, network: NodeNetwork, registry: &Registry) -> Result<ProtoNetwork, String> {
|
||||
pub fn compile_single(&self, network: NodeNetwork, registry: &Registry) -> Result<ProtoNetwork, CompileError> {
|
||||
assert_eq!(network.exports.len(), 1, "Graph with multiple outputs not yet handled");
|
||||
let Some(proto_network) = self.compile(network, registry).next() else {
|
||||
return Err("Failed to convert graph into proto graph".to_string());
|
||||
return Err(CompileError::Message("Failed to convert graph into proto graph".to_string()));
|
||||
};
|
||||
proto_network
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user