Skip to content

Commit

Permalink
Refactored and cleaned up code for representing resolved ASTs
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacShelton committed Oct 27, 2024
1 parent e8c6bce commit 858fe60
Show file tree
Hide file tree
Showing 52 changed files with 911 additions and 768 deletions.
9 changes: 0 additions & 9 deletions src/ast/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ mod parameters;

use super::{Privacy, Stmt, Type};
use crate::{name::Name, source_files::Source, tag::Tag};
use derive_more::IsVariant;
pub use parameters::{Parameter, Parameters};

#[derive(Clone, Debug)]
Expand All @@ -16,12 +15,4 @@ pub struct Function {
pub abide_abi: bool,
pub tag: Option<Tag>,
pub privacy: Privacy,
pub genericness: Genericness,
}

#[derive(Copy, Clone, Debug, PartialEq, IsVariant)]
pub enum Genericness {
Concrete,
Contract,
Template,
}
3 changes: 1 addition & 2 deletions src/c/translation/function.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{parameters::has_parameters, types::get_name_and_type};
use crate::{
ast::{self, AstFile, Function, Genericness, Parameter, Parameters, Privacy},
ast::{self, AstFile, Function, Parameter, Parameters, Privacy},
c::parser::{
error::ParseErrorKind, CTypedef, DeclarationSpecifiers, Declarator,
ParameterDeclarationCore, ParameterTypeList, ParseError,
Expand Down Expand Up @@ -82,7 +82,6 @@ pub fn declare_function(
abide_abi: true,
tag: None,
privacy: Privacy::Public,
genericness: Genericness::Concrete,
});

Ok(())
Expand Down
10 changes: 2 additions & 8 deletions src/interpreter_env/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
ast::{
AstFile, Call, Enum, EnumMember, ExprKind, Field, FieldInitializer, FillBehavior, Function,
Genericness, InterpreterSyscall, Language, Parameter, Parameters, Privacy, StmtKind,
StructLiteral, Structure, TypeKind,
InterpreterSyscall, Language, Parameter, Parameters, Privacy, StmtKind, StructLiteral,
Structure, TypeKind,
},
interpreter::{
syscall_handler::{BuildSystemSyscallHandler, ProjectKind},
Expand Down Expand Up @@ -41,7 +41,6 @@ fn thin_void_function(name: impl Into<String>, syscall_kind: InterpreterSyscallK
source,
tag: None,
privacy: Privacy::Public,
genericness: Genericness::Concrete,
}
}

Expand Down Expand Up @@ -78,7 +77,6 @@ fn thin_cstring_function(
source,
tag: None,
privacy: Privacy::Public,
genericness: Genericness::Concrete,
}
}

Expand Down Expand Up @@ -106,7 +104,6 @@ pub fn setup_build_system_interpreter_symbols(file: &mut AstFile) {
abide_abi: false,
tag: Some(Tag::InterpreterEntryPoint),
privacy: Privacy::Public,
genericness: Genericness::Concrete,
});

