Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members

check.cc

Go to the documentation of this file.
00001 /*--------------------------------------------------------------------
00002  *
00003  * (C) Copyright Koninklijke Philips Electronics NV 2006. 
00004  * All rights reserved. This software is licensed under the terms of
00005  * version 2.1 of the GNU Lesser General Public License as published 
00006  * by the Free Software Foundation. For licensing and warranty
00007  * information, see the file COPYING in the main directory.
00008  *
00009  *------------------------------------------------------------------*/
00010 
00011 #include "check.h"
00012 #include "portbase.h"
00013 #include "fifobase.h"
00014 #include "processbase.h"
00015 #include "networkbase.h"
00016 
00017 using std::ostream;
00018 using std::endl;
00019 
00020 static unsigned int check(const InPortBase* p, ostream& o)
00021 {
00022   unsigned int e = 0;
00023 
00024   // check parent is a component
00025   Component* c = p->parentComponent();
00026   if (!c) {
00027     o << p->fullName() << ": parent is not a component" << endl;
00028     e++;
00029   }
00030 
00031   unsigned int ns = p->nrSrc();
00032   if (ns == 0) {
00033     o << p->fullName() << ": has no source" << endl;
00034     e++;
00035   } else if (ns == 1) {
00036     // OK, src must be inport or fifo
00037     InPortBase* s = p->getSrcPort();
00038     FifoBase* f = p->getSrcFifo();
00039     if (!f && !s) {
00040       o << p->fullName() << ": source is not a fifo or an inport" << endl;
00041       e++;
00042     }
00043   } else if (ns > 1) {
00044     o << p->fullName() << ": has more than one source" << endl;
00045     e++;
00046   }
00047 
00048   unsigned int nd = p->nrDst();
00049   if (nd == 0) {
00050     // OK, but must have a parent
00051     if (!p->parent()) {
00052       o << p->fullName() << ": has no parent" << endl;
00053       e++;
00054     }
00055   } else if (nd > 0) {
00056     for (unsigned int i=0; i<nd; i++)
00057     {
00058       // dst must be inport
00059       InPortBase* d = p->getDstPort(i);
00060       if (!d) {
00061         o << p->fullName() << ": destination is not an inport" << endl;
00062         e++;
00063       }
00064     }
00065   } 
00066   return e;
00067 }
00068 
00069 static unsigned int check(const OutPortBase* p, ostream& o)
00070 {
00071   unsigned int e = 0;
00072 
00073   // check parent is a component
00074   Component* c = p->parentComponent();
00075   if (!c) {
00076     o << p->fullName() << ": parent is not a component" << endl;
00077     e++;
00078   }
00079 
00080   unsigned int ns = p->nrSrc();
00081   if (ns == 0) {
00082     // OK, but musty have a parent
00083     if (!p->parent()) {
00084       o << p->fullName() << ": parent is not a process" << endl;
00085       e++;
00086     }
00087   } else if (ns == 1) {
00088     // src must be outport
00089     OutPortBase* d = p->getSrcPort();
00090     if (!d) {
00091       o << p->fullName() << ": source is not an inport" << endl;
00092       e++;
00093     }
00094   } else if (ns > 1) {
00095     o << p->fullName() << ": has more than one source" << endl;
00096     e++;
00097   }
00098 
00099   unsigned int nd = p->nrDst();
00100   if (nd == 0) {
00101     o << p->fullName() << ": has no source" << endl;
00102     e++;
00103   } else if (nd > 1) {
00104     for (unsigned int i=0; i<nd; i++)
00105     {
00106       // OK, dst must be outport or fifo
00107       OutPortBase* s = p->getDstPort(i);
00108       FifoBase* f = p->getDstFifo(i);
00109       if (!f && !s) {
00110         o << p->fullName() << ": destination is not a fifo or an inport" << endl;
00111         e++;
00112       }
00113     }
00114   } 
00115   return e;
00116 }
00117 
00118 static unsigned int check(const FifoBase* f, ostream& o)
00119 {
00120   unsigned int e = 0;
00121 
00122   // check parent is a network
00123   NetworkBase* n = f->parentNetwork();
00124   if (!n) {
00125     o << f->fullName() << ": parent is not a network" << endl;
00126     e++;
00127   }
00128 
00129   // check that the fifo has one src and one or more dst
00130   unsigned int ns = f->nrSrc();
00131   if (ns == 0) {
00132     o << f->fullName() << ": has no source" << endl;
00133     e++;
00134   } else if (ns > 1) {
00135     o << f->fullName() << ": has more than one source" << endl;
00136     e++;
00137   }
00138   unsigned int nd = f->nrDst();
00139   if (nd == 0) {
00140     o << f->fullName() << ": has no destination" << endl;
00141     e++;
00142   } 
00143 
00144   // check that src is an OutPort and dst are InPorts
00145   OutPortBase* s = 0;
00146   if (ns != 0) {
00147     s = f->srcPort();
00148     if (!s) {
00149       o << f->fullName() << ": source is not an OutPort" << endl;
00150       e++;
00151     }
00152   }
00153   InPortBase*  d = 0;
00154   if (nd != 0) {
00155     for (unsigned int i=0; i<nd; i++)
00156     {
00157       d = f->dstPort(i);
00158       if (!d) {
00159         o << f->fullName() << ": destination is not an InPort" << endl;
00160         e++;
00161       }
00162     }
00163   }
00164 
00165   // check port levels
00166   if (ns != 0 && s && s->parent()) {  
00167     if (s->parent()->parent() != dynamic_cast<IdBase*>(n))
00168     {
00169       o << f->fullName() << ": source at wrong level" << endl;
00170       e++;
00171     }
00172   }
00173   if (nd != 0 && d && d->parent()) {  
00174     if (d->parent()->parent() != dynamic_cast<IdBase*>(n))
00175     {
00176       o << f->fullName() << ": destination at wrong level" << endl;
00177       e++;
00178     }
00179   }
00180 
00181   return e;
00182 }
00183 
00184 
00185 static unsigned int check(const Component* c, ostream& o)
00186 {
00187   unsigned int e = 0;
00188   unsigned int i;
00189 
00190   // check ports
00191   for (i=0; i<c->nrInPorts(); i++)
00192     e += check(c->getInPort(i), o);
00193   for (i=0; i<c->nrOutPorts(); i++)
00194     e += check(c->getOutPort(i), o);
00195 
00196   return e;
00197 }
00198 
00199 static unsigned int check(const ProcessBase* p, ostream& o)
00200 {
00201   unsigned int e = check((Component*)p, o);
00202 
00203   // check parent is a network
00204   NetworkBase* n = p->parentNetwork();
00205   if (!n) {
00206     o << p->fullName() << ": parent is not a network" << endl;
00207     e++;
00208   }
00209 
00210   return e;
00211 }
00212 
00213 unsigned int check(const NetworkBase* n, ostream& o)
00214 {
00215   unsigned int e = check((Component*)n, o);
00216   unsigned int i;
00217 
00218   // check parent is a network, or 0
00219   // if parent == 0 check that network has no ports
00220   if (n->parent()) {
00221     NetworkBase* p = n->parentNetwork();
00222     if (!p) {
00223       o << n->fullName() << ": parent is not a network" << endl;
00224       e++;
00225     }
00226   }
00227 
00228   // check fifos
00229   for (i=0; i<n->nrFifos(); i++)
00230     e += check(n->getFifo(i), o);
00231 
00232   // check processes
00233   for (i=0; i<n->nrProcesses(); i++)
00234     e += check(n->getProcess(i), o);
00235 
00236   // check networks
00237   for (i=0; i<n->nrNetworks(); i++)
00238     e += check(n->getNetwork(i), o);
00239 
00240   return e;
00241 }
00242 
00243 
00245 
00246 static unsigned int uniqueInPortId(const Component* c, ostream& o)
00247 {
00248   unsigned int e = 0;
00249 
00250   for (unsigned int i=0; i<c->nrInPorts(); i++)
00251   {
00252     InPortBase* f = c->getInPort(i);
00253     for (unsigned int j=i+1; j<c->nrInPorts(); j++)
00254     {
00255       InPortBase* g = c->getInPort(j);
00256       if (strcmp(f->name(), g->name()) == 0)
00257       {
00258         o << f->fullName() << ": InPort Id is not unique" << endl;
00259         e++;
00260       }
00261     }
00262   }
00263   return e;
00264 }
00265 
00266 static unsigned int uniqueOutPortId(const Component* c, ostream& o)
00267 {
00268   unsigned int e = 0;
00269 
00270   for (unsigned int i=0; i<c->nrOutPorts(); i++)
00271   {
00272     OutPortBase* f = c->getOutPort(i);
00273     for (unsigned int j=i+1; j<c->nrOutPorts(); j++)
00274     {
00275       OutPortBase* g = c->getOutPort(j);
00276       if (strcmp(f->name(), g->name()) == 0)
00277       {
00278         o << f->fullName() << ": OutPort Id is not unique" << endl;
00279         e++;
00280       }
00281     }
00282   }
00283   return e;
00284 }
00285 
00286 static unsigned int uniqueFifoId(const NetworkBase* n, ostream& o)
00287 {
00288   unsigned int e = 0;
00289 
00290   for (unsigned int i=0; i<n->nrFifos(); i++)
00291   {
00292     FifoBase* f = n->getFifo(i);
00293     for (unsigned int j=i+1; j<n->nrFifos(); j++)
00294     {
00295       FifoBase* g = n->getFifo(j);
00296       if (strcmp(f->name(), g->name()) == 0)  
00297       {
00298         o << f->fullName() << ": Fifo Id is not unique" << endl;
00299         e++;
00300       }
00301     }
00302   }
00303   return e;
00304 }
00305 
00306 static unsigned int uniqueProcessId(const NetworkBase* n, ostream& o)
00307 {
00308   unsigned int e = uniqueInPortId(n,o) + uniqueOutPortId(n,o);
00309 
00310   for (unsigned int i=0; i<n->nrProcesses(); i++)
00311   {
00312     ProcessBase* f = n->getProcess(i);
00313     for (unsigned int j=i+1; j<n->nrProcesses(); j++)
00314     {
00315       ProcessBase* g = n->getProcess(j);
00316       if (strcmp(f->name(), g->name()) == 0)
00317       {
00318         o << f->fullName() << ": Process Id is not unique" << endl;
00319         e++;
00320       }
00321     }
00322   }
00323   return e;
00324 }
00325 
00326 static unsigned int uniqueNetworkId(const NetworkBase* n, ostream& o)
00327 {
00328   unsigned int e = uniqueInPortId(n,o) + uniqueOutPortId(n,o)
00329     + uniqueFifoId(n,o) + uniqueProcessId(n,o);
00330 
00331   for (unsigned int i=0; i<n->nrNetworks(); i++)
00332   {
00333     NetworkBase* f = n->getNetwork(i);
00334     e += uniqueNetworkId(f,o);
00335 
00336     for (unsigned int j=i+1; j<n->nrNetworks(); j++)
00337     {
00338       NetworkBase* g = n->getNetwork(j);
00339       if (strcmp(f->name(), g->name()) == 0)
00340       {
00341         o << f->fullName() << ": Network Id is not unique" << endl;
00342         e++;
00343       }
00344     }
00345   }
00346   return e;
00347 }
00348 
00349 unsigned int uniqueId(const NetworkBase* n, ostream& o)
00350 {
00351   return uniqueNetworkId(n,o);
00352 }

Generated on Wed Feb 15 14:52:38 2006 for yapi by doxygen 1.3.2