00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _LIB_LEX_FLEXSCANNERBASE_H_
00018 #define _LIB_LEX_FLEXSCANNERBASE_H_ 1
00019
00092
00093
00094
00103 class _InternalFlexScannerBase
00104 {
00105 public:
00107 struct Config
00108 {
00111 bool loc_use_lpos;
00112
00114 int tab_width;
00115
00117 int max_file_depth;
00118
00121 int ahead_toks_wanted;
00125 int old_toks_wanted;
00126
00128 Config();
00129 inline ~Config() {}
00130 };
00131
00133 struct XYPos
00134 {
00135 int line;
00136 int lpos;
00137
00138 inline XYPos(int l,int p) : line(l),lpos(p) {}
00139 inline ~XYPos() {}
00140 };
00141
00149 struct TokenEntry : LinkedListBase<TokenEntry>
00150 {
00151 int token;
00152 SCLocationRange lloc;
00153
00155 virtual bool MayBeCleared() const;
00156
00165 virtual void clear(bool force=0);
00166
00167 inline TokenEntry() : LinkedListBase<TokenEntry>(),
00168 token(-1),lloc() {}
00169 virtual ~TokenEntry()
00170 { TokenEntry::clear(); }
00171
00172 private:
00174 TokenEntry(const TokenEntry &);
00176 void operator=(const TokenEntry &);
00177 };
00178
00180 struct LexerInput
00181 {
00183 LexerInput *down;
00184
00186 FILE *fp;
00187 TLString fp_path;
00188
00191 XYPos saved;
00192
00197 bool must_pop_state;
00199 bool must_pop_pos_arch;
00200
00202 bool read_eof;
00203
00207 int special_next_tok;
00208
00212 LinkedList<TokenEntry> next_toks;
00213 LinkedList<TokenEntry> prev_toks;
00214
00215 private:
00217 LexerInput(const LexerInput &);
00219 void operator=(const LexerInput &);
00220 public:
00222 LexerInput(LexerInput *down);
00223 ~LexerInput();
00224
00236 int OpenFile(const TLString &path,SError &error);
00237
00243 ssize_t read(char *buf,size_t len);
00244 };
00245
00246 protected:
00248 uint32 magic;
00250 static const uint32 MyMagic=0xdeadbeefU;
00251
00253
00254
00255 void *scanner;
00256
00260 TokenEntry *lex_token;
00261
00263 LexerInput *top_inp;
00266 LexerInput *read_inp;
00267
00269 int file_depth;
00270
00272 int n_errors;
00273
00280 LinkedList<TokenEntry> zombie_list;
00282 int zombie_list_nents;
00284 static const int zombie_list_threash=256;
00285
00287 void __TidyUpZombieList(bool force);
00288 int last_zombie_list_nents;
00289
00290 inline void _TidyUpZombieList(bool force=0)
00291 {
00292 if(force ||
00293 zombie_list_nents>=last_zombie_list_nents+zombie_list_threash)
00294 { __TidyUpZombieList(force); }
00295 }
00296
00298 XYPos p0;
00300 XYPos p1;
00301
00303 SourcePositionArchive *pos_arch;
00304
00307 bool pos_arch_allocated;
00308
00310 Config cfg;
00311
00312
00313
00316 inline void _pi_tok(size_t l)
00317 { p1.lpos+=l; }
00319 inline void _pi_tab()
00320 { p1.lpos=(p1.lpos/cfg.tab_width+1)*cfg.tab_width; }
00322 inline void _pi_line()
00323 { ++p1.line; p1.lpos=0; }
00325 void _pi_char(char c);
00328 void _pi_str(const char *str,size_t len);
00331 inline void _pi_start()
00332 { p0=p1; }
00334 void _pi_eof();
00336 inline TokenEntry *_tok_ptr()
00337 { return(lex_token); }
00338
00339 protected:
00341 SCLocation _MakeCurrLoc() const;
00343 SCLocation _MakeCurrEndLoc() const;
00345 SCLocationRange _MakeCurrLocRange() const;
00346
00347
00348
00349
00355 virtual TokenEntry *AllocTokenEntry();
00356
00368 virtual void reset();
00369
00370
00371
00379 void _RawYYLex(TokenEntry *dest);
00380
00392 void _reset(bool no_virtuals=0);
00393
00394
00395
00396
00397
00399 virtual int _lex(void *scanner);
00401 virtual int _lex_init(void **scanner_p);
00403 virtual void _lex_destroy(void *scanner);
00405 virtual int _wrap();
00407 virtual int _SetInputBH(LexerInput *inp,bool included,
00408 XYPos alt_pos,SourcePositionArchive *alt_pos_arch);
00409
00410 private:
00412 _InternalFlexScannerBase(const _InternalFlexScannerBase &);
00414 void operator=(const _InternalFlexScannerBase &);
00415
00416 protected:
00418 _InternalFlexScannerBase();
00419 public:
00420 virtual ~_InternalFlexScannerBase();
00421
00450 int SetInput(const TLString &path,SError &error,bool included,
00451 int first_token=-1,
00452 XYPos alt_pos=XYPos(1,0),SourcePositionArchive *alt_pos_arch=NULL);
00453
00513 TokenEntry *LexNextToken();
00514
00521 inline SCLocation CurrLoc() const
00522 { return(_MakeCurrLoc()); }
00523 };
00524
00525
00526 #ifdef PREFIX_FlexScannerBase
00527
00546 class PREFIX_FlexScannerBase : public _InternalFlexScannerBase
00547 {
00548 protected:
00550 int _lex(void *scanner);
00552 int _lex_init(void **scanner_p);
00554 void _lex_destroy(void *scanner);
00556 int _wrap();
00558 int _SetInputBH(LexerInput *inp,bool included,
00559 XYPos alt_pos,SourcePositionArchive *alt_pos_arch);
00560
00561 private:
00563 PREFIX_FlexScannerBase(const PREFIX_FlexScannerBase &);
00565 void operator=(const PREFIX_FlexScannerBase &);
00566 public:
00567 PREFIX_FlexScannerBase();
00568 virtual ~PREFIX_FlexScannerBase();
00569 };
00570
00571 #endif
00572
00573 #endif