file.enums.push(Enum {
Expand Down Expand Up @@ -244,7 +241,6 @@ pub fn setup_build_system_interpreter_symbols(file: &mut AstFile) {
source,
tag: None,
privacy: Privacy::Public,
genericness: Genericness::Concrete,
});

file.functions.push(Function {
Expand Down Expand Up @@ -288,7 +284,6 @@ pub fn setup_build_system_interpreter_symbols(file: &mut AstFile) {
source,
tag: None,
privacy: Privacy::Public,
genericness: Genericness::Concrete,
});

file.functions.push(Function {
Expand Down Expand Up @@ -316,7 +311,6 @@ pub fn setup_build_system_interpreter_symbols(file: &mut AstFile) {
source,
tag: None,
privacy: Privacy::Public,
genericness: Genericness::Concrete,
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ mod structure;

use self::error::{LowerError, LowerErrorKind};
use crate::{
ast::CInteger,
ast::{CInteger, FloatSize},
cli::BuildOptions,
ir::{self, IntegerSign},
resolved::{self, FloatSize},
resolved,
target::{Target, TargetOsExt},
};
use function::lower_function;
Expand Down
5 changes: 1 addition & 4 deletions src/parser/parse_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{
Parser,
};
use crate::{
ast::{Function, Genericness, Parameters, Privacy, TypeKind},
ast::{Function, Parameters, Privacy, TypeKind},
inflow::Inflow,
name::Name,
token::{Token, TokenKind},
Expand All @@ -18,14 +18,12 @@ impl<'a, I: Inflow<Token>> Parser<'a, I> {
let mut is_foreign = false;
let mut abide_abi = false;
let mut privacy = Privacy::Private;
let mut genericness = Genericness::Concrete;

for annotation in annotations {
match annotation.kind {
AnnotationKind::Foreign => is_foreign = true,
AnnotationKind::AbideAbi => abide_abi = true,
AnnotationKind::Public => privacy = Privacy::Public,
AnnotationKind::Template => genericness = Genericness::Template,
_ => return Err(self.unexpected_annotation(&annotation, Some("for function"))),
}
}
Expand Down Expand Up @@ -69,7 +67,6 @@ impl<'a, I: Inflow<Token>> Parser<'a, I> {
abide_abi,
tag: None,
privacy,
genericness,
})
}
}
6 changes: 1 addition & 5 deletions src/pragma_section/parse.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use super::PragmaSection;
use crate::{
ast::{
AstFile, Expr, ExprKind, Function, Genericness, Parameters, Privacy, Stmt, StmtKind,
TypeKind,
},
ast::{AstFile, Expr, ExprKind, Function, Parameters, Privacy, Stmt, StmtKind, TypeKind},
diagnostics::ErrorDiagnostic,
inflow::Inflow,
name::Name,
Expand Down Expand Up @@ -117,7 +114,6 @@ impl PragmaSection {
abide_abi: false,
tag: None,
privacy: Privacy::Public,
genericness: Genericness::Concrete,
});
} else {
return Err(Box::new(ParseError::expected(
Expand Down
4 changes: 2 additions & 2 deletions src/resolve/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use super::{
};
use crate::{
ast::{
self, CInteger, CIntegerAssumptions, ConformBehavior, Language, Settings, UnaryOperator,
self, CInteger, CIntegerAssumptions, ConformBehavior, IntegerKnown, Language, Settings,
UnaryOperator,
},
resolve::{
error::ResolveErrorKind,
Expand All @@ -41,7 +42,6 @@ use crate::{
};
use ast::FloatSize;
pub use basic_binary_operation::resolve_basic_binary_operator;
use resolved::IntegerKnown;
use std::collections::HashMap;

pub struct ResolveExprCtx<'a, 'b> {
Expand Down
1 change: 1 addition & 0 deletions src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ pub fn resolve<'a>(
None
}
}),
is_generic: false,
});

ctx.jobs.push_back(FuncJob::Regular(
Expand Down
27 changes: 27 additions & 0 deletions src/resolved/block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use super::{Stmt, StmtKind, Type, TypeKind};
use crate::source_files::Source;

#[derive(Clone, Debug)]
pub struct Block {
pub stmts: Vec<Stmt>,
}

impl Block {
pub fn new(stmts: Vec<Stmt>) -> Self {
Self { stmts }
}

pub fn get_result_type(&self, source: Source) -> Type {
if let Some(stmt) = self.stmts.last() {
match &stmt.kind {
StmtKind::Return(..) => None,
StmtKind::Expr(expr) => Some(expr.resolved_type.clone()),
StmtKind::Declaration(..) => None,
StmtKind::Assignment(..) => None,
}
} else {
None
}
.unwrap_or(TypeKind::Void.at(source))
}
}
15 changes: 15 additions & 0 deletions src/resolved/datatype/kind/anonymous_enum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::{ast::EnumMember, resolved::Type, source_files::Source};
use indexmap::IndexMap;

#[derive(Clone, Debug)]
pub struct AnonymousEnum {
pub resolved_type: Box<Type>,
pub source: Source,
pub members: IndexMap<String, EnumMember>,
}

impl PartialEq for AnonymousEnum {
fn eq(&self, other: &Self) -> bool {
self.resolved_type.eq(&other.resolved_type) && self.members.eq(&other.members)
}
}
7 changes: 7 additions & 0 deletions src/resolved/datatype/kind/fixed_array.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::resolved::Type;

#[derive(Clone, Debug, PartialEq)]
pub struct FixedArray {
pub size: u64,
pub inner: Type,
}
8 changes: 8 additions & 0 deletions src/resolved/datatype/kind/function_pointer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use crate::resolved::{Parameter, Type};

#[derive(Clone, Debug, PartialEq)]
pub struct FunctionPointer {
pub parameters: Vec<Parameter>,
pub return_type: Box<Type>,
pub is_cstyle_variadic: bool,
}
Loading

0 comments on commit 858fe60

Please sign in to comment.