dap4/d4core/src/main/java/dap4/core/ce/CEConstraint.java
public void
    expand()
    {
        // Create a queue of unprocessed leaf compounds
        Queue<DapVariable> queue = new ArrayDeque<DapVariable>();

        for(int i = 0; i < variables.size(); i++) {
            DapVariable var = variables.get(i);
            if(!var.isTopLevel())
                continue;
            // prime the queue
            DapType base = var.getBaseType();
            if(base.getTypeSort().isCompound()) {
                DapStructure struct = (DapStructure) base; // remember Sequence subclass Structure
                if(expansionCount(struct) == 0)
                    queue.add(var);
            }
        }
        // Process the queue in prefix order
        while(queue.size() > 0) {
            DapVariable vvstruct = queue.remove();
            DapStructure dstruct = (DapStructure) vvstruct.getBaseType();
            for(DapVariable field : dstruct.getFields()) {
                if(findVariableIndex(field) < 0) {
                    // Add field as leaf
                    this.segments.add(new Segment(field));
                    this.variables.add(field);
                }
                DapType fbase = field.getBaseType();
                if(fbase.getTypeSort().isCompound()) {
                    if(expansionCount((DapStructure) fbase) == 0)
                        queue.add(field);
                }
            }
        }
        this.expansion = Expand.EXPANDED;
    }
public void
    expand()
    {
        // Create a queue of unprocessed leaf compounds
        Queue<DapVariable> queue = new ArrayDeque<DapVariable>();

        for(int i = 0; i < variables.size(); i++) {
            DapVariable var = variables.get(i);
            if(!var.isTopLevel())
                continue;
            // prime the queue
            DapType base = var.getBaseType();
            if(base.getTypeSort().isCompound()) {
                DapStructure struct = (DapStructure) base; // remember Sequence subclass Structure
                if(expansionCount(struct) == 0)
                    queue.add(var);
            }
        }
        // Process the queue in prefix order
        while(queue.size() > 0) {
            DapVariable vvstruct = queue.remove();
            DapStructure dstruct = (DapStructure) vvstruct.getBaseType();
            for(DapVariable field : dstruct.getFields()) {
                if(findVariableIndex(field) < 0) {
                    // Add field as leaf
                    this.segments.add(new Segment(field));
                    this.variables.add(field);
                }
                DapType fbase = field.getBaseType();
                if(fbase.getTypeSort().isCompound()) {
                    if(expansionCount((DapStructure) fbase) == 0)
                        queue.add(field);
                }
            }
        }
        this.expansion = Expand.EXPANDED;
    }
Locate each unexpanded Structure|Sequence and:
1. check that none of its fields is referenced => do not expand
2. add all of its fields as leaves
Note that #2 may end up adding additional leaf structs &/or seqs