# HG changeset patch # User jeandet # Date 2014-04-21 22:25:40 # Node ID 096591f9de090a25abb7b97e868cdf7add0d7774 # Parent 0db2be5e5c439da2d39c516bb76f01bf4346c97e Netlist parsing and loading ok, get in memory abstract syntax tree and concrete tree mapping. Next step -> PCB file parsing and loading. diff --git a/qilib/qicadnetlist.cpp b/qilib/qicadnetlist.cpp --- a/qilib/qicadnetlist.cpp +++ b/qilib/qicadnetlist.cpp @@ -60,6 +60,7 @@ const char* node_c ="(no QIlib::QIcadNetList::QIcadNetList() + :netlistRoot(NULL) { } @@ -107,36 +108,23 @@ QIlib::AbstractNode *QIlib::QIcadNetList return NULL; } -/* - QString version; - QIcadNetListDesign design; - QList components; - QList libparts; - QIcadNetListLevel rootSheet; -*/ - -#define setVal(dest,node,name,index) \ - (node) = getAbstractNode((name),(index));\ - if(((node)!=NULL)&&(0<(node)->Values.count())) \ -{\ - (dest) = (node)->Values.at(0); \ - } \ - void QIlib::QIcadNetList::updateConcreteTree() { - QIlib::AbstractNode *node; - setVal(this->version,node,QIlib::Lexique::version_c,0); - setVal(this->design.date,node,QIlib::Lexique::date_c,0); - setVal(this->design.source,node,QIlib::Lexique::source_c,0); - setVal(this->design.tool,node,QIlib::Lexique::tool_c,0); - this->design.date.clear(); + if(this->rootNode.nodes.count()) + { + if(this->rootNode.nodes.at(0)->name==QIlib::Lexique::root_c) + { + if(this->netlistRoot==NULL) + { + this->netlistRoot = new QIcadNetListRoot(this->rootNode.nodes.at(0)); + } + } + } } - - QIlib::QIcadAbstractNodeWrapper::QIcadAbstractNodeWrapper(AbstractNode *node) { this->p_node = node; @@ -189,12 +177,522 @@ void QIlib::QIcadAbstractNodeWrapper::se QIlib::QIcadNetListRoot::QIcadNetListRoot(QIlib::AbstractNode *node) :QIcadAbstractNodeWrapper(node) { + this->setNode(node); +} +void QIlib::QIcadNetListRoot::setNode(QIlib::AbstractNode *node) +{ + this->p_node = node; + if(node->name==QIlib::Lexique::root_c) + { + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::design_c) + { + this->design.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::components_c) + { + this->setComponents(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::libparts_c) + { + this->setLibParts(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::libraries_c) + { + this->setLibraries(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::nets_c) + { + this->setNets(node->nodes.at(i)); + } + } + } +} + +void QIlib::QIcadNetListRoot::setComponents(QIlib::AbstractNode *node) +{ + while(components.count()) + { + QIcadNetListComponent* component; + component = components.last(); + components.removeLast(); + delete component; + } + apendComponents(node); +} + +void QIlib::QIcadNetListRoot::apendComponents(QIlib::AbstractNode *node) +{ + if(node->name==QIlib::Lexique::components_c) + { + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::component_c) + { + this->components.append(new QIcadNetListComponent(node->nodes.at(i))); + } + } + } +} + +void QIlib::QIcadNetListRoot::setLibParts(QIlib::AbstractNode *node) +{ + while(libparts.count()) + { + QIcadNetListLibPart* libpart; + libpart = libparts.last(); + libparts.removeLast(); + delete libpart; + } + apendLibParts(node); +} + +void QIlib::QIcadNetListRoot::apendLibParts(QIlib::AbstractNode *node) +{ + if(node->name==QIlib::Lexique::libparts_c) + { + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::libpart_c) + { + this->libparts.append(new QIcadNetListLibPart(node->nodes.at(i))); + } + } + } +} + +void QIlib::QIcadNetListRoot::setLibraries(QIlib::AbstractNode *node) +{ + while(libraries.count()) + { + QIcadNetListLibrary* lib; + lib = libraries.last(); + libraries.removeLast(); + delete lib; + } + apendLibraries(node); +} + +void QIlib::QIcadNetListRoot::apendLibraries(QIlib::AbstractNode *node) +{ + if(node->name==QIlib::Lexique::libraries_c) + { + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::library_c) + { + this->libraries.append(new QIcadNetListLibrary(node->nodes.at(i))); + } + } + } +} + +void QIlib::QIcadNetListRoot::setNets(QIlib::AbstractNode *node) +{ + while(nets.count()) + { + QIcadNetListNet* net; + net = nets.last(); + nets.removeLast(); + delete net; + } + apendNets(node); +} + +void QIlib::QIcadNetListRoot::apendNets(QIlib::AbstractNode *node) +{ + if(node->name==QIlib::Lexique::nets_c) + { + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::net_c) + { + this->nets.append(new QIcadNetListNet(node->nodes.at(i))); + } + } + } } QIlib::QIcadNetListComponent::QIcadNetListComponent(QIlib::AbstractNode *node) :QIcadAbstractNodeWrapper(node) { + setNode(node); +} +void QIlib::QIcadNetListComponent::setNode(QIlib::AbstractNode *node) +{ + if(node->name==QIlib::Lexique::component_c) + { + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::ref_c) + { + this->ref.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::value_c) + { + this->value.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::libsource_c) + { + this->libsource.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::sheetpath_c) + { + this->sheetpath.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::tstamp_c) + { + this->tstamp.setNode(node->nodes.at(i)); + } + } + } } + + +QIlib::QIcadNetListDesign::QIcadNetListDesign(QIlib::AbstractNode *node) + :QIcadAbstractNodeWrapper(node) +{ + this->setNode(node); +} + +void QIlib::QIcadNetListDesign::setNode(QIlib::AbstractNode *node) +{ + if(node->name==QIlib::Lexique::design_c) + { + this->p_node = node; + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::source_c) + { + this->source.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::date_c) + { + this->date.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::tool_c) + { + this->tool.setNode(node->nodes.at(i)); + } + } + } +} + +QIlib::QIcadNetListLibPart::QIcadNetListLibPart(QIlib::AbstractNode *node) +{ + setNode(node); +} +/* +(libparts + (libpart (lib guan) (part 24L-MOD-8) + (fields + (field (name Reference) IC) + (field (name Value) 24L-MOD-8)) + (pins + (pin (num 1) (name GND) (type power_in)) + (pin (num 2) (name VCC) (type power_in)) +*/ +void QIlib::QIcadNetListLibPart::setNode(QIlib::AbstractNode *node) +{ + if(node->name==QIlib::Lexique::libpart_c) + { + this->p_node = node; + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::lib_c) + { + this->lib.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::part_c) + { + this->part.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::fields_c) + { + setFields(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::pins_c) + { + setPins(node->nodes.at(i)); + } + } + } +} + +void QIlib::QIcadNetListLibPart::setFields(QIlib::AbstractNode *node) +{ + while(fields.count()) + { + QIcadNetListField* field; + field = fields.last(); + fields.removeLast(); + delete field; + } + apendFields(node); +} + +void QIlib::QIcadNetListLibPart::apendFields(QIlib::AbstractNode *node) +{ + if(node->name==QIlib::Lexique::fields_c) + { + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::field_c) + { + this->fields.append(new QIcadNetListField(node->nodes.at(i))); + } + } + } +} + +void QIlib::QIcadNetListLibPart::setPins(QIlib::AbstractNode *node) +{ + while(pins.count()) + { + QIcadNetListPin* pin; + pin = pins.last(); + pins.removeLast(); + delete pin; + } + apendPins(node); +} + +void QIlib::QIcadNetListLibPart::apendPins(QIlib::AbstractNode *node) +{ + if(node->name==QIlib::Lexique::pins_c) + { + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::pin_c) + { + this->pins.append(new QIcadNetListPin(node->nodes.at(i))); + } + } + } +} + + +QIlib::QIcadNetListLibrary::QIcadNetListLibrary(QIlib::AbstractNode *node) +{ + setNode(node); +} + +void QIlib::QIcadNetListLibrary::setNode(QIlib::AbstractNode *node) +{ +/* + (library (logical guan) + (uri /home/guan/boards/guan.lib)) +*/ + if(node->name==QIlib::Lexique::library_c) + { + this->p_node = node; + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::logical_c) + { + this->logical.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::uri_c) + { + this->uri.setNode(node->nodes.at(i)); + } + } + } +} + + + +QIlib::QIcadNetListField::QIcadNetListField(QIlib::AbstractNode *node) +{ + setNode(node); +} + +void QIlib::QIcadNetListField::setNode(QIlib::AbstractNode *node) +{ + if(node->name==QIlib::Lexique::field_c) + { + this->p_node = node; + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::name_c) + { + this->name.setNode(node->nodes.at(i)); + } + } + } +} + + +QIlib::QIcadNetListLibPart::QIcadNetListPin::QIcadNetListPin(QIlib::AbstractNode *node) +{ + setNode(node); +} + +void QIlib::QIcadNetListLibPart::QIcadNetListPin::setNode(QIlib::AbstractNode *node) +{ + //(pin (num 1) (name GND) (type power_in)) + if(node->name==QIlib::Lexique::pin_c) + { + this->p_node = node; + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::name_c) + { + this->name.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::num_c) + { + this->num.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::type_c) + { + this->type.setNode(node->nodes.at(i)); + } + } + } +} + +QIlib::QIcadNetListComponent::QIcadNetListLibSource::QIcadNetListLibSource(QIlib::AbstractNode *node) +{ + setNode(node); +} + +void QIlib::QIcadNetListComponent::QIcadNetListLibSource::setNode(QIlib::AbstractNode *node) +{ + //(libsource (lib guan) (part 24L-MOD-8)) + if(node->name==QIlib::Lexique::libsource_c) + { + this->p_node = node; + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::lib_c) + { + this->lib.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::part_c) + { + this->part.setNode(node->nodes.at(i)); + } + } + } +} + +QIlib::QIcadNetListComponent::QIcadNetListSheetPath::QIcadNetListSheetPath(QIlib::AbstractNode *node) +{ + setNode(node); +} + +void QIlib::QIcadNetListComponent::QIcadNetListSheetPath::setNode(QIlib::AbstractNode *node) +{ + //(sheetpath (names /) (tstamps /)) + if(node->name==QIlib::Lexique::sheetpath_c) + { + this->p_node = node; + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::names_c) + { + this->names.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::tstamps_c) + { + this->tstamps.setNode(node->nodes.at(i)); + } + } + } +} + +QIlib::QIcadNetListNet::QIcadNetListNet(QIlib::AbstractNode *node) +{ + setNode(node); +} + +void QIlib::QIcadNetListNet::setNode(QIlib::AbstractNode *node) +{ + /* + (nets + (net (code 15) (name "") + (node (ref C4) (pin 1)) + (node (ref U2) (pin 4))) + (net (code 16) (name GND) + (node (ref D1) (pin 2)) + (node (ref C1) (pin 2)) + (node (ref IC1) (pin 1)) + */ + if(node->name==QIlib::Lexique::net_c) + { + this->p_node = node; + while(NetNodes.count()) + { + QIcadNetListNetNode* net; + net = NetNodes.last(); + NetNodes.removeLast(); + delete net; + } + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::name_c) + { + this->name.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::code_c) + { + this->code.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::node_c) + { + NetNodes.append(new QIcadNetListNetNode(node->nodes.at(i))); + } + } + } +} + +QIlib::QIcadNetListNet::QIcadNetListNetNode::QIcadNetListNetNode(QIlib::AbstractNode *node) +{ + setNode(node); +} + +void QIlib::QIcadNetListNet::QIcadNetListNetNode::setNode(QIlib::AbstractNode *node) +{ + //(node (ref D1) (pin 2)) + if(node->name==QIlib::Lexique::node_c) + { + this->p_node = node; + for(int i=0;inodes.count();i++) + { + if(node->nodes.at(i)->name==QIlib::Lexique::ref_c) + { + this->ref.setNode(node->nodes.at(i)); + } + if(node->nodes.at(i)->name==QIlib::Lexique::pin_c) + { + this->pin.setNode(node->nodes.at(i)); + } + } + } +} + + + + + + + + + + + + + + + + + + + + + diff --git a/qilib/qicadnetlist.h b/qilib/qicadnetlist.h --- a/qilib/qicadnetlist.h +++ b/qilib/qicadnetlist.h @@ -69,97 +69,37 @@ extern "C" const char* node_c ; } -class QIcadNetListLevel -{ -public: - QIcadNetListLevel() {} - QList sublevels; - QList nets; -}; -class QIcadNetListDesign -{ -public: - QIcadNetListDesign(){} - QString source; - QString date; - QString tool; -}; - -class QIcadNetListComponent -{ -public: - typedef struct libsource_t - { - QString lib; - QString part; - }libsource_t; - typedef struct sheetpath_t - { - QString names; - QString tstamp; - }sheetpath_t; - QIcadNetListComponent(){} - QString ref; - QString value; - QString tstamp; - libsource_t libsource; - sheetpath_t sheetpath; -}; - -class QIcadNetListLibPart -{ -public: - typedef struct fields_t - { - QString ref; - QString value; - QString footprint; - QString datasheet; - }fields_t; - typedef struct pin_t - { - int num; - QString name; - QString type; - }pin_t; - QIcadNetListLibPart(); - QString lib; - QString part; - QStringList footprints; - fields_t fields; - QList pins; -}; class QIcadAbstractNodeWrapper { public: QIcadAbstractNodeWrapper(QIlib::AbstractNode* node); + QIcadAbstractNodeWrapper(){} ~QIcadAbstractNodeWrapper(); QString value(); QString value(int index); QString catValues(); - void setNode(QIlib::AbstractNode* node); QList childs; QIcadAbstractNodeWrapper* parent; + virtual void setNode(QIlib::AbstractNode* node); -private: QIlib::AbstractNode* p_node; }; -class QIcadNetListRoot : public AbstractNode +class QIcadNetListDesign : public QIcadAbstractNodeWrapper { public: - QIcadNetListRoot(QIlib::AbstractNode* node); + QIcadNetListDesign(QIlib::AbstractNode* node); + QIcadNetListDesign(){} QIcadAbstractNodeWrapper source; QIcadAbstractNodeWrapper date; QIcadAbstractNodeWrapper tool; - QList components; - QList libparts; - QList libraries; + void setNode(QIlib::AbstractNode* node); }; + /* * (comp (ref IC1) (value 24L-MOD-8) @@ -169,13 +109,32 @@ public: */ class QIcadNetListComponent:public QIcadAbstractNodeWrapper { + class QIcadNetListLibSource : QIcadAbstractNodeWrapper + { + public: + QIcadNetListLibSource(AbstractNode* node); + QIcadNetListLibSource(){} + QIcadAbstractNodeWrapper lib; + QIcadAbstractNodeWrapper part; + void setNode(AbstractNode* node); + }; + class QIcadNetListSheetPath : QIcadAbstractNodeWrapper + { + public: + QIcadNetListSheetPath(AbstractNode* node); + QIcadNetListSheetPath(){} + QIcadAbstractNodeWrapper names; + QIcadAbstractNodeWrapper tstamps; + void setNode(AbstractNode* node); + }; public: QIcadNetListComponent(AbstractNode* node); QIcadAbstractNodeWrapper ref; QIcadAbstractNodeWrapper value; - QIcadAbstractNodeWrapper libsource; - QIcadAbstractNodeWrapper sheetpath; + QIcadNetListLibSource libsource; + QIcadNetListSheetPath sheetpath; QIcadAbstractNodeWrapper tstamp; + void setNode(QIlib::AbstractNode* node); }; @@ -194,6 +153,7 @@ class QIcadNetListField : QIcadAbstractN public: QIcadNetListField(AbstractNode* node); QIcadAbstractNodeWrapper name; + void setNode(AbstractNode* node); }; @@ -206,11 +166,19 @@ class QIcadNetListLibPart : QIcadAbstrac QIcadAbstractNodeWrapper type; QIcadAbstractNodeWrapper num; QIcadAbstractNodeWrapper name; + void setNode(AbstractNode* node); }; public: QIcadNetListLibPart(AbstractNode* node); + QIcadAbstractNodeWrapper lib; + QIcadAbstractNodeWrapper part; QList fields; QList pins; + void setNode(AbstractNode* node); + void setFields(QIlib::AbstractNode* node); + void apendFields(QIlib::AbstractNode* node); + void setPins(QIlib::AbstractNode* node); + void apendPins(QIlib::AbstractNode* node); }; /* @@ -228,6 +196,8 @@ class QIcadNetListLibrary : QIcadAbstra public: QIcadNetListLibrary(AbstractNode* node); QIcadAbstractNodeWrapper uri; + QIcadAbstractNodeWrapper logical; + void setNode(AbstractNode* node); }; /* (nets @@ -248,12 +218,36 @@ class QIcadNetListNet : QIcadAbstractNod QIcadNetListNetNode(AbstractNode* node); QIcadAbstractNodeWrapper ref; QIcadAbstractNodeWrapper pin; + void setNode(AbstractNode* node); }; public: QIcadNetListNet(AbstractNode* node); QList NetNodes; + QIcadAbstractNodeWrapper code; + QIcadAbstractNodeWrapper name; + void setNode(AbstractNode* node); + }; +class QIcadNetListRoot : public QIcadAbstractNodeWrapper +{ +public: + QIcadNetListRoot(QIlib::AbstractNode* node); + QIcadNetListDesign design; + QList components; + QList libparts; + QList libraries; + QList nets; + void setNode(QIlib::AbstractNode* node); + void setComponents(QIlib::AbstractNode* node); + void apendComponents(QIlib::AbstractNode* node); + void setLibParts(QIlib::AbstractNode* node); + void apendLibParts(QIlib::AbstractNode* node); + void setLibraries(QIlib::AbstractNode* node); + void apendLibraries(QIlib::AbstractNode* node); + void setNets(QIlib::AbstractNode* node); + void apendNets(QIlib::AbstractNode* node); +}; class QIcadNetList : private lispLike_Driver @@ -263,13 +257,8 @@ public: bool parseNetList(const QString& netlist); QString toString(); QString fileName; - QString version; - QIcadNetListDesign design; - QList components; - QList libparts; - QIcadNetListLevel rootSheet; QString print(); - QIcadAbstractNodeWrapper netlistRoot; + QIcadNetListRoot* netlistRoot; private: QIlib::AbstractNode* getAbstractNode(const QString& node,int index); QIlib::AbstractNode* getAbstractNode(QIlib::AbstractNode* rootNode,const QString& node,int* index); diff --git a/test/dumpLispLikeFiles/main.cpp b/test/dumpLispLikeFiles/main.cpp --- a/test/dumpLispLikeFiles/main.cpp +++ b/test/dumpLispLikeFiles/main.cpp @@ -41,8 +41,19 @@ int main(int argc, char *argv[]) tm.start(); NetListdriver.parseNetList(argv[1]); qDebug()<<"File parsed in "<nets.count();i++) + { + std::cout<<"Found net:"<nets.at(i)->name.value().toStdString()<<" "<nets.at(i)->code.value().toStdString()<<"\n"; + } + } } + } return 0; }