|
|
#include "vhdl_file.h"
|
|
|
#include <QDebug>
|
|
|
|
|
|
VHDL_Tools::VHDL_File::VHDL_File()
|
|
|
{
|
|
|
this->scanner = NULL;
|
|
|
}
|
|
|
|
|
|
|
|
|
bool VHDL_Tools::VHDL_File::parseFile(const QString &file, bool trashPreviousTree)
|
|
|
{
|
|
|
std::ifstream in_file( file.toStdString().c_str() );
|
|
|
if( ! in_file.good() ) return false;
|
|
|
if(scanner==NULL)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
scanner = new VHDL_Tools::vhdl_Scanner( &in_file ,file);
|
|
|
}
|
|
|
catch( std::bad_alloc &ba )
|
|
|
{
|
|
|
std::cerr << "Failed to allocate scanner: (" <<
|
|
|
ba.what() << ")\n";
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
qDebug()<<"Parsing File "<<file<<"\n";
|
|
|
scanner->newFile(&in_file,file,trashPreviousTree);
|
|
|
while (scanner->scan()!=0);
|
|
|
makeParseTree(scanner->getScanTree());
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
VHDL_Tools::VHDL_AST_Node *VHDL_Tools::VHDL_File::getParseTree()
|
|
|
{
|
|
|
return rootNode;
|
|
|
}
|
|
|
|
|
|
int VHDL_Tools::VHDL_File::makeParseTree(VHDL_AST_Node *rootNode)
|
|
|
{
|
|
|
this->rootNode = rootNode;
|
|
|
VHDL_AST_Node *currentNode=rootNode;
|
|
|
QStack<VHDL_AST_Node*> openBlocks;
|
|
|
openBlocks.push(rootNode);
|
|
|
do
|
|
|
{
|
|
|
parseNext(¤tNode,&openBlocks);
|
|
|
}while(currentNode->childs.count());
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
int VHDL_Tools::VHDL_File::parseNext(VHDL_Tools::VHDL_AST_Node **rootNode, QStack<VHDL_Tools::VHDL_AST_Node *> *openBlocksContext)
|
|
|
{
|
|
|
VHDL_AST_Node *currentNode=*rootNode;
|
|
|
if(currentNode)
|
|
|
{
|
|
|
switch (currentNode->type)
|
|
|
{
|
|
|
case entity:
|
|
|
parse_Entity(¤tNode,openBlocksContext);
|
|
|
break;
|
|
|
case architecture:
|
|
|
parse_Architecture(¤tNode,openBlocksContext);
|
|
|
break;
|
|
|
case clause:
|
|
|
parse_Clause(¤tNode,openBlocksContext);
|
|
|
break;
|
|
|
case package:
|
|
|
parse_Package(¤tNode,openBlocksContext);
|
|
|
break;
|
|
|
default:
|
|
|
walk_forward(¤tNode,0);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
*rootNode =currentNode;
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|