|
| def | from_source (cls, filename, args=None, unsaved_files=None, options=0, index=None) |
| |
| def | from_ast_file (cls, filename, index=None) |
| |
| def | __init__ (self, ptr, index) |
| |
| def | __del__ (self) |
| |
| def | cursor (self) |
| |
| def | spelling (self) |
| |
| def | get_includes (self) |
| |
| def | get_file (self, filename) |
| |
| def | get_location (self, filename, position) |
| |
| def | get_extent (self, filename, locations) |
| |
| def | diagnostics (self) |
| |
| def | reparse (self, unsaved_files=None, options=0) |
| |
| def | save (self, filename) |
| |
| def | codeComplete (self, path, line, column, unsaved_files=None, include_macros=False, include_code_patterns=False, include_brief_comments=False) |
| |
| def | get_tokens (self, locations=None, extent=None) |
| |
| def | __init__ (self, obj) |
| |
| def | from_param (self) |
| |
Represents a source code translation unit.
This is one of the main types in the API. Any time you wish to interact
with Clang's representation of a source file, you typically start with a
translation unit.
Definition at line 2421 of file cindex.py.
| def from_source |
( |
|
cls, |
|
|
|
filename, |
|
|
|
args = None, |
|
|
|
unsaved_files = None, |
|
|
|
options = 0, |
|
|
|
index = None |
|
) |
| |
Create a TranslationUnit by parsing source.
This is capable of processing source code both from files on the
filesystem as well as in-memory contents.
Command-line arguments that would be passed to clang are specified as
a list via args. These can be used to specify include paths, warnings,
etc. e.g. ["-Wall", "-I/path/to/include"].
In-memory file content can be provided via unsaved_files. This is an
iterable of 2-tuples. The first element is the str filename. The
second element defines the content. Content can be provided as str
source code or as file objects (anything with a read() method). If
a file object is being used, content will be read until EOF and the
read cursor will not be reset to its original position.
options is a bitwise or of TranslationUnit.PARSE_XXX flags which will
control parsing behavior.
index is an Index instance to utilize. If not provided, a new Index
will be created for this TranslationUnit.
To parse source from the filesystem, the filename of the file to parse
is specified by the filename argument. Or, filename could be None and
the args list would contain the filename(s) to parse.
To parse source from an in-memory buffer, set filename to the virtual
filename you wish to associate with this source (e.g. "test.c"). The
contents of that file are then provided in unsaved_files.
If an error occurs, a TranslationUnitLoadError is raised.
Please note that a TranslationUnit with parser errors may be returned.
It is the caller's responsibility to check tu.diagnostics for errors.
Also note that Clang infers the source language from the extension of
the input filename. If you pass in source code containing a C++ class
declaration with the filename "test.c" parsing will fail.
Definition at line 2462 of file cindex.py.
| def get_extent |
( |
|
self, |
|
|
|
filename, |
|
|
|
locations |
|
) |
| |
Obtain a SourceRange from this translation unit.
The bounds of the SourceRange must ultimately be defined by a start and
end SourceLocation. For the locations argument, you can pass:
- 2 SourceLocation instances in a 2-tuple or list.
- 2 int file offsets via a 2-tuple or list.
- 2 2-tuple or lists of (line, column) pairs in a 2-tuple or list.
e.g.
get_extent('foo.c', (5, 10))
get_extent('foo.c', ((1, 1), (1, 15)))
Definition at line 2626 of file cindex.py.
| def save |
( |
|
self, |
|
|
|
filename |
|
) |
| |
Saves the TranslationUnit to a file.
This is equivalent to passing -emit-ast to the clang frontend. The
saved file can be loaded back into a TranslationUnit. Or, if it
corresponds to a header, it can be used as a pre-compiled header file.
If an error occurs while saving, a TranslationUnitSaveError is raised.
If the error was TranslationUnitSaveError.ERROR_INVALID_TU, this means
the constructed TranslationUnit was not valid at time of save. In this
case, the reason(s) why should be available via
TranslationUnit.diagnostics().
filename -- The path to save the translation unit to.
Definition at line 2715 of file cindex.py.