00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef Scanner_h
00028 #define Scanner_h
00029
00030 #include "FlexLexer.h"
00031 #include "ycp/StaticDeclaration.h"
00032 #include <stdio.h>
00033 #include <string>
00034
00035 class TableEntry;
00036 class SymbolTable;
00037 #include "ycp/Type.h"
00038
00039
00040 typedef struct formalparamstack {
00041 struct formalparamstack *next;
00042 const char *name;
00043 constTypePtr type;
00044 unsigned int line;
00045 } formalparam_t;
00046
00047 typedef union {
00048 bool bval;
00049 long long ival;
00050 double fval;
00051 const char *sval;
00052 unsigned char *cval;
00053 char *pval;
00054 char *yval;
00055 const char *nval;
00056 declaration_t *dval;
00057 TableEntry *tval;
00058 formalparam_t *fpval;
00059 void *val;
00060 } tokenValue;
00061
00072 class Scanner : public yyFlexLexer
00073 {
00074 private:
00081 static const int STRING_HUNK = 1024;
00082
00088 string m_filename;
00089
00094 const char *m_inputBuffer;
00095
00100 FILE *m_inputFile;
00101
00107 int m_inputFd;
00108
00112 tokenValue m_scannedValue;
00113
00117 constTypePtr m_scannedType;
00118
00122 int m_lineNumber;
00123
00127 char *m_scandataBufferPtr;
00128
00132 char *m_scandataBuffer;
00133
00137 int m_scandataBufferSize;
00138
00143 bool m_buffered;
00144
00145
00146 SymbolTable *m_globalTable;
00147 SymbolTable *m_localTable;
00148
00153 bool m_owningGlobal;
00154 bool m_owningLocal;
00155
00160 std::list<std::pair<std::string, Y2Namespace *> > m_autoimport_predefined;
00161
00162 public:
00171 Scanner (FILE *inputfile, const char *filename);
00172
00179 Scanner(const char *inputbuffer);
00180
00189 Scanner(int input_fd, const char *filename);
00190
00194 ~Scanner();
00195
00200 void setBuffered();
00201
00210 void initTables (SymbolTable *globalTable, SymbolTable *localTable);
00211
00216 SymbolTable *globalTable () const;
00217
00222 SymbolTable *localTable () const;
00223
00230 int yylex();
00231
00242 int LexerInput( char* buf, int max_size );
00243
00248 void LexerError( const char* msg );
00249
00254 tokenValue scannedValue() const;
00255
00260 constTypePtr scannedType() const;
00261
00265 int lineNumber() const;
00266
00274 void logError (const char *loginfo, int lineno, ...) __attribute__ ((format (printf, 2, 4)));
00275
00279 void logWarning (const char *loginfo, int lineno, ...) __attribute__ ((format (printf, 2, 4)));
00280
00284 const std::list<std::pair<std::string, Y2Namespace *> > & autoimport_predefined() const { return m_autoimport_predefined; };
00285
00289 static char *doStrdup (const char *s);
00290
00294 void closeInput ();
00295
00296 private:
00301 void setScannedToken (const tokenValue & value, constTypePtr type);
00302
00307 char *extend_scanbuffer (int size);
00308
00309 };
00310
00311 #endif // Scanner_h