Parse GCC extensions in the parser instead of just undeffing them in the
authorJohan Dahlin <johan@gnome.org>
Sun, 31 Aug 2008 16:10:18 +0000 (16:10 +0000)
committerJohan Dahlin <johan@src.gnome.org>
Sun, 31 Aug 2008 16:10:18 +0000 (16:10 +0000)
2008-08-31  Johan Dahlin  <johan@gnome.org>

    * giscanner/scannerlexer.l:
    * giscanner/scannerparser.y:
    * giscanner/sourcescanner.h:
    * giscanner/sourcescanner.py:
    Parse GCC extensions in the parser instead of just undeffing them
    in the pre-processor.

svn path=/trunk/; revision=553

ChangeLog
giscanner/scannerlexer.l
giscanner/scannerparser.y
giscanner/sourcescanner.h
giscanner/sourcescanner.py

index a239e80..424ddd3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-08-31  Johan Dahlin  <johan@gnome.org>
+
+       * giscanner/scannerlexer.l:
+       * giscanner/scannerparser.y:
+       * giscanner/sourcescanner.h:
+       * giscanner/sourcescanner.py:
+       Parse GCC extensions in the parser instead of just undeffing them
+       in the pre-processor.
+
 2008-08-31  Johan Dahlin  <johan@gnome.org>
 
        * giscanner/glibtransformer.py:
index c4eb1d4..45a47ab 100644 (file)
@@ -44,7 +44,7 @@ static int yywrap (void);
 static void parse_comment (GISourceScanner *scanner);
 static void process_directive (GISourceScanner *scanner);
 static int check_identifier (GISourceScanner *scanner, const char *);
-static int parse_attribute (void);
+static int parse_ignored_macro (void);
 %}
 
 intsuffix                              ([uU][lL]?[lL]?)|([lL][lL]?[uU]?)
@@ -118,7 +118,12 @@ stringtext                         ([^\"])|(\\.)
 ","                                    { return ','; }
 "->"                                   { return ARROW; }
 
-"__attribute__"                        { if (!parse_attribute()) REJECT; }
+"__attribute__"                        { if (!parse_ignored_macro()) REJECT; }
+"__const"                               { return CONST; }
+"__extension__"                         { return EXTENSION; }
+"__inline"                             { return INLINE; }
+"__nonnull"                            { if (!parse_ignored_macro()) REJECT; }
+"__restrict"                           { return RESTRICT; }
 
 [a-zA-Z_][a-zA-Z_0-9]*                 { if (scanner->macro_scan) return IDENTIFIER; else REJECT; }
 
@@ -409,8 +414,12 @@ process_directive (GISourceScanner *scanner)
        g_string_free (filename_builder, TRUE);
 }
 
+/*
+ * This parses a macro which is ignored, such as
+ * __attribute__(x)
+ */
 static int
-parse_attribute (void)
+parse_ignored_macro (void)
 {
        int c;
        int nest;
index f21950d..dbde322 100644 (file)
@@ -70,9 +70,9 @@ static GHashTable *const_table = NULL;
 %token SLEQ SREQ EQ NOTEQ LTEQ GTEQ ANDAND OROR PLUSPLUS MINUSMINUS ARROW
 
 %token AUTO BOOL BREAK CASE CHAR CONST CONTINUE DEFAULT DO DOUBLE ELSE ENUM
-%token EXTERN FLOAT FOR GOTO IF INLINE INT LONG REGISTER RESTRICT RETURN SHORT
-%token SIGNED SIZEOF STATIC STRUCT SWITCH TYPEDEF UNION UNSIGNED VOID VOLATILE
-%token WHILE
+%token EXTENSION EXTERN FLOAT FOR GOTO IF INLINE INT LONG REGISTER RESTRICT
+%token RETURN SHORT SIGNED SIZEOF STATIC STRUCT SWITCH TYPEDEF UNION UNSIGNED
+%token VOID VOLATILE WHILE
 
 %token FUNCTION_MACRO OBJECT_MACRO
 
@@ -858,6 +858,10 @@ type_qualifier
          {
                $$ = TYPE_QUALIFIER_RESTRICT;
          }
+       | EXTENSION
+         {
+               $$ = TYPE_QUALIFIER_EXTENSION;
+         }
        | VOLATILE
          {
                $$ = TYPE_QUALIFIER_VOLATILE;
index 93fa450..171a995 100644 (file)
@@ -75,7 +75,8 @@ typedef enum
   TYPE_QUALIFIER_NONE = 0,
   TYPE_QUALIFIER_CONST = 1 << 1,
   TYPE_QUALIFIER_RESTRICT = 1 << 2,
-  TYPE_QUALIFIER_VOLATILE = 1 << 3
+  TYPE_QUALIFIER_VOLATILE = 1 << 3,
+  TYPE_QUALIFIER_EXTENSION = 1 << 4
 } TypeQualifier;
 
 typedef enum
index a58c44a..46ab7f5 100644 (file)
@@ -56,6 +56,7 @@ TYPE_QUALIFIER_NONE = 0
 TYPE_QUALIFIER_CONST = 1 << 1
 TYPE_QUALIFIER_RESTRICT = 1 << 2
 TYPE_QUALIFIER_VOLATILE = 1 << 3
+TYPE_QUALIFIER_EXTENSION = 1 << 4
 
 FUNCTION_NONE = 0
 FUNCTION_INLINE = 1 << 1
@@ -231,11 +232,6 @@ class SourceScanner(object):
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE)
 
-        proc.stdin.write('#define __const\n')
-        proc.stdin.write('#define __extension__\n')
-        proc.stdin.write('#define __inline\n')
-        proc.stdin.write('#define __restrict\n')
-
         for define in defines:
             proc.stdin.write('#ifndef %s\n' % (define, ))
             proc.stdin.write('# define %s\n' % (define, ))