{
assert(bufpos <= bufend);
if (bufpos >= bufend) {
+ if (input == NULL) {
+ c = EOF;
+ return;
+ }
+
size_t s = fread(buf + MAX_PUTBACK, 1, sizeof(buf) - MAX_PUTBACK,
input);
if(s == 0) {
if(v >= TARGET_LONG_MIN && v <= TARGET_LONG_MAX) {
lexer_token.datatype = type_long;
return;
- } else if(is_oct_hex && v >= 0 && v <= TARGET_ULONG_MAX) {
+ } else if(is_oct_hex && v >= 0 && (unsigned long long)v <= (unsigned long long)TARGET_ULONG_MAX) {
lexer_token.datatype = type_unsigned_long;
return;
}
end_of_wide_char_constant:;
size_t size = (size_t) obstack_object_size(&symbol_obstack);
+ assert(size % sizeof(wchar_rep_t) == 0);
+ size /= sizeof(wchar_rep_t);
+
const wchar_rep_t *string = obstack_finish(&symbol_obstack);
lexer_token.type = T_WIDE_CHARACTER_CONSTANT;
#define ELSE_CODE(code) \
default: \
- code; \
+ code \
} \
} /* end of while(1) */ \
break;
void init_lexer(void)
{
strset_init(&stringset);
+ symbol_L = symbol_table_insert("L");
}
void lexer_open_stream(FILE *stream, const char *input_name)
lexer_token.source_position.linenr = 0;
lexer_token.source_position.input_name = input_name;
- symbol_L = symbol_table_insert("L");
bufpos = NULL;
bufend = NULL;
c = '\n';
}
+void lexer_open_buffer(const char *buffer, size_t len, const char *input_name)
+{
+ input = NULL;
+ lexer_token.source_position.linenr = 0;
+ lexer_token.source_position.input_name = input_name;
+
+ bufpos = buffer;
+ bufend = buffer + len;
+
+ /* place a virtual \n at the beginning so the lexer knows that we're
+ * at the beginning of a line */
+ c = '\n';
+}
+
void exit_lexer(void)
{
strset_destroy(&stringset);