/structural/supporting_matl_misc_and_old/support/matrixTypeGenerator/ver_2/BLAS_LAPACK/generator/src/laFortRead.cpp
C++ | 6229 lines | 4928 code | 739 blank | 562 comment | 858 complexity | c5e787dc7056794a46af21b0c488ee4a MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- #include <fstream>
- #include <ostream>
- #include <iostream>
- #include <vector>
- #include <list>
- #include <string>
- #include <cctype>
- #include <cstdlib>
- #include <sstream>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include "eMsg.h"
- using namespace std;
- #define LINE_SIZE 1024
- // this is a list of all the globals
- // objList<fortranType> fTypes;
- // objList<cppType_basic> bTypes;
- // objList<cppType_template> tTypes;
- // list<fortranFunction> fortranFunctionList;
- // objList<mapText> textMaps;
- // objList<cppFunctionName> cppFuncs;
- // cppType* voidType;
- // sourceFile fortranSource;
- // sourceFile cppPrototype;
- // sourceFile cppDefinition;
- // commandSource_recording recorder;
- char* copyLine(const char* ln)
- {
- unsigned long L=0;
- if(ln==NULL)
- throw eMsg("fortranFunction: the input array is NULL");
- while(ln[L]!=0)
- L++;
- L++;
- char* retVal=new char[L];
- if(retVal==NULL)
- throw eMsg("copyLine(): Failed to allocate memory");
- for(unsigned long i=0;i<L;i++)
- retVal[i]=ln[i];
- return retVal;
- }
- bool strEqual(const char* lhs, const char* rhs)
- {
- if(lhs==NULL || rhs==NULL)
- {
- if(lhs==rhs)
- return true;
- return false;
- }
- unsigned long i=0;
- while(lhs[i]!=0 && rhs!=0)
- {
- if(lhs[i]!=rhs[i])
- return false;
- i++;
- }
- if(rhs[i]!=lhs[i])
- return false;
- return true;
- }
- bool strFilterEqual(const char* fltr, const char* test)
- {
- unsigned long at=0;
- unsigned long atFlt=0;
- // Null filter means everything matches automatically
- if(fltr[atFlt]==0)
- return true;
- while(fltr[atFlt]!=0 && test[at]!=0)
- {
- // Are we matching tokens?
- if(fltr[atFlt]=='*')
- {
- atFlt++;
- // test to see if there is a trailing token, otherwise we return true
- if(fltr[atFlt]==0)
- return true;
- // The function of a '**' is undefined
- if(fltr[atFlt]=='*')
- throw eMsg("strFilterEqual(): '**' type filter not allowed");
- // There is a token and thus we need to find a match
- bool seekMatch=true;
- while(seekMatch)
- {
- // seek forward until a possible match
- while(test[at]!=0 && test[at]!=fltr[atFlt])
- at++;
- if(test[at]==0)
- return false;
- unsigned long cnt=0;
- while(test[at+cnt]!=0 && fltr[atFlt+cnt]!=0 && fltr[atFlt+cnt]!='*' && test[at+cnt]==fltr[atFlt+cnt])
- cnt++;
- // test to see if the test string ran out
- if( test[at+cnt]==0 )
- // this is ok only if we are at the end of the filter
- return fltr[atFlt+cnt]==0 || (fltr[atFlt+cnt]=='*' && fltr[atFlt+cnt+1]==0);
- // string didn;t run out test to see if the token was matched
- if( fltr[atFlt+cnt]=='*' || fltr[atFlt+cnt]==0 )
- {
- at+=cnt;
- atFlt+=cnt;
- // Test if the filter has ended, if so then we can complete the test
- if( fltr[atFlt]==0 )
- return test[at]==0;
- // everything matched and nothing has ended so we keep searching
- seekMatch=false;
- }
- else
- {
- // could not find token match, try again starting from the next character
- at++;
- }
- }
- }
- else
- {
- // no '*' has been found so a simple search
- if(test[at]!=fltr[atFlt])
- return false;
- at++;
- atFlt++;
- }
- }
- // reached the end of test or filter thus only successful if both at the end
- return test[at]==fltr[atFlt];
- }
- class wordList
- {
- private:
- unsigned long sz;
- vector<unsigned long> start;
- vector<unsigned long> end;
- char* line;
- public:
- wordList& setLine(const char* line_in)
- {
- if(line_in==NULL)
- {
- sz=0;
- return *this;
- }
- unsigned long at=0;
- sz=0;
- while(line_in[at]!=0)
- {
- while(line_in[at]!=0 && isspace(line_in[at]))
- at++;
- if(line_in[at]!=0)
- sz++;
- while(line_in[at]!=0 && !isspace(line_in[at]))
- at++;
- }
- start.resize(sz);
- end.resize(sz);
- if(line!=NULL)
- delete[] line;
- line=new char[at+1];
- at=0;
- unsigned long atWrd=0;
- while(line_in[at]!=0)
- {
- while(line_in[at]!=0 && isspace(line_in[at]))
- {
- line[at]=line_in[at];
- at++;
- }
- if(line_in[at]!=0)
- start[atWrd]=at;
- while(line_in[at]!=0 && !isspace(line_in[at]))
- {
- end[atWrd]=at;
- line[at]=line_in[at];
- at++;
- }
- atWrd++;
- }
- line[at]=0;
- return *this;
- }
- wordList(const char* line_in=NULL) : sz(0) , start(0) , end(0) , line(NULL)
- {
- setLine(line_in);
- }
- ~wordList()
- {
- if(line!=NULL)
- delete[] line;
- }
- wordList& getWord(unsigned long at, char* word, unsigned long bfSz)
- {
- if(at>=sz)
- throw eMsg("wordList: The argument does not exist");
- unsigned long wSz=end[at]-start[at]+1;
- if(wSz>bfSz+1)
- throw eMsg("wordList: the buffer provided is not big enough");
- unsigned long i;
- for(i=0;i<wSz;i++)
- word[i]=line[start[at]+i];
- word[i]=0;
- return *this;
- }
- unsigned long size()
- {
- return sz;
- }
- unsigned long getStart(unsigned long at)
- {
- if(at>=sz)
- throw eMsg("wordList: the requested start does not exist");
- return start[at];
- }
- unsigned long getEnd(unsigned long at)
- {
- if(at>=sz)
- throw eMsg("wordList: the requested end does not exist");
- return end[at];
- }
- };
- class cppType
- {
- protected:
- static int typeID;
- int myID;
- friend class cppType_template;
- virtual void addMyID(list<int>& idList) const
- {
- idList.push_back(myID);
- }
- public:
- cppType()
- {
- myID=typeID++;
- }
- cppType(const cppType& rhs)
- {
- this->myID=rhs.myID;
- }
- virtual ~cppType()
- {}
- // virtual const char* getName()=0;
- virtual void printType(ostream& out)=0;
- virtual void printDescription(ostream& out)=0;
- virtual cppType* copyType()=0;
- bool operator==(const cppType& rhs)
- {
- list<int> lhsType;
- list<int> rhsType;
- this->addMyID(lhsType);
- rhs.addMyID(rhsType);
- unsigned long tpCount=lhsType.size();
- if(tpCount!=rhsType.size())
- return false;
- list<int>::iterator itLhs=lhsType.begin();
- list<int>::iterator itRhs=rhsType.begin();
- for(unsigned long i=0;i<tpCount;i++)
- {
- if(*itLhs!=*itRhs)
- return false;
- itLhs++;
- itRhs++;
- }
- return true;
- }
- bool operator!=(const cppType& rhs)
- {
- return !(*this==rhs);
- }
- };
- int cppType::typeID=0;
- class cppType_basic : public cppType
- {
- private:
- char* name;
- char* description;
- public:
- cppType_basic& setName(const char* name_in)
- {
- unsigned long i=0;
- while(name_in[i]!=0)
- i++;
- i++;
- if(name!=NULL)
- delete[] name;
- name=new char[i];
- if(name==NULL)
- throw eMsg("cppType_basic::setName(): Failed to allocate memory");
- for(unsigned long j=0;j<i;j++)
- name[j]=name_in[j];
- return *this;
- }
- cppType_basic& setDescription(const char* desc_in)
- {
- unsigned long i=0;
- while(desc_in[i]!=0)
- i++;
- i++;
- if(description!=NULL)
- delete[] description;
- description=new char[i];
- if(description==NULL)
- throw eMsg("cppType_basic::setDescription(): Failed to allocate memory");
- for(unsigned long j=0;j<i;j++)
- description[j]=desc_in[j];
- return *this;
- }
- cppType_basic() : name(NULL) , description(NULL)
- {}
- cppType_basic(const char* name_in, const char* desc_in) : name(NULL) , description(NULL)
- {
- setName(name_in);
- setDescription(desc_in);
- }
- cppType_basic(const cppType_basic& rhs) : cppType(rhs) , name(NULL) , description(NULL)
- {
- if(rhs.name!=NULL)
- this->setName(rhs.name);
- if(rhs.description)
- this->setDescription(rhs.description);
- }
- virtual ~cppType_basic()
- {
- if(name!=NULL)
- delete[] name;
- if(description!=NULL)
- delete[] description;
- }
- virtual void printType(ostream& out)
- {
- if(name==NULL)
- return;
- out << name;
- }
- virtual void printDescription(ostream& out)
- {
- if(description==NULL)
- return;
- out << name << ": " << description;
- }
- virtual cppType* copyType()
- {
- return new cppType_basic(*this);
- }
- const char* getName()
- {
- return name;
- }
- };
- class cppType_template : public cppType_basic
- {
- private:
- vector<bool> isType;
- vector<cppType*> args;
- vector<int> vals;
- vector<bool> canDelete;
- void addMyID(list<int>& idList) const
- {
- this->cppType::addMyID(idList);
- for(unsigned long i=0;i<args.size();i++)
- {
- if(isType[i])
- {
- if(args[i]==NULL)
- throw eMsg("cppType_template: template parameter has not been set");
- args[i]->addMyID(idList);
- }
- else
- {
- idList.push_back(vals[i]);
- }
- }
- }
- public:
- cppType_template(const char* name_in,const char* desc_in,unsigned long size_in) : cppType_basic(name_in,desc_in) , isType(size_in,true) , args(size_in,NULL) , vals(size_in,0) , canDelete(size_in,false)
- {}
- cppType_template(unsigned long size_in=0) : isType(size_in,true) , args(size_in,NULL) , vals(size_in,0) , canDelete(size_in,false)
- {}
- cppType_template(const cppType_template& rhs) : cppType_basic(rhs) , isType(rhs.isType) , args(rhs.args) , vals(rhs.vals) , canDelete(rhs.isType.size(),false)
- {}
- virtual ~cppType_template()
- {
- for(unsigned long i=0;i<args.size();i++)
- {
- if(canDelete[i] && args[i]!=NULL)
- delete args[i];
- }
- }
- cppType_template& resize(unsigned long size_in=0)
- {
- isType.resize(size_in,true);
- args.resize(size_in,NULL);
- vals.resize(size_in,0);
- canDelete.resize(size_in,false);
- return *this;
- }
- unsigned long size()
- {
- return isType.size();
- }
- cppType_template& clearTypes()
- {
- for(unsigned long i=0;i<isType.size();i++)
- {
- if(isType[i])
- args[i]=NULL;
- }
- return *this;
- }
- cppType_template& setArgType(unsigned long at, cppType* arg, bool canDelete_in)
- {
- if(at>=isType.size())
- throw eMsg("cppType_template: The argument does not exist");
- if(args[at]!=NULL && args[at]!=arg && canDelete[at])
- delete args[at];
- isType[at]=true;
- args[at]=arg;
- canDelete[at]=canDelete_in;
- return *this;
- }
- cppType_template& setArgType(unsigned long at, int val)
- {
- if(at>=isType.size())
- throw eMsg("cppType_template: The argument does not exist");
- isType[at]=true;
- vals[at]=val;
- return *this;
- }
- virtual void printType(ostream& out)
- {
- this->cppType_basic::printType(out);
- out << '<';
- for(unsigned long i=0;i<isType.size();i++)
- {
- if(i>0)
- out << ',';
- out << ' ';
- if(isType[i] && args[i]!=NULL)
- args[i]->printType(out);
- else if(!isType[i])
- out << vals[i];
- else
- throw eMsg("cppType_template: the template type has not been set");
- out << ' ';
- }
- out << '>';
- }
- virtual void printDescription(ostream& out)
- {
- this->cppType_basic::printDescription(out);
- }
- virtual cppType* copyType()
- {
- return new cppType_template(*this);
- }
- };
- class fortranType
- {
- private:
- vector<vector<const char*> > fTypeName;
- cppType* cType;
- public:
- fortranType(unsigned long sz_in) : fTypeName(sz_in,vector<const char*>(0,NULL))
- {}
- fortranType& setSize(unsigned long sz_in)
- {
- fTypeName.resize(sz_in);
- return *this;
- }
- fortranType& setTypeSize(unsigned long typeAt, unsigned long wordCnt)
- {
- if(typeAt>=fTypeName.size())
- throw eMsg("fortranType: the requested type does not exist");
- fTypeName[typeAt].resize(wordCnt);
- return *this;
- }
- fortranType& setText(unsigned long typeAt,unsigned long at, const char* wrd)
- {
- if(typeAt>=fTypeName.size())
- throw eMsg("fortranType: the requested type does not exist");
- if(at>=fTypeName[typeAt].size())
- throw eMsg("fortranType: the word in the type does not exist");
- fTypeName[typeAt][at]=wrd;
- return *this;
- }
- fortranType& setType(cppType* cType_in)
- {
- if(cType_in==NULL)
- throw eMsg("fortranType: the type is NULL");
- cType=cType_in;
- return *this;
- }
- bool isType(wordList& line,unsigned long& end)
- {
- char word[LINE_SIZE];
- for(unsigned long i=0;i<fTypeName.size();i++)
- {
- bool fail=false;
- unsigned long j;
- for(j=0; j<fTypeName[i].size();j++)
- {
- line.getWord(j,word,LINE_SIZE);
- if(!strEqual(word,fTypeName[i][j]))
- fail=true;
- else
- end=line.getEnd(j);
- }
- if(!fail)
- {
- return true;
- }
- }
- return false;
- }
- bool isType(wordList& line)
- {
- unsigned long end;
- return this->isType(line,end);
- }
- cppType* getType()
- {
- return cType;
- }
- };
- template<class oType>
- class objList
- {
- private:
- list<oType*> typeObjs;
- bool own;
- vector<oType*> vct;
- bool vctGood;
- public:
- objList(bool own_in=true) : own(own_in) , vctGood(false)
- {}
- ~objList()
- {
- if(own)
- {
- for(typename list<oType*>::iterator it=typeObjs.begin();it!=typeObjs.end();it++)
- delete *it;
- }
- }
- unsigned long size()
- {
- return typeObjs.size();
- }
- objList& addObj(oType* newType)
- {
- if(newType==NULL)
- throw eMsg("objList: the new type is NULL");
- typeObjs.push_back(newType);
- vctGood=false;
- return *this;
- }
- oType* getObj(unsigned long at)
- {
- if(at>=typeObjs.size())
- throw eMsg("objList: The requested type does not exist");
- if(!vctGood)
- {
- vct.resize(typeObjs.size(),NULL);
- typename list<oType*>::iterator it=typeObjs.begin();
- for(unsigned long i=0;i<typeObjs.size();i++)
- {
- vct[i]=*it;
- it++;
- }
- vctGood=true;
- }
- return vct[at];
- }
- objList& deleteBack(unsigned long cnt=1)
- {
- if(cnt>typeObjs.size())
- cnt=typeObjs.size();
- for(unsigned long i=0;i<cnt;i++)
- {
- if(own)
- delete typeObjs.back();
- typeObjs.pop_back();
- }
- return *this;
- }
- };
- objList<fortranType> fTypes;
- objList<cppType_basic> bTypes;
- objList<cppType_template> tTypes;
- cppType* voidType;
- cppType* readType(wordList& line, unsigned long& end)
- {
- for(unsigned long i=0;i<fTypes.size();i++)
- {
- fortranType* fTp=fTypes.getObj(i);
- if(fTp->isType(line,end))
- {
- end++;
- return fTp->getType();
- }
- }
- return NULL;
- }
- cppType* readType(wordList& line)
- {
- unsigned long end;
- return readType(line,end);
- }
- class variable
- {
- private:
- char* name;
- cppType* type;
- bool deleteType;
- unsigned long pointerLevel;
- bool isReference;
- bool isConst;
- public:
- variable& setName(const char* name_in)
- {
- if(name!=NULL)
- delete[] name;
- if(name_in==NULL)
- {
- name=NULL;
- return *this;
- }
- unsigned long L=0;
- while(name_in[L]!=0)
- L++;
- L++;
- name=new char[L];
- if(name==NULL)
- throw eMsg("variable: Failed to allocate memory");
- for(unsigned long i=0;i<L;i++)
- name[i]=name_in[i];
- return *this;
- }
- variable& setType(cppType* type_in,bool deleteType_in=false)
- {
- if(type!=NULL && type!=type_in && deleteType)
- delete type;
- type=type_in;
- deleteType=deleteType_in;
- return *this;
- }
- variable& setPointerLevel(unsigned long lvl_in)
- {
- pointerLevel=lvl_in;
- return *this;
- }
- variable& setReference(bool isRef_in)
- {
- isReference=isRef_in;
- return *this;
- }
- variable& setConst(bool isConst_in)
- {
- isConst=isConst_in;
- return *this;
- }
- variable(cppType* type_in=NULL,const char* name_in=NULL,long pntrLevel=0,bool isReference_in=false,bool isConst_in=false,bool deleteType_in=false) : name(NULL) , type(type_in) , deleteType(false) , pointerLevel(pntrLevel) , isReference(isReference_in) , isConst(isConst_in)
- {
- setType(type_in,deleteType_in);
- setName(name_in);
- }
- variable(const variable& asg) : name(NULL) , type(NULL) , deleteType(false) , pointerLevel(0) , isReference(false) , isConst(false)
- {
- *this=asg;
- }
- ~variable()
- {
- if(name!=NULL)
- delete[] name;
- if(deleteType && type!=NULL)
- delete type;
- }
- variable& operator=(const variable& asg)
- {
- if(name!=NULL)
- delete[] name;
- if(asg.name==NULL)
- this->name=NULL;
- else
- {
- this->name=copyLine(asg.name);
- if(this->name==NULL)
- throw eMsg("variable::operator=(): Failed to allocate memory");
- }
- if(this->deleteType && this->type!=NULL)
- delete this->type;
- if(asg.deleteType)
- {
- if(asg.type==NULL)
- {
- this->type=NULL;
- this->deleteType=false;
- }
- else
- {
- this->type=asg.type->copyType();
- if(this->type==NULL)
- throw eMsg("variable::operator=(): Failed to allocate memory");
- this->deleteType=asg.deleteType;
- }
- }
- else
- {
- this->deleteType=false;
- this->type=asg.type;
- }
- this->pointerLevel=asg.pointerLevel;
- this->isReference=asg.isReference;
- this->isConst=asg.isConst;
- return *this;
- }
- variable& printName(ostream& out)
- {
- if(name==NULL)
- throw eMsg("variable: Name has not been set");
- out << name;
- return *this;
- }
- variable& printDecl(ostream& out)
- {
- if(type==NULL)
- throw eMsg("variable: type has not been set");
- if(isConst)
- out << "const ";
- type->printType(out);
- for(unsigned long i=0;i<pointerLevel;i++)
- out << '*';
- if(isReference)
- out << '&';
- out << ' ';
- this->printName(out);
- return *this;
- }
- cppType* getType()
- {
- return type;
- }
- const char* getName()
- {
- return name;
- }
- };
- struct comment
- {
- char* line;
- bool tagged;
-
- comment() : line(NULL)
- {}
-
- ~comment()
- {
- if(line!=NULL)
- delete[] line;
- }
-
- comment(const comment& asg)
- {
- if(asg.line!=NULL)
- {
- unsigned long i=0;
- while(asg.line[i]!=0)
- i++;
- this->line=new char[i+1];
- if(this->line==NULL)
- throw eMsg("comment: Failed to allocate memory");
- i=0;
- while(asg.line[i]!=0)
- {
- this->line[i]=asg.line[i];
- i++;
- }
- this->line[i]=0;
- }
- else
- {
- this->line=NULL;
- }
- this->tagged=asg.tagged;
- }
- comment& operator=(const comment& asg)
- {
- if(this->line!=NULL)
- delete[] this->line;
- if(asg.line!=NULL)
- {
- unsigned long i=0;
- while(asg.line[i]!=0)
- i++;
- this->line=new char[i+1];
- if(this->line==NULL)
- throw eMsg("comment: Failed to allocate memory");
- i=0;
- while(asg.line[i]!=0)
- {
- this->line[i]=asg.line[i];
- i++;
- }
- }
- else
- {
- this->line=NULL;
- }
- this->tagged=asg.tagged;
- }
- };
- class nameSource
- {
- protected:
- vector<bool> sourceIsSunk;
- void setSourceSize(unsigned long sz_in)
- {
- sourceIsSunk.resize(sz_in,false);
- }
- public:
- nameSource() : sourceIsSunk(0,false)
- {}
- virtual ~nameSource()
- {}
- virtual unsigned long sourceSize()
- {
- return sourceIsSunk.size();
- }
- virtual const char* getSourceName(unsigned long at)=0;
- virtual const char* getSourceDescription()=0;
- virtual const char* getSourceTermDescription(unsigned long at)=0;
- virtual bool isSunk(unsigned long at)
- {
- if(at>=sourceIsSunk.size())
- throw eMsg("nameSource::isSunk(): The source does not exist");
- return sourceIsSunk[at];
- }
- virtual void setSunk(unsigned long at,bool isSunk=true)
- {
- if(at>=sourceIsSunk.size())
- throw eMsg("nameSource::setSunk(): The source does not exist");
- sourceIsSunk[at]=isSunk;
- }
- };
- class nameSink
- {
- protected:
- vector<nameSource*> sources;
- vector<unsigned long> atSources;
- void setSinkSize(unsigned long sz)
- {
- sources.resize(sz);
- atSources.resize(sz);
- }
- public:
- nameSink()
- {}
- virtual ~nameSink()
- {}
- unsigned long sinkSize()
- {
- return sources.size();
- }
- void setSource(unsigned long atSnk,nameSource* src,unsigned long atSrc)
- {
- if(atSnk>=sources.size())
- throw eMsg("nameSink: The sink does not exist");
- sources[atSnk]=src;
- atSources[atSnk]=atSrc;
- }
- bool sinkSet(unsigned long at)
- {
- if(at>=sources.size())
- throw eMsg("nameSink: The sink does not exist");
- if(sources[at]!=NULL)
- return true;
- return false;
- }
- virtual const char* getSinkDescription()=0;
- virtual const char* getSinkTermDescription(unsigned long at)=0;
- };
- class declaration
- {
- public:
- virtual void printDecl(ostream& out)=0;
- };
- class code
- {
- public:
- code()
- {}
- virtual ~code()
- {}
- virtual void writeCode(ostream& out)=0;
- };
- class function
- {
- public:
- virtual const char* getFunctionName()=0;
- virtual unsigned long getFunctionArgumentCount()=0;
- // virtual const char* getArgName(unsigned long at)=0;
- virtual const char* getArgumentDescription(unsigned long at)=0;
- };
- class nameMap : virtual public nameSource , virtual public nameSink
- {
- public:
- nameMap()
- {}
- virtual ~nameMap()
- {}
- };
- class mappingCode : public nameMap , public code
- {
- public:
- mappingCode()
- {}
- virtual ~mappingCode()
- {}
- };
- enum txtTYPE
- {
- ttINPUT,
- ttOUTPUT,
- ttTYPE,
- ttCUSTOM
- };
- class mapText
- {
- private:
- char* txt;
- unsigned long inCnt;
- unsigned long outCnt;
- unsigned long typeCnt;
- unsigned long custCnt;
- char* desc;
- char** inDesc;
- char** outDesc;
- char** tpDesc;
- char** cstDesc;
- void clearText()
- {
- if(txt!=NULL)
- delete[] txt;
- txt=NULL;
- if(desc!=NULL)
- delete[] desc;
- desc=NULL;
- if(inDesc!=NULL)
- {
- for(unsigned long i=0;i<inCnt;i++)
- {
- if(inDesc[i])
- delete[] inDesc[i];
- }
- delete[] inDesc;
- inDesc=NULL;
- }
- inCnt=0;
- if(outDesc!=NULL)
- {
- for(unsigned long i=0;i<outCnt;i++)
- {
- if(outDesc[i])
- delete[] outDesc[i];
- }
- delete[] outDesc;
- outDesc=NULL;
- }
- outCnt=0;
- if(tpDesc!=NULL)
- {
- for(unsigned long i=0;i<typeCnt;i++)
- {
- if(tpDesc[i])
- delete[] tpDesc[i];
- }
- delete[] tpDesc;
- tpDesc=NULL;
- }
- typeCnt=0;
- if(cstDesc!=NULL)
- {
- for(unsigned long i=0;i<custCnt;i++)
- {
- if(cstDesc[i])
- delete[] cstDesc[i];
- }
- delete[] cstDesc;
- cstDesc=NULL;
- }
- custCnt=0;
- }
- public:
- bool setText(const char* text)
- {
- clearText();
- if(text==NULL)
- {
- txt=NULL;
- return false;
- }
- else
- {
- txt=copyLine(text);
- if(txt==NULL)
- throw eMsg("mapText: Failed to allocate text");
- }
- unsigned long at=0;
- inCnt=0;
- outCnt=0;
- typeCnt=0;
- custCnt=0;
- while(txt[at]!=0)
- {
- if(txt[at]=='@')
- {
- char number[24];
- at++;
- if(txt[at]!='(')
- return false;
- at++;
- txtTYPE tt=ttINPUT;
- if(txt[at]=='o')
- tt=ttOUTPUT;
- else if(txt[at]=='i')
- tt=ttINPUT;
- else if(txt[at]=='t')
- tt=ttTYPE;
- else if(txt[at]=='c')
- tt=ttCUSTOM;
- else
- return false;
- at++;
- unsigned long i=0;
- while(txt[at]!=')' && txt[at]!=0)
- {
- if(!isdigit(txt[at]))
- return false;
- number[i++]=txt[at++];
- }
- number[i]=0;
- if(txt[at]==0)
- return false;
- if(txt[at]!=')')
- return false;
- unsigned long atTerm=atoi(number);
- switch(tt)
- {
- case ttOUTPUT:
- if(outCnt<(atTerm+1))
- outCnt=atTerm+1;
- break;
- case ttINPUT:
- if(inCnt<(atTerm+1))
- inCnt=atTerm+1;
- break;
- case ttTYPE:
- if(typeCnt<(atTerm+1))
- typeCnt=atTerm+1;
- break;
- case ttCUSTOM:
- if(custCnt<(atTerm+1))
- custCnt=atTerm+1;
- break;
- default:
- throw eMsg("mapText: An unexpected error occured");
- }
- }
- at++;
- }
- if(inCnt>0)
- {
- inDesc=new char*[inCnt];
- if(inDesc==NULL)
- throw eMsg("mapText::setText(): Failed to allocate memory");
- for(unsigned long i=0;i<inCnt;i++)
- inDesc[i]=NULL;
- }
- if(outCnt>0)
- {
- outDesc=new char*[outCnt];
- if(outDesc==NULL)
- throw eMsg("mapText::setText(): Failed to allocate memory");
- for(unsigned long i=0;i<outCnt;i++)
- outDesc[i]=NULL;
- }
- if(typeCnt>0)
- {
- tpDesc=new char*[typeCnt];
- if(tpDesc==NULL)
- throw eMsg("mapText::setText(): Failed to allocate memory");
- for(unsigned long i=0;i<typeCnt;i++)
- tpDesc[i]=NULL;
- }
- if(custCnt>0)
- {
- cstDesc=new char*[custCnt];
- if(cstDesc==NULL)
- throw eMsg("mapText::setText(): Failed to allocate memory");
- for(unsigned long i=0;i<custCnt;i++)
- cstDesc[i]=NULL;
- }
- return true;
- };
- mapText(const char* txt_in=NULL) : txt(NULL) , inCnt(0) , outCnt(0) , typeCnt(0) , custCnt(0) , desc(NULL) , inDesc(NULL) , outDesc(NULL) , tpDesc(NULL) , cstDesc(NULL)
- {
- if(txt_in!=NULL)
- {
- if(!setText(txt_in))
- throw eMsg("mapText::mapText(): Cannot create mapText with malformed text");
- }
- }
- ~mapText()
- {
- clearText();
- }
- mapText& setDescription(const char* dsc_in)
- {
- if(desc!=NULL)
- delete[] desc;
- if(dsc_in==NULL)
- desc=NULL;
- else
- {
- desc=copyLine(dsc_in);
- if(desc==NULL)
- throw eMsg("mapText::setDescription(): Failed to allocate memory");
- }
- return *this;
- }
- mapText& setInputDescription(unsigned long at, const char* dsc_in)
- {
- if(at>=inCnt)
- throw eMsg("mapText::setInputDescription(): The input description does not exist");
- if(inDesc==NULL)
- throw eMsg("mapText::setInputDescription(): The container for the input description has not been set");
- if(inDesc[at]!=NULL)
- delete[] inDesc[at];
- if(dsc_in==NULL)
- inDesc[at]=NULL;
- else
- {
- inDesc[at]=copyLine(dsc_in);
- if(inDesc[at]==NULL)
- throw eMsg("mapText::setInputDescription(): Failed to allocate memory");
- }
- return *this;
- }
- mapText& setOutputDescription(unsigned long at, const char* dsc_in)
- {
- if(at>=outCnt)
- throw eMsg("mapText::setOutputDescription(): The input description does not exist");
- if(outDesc==NULL)
- throw eMsg("mapText::setOutputDescription(): The container for the input description has not been set");
- if(outDesc[at]!=NULL)
- delete[] outDesc[at];
- if(dsc_in==NULL)
- outDesc[at]=NULL;
- else
- {
- outDesc[at]=copyLine(dsc_in);
- if(outDesc[at]==NULL)
- throw eMsg("mapText::setOutputDescription(): Failed to allocate memory");
- }
- return *this;
- }
- mapText& setTypeDescription(unsigned long at, const char* dsc_in)
- {
- if(at>=typeCnt)
- throw eMsg("mapText::setTypeDescription(): The input description does not exist");
- if(tpDesc==NULL)
- throw eMsg("mapText::setTypeDescription(): The container for the input description has not been set");
- if(tpDesc[at]!=NULL)
- delete[] tpDesc[at];
- if(dsc_in==NULL)
- tpDesc[at]=NULL;
- else
- {
- tpDesc[at]=copyLine(dsc_in);
- if(tpDesc[at]==NULL)
- throw eMsg("mapText::setTypeDescription(): Failed to allocate memory");
- }
- return *this;
- }
- mapText& setCustomDescription(unsigned long at, const char* dsc_in)
- {
- if(at>=custCnt)
- throw eMsg("mapText::setCustomDescription(): The input description does not exist");
- if(cstDesc==NULL)
- throw eMsg("mapText::setCustomDescription(): The container for the input description has not been set");
- if(cstDesc[at]!=NULL)
- delete[] cstDesc[at];
- if(dsc_in==NULL)
- cstDesc[at]=NULL;
- else
- {
- cstDesc[at]=copyLine(dsc_in);
- if(cstDesc[at]==NULL)
- throw eMsg("mapText::setCustomDescription(): Failed to allocate memory");
- }
- return *this;
- }
- const char* getTxt() const
- {
- return txt;
- }
- unsigned long getInCnt() const
- {
- return inCnt;
- }
- unsigned long getOutCnt() const
- {
- return outCnt;
- }
- unsigned long getTypeCnt() const
- {
- return typeCnt;
- }
- unsigned long getCustCnt() const
- {
- return custCnt;
- }
- const char* getDescription() const
- {
- return desc;
- }
- const char* getInputDescription(unsigned long at) const
- {
- if(at>=inCnt)
- throw eMsg("mapText::getInputDescription(): The requested description does not exist");
- return inDesc[at];
- }
- const char* getOutputDescription(unsigned long at) const
- {
- if(at>=outCnt)
- throw eMsg("mapText::getOutputDescription(): The description does not exist");
- return outDesc[at];
- }
- const char* getTypeDescription(unsigned long at) const
- {
- if(at>=typeCnt)
- throw eMsg("mapText::getTypeDescription(): The description does not exist");
- return tpDesc[at];
- }
- const char* getCustomDescription(unsigned long at) const
- {
- if(at>=custCnt)
- throw eMsg("mapText::getCustomDescription(): The description does not exist");
- return cstDesc[at];
- }
- };
- objList<mapText> textMaps;
- class nameMap_text : public mappingCode
- {
- private:
- const mapText* mpTxt;
- const char* txt;
- unsigned long outCnt;
- unsigned long typeCnt;
- unsigned long custCnt;
- vector<cppType*> types;
- vector<bool> canDelete;
- vector<char*> outNames;
- vector<char*> custNames;
- public:
- nameMap_text& setText(const mapText& mpTxt_in)
- {
- mpTxt=&mpTxt_in;
- this->txt=mpTxt->getTxt();
- this->outCnt=mpTxt->getOutCnt();
- this->typeCnt=mpTxt->getTypeCnt();
- this->custCnt=mpTxt->getCustCnt();
- types.resize(typeCnt,NULL);
- canDelete.resize(typeCnt,false);
- outNames.resize(outCnt,NULL);
- custNames.resize(custCnt,NULL);
- this->setSinkSize(mpTxt->getInCnt());
- this->setSourceSize(outCnt);
- return *this;
- }
- nameMap_text() : mpTxt(NULL) , txt(NULL) , outCnt(0) , typeCnt(0) , custCnt(0) , types(0,NULL) , canDelete(0,false) , outNames(0,NULL) , custNames(0,NULL)
- {}
- nameMap_text(const mapText& mpTxt_in) : mpTxt(NULL) , txt(NULL) , outCnt(0) , typeCnt(0) , custCnt(0) , types(0,NULL) , canDelete(0,false) , outNames(0,NULL) , custNames(0,NULL)
- {
- this->setText(mpTxt_in);
- }
- ~nameMap_text()
- {
- for(unsigned long i=0;i<types.size();i++)
- {
- if(types[i]!=NULL && canDelete[i])
- delete types[i];
- }
- for(unsigned long i=0;i<outNames.size();i++)
- {
- if(outNames[i]!=NULL)
- delete[] outNames[i];
- }
- for(unsigned long i=0;i<custNames.size();i++)
- {
- if(custNames[i]!=NULL)
- delete[] custNames[i];
- }
- }
- nameMap_text& setOutName(unsigned long at,const char* name)
- {
- if(at>=outNames.size())
- throw eMsg("nameMap_text: The nameMap does not have those outputs");
- if(outNames[at]!=NULL)
- delete[] outNames[at];
- outNames[at]=NULL;
- if(name==NULL)
- return *this;
- outNames[at]=copyLine(name);
- if(outNames[at]==NULL)
- throw eMsg("nameMap_text: failed to allocate memory");
- return *this;
- }
- const char* getOutName(unsigned long at)
- {
- if(at>=outNames.size())
- throw eMsg("nameMap_text: The output does not exist");
- return outNames[at];
- }
- unsigned long outNameCount()
- {
- return outNames.size();
- }
- nameMap_text& setCustName(unsigned long at,const char* name)
- {
- if(at>=custNames.size())
- throw eMsg("nameMap_text: The nameMap does not have those customs");
- if(custNames[at]!=NULL)
- delete[] custNames[at];
- custNames[at]=NULL;
- if(name==NULL)
- return *this;
- custNames[at]=copyLine(name);
- if(custNames[at]==NULL)
- throw eMsg("nameMap_text: failed to allocate memory");
- return *this;
- }
- const char* getCustName(unsigned long at)
- {
- if(at>=custNames.size())
- throw eMsg("nameMap_text: The custom does not exist");
- return custNames[at];
- }
- unsigned long custNameCount()
- {
- return custNames.size();
- }
- nameMap_text& setCppType(unsigned long at, cppType* type_in,bool canDelete_in=false)
- {
- if(at>=types.size())
- throw eMsg("nameMap_text: The type does not exist");
- if(types[at]!=NULL && types[at]!=type_in && canDelete[at])
- delete types[at];
- types[at]=type_in;
- canDelete[at]=canDelete_in;
- return *this;
- }
- cppType* getCppType(unsigned long at)
- {
- if(at>=types.size())
- throw eMsg("nameMap_text: The type does not exist");
- return types[at];
- }
- unsigned long getTypeCount()
- {
- return types.size();
- }
- void writeCode(ostream& out)
- {
- if(txt==NULL)
- return;
- unsigned long at=0;
- while(txt[at]!=0)
- {
- if(txt[at]=='@')
- {
- char number[24];
- at++;
- if(txt[at]!='(')
- throw eMsg("nameMap_text: malformed text");
- at++;
- txtTYPE tt=ttINPUT;
- if(txt[at]=='o')
- tt=ttOUTPUT;
- else if(txt[at]=='i')
- tt=ttINPUT;
- else if(txt[at]=='t')
- tt=ttTYPE;
- else if(txt[at]=='c')
- tt=ttCUSTOM;
- else
- throw eMsg("nameMap_text: The text is malformed");
- at++;
- unsigned long i=0;
- while(txt[at]!=')' && txt[at]!=0)
- {
- if(!isdigit(txt[at]))
- throw eMsg("nameMap_text: malformed text");
- number[i++]=txt[at++];
- }
- if(txt[at]==0)
- throw eMsg("nameMap_text: malformed text");
- if(txt[at]!=')')
- throw eMsg("nameMap_text: malformed text");
- number[i]=0;
- unsigned long atTerm=atoi(number);
- switch(tt)
- {
- case ttOUTPUT:
- if(atTerm>=outCnt)
- throw eMsg("nameMap_text: specified an output that does not exist");
- if(outNames[atTerm]==NULL)
- throw eMsg("nameMap_text: not all the outputs have been specified");
- out << outNames[atTerm];
- break;
- case ttINPUT:
- if(atTerm>=this->sinkSize())
- throw eMsg("nameMap_text: specified and input that does not exist");
- if(this->sources[atTerm]==NULL)
- throw eMsg("nameMap_text: the input data has not been specified");
- out << this->sources[atTerm]->getSourceName(this->atSources[atTerm]);
- break;
- case ttTYPE:
- if(atTerm>=typeCnt)
- throw eMsg("nameMap_text: The requested type does not exist");
- if(types[atTerm]==NULL)
- throw eMsg("nameMap_text: The requested type has not been specified");
- types[atTerm]->printType(out);
- break;
- case ttCUSTOM:
- if(atTerm>=custCnt)
- throw eMsg("nameMap_text: The requested custom does not exist");
- if(custNames[atTerm]==NULL)
- throw eMsg("nameMap_text: The requested custom has not been specified");
- out << custNames[atTerm];
- break;
- default:
- throw eMsg("nameMap_text: There was an error trying to fill in a custom item");
- }
- }
- else
- {
- out << txt[at];
- }
- at++;
- }
- out << endl;
- }
- const char* getSinkDescription()
- {
- if(mpTxt==NULL)
- throw eMsg("nameMap_text::getSinkDescription(): The text does not exist");
- return mpTxt->getDescription();
- }
- const char* getSinkTermDescription(unsigned long at)
- {
- if(mpTxt==NULL)
- throw eMsg("nameMap_text::getSinkTermDescription(): The text does not exist");
- return mpTxt->getInputDescription(at);
- }
- const char* getSourceName(unsigned long at)
- {
- if(at>=outCnt)
- throw eMsg("nameMap_text::getSourceName(): The source name does not exist");
- return outNames[at];
- }
- const char* getSourceDescription()
- {
- if(mpTxt==NULL)
- throw eMsg("nameMap_text::getSourceDescription(): The text has not been set");
- return mpTxt->getDescription();
- }
- const char* getSourceTermDescription(unsigned long at)
- {
- if(mpTxt==NULL)
- throw eMsg("nameMap_text::getSourceTermDescription(): The text source has not been set");
- return mpTxt->getOutputDescription(at);
- }
- };
- class returnSink : public mappingCode
- {
- public:
- returnSink()
- {
- this->setSourceSize(0);
- this->setSinkSize(1);
- }
- const char* getSinkDescription()
- {
- return "Returns a varible";
- }
- const char* getSinkTermDescription(unsigned long at)
- {
- return "The variable to be sunk";
- }
- const char* getSourceName(unsigned long at)
- {
- throw eMsg("returnSink::getSourceName(): This object is not meant to return any source information");
- }
- const char* getSourceDescription()
- {
- return "This is an empty source that merely returns a variable";
- }
- const char* getSourceTermDescription(unsigned long at)
- {
- throw eMsg("returnSink::getSourceTermDescription(): This object has not sources");
- }
- void writeCode(ostream& out)
- {
- out << "\treturn " << this->sources[0]->getSourceName(this->atSources[0]) << ';' << endl;
- }
- };
- class returnValue : public mappingCode
- {
- private:
- char* value;
- public:
- returnValue(const char* val=NULL) : value(NULL)
- {
- this->setSourceSize(0);
- this->setSinkSize(0);
- if(val!=NULL)
- {
- value=copyLine(val);
- if(value==NULL)
- throw eMsg("returnValue::returnValue(): Failed to allocate memory");
- }
- }
- ~returnValue()
- {
- if(value!=NULL)
- delete[] value;
- }
- returnValue& setValue(const char* val)
- {
- if(value!=NULL)
- delete[] value;
- if(val==NULL)
- {
- value=NULL;
- return *this;
- }
- value=copyLine(val);
- if(value==NULL)
- throw eMsg("returnValue::setValue(): Failed to allocate memory");
- return *this;
- }
- const char* getSinkDescription()
- {
- return "This is an empty sink that returns a value";
- }
- const char* getSinkTermDescription(unsigned long at)
- {
- throw eMsg("returnValue::getSinkTermDescription(): This is an empty sink");
- }
- const char* getSourceName(unsigned long at)
- {
- throw eMsg("returnValue::getSourceName(): This is an empty source");
- }
- const char* getSourceDescription()
- {
- return "This is an empty source that return a value";
- }
- const char* getSourceTermDescription(unsigned long at)
- {
- throw eMsg("returnValue::getSourceTermDescription(): This is an empty source");
- }
- void writeCode(ostream& out)
- {
- if(value==NULL)
- throw eMsg("returnValue::writeCode(): The value has not been set");
- out << "\treturn " << value << ';' << endl;
- }
- };
- class callingCode : public mappingCode
- {
- protected:
- function* func;
- bool canDelete;
- unsigned long inExtra;
- void printCall(ostream& out)
- {
- if(func==NULL)
- throw eMsg("callingCode::printCall(): The calling code does not have a function to call");
- out << func->getFunctionName() << "( ";
- bool isFirst=true;
- for(unsigned long i=0;i<func->getFunctionArgumentCount();i++)
- {
- if(!isFirst)
- out << " , ";
- out << this->sources[i]->getSourceName(this->atSources[i]);
- isFirst=false;
- }
- out << " )";
- }
- callingCode(unsigned long outCnt,function* func_in=NULL,bool canDelete_in=false, unsigned long inExtra_in=0) : func(func_in) , canDelete(canDelete_in) , inExtra(inExtra_in)
- {
- if(func_in!=NULL)
- this->setSinkSize(func_in->getFunctionArgumentCount());
- this->setSourceSize(outCnt);
- }
- public:
- callingCode(function* func_in=NULL,bool canDelete_in=false) : func(func_in) , canDelete(canDelete_in) , inExtra(0)
- {
- if(func_in!=NULL)
- this->setSinkSize(func_in->getFunctionArgumentCount());
- this->setSourceSize(0);
- }
- virtual ~callingCode()
- {
- if(func!=NULL && canDelete)
- delete func;
- }
- virtual void setFunction(function* func_in,bool canDelete_in=false)
- {
- if(func!=NULL && func!=func_in && canDelete)
- delete func;
- func=func_in;
- canDelete=canDelete_in;
- if(func!=NULL)
- this->setSinkSize(func->getFunctionArgumentCount()+inExtra);
- }
- virtual void writeCode(ostream& out)
- {
- out << '\t';
- this->printCall(out);
- out << ';' << endl;
- }
- virtual const char* getSourceName(unsigned long at)
- {
- throw eMsg("callingCode::getSourceName(): This code provides no sources");
- }
- virtual const char* getSourceDescription()
- {
- return "This calls a function, no new variables are created";
- }
- virtual const char* getSourceTermDescription(unsigned long at)
- {
- throw eMsg("callingCode::getSourceDescription(): This code provides no sources");
- }
- virtual const char* getSinkDescription()
- {
- return "This calls a function where each argument is an input to this code segment";
- }
- virtual const char* getSinkTermDescription(unsigned long at)
- {
- if(func==NULL)
- throw eMsg("callingCode::getSinkTermDescription(): The function has not been set");
- if(at>=this->sinkSize())
- throw eMsg("callingCode::getSinkTermDescription(): The sink does not exist");
- return func->getArgumentDescription(at);
- }
- };
- class callingCode_return : public callingCode
- {
- public:
- callingCode_return(function* func_in=NULL,bool canDelete_in=false) : callingCode(func_in,canDelete_in)
- {}
- void writeCode(ostream& out)
- {
- out << "\treturn ";
- this->printCall(out);
- out << ';' << endl;
- }
- const char* getSinkDescription()
- {
- return "return a function call where each argument is an input to this code segment";
- }
- const char* getSourceDescription()
- {
- return "This calls a function, no new variables are created because it returns";
- }
- };
- class callingCode_assignNew : public callingCode
- {
- private:
- cppType* retType;
- char* retVar;
- bool deleteRet;
- public:
- callingCode_assignNew(function* func_in=NULL,bool canDelete_in=false, cppType* retType_in=NULL, const char* retVar_in=NULL, bool deleteRet_in=false) : callingCode(1,func_in,canDelete_in) , retType(retType_in) , retVar(NULL) , deleteRet(deleteRet_in)
- {
- if(retVar_in!=NULL)
- {
- retVar=copyLine(retVar_in);
- if(retVar==NULL)
- throw eMsg("callingCode_assignNew::callingCode_assignNew(): Failed to allocate memory");
- }
- }
- ~callingCode_assignNew()
- {
- if(retType!=NULL && deleteRet)
- delete retType;
- if(retVar!=NULL)
- delete[] retVar;
- }
- callingCode_assignNew& setVariable(cppType* retType_in,const char* retVar_in,bool deleteRet=false)
- {
- if(retType!=NULL && deleteRet)
- delete retType;
- if(retVar!=NULL)
- delete[] retVar;
- retType=retType_in;
- if(retVar_in==NULL)
- {
- retVar=NULL;
- }
- else
- {
- retVar=copyLine(retVar_in);
- if(retVar==NULL)
- throw eMsg("callingCode_assignNew::setVariable(): Failed to allocate memory");
- }
- return *this;
- }
- void writeCode(ostream& out)
- {
- if(retType==NULL || retVar==NULL)
- throw eMsg("callingCode_assignNew::writeCode(): Not all the inputs have been specified");
- out << '\t';
- retType->printType(out);
- out << ' ' << retVar << '=';
- this->printCall(out);
- out << ';' << endl;
- }
- const char* getSinkDescription()
- {
- return "return a function call where each argument is an input to this code segment";
- }
- const char* getSourceName(unsigned long at)
- {
- if(at!=0)
- throw eMsg("callingCode_assignNew::getSourceName(): The output does not exist");
- if(retVar==NULL)
- throw eMsg("callingCode_assignNew::getSourceName(): The output has not been specified");
- return retVar;
- }
- const char* getSourceDescription()
- {
- return "The calls a function, the return value is assigned to this code segments output variable";
- }
- const char* getSourceTermDescription(unsigned long at)
- {
- if(at!=0)
- throw eMsg("callingCode_assignNew::getSourceTermDescription(): The output does not exist");
- return "The variable return value is assigned to";
- }
- };
- class callingCode_assignOld : public callingCode
- {
- public:
- callingCode_assignOld(function* func_in=NULL,bool canDelete_in=false) : callingCode(0,func_in,canDelete_in,1)
- {}
- void writeCode(ostream& out)
- {
- unsigned long atSink=this->sinkSize()-1;
- out << '\t' << this->sources[atSink]->getSourceName(this->atSources[atSink]) << '=';
- this->printCall(out);
- out << ';' << endl;
- }
- const char* getSinkDescription()
- {
- return "return a function call where each argument is an input to this code segment, the return value is assigned to an old variable";
- }
- const char* getSourceDescription()
- {
- return "This calls a function, no new variables are created because it returns";
- }
- const char* getSinkTermDescription(unsigned long at)
- {
- if(at>=this->sinkSize())
- throw eMsg("callingCode_assignOld::getSinkTermDescription(): THe sink does not exist");
- if(at<(this->sinkSize()-1))
- return callingCode::getSinkTermDescription(at);
- return "The variable where the return value is assigned";
- }
- };
- class cppFunctionCode : public declaration
- {
- public:
- virtual void writeDefinition(ostream& out)=0;
- };
- class cppFunctionName;
- class cppFunctionInstance;
- class cppFunctionName
- {
- private:
- char* name;
- list<cppFunctionInstance*> funcList;
- bool isEqual(cppFunctionInstance* rhs,cppFunctionInstance* lhs);
- public:
- cppFunctionName(const char* fName=NULL);
- virtual ~cppFunctionName();
- const char* getName();
- bool isUnique(cppFunctionInstance* fnc_test);
- unsigned long getFunctionCount();
- cppFunctionInstance* getFunctionInstance(unsigned long at);
- cppFunctionInstance* createFunctionInstance();
- void deleteLastInstance();
- };
- class cppFunctionInstance : public cppFunctionCode , public nameSource
- {
- private:
- cppFunctionName* funcNameSource;
- list<mappingCode*> mapCodePointers;
- list<bool> delMapCode;
- callingCode* myCall;
- bool deleteCall;
- list<code*> defnCode;
- list<nameSource*> sources;
- list<nameSink*> sinks;
- vector<variable*> args;
- vector<bool> deleteVar;
- vector<char*> argDesc;
- vector<bool> sunk;
- cppType* retType;
- bool callAdded;
- bool retCalled;
- bool areSinksClosed();
- void printFunctionDecl(ostream& out);
- public:
- cppFunctionInstance(cppFunctionName* funcNameSource_in);
- ~cppFunctionInstance();
- unsigned long getArgumentCount();
- cppFunctionInstance& setArgumentCount(unsigned long argCnt);
- cppFunctionInstance& addArgument(unsigned long at, variable* arg,const char* desc,bool canDelete_in=false);
- cppFunctionInstance& defineReturn(cppType* retType_in);
- variable* getVariable(unsigned long at);
- bool checkSinks();
- bool canWrite();
- bool canAdd();
- bool canAddCall();
- cppFunctionInstance& addMap(mappingCode* mpCd_in,bool retCall=false,bool canDelete_in=false);
- cppFunctionInstance& addCall(callingCode* clCd_in,bool retCall=false,bool canDelete_in=false);
- unsigned long sourceObjectCount();
- unsigned long sinkObjectCount();
- nameSource* getSource(unsigned long at);
- nameSink* getSink(); // returns the most recently added sink
- nameSink* getSink(unsigned long at);
- // this is inherited from nameSource
- unsigned long sourceSize();
- const char* getSourceName(unsigned long at);
- const char* getSourceDescription();
- const char* getSourceTermDescription(unsigned long at);
- bool isSunk(unsigned long at);
- void setSunk(unsigned long at,bool isSunk=true);
- void writeDefinition(ostream& out);
- void printDecl(ostream& out);
- };
- bool cppFunctionName::isEqual(cppFunctionInstance* rhs,cppFunctionInstance* lhs)
- {
- if(rhs->getArgumentCount()!=lhs->getArgumentCount())
- return false;
- for(unsigned long i=0;i<rhs->getArgumentCount();i++)
- {
- if((*(rhs->getVariable(i)->getType()))!=(*(lhs->getVariable(i)->getType())))
- return false;
- }
- return true;
- }
- cppFunctionName::cppFunctionName(const char* fName) : name(NULL)
- {
- if(fName!=NULL)
- {
- name=copyLine(fName);
- if(name==NULL)
- throw eMsg("cppFunctionName: Failed to allocate memory");
- }
- }
- cppFunctionName::~cppFunctionName()
- {
- if(name!=NULL)
- delete[] name;
- for(list<cppFunctionInstance*>::iterator it=funcList.begin();it!=funcList.end();it++)
- {
- if((*it)!=NULL)
- delete *it;
- }
- }
- const char* cppFunctionName::getName()
- {
- if(name==NULL)
- throw eMsg("cppFunctionName: The function name has not been specified");
- return name;
- }
- bool cppFunctionName::isUnique(cppFunctionInstance* fnc_test)
- {
- for(list<cppFunctionInstance*>::iterator it=funcList.begin();it!=funcList.end();it++)
- {
- if(fnc_test!=*it)
- {
- if(isEqual(fnc_test,*it))
- return false;
- }
- }
- return true;
- }
- unsigned long cppFunctionName::getFunctionCount()
- {
- return funcList.size();
- }
- cppFunctionInstance* cppFunctionName::getFunctionInstance(unsigned long at)
- {
- if(at>=funcList.size())
- throw eMsg("cppFunctionName::getFunctionInstance(): The function instance does not exist");
- list<cppFunctionInstance*>::iterator it=funcList.begin();
- for(unsigned long i=0;i<at;i++)
- it++;
- return *it;
- }
- cppFunctionInstance* cppFunctionName::createFunctionInstance()
- {
- funcList.push_back(new cppFunctionInstance(this));
- if(funcList.back()==NULL)
- throw eMsg("cppFunctionName::createFunctionInstance(): Failed to allocate memory");
- return funcList.back();
- }
- void cppFunctionName::deleteLastInstance()
- {
- if(funcList.size()==0)
- return;
- delete funcList.back();
- funcList.pop_back();
- }
- bool cppFunctionInstance::areSinksClosed()
- {
- if(sinks.size()>0)
- {
- nameSink* lstSnk=sinks.back();
- for(unsigned long i=0;i<lstSnk->sinkSize();i++)
- {
- if(!lstSnk->sinkSet(i))
- return false;
- }
- }
- return true;
- }
- void cppFunctionInstance::printFunctionDecl(ostream& out)
- {
- if(retType==NULL || funcNameSource==NULL)
- throw eMsg("cppFunctionInstance::printFunctionDecl(): Not all the inputs have been set");
- if(!funcNameSource->isUnique(this))
- throw eMsg("cppFunctionInstance::printFunctionDecl(): This function instance is not unique");
- for(unsigned long i=0;i<args.size();i++)
- {
- if(args[i]==NULL)
- throw eMsg("cppFunctionInstance::printFunctionDecl(): Not all the inputs have been set");
- }
- retType->printType(out);
- out << ' ';
- out << funcNameSource->getName();
- out << "( ";
- bool isFirst=true;
- for(unsigned long i=0;i<args.size();i++)
- {
- if(!isFirst)
- out << " , ";
- args[i]->printDecl(out);
- isFirst=false;
- }
- out << " )";
- }
- cppFunctionInstance::cppFunctionInstance(cppFunctionName* funcNameSource_in) : funcNameSource(funcNameSource_in) , callAdded(false) , retCalled(false)
- {
- sources.push_back(this);
- }
- cppFunctionInstance::~cppFunctionInstance()
- {
- for(unsigned long i=0;i<argDesc.size();i++)
- {
- if(argDesc[i]!=NULL)
- delete[] argDesc[i];
- }
- for(unsigned long i=0;i<args.size();i++)
- {
- if(args[i]!=NULL && deleteVar[i])
- delete args[i];
- }
- typename list<mappingCode*>::iterator itPntr=mapCodePointers.begin();
- for(typename list<bool>::iterator itDel=delMapCode.begin();itDel!=delMapCode.end();itDel++)
- {
- if((*itPntr)!=NULL && (*itDel))
- delete (*itPntr);
- itPntr++;
- }
- }
- unsigned long cppFunctionInstance::getArgumentCount()
- {
- return args.size();
- }
- cppFunctionInstance& cppFunctionInstance::setArgumentCount(unsigned long argCnt)
- {
- for(unsigned long i=argCnt;i<argDesc.size();i++)
- {
- if(deleteVar[i])
- delete args[i];
- delete[] argDesc[i];
- argDesc[i]=NULL;
- }
- args.resize(argCnt,NULL);
- argDesc.resize(argCnt,NULL);
- deleteVar.resize(argCnt,false);
- sunk.resize(argCnt,false);
- return *this;
- }
- cppFunctionInstance& cppFunctionInstance::addArgument(unsigned long at, variable* arg,const char* desc,bool canDelete_in)
- {
- if(at>=args.size())
- throw eMsg("cppFunctionInstance::addArgument(): The argument does not exist");
- if(args[at]!=NULL && args[at]!=arg && deleteVar[at])
- delete args[at];
- args[at]=arg;
- deleteVar[at]=canDelete_in;
- if(argDesc[at]!=NULL)
- delete[] argDesc[at];
- argDesc[at]=copyLine(desc);
- if(argDesc[at]==NULL)
- throw eMsg("cppFunctionInstance::addArgument(): Failed to allocate memory");
- return *this;
- }
- cppFunctionInsta…
Large files files are truncated, but you can click here to view the full file