Skip to content

Commit

Permalink
Remove c parser and use the c++ one instead
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed Dec 17, 2019
1 parent 2d6c404 commit ca2ab82
Show file tree
Hide file tree
Showing 25 changed files with 16 additions and 105,102 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
[submodule "tree-sitter-c-sharp"]
path = tree-sitter-c-sharp
url = https://github.com/tree-sitter/tree-sitter-c-sharp/
[submodule "tree-sitter-c"]
path = tree-sitter-c
url = https://github.com/tree-sitter/tree-sitter-c.git
[submodule "tree-sitter-cpp"]
path = tree-sitter-cpp
url = https://github.com/tree-sitter/tree-sitter-cpp.git
1 change: 0 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ fn main() {
}
let ignore = vec![
"tree-sitter-typescript".to_string(),
"tree-sitter-c".to_string(),
"tree-sitter-cpp".to_string(),
];
let dirs = collect_tree_sitter_dirs(ignore);
Expand Down
1 change: 0 additions & 1 deletion enums/src/languages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ mk_langs!(
(Java, tree_sitter_java),
(Go, tree_sitter_go),
(Html, tree_sitter_html),
(C, tree_sitter_c),
(CSharp, tree_sitter_c_sharp),
(Rust, tree_sitter_rust),
(Css, tree_sitter_css),
Expand Down
16 changes: 0 additions & 16 deletions src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,6 @@ impl Checker for CcommentCode {
}
}

impl Checker for CCode {
mk_checker!(is_comment, Comment);
mk_checker!(is_string, StringLiteral, ConcatenatedString);
mk_checker!(is_call, CallExpression);
mk_checker!(is_func, FunctionDefinition);
mk_checker!(is_func_space, TranslationUnit);

fn is_useful_comment(node: &Node, code: &[u8]) -> bool {
lazy_static! {
static ref AC: AhoCorasick = AhoCorasick::new(vec![b"<div rustbindgen"]);
}
let code = &code[node.start_byte()..node.end_byte()];
AC.is_match(code)
}
}

impl Checker for CppCode {
mk_checker!(is_comment, Comment);
mk_checker!(
Expand Down
13 changes: 0 additions & 13 deletions src/cyclomatic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,6 @@ impl Cyclomatic for RustCode {
}
}

impl Cyclomatic for CCode {
fn compute(node: &Node, stats: &mut Stats) {
use C::*;

match node.kind_id().into() {
If | For | While | Case | ConditionalExpression | AMPAMP | PIPEPIPE => {
stats.cyclomatic += 1.;
}
_ => {}
}
}
}

impl Cyclomatic for CppCode {
fn compute(node: &Node, stats: &mut Stats) {
use Cpp::*;
Expand Down
28 changes: 0 additions & 28 deletions src/getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,34 +236,6 @@ impl Getter for RustCode {
}
}

impl Getter for CCode {
fn get_func_space_name<'a>(node: &Node, code: &'a [u8]) -> Option<&'a str> {
// we're in a function_definition so need to get the declarator
if let Some(declarator) = node.child_by_field_name("declarator") {
if let Some(fd) = declarator.first_occurence(|id| C::FunctionDeclarator == id) {
if let Some(first) = fd.child(0) {
if first.kind_id() == C::Identifier {
let code = &code[first.start_byte()..first.end_byte()];
return std::str::from_utf8(code).ok();
}
}
}
}
None
}

fn get_kind(node: &Node) -> NodeKind {
use C::*;

let typ = node.kind_id();
match typ.into() {
FunctionDefinition => NodeKind::Function,
TranslationUnit => NodeKind::Unit,
_ => NodeKind::Unknown,
}
}
}

impl Getter for CppCode {
fn get_func_space_name<'a>(node: &Node, code: &'a [u8]) -> Option<&'a str> {
let typ = node.kind_id();
Expand Down
24 changes: 0 additions & 24 deletions src/halstead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,30 +280,6 @@ impl Halstead for RustCode {
}
}

impl Halstead for CCode {
fn compute<'a>(node: &Node<'a>, code: &'a [u8], stats: &mut Stats<'a>) {
use C::*;

let id = node.kind_id();

match id.into() {
DOT | LPAREN | COMMA | STAR | GTGT | COLON | Return | Break | Continue | If | Else
| Switch | Case | Default | For | While | Goto | Do | EQ | AMPAMP | PIPEPIPE | PLUS
| PLUSPLUS | SLASH | PERCENT | PIPE | AMP | LTLT | TILDE | LT | LTEQ | EQEQ
| BANGEQ | GTEQ | GT | PLUSEQ | BANG | STAREQ | SLASHEQ | PERCENTEQ | GTGTEQ
| LTLTEQ | AMPEQ | CARET | CARETEQ | PIPEEQ | LBRACK | LBRACE | QMARK
| TypeSpecifier | Sizeof => {
*stats.operators.entry(id).or_insert(0) += 1;
}
Identifier | TypeIdentifier | FieldIdentifier | PrimitiveType | StringLiteral
| NumberLiteral | True | False | Null | DOTDOTDOT => {
*stats.operands.entry(get_id(node, code)).or_insert(0) += 1;
}
_ => {}
}
}
}

impl Halstead for CppCode {
fn compute<'a>(node: &Node<'a>, code: &'a [u8], stats: &mut Stats<'a>) {
use Cpp::*;
Expand Down
Loading

0 comments on commit ca2ab82

Please sign in to comment.