leo_ast/program/
program_scope.rs1use crate::{
20 Composite,
21 ConstDeclaration,
22 Constructor,
23 Function,
24 Indent,
25 Interface,
26 Mapping,
27 ProgramId,
28 StorageVariable,
29 Type,
30};
31
32use leo_span::{Span, Symbol};
33use serde::{Deserialize, Serialize};
34use std::fmt;
35
36#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
38pub struct ProgramScope {
39 pub program_id: ProgramId,
41 pub parents: Vec<(Span, Type)>,
43 pub consts: Vec<(Symbol, ConstDeclaration)>,
45 pub composites: Vec<(Symbol, Composite)>,
47 pub mappings: Vec<(Symbol, Mapping)>,
49 pub storage_variables: Vec<(Symbol, StorageVariable)>,
51 pub functions: Vec<(Symbol, Function)>,
53 pub interfaces: Vec<(Symbol, Interface)>,
55 pub constructor: Option<Constructor>,
57 pub span: Span,
59}
60
61impl fmt::Display for ProgramScope {
62 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63 writeln!(f, "program {} {{", self.program_id)?;
64 for (_, const_decl) in self.consts.iter() {
65 writeln!(f, "{};", Indent(const_decl))?;
66 }
67 if let Some(constructor) = &self.constructor {
68 writeln!(f, "{}", Indent(constructor))?;
69 }
70 for (_, composite_) in self.composites.iter() {
71 writeln!(f, "{}", Indent(composite_))?;
72 }
73 for (_, mapping) in self.mappings.iter() {
74 writeln!(f, "{};", Indent(mapping))?;
75 }
76 for (_, function) in self.functions.iter().filter(|f| f.1.variant.is_entry()) {
77 writeln!(f, "{}", Indent(function))?;
78 }
79 for (_, function) in self.functions.iter().filter(|f| f.1.variant.is_view()) {
80 writeln!(f, "{}", Indent(function))?;
81 }
82 writeln!(f, "}}")?;
83
84 for (_, function) in self.functions.iter().filter(|f| !f.1.variant.is_entry() && !f.1.variant.is_view()) {
85 writeln!(f, "{}", Indent(function))?;
86 }
87 Ok(())
88 }
89}