Skip to content

Commit

Permalink
Implement -preview=complex
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuclaw committed Jan 28, 2021
1 parent b483274 commit f432256
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/dmd/cli.d
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,8 @@ dmd -cov -unittest myprog.d
"'in' contracts of overridden methods must be a superset of parent contract"),
Feature("shortenedMethods", "shortenedMethods",
"allow use of => for methods and top-level functions in addition to lambdas"),
Feature("complex", "previewComplex",
"remove complex and imaginary types from the language"),
// DEPRECATED previews
// trigger deprecation message once D repositories don't use this flag anymore
Feature("markdown", "markdown", "enable Markdown replacements in Ddoc", false, false),
Expand Down
8 changes: 7 additions & 1 deletion src/dmd/cppmangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,7 @@ extern(C++):
if (t.isImmutable() || t.isShared())
return error(t);

/* __c_(u)long(long) get special mangling
/* __c_(u)long(long) and others get special mangling
*/
const id = t.sym.ident;
//printf("enum id = '%s'\n", id.toChars());
Expand All @@ -1849,6 +1849,12 @@ extern(C++):
return writeBasicType(t, 0, 'x');
else if (id == Id.__c_ulonglong)
return writeBasicType(t, 0, 'y');
else if (id == Id.__c_complex_float)
return writeBasicType(t, 'C', 'f');
else if (id == Id.__c_complex_double)
return writeBasicType(t, 'C', 'd');
else if (id == Id.__c_complex_long_double)
return writeBasicType(t, 'C', 'e');

doSymbol(t);
}
Expand Down
5 changes: 4 additions & 1 deletion src/dmd/denum.d
Original file line number Diff line number Diff line change
Expand Up @@ -470,5 +470,8 @@ bool isSpecialEnumIdent(const Identifier ident) @nogc nothrow
ident == Id.__c_longlong ||
ident == Id.__c_ulonglong ||
ident == Id.__c_long_double ||
ident == Id.__c_wchar_t;
ident == Id.__c_wchar_t ||
ident == Id.__c_complex_float ||
ident == Id.__c_complex_double ||
ident == Id.__c_complex_long_double;
}
12 changes: 12 additions & 0 deletions src/dmd/dtoh.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ private struct DMDType
__gshared Identifier c_ulonglong;
__gshared Identifier c_long_double;
__gshared Identifier c_wchar_t;
__gshared Identifier c_complex_float;
__gshared Identifier c_complex_double;
__gshared Identifier c_complex_long_double;

static void _init()
{
Expand All @@ -47,6 +50,9 @@ private struct DMDType
c_ulonglong = Identifier.idPool("__c_ulonglong");
c_long_double = Identifier.idPool("__c_long_double");
c_wchar_t = Identifier.idPool("__c_wchar_t");
c_complex_float = Identifier.idPool("__c_complex_float");
c_complex_double = Identifier.idPool("__c_complex_double");
c_complex_long_double = Identifier.idPool("__c_complex_long_double");
}
}

