Skip to content

Commit

Permalink
Fix ctor not being serialized properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernthedev committed Nov 25, 2024
1 parent 202410e commit c675b64
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 91 deletions.
10 changes: 5 additions & 5 deletions src/generate/cpp/cpp_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::generate::cpp::cpp_type::CORDL_NO_INCLUDE_IMPL_DEFINE;
use crate::generate::cs_type_tag::CsTypeTag;
use crate::generate::metadata::CordlMetadata;
use crate::generate::type_extensions::TypeDefinitionExtensions;
use crate::generate::writer::{CppWritable, CppWriter};
use crate::generate::writer::{Writable, Writer};
use crate::helpers::sorting::DependencyGraph;

use super::config::CppGenerationConfig;
Expand Down Expand Up @@ -208,17 +208,17 @@ impl CppContext {
let base_path = &config.header_path;

trace!("Writing {:?}", self.typedef_path.as_path());
let mut typedef_writer = CppWriter {
let mut typedef_writer = Writer {
stream: File::create(self.typedef_path.as_path())?,
indent: 0,
newline: true,
};
let mut typeimpl_writer = CppWriter {
let mut typeimpl_writer = Writer {
stream: File::create(self.type_impl_path.as_path())?,
indent: 0,
newline: true,
};
let mut fundamental_writer = CppWriter {
let mut fundamental_writer = Writer {
stream: File::create(self.fundamental_path.as_path())?,
indent: 0,
newline: true,
Expand Down Expand Up @@ -477,7 +477,7 @@ impl CppContext {
}

/// Writes IL2CPP argument macros for the given C++ type.
fn write_il2cpp_arg_macros(ty: &CppType, writer: &mut CppWriter) -> color_eyre::Result<()> {
fn write_il2cpp_arg_macros(ty: &CppType, writer: &mut Writer) -> color_eyre::Result<()> {
let is_generic_instantiation = ty.generic_instantiations_args_types.is_some();
if is_generic_instantiation {
return Ok(());
Expand Down
6 changes: 3 additions & 3 deletions src/generate/cpp/cpp_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::generate::metadata::CordlMetadata;
use crate::generate::type_extensions::{
TypeDefinitionExtensions, TypeDefinitionIndexExtensions, TypeExtentions,
};
use crate::generate::writer::CppWritable;
use crate::generate::writer::Writable;

use itertools::Itertools;
use log::warn;
Expand Down Expand Up @@ -640,7 +640,7 @@ pub(crate) fn prop_methods_from_fieldinfo(
};

// construct getter and setter bodies
let getter_body: Vec<Arc<dyn CppWritable>> =
let getter_body: Vec<Arc<dyn Writable>> =
if let Some(instance_null_check) = instance_null_check {
vec![
Arc::new(CppLine::make(instance_null_check.into())),
Expand All @@ -650,7 +650,7 @@ pub(crate) fn prop_methods_from_fieldinfo(
vec![Arc::new(CppLine::make(getter_call))]
};

let setter_body: Vec<Arc<dyn CppWritable>> =
let setter_body: Vec<Arc<dyn Writable>> =
if let Some(instance_null_check) = instance_null_check {
vec![
Arc::new(CppLine::make(instance_null_check.into())),
Expand Down
10 changes: 5 additions & 5 deletions src/generate/cpp/cpp_members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use pathdiff::diff_paths;

use crate::generate::{
cs_members::{CsGenericTemplate, CsGenericTemplateType},
writer::CppWritable,
writer::Writable,
};

use std::{
Expand Down Expand Up @@ -285,7 +285,7 @@ pub struct CppMethodDecl {
pub is_inline: bool,

pub brief: Option<String>,
pub body: Option<Vec<Arc<dyn CppWritable>>>,
pub body: Option<Vec<Arc<dyn Writable>>>,
}

impl PartialEq for CppMethodDecl {
Expand Down Expand Up @@ -389,7 +389,7 @@ pub struct CppMethodImpl {
pub prefix_modifiers: Vec<String>,

pub brief: Option<String>,
pub body: Vec<Arc<dyn CppWritable>>,
pub body: Vec<Arc<dyn Writable>>,
}

impl PartialEq for CppMethodImpl {
Expand Down Expand Up @@ -470,7 +470,7 @@ pub struct CppConstructorDecl {
pub initialized_values: HashMap<String, String>,

pub brief: Option<String>,
pub body: Option<Vec<Arc<dyn CppWritable>>>,
pub body: Option<Vec<Arc<dyn Writable>>>,
}

impl PartialEq for CppConstructorDecl {
Expand Down Expand Up @@ -521,7 +521,7 @@ pub struct CppConstructorImpl {

pub template: Option<CppTemplate>,

pub body: Vec<Arc<dyn CppWritable>>,
pub body: Vec<Arc<dyn Writable>>,
}

impl PartialEq for CppConstructorImpl {
Expand Down
78 changes: 39 additions & 39 deletions src/generate/cpp/cpp_members_serialize.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use itertools::Itertools;
use std::io::Write;

use crate::generate::writer::{CppWritable, CppWriter, SortLevel, Sortable};
use crate::generate::writer::{Writable, Writer, SortLevel, Sortable};

use super::cpp_members::{
CppCommentedString, CppConstructorDecl, CppConstructorImpl, CppFieldDecl, CppFieldImpl,
Expand All @@ -10,8 +10,8 @@ use super::cpp_members::{
CppStaticAssert, CppTemplate, CppUsingAlias,
};

impl CppWritable for CppTemplate {
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
impl Writable for CppTemplate {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
writeln!(
writer,
"template<{}>",
Expand All @@ -26,8 +26,8 @@ impl CppWritable for CppTemplate {
}
}

impl CppWritable for CppForwardDeclare {
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
impl Writable for CppForwardDeclare {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
if let Some(namespace) = &self.cpp_namespace {
writeln!(writer, "namespace {namespace} {{")?;
}
Expand Down Expand Up @@ -66,8 +66,8 @@ impl CppWritable for CppForwardDeclare {
}
}

impl CppWritable for CppCommentedString {
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
impl Writable for CppCommentedString {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
writeln!(writer, "{}", self.data)?;
if let Some(val) = &self.comment {
writeln!(writer, "// {val}")?;
Expand All @@ -76,8 +76,8 @@ impl CppWritable for CppCommentedString {
}
}

impl CppWritable for CppInclude {
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
impl Writable for CppInclude {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
// this is so bad
let path = if cfg!(windows) {
self.include.to_string_lossy().replace('\\', "/")
Expand All @@ -93,8 +93,8 @@ impl CppWritable for CppInclude {
Ok(())
}
}
impl CppWritable for CppUsingAlias {
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
impl Writable for CppUsingAlias {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
if let Some(template) = &self.template {
template.write(writer)?;
}
Expand All @@ -115,8 +115,8 @@ impl Sortable for CppUsingAlias {
}
}

impl CppWritable for CppFieldDecl {
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
impl Writable for CppFieldDecl {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
if let Some(comment) = &self.brief_comment {
writeln!(writer, "/// @brief {comment}")?;
}
Expand Down Expand Up @@ -162,8 +162,8 @@ impl Sortable for CppFieldDecl {
}
}

impl CppWritable for CppFieldImpl {
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
impl Writable for CppFieldImpl {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
if let Some(template) = &self.declaring_type_template {
template.write(writer)?;
}
Expand Down Expand Up @@ -201,9 +201,9 @@ impl Sortable for CppFieldImpl {
}
}

impl CppWritable for CppMethodDecl {
impl Writable for CppMethodDecl {
// declaration
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
if let Some(brief) = &self.brief {
writeln!(writer, "/// @brief {brief}")?;
}
Expand Down Expand Up @@ -296,9 +296,9 @@ impl Sortable for CppMethodDecl {
}
}

impl CppWritable for CppMethodImpl {
impl Writable for CppMethodImpl {
// declaration
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
if let Some(brief) = &self.brief {
writeln!(writer, "/// @brief {brief}")?;
}
Expand Down Expand Up @@ -383,9 +383,9 @@ impl Sortable for CppMethodImpl {
}
}

impl CppWritable for CppConstructorDecl {
impl Writable for CppConstructorDecl {
// declaration
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
// I'm lazy
if self.is_protected {
writeln!(writer, "protected:")?;
Expand Down Expand Up @@ -482,9 +482,9 @@ impl Sortable for CppConstructorDecl {
}
}

impl CppWritable for CppConstructorImpl {
impl Writable for CppConstructorImpl {
// declaration
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
writeln!(writer, "// Ctor Parameters {:?}", self.parameters)?;

// Constructor
Expand Down Expand Up @@ -551,8 +551,8 @@ impl Sortable for CppConstructorImpl {
}
}

impl CppWritable for CppPropertyDecl {
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
impl Writable for CppPropertyDecl {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
let prefix_modifiers: Vec<&str> = vec![];
let suffix_modifiers: Vec<&str> = vec![];

Expand Down Expand Up @@ -596,8 +596,8 @@ impl Sortable for CppPropertyDecl {
}
}

impl CppWritable for CppMethodSizeStruct {
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
impl Writable for CppMethodSizeStruct {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
writeln!(
writer,
"// Writing Method size for method: {}.{}",
Expand Down Expand Up @@ -668,8 +668,8 @@ impl Sortable for CppMethodSizeStruct {
}
}

impl CppWritable for CppStaticAssert {
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
impl Writable for CppStaticAssert {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
let condition = &self.condition;
match &self.message {
None => writeln!(writer, "static_assert({condition})"),
Expand All @@ -678,16 +678,16 @@ impl CppWritable for CppStaticAssert {
Ok(())
}
}
impl CppWritable for CppLine {
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
impl Writable for CppLine {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
writer.write_all(self.line.as_bytes())?;
writeln!(writer)?; // add line ending
Ok(())
}
}

impl CppWritable for CppNestedStruct {
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
impl Writable for CppNestedStruct {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
if self.is_private {
writeln!(writer, "private:")?;
}
Expand Down Expand Up @@ -741,8 +741,8 @@ impl Sortable for CppNestedStruct {
}
}

impl CppWritable for CppNestedUnion {
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
impl Writable for CppNestedUnion {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
if self.is_private {
writeln!(writer, "private:")?;
}
Expand Down Expand Up @@ -773,8 +773,8 @@ impl Sortable for CppNestedUnion {
}
}

impl CppWritable for CppMember {
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
impl Writable for CppMember {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
match self {
CppMember::FieldDecl(f) => f.write(writer),
CppMember::FieldImpl(f) => f.write(writer),
Expand All @@ -793,8 +793,8 @@ impl CppWritable for CppMember {
}
}

impl CppWritable for CppNonMember {
fn write(&self, writer: &mut CppWriter) -> color_eyre::Result<()> {
impl Writable for CppNonMember {
fn write(&self, writer: &mut Writer) -> color_eyre::Result<()> {
match self {
CppNonMember::SizeStruct(ss) => ss.write(writer),
CppNonMember::Comment(c) => c.write(writer),
Expand Down
Loading

0 comments on commit c675b64

Please sign in to comment.