Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Function parameters init as variables #20

Merged
merged 6 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "semantic-analyzer"
version = "0.3.1"
version = "0.3.2"
authors = ["Evgeny Ukhanov <mrlsd@ya.ru>"]
description = "Semantic analyzer library for compilers written in Rust for semantic analysis of programming languages AST"
keywords = ["compiler", "semantic-analisis", "semantic-alalyzer", "compiler-design", "semantic"]
Expand All @@ -13,5 +13,9 @@ repository = "https://github.com/mrLSD/semantic-analyzer-rs"
[lib]
doctest = false

#[lints.clippy]
#pedantic = "deny"
#nursery = "deny"

[dependencies]
nom_locate = "4.2"
11 changes: 11 additions & 0 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl GetName for ImportName<'_> {
}

impl<'a> ImportName<'a> {
#[must_use]
pub const fn new(ident: Ident<'a>) -> Self {
Self(ident)
}
Expand All @@ -47,6 +48,7 @@ pub struct ConstantName<'a>(Ident<'a>);

impl<'a> ConstantName<'a> {
/// Init `ConstantName`, especially useful for testing
#[must_use]
pub const fn new(name: Ident<'a>) -> Self {
Self(name)
}
Expand All @@ -69,6 +71,7 @@ impl GetName for ConstantName<'_> {
pub struct FunctionName<'a>(Ident<'a>);

impl<'a> FunctionName<'a> {
#[must_use]
pub const fn new(name: Ident<'a>) -> Self {
Self(name)
}
Expand All @@ -92,6 +95,7 @@ impl<'a> ToString for FunctionName<'a> {
pub struct ParameterName<'a>(Ident<'a>);

impl<'a> ParameterName<'a> {
#[must_use]
pub const fn new(name: Ident<'a>) -> Self {
Self(name)
}
Expand All @@ -112,6 +116,7 @@ impl ToString for ParameterName<'_> {
pub struct ValueName<'a>(Ident<'a>);

impl<'a> ValueName<'a> {
#[must_use]
pub const fn new(name: Ident<'a>) -> Self {
Self(name)
}
Expand All @@ -138,16 +143,19 @@ impl CodeLocation {
/// Initialize code location with:
/// - `location` - line of source code
/// - `offset` - position on the line of source code
#[must_use]
pub const fn new(location: u32, offset: usize) -> Self {
Self(location, offset)
}

/// Get location line in the source
#[must_use]
pub const fn line(&self) -> u32 {
self.0
}

/// Get location position on the line in the source
#[must_use]
pub const fn offset(&self) -> usize {
self.1
}
Expand Down Expand Up @@ -383,6 +391,7 @@ pub enum PrimitiveValue {
}

impl PrimitiveValue {
#[must_use]
pub const fn get_type(&self) -> Type<'_> {
match self {
Self::U8(_) => Type::Primitive(PrimitiveTypes::U8),
Expand Down Expand Up @@ -451,6 +460,8 @@ pub enum ExpressionOperations {
}

impl ExpressionOperations {
/// Get expression operation priority level
#[must_use]
pub const fn priority(&self) -> u8 {
match self {
Self::Plus => 5,
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::pedantic, clippy::nursery)]
#![allow(clippy::module_name_repetitions)]
//! # Semantic Analyzer
//! The semantic analyzer consists of the following basic elements:
//! - AST is an abstract syntax tree that implements a predefined set of
Expand Down
Loading
Loading