Skip to content

Instantly share code, notes, and snippets.

@chikatoike
Created October 8, 2012 22:05
Show Gist options
  • Save chikatoike/3855292 to your computer and use it in GitHub Desktop.
Save chikatoike/3855292 to your computer and use it in GitHub Desktop.
clang/cindex.pyの検証コード
# -*- coding: utf-8 -*-
import sys
import os
import platform
from ctypes import *
# neocomplcache-clang付属のcindex.pyを使用する
sys.path.append(os.path.expandvars('$HOMEPATH/Dropbox/home/.vim/vundle/neocomplcache-clang/autoload/neocomplcache/sources/clang_complete'))
sys.path.append(os.path.expandvars('/mnt/hgfs/work/.vim/vundle/neocomplcache-clang/autoload/neocomplcache/sources/clang_complete'))
# clang.dllが存在するディレクトリを指定
if platform.system() == 'Windows':
sys.argv = [os.path.expandvars('$HOMEPATH/Dropbox/windows/software/bin')]
else:
sys.argv = [os.path.expandvars('$HOME/work/clang+llvm-3.1-x86-linux-ubuntu_12.04/lib')]
from clang.cindex import *
import clang.cindex
source = """\
#include <string>
struct type {
int member;
};
int
main(){
type t;
t.member = 0;
}
"""
index = Index.create()
tree = index.parse("input.cpp", unsaved_files = [ ("input.cpp", source) ])
# f = File.from_name(tree, 'input.cpp')
# print SourceLocation.from_position(tree,
# f,
# 10, 7)
currentFile = ('input.cpp', source)
complete_flags = 0
cr = tree.codeComplete('input.cpp', 10, 7, [currentFile], complete_flags)
print "\n".join(map(str, cr.results))
print "diagnostics: ", len(tree.diagnostics)
for diagnostic in tree.diagnostics:
print diagnostic
# Get include files.
for value in tree.get_includes():
# print value.source
if value.source != None:
print value.source.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment