##// END OF EJS Templates
Work in progress.
Work in progress.

File last commit:

r2:f40b36fd7205 tip default
r2:f40b36fd7205 tip default
Show More
vhdl_file.cpp
87 lines | 2.0 KiB | text/x-c | CppLexer
#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(&currentNode,&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(&currentNode,openBlocksContext);
break;
case architecture:
parse_Architecture(&currentNode,openBlocksContext);
break;
case clause:
parse_Clause(&currentNode,openBlocksContext);
break;
case package:
parse_Package(&currentNode,openBlocksContext);
break;
default:
walk_forward(&currentNode,0);
break;
}
}
*rootNode =currentNode;
return 0;
}