diff --git a/Cargo.lock b/Cargo.lock index 80082bc..5d676dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" @@ -64,9 +64,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.38" +version = "0.4.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" dependencies = [ "android-tzdata", "iana-time-zone", @@ -101,9 +101,9 @@ dependencies = [ [[package]] name = "comfy-table" -version = "7.1.0" +version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c64043d6c7b7a4c58e39e7efccfdea7b93d885a795d0c054a69dbbf4dd52686" +checksum = "24f165e7b643266ea80cb858aed492ad9280e3e05ce24d4a99d7d7b889b6a4d9" dependencies = [ "crossterm", "strum", @@ -119,14 +119,14 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "crossterm" -version = "0.27.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df" +checksum = "829d955a0bb380ef178a640b91779e3987da38c9aea133b20614cfed8cdea9c6" dependencies = [ "bitflags 2.5.0", "crossterm_winapi", - "libc", "parking_lot", + "rustix", "winapi", ] @@ -141,9 +141,9 @@ dependencies = [ [[package]] name = "csv" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe" +checksum = "acdc4883a9c96732e4733212c01447ebd805833b7275a73ca3ee080fd77afdaf" dependencies = [ "csv-core", "itoa", @@ -160,6 +160,28 @@ dependencies = [ "memchr", ] +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "getrandom" version = "0.2.12" @@ -173,54 +195,57 @@ dependencies = [ [[package]] name = "gitql-ast" -version = "0.25.0" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccfe61481132151fdf0878c5d9dcdc8c7a99d06fbe1ccc6538c0a5ce63c6ec20" +checksum = "f85e456ba3f5ac7108b8b7de5313dbc56e2fcd660ecbfcf039ed162c64d635fd" dependencies = [ - "gitql-core", + "dyn-clone", ] [[package]] name = "gitql-cli" -version = "0.28.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef72318486c350b90cabcd5efdb7ab0c2275ba23605ff11d71c522a13545a1e8" +checksum = "cb353574238e0f6f660e456f243549682949139d5f87159fc1fcfd8625afe8af" dependencies = [ "comfy-table", + "csv", "gitql-ast", "gitql-core", "gitql-parser", + "serde_json", "termcolor", ] [[package]] name = "gitql-core" -version = "0.5.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfb7e49988ee709f5b61be226503f68cb3781832b625e3a990180d6c174f0367" +checksum = "5c1db5bc3dd9ff5a2211a8fefdcd492e6fe5bbf322d1be74adb30a2c099778d7" dependencies = [ "chrono", - "csv", - "serde_json", + "dyn-clone", + "gitql-ast", + "indexmap", + "regex", ] [[package]] name = "gitql-engine" -version = "0.28.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da75c1150718f55249af8b70fc115d9f09959661293a3af06839f8b769f1425" +checksum = "c682756bd263db67f31e4a38c721f86a7389173f865b41fc914e3c045b2447c4" dependencies = [ "chrono", "gitql-ast", "gitql-core", - "regex", ] [[package]] name = "gitql-parser" -version = "0.27.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59af3408cec8c3f63ab7a6030be1aec980ca74c1d4c0dc870790842b291db13" +checksum = "04cc210b34dd2226ab0ef2994723460afe364d012f0b4a6d0ae04d9e4fefa44e" dependencies = [ "gitql-ast", "gitql-core", @@ -228,11 +253,12 @@ dependencies = [ [[package]] name = "gitql-std" -version = "0.5.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3908a86eb9b8e36d44f1c716a317851feb9c9a2d8617de725f8d50d60dab4cca" +checksum = "2525fff4c4c6776445edb5eda534e522ebb5492d7190f53b89498abe4e5cdee1" dependencies = [ "chrono", + "gitql-ast", "gitql-core", "rand", "regex", @@ -245,11 +271,17 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" + [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "iana-time-zone" @@ -274,6 +306,16 @@ dependencies = [ "cc", ] +[[package]] +name = "indexmap" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" +dependencies = [ + "equivalent", + "hashbrown", +] + [[package]] name = "itoa" version = "1.0.11" @@ -291,9 +333,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.153" +version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" @@ -420,9 +468,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.4" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -432,9 +480,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.6" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -443,9 +491,22 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "rustix" +version = "0.38.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] [[package]] name = "rustversion" @@ -487,11 +548,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.115" +version = "1.0.134" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +checksum = "d00f4175c42ee48b15416f6193a959ba3a0d67fc699a0db9ad12df9f83991c7d" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -504,15 +566,15 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "strum" -version = "0.25.0" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" [[package]] name = "strum_macros" -version = "0.25.3" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ "heck", "proc-macro2", @@ -549,15 +611,15 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-width" -version = "0.1.11" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" [[package]] name = "uuid" -version = "1.8.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" +checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" dependencies = [ "getrandom", ] @@ -662,6 +724,15 @@ dependencies = [ "windows-targets 0.52.4", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.4", +] + [[package]] name = "windows-targets" version = "0.48.5" diff --git a/Cargo.toml b/Cargo.toml index 00017bd..c70c839 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,10 +13,10 @@ categories = ["command-line-utilities"] exclude = [".github/**", "docs/**", "media/**", "scripts/**"] [dependencies] -gitql-core = "0.5.0" -gitql-std = "0.5.0" -gitql-cli = "0.28.0" -gitql-ast = "0.25.0" -gitql-parser = "0.27.0" -gitql-engine = "0.28.0" +gitql-core = "0.12.0" +gitql-std = "0.12.0" +gitql-cli = "0.35.0" +gitql-ast = "0.31.0" +gitql-parser = "0.34.0" +gitql-engine = "0.35.0" clang-sys = "1.8.1" diff --git a/samples/Main.cpp b/samples/Main.cpp new file mode 100644 index 0000000..9771496 --- /dev/null +++ b/samples/Main.cpp @@ -0,0 +1,4 @@ + +int add(int a, int b) { return a + b; } + +double add(double a, double b) { return a + b; } \ No newline at end of file diff --git a/src/data_provider.rs b/src/data_provider.rs index 34fc47f..c92cc91 100644 --- a/src/data_provider.rs +++ b/src/data_provider.rs @@ -1,7 +1,11 @@ use std::vec; use gitql_core::object::Row; -use gitql_core::value::Value; +use gitql_core::values::base::Value; +use gitql_core::values::boolean::BoolValue; +use gitql_core::values::integer::IntValue; +use gitql_core::values::null::NullValue; +use gitql_core::values::text::TextValue; use gitql_engine::data_provider::DataProvider; use crate::visitor::class; @@ -40,7 +44,7 @@ fn select_clang_ast_objects( ) -> Result, String> { let rows = match table { "classes" => select_classes(path, selected_columns)?, - "enums" => select_enumss(path, selected_columns)?, + "enums" => select_enums(path, selected_columns)?, "unions" => select_unions(path, selected_columns)?, "functions" => select_functions(path, selected_columns)?, "globals" => select_variables(path, selected_columns)?, @@ -53,65 +57,69 @@ fn select_classes(path: &str, selected_columns: &[String]) -> Result, S let mut rows: Vec = vec![]; let ast_classes = class::select_clang_classes(path); for class in ast_classes.iter() { - let mut values: Vec = Vec::with_capacity(selected_columns.len()); + let mut values: Vec> = Vec::with_capacity(selected_columns.len()); for field_name in selected_columns { if field_name == "name" { - values.push(Value::Text(class.name.to_owned())); + values.push(Box::new(TextValue::new(class.name.to_owned()))); continue; } if field_name == "bases_count" { - values.push(Value::Integer(class.attributes.bases_count.into())); + values.push(Box::new(IntValue::new(class.attributes.bases_count.into()))); continue; } if field_name == "methods_count" { - values.push(Value::Integer(class.attributes.methods_count.into())); + values.push(Box::new(IntValue::new( + class.attributes.methods_count.into(), + ))); continue; } if field_name == "fields_count" { - values.push(Value::Integer(class.attributes.fields_count.into())); + values.push(Box::new(IntValue::new( + class.attributes.fields_count.into(), + ))); continue; } if field_name == "is_struct" { - values.push(Value::Boolean(class.is_struct)); + values.push(Box::new(BoolValue::new(class.is_struct))); continue; } if field_name == "size" { - values.push(Value::Integer(class.size)); + values.push(Box::new(IntValue::new(class.size))); continue; } if field_name == "align" { - values.push(Value::Integer(class.align)); + values.push(Box::new(IntValue::new(class.align))); continue; } if field_name == "file" { - values.push(Value::Text(class.location.file.to_string())); + values.push(Box::new(TextValue::new(class.location.file.to_string()))); continue; } if field_name == "line" { - values.push(Value::Integer(class.location.line.into())); + values.push(Box::new(IntValue::new(class.location.line.into()))); continue; } if field_name == "column" { - values.push(Value::Integer(class.location.column.into())); + values.push(Box::new(IntValue::new(class.location.column.into()))); continue; } if field_name == "offset" { - values.push(Value::Integer(class.location.offset.into())); + values.push(Box::new(IntValue::new(class.location.offset.into()))); continue; } - values.push(Value::Null); + values.push(Box::new(NullValue)); } let row = Row { values }; @@ -121,51 +129,52 @@ fn select_classes(path: &str, selected_columns: &[String]) -> Result, S Ok(rows) } -fn select_enumss(path: &str, selected_columns: &[String]) -> Result, String> { +fn select_enums(path: &str, selected_columns: &[String]) -> Result, String> { let mut rows: Vec = vec![]; let ast_enums = enumeration::select_clang_enums(path); for enumeration in ast_enums.iter() { - let mut values: Vec = Vec::with_capacity(selected_columns.len()); + let mut values: Vec> = Vec::with_capacity(selected_columns.len()); for field_name in selected_columns { if field_name == "name" { - values.push(Value::Text(enumeration.name.to_owned())); + values.push(Box::new(TextValue::new(enumeration.name.to_owned()))); continue; } if field_name == "constants_count" { - values.push(Value::Integer( - enumeration.attributes.constants_count.into(), - )); + let value = enumeration.attributes.constants_count.into(); + values.push(Box::new(IntValue::new(value))); continue; } if field_name == "type_literal" { - values.push(Value::Text(enumeration.type_literal.to_string())); + let value = Box::new(TextValue::new(enumeration.type_literal.to_owned())); + values.push(value); continue; } if field_name == "file" { - values.push(Value::Text(enumeration.location.file.to_string())); + let value = Box::new(TextValue::new(enumeration.location.file.to_owned())); + values.push(value); continue; } if field_name == "line" { - values.push(Value::Integer(enumeration.location.line.into())); + values.push(Box::new(IntValue::new(enumeration.location.line.into()))); continue; } if field_name == "column" { - values.push(Value::Integer(enumeration.location.column.into())); + values.push(Box::new(IntValue::new(enumeration.location.column.into()))); continue; } if field_name == "offset" { - values.push(Value::Integer(enumeration.location.offset.into())); + values.push(Box::new(IntValue::new(enumeration.location.offset.into()))); continue; } - values.push(Value::Null); + values.push(Box::new(NullValue)); } let row = Row { values }; @@ -179,45 +188,47 @@ fn select_unions(path: &str, selected_columns: &[String]) -> Result, St let mut rows: Vec = vec![]; let ast_unions = unions::select_clang_unions(path); for union_node in ast_unions.iter() { - let mut values: Vec = Vec::with_capacity(selected_columns.len()); + let mut values: Vec> = Vec::with_capacity(selected_columns.len()); for field_name in selected_columns { if field_name == "name" { - values.push(Value::Text(union_node.name.to_owned())); + values.push(Box::new(TextValue::new(union_node.name.to_owned()))); continue; } if field_name == "fields_count" { - values.push(Value::Integer(union_node.attributes.fields_count.into())); + let value = union_node.attributes.fields_count.into(); + values.push(Box::new(IntValue::new(value))); continue; } if field_name == "size" { - values.push(Value::Integer(union_node.size)); + values.push(Box::new(IntValue::new(union_node.size))); continue; } if field_name == "file" { - values.push(Value::Text(union_node.location.file.to_string())); + let value = Box::new(TextValue::new(union_node.location.file.to_owned())); + values.push(value); continue; } if field_name == "line" { - values.push(Value::Integer(union_node.location.line.into())); + values.push(Box::new(IntValue::new(union_node.location.line.into()))); continue; } if field_name == "column" { - values.push(Value::Integer(union_node.location.column.into())); + values.push(Box::new(IntValue::new(union_node.location.column.into()))); continue; } if field_name == "offset" { - values.push(Value::Integer(union_node.location.offset.into())); + values.push(Box::new(IntValue::new(union_node.location.offset.into()))); continue; } - values.push(Value::Null); + values.push(Box::new(NullValue)); } let row = Row { values }; @@ -231,95 +242,95 @@ fn select_functions(path: &str, selected_columns: &[String]) -> Result, let mut rows: Vec = vec![]; let ast_functions = function::select_clang_functions(path); for function in ast_functions.iter() { - let mut values: Vec = Vec::with_capacity(selected_columns.len()); + let mut values: Vec> = Vec::with_capacity(selected_columns.len()); for field_name in selected_columns { if field_name == "name" { - values.push(Value::Text(function.name.to_owned())); + values.push(Box::new(TextValue::new(function.name.to_owned()))); continue; } if field_name == "signature" { - values.push(Value::Text(function.signature.to_owned())); + values.push(Box::new(TextValue::new(function.signature.to_owned()))); continue; } if field_name == "args_count" { - values.push(Value::Integer(function.arguments_count as i64)); + values.push(Box::new(IntValue::new(function.arguments_count as i64))); continue; } if field_name == "class_name" { - values.push(Value::Text(function.class_name.to_owned())); + values.push(Box::new(TextValue::new(function.class_name.to_owned()))); continue; } if field_name == "return_type" { - values.push(Value::Text(function.return_type.to_owned())); + values.push(Box::new(TextValue::new(function.return_type.to_owned()))); continue; } if field_name == "is_method" { - values.push(Value::Boolean(function.is_method)); + values.push(Box::new(BoolValue::new(function.is_method))); continue; } if field_name == "is_virtual" { - values.push(Value::Boolean(function.is_virtual)); + values.push(Box::new(BoolValue::new(function.is_virtual))); continue; } if field_name == "is_pure_virtual" { - values.push(Value::Boolean(function.is_pure_virtual)); + values.push(Box::new(BoolValue::new(function.is_pure_virtual))); continue; } if field_name == "is_static" { - values.push(Value::Boolean(function.is_static)); + values.push(Box::new(BoolValue::new(function.is_static))); continue; } if field_name == "is_const" { - values.push(Value::Boolean(function.is_const)); + values.push(Box::new(BoolValue::new(function.is_const))); continue; } if field_name == "has_template" { - values.push(Value::Boolean(function.has_template)); + values.push(Box::new(BoolValue::new(function.has_template))); continue; } if field_name == "access_modifier" { - values.push(Value::Integer(function.access_modifier as i64)); + values.push(Box::new(IntValue::new(function.access_modifier as i64))); continue; } if field_name == "is_variadic" { - values.push(Value::Boolean(function.is_variadic)); + values.push(Box::new(BoolValue::new(function.is_variadic))); continue; } if field_name == "file" { - values.push(Value::Text(function.location.file.to_string())); + values.push(Box::new(TextValue::new(function.location.file.to_owned()))); continue; } if field_name == "line" { - values.push(Value::Integer(function.location.line as i64)); + values.push(Box::new(IntValue::new(function.location.line.into()))); continue; } if field_name == "column" { - values.push(Value::Integer(function.location.column as i64)); + values.push(Box::new(IntValue::new(function.location.column.into()))); continue; } if field_name == "offset" { - values.push(Value::Integer(function.location.offset as i64)); + values.push(Box::new(IntValue::new(function.location.offset.into()))); continue; } - values.push(Value::Null); + values.push(Box::new(NullValue)); } let row = Row { values }; @@ -333,44 +344,44 @@ fn select_variables(path: &str, selected_columns: &[String]) -> Result, let mut rows: Vec = vec![]; let ast_variables = global::select_clang_variables(path); for variable in ast_variables.iter() { - let mut values: Vec = Vec::with_capacity(selected_columns.len()); + let mut values: Vec> = Vec::with_capacity(selected_columns.len()); for field_name in selected_columns { if field_name == "name" { - values.push(Value::Text(variable.name.to_owned())); + values.push(Box::new(TextValue::new(variable.name.to_owned()))); continue; } if field_name == "type" { - values.push(Value::Text(variable.type_literal.to_owned())); + values.push(Box::new(TextValue::new(variable.type_literal.to_owned()))); continue; } if field_name == "is_volatile" { - values.push(Value::Boolean(variable.is_volatile)); + values.push(Box::new(BoolValue::new(variable.is_volatile))); continue; } if field_name == "file" { - values.push(Value::Text(variable.location.file.to_string())); + values.push(Box::new(TextValue::new(variable.location.file.to_string()))); continue; } if field_name == "line" { - values.push(Value::Integer(variable.location.line as i64)); + values.push(Box::new(IntValue::new(variable.location.line as i64))); continue; } if field_name == "column" { - values.push(Value::Integer(variable.location.column as i64)); + values.push(Box::new(IntValue::new(variable.location.column as i64))); continue; } if field_name == "offset" { - values.push(Value::Integer(variable.location.offset as i64)); + values.push(Box::new(IntValue::new(variable.location.offset as i64))); continue; } - values.push(Value::Null); + values.push(Box::new(NullValue)); } let row = Row { values }; diff --git a/src/main.rs b/src/main.rs index aa0a27d..9be484b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,18 +8,23 @@ use data_provider::ClangAstDataProvider; use gitql_cli::arguments::OutputFormat; use gitql_cli::diagnostic_reporter; use gitql_cli::diagnostic_reporter::DiagnosticReporter; -use gitql_cli::render; +use gitql_cli::printer::base::OutputPrinter; +use gitql_cli::printer::csv_printer::CSVPrinter; +use gitql_cli::printer::json_printer::JSONPrinter; +use gitql_cli::printer::table_printer::TablePrinter; use gitql_core::environment::Environment; use gitql_core::schema::Schema; use gitql_engine::data_provider::DataProvider; use gitql_engine::engine; use gitql_parser::diagnostic::Diagnostic; use gitql_parser::parser; -use gitql_parser::tokenizer; +use gitql_parser::tokenizer::Tokenizer; use gitql_std::aggregation::aggregation_function_signatures; use gitql_std::aggregation::aggregation_functions; -use gitql_std::function::standard_function_signatures; -use gitql_std::function::standard_functions; +use gitql_std::standard::standard_function_signatures; +use gitql_std::standard::standard_functions; +use gitql_std::window::window_function_signatures; +use gitql_std::window::window_functions; use schema::tables_fields_names; use schema::tables_fields_types; @@ -57,9 +62,13 @@ fn main() { let aggregation_signatures = aggregation_function_signatures(); let aggregation_functions = aggregation_functions(); + let window_signatures = window_function_signatures(); + let window_function = window_functions(); + let mut env = Environment::new(schema); - env.with_standard_functions(std_signatures, std_functions); - env.with_aggregation_functions(aggregation_signatures, aggregation_functions); + env.with_standard_functions(&std_signatures, std_functions); + env.with_aggregation_functions(&aggregation_signatures, aggregation_functions); + env.with_window_functions(&window_signatures, window_function); execute_clangql_query(query, &arguments, files, &mut env, &mut reporter); } @@ -94,9 +103,13 @@ fn launch_clangql_repl(arguments: Arguments) { let aggregation_signatures = aggregation_function_signatures(); let aggregation_functions = aggregation_functions(); + let window_signatures = window_function_signatures(); + let window_function = window_functions(); + let mut global_env = Environment::new(schema); - global_env.with_standard_functions(std_signatures, std_functions); - global_env.with_aggregation_functions(aggregation_signatures, aggregation_functions); + global_env.with_standard_functions(&std_signatures, std_functions); + global_env.with_aggregation_functions(&aggregation_signatures, aggregation_functions); + global_env.with_window_functions(&window_signatures, window_function); let mut input = String::new(); @@ -150,7 +163,7 @@ fn execute_clangql_query( reporter: &mut DiagnosticReporter, ) { let front_start = std::time::Instant::now(); - let tokenizer_result = tokenizer::tokenize(query.clone()); + let tokenizer_result = Tokenizer::tokenize(query.clone()); if tokenizer_result.is_err() { let diagnostic = tokenizer_result.err().unwrap(); reporter.report_diagnostic(&query, *diagnostic); @@ -188,34 +201,34 @@ fn execute_clangql_query( } // Render the result only if they are selected groups not any other statement - let engine_result = evaluation_result.ok().unwrap(); - if let SelectedGroups(mut groups) = engine_result { - match arguments.output_format { - OutputFormat::Render => { - render::render_objects(&mut groups, arguments.pagination, arguments.page_size); - } - OutputFormat::JSON => { - if let Ok(json) = groups.as_json() { - println!("{}", json); - } - } - OutputFormat::CSV => { - if let Ok(csv) = groups.as_csv() { - println!("{}", csv); - } - } + let engine_duration = engine_start.elapsed(); + + let printer: Box = match arguments.output_format { + OutputFormat::Render => { + Box::new(TablePrinter::new(arguments.pagination, arguments.page_size)) } - } + OutputFormat::JSON => Box::new(JSONPrinter {}), + OutputFormat::CSV => Box::new(CSVPrinter {}), + }; - let engine_duration = engine_start.elapsed(); + // Render the result only if they are selected groups not any other statement + let evaluations_results = evaluation_result.ok().unwrap(); + for evaluation_result in evaluations_results { + let mut rows_count = 0; + if let SelectedGroups(mut groups) = evaluation_result { + if !groups.is_empty() { + rows_count += groups.groups[0].len(); + printer.print(&mut groups); + } + } - if arguments.analysis { - println!("\n"); - println!("Analysis:"); - println!("Frontend : {:?}", front_duration); - println!("Engine : {:?}", engine_duration); - println!("Total : {:?}", (front_duration + engine_duration)); - println!("\n"); + if arguments.analysis { + let total_time = front_duration + engine_duration; + println!( + "{} row in set (total: {:?}, front: {:?}, engine: {:?})", + rows_count, total_time, front_duration, engine_duration + ); + } } } diff --git a/src/schema.rs b/src/schema.rs index 1ea6018..4d9d6ae 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -1,47 +1,48 @@ -use gitql_core::types::DataType; use std::collections::HashMap; use std::sync::OnceLock; -pub fn tables_fields_types() -> &'static HashMap<&'static str, DataType> { - static HASHMAP: OnceLock> = OnceLock::new(); - HASHMAP.get_or_init(|| { - let mut map = HashMap::new(); - map.insert("name", DataType::Text); - map.insert("type", DataType::Text); - map.insert("signature", DataType::Text); - map.insert("class_name", DataType::Text); +use gitql_ast::types::base::DataType; +use gitql_ast::types::boolean::BoolType; +use gitql_ast::types::integer::IntType; +use gitql_ast::types::text::TextType; - map.insert("access_modifier", DataType::Integer); +pub fn tables_fields_types() -> HashMap<&'static str, Box> { + let mut map: HashMap<&'static str, Box> = HashMap::new(); + map.insert("name", Box::new(TextType)); + map.insert("type", Box::new(TextType)); + map.insert("signature", Box::new(TextType)); + map.insert("class_name", Box::new(TextType)); - map.insert("is_method", DataType::Boolean); - map.insert("is_virtual", DataType::Boolean); - map.insert("is_pure_virtual", DataType::Boolean); - map.insert("is_static", DataType::Boolean); - map.insert("is_const", DataType::Boolean); - map.insert("is_variadic", DataType::Boolean); - map.insert("is_volatile", DataType::Boolean); - map.insert("is_struct", DataType::Boolean); - map.insert("has_template", DataType::Boolean); + map.insert("access_modifier", Box::new(IntType)); - map.insert("return_type", DataType::Text); - map.insert("type_literal", DataType::Text); + map.insert("is_method", Box::new(BoolType)); + map.insert("is_virtual", Box::new(BoolType)); + map.insert("is_pure_virtual", Box::new(BoolType)); + map.insert("is_static", Box::new(BoolType)); + map.insert("is_const", Box::new(BoolType)); + map.insert("is_variadic", Box::new(BoolType)); + map.insert("is_volatile", Box::new(BoolType)); + map.insert("is_struct", Box::new(BoolType)); + map.insert("has_template", Box::new(BoolType)); - map.insert("args_count", DataType::Integer); - map.insert("bases_count", DataType::Integer); - map.insert("methods_count", DataType::Integer); - map.insert("fields_count", DataType::Integer); - map.insert("constants_count", DataType::Integer); + map.insert("return_type", Box::new(TextType)); + map.insert("type_literal", Box::new(TextType)); - map.insert("size", DataType::Integer); - map.insert("align", DataType::Integer); + map.insert("args_count", Box::new(IntType)); + map.insert("bases_count", Box::new(IntType)); + map.insert("methods_count", Box::new(IntType)); + map.insert("fields_count", Box::new(IntType)); + map.insert("constants_count", Box::new(IntType)); - // Source code location columns - map.insert("file", DataType::Text); - map.insert("line", DataType::Integer); - map.insert("column", DataType::Integer); - map.insert("offset", DataType::Integer); - map - }) + map.insert("size", Box::new(IntType)); + map.insert("align", Box::new(IntType)); + + // Source code location columns + map.insert("file", Box::new(TextType)); + map.insert("line", Box::new(IntType)); + map.insert("column", Box::new(IntType)); + map.insert("offset", Box::new(IntType)); + map } pub fn tables_fields_names() -> &'static HashMap<&'static str, Vec<&'static str>> {