Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

application.hh

00001 /*
00002 *  Name:      application.hh
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   UESQLC application
00005 *  Date:      $Date: 2003/10/06 13:21:36 $
00006 *  Revision:  $Revision: 1.40 $
00007 *
00008 *  Copyright (C) 1996-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #ifndef _UESQLC_APPLICATION__
00027 #define _UESQLC_APPLICATION__
00028 
00029 #include <cstdio>
00030 #include <mpcl/abstract_application.hh>
00031 #include <mpcl/memory/smart_pointer.hh>
00032 #include <mpcl/text/codegen/pattern_based_code_generator.hh>
00033 #include <mpcl/util/collection/map.hh>
00034 #include <mpcl/util/collection/string_to_string_map.hh>
00035 #include <mpcl/util/prefs/config_processor.hh>
00036 #include <mpcl/text/codegen/variable_string.hh>
00037 #include "defs.hh"
00038 #include "invariant_verifier.hh"
00039 
00040 using mpcl::memory::TSmartPointer;
00041 using mpcl::text::TString;
00042 using mpcl::text::codegen::TPatternBasedCodeGenerator;
00043 using mpcl::text::codegen::TStringToVariableMap;
00044 using mpcl::text::codegen::TVariableString;
00045 using mpcl::util::collection::TMap;
00046 using mpcl::util::collection::TStringToStringMap;
00047 using mpcl::util::prefs::TConfigProcessor;
00048 
00049 
00051 class TApplication : public mpcl::TAbstractApplication
00052 {
00053 
00054   private:
00055 
00057     typedef 
00058       TSmartPointer <TPatternBasedCodeGenerator>  
00059       QTPatternBasedCodeGenerator;
00060 
00065     typedef
00066       TMap<TString, QTPatternBasedCodeGenerator>
00067       TTargetToCodeGeneratorMap;
00068 
00070     typedef
00071       TMap<TString, TStringToVariableMap>
00072       TTargetToRuntimeParametersMapMap;
00073 
00074 
00075   private:
00076 
00078     static const char* const   _pkcExtension;
00079 
00081     bool   gCfgComplementaryFiles;
00082     
00084     bool   gCfgHelp;
00085 
00087     bool   gCfgLineDirectives;
00088 
00090     bool   gCfgMainFile;
00091     
00093     bool   gCfgOutputCdml;
00094 
00096     bool   gCfgOutputCdmlSkel;
00097 
00099     bool   gCfgParameters;
00100 
00102     bool   gCfgSyntaxCheckOnly;
00103 
00105     bool   gCfgVersion;
00106 
00108     bool   gCompilationOk;
00109 
00111     bool   gReusingTarget;
00112 
00114     TStringToVariableMap*   ptRuntimeParametersMap;
00115 
00117     TStringToVariableMap   tCodeParametersMap;
00118 
00120     TConfigProcessor   tConfigProcessor;
00121 
00123     TInvariantVerifier   tInvariantVerifier;
00124 
00129     TMap<TString, long int>   tReservedWordMap;
00130 
00135     TTargetToCodeGeneratorMap   tTargetToCodeGeneratorMap;
00136 
00138     TTargetToRuntimeParametersMapMap   tTargetToRuntimeParametersMapMap;
00139 
00141     unsigned int   uiCfgDebug;
00142 
00144     TString   yCfgCdmlPath;
00145 
00147     TString   yCfgComplementaryFileDirectory;
00148 
00150     TString   yCfgLanguage;
00151 
00153     TString   yCfgTarget;
00154 
00156     TString   yCurrentInputFileName;
00157 
00159     TString   yCurrentTarget;
00160 
00162     TString   yLastToken;
00163 
00165     TString   yOutputCode;
00166 
00168     TString   yPostfixOutputCode;
00169 
00171     TString   yPrefixOutputCode;
00172 
00174     size_t   zEmbeddedIntroducerLine;
00175 
00176 
00177   public:
00178 
00179     //
00180     //  C O N S T R U C T O R S
00181     //
00182 
00190     TApplication ( const char*  pkcAPPLICATION_NAME    ,
00191                    const char*  pkcAPPLICATION_RELEASE ,
00192                    int          iPARAMETER_COUNT       ,
00193                    const char** ppkcPARAMETERS         );
00194 
00196     ~TApplication (void)
00197     {
00198       closeFiles();
00199     }
00200 
00206     void bindCodeParameter ( const TString& rkyVARIABLE ,
00207                              const TString& rkyVALUE    )
00208     {
00209       tCodeParametersMap.bind (rkyVARIABLE, TVariableString (rkyVALUE));
00210     }
00211 
00217     TString collapseStringLiteral (const char* pkcSOURCE_TEXT);
00218     
00224     void handleTarget (const TString& rkySOURCE_TEXT);
00225 
00235     int identifyToken (const char* pkcSOURCE_TEXT, unsigned int uiPERIOD_COUNT = 0);
00236 
00241     void initCodeParameters (void);
00242 
00246     void initialize (void);
00247 
00253     void loadCodeGenerator (const TString& rkyTARGET);
00254 
00261     void outputClauseCode (const char* pkcINSTRUCTION_NAME, const char* pkcCLAUSE_NAME = "body")
00262     {
00263       yOutputCode.append (getClauseCode (pkcINSTRUCTION_NAME, pkcCLAUSE_NAME));
00264     }
00265 
00271     void outputCode (const char* pkccSOURCE_TEXT, size_t zLENGTH = 0);
00272 
00277     void outputCode (const TString& rkySOURCE_TEXT)
00278     {
00279       yOutputCode.append (rkySOURCE_TEXT);
00280     }
00281 
00286     void postAppend (const TString& rkySOURCE_TEXT)
00287     {
00288       yPostfixOutputCode.append (rkySOURCE_TEXT);
00289     }
00290 
00295     void preAppend (const TString& rkySOURCE_TEXT)
00296     {
00297       yPrefixOutputCode.append (rkySOURCE_TEXT);
00298     }
00299 
00304     void pushTokenName (const char* pkcLAST_TOKEN)
00305     {
00306       yLastToken = pkcLAST_TOKEN;  
00307     }
00308 
00313     void pushTokenName (const TString& kyLAST_TOKEN)
00314     {
00315       yLastToken = kyLAST_TOKEN;
00316     }
00317 
00319     void setCompilationFailed (void)
00320     {
00321       gCompilationOk = false;
00322     }
00323 
00333     int splitToken (unsigned int uiPERIOD_COUNT)
00334       throw (TFatalException);
00335 
00340     int start (void);
00341 
00342 
00343   public:
00344 
00345     //
00346     //  S E L E C T O R S
00347     //
00348 
00350     bool compilationFailed (void) const
00351     {
00352       return !gCompilationOk;
00353     }
00354 
00359     void createComplementaryFiles (void) const;
00360 
00362     TString debugDescription (void) const;
00363 
00371     TString getClauseCode ( const char* pkcINSTRUCTION_NAME     ,
00372                             const char* pkcCLAUSE_NAME = "body" );
00373 
00381     size_t getEmbeddedLineNumber (void) const
00382     {
00383       return zEmbeddedIntroducerLine;
00384     }
00385 
00393     TString getLineDirective (unsigned int uiLINE_NUMBER = 0) const;
00394 
00401     void handleCompilerError (const char* pkcMESSAGE);
00402     
00407     bool isReusingTarget (void) const;
00408 
00410     void printDebugInformation (void) const
00411     {
00412       if ( uiCfgDebug > 0 )
00413       {
00414         std::cerr << debugDescription();
00415       }
00416     }
00417 
00422     TString programFileName (void) const
00423     {
00424       return tConfigProcessor.programFileName();
00425     }
00426 
00434     void require (long int liINVARIANT_IDENTIFIER...) const;
00435 
00442     bool useLineDirective (void) const
00443     {
00444       return ( gCfgLineDirectives && ( yCfgLanguage == "c++" ) );
00445     }
00446     
00447 
00448   private:
00449 
00450     //
00451     //  C O N S T R U C T O R S
00452     //
00453 
00459     void openFiles ( const TString& rkyINPUT_FILE_NAME  ,
00460                      const TString& rkyOUTPUT_FILE_NAME );
00461 
00463     void closeFiles (void);
00464 
00465 
00466   private:
00467 
00468     //
00469     //  S E L E C T O R S
00470     //
00471 
00473     void printExceptionDescription (const mpcl::TException& rktEXCEPTION) const;
00474 
00476     void printParameters (void) const;
00477 
00479     void printUsage (void) const;
00480 
00481 };  // class TApplication
00482 
00483 
00484 //
00485 //  E X P O R T E D   V A R I A B L E S
00486 //
00487 
00488 extern char    yytext[];
00489 extern int     yylineno;
00490 extern int     yydebug;
00491 extern FILE*   yyin;
00492 extern FILE*   yyout;
00493 
00494 
00495 //
00496 //  E X P O R T E D   F U N C T I O N S
00497 //
00498 
00499 extern int yyparse (void);
00500 
00501 
00502 #endif  // not _UESQLC_APPLICATION__

Generated on Mon Oct 13 02:40:10 2003 for UESQLC by doxygen1.2.18