forked from AbleOS/ableos
Added types
This commit is contained in:
parent
0775d0c70a
commit
d0d6f0475e
|
@ -1,4 +1,6 @@
|
||||||
mod parser;
|
mod parser;
|
||||||
|
mod types;
|
||||||
|
mod protocol;
|
||||||
|
|
||||||
use crate::idl::parser::parse;
|
use crate::idl::parser::parse;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
|
@ -2,10 +2,10 @@ use std::{iter::Peekable, slice::Iter};
|
||||||
use super::Token;
|
use super::Token;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct AST(Vec<Declaration>);
|
pub struct AST(pub Vec<Declaration>);
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
enum Declaration{
|
pub enum Declaration{
|
||||||
EnumDeclaration(EnumDeclaration),
|
EnumDeclaration(EnumDeclaration),
|
||||||
StructDeclaration(StructDeclaration),
|
StructDeclaration(StructDeclaration),
|
||||||
TypeDeclaration(TypeDeclaration),
|
TypeDeclaration(TypeDeclaration),
|
||||||
|
@ -13,40 +13,40 @@ enum Declaration{
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
struct StructDeclaration {
|
pub struct StructDeclaration {
|
||||||
name : String,
|
pub name : String,
|
||||||
members : Vec<StructMember>,
|
pub members : Vec<StructMember>,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
struct TypeDeclaration {
|
pub struct TypeDeclaration {
|
||||||
name : String,
|
pub name : String,
|
||||||
type_name : String,
|
pub type_name : String,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
struct StructMember {
|
pub struct StructMember {
|
||||||
name : String,
|
pub name : String,
|
||||||
type_name : String,
|
pub type_name : String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
struct EnumDeclaration {
|
pub struct EnumDeclaration {
|
||||||
name : String,
|
pub name : String,
|
||||||
members : Vec<EnumMember>,
|
pub members : Vec<EnumMember>,
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
struct EnumMember {
|
pub struct EnumMember {
|
||||||
name : String,
|
pub name : String,
|
||||||
number: u64,
|
pub number: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
struct ProtocolDeclaration{
|
pub struct ProtocolDeclaration{
|
||||||
name : String,
|
name : String,
|
||||||
interface : Vec<FuncDeclaration>,
|
interface : Vec<FuncDeclaration>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
struct FuncDeclaration {
|
pub struct FuncDeclaration {
|
||||||
name : String,
|
name : String,
|
||||||
arg_list : Vec<String>,
|
arg_list : Vec<String>,
|
||||||
return_type : String,
|
return_type : String,
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
pub enum ProtocolTypes {
|
pub struct Protocol {
|
||||||
Byte,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Protocol {}
|
|
||||||
impl Protocol {
|
impl Protocol {
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
true
|
true
|
||||||
|
|
75
dev/src/idl/types.rs
Normal file
75
dev/src/idl/types.rs
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use crate::idl::protocol::Protocol;
|
||||||
|
use crate::idl::parser::AST;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
enum Type {
|
||||||
|
U64,
|
||||||
|
U32,
|
||||||
|
U16,
|
||||||
|
U8,
|
||||||
|
|
||||||
|
I64,
|
||||||
|
I32,
|
||||||
|
I16,
|
||||||
|
I8,
|
||||||
|
|
||||||
|
Bool,
|
||||||
|
|
||||||
|
F32,
|
||||||
|
F64,
|
||||||
|
|
||||||
|
Struct(StructType),
|
||||||
|
Enum(EnumType),
|
||||||
|
Alias(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
struct StructType {
|
||||||
|
members : HashMap<String, String>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
struct EnumType {
|
||||||
|
members : HashMap<String, u8>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn get_protocols(ast : AST) -> Vec<Protocol> {
|
||||||
|
let protocols : Vec<Protocol> = Vec::new();
|
||||||
|
let mut symbol_table : HashMap<String, Type> = HashMap::new();
|
||||||
|
let declarations = ast.0;
|
||||||
|
// First Pass
|
||||||
|
// We just populate the symbol table here
|
||||||
|
for decl in declarations.iter() {
|
||||||
|
match decl{
|
||||||
|
super::parser::Declaration::EnumDeclaration(e) => {
|
||||||
|
let mut members = HashMap::new();
|
||||||
|
for m in e.members.iter(){
|
||||||
|
members.insert(m.name.to_string(), m.number as u8);
|
||||||
|
}
|
||||||
|
symbol_table.insert(e.name.to_string(), Type::Enum(EnumType{members}));
|
||||||
|
},
|
||||||
|
super::parser::Declaration::StructDeclaration(s) => {
|
||||||
|
let mut members = HashMap::new();
|
||||||
|
for m in s.members.iter() {
|
||||||
|
members.insert(m.name.to_string(), m.type_name.to_string());
|
||||||
|
}
|
||||||
|
symbol_table.insert(s.name.to_string(), Type::Struct(StructType{members}));
|
||||||
|
},
|
||||||
|
super::parser::Declaration::TypeDeclaration(t) => {
|
||||||
|
symbol_table.insert(t.name.to_string(), Type::Alias(t.type_name.to_string()));
|
||||||
|
},
|
||||||
|
super::parser::Declaration::ProtocolDeclaration(_) => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for decl in declarations.iter(){
|
||||||
|
match decl {
|
||||||
|
super::parser::Declaration::ProtocolDeclaration(p) => {
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protocols
|
||||||
|
}
|
Loading…
Reference in a new issue