#ifndef VHDL_IMPORT_H
#define VHDL_IMPORT_H

#include <string>
#include <list>

#include "../hub.h"
#include "../structural.h"
#include "../attr.h"
#include "vhdl_bison_parser.hpp"
#include "../named.h"
#include "../import.h"
#include "../location.h"
#include "../symfunc.h"
#include "../named.h"

class VhdlImport: public VhdlParserClient, public Import {
    
    VhdlParser parser_;
	// ---------------- context other than Location ----------------------------------
	hub::StructArch*    theArchImpl_;		// current structure
	hub::Instance* 		theInstance_;		// current instance
	hub::Name			synthLibName_;		// library name for existing primitives
	hub::Library*		theSynthLib_;		// library for synthesized primitives

	hub::Entity*		theComponent_;		// current component (declaration)
	hub::number_t		compPortsCount_;		// port count of current component 

	hub::Joinable* lastPort_;
			      
protected:
    // ---- interface to semantic classes
	virtual void haveUnit(void);
	virtual void endUnit(void);
	virtual void haveEntity( const StringToken& entName );
	virtual void endEntity(void);
	virtual void havePort(InterfaceDecl& intDecl );
	virtual void haveArch(const StringToken& archName,const StringToken& entName );
	virtual void endArch(const StringToken& archName ="" );
		//signal declaration
	virtual void haveSignalDeclar( InterfaceDecl intDecl );
		//component declaration
	virtual void haveComponent(const StringToken& compName);
	virtual void endComponent(const StringToken& compName);
	virtual void haveComponentPort(InterfaceDecl& intDecl );
		// component instantion
	virtual void haveComponentInst(const StringToken& label, const StringToken& compName,const StringToken& archName);
	virtual void havePortAssoc(const StringToken& compPortName,const StringToken& NetName);
	virtual void havePosPortAssoc(int portPosition, const StringToken& NetName);
	virtual void endComponentInst(void);
		//signal_assignment
	virtual StringToken* haveSymFunc(const std::list<StringToken> listInputNames,
		const std::string& func, bool createNet = true);
	virtual void haveOperand(const StringToken& portName ); 
	virtual void haveSignalAssignment(StringToken targetName, Expr* waveform );
	void paramsCheck (void);
	const hub::PortProto::flagsType&  DecodeDir( const Mode m ); 
	static hub::SymFunc::Func decodeFunc ( const std::string& func); 


public:
    // ---- import method
    virtual void operator() (const std::string& ="");
    virtual void operator() (hub::Library*,      const std::string& ="");
    virtual void operator() (hub::Entity*,       const std::string& ="");
    virtual void operator() (hub::Architecture*, const std::string& ="");

    VhdlImport (hub::Hub* h, const std::string& fn="" ): 
    Import (h, fn), 
    parser_(this) {}

    VhdlImport (hub::Library* lib, const std::string& fn="" ): 
    Import (lib, fn), 
    parser_(this) {}

    VhdlImport (hub::Entity* ent, const std::string& fn="" ): 
    Import (ent, fn), 
    parser_(this) {}

    VhdlImport (hub::Architecture* arch, const std::string& fn="" ): 
    Import (arch, fn), 
    parser_(this) {}

    ~VhdlImport () {}
	

};

#endif
