Skip to content

Commit 4b3da96

Browse files
authored
implements complex types (#36)
also enables support for __extension__ on the expression level and adds builtin types to the AST for support plethora of compiler-specific builtins. No tests, I am still trying to figure out how to add portable tests.
1 parent 0d845ec commit 4b3da96

File tree

8 files changed

+260
-167
lines changed

8 files changed

+260
-167
lines changed

ctoxml/test.t/complex-pre.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
int main(void )
2+
{
3+
double _Complex z1 = 0.0 + __builtin_inff() * _Imaginary_I;
4+
double _Complex z2 = 0.0 + __builtin_inff() * 1.0iF;
5+
printf("z1 = %.1f%+.1fi\n", creal(z1), cimag(z1));
6+
printf("z2 = %.1f%+.1fi\n", creal(z2), cimag(z2));
7+
}

ctoxml/test.t/run.t

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5385,3 +5385,65 @@
53855385
</body>
53865386
</fundef>
53875387
</file>
5388+
5389+
$ ctoxml complex-pre.c
5390+
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
5391+
<file>
5392+
<fundef id="main" store="auto">
5393+
<type>
5394+
<long/>
5395+
</type>
5396+
<body>
5397+
<var id="z1" store="auto">
5398+
<cdouble/>
5399+
<add>
5400+
<float>0.0</float>
5401+
<mul>
5402+
<call>
5403+
<get ref="__builtin_inff"/>
5404+
</call>
5405+
<get ref="_Imaginary_I"/>
5406+
</mul>
5407+
</add>
5408+
</var>
5409+
<var id="z2" store="auto">
5410+
<cdouble/>
5411+
<add>
5412+
<float>0.0</float>
5413+
<mul>
5414+
<call>
5415+
<get ref="__builtin_inff"/>
5416+
</call>
5417+
<float>1.0iF</float>
5418+
</mul>
5419+
</add>
5420+
</var>
5421+
<call>
5422+
<get ref="printf"/>
5423+
<string>z1 = %.1f%+.1fi
5424+
</string>
5425+
<call>
5426+
<get ref="creal"/>
5427+
<get ref="z1"/>
5428+
</call>
5429+
<call>
5430+
<get ref="cimag"/>
5431+
<get ref="z1"/>
5432+
</call>
5433+
</call>
5434+
<call>
5435+
<get ref="printf"/>
5436+
<string>z2 = %.1f%+.1fi
5437+
</string>
5438+
<call>
5439+
<get ref="creal"/>
5440+
<get ref="z2"/>
5441+
</call>
5442+
<call>
5443+
<get ref="cimag"/>
5444+
<get ref="z2"/>
5445+
</call>
5446+
</call>
5447+
</body>
5448+
</fundef>
5449+
</file>

frontc/cabs.ml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ and storage =
3434

3535
(** Base type *)
3636
and base_type =
37-
NO_TYPE (** Old K&R declaration without type *)
37+
| NO_TYPE (** Old K&R declaration without type *)
3838
| VOID (** "void" type *)
3939
| CHAR of sign (** "char" type with sign modifier *)
4040
| INT of size * sign (** "int" type with size and sign modifiers *)
4141
| BITFIELD of sign * expression
4242
(** Bitfield with sign modifier and size expression *)
4343
| FLOAT of bool (** "float" type with long (true) modifier *)
44-
| DOUBLE of bool (** "doubl" type with long (true) modifier *)
44+
| DOUBLE of bool (** "double" type with long (true) modifier *)
45+
| COMPLEX_FLOAT (** float complex *)
46+
| COMPLEX_DOUBLE (** double complex *)
47+
| COMPLEX_LONG_DOUBLE (** long double complex *)
4548
| PTR of base_type (** Pointer "*" to the given type *)
4649
| RESTRICT_PTR of base_type (** REstricted pointer "*" to the given type. *)
4750
| ARRAY of base_type * expression
@@ -60,8 +63,11 @@ and base_type =
6063
| VOLATILE of base_type
6164
(** "volatile" modifier *)
6265
| GNU_TYPE of gnu_attrs * base_type
63-
(** Not a type, just to record the file/line of an identifier. *)
66+
(** a type annotated with GNU attributes *)
67+
| BUILTIN_TYPE of string
68+
(** a machine-specific or complier-specific builtin type *)
6469
| TYPE_LINE of string * int * base_type
70+
(** Not a type, just to record the file/line of an identifier. *)
6571

6672
(** A name in a declaration with identifier, full type, GNU attributes and
6773
* initialization expression. *)

0 commit comments

Comments
 (0)