parent
2cc9556dbe
commit
c9e6449292
|
@ -0,0 +1,32 @@
|
|||
use crate::error::*;
|
||||
use syn::visit_mut::VisitMut;
|
||||
use syn::Block;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Analyzer {}
|
||||
|
||||
impl Analyzer {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn analyze(&self, ast: &mut Block) -> Result<(), Error> {
|
||||
let mut child = AnalyzerImpl { error: None };
|
||||
child.visit_block_mut(ast);
|
||||
|
||||
if let Some(e) = child.error {
|
||||
Err(e)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct AnalyzerImpl {
|
||||
error: Option<Error>,
|
||||
}
|
||||
|
||||
impl VisitMut for AnalyzerImpl {
|
||||
// write code here
|
||||
}
|
|
@ -5,6 +5,7 @@ use std::path::{Path, PathBuf};
|
|||
use std::sync::Arc;
|
||||
use syn::Block;
|
||||
|
||||
use crate::analyzer::Analyzer;
|
||||
use crate::config::Config;
|
||||
use crate::error::*;
|
||||
use crate::optimizer::Optimizer;
|
||||
|
@ -57,6 +58,7 @@ impl Compiler {
|
|||
});
|
||||
|
||||
let resolver = Resolver::new().include_handler(include_handler);
|
||||
let analyzer = Analyzer::new();
|
||||
let optimizer = Optimizer::new().rm_whitespace(self.config.rm_whitespace);
|
||||
|
||||
let compile_file = |input: &Path,
|
||||
|
@ -68,6 +70,7 @@ impl Compiler {
|
|||
let r = resolver.resolve(&*input, &mut tsource.ast)?;
|
||||
report.deps = r.deps;
|
||||
|
||||
analyzer.analyze(&mut tsource.ast)?;
|
||||
optimizer.optimize(&mut tsource.ast);
|
||||
|
||||
if let Some(parent) = output.parent() {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#[macro_use]
|
||||
mod error;
|
||||
|
||||
mod analyzer;
|
||||
mod compiler;
|
||||
mod config;
|
||||
mod optimizer;
|
||||
|
|
Loading…
Reference in New Issue