Skip to content

Commit

Permalink
Initializes type parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed Oct 23, 2024
1 parent f4a0a76 commit 181b4c7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 11 deletions.
7 changes: 7 additions & 0 deletions example/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class class1 {
class1();
class1(const char *v1);
~class1();

const char *value() const;
protected:
std::string v1;
};
Expand All @@ -24,3 +26,8 @@ class1::class1(const char *v1) : v1(v1)
class1::~class1()
{
}

const char *class1::value() const
{
return v1.c_str();
}
2 changes: 2 additions & 0 deletions example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ cpp! {
class class1 {
public:
class1();

const char *value() const;
};
}
3 changes: 2 additions & 1 deletion macros/src/cpp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use self::class::Class;
use crate::symbol::{Name, Segment, Signature, Symbol, Type};
use crate::symbol::{Name, Segment, Signature, Symbol};
use crate::ty::Type;
use crate::META;
use proc_macro2::{Literal, Span, TokenStream};
use quote::{format_ident, quote};
Expand Down
5 changes: 4 additions & 1 deletion macros/src/cpp/class.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::func::Param;
use super::kw;
use crate::ty::Type;
use proc_macro2::Span;
use syn::ext::IdentExt;
use syn::parse::{Parse, ParseStream};
Expand Down Expand Up @@ -33,10 +34,12 @@ impl Parse for Class {
let l = body.lookahead1();

if l.peek(kw::public) {
body.parse::<kw::public>()?;
body.parse::<kw::public>().unwrap();
body.parse::<Token![:]>()?;

accessibility = Accessibility::Public;
} else if l.peek(Token![const]) {
body.parse::<Type>()?;
} else if l.peek(Ident) {
let r = body.parse::<Ident>()?;
let l = body.lookahead1();
Expand Down
1 change: 1 addition & 0 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use syn::{parse_macro_input, Error};
mod cpp;
mod meta;
mod symbol;
mod ty;

/// Generate binding to C++ functions and methods.
#[proc_macro]
Expand Down
11 changes: 2 additions & 9 deletions macros/src/symbol.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::ty::Type;
use std::borrow::Cow;
use thiserror::Error;

Expand Down Expand Up @@ -67,7 +68,7 @@ impl<'a> Symbol<'a> {
match t {
Type::Void => n.push('v'),
Type::Ulong => n.push('m'),
Type::Ptr(v) => push_type(n, &v),
Type::Ptr { c: _, t } => push_type(n, &t),
}
}

Expand Down Expand Up @@ -117,14 +118,6 @@ impl Signature {
}
}

/// C++ type.
#[derive(Debug)]
pub enum Type {
Void,
Ulong,
Ptr(Box<Self>),
}

/// Represents an error when [`Symbol`] fails to parse from a mangled name.
#[derive(Debug, Error)]
pub enum SymbolError {
Expand Down
15 changes: 15 additions & 0 deletions macros/src/ty/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use syn::parse::{Parse, ParseStream};

/// C++ type.
#[derive(Debug)]
pub enum Type {
Void,
Ulong,
Ptr { c: bool, t: Box<Self> },
}

impl Parse for Type {
fn parse(input: ParseStream) -> syn::Result<Self> {
todo!()
}
}

0 comments on commit 181b4c7

Please sign in to comment.