mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-24 07:40:19 +00:00
Data structure for parsed contents of bridge module
This commit is contained in:
parent
633f5669fa
commit
00a83852cd
@ -1,7 +1,10 @@
|
||||
use crate::syntax::namespace::Namespace;
|
||||
use quote::quote;
|
||||
use syn::parse::{Error, Parse, ParseStream, Result};
|
||||
use syn::{braced, token, Attribute, Ident, Item, Token, Visibility};
|
||||
use syn::{
|
||||
braced, token, Attribute, Ident, Item as RustItem, ItemEnum, ItemForeignMod, ItemStruct,
|
||||
ItemUse, Token, Visibility,
|
||||
};
|
||||
|
||||
pub struct Module {
|
||||
pub namespace: Namespace,
|
||||
@ -14,6 +17,14 @@ pub struct Module {
|
||||
pub content: Vec<Item>,
|
||||
}
|
||||
|
||||
pub enum Item {
|
||||
Struct(ItemStruct),
|
||||
Enum(ItemEnum),
|
||||
ForeignMod(ItemForeignMod),
|
||||
Use(ItemUse),
|
||||
Other(RustItem),
|
||||
}
|
||||
|
||||
impl Parse for Module {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
let namespace = Namespace::none();
|
||||
@ -53,3 +64,16 @@ impl Parse for Module {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for Item {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
let item = input.parse()?;
|
||||
match item {
|
||||
RustItem::Struct(item) => Ok(Item::Struct(item)),
|
||||
RustItem::Enum(item) => Ok(Item::Enum(item)),
|
||||
RustItem::ForeignMod(item) => Ok(Item::ForeignMod(item)),
|
||||
RustItem::Use(item) => Ok(Item::Use(item)),
|
||||
other => Ok(Item::Other(other)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
use crate::syntax::discriminant::DiscriminantSet;
|
||||
use crate::syntax::file::Item;
|
||||
use crate::syntax::report::Errors;
|
||||
use crate::syntax::Atom::*;
|
||||
use crate::syntax::{
|
||||
@ -11,7 +12,7 @@ use syn::parse::{ParseStream, Parser};
|
||||
use syn::punctuated::Punctuated;
|
||||
use syn::{
|
||||
Abi, Attribute, Error, Fields, FnArg, ForeignItem, ForeignItemFn, ForeignItemType,
|
||||
GenericArgument, Ident, Item, ItemEnum, ItemForeignMod, ItemStruct, LitStr, Pat, PathArguments,
|
||||
GenericArgument, Ident, ItemEnum, ItemForeignMod, ItemStruct, LitStr, Pat, PathArguments,
|
||||
Result, ReturnType, Token, Type as RustType, TypeBareFn, TypePath, TypeReference, TypeSlice,
|
||||
};
|
||||
|
||||
@ -33,7 +34,7 @@ pub fn parse_items(cx: &mut Errors, items: Vec<Item>) -> Vec<Api> {
|
||||
},
|
||||
Item::ForeignMod(foreign_mod) => parse_foreign_mod(cx, foreign_mod, &mut apis),
|
||||
Item::Use(item) => cx.error(item, error::USE_NOT_ALLOWED),
|
||||
_ => cx.error(item, "unsupported item"),
|
||||
Item::Other(item) => cx.error(item, "unsupported item"),
|
||||
}
|
||||
}
|
||||
apis
|
||||
|
Loading…
Reference in New Issue
Block a user