#![cfg_attr(feature = "clippy", feature(plugin))]
#![cfg_attr(feature = "clippy", plugin(clippy))]
extern crate clang;
#[macro_use]
extern crate error_chain;
extern crate glob;
#[macro_use]
extern crate lazy_static;
extern crate python_parser;
extern crate regex;
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate slog_envlogger;
extern crate snapshot;
extern crate walkdir;
extern crate yaml_rust;
pub mod analysis;
pub mod config_parser;
pub mod entity;
pub mod error;
pub mod language_type;
pub mod synthesis;
use analysis::{Analysis, ProjectFile};
use config_parser::ProjectParameters;
use error::*;
use language_type::LanguageType;
use std::path::PathBuf;
use synthesis::*;
#[derive(Default, Debug)]
pub struct Thinline<T>
where
T: LanguageType,
{
pub project_parameters: ProjectParameters,
pub analysis: Analysis<T>,
pub synthesis: Synthesis,
}
impl<T> Thinline<T>
where
T: LanguageType,
{
pub fn new() -> Self {
Self::default()
}
pub fn parse_project_config<P: Into<PathBuf>>(
&mut self,
project_dir: P,
config_name: &str,
) -> Result<()> {
let project_config = project_dir.into().join(config_name);
if !project_config.exists() || !project_config.is_file() {
return Err(Error::from(format!(
"The given project config file '{}' does not exist or is a directory.",
project_config.to_str().ok_or_else(
|| "Unable to stringify project config file.",
)?
)));
}
self.project_parameters = ProjectParameters::parse(project_config.to_str().ok_or_else(
|| "Unable to stringify project config file.",
)?)?;
println!("{:?}", self.project_parameters);
Ok(())
}
pub fn analyze_project<P: Into<PathBuf>>(&mut self, project_path: P) -> Result<()> {
self.analysis = Analysis::new();
let project_path_p = project_path.into();
if project_path_p.is_dir() {
if let Some(source_dirs) = &self.project_parameters.source_dirs {
self.analysis.collect_sources(&project_path_p, &source_dirs)?;
}
}
if project_path_p.is_file() {
if let Some(ext) = project_path_p.extension() {
if T::file_types().contains(&ext.to_str().ok_or_else(
|| "Unable to stringify file extension.",
)?)
{
self.analysis.project_files_mut().push(ProjectFile::new(
&project_path_p,
));
}
}
}
self.analysis.extract_entities()?;
Ok(())
}
}