Scanner.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |  
00003 |                      __   __    ____ _____ ____                      |  
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |  
00005 |                       \ V / _` \___ \ | |   __) |                    |  
00006 |                        | | (_| |___) || |  / __/                     |  
00007 |                        |_|\__,_|____/ |_| |_____|                    |  
00008 |                                                                      |  
00009 |                               core system                            | 
00010 |                                                        (C) SuSE GmbH |  
00011 \----------------------------------------------------------------------/ 
00012 
00013    File:        Scanner.h
00014 
00015    Author:      Klaus Kaempf <kkaempf@suse.de>
00016                 Mathias Kettner <kettner@suse.de>
00017    Maintainer:  Klaus Kaempf <kkaempf@suse.de>
00018 
00019 /-*/
00020 // -*- c++ -*-
00021 
00022 /*
00023  * Interface to the flex generated scanner
00024  *
00025  */
00026 
00027 #ifndef Scanner_h
00028 #define Scanner_h
00029 
00030 #ifndef __FLEX_LEXER_H
00031 #include "FlexLexer.h"
00032 #endif
00033 
00034 #include "ycp/StaticDeclaration.h"
00035 #include <stdio.h>
00036 #include <string>
00037 
00038 class TableEntry;
00039 class SymbolTable;
00040 #include "ycp/Type.h"
00041 #include "ycp/y2log.h"
00042 
00043 // linked list for formal parameters
00044 typedef struct formalparamstack {
00045     struct formalparamstack *next;      // ptr to next formal parameter
00046     const char *name;                   // name of formal parameter
00047     constTypePtr type;                  // type of formal parameter
00048     unsigned int line;                  // line number of name token
00049 } formalparam_t;
00050 
00051 typedef union {
00052         bool bval;              // boolean
00053         long long ival;         // integer
00054         double fval;            // float
00055         const char *sval;       // string
00056         unsigned char *cval;    // bytecode
00057         char *pval;             // path
00058         char *yval;             // symbol
00059         const char *nval;       // name
00060         declaration_t *dval;    // builtin declaration
00061         TableEntry *tval;       // table entry
00062         formalparam_t *fpval;   // formal parameter chain
00063         void *val;              // any other value
00064 } tokenValue;
00065 
00076 class Scanner : public yyFlexLexer, public Logger
00077 {
00078 private:
00085     static const int STRING_HUNK = 1024;
00086 
00092     string m_filename;
00093 
00098     const char *m_inputBuffer;
00099 
00104     FILE *m_inputFile;
00105 
00111     int m_inputFd;
00112 
00116     tokenValue m_scannedValue;
00117 
00121     constTypePtr m_scannedType;
00122 
00126     int m_lineNumber;
00127 
00131     char *m_scandataBufferPtr;
00132 
00136     char *m_scandataBuffer;
00137 
00141     int m_scandataBufferSize;
00142 
00147     bool m_buffered;
00148 
00149     // current symbol tables, used also in parser.yy
00150     SymbolTable *m_globalTable;
00151     SymbolTable *m_localTable;
00152 
00157     bool m_owningGlobal;
00158     bool m_owningLocal;
00159 
00164     std::list<std::pair<std::string, Y2Namespace *> > m_autoimport_predefined;
00165 
00166 public:
00175     Scanner (FILE *inputfile, const char *filename);
00176 
00183     Scanner(const char *inputbuffer);
00184 
00193     Scanner(int input_fd, const char *filename);
00194 
00198     ~Scanner();
00199 
00204     void setBuffered();
00205 
00214     void initTables (SymbolTable *globalTable, SymbolTable *localTable);
00215 
00220     SymbolTable *globalTable () const;
00221 
00226     SymbolTable *localTable () const;
00227 
00234     int yylex();
00235 
00246     int LexerInput( char* buf, int max_size );
00247 
00252     void LexerError( const char* msg );
00253 
00258     tokenValue scannedValue() const;
00259 
00264     constTypePtr scannedType() const;
00265 
00269     int lineNumber() const;
00270 
00274     string filename() const;
00275 
00283     void logError (const char *loginfo, int lineno, ...) __attribute__ ((format (printf, 2, 4)));
00284 
00288     void logWarning (const char *loginfo, int lineno, ...) __attribute__ ((format (printf, 2, 4)));
00289 
00293     const std::list<std::pair<std::string, Y2Namespace *> > & autoimport_predefined() const { return m_autoimport_predefined; };
00294 
00298     static char *doStrdup (const char *s);
00299 
00303     void closeInput ();
00304     
00305 private:
00310     void setScannedToken (const tokenValue & value, constTypePtr type);
00311 
00316     char *extend_scanbuffer (int size);
00317 
00318 public:
00319 
00320     virtual void error(string error);
00321     virtual void warning(string warning);
00322 
00323 };
00324 
00325 #endif // Scanner_h

Generated on Fri Jun 16 18:07:45 2006 for yast2-core by  doxygen 1.4.6