Source

cylon / ext / clang / genjson / run.py

#!/usr/bin/env python

import os
import sys
import imp
import commands as com

try:
    import json
except ImportError:
    import simplejson as json # if that fails...
    pass

cmd = "clang -cc1 -load libclang_genjson.so -plugin print-json".split()
fname = sys.argv[-1]

cmd.append(fname)
sc,out = com.getstatusoutput(' '.join(cmd))
print out
if sc == 0:
    fname = os.path.splitext(fname)[0]
    ast_name = os.path.basename(fname) + "_ast.py"
    json_name= os.path.basename(fname) + "_ast.json"
    mod_name = os.path.splitext(os.path.basename(ast_name))[0]
    mod = imp.find_module(mod_name)
    mod = imp.load_module(mod_name, *mod)
    if os.path.exists(json_name):
        os.remove(json_name)
    json.dump({'ast': mod.ast},
              open(json_name,"w"),
              indent=2)

    ast_stream = open(ast_name, "w")
    from pprint import pprint
    pprint({'ast' : mod.ast},
           stream=ast_stream,
           indent=2)
    
sys.exit(sc)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.