mirror of
https://github.com/topjohnwu/cxx.git
synced 2025-02-23 17:40:53 +00:00
Merge pull request #412 from dtolnay/sort
Perform topological sort of structs earlier during type checking
This commit is contained in:
commit
0acfc126c7
@ -12,7 +12,6 @@ pub(super) mod include;
|
||||
mod namespace;
|
||||
mod nested;
|
||||
pub(super) mod out;
|
||||
mod toposort;
|
||||
mod write;
|
||||
|
||||
pub(super) use self::error::Error;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::gen::block::Block;
|
||||
use crate::gen::nested::NamespaceEntries;
|
||||
use crate::gen::out::OutFile;
|
||||
use crate::gen::{builtin, include, toposort, Opt};
|
||||
use crate::gen::{builtin, include, Opt};
|
||||
use crate::syntax::atom::Atom::{self, *};
|
||||
use crate::syntax::symbol::Symbol;
|
||||
use crate::syntax::{
|
||||
@ -96,7 +96,7 @@ fn write_data_structures<'a>(out: &mut OutFile<'a>, apis: &'a [Api]) {
|
||||
}
|
||||
}
|
||||
|
||||
for strct in toposort::sort(apis, out.types) {
|
||||
for strct in &out.types.toposorted_structs {
|
||||
out.next_section();
|
||||
if !out.types.cxx.contains(&strct.name.rust) {
|
||||
write_struct(out, strct);
|
||||
|
@ -20,6 +20,7 @@ pub mod report;
|
||||
pub mod set;
|
||||
pub mod symbol;
|
||||
mod tokens;
|
||||
mod toposort;
|
||||
pub mod types;
|
||||
|
||||
use self::discriminant::Discriminant;
|
||||
|
@ -3,7 +3,8 @@ use crate::syntax::improper::ImproperCtype;
|
||||
use crate::syntax::report::Errors;
|
||||
use crate::syntax::set::OrderedSet as Set;
|
||||
use crate::syntax::{
|
||||
Api, Derive, Enum, ExternFn, ExternType, Impl, Pair, ResolvableName, Struct, Type, TypeAlias,
|
||||
toposort, Api, Derive, Enum, ExternFn, ExternType, Impl, Pair, ResolvableName, Struct, Type,
|
||||
TypeAlias,
|
||||
};
|
||||
use proc_macro2::Ident;
|
||||
use quote::ToTokens;
|
||||
@ -21,6 +22,7 @@ pub struct Types<'a> {
|
||||
pub explicit_impls: Set<&'a Impl>,
|
||||
pub resolutions: Map<&'a Ident, &'a Pair>,
|
||||
pub struct_improper_ctypes: UnorderedSet<&'a Ident>,
|
||||
pub toposorted_structs: Vec<&'a Struct>,
|
||||
}
|
||||
|
||||
impl<'a> Types<'a> {
|
||||
@ -35,6 +37,7 @@ impl<'a> Types<'a> {
|
||||
let mut explicit_impls = Set::new();
|
||||
let mut resolutions = Map::new();
|
||||
let struct_improper_ctypes = UnorderedSet::new();
|
||||
let toposorted_structs = Vec::new();
|
||||
|
||||
fn visit<'a>(all: &mut Set<&'a Type>, ty: &'a Type) {
|
||||
all.insert(ty);
|
||||
@ -205,8 +208,11 @@ impl<'a> Types<'a> {
|
||||
explicit_impls,
|
||||
resolutions,
|
||||
struct_improper_ctypes,
|
||||
toposorted_structs,
|
||||
};
|
||||
|
||||
types.toposorted_structs = toposort::sort(apis, &types);
|
||||
|
||||
let mut unresolved_structs: Vec<&Ident> = types.structs.keys().copied().collect();
|
||||
let mut new_information = true;
|
||||
while new_information {
|
||||
|
Loading…
x
Reference in New Issue
Block a user