comparison src/tokenizer.cpp @ 4:180d26aa2a17

Fedora 9 compile and const correctness.
author Carl Byington <carl@five-ten-sg.com>
date Thu, 12 Jun 2008 17:51:33 -0700
parents 48d06780cf77
children
comparison
equal deleted inserted replaced
3:4a81cc2da570 4:180d26aa2a17
285 { s_single, s_term, s_string, s_single, s_eol, }, // 0xfe 285 { s_single, s_term, s_string, s_single, s_eol, }, // 0xfe
286 { s_single, s_term, s_string, s_single, s_eol, }, // 0xff 286 { s_single, s_term, s_string, s_single, s_eol, }, // 0xff
287 }; 287 };
288 288
289 289
290 TOKEN::TOKEN(char *fn, string_set *includes) { 290 TOKEN::TOKEN(const char *fn, string_set *includes) {
291 pushed = false; 291 pushed = false;
292 include_files = includes; 292 include_files = includes;
293 include(fn); 293 include(fn);
294 } 294 }
295 295
299 } 299 }
300 300
301 301
302 void TOKEN::pop() { 302 void TOKEN::pop() {
303 ifstream *is = streams.front(); 303 ifstream *is = streams.front();
304 char *fn = filenames.front(); 304 const char *fn = filenames.front();
305 streams.pop_front(); 305 streams.pop_front();
306 filenamess.erase(fn); 306 filenamess.erase(fn);
307 if (filenames.size() > 1) filenames.pop_front(); 307 if (filenames.size() > 1) filenames.pop_front();
308 if (linenumbers.size() > 1) linenumbers.pop_front(); 308 if (linenumbers.size() > 1) linenumbers.pop_front();
309 is->close(); 309 is->close();
317 } 317 }
318 318
319 319
320 bool TOKEN::next_char(u_char &uc) { 320 bool TOKEN::next_char(u_char &uc) {
321 if (pushed) { 321 if (pushed) {
322 uc = (u_char)tolower((char)pushed_char); 322 uc = (u_char)tolower((char)pushed_char);
323 pushed = false; 323 pushed = false;
324 return true; 324 return true;
325 } 325 }
326 while (!streams.empty() && streams.front()->eof()) { 326 while (!streams.empty() && streams.front()->eof()) {
327 pop(); 327 pop();
332 if (is->eof()) return next_char(uc); 332 if (is->eof()) return next_char(uc);
333 if (uc == (u_char)'\n') { 333 if (uc == (u_char)'\n') {
334 int &line = linenumbers.front(); 334 int &line = linenumbers.front();
335 line++; 335 line++;
336 } 336 }
337 uc = (u_char)tolower((char)uc); 337 uc = (u_char)tolower((char)uc);
338 return true; 338 return true;
339 } 339 }
340 340
341 341
342 bool TOKEN::include(char *fn) { 342 bool TOKEN::include(const char *fn) {
343 string_set::iterator i = filenamess.find(fn); 343 string_set::iterator i = filenamess.find(fn);
344 if (i != filenamess.end()) { 344 if (i != filenamess.end()) {
345 token_error("redundant or recursive include file detected"); 345 token_error("redundant or recursive include file detected");
346 return false; 346 return false;
347 } 347 }
361 linenumbers.push_front(1); 361 linenumbers.push_front(1);
362 return true; 362 return true;
363 } 363 }
364 364
365 365
366 char *TOKEN::next() { 366 const char *TOKEN::next() {
367 if (!pending_tokens.empty()) { 367 if (!pending_tokens.empty()) {
368 char *t = pending_tokens.front(); 368 const char *t = pending_tokens.front();
369 pending_tokens.pop_front(); 369 pending_tokens.pop_front();
370 return t; 370 return t;
371 } 371 }
372 if (streams.empty()) return NULL; 372 if (streams.empty()) return NULL;
373 const int PENDING_LIMIT = 1000; 373 const int PENDING_LIMIT = 1000;
443 if (st == s_init) break; 443 if (st == s_init) break;
444 } 444 }
445 445
446 buffer[count] = '\0'; 446 buffer[count] = '\0';
447 if (count == 0) return NULL; 447 if (count == 0) return NULL;
448 char *t = register_string((char*)buffer); 448 const char *t = register_string((char*)buffer);
449 if (t == token_include) { 449 if (t == token_include) {
450 char *f = next(); // should be file name 450 const char *f = next(); // should be file name
451 char *s = next(); // should be semicolon 451 const char *s = next(); // should be semicolon
452 if (s == token_semi) { 452 if (s == token_semi) {
453 include(f); 453 include(f);
454 return next(); 454 return next();
455 } 455 }
456 else { 456 else {
462 return t; 462 return t;
463 } 463 }
464 464
465 465
466 int TOKEN::nextint() { 466 int TOKEN::nextint() {
467 char *t = next(); 467 const char *t = next();
468 char *e; 468 char *e;
469 long i = strtol(t, &e, 10); 469 long i = strtol(t, &e, 10);
470 if (*e != '\0') { 470 if (*e != '\0') {
471 token_error("integer", t); 471 token_error("integer", t);
472 return 0; 472 return 0;
513 } 513 }
514 514
515 515
516 void TOKEN::token_error() { 516 void TOKEN::token_error() {
517 token_error("syntax error at line %d in file %s -- ", cur_line(), cur_fn()); 517 token_error("syntax error at line %d in file %s -- ", cur_line(), cur_fn());
518 line_list::iterator j = linenumbers.begin(); 518 line_list::iterator j = linenumbers.begin();
519 string_list::iterator i = filenames.begin(); 519 string_list::const_iterator i = filenames.begin();
520 for (; i!=filenames.end(); i++,j++) { 520 for (; i!=filenames.end(); i++,j++) {
521 if (i != filenames.begin()) { 521 if (i != filenames.begin()) {
522 char *fn = (*i); 522 const char *fn = (*i);
523 int li = (*j); 523 int li = (*j);
524 token_error(" included from line %d in file %s -- ", li, fn); 524 token_error(" included from line %d in file %s -- ", li, fn);
525 } 525 }
526 } 526 }
527 } 527 }