Skip to content

Commit 051b16a

Browse files
author
bors-servo
authored
Auto merge of #539 - fitzgen:gotta-land-some-of-this-stuff, r=emilio
Gotta land some of this stuff... My patch queue is getting quite large, as I refactor templates in bindgen, so I figure I should land the stuff that is in good shape sooner rather than later :-P This stuff tweaks the named template parameter analysis, adds some edge kinds, stuff like that. This is still not used by codegen, yet. I have another branch where I de-dupe named types and all of that, and there is only two tests failing now, but still some clean up needed. This also contains the expanded documentation for te named template parameter analysis that I promised. See each commit message for details. r? @emilio
2 parents dd7c469 + 7e22fca commit 051b16a

File tree

7 files changed

+414
-102
lines changed

7 files changed

+414
-102
lines changed

src/ir/comp.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ impl CompInfo {
871871
}
872872

873873
impl TemplateDeclaration for CompInfo {
874-
fn template_params(&self, _ctx: &BindgenContext) -> Option<Vec<ItemId>> {
874+
fn self_template_params(&self, _ctx: &BindgenContext) -> Option<Vec<ItemId>> {
875875
if self.template_args.is_empty() {
876876
None
877877
} else {
@@ -1040,10 +1040,10 @@ impl Trace for CompInfo {
10401040
if let Some(template) = self.specialized_template() {
10411041
// This is an instantiation of a template declaration with concrete
10421042
// template type arguments.
1043-
tracer.visit(template);
1043+
tracer.visit_kind(template, EdgeKind::TemplateDeclaration);
10441044
let args = item.applicable_template_args(context);
10451045
for a in args {
1046-
tracer.visit(a);
1046+
tracer.visit_kind(a, EdgeKind::TemplateArgument);
10471047
}
10481048
} else {
10491049
let params = item.applicable_template_args(context);
@@ -1055,27 +1055,27 @@ impl Trace for CompInfo {
10551055
}
10561056

10571057
for base in self.base_members() {
1058-
tracer.visit(base.ty);
1058+
tracer.visit_kind(base.ty, EdgeKind::BaseMember);
10591059
}
10601060

10611061
for field in self.fields() {
1062-
tracer.visit(field.ty());
1062+
tracer.visit_kind(field.ty(), EdgeKind::Field);
10631063
}
10641064

10651065
for &ty in self.inner_types() {
1066-
tracer.visit(ty);
1066+
tracer.visit_kind(ty, EdgeKind::InnerType);
10671067
}
10681068

10691069
for &var in self.inner_vars() {
1070-
tracer.visit(var);
1070+
tracer.visit_kind(var, EdgeKind::InnerVar);
10711071
}
10721072

10731073
for method in self.methods() {
1074-
tracer.visit(method.signature);
1074+
tracer.visit_kind(method.signature, EdgeKind::Method);
10751075
}
10761076

10771077
for &ctor in self.constructors() {
1078-
tracer.visit(ctor);
1078+
tracer.visit_kind(ctor, EdgeKind::Constructor);
10791079
}
10801080
}
10811081
}

src/ir/context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ impl<'ctx> BindgenContext<'ctx> {
634634
.and_then(|canon_decl| {
635635
self.get_resolved_type(&canon_decl)
636636
.and_then(|template_decl_id| {
637-
template_decl_id.num_template_params(self)
637+
template_decl_id.num_self_template_params(self)
638638
.map(|num_params| {
639639
(*canon_decl.cursor(),
640640
template_decl_id,
@@ -658,7 +658,7 @@ impl<'ctx> BindgenContext<'ctx> {
658658
.cloned()
659659
})
660660
.and_then(|template_decl| {
661-
template_decl.num_template_params(self)
661+
template_decl.num_self_template_params(self)
662662
.map(|num_template_params| {
663663
(*template_decl.decl(),
664664
template_decl.id(),
@@ -706,7 +706,7 @@ impl<'ctx> BindgenContext<'ctx> {
706706
use clang_sys;
707707

708708
let num_expected_args = match self.resolve_type(template)
709-
.num_template_params(self) {
709+
.num_self_template_params(self) {
710710
Some(n) => n,
711711
None => {
712712
warn!("Tried to instantiate a template for which we could not \
@@ -1331,13 +1331,13 @@ impl PartialType {
13311331
}
13321332

13331333
impl TemplateDeclaration for PartialType {
1334-
fn template_params(&self, _ctx: &BindgenContext) -> Option<Vec<ItemId>> {
1334+
fn self_template_params(&self, _ctx: &BindgenContext) -> Option<Vec<ItemId>> {
13351335
// Maybe at some point we will eagerly parse named types, but for now we
13361336
// don't and this information is unavailable.
13371337
None
13381338
}
13391339

1340-
fn num_template_params(&self, _ctx: &BindgenContext) -> Option<usize> {
1340+
fn num_self_template_params(&self, _ctx: &BindgenContext) -> Option<usize> {
13411341
// Wouldn't it be nice if libclang would reliably give us this
13421342
// information‽
13431343
match self.decl().kind() {

src/ir/function.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use super::context::{BindgenContext, ItemId};
44
use super::dot::DotAttributes;
55
use super::item::Item;
6-
use super::traversal::{Trace, Tracer};
6+
use super::traversal::{EdgeKind, Trace, Tracer};
77
use super::ty::TypeKind;
88
use clang;
99
use clang_sys::CXCallingConv;
@@ -336,10 +336,10 @@ impl Trace for FunctionSig {
336336
fn trace<T>(&self, _: &BindgenContext, tracer: &mut T, _: &())
337337
where T: Tracer,
338338
{
339-
tracer.visit(self.return_type());
339+
tracer.visit_kind(self.return_type(), EdgeKind::FunctionReturn);
340340

341341
for &(_, ty) in self.argument_types() {
342-
tracer.visit(ty);
342+
tracer.visit_kind(ty, EdgeKind::FunctionParameter);
343343
}
344344
}
345345
}

src/ir/item.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use super::dot::{DotAttributes};
77
use super::function::Function;
88
use super::item_kind::ItemKind;
99
use super::module::Module;
10-
use super::traversal::{Trace, Tracer};
10+
use super::traversal::{EdgeKind, Trace, Tracer};
1111
use super::ty::{TemplateDeclaration, Type, TypeKind};
1212
use clang;
1313
use clang_sys;
@@ -205,7 +205,7 @@ impl Trace for Item {
205205
tracer.visit(fun.signature());
206206
}
207207
ItemKind::Var(ref var) => {
208-
tracer.visit(var.ty());
208+
tracer.visit_kind(var.ty(), EdgeKind::VarType);
209209
}
210210
ItemKind::Module(_) => {
211211
// Module -> children edges are "weak", and we do not want to
@@ -930,22 +930,22 @@ impl DotAttributes for Item {
930930
}
931931

932932
impl TemplateDeclaration for ItemId {
933-
fn template_params(&self, ctx: &BindgenContext) -> Option<Vec<ItemId>> {
933+
fn self_template_params(&self, ctx: &BindgenContext) -> Option<Vec<ItemId>> {
934934
ctx.resolve_item_fallible(*self)
935-
.and_then(|item| item.template_params(ctx))
935+
.and_then(|item| item.self_template_params(ctx))
936936
}
937937
}
938938

939939
impl TemplateDeclaration for Item {
940-
fn template_params(&self, ctx: &BindgenContext) -> Option<Vec<ItemId>> {
941-
self.kind.template_params(ctx)
940+
fn self_template_params(&self, ctx: &BindgenContext) -> Option<Vec<ItemId>> {
941+
self.kind.self_template_params(ctx)
942942
}
943943
}
944944

945945
impl TemplateDeclaration for ItemKind {
946-
fn template_params(&self, ctx: &BindgenContext) -> Option<Vec<ItemId>> {
946+
fn self_template_params(&self, ctx: &BindgenContext) -> Option<Vec<ItemId>> {
947947
match *self {
948-
ItemKind::Type(ref ty) => ty.template_params(ctx),
948+
ItemKind::Type(ref ty) => ty.self_template_params(ctx),
949949
// If we start emitting bindings to explicitly instantiated
950950
// functions, then we'll need to check ItemKind::Function for
951951
// template params.

0 commit comments

Comments
 (0)