Exemplo n.º 1
0
func appendAttrs(list ast.StmtList, attrs Attrs) ast.StmtList {
	for _, name := range attrs.SortedNames() {
		stmt := &ast.Attr{
			Field: ast.Id(name),
			Value: ast.Id(attrs[name]),
		}
		list = append(list, stmt)
	}
	return list
}
Exemplo n.º 2
0
func (this *writer) Write() *ast.Graph {
	t := &ast.Graph{}
	t.Strict = this.Strict
	t.Type = ast.GraphType(this.Directed)
	t.Id = ast.Id(this.Name)

	t.StmtList = appendAttrs(t.StmtList, this.Attrs)

	for _, edge := range this.Edges.Edges {
		holder := this.newEdgeStmt(edge)
		if holder != nil {
			t.StmtList = append(t.StmtList, this.newEdgeStmt(edge))
		}
	}

	subGraphs := this.SubGraphs.Sorted()
	for _, s := range subGraphs {
		if _, ok := this.writtenLocations[s.Name]; !ok {
			t.StmtList = append(t.StmtList, this.newSubGraph(s.Name))
		}
	}

	nodes := this.Nodes.Sorted()
	for _, n := range nodes {
		if _, ok := this.writtenLocations[n.Name]; !ok {
			t.StmtList = append(t.StmtList, this.newNodeStmt(n.Name))
		}
	}

	return t
}
Exemplo n.º 3
0
func (this *writer) newSubGraph(name string) *ast.SubGraph {
	sub := this.SubGraphs.SubGraphs[name]
	this.writtenLocations[sub.Name] = true
	s := &ast.SubGraph{}
	s.Id = ast.Id(sub.Name)
	s.StmtList = appendAttrs(s.StmtList, sub.Attrs)
	children := this.Relations.SortedChildren(name)
	for _, child := range children {
		s.StmtList = append(s.StmtList, this.newNodeStmt(child))
	}
	return s
}