#include "FunctionalInterface.h"
#include "GroupBlock.h"
-GroupInterface::GroupInterface(AbstractBlock* _owner, const QString& _name, int _direction, int _purpose) throw(Exception) : ConnectedInterface(_owner,_name,"expression","",_direction,_purpose) {
+GroupInterface::GroupInterface(AbstractBlock* _owner, const QString& _name, int _direction, int _purpose) throw(Exception) : ConnectedInterface(_owner,_name,_direction,_purpose,"inherited","") {
if (! _owner->isGroupBlock()) throw(Exception(BLOCK_INVALID_TYPE));
connectedFrom = NULL;
+ // force clock and reset to boolean width type instead of inherited
+ if ((purpose == Clock) || (purpose == Reset)) {
+ type = Boolean;
+ }
}
bool GroupInterface::isGroupInterface() {
AbstractInterface *GroupInterface::clone() {
GroupInterface *inter = new GroupInterface(owner,name,direction, purpose);
- inter->setWidth(width);
- inter->connectFrom(NULL);
-
+ inter->setWidth(width);
return inter;
}
+int GroupInterface::getWidth() {
+
+ bool ok;
+ int w = -1;
+
+ QString expr = width;
+
+ if (type == Boolean) {
+ return 1;
+ }
+ else if (type == Inherited) {
+ // must search from which iface it is connected.
+ ConnectedInterface* fromIface = connectedFrom;
+ while ((fromIface != NULL) && (fromIface->getType() == Inherited)) {
+ fromIface = fromIface->getConnectedFrom();
+ }
+ if (fromIface == NULL) return -1;
+ w = fromIface->getWidth();
+ }
+ return w;
+}
bool GroupInterface::canConnectTo(AbstractInterface *iface) {
3 - this is owned by a group and iface by its parent group
2.1 - this is an output, iface is an output of the group
2.2 - both are inout
+
*/
if (iface->isReferenceInterface()) return false;
- if (iface->getConnectedFrom() != NULL) return false;
+ ConnectedInterface* connIface = AI_TO_CON(iface);
+ if (connIface->getConnectedFrom() != NULL) return false;
if (this->getOwner() == iface->getOwner()->getParent()) {
if ((direction == Input) && (iface->getDirection() == Input)) return true;
if ((direction == Output) && (iface->getDirection() == Output)) return true;
if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
}
+
return false;
}
3 - this is owned by a group and iface by its parent group
2.1 - this is an input, iface is an input of the group
2.2 - both are inout
+ 4 - this is owned by top group and iface is an output of a source block
*/
if (iface->isReferenceInterface()) return false;
if (getConnectedFrom() != NULL) return false;
if ((direction == Input) && (iface->getDirection() == Input)) return true;
if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
}
+ else if ((getOwner()->isTopGroupBlock()) && (iface->getOwner()->isSourceBlock())) {
+ if ((direction == Input) && (iface->getDirection() == Output)) return true;
+ }
return false;
}