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 #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
00044 typedef struct formalparamstack {
00045 struct formalparamstack *next;
00046 const char *name;
00047 constTypePtr type;
00048 unsigned int line;
00049 } formalparam_t;
00050
00051 typedef union {
00052 bool bval;
00053 long long ival;
00054 double fval;
00055 const char *sval;
00056 unsigned char *cval;
00057 char *pval;
00058 char *yval;
00059 const char *nval;
00060 declaration_t *dval;
00061 TableEntry *tval;
00062 formalparam_t *fpval;
00063 void *val;
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
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