|
3 | 3 | use proc_macro::{Diagnostic, Level, TokenStream};
|
4 | 4 | use proc_macro2::{Ident, Span};
|
5 | 5 | use quote::quote;
|
6 |
| -use syn::{punctuated::Punctuated, spanned::Spanned, Expr, FnArg, Lit, Pat, Type}; |
| 6 | +use syn::{punctuated::Punctuated, spanned::Spanned, Expr, FnArg, Pat, Type}; |
7 | 7 |
|
8 | 8 | enum ArgType {
|
9 |
| - Array(bool, usize), |
10 |
| - Slice(bool), |
11 |
| - Pointer(bool), |
12 |
| - Reference(bool), |
| 9 | + Array(bool), // mutable? |
| 10 | + Slice(bool), // mutable? |
| 11 | + Pointer(bool), // mutable? |
| 12 | + Reference(bool), // mutable? |
13 | 13 | String,
|
14 | 14 | Path,
|
15 | 15 | }
|
@@ -82,48 +82,7 @@ pub fn syscall(_: TokenStream, item: TokenStream) -> TokenStream {
|
82 | 82 | fn determine_arg_type(typ: &Type) -> Option<ArgType> {
|
83 | 83 | match typ {
|
84 | 84 | Type::Reference(typ) => match typ.elem.as_ref() {
|
85 |
| - Type::Array(array) => match &array.len { |
86 |
| - Expr::Lit(lit) => match &lit.lit { |
87 |
| - Lit::Int(lit) => match lit.base10_parse() { |
88 |
| - Ok(len) => Some(ArgType::Array(typ.mutability.is_some(), len)), |
89 |
| - Err(err) => { |
90 |
| - Diagnostic::spanned( |
91 |
| - lit.span().unwrap(), |
92 |
| - Level::Error, |
93 |
| - &format!("failed to parse array length: {}", err), |
94 |
| - ) |
95 |
| - .emit(); |
96 |
| - |
97 |
| - // If we can't parse the array length, we just give it an arbitrary length. |
98 |
| - // This is probably not the best way to do this, but it won't cause any |
99 |
| - // further errors to be emitted. |
100 |
| - Some(ArgType::Array(typ.mutability.is_some(), 0)) |
101 |
| - } |
102 |
| - }, |
103 |
| - _ => { |
104 |
| - Diagnostic::spanned( |
105 |
| - lit.span().unwrap(), |
106 |
| - Level::Error, |
107 |
| - "array length must be a constant integer", |
108 |
| - ) |
109 |
| - .emit(); |
110 |
| - |
111 |
| - // Same as above. |
112 |
| - Some(ArgType::Array(typ.mutability.is_some(), 0)) |
113 |
| - } |
114 |
| - }, |
115 |
| - _ => { |
116 |
| - Diagnostic::spanned( |
117 |
| - array.span().unwrap(), |
118 |
| - Level::Error, |
119 |
| - "array length must be a constant integer", |
120 |
| - ) |
121 |
| - .emit(); |
122 |
| - |
123 |
| - // Same as above. |
124 |
| - Some(ArgType::Array(typ.mutability.is_some(), 0)) |
125 |
| - } |
126 |
| - }, |
| 85 | + Type::Array(_) => Some(ArgType::Array(typ.mutability.is_some())), |
127 | 86 | Type::Slice(_) => Some(ArgType::Slice(typ.mutability.is_some())),
|
128 | 87 | Type::Path(path) => {
|
129 | 88 | if path.path.segments.last().unwrap().ident == "str" {
|
@@ -161,7 +120,7 @@ fn process_args(args: &Punctuated<FnArg, syn::Token![,]>) -> Vec<FnArg> {
|
161 | 120 | result.push(syn::parse_quote!(#data: usize));
|
162 | 121 | result.push(syn::parse_quote!(#len: usize));
|
163 | 122 | }
|
164 |
| - Some(ArgType::Array(_, _)) => { |
| 123 | + Some(ArgType::Array(_)) => { |
165 | 124 | let data = Ident::new(&format!("{}_data", ident), Span::call_site());
|
166 | 125 |
|
167 | 126 | result.push(syn::parse_quote!(#data: usize));
|
@@ -225,21 +184,13 @@ fn process_call_args(args: &Punctuated<FnArg, syn::Token![,]>) -> Vec<Expr> {
|
225 | 184 |
|
226 | 185 | result.push(slice_expr);
|
227 | 186 | }
|
228 |
| - ArgType::Array(is_mut, length) => { |
| 187 | + ArgType::Array(is_mut) => { |
229 | 188 | let array_expr: Expr = if is_mut {
|
230 | 189 | syn::parse_quote! {
|
231 |
| - { |
232 |
| - let slice = crate::utils::validate_slice_mut(#data_ident as *mut _, #length).ok_or(AeroSyscallError::EINVAL)?; |
233 |
| - &mut slice[0..#length] |
234 |
| - } |
| 190 | + crate::utils::validate_array_mut(#data_ident as *mut _).ok_or(AeroSyscallError::EINVAL)? |
235 | 191 | }
|
236 | 192 | } else {
|
237 |
| - syn::parse_quote! { |
238 |
| - { |
239 |
| - let slice = crate::utils::validate_slice(#data_ident as *const _, #length).ok_or(AeroSyscallError::EINVAL)?; |
240 |
| - &slice[0..#length] |
241 |
| - } |
242 |
| - } |
| 193 | + unimplemented!() |
243 | 194 | };
|
244 | 195 |
|
245 | 196 | result.push(array_expr);
|
|
0 commit comments