Node module for static analysis of programs written in C programming language. Right now it supports only single file C programs.
So far it can provide following information from a given source code -
- Symbol Table
- Call Graph
- Statement List
For lexing purpose node-c-lexer
is used.
Before tokenizing the source code node-c-lexer
assumes that all preprocessors are removed.
To remove the preprocessor it provides an API also.
If preprocessor free code is given then there is no dependency.
But if preprocessor is to be removed with node-c-lexer
then it requires that the commandcpp
is in the PATH.
Install the module with npm
npm install node-c-analyzer
Require the module
var analyzer = require("node-c-analyzer");
Get the lexer and parser; remove preprocessors; tokenize source code; parse token stream.
var parser = analyzer.parser;
var lexer = parser.lexer;
lexer.cppUnit.clearPreprocessors("./codefile.c", function(err, codeText){
if(err){
res.send({"error": err});
}
else{
var tokens = lexer.lexUnit.tokenize(codeText);
var parse_tree = parser.parse(tokens);
}
});
Call appropriate function of appropriate analyzer with the parse tree.
var symbol_table = analyzer.symbol_table_analyzer.get_symbol_table(parse_tree);
Module consists of following three analyzers -
Available API list -
get_symbol_table
- Argument: Parse tree
- Returns: JSON containing details information about all the symbols used in the program
get_scope_list
- Argument: Symbol table
- Returns: JSON containing all the scopes as key value pair; where key is stringified name of the scope.
get_function_list
- Argument: Symbol table
- Returns: JSON array containing information about functions
Available API list -
get_call_graph
- Argument: Parse tree
Available API list -
get_statement_list
- Argument: Parse tree