This commit is contained in:
nora 2022-07-24 18:22:52 +02:00
parent b74c11987b
commit 475a520de3
8 changed files with 61 additions and 8 deletions

14
Cargo.lock generated
View file

@ -21,7 +21,9 @@ dependencies = [
name = "analysis"
version = "0.1.0"
dependencies = [
"bumpalo",
"parser",
"rustc-hash",
]
[[package]]
@ -51,6 +53,12 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bumpalo"
version = "3.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3"
[[package]]
name = "cc"
version = "1.0.73"
@ -345,6 +353,12 @@ version = "0.6.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64"
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "ryu"
version = "1.0.10"

View file

@ -6,4 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
parser = { path = "../parser" }
bumpalo = "3.10.0"
parser = { path = "../parser" }
rustc-hash = "1.1.0"

7
analysis/src/hir.rs Normal file
View file

@ -0,0 +1,7 @@
pub struct Hir<'hir> {
x: &'hir (),
}
pub struct ExternalDecl;
pub struct FunctionDef;

View file

@ -1,6 +1,5 @@
#![allow(dead_code)] // TODO: no
#![warn(rust_2018_idioms)]
struct Ctx<P> {
parser: P,
}
mod hir;
mod lower;

31
analysis/src/lower.rs Normal file
View file

@ -0,0 +1,31 @@
use parser::{
ast::{self, Ident},
Span,
};
use rustc_hash::FxHashMap;
use crate::hir;
pub struct LowerCtx<'hir> {
hir_arena: &'hir bumpalo::Bump,
global_symbols: FxHashMap<Ident, &'hir hir::ExternalDecl>,
}
impl<'hir> LowerCtx<'hir> {
pub fn lower_translation_unit(&mut self, unit: &ast::TranslationUnit) -> hir::Hir<'hir> {
for decl in unit {}
todo!()
}
fn lower_decl(&mut self, decl: &ast::ExternalDecl, span: Span) -> hir::ExternalDecl {
match decl {
ast::ExternalDecl::Decl(_) => todo!(),
ast::ExternalDecl::FunctionDef(func) => todo!(),
}
}
fn lower_function_def(&mut self, def: &ast::FunctionDef, span: Span) -> hir::FunctionDef {
todo!()
}
}

View file

@ -261,4 +261,4 @@ pub enum ExternalDecl {
FunctionDef(FunctionDef),
}
pub type TranslationUnit = Vec<ExternalDecl>;
pub type TranslationUnit = Vec<Spanned<ExternalDecl>>;

View file

@ -6,7 +6,7 @@ use std::fmt::Debug;
use crate::token::Token;
mod ast;
pub mod ast;
mod parser;
mod pre;
mod pretty;

View file

@ -5,7 +5,7 @@ use crate::{
ast::{
Decl, DeclAttr, DeclSpec, Declarator, DirectDeclarator, ExternalDecl, FunctionDef,
FunctionParamDecl, Ident, InitDecl, IntTy, IntTyKind, IntTySignedness, NormalDecl, Stmt,
TypeSpecifier,
TypeSpecifier, TranslationUnit,
},
pre::Punctuator as P,
token::{Keyword as Kw, Token as Tok},
@ -567,7 +567,7 @@ where
pub fn parse_declarations<'src>(
src: impl Iterator<Item = (Tok<'src>, Span)>,
) -> Result<Vec<Spanned<ExternalDecl>>> {
) -> Result<TranslationUnit> {
use peekmore::PeekMore;
let mut parser = Parser {