Skip to content

Commit

Permalink
Added ability for structures to be declared public
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacShelton committed Oct 8, 2024
1 parent f5f7249 commit c5904b9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ast/structure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Structure {
pub fields: IndexMap<String, Field>,
pub is_packed: bool,
pub source: Source,
pub privacy: Privacy,
}

#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, IsVariant)]
Expand Down
1 change: 1 addition & 0 deletions src/c/translation/types/composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub fn make_composite(
fields,
is_packed,
source: composite.source,
privacy: Privacy::Private,
});

Ok(TypeKind::Named(name))
Expand Down
2 changes: 2 additions & 0 deletions src/interpreter_env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub fn setup_build_system_interpreter_symbols(file: &mut AstFile) {
)]),
is_packed: false,
source,
privacy: Privacy::Private,
});

file.structures.push(Structure {
Expand All @@ -156,6 +157,7 @@ pub fn setup_build_system_interpreter_symbols(file: &mut AstFile) {
)]),
is_packed: false,
source,
privacy: Privacy::Private,
});

file.functions.push(thin_cstring_function(
Expand Down
5 changes: 4 additions & 1 deletion src/parser/parse_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{
Parser,
};
use crate::{
ast::{Field, Structure},
ast::{Field, Privacy, Structure},
inflow::Inflow,
name::Name,
token::{Token, TokenKind},
Expand All @@ -24,11 +24,13 @@ impl<'a, I: Inflow<Token>> Parser<'a, I> {

let mut is_packed = false;
let mut namespace = None;
let mut privacy = Privacy::Private;

for annotation in annotations {
match annotation.kind {
AnnotationKind::Packed => is_packed = true,
AnnotationKind::Namespace(new_namespace) => namespace = Some(new_namespace),
AnnotationKind::Public => privacy = Privacy::Public,
_ => return Err(self.unexpected_annotation(&annotation, Some("for struct"))),
}
}
Expand Down Expand Up @@ -68,6 +70,7 @@ impl<'a, I: Inflow<Token>> Parser<'a, I> {
fields,
is_packed,
source,
privacy,
})
}
}

0 comments on commit c5904b9

Please sign in to comment.