lex floating suffix, parser can now parse it's own source completely
authorMatthias Braun <matze@braunis.de>
Fri, 28 Sep 2007 19:02:24 +0000 (19:02 +0000)
committerMatthias Braun <matze@braunis.de>
Fri, 28 Sep 2007 19:02:24 +0000 (19:02 +0000)
[r18364]

lexer.c
type.c

diff --git a/lexer.c b/lexer.c
index 7dbaaab..9dbd2fa 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -281,6 +281,21 @@ static void parse_integer_suffix(void)
        }
 }
 
+static void parse_floating_suffix(void)
+{
+       switch(c) {
+       /* TODO: do something usefull with the suffixes... */
+       case 'f':
+       case 'F':
+       case 'l':
+       case 'L':
+               next_char();
+               break;
+       default:
+               break;
+       }
+}
+
 static void parse_number_hex(void)
 {
        assert(c == 'x' || c == 'X');
@@ -365,6 +380,8 @@ static void parse_floatingpoint_exponent(long double value)
 
        lexer_token.type         = T_FLOATINGPOINT;
        lexer_token.v.floatvalue = value;
+
+       parse_floating_suffix();
 }
 
 static void parse_floatingpoint_fract(int integer_part)
@@ -386,6 +403,8 @@ static void parse_floatingpoint_fract(int integer_part)
 
        lexer_token.type         = T_FLOATINGPOINT;
        lexer_token.v.floatvalue = value;
+
+       parse_floating_suffix();
 }
 
 static void parse_number_dec(void)
@@ -1019,10 +1038,12 @@ void init_lexer(void)
 void lexer_open_stream(FILE *stream, const char *input_name)
 {
        input                                  = stream;
-       lexer_token.source_position.linenr     = 1;
+       lexer_token.source_position.linenr     = 0;
        lexer_token.source_position.input_name = input_name;
 
-       next_char();
+       /* 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)
diff --git a/type.c b/type.c
index 5bb7a5f..d241abf 100644 (file)
--- a/type.c
+++ b/type.c
@@ -46,7 +46,7 @@ void print_atomic_type(const atomic_type_t *type)
        switch(type->atype) {
        case ATOMIC_TYPE_INVALID:     s = "INVALIDATOMIC";      break;
        case ATOMIC_TYPE_VOID:        s = "void";               break;
-       case ATOMIC_TYPE_BOOL:        s = "bool";               break;
+       case ATOMIC_TYPE_BOOL:        s = "_Bool";              break;
        case ATOMIC_TYPE_CHAR:        s = "char";               break;
        case ATOMIC_TYPE_SCHAR:       s = "signed char";        break;
        case ATOMIC_TYPE_UCHAR:       s = "unsigned char";      break;
@@ -260,11 +260,15 @@ bool type_valid(const type_t *type)
 
 bool is_type_integer(const type_t *type)
 {
+       if(type->type == TYPE_ENUM)
+               return 1;
+
        if(type->type != TYPE_ATOMIC)
                return 0;
 
        atomic_type_t *atomic_type = (atomic_type_t*) type;
        switch(atomic_type->atype) {
+       case ATOMIC_TYPE_BOOL:
        case ATOMIC_TYPE_CHAR:
        case ATOMIC_TYPE_SCHAR:
        case ATOMIC_TYPE_UCHAR:
@@ -282,24 +286,13 @@ bool is_type_integer(const type_t *type)
        }
 }
 
-bool is_type_arithmetic(const type_t *type)
+bool is_type_floating(const type_t *type)
 {
        if(type->type != TYPE_ATOMIC)
                return 0;
 
        atomic_type_t *atomic_type = (atomic_type_t*) type;
        switch(atomic_type->atype) {
-       case ATOMIC_TYPE_CHAR:
-       case ATOMIC_TYPE_SCHAR:
-       case ATOMIC_TYPE_UCHAR:
-       case ATOMIC_TYPE_SHORT:
-       case ATOMIC_TYPE_USHORT:
-       case ATOMIC_TYPE_INT:
-       case ATOMIC_TYPE_UINT:
-       case ATOMIC_TYPE_LONG:
-       case ATOMIC_TYPE_ULONG:
-       case ATOMIC_TYPE_LONGLONG:
-       case ATOMIC_TYPE_ULONGLONG:
        case ATOMIC_TYPE_FLOAT:
        case ATOMIC_TYPE_DOUBLE:
        case ATOMIC_TYPE_LONG_DOUBLE:
@@ -314,11 +307,15 @@ bool is_type_arithmetic(const type_t *type)
        case ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY:
 #endif
                return 1;
-       case ATOMIC_TYPE_INVALID:
-       case ATOMIC_TYPE_VOID:
-       case ATOMIC_TYPE_BOOL:
+       default:
                return 0;
        }
+}
+
+bool is_type_arithmetic(const type_t *type)
+{
+       if(is_type_integer(type) || is_type_floating(type))
+               return 1;
 
        return 0;
 }
@@ -340,7 +337,7 @@ static type_t *identify_new_type(type_t *type)
        return result;
 }
 
-type_t *make_atomic_type(atomic_type_type_t type, unsigned qualifiers)
+type_t *make_atomic_type(atomic_type_type_t type, type_qualifier_t qualifiers)
 {
        atomic_type_t *atomic_type
                = obstack_alloc(type_obst, sizeof(atomic_type[0]));
@@ -352,7 +349,7 @@ type_t *make_atomic_type(atomic_type_type_t type, unsigned qualifiers)
        return identify_new_type((type_t*) atomic_type);
 }
 
-type_t *make_pointer_type(type_t *points_to, unsigned qualifiers)
+type_t *make_pointer_type(type_t *points_to, type_qualifier_t qualifiers)
 {
        pointer_type_t *pointer_type
                = obstack_alloc(type_obst, sizeof(pointer_type[0]));