Skip to content

Commit f7b5fae

Browse files
author
bors-servo
authored
Auto merge of #156 - fitzgen:doc-parse-mod, r=emilio
Document the `parse` module r? @emilio
2 parents e8aac63 + 7130fb3 commit f7b5fae

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

src/ir/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ impl ClangItemParser for Item {
695695
}
696696

697697
/// Parse a C++ type. If we find a reference to a type that has not been
698-
/// defined yet, use UnresolvedTypeRef as a placeholder.
698+
/// defined yet, use `UnresolvedTypeRef` as a placeholder.
699699
///
700700
/// This logic is needed to avoid parsing items with the incorrect parent
701701
/// and it's sort of complex to explain, so I'll just point to

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ macro_rules! doc_mod {
5555
mod clangll;
5656
doc_mod!(clang);
5757
doc_mod!(ir);
58-
mod parse;
58+
doc_mod!(parse);
5959
mod regex_set;
6060

6161
mod codegen {

src/parse.rs

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,90 @@
1+
//! Common traits and types related to parsing our IR from Clang cursors.
2+
13
use clang;
24
use ir::ty::TypeKind;
35
use ir::item::ItemId;
46
use ir::context::BindgenContext;
57

8+
/// Not so much an error in the traditional sense, but a control flow message
9+
/// when walking over Clang's AST with a cursor.
610
#[derive(Debug)]
711
pub enum ParseError {
12+
/// Recurse down the current AST node's children.
813
Recurse,
14+
/// Continue on to the next sibling AST node, or back up to the parent's
15+
/// siblings if we've exhausted all of this node's siblings (and so on).
916
Continue,
1017
}
1118

19+
/// The result of parsing a Clang AST node.
1220
#[derive(Debug)]
1321
pub enum ParseResult<T> {
22+
/// We've already resolved this item before, here is the extant `ItemId` for
23+
/// it.
1424
AlreadyResolved(ItemId),
25+
26+
/// This is a newly parsed item. If the cursor is `Some`, it points to the
27+
/// AST node where the new `T` was declared.
1528
New(T, Option<clang::Cursor>),
1629
}
1730

31+
/// An intermediate representation "sub-item" (i.e. one of the types contained
32+
/// inside an `ItemKind` variant) that can be parsed from a Clang cursor.
1833
pub trait ClangSubItemParser : Sized {
34+
/// Attempt to parse this type from the given cursor.
35+
///
1936
/// The fact that is a reference guarantees it's held by the context, and
2037
/// allow returning already existing types.
2138
fn parse(cursor: clang::Cursor, context: &mut BindgenContext) -> Result<ParseResult<Self>, ParseError>;
2239
}
2340

41+
/// An intermediate representation item that can be parsed from a Clang cursor.
2442
pub trait ClangItemParser: Sized {
43+
/// Parse this item from the given Clang cursor.
2544
fn parse(cursor: clang::Cursor,
2645
parent: Option<ItemId>,
2746
context: &mut BindgenContext) -> Result<ItemId, ParseError>;
47+
48+
/// Parse this item from the given Clang type.
49+
fn from_ty(ty: &clang::Type,
50+
location: Option<clang::Cursor>,
51+
parent: Option<ItemId>,
52+
ctx: &mut BindgenContext) -> Result<ItemId, ParseError>;
53+
54+
/// Identical to `from_ty`, but use the given `id` as the `ItemId` for the
55+
/// newly parsed item.
56+
fn from_ty_with_id(id: ItemId,
57+
ty: &clang::Type,
58+
location: Option<clang::Cursor>,
59+
parent: Option<ItemId>,
60+
ctx: &mut BindgenContext) -> Result<ItemId, ParseError>;
61+
62+
/// Parse this item from the given Clang type, or if we haven't resolved all
63+
/// the other items this one depends on, an unresolved reference.
2864
fn from_ty_or_ref(ty: clang::Type,
2965
location: Option<clang::Cursor>,
3066
parent_id: Option<ItemId>,
3167
context: &mut BindgenContext) -> ItemId;
68+
69+
/// Identical to `from_ty_or_ref`, but use the given `potential_id` as the
70+
/// `ItemId` for the newly parsed item.
3271
fn from_ty_or_ref_with_id(potential_id: ItemId,
3372
ty: clang::Type,
3473
location: Option<clang::Cursor>,
3574
parent_id: Option<ItemId>,
3675
context: &mut BindgenContext) -> ItemId;
37-
fn from_ty_with_id(id: ItemId,
38-
ty: &clang::Type,
39-
location: Option<clang::Cursor>,
40-
parent: Option<ItemId>,
41-
ctx: &mut BindgenContext) -> Result<ItemId, ParseError>;
42-
fn from_ty(ty: &clang::Type,
43-
location: Option<clang::Cursor>,
44-
parent: Option<ItemId>,
45-
ctx: &mut BindgenContext) -> Result<ItemId, ParseError>;
76+
77+
/// Create a named template type.
4678
fn named_type<S>(name: S, default: Option<ItemId>, parent: ItemId,
4779
context: &mut BindgenContext) -> ItemId
4880
where S: Into<String>;
81+
82+
/// Identical to `named_type`, but use `id` as the resulting item's
83+
/// `ItemId`.
4984
fn named_type_with_id<S>(id: ItemId, name: S, default: Option<ItemId>,
5085
parent: ItemId, context: &mut BindgenContext) -> ItemId
5186
where S: Into<String>;
87+
88+
/// Create a builtin type.
5289
fn builtin_type(kind: TypeKind, is_const: bool, context: &mut BindgenContext) -> ItemId;
5390
}

0 commit comments

Comments
 (0)