Esempio n. 1
0
func (a *arch) AddNewObject(tree tr.TreeIf, cursor tr.Cursor, obj tr.TreeElementIf) (newCursor tr.Cursor, err error) {
	if obj == nil {
		err = fmt.Errorf("arch.AddNewObject error: nil object")
		return
	}
	switch obj.(type) {
	case pf.IOTypeIf:
		t := obj.(pf.IOTypeIf)
		_, ok := a.iotypes.Find(t.Name())
		if ok {
			err = fmt.Errorf("arch.AddNewObject warning: duplicate ioType name %s (abort)\n", t.Name())
			return
		}
		a.iotypes.Append(t.(*iotype))
		cursor.Position = len(a.IOTypes()) - 1
		newCursor = tree.Insert(cursor)
		t.AddToTree(tree, newCursor)

	case pf.ProcessIf:
		p := obj.(pf.ProcessIf)
		_, ok := a.processes.Find(p.Name())
		if ok {
			err = fmt.Errorf("arch.AddNewObject warning: duplicate process name %s (abort)\n", p.Name())
			return
		}
		a.processes.Append(p.(*process))
		newCursor = tree.Insert(cursor)
		p.AddToTree(tree, newCursor)
		//log.Printf("arch.AddNewObject: successfully added process %v\n", p)

	default:
		log.Fatalf("arch.AddNewObject error: invalid type %T\n", obj)
	}
	return
}
Esempio n. 2
0
func (l *library) AddNewObject(tree tr.TreeIf, cursor tr.Cursor, obj tr.TreeElementIf) (newCursor tr.Cursor, err error) {
	if obj == nil {
		err = fmt.Errorf("library.AddNewObject error: nil object")
		return
	}
	switch obj.(type) {
	case bh.SignalTypeIf:
		t := obj.(bh.SignalTypeIf)
		ok := l.AddSignalType(t)
		if !ok {
			err = fmt.Errorf("library.AddNewObject warning: duplicate")
			return
		}
		cursor.Position = len(l.SignalTypes()) - 1
		newCursor = tree.Insert(cursor)
		t.AddToTree(tree, newCursor)

	case bh.NodeTypeIf:
		t := obj.(bh.NodeTypeIf)
		err = l.AddNodeType(t)
		if err != nil {
			err = fmt.Errorf("library.AddNewObject error: AddNodeType failed: %s", err)
			return
		}
		newCursor = tree.Insert(cursor)
		t.AddToTree(tree, newCursor)

	default:
		log.Fatalf("library.AddNewObject error: invalid type %T\n", obj)
	}
	return
}
Esempio n. 3
0
func (p *port) treeAddNewObject(tree tr.TreeIf, cursor tr.Cursor, conn bh.ConnectionIf, otherPort bh.PortIf) (newCursor tr.Cursor) {
	newCursor = tree.Insert(cursor)
	conn.AddToTree(tree, newCursor)
	contextCursor := tree.Parent(tree.Parent(cursor))
	cCursor := tree.CursorAt(contextCursor, otherPort)
	cChild := tree.Append(cCursor)
	conn.AddToTree(tree, cChild)
	return
}
Esempio n. 4
0
func (t *nodeType) treeInstObject(tree tr.TreeIf, cursor tr.Cursor, obj tr.TreeElementIf) (newCursor tr.Cursor) {
	switch obj.(type) {
	case bh.ImplementationIf:
		impl := obj.(bh.ImplementationIf)
		// update all instance nodes in the tree with new implementation
		for _, n := range t.Instances() {
			nCursor := tree.Cursor(n)
			tCursor := tree.CursorAt(nCursor, t)
			tCursor.Position = len(t.Implementation()) - 1
			newICursor := tree.Insert(tCursor)
			impl.AddToTree(tree, newICursor)
		}

	case bh.PortTypeIf:
		pt := obj.(bh.PortTypeIf)
		// update all instance nodes in the tree with new port
		for _, n := range t.Instances() {
			var p bh.PortIf
			var ok bool
			if pt.Direction() == gr.InPort {
				p, ok, _ = n.(*node).inPort.Find(n.Name(), pt.Name())
			} else {
				p, ok, _ = n.(*node).outPort.Find(n.Name(), pt.Name())
			}
			if !ok {
				log.Fatalf("nodeType.treeInstObject error: port %s not found.\n", pt.Name())
			}
			nCursor := tree.Cursor(n)
			// Insert new port at the same position as in the type:
			// Need to deal with implementations in type VS type in node
			if cursor.Position >= 0 {
				nCursor.Position = cursor.Position - len(t.Implementation()) + 1
			}
			newNCursor := tree.Insert(nCursor)
			p.AddToTree(tree, newNCursor)
			// Update mirrored type in node:
			tCursor := tree.CursorAt(nCursor, t)
			tCursor.Position = cursor.Position
			t.treeNewObject(tree, tCursor, obj)
		}

	default:
		log.Fatalf("nodeType.AddNewObject error: invalid type %T\n", obj)
	}
	return
}
Esempio n. 5
0
func (t *nodeType) treeNewObject(tree tr.TreeIf, cursor tr.Cursor, obj tr.TreeElementIf) (newCursor tr.Cursor) {
	switch obj.(type) {
	case bh.ImplementationIf:
		cursor.Position = len(t.Implementation()) - 1
		newCursor = tree.Insert(cursor)
		obj.(bh.ImplementationIf).AddToTree(tree, newCursor)

	case bh.PortTypeIf:
		pt := obj.(bh.PortTypeIf)
		newCursor = tree.Insert(cursor)
		pt.AddToTree(tree, newCursor)
		for _, impl := range t.Implementation() {
			if impl.ImplementationType() == bh.NodeTypeGraph {
				// bh.NodeIf linked to outer port
				g := impl.Graph().(*signalGraphType)
				var n bh.NodeIf
				index := -len(t.Implementation())
				if pt.Direction() == gr.InPort {
					n = g.findInputNodeFromPortType(pt)
					if cursor.Position == tr.AppendCursor {
						index += len(g.InputNodes())
					}
				} else {
					n = g.findOutputNodeFromPortType(pt)
					if cursor.Position == tr.AppendCursor {
						index += len(g.InputNodes()) + len(g.OutputNodes())
					}
				}
				if n == nil {
					log.Fatalf("nodeType.AddNewObject error: invalid implementation...\n")
				}
				if cursor.Position != tr.AppendCursor {
					index += cursor.Position
				}
				gCursor := tree.CursorAt(cursor, impl)
				gCursor.Position = index
				n.AddToTree(tree, tree.Insert(gCursor))
			}
		}

	default:
		log.Fatalf("nodeType.AddNewObject error: invalid type %T\n", obj)
	}
	return
}
Esempio n. 6
0
func (t *signalGraphType) treeAddNewObject(tree tr.TreeIf, cursor tr.Cursor, n bh.NodeIf) (newCursor tr.Cursor) {
	newCursor = tree.Insert(cursor)
	n.AddToTree(tree, newCursor)
	return
}
Esempio n. 7
0
func (p *process) AddNewObject(tree tr.TreeIf, cursor tr.Cursor, obj tr.TreeElementIf) (newCursor tr.Cursor, err error) {
	if obj == nil {
		err = fmt.Errorf("process.AddNewObject error: %v nil object", p)
		return
	}
	switch obj.(type) {
	case pf.ChannelIf:
		c := obj.(*channel)
		c.process = p
		cLinkText := c.linkText
		link := strings.Split(cLinkText, "/")
		if len(link) != 2 {
			err = fmt.Errorf("process.AddNewObject error: %v invalid link text %s (abort)\n", p, c.linkText)
			return
		}
		archlist := p.Arch().Platform().(*platform).archlist
		aa, ok := archlist.Find(link[0])
		if !ok {
			err = fmt.Errorf("process.AddNewObject error: %v invalid link text %s: no such arch (abort)\n", p, c.linkText)
			return
		}
		var pp pf.ProcessIf
		pp, ok = aa.(*arch).processes.Find(link[1])
		if !ok {
			err = fmt.Errorf("process.AddNewObject error: %v invalid link text %s: no such process (abort)\n", p, c.linkText)
			return
		}
		var l *channelList
		var dd gr.PortDirection
		var ll *channelList
		var cPos, ccPos int
		if c.Direction() == gr.InPort {
			l = &p.inChannels
			ll = &pp.(*process).outChannels
			dd = gr.OutPort
			cPos = len(l.Channels())
			ccPos = tr.AppendCursor
		} else {
			l = &p.outChannels
			ll = &pp.(*process).inChannels
			dd = gr.InPort
			cPos = tr.AppendCursor
			ccPos = len(ll.Channels())
		}
		cName := channelMakeName(c.iotype, pp)
		_, ok = l.Find(cName)
		if ok {
			err = fmt.Errorf("process.AddNewObject warning: %v duplicate %v channel name %s/%s (abort)\n",
				p, c.Direction(), c.linkText, c.iotype.Name())
			return
		}
		ccLinkText := fmt.Sprintf("%s/%s", p.Arch().Name(), p.Name())
		ccName := channelMakeName(c.iotype, p)
		_, ok = l.Find(ccName)
		_, ok = ll.Find(cName)
		if ok {
			err = fmt.Errorf("process.AddNewObject warning: %v duplicate %v channel name %s/%s on other side (abort)\n",
				pp, dd, ccLinkText, c.iotype.Name())
			return
		}
		cc := ChannelNew(dd, c.iotype, pp, ccLinkText)
		cc.link = c
		c.link = cc
		l.Append(c)
		ll.Append(cc)
		ppCursor := tree.Cursor(pp)
		if ppCursor.Position == tr.AppendCursor {
			ppCursor.Position = ccPos
		}
		newCursor = tree.Insert(ppCursor)
		cc.AddToTree(tree, newCursor)
		if cursor.Position == tr.AppendCursor {
			cursor.Position = cPos
		}
		newCursor = tree.Insert(cursor)
		c.AddToTree(tree, newCursor)
		if p.Arch().Name() != aa.Name() {
			p.Arch().(*arch).AddArchPort(c)
			aa.(*arch).AddArchPort(cc)
		}
		//log.Printf("process.AddNewObject: %v successfully added channel %v\n", p, c)

	default:
		log.Fatalf("process.AddNewObject error: invalid type %T\n", obj)
	}
	return
}