From c5904b90ff4af0ebc6708a76822fdc656908db93 Mon Sep 17 00:00:00 2001 From: IsaacShelton Date: Mon, 7 Oct 2024 19:25:34 -0500 Subject: [PATCH] Added ability for structures to be declared public --- src/ast/structure/mod.rs | 1 + src/c/translation/types/composite.rs | 1 + src/interpreter_env/mod.rs | 2 ++ src/parser/parse_structure.rs | 5 ++++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ast/structure/mod.rs b/src/ast/structure/mod.rs index 22d45e19..5fcfc115 100644 --- a/src/ast/structure/mod.rs +++ b/src/ast/structure/mod.rs @@ -9,6 +9,7 @@ pub struct Structure { pub fields: IndexMap, pub is_packed: bool, pub source: Source, + pub privacy: Privacy, } #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, IsVariant)] diff --git a/src/c/translation/types/composite.rs b/src/c/translation/types/composite.rs index aaf3b04b..8d89035c 100644 --- a/src/c/translation/types/composite.rs +++ b/src/c/translation/types/composite.rs @@ -97,6 +97,7 @@ pub fn make_composite( fields, is_packed, source: composite.source, + privacy: Privacy::Private, }); Ok(TypeKind::Named(name)) diff --git a/src/interpreter_env/mod.rs b/src/interpreter_env/mod.rs index e3725104..56eec2e4 100644 --- a/src/interpreter_env/mod.rs +++ b/src/interpreter_env/mod.rs @@ -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 { @@ -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( diff --git a/src/parser/parse_structure.rs b/src/parser/parse_structure.rs index 264b0bba..e6a47ec8 100644 --- a/src/parser/parse_structure.rs +++ b/src/parser/parse_structure.rs @@ -4,7 +4,7 @@ use super::{ Parser, }; use crate::{ - ast::{Field, Structure}, + ast::{Field, Privacy, Structure}, inflow::Inflow, name::Name, token::{Token, TokenKind}, @@ -24,11 +24,13 @@ impl<'a, I: Inflow> 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"))), } } @@ -68,6 +70,7 @@ impl<'a, I: Inflow> Parser<'a, I> { fields, is_packed, source, + privacy, }) } }