[gobject-introspection: 1/3] Recognize additional basic types from ISO/IEC TS 18661-3:2015.
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection: 1/3] Recognize additional basic types from ISO/IEC TS 18661-3:2015.
- Date: Tue, 3 Jul 2018 13:15:55 +0000 (UTC)
commit da426f7672b9c88658685aaf5cef948e02eb8c01
Author: Tomasz Miąsko <tomasz miasko gmail com>
Date: Mon Apr 2 00:00:00 2018 +0000
Recognize additional basic types from ISO/IEC TS 18661-3:2015.
Recognize additional floating point types from ISO/IEC TS 18661-3:2015,
that are already in use by glibc. This continues work from commit
8cf3e8e5cf6d0d49db359f50c6eb0bc9ca22fbef and fixes issue #201.
* _Float16
* _Float32
* _Float64
* _Float128
* _Float32x
* _Float64x
* _Float128x
Use a single BASIC_TYPE token for basic types, while using its string
representation as a type name. This also fixes incorrect type used
previously for __uint128_t, __int128_t, __uint128, __int128, and
_Float128 (they have been mapped to int and float respectively).
Also avoid mapping bool and _Bool to gboolean as those are distinct
types and generally ABI incompatible. Fixes issue #202.
After this changes, when _Bool, _Float* or _int128 types are used
as a part of public API, g-ir-scanner will produce warning about
unresolved type. This is appropriate given that they are currently
inexpressible in GIRepository format.
giscanner/ast.py | 2 --
giscanner/scannerlexer.l | 37 +++++++++++++++++++++----------------
giscanner/scannerparser.y | 42 ++++++++++++++----------------------------
tests/warn/unresolved-type.h | 37 ++++++++++++++++++++++++++++++++-----
4 files changed, 67 insertions(+), 51 deletions(-)
---
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 44ce523c..a1a57cc2 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -309,8 +309,6 @@ type_names['int32_t'] = TYPE_INT32
type_names['uint32_t'] = TYPE_UINT32
type_names['int64_t'] = TYPE_INT64
type_names['uint64_t'] = TYPE_UINT64
-# C99 stdbool
-type_names['bool'] = TYPE_BOOLEAN
# A few additional GLib type aliases
type_names['guchar'] = TYPE_UINT8
diff --git a/giscanner/scannerlexer.l b/giscanner/scannerlexer.l
index 7ffaad7f..08d72894 100644
--- a/giscanner/scannerlexer.l
+++ b/giscanner/scannerlexer.l
@@ -177,8 +177,6 @@ stringtext ([^\\\"])|(\\.)
"_Nullable" { /* Ignore */ }
"_Null_unspecified" { /* Ignore */ }
"_Noreturn" { /* Ignore */ }
-"__signed" { return SIGNED; }
-"__signed__" { return SIGNED; }
"__restrict" { return RESTRICT; }
"__restrict__" { return RESTRICT; }
"thread_local" { return THREAD_LOCAL; }
@@ -186,15 +184,13 @@ stringtext ([^\\\"])|(\\.)
"__typeof" { if (!parse_ignored_macro()) REJECT; }
"__volatile" { return VOLATILE; }
"__volatile__" { return VOLATILE; }
-"_Bool" { return BOOL; }
+"_Bool" { return BASIC_TYPE; }
"typedef char __static_assert_t".*"\n" { ++lineno; /* Ignore */ }
"__cdecl" { /* Ignore */ }
"__declspec(deprecated(".*"))" { /* Ignore */ }
"__declspec"[\t ]*"("[a-z\t ]+")" { /* Ignore */ }
"__stdcall" { /* ignore */ }
"__w64" { /* ignore */ }
-"__int64" { return INT; }
-"_Float128" { return FLOAT; }
"G_GINT64_CONSTANT" { return INTL_CONST; }
"G_GUINT64_CONSTANT" { return INTUL_CONST; }
@@ -208,34 +204,43 @@ stringtext ([^\\\"])|(\\.)
"asm" { if (!parse_ignored_macro()) REJECT; }
"auto" { return AUTO; }
-"bool" { return BOOL; }
"break" { return BREAK; }
"case" { return CASE; }
-"char" { return CHAR; }
+"char" { return BASIC_TYPE; }
"const" { return CONST; }
"continue" { return CONTINUE; }
"default" { return DEFAULT; }
"do" { return DO; }
-"double" { return DOUBLE; }
+"double" { return BASIC_TYPE; }
"else" { return ELSE; }
"enum" { return ENUM; }
"extern" { return EXTERN; }
-"float" { return FLOAT; }
+"float" { return BASIC_TYPE; }
+"_Float16" { return BASIC_TYPE; }
+"_Float32" { return BASIC_TYPE; }
+"_Float64" { return BASIC_TYPE; }
+"_Float128" { return BASIC_TYPE; }
+"_Float32x" { return BASIC_TYPE; }
+"_Float64x" { return BASIC_TYPE; }
+"_Float128x" { return BASIC_TYPE; }
"for" { return FOR; }
"goto" { return GOTO; }
"if" { return IF; }
"inline" { return INLINE; }
-"int" { return INT; }
-"__uint128_t" { return INT; }
-"__int128_t" { return INT; }
-"__uint128" { return INT; }
-"__int128" { return INT; }
-"long" { return LONG; }
+"int" { return BASIC_TYPE; }
+"__int64" { return BASIC_TYPE; }
+"__uint128_t" { return BASIC_TYPE; }
+"__int128_t" { return BASIC_TYPE; }
+"__uint128" { return BASIC_TYPE; }
+"__int128" { return BASIC_TYPE; }
+"long" { return BASIC_TYPE; }
"register" { return REGISTER; }
"restrict" { return RESTRICT; }
"return" { return RETURN; }
-"short" { return SHORT; }
+"short" { return BASIC_TYPE; }
"signed" { return SIGNED; }
+"__signed" { return SIGNED; }
+"__signed__" { return SIGNED; }
"sizeof" { return SIZEOF; }
"static" { return STATIC; }
"struct" { return STRUCT; }
diff --git a/giscanner/scannerparser.y b/giscanner/scannerparser.y
index abfbe065..9b4e1368 100644
--- a/giscanner/scannerparser.y
+++ b/giscanner/scannerparser.y
@@ -245,6 +245,7 @@ set_or_merge_base_type (GISourceType *type,
%parse-param { GISourceScanner* scanner }
%lex-param { GISourceScanner* scanner }
+%token <str> BASIC_TYPE
%token <str> IDENTIFIER "identifier"
%token <str> TYPEDEF_NAME "typedef-name"
@@ -254,8 +255,8 @@ set_or_merge_base_type (GISourceType *type,
%token ELLIPSIS ADDEQ SUBEQ MULEQ DIVEQ MODEQ XOREQ ANDEQ OREQ SL SR
%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 EXTENSION EXTERN FLOAT FOR GOTO IF INLINE INT LONG REGISTER RESTRICT
+%token AUTO BREAK CASE CONST CONTINUE DEFAULT DO ELSE ENUM
+%token EXTENSION EXTERN FOR GOTO IF INLINE REGISTER RESTRICT
%token RETURN SHORT SIGNED SIZEOF STATIC STRUCT SWITCH THREAD_LOCAL TYPEDEF
%token UNION UNSIGNED VOID VOLATILE WHILE
@@ -274,6 +275,7 @@ set_or_merge_base_type (GISourceType *type,
%type <ctype> struct_or_union_specifier
%type <ctype> type_specifier
%type <str> identifier
+%type <str> basic_type
%type <str> typedef_name
%type <str> identifier_or_typedef_name
%type <symbol> abstract_declarator
@@ -877,35 +879,18 @@ storage_class_specifier
}
;
+basic_type
+ : BASIC_TYPE
+ {
+ $$ = g_strdup (yytext);
+ }
+ ;
+
type_specifier
: VOID
{
$$ = gi_source_type_new (CTYPE_VOID);
}
- | CHAR
- {
- $$ = gi_source_basic_type_new ("char");
- }
- | SHORT
- {
- $$ = gi_source_basic_type_new ("short");
- }
- | INT
- {
- $$ = gi_source_basic_type_new ("int");
- }
- | LONG
- {
- $$ = gi_source_basic_type_new ("long");
- }
- | FLOAT
- {
- $$ = gi_source_basic_type_new ("float");
- }
- | DOUBLE
- {
- $$ = gi_source_basic_type_new ("double");
- }
| SIGNED
{
$$ = gi_source_basic_type_new ("signed");
@@ -914,9 +899,10 @@ type_specifier
{
$$ = gi_source_basic_type_new ("unsigned");
}
- | BOOL
+ | basic_type
{
- $$ = gi_source_basic_type_new ("bool");
+ $$ = gi_source_type_new (CTYPE_BASIC_TYPE);
+ $$->name = $1;
}
| struct_or_union_specifier
| enum_specifier
diff --git a/tests/warn/unresolved-type.h b/tests/warn/unresolved-type.h
index d20182c8..7265753c 100644
--- a/tests/warn/unresolved-type.h
+++ b/tests/warn/unresolved-type.h
@@ -1,23 +1,50 @@
+#include <stdbool.h>
#include "common.h"
typedef struct {
int i;
} MyStruct;
-// EXPECT:5: Warning: Test: symbol='MyStruct': Unknown namespace for identifier 'MyStruct'
+// EXPECT:6: Warning: Test: symbol='MyStruct': Unknown namespace for identifier 'MyStruct'
typedef enum {
TEST_MY_ENUM_A = 0
} MyEnum;
-// EXPECT:11: Warning: Test: symbol='MyEnum': Unknown namespace for identifier 'MyEnum'
+// EXPECT:12: Warning: Test: symbol='MyEnum': Unknown namespace for identifier 'MyEnum'
typedef enum {
MY_ENUM_A = 0
} TestMyEnum2;
-// EXPECT:17: Warning: Test: symbol='TestMyEnum2': Unknown namespace for symbol 'MY_ENUM_A'
+// EXPECT:18: Warning: Test: symbol='TestMyEnum2': Unknown namespace for symbol 'MY_ENUM_A'
-/* Stub function here so namespace isn't empty */
-void test_foo (void);
+void test_bool1 (_Bool b);
+// EXPECT:22: Warning: Test: test_bool1: argument b: Unresolved type: '_Bool'
+
+void test_bool2 (bool b);
+// EXPECT:25: Warning: Test: test_bool2: argument b: Unresolved type: '_Bool'
+
+void test_bool3 (gboolean b);
+
+void test_f16 (_Float16 f);
+// EXPECT:30: Warning: Test: test_f16: argument f: Unresolved type: '_Float16'
+
+void test_f32 (_Float32 f);
+// EXPECT:33: Warning: Test: test_f32: argument f: Unresolved type: '_Float32'
+
+void test_f64 (_Float64 f);
+// EXPECT:36: Warning: Test: test_f64: argument f: Unresolved type: '_Float64'
+
+void test_f128 (_Float128 f);
+// EXPECT:39: Warning: Test: test_f128: argument f: Unresolved type: '_Float128'
+
+void test_f32x (_Float32x f);
+// EXPECT:42: Warning: Test: test_f32x: argument f: Unresolved type: '_Float32x'
+
+void test_f64x (_Float64x f);
+// EXPECT:45: Warning: Test: test_f64x: argument f: Unresolved type: '_Float64x'
+
+void test_f128x (_Float128x f);
+// EXPECT:48: Warning: Test: test_f128x: argument f: Unresolved type: '_Float128x'
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]