pub struct Parser<'tu> {/* private fields */ }
Expand description
Parses translation units.
Implementations§
Source§impl<'tu>Parser<'tu>
impl<'tu>Parser<'tu>
Sourcepub fncache_completion_results( &mut self, cache_completion_results:bool,) -> &mutParser<'tu>
pub fncache_completion_results( &mut self, cache_completion_results:bool,) -> &mutParser<'tu>
Sets whether certain code completion results will be cached when the translation unit isreparsed.
This option increases the time it takes to reparse the translation unit but improvescode completion performance.
Sourcepub fndetailed_preprocessing_record( &mut self, detailed_preprocessing_record:bool,) -> &mutParser<'tu>
pub fndetailed_preprocessing_record( &mut self, detailed_preprocessing_record:bool,) -> &mutParser<'tu>
Sets whether a detailed preprocessing record will be constructed which tracks all macrodefinitions and instantiations.
Sourcepub fnbriefs_in_completion_results( &mut self, briefs_in_completion_results:bool,) -> &mutParser<'tu>
pub fnbriefs_in_completion_results( &mut self, briefs_in_completion_results:bool,) -> &mutParser<'tu>
Sets whether documentation comment briefs will be included in code completion results.
Sourcepub fnincomplete(&mut self, incomplete:bool) -> &mutParser<'tu>
pub fnincomplete(&mut self, incomplete:bool) -> &mutParser<'tu>
Sets whether the translation unit will be considered incomplete.
This option suppresses certain semantic analyses and is typically used when parsingheaders with the intent of creating a precompiled header.
Sourcepub fnskip_function_bodies( &mut self, skip_function_bodies:bool,) -> &mutParser<'tu>
pub fnskip_function_bodies( &mut self, skip_function_bodies:bool,) -> &mutParser<'tu>
Sets whether function and method bodies will be skipped.
Sourcepub fnkeep_going(&mut self, keep_going:bool) -> &mutParser<'tu>
pub fnkeep_going(&mut self, keep_going:bool) -> &mutParser<'tu>
Sets whether processing will continue after a fatal error is encountered.
Sourcepub fnsingle_file_parse(&mut self, single_file_parse:bool) -> &mutParser<'tu>
pub fnsingle_file_parse(&mut self, single_file_parse:bool) -> &mutParser<'tu>
Sets whether incremental processing will be used.
Sourcepub fnlimit_skip_function_bodies_to_preamble( &mut self, limit_skip_function_bodies_to_preamble:bool,) -> &mutParser<'tu>
pub fnlimit_skip_function_bodies_to_preamble( &mut self, limit_skip_function_bodies_to_preamble:bool,) -> &mutParser<'tu>
Sets whether function bodies will only be skipped in the preamble.
Used in conjunction withskip_function_bodies
.
Sourcepub fninclude_attributed_types( &mut self, include_attributed_types:bool,) -> &mutParser<'tu>
pub fninclude_attributed_types( &mut self, include_attributed_types:bool,) -> &mutParser<'tu>
Sets whether attributed types should be included.
Sourcepub fnvisit_implicit_attributes( &mut self, visit_implicit_attributes:bool,) -> &mutParser<'tu>
pub fnvisit_implicit_attributes( &mut self, visit_implicit_attributes:bool,) -> &mutParser<'tu>
Sets whether implicit attributes should be visited.
Sourcepub fnignore_non_errors_from_included_files( &mut self, ignore_non_errors_from_included_files:bool,) -> &mutParser<'tu>
pub fnignore_non_errors_from_included_files( &mut self, ignore_non_errors_from_included_files:bool,) -> &mutParser<'tu>
Indicates that non-errors (e.g. warnings) from included files should be ignored.
Sourcepub fnretain_excluded_conditional_blocks( &mut self, retain_excluded_conditional_blocks:bool,) -> &mutParser<'tu>
pub fnretain_excluded_conditional_blocks( &mut self, retain_excluded_conditional_blocks:bool,) -> &mutParser<'tu>
Sets whether the preprocessor will retain excluded conditional blocks.
Source§impl<'tu>Parser<'tu>
impl<'tu>Parser<'tu>
Sourcepub fnarguments<S:AsRef<str>>(&mut self, arguments: &[S]) -> &mutParser<'tu>
pub fnarguments<S:AsRef<str>>(&mut self, arguments: &[S]) -> &mutParser<'tu>
Sets the compiler arguments to provide tolibclang
.
Any compiler argument that could be supplied toclang
may be supplied to thisfunction. However, the following arguments are ignored:
-c
-emit-ast
-fsyntax-only
-o
and the following<output>
Sourcepub fnunsaved(&mut self, unsaved: &[Unsaved]) -> &mutParser<'tu>
pub fnunsaved(&mut self, unsaved: &[Unsaved]) -> &mutParser<'tu>
Sets the unsaved files to use.
Sourcepub fnparse(&self) ->Result<TranslationUnit<'tu>,SourceError>
pub fnparse(&self) ->Result<TranslationUnit<'tu>,SourceError>
Parses a translation unit.
§Failures
- an error occurs while deserializing an AST file
libclang
crashes- an unknown error occurs
Examples found in repository?
5fnmain() {6// Acquire an instance of `Clang`7letclang = Clang::new().unwrap();89// Create a new `Index`10letindex = Index::new(&clang,false,false);1112// Parse a source file into a translation unit13lettu = index.parser("examples/structs.c").parse().unwrap();1415// Get the structs in this translation unit16letstructs = tu.get_entity().get_children().into_iter().filter(|e| {17 e.get_kind() == EntityKind::StructDecl18 }).collect::<Vec<_>>();1920// Print information about the structs21forstruct_instructs {22lettype_ = struct_.get_type().unwrap();23letsize = type_.get_sizeof().unwrap();24println!("struct: {:?} (size: {} bytes)", struct_.get_name().unwrap(), size);2526forfieldinstruct_.get_children() {27letname = field.get_name().unwrap();28letoffset = type_.get_offsetof(&name).unwrap();29println!(" field: {:?} (offset: {} bits)", name, offset);30 }31 }32}