EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

BaseTools/Source/C/VfrCompile/Pccts/h/DLexerBase.cpp

Go to the documentation of this file.
00001 /* DLGLexerBase.c
00002  *
00003  * SOFTWARE RIGHTS
00004  *
00005  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
00006  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
00007  * company may do whatever they wish with source code distributed with
00008  * PCCTS or the code generated by PCCTS, including the incorporation of
00009  * PCCTS, or its output, into commerical software.
00010  *
00011  * We encourage users to develop software with PCCTS.  However, we do ask
00012  * that credit is given to us for developing PCCTS.  By "credit",
00013  * we mean that if you incorporate our source code into one of your
00014  * programs (commercial product, research project, or otherwise) that you
00015  * acknowledge this fact somewhere in the documentation, research report,
00016  * etc...  If you like PCCTS and have developed a nice tool with the
00017  * output, please mention that you developed it using PCCTS.  In
00018  * addition, we ask that this header remain intact in our source code.
00019  * As long as these guidelines are kept, we expect to continue enhancing
00020  * this system and expect to make other tools available as they are
00021  * completed.
00022  *
00023  * ANTLR 1.33
00024  * Terence Parr
00025  * Parr Research Corporation
00026  * with Purdue University and AHPCRC, University of Minnesota
00027  * 1989-2000
00028  */
00029 
00030 #include "pcctscfg.h"
00031 
00032 #include "pccts_stdio.h"
00033 #include "pccts_stdlib.h"
00034 
00035 PCCTS_NAMESPACE_STD
00036 
00037 /* I have to put this here due to C++ limitation
00038  * that you can't have a 'forward' decl for enums.
00039  * I hate C++!!!!!!!!!!!!!!!
00040  */
00041 
00042 // MR1
00043 // MR1  10-Apr-97  133MR1  Prevent use of varying sizes for the
00044 // MR1                          ANTLRTokenType enum
00045 // MR1
00046 
00047 enum ANTLRTokenType { TER_HATES_CPP=0, ITS_UTTER_GARBAGE,               // MR1
00048                                          WITH_SOME_GOOD_IDEAS=9999};    // MR1
00049 
00050 #define ANTLR_SUPPORT_CODE
00051 
00052 #include "pcctscfg.h"
00053 #include DLEXERBASE_H
00054 #include APARSER_H              // MR23
00055 
00056 DLGLexerBase::
00057 DLGLexerBase(DLGInputStream *in,
00058              unsigned bufsize,
00059              int _interactive,
00060              int _track_columns)
00061 {
00062         this->_bufsize = bufsize;
00063         this->_lextext = new DLGChar[_bufsize];
00064         if ( this->_lextext==NULL ) {
00065             panic("text buffer is NULL");
00066         }
00067         this->_begexpr = this->_endexpr = NULL;
00068         this->ch = this->bufovf = 0;
00069         this->nextpos = NULL;
00070         this->cl = 0;
00071         this->add_erase = 0;
00072         this->input = in;
00073         this->_begcol = 0;
00074         this->_endcol = 0;
00075         this->_line = 1;
00076         this->charfull = 0;
00077         this->automaton = 0;
00078         this->token_to_fill = NULL;
00079         this->interactive = _interactive;
00080         this->track_columns = _track_columns;
00081         this->debugLexerFlag = 0;                                       // MR1
00082         this->parser = NULL;                                            // MR1
00083     this->lexErrCount=0;                        // MR11
00084 }
00085 
00086 // MR19  THM 
00087 
00088 void DLGLexerBase::reset()
00089 {
00090         this->charfull = 0;
00091         this->_begcol = 0;
00092         this->_endcol = 0;
00093         this->automaton = 0;
00094         this->_line=1;
00095         this->lexErrCount=0;
00096 }
00097 
00098 void DLGLexerBase::
00099 setInputStream( DLGInputStream *in )
00100 {
00101         this->input = in;
00102         _line = 1;
00103         charfull = 0;
00104 }
00105 
00106 /* saves dlg state, but not what feeds dlg (such as file position) */
00107 void DLGLexerBase::
00108 saveState(DLGState *state)
00109 {
00110         state->input = input;
00111         state->interactive = interactive;
00112         state->track_columns = track_columns;
00113         state->auto_num = automaton;
00114         state->add_erase = add_erase;
00115         state->lookc = ch;
00116         state->char_full = charfull;
00117         state->begcol = _begcol;
00118         state->endcol = _endcol;
00119         state->line = _line;
00120         state->lextext = _lextext;
00121         state->begexpr = _begexpr;
00122         state->endexpr = _endexpr;
00123         state->bufsize = _bufsize;
00124         state->bufovf = bufovf;
00125         state->nextpos = nextpos;
00126         state->class_num = cl;
00127         state->debugLexerFlag = debugLexerFlag;                         // MR1
00128         state->parser = parser;                                         // MR1
00129 }
00130 
00131 void DLGLexerBase::
00132 restoreState(DLGState *state)
00133 {
00134         input = state->input;
00135         interactive = state->interactive;
00136         track_columns = state->track_columns;
00137         automaton = state->auto_num;
00138         add_erase = state->add_erase;
00139         ch = state->lookc;
00140         charfull = state->char_full;
00141         _begcol = state->begcol;
00142         _endcol = state->endcol;
00143         _line = state->line;
00144         _lextext = state->lextext;
00145         _begexpr = state->begexpr;
00146         _endexpr = state->endexpr;
00147         _bufsize = state->bufsize;
00148         bufovf = state->bufovf;
00149         nextpos = state->nextpos;
00150         cl = state->class_num;
00151         debugLexerFlag = state->debugLexerFlag;                         // MR1
00152         parser = state->parser;                                         // MR1
00153 }
00154 
00155 /* erase what is currently in the buffer, and get a new reg. expr */
00156 void DLGLexerBase::
00157 skip()
00158 {
00159         add_erase = 1;
00160 }
00161 
00162 /* don't erase what is in the lextext buffer, add on to it */
00163 void DLGLexerBase::
00164 more()
00165 {
00166         add_erase = 2;
00167 }
00168 
00169 /* substitute c for the reg. expr last matched and is in the buffer */
00170 void DLGLexerBase::
00171 replchar(DLGChar c)
00172 {
00173         /* can't allow overwriting null at end of string */
00174         if (_begexpr < &_lextext[_bufsize-1]){
00175                 *_begexpr = c;
00176                 *(_begexpr+1) = '\0';
00177         }
00178         _endexpr = _begexpr;
00179         if (c != '\0') {
00180                 nextpos = _begexpr + 1;
00181         }
00182         else {
00183                 nextpos = _begexpr;     /* MR30 Zero terminates string. */
00184         }
00185 }
00186 
00187 /* replace the string s for the reg. expr last matched and in the buffer */
00188 
00189 #ifdef _MSC_VER  // MR23
00190 //Turn off "assignment within conditional expression" warning
00191 #pragma warning(disable : 4706)
00192 #endif
00193 void DLGLexerBase::
00194 replstr(const DLGChar *s) /* MR20 const */
00195 {
00196         register DLGChar *l= &_lextext[_bufsize -1];
00197 
00198         nextpos = _begexpr;
00199         if (s){
00200                 while ((nextpos <= l) && (*(nextpos++) = *(s++))){
00201                         /* empty */
00202                 }
00203                 /* correct for NULL at end of string */
00204                 nextpos--;
00205         }
00206         if ((nextpos <= l) && (*(--s) == 0)){
00207                 bufovf = 0;
00208         }else{
00209                 bufovf = 1;
00210         }
00211         *(nextpos) = '\0';
00212         _endexpr = nextpos - 1;
00213 }
00214 #ifdef _MSC_VER  // MR23
00215 #pragma warning(default: 4706)
00216 #endif
00217 
00218 void DLGLexerBase::
00219 errstd(const char *s)                               /* MR20 const */
00220 {
00221         lexErrCount++;                              /* MR11 */
00222         /* MR23 */ printMessage(stderr,
00223                 "%s near line %d (text was '%s')\n",
00224                 ((s == NULL) ? "Lexical error" : s),
00225                 _line,_lextext);
00226 }
00227 
00228 int DLGLexerBase::
00229 err_in()
00230 {
00231         /* MR23 */ printMessage(stderr,"No input stream, function, or string\n");
00232         /* return eof to get out gracefully */
00233         return EOF;
00234 }
00235 
00236 ANTLRTokenType DLGLexerBase::
00237 erraction()
00238 {
00239         errstd("invalid token");
00240         advance();
00241         skip();
00242         return (ANTLRTokenType) 0;      // bogus, but satisfies compiler
00243 }
00244 
00245 _ANTLRTokenPtr DLGLexerBase::
00246 getToken()
00247 {
00248         if ( token_to_fill==NULL ) panic("NULL token_to_fill");
00249         ANTLRTokenType tt = nextTokenType();
00250         _ANTLRTokenPtr tk = token_to_fill->makeToken(tt, _lextext,_line);
00251         return tk;
00252 }
00253 
00254 void DLGLexerBase::
00255 panic(const char *msg)      /* MR20 const */
00256 {
00257         if (parser)                             //MR23
00258                 parser->panic(msg);     //MR23
00259         else                                    //MR23
00260         {
00261                 /* MR23 */ printMessage(stderr, "DLG panic: %s\n", msg);
00262         //
00263         //  7-Apr-97 133MR1
00264         //
00265                 exit(PCCTS_EXIT_FAILURE);                                       // MR1
00266         }
00267 }
00268 
00269 ANTLRParser * DLGLexerBase::                                            // MR1
00270 setParser(ANTLRParser *p) {                                             // MR1
00271   ANTLRParser   *oldValue=parser;                                       // MR1
00272   parser=p;                                                             // MR1
00273   return oldValue;                                                      // MR1
00274 }                                                                       // MR1
00275                                                                         // MR1
00276 ANTLRParser * DLGLexerBase::                                            // MR1
00277 getParser() {                                                           // MR1
00278   return parser;                                                        // MR1
00279 }                                                                       // MR1
00280                                                                         // MR1
00281 int DLGLexerBase::                                                      // MR1
00282 debugLexer(int newValue) {                                              // MR1
00283   int   oldValue=debugLexerFlag;                                        // MR1
00284   debugLexerFlag=newValue;                                              // MR1
00285   return oldValue;                                                      // MR1
00286 }                                                                       // MR1
00287 
00288 //MR23
00289 int DLGLexerBase::printMessage(FILE* pFile, const char* pFormat, ...)
00290 {
00291         va_list marker;
00292         va_start( marker, pFormat );
00293 
00294         int iRet = 0;
00295         if (parser)
00296                 parser->printMessageV(pFile, pFormat, marker);
00297         else
00298                 iRet = vfprintf(pFile, pFormat, marker);
00299 
00300         va_end( marker );
00301         return iRet;
00302 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines