node-castjson

A warper interface for castjson whihc is a C language project parsing C/C++ source code to AST(JSON) with LLVM libclang


Keywords
C, C++, LLVM, clang, parser, json, wraper
License
MIT
Install
npm install node-castjson@1.0.7

Documentation

README (node-castjson)

A warper interface for castjson whihc is a C language project parsing C/C++ source code to AST(JSON) with LLVM libclang.

Installation

npm install node-castjson

Quick Start

const CASTJson = require('node-castjson');

let jsonbuf = {'data': ''};
let bStatus = castJson.parse('test/sample/dirmodule.c', jsonbuf);
if (bStatus) {
    console.log(JSON.parse(jsonbuf.data));
}

Example

Input: One function in test/sample/dirmodule.c!ReadDir()

static
const FILE_ENTRY*
ReadDir(
    IN  char*   const szPath,
    IN  bool    const bRecursive
)
{
    const FILE_ENTRY* pFileEntry = NULL;
    szPath;
    bRecursive;    
    return pFileEntry;
}

Output: JSON format from castjson.exe/castjson.out utility.

{ File: 'dirmodule.c',
  Functions: [ 
     { "Name"       : "ReadDir",
       "Return"     : "const FILE_ENTRY *",
       "Parameters" : { "szPath"     : "char *const",
                        "bRecursive" : "bool" }
   ]
}

Test

$ mocha

  CAstJson class
    - getToolPath()
      √ should return true
    - parse()
      √ should return true (153ms)


  2 passing (163ms)

Resource

  1. node-castjson https://github.com/dougpuob/node-castjson.git
  2. castjson https://github.com/dougpuob/castjson.git

License

MIT