vrq
/usr/src/RPM/BUILD/vrq-1.0.96/src/cbackend.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Copyright (C) 1997-2007, Mark Hummel
00003  * This file is part of Vrq.
00004  *
00005  * Vrq is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * Vrq is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
00018  * Boston, MA  02110-1301  USA
00019  *****************************************************************************
00020  */
00021 /******************************************************************************
00022  *
00023  *
00024  *         cbackend.hpp
00025  *              - abstract class definition for code generators 
00026  *
00027  ******************************************************************************
00028  */
00029 
00030 #ifndef CBACKEND_HPP
00031 #define CBACKEND_HPP
00032 
00033 #include <stdio.h>
00034 #include "glue.h"
00035 #include <list>
00036 #include <map>
00037 #include <string>
00038 
00039 using namespace std;
00040 
00041 class CNode;
00042 class CModule;
00043 class CInstance;
00044 class CObstack;
00045 
00178 class CElement
00179 {
00180 private:
00181     string filename;       // Optional filename for compilation unit
00182     int    filenameValid;  // non-zero to indicate filename is valid
00183     CNode* code;           // parse tree pointer for compilation unit
00184 public:
00191     CElement( const char* filename, int filenameValid, CNode* code ) :
00192         filename(filename),
00193         filenameValid( filenameValid ),
00194         code(code ) {}
00200     const char* Filename() { return filenameValid ? filename.c_str() : NULL; }
00205     CNode* Code() { return code; }      
00210     void   Code( CNode* code ) { this->code = code; }   
00211 };
00212 
00216 class CBackendException {};
00221 class CBackendAbort : CBackendException {};
00226 class CBackendExit : CBackendException {};
00231 class CBackendFail : CBackendException {};
00232 
00249 class CBackend 
00250 {
00251 protected:
00252     list<string>       switches;  
00253     map<string,string> switchDescription; 
00254 public:
00259         virtual char* GetToolName( void ) = 0;
00264         virtual char* GetToolDescription( void ) = 0;
00271         virtual int AcceptAllPlusArgs( void ) { return FALSE; }
00277         virtual list<string>& GetSwitches( void ) {return switches;}
00284         virtual const char* GetSwitchDescription( const char* sw ) 
00285         {
00286             MASSERT( switchDescription.find(sw) != 
00287                                 switchDescription.end() );
00288             return switchDescription[sw].c_str();
00289         }
00296         virtual void RegisterSwitch( const char* switchName, 
00297                                                 const char* description )
00298         {
00299             switches.push_back( switchName );
00300             switchDescription[switchName] = description;
00301         }
00308         virtual int RequireModuleResolution() { return TRUE; }
00315         virtual int ResolveModules() = 0;
00323         virtual int ResolveInstance( CModule* module, CInstance* inst ) = 0;
00332         virtual int HideTool() { return FALSE; } 
00343         virtual int IgnoreVrqComments() { return FALSE; }
00348         virtual void Activate() = 0;
00361         virtual void Process( list<CElement>& inputList,
00362                               list<CElement>& outputList ) = 0;
00363 };
00364 
00365 #endif // CBACKEND_HPP