Add ScopeTypes to Pass
This commit is contained in:
parent
b012a46e91
commit
e13b6349f0
@ -330,7 +330,7 @@ pub struct TypeDefinition {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum TypeDefinitionKind {
|
pub enum TypeDefinitionKind {
|
||||||
Struct(Vec<(String, Type)>),
|
Struct(Vec<(String, TypeKind)>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -109,6 +109,7 @@ impl<T: Clone + std::fmt::Debug> Storage<T> {
|
|||||||
pub struct Scope {
|
pub struct Scope {
|
||||||
pub function_returns: Storage<ScopeFunction>,
|
pub function_returns: Storage<ScopeFunction>,
|
||||||
pub variables: Storage<ScopeVariable>,
|
pub variables: Storage<ScopeVariable>,
|
||||||
|
pub types: Storage<ScopeTypedefKind>,
|
||||||
/// Hard Return type of this scope, if inside a function
|
/// Hard Return type of this scope, if inside a function
|
||||||
pub return_type_hint: Option<TypeKind>,
|
pub return_type_hint: Option<TypeKind>,
|
||||||
}
|
}
|
||||||
@ -125,11 +126,17 @@ pub struct ScopeVariable {
|
|||||||
pub mutable: bool,
|
pub mutable: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum ScopeTypedefKind {
|
||||||
|
Struct(Vec<(String, TypeKind)>),
|
||||||
|
}
|
||||||
|
|
||||||
impl Scope {
|
impl Scope {
|
||||||
pub fn inner(&self) -> Scope {
|
pub fn inner(&self) -> Scope {
|
||||||
Scope {
|
Scope {
|
||||||
function_returns: self.function_returns.clone(),
|
function_returns: self.function_returns.clone(),
|
||||||
variables: self.variables.clone(),
|
variables: self.variables.clone(),
|
||||||
|
types: self.types.clone(),
|
||||||
return_type_hint: self.return_type_hint.clone(),
|
return_type_hint: self.return_type_hint.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,6 +225,13 @@ impl Context {
|
|||||||
|
|
||||||
impl Module {
|
impl Module {
|
||||||
fn pass<T: Pass>(&mut self, pass: &mut T, state: &mut State<T::TError>, scope: &mut Scope) {
|
fn pass<T: Pass>(&mut self, pass: &mut T, state: &mut State<T::TError>, scope: &mut Scope) {
|
||||||
|
for typedef in &self.typedefs {
|
||||||
|
let kind = match &typedef.kind {
|
||||||
|
TypeDefinitionKind::Struct(fields) => ScopeTypedefKind::Struct(fields.clone()),
|
||||||
|
};
|
||||||
|
scope.types.set(typedef.name.clone(), kind).ok();
|
||||||
|
}
|
||||||
|
|
||||||
for function in &self.functions {
|
for function in &self.functions {
|
||||||
scope
|
scope
|
||||||
.function_returns
|
.function_returns
|
||||||
|
Loading…
Reference in New Issue
Block a user