Expand Down Expand Up @@ -1744,6 +1750,12 @@ public:
buf.writestring("long double");
else if (ed.ident == DMDType.c_wchar_t)
buf.writestring("wchar_t");
else if (ed.ident == DMDType.c_complex_float)
buf.writestring("_Complex float");
else if (ed.ident == DMDType.c_complex_double)
buf.writestring("_Complex double");
else if (ed.ident == DMDType.c_complex_long_double)
buf.writestring("_Complex long double");
else
{
//ed.print();
Expand Down
5 changes: 5 additions & 0 deletions src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -6825,6 +6825,7 @@ struct Param
bool vgc;
bool vfield;
bool vcomplex;
bool previewComplex;
uint8_t symdebug;
bool symdebugref;
bool optimize;
Expand Down Expand Up @@ -6958,6 +6959,7 @@ struct Param
vgc(),
vfield(),
vcomplex(),
previewComplex(),
symdebug(),
symdebugref(),
optimize(),
Expand Down Expand Up @@ -7396,6 +7398,9 @@ struct Id
static Identifier* __c_ulonglong;
static Identifier* __c_long_double;
static Identifier* __c_wchar_t;
static Identifier* __c_complex_float;
static Identifier* __c_complex_double;
static Identifier* __c_complex_long_double;
static Identifier* cpp_type_info_ptr;
static Identifier* _assert;
static Identifier* _unittest;
Expand Down
3 changes: 2 additions & 1 deletion src/dmd/globals.d
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ extern (C++) struct Param
bool vtemplatesListInstances; // collect and list statistics on template instantiations origins. TODO: make this an enum when we want to list other kinds of instances
bool vgc; // identify gc usage
bool vfield; // identify non-mutable field variables
bool vcomplex; // identify complex/imaginary type usage
bool vcomplex; // deprecate complex imaginary types
bool previewComplex; // remove complex and imaginary types
ubyte symdebug; // insert debug symbolic information
bool symdebugref; // insert debug information for all referenced types, too
bool optimize; // run optimizer
Expand Down
3 changes: 2 additions & 1 deletion src/dmd/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ struct Param
bool vtemplatesListInstances; // collect and list statistics on template instantiations origins
bool vgc; // identify gc usage
bool vfield; // identify non-mutable field variables
bool vcomplex; // identify complex/imaginary type usage
bool vcomplex; // deprecate complex imaginary types
bool previewComplex; // remove complex and imaginary types
unsigned char symdebug; // insert debug symbolic information
bool symdebugref; // insert debug information for all referenced types, too
bool optimize; // run optimizer
Expand Down
6 changes: 6 additions & 0 deletions src/dmd/glue.d
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,12 @@ tym_t totym(Type tx)
t = tb.ty == Tuns32 ? TYulong : TYullong;
else if (id == Id.__c_long_double)
t = TYdouble;
else if (id == Id.__c_complex_float)
t = TYcfloat;
else if (id == Id.__c_complex_double)
t = TYcdouble;
else if (id == Id.__c_complex_long_double)
t = TYcldouble;
else
t = totym(tb);
break;
Expand Down
3 changes: 3 additions & 0 deletions src/dmd/id.d
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ immutable Msgtable[] msgtable =
{ "__c_ulonglong" },
{ "__c_long_double" },
{ "__c_wchar_t" },
{ "__c_complex_float" },
{ "__c_complex_double" },
{ "__c_complex_long_double" },
{ "cpp_type_info_ptr", "__cpp_type_info_ptr" },
{ "_assert", "assert" },
{ "_unittest", "unittest" },
Expand Down
18 changes: 17 additions & 1 deletion src/dmd/lexer.d
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,22 @@ class Lexer
p++;
}
}
if (global.params.previewComplex)
{
switch (t.value)
{
case TOK.imaginary32:
case TOK.imaginary64:
case TOK.imaginary80:
case TOK.complex32:
case TOK.complex64:
case TOK.complex80:
t.value = TOK.identifier;
break;
default:
break;
}
}
//printf("t.value = %d\n",t.value);
return;
}
Expand Down Expand Up @@ -2242,7 +2258,7 @@ class Lexer
p++;
break;
}
if (*p == 'i' || *p == 'I')
if ((*p == 'i' || *p == 'I') && !global.params.previewComplex)
{
if (*p == 'I')
error("use 'i' suffix instead of 'I'");
Expand Down
16 changes: 15 additions & 1 deletion src/dmd/target.d
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,21 @@ extern (C++) struct Target
return false; // returns a pointer
}

Type tn = tf.next.toBasetype();
Type tn = tf.next;
if (auto te = tn.isTypeEnum())
{
if (te.sym.isSpecial())
{
// Special enums with target-specific return style
if (te.sym.ident == Id.__c_complex_float)
tn = Type.tcomplex32.castMod(tn.mod);
else if (te.sym.ident == Id.__c_complex_double)
tn = Type.tcomplex64.castMod(tn.mod);
else if (te.sym.ident == Id.__c_complex_long_double)
tn = Type.tcomplex80.castMod(tn.mod);
}
}
tn = tn.toBasetype();
//printf("tn = %s\n", tn.toChars());
d_uns64 sz = tn.size();
Type tns = tn;
Expand Down
5 changes: 4 additions & 1 deletion src/dmd/toctype.d
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ public:
// https://issues.dlang.org/show_bug.cgi?id=13792
t.ctype = Type_toCtype(Type.tvoid);
}
else if (sym.ident == Id.__c_long)
else if (sym.ident == Id.__c_long ||
sym.ident == Id.__c_complex_float ||
sym.ident == Id.__c_complex_double ||
sym.ident == Id.__c_complex_long_double)
{
t.ctype = type_fake(totym(t));
t.ctype.Tcount++;
Expand Down
1 change: 1 addition & 0 deletions test/compilable/previewhelp.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ Upcoming language changes listed by -preview=name:
=in `in` on parameters means `scope const [ref]` and accepts rvalues
=inclusiveincontracts 'in' contracts of overridden methods must be a superset of parent contract
=shortenedMethods allow use of => for methods and top-level functions in addition to lambdas
=complex remove complex and imaginary types from the language
----
*/

0 comments on commit f432256

Please sign in to comment.