Skip to content

Commit 8811596

Browse files
committed
[expression.d] compress flags
1 parent 0cb6dfe commit 8811596

File tree

4 files changed

+111
-195
lines changed

4 files changed

+111
-195
lines changed

compiler/src/dmd/expression.d

Lines changed: 65 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,13 @@ extern (C++) abstract class Expression : ASTNode
304304

305305
static struct BitFields
306306
{
307-
bool parens; // if this is a parenthesized expression
308-
bool rvalue; // true if this is considered to be an rvalue, even if it is an lvalue
309-
bool gcPassDone; // `checkGC` has been run on this expression
307+
OwnedBy ownedByCtfe = OwnedBy.code;
308+
bool parens; // if this is a parenthesized expression
309+
bool rvalue; // true if this is considered to be an rvalue, even if it is an lvalue
310+
bool gcPassDone; // `checkGC` has been run on this expression
311+
bool flag1; // reserved space for flags of derived classes
312+
bool flag2; // ditto
313+
bool flag3; // ditto
310314
}
311315
import dmd.common.bitfields;
312316
mixin(generateBitFields!(BitFields, ubyte));
@@ -1246,7 +1250,7 @@ extern (C++) final class DollarExp : IdentifierExp
12461250
extern (C++) final class DsymbolExp : Expression
12471251
{
12481252
Dsymbol s;
1249-
bool hasOverloads;
1253+
alias hasOverloads = flag1;
12501254

12511255
extern (D) this(Loc loc, Dsymbol s, bool hasOverloads = true) @safe
12521256
{
@@ -1382,8 +1386,6 @@ extern (C++) final class NullExp : Expression
13821386
*/
13831387
extern (C++) final class StringExp : Expression
13841388
{
1385-
char postfix = NoPostfix; // 'c', 'w', 'd'
1386-
OwnedBy ownedByCtfe = OwnedBy.code;
13871389
private union
13881390
{
13891391
char* string; // if sz == 1
@@ -1393,6 +1395,7 @@ extern (C++) final class StringExp : Expression
13931395
} // (const if ownedByCtfe == OwnedBy.code)
13941396
size_t len; // number of code units
13951397
ubyte sz = 1; // 1: char, 2: wchar, 4: dchar
1398+
char postfix = NoPostfix; // 'c', 'w', 'd'
13961399

13971400
/**
13981401
* Whether the string literal's type is fixed
@@ -1402,12 +1405,12 @@ extern (C++) final class StringExp : Expression
14021405
* wstring y = cast(string) "abc"; // Error: type was committed after cast
14031406
* ---
14041407
*/
1405-
bool committed;
1408+
alias committed = flag1;
14061409

14071410
/// If the string is parsed from a hex string literal
1408-
bool hexString = false;
1411+
alias hexString = flag2;
14091412
/// If the string is from a collected C macro
1410-
bool cMacro = false;
1413+
alias cMacro = flag3;
14111414

14121415
enum char NoPostfix = 0;
14131416

@@ -1760,10 +1763,9 @@ extern (C++) final class StringExp : Expression
17601763

17611764
extern (C++) final class InterpExp : Expression
17621765
{
1763-
char postfix = NoPostfix; // 'c', 'w', 'd'
1764-
OwnedBy ownedByCtfe = OwnedBy.code;
17651766
InterpolatedSet* interpolatedSet;
17661767

1768+
char postfix = NoPostfix; // 'c', 'w', 'd'
17671769
enum char NoPostfix = 0;
17681770

17691771
extern (D) this(Loc loc, InterpolatedSet* set, char postfix = NoPostfix) scope @safe
@@ -1895,8 +1897,8 @@ extern (C++) final class TupleExp : Expression
18951897
*/
18961898
extern (C++) final class ArrayLiteralExp : Expression
18971899
{
1898-
OwnedBy ownedByCtfe = OwnedBy.code;
1899-
bool onstack = false;
1900+
bool onstack() { return flag1; }
1901+
void onstack(bool v) { flag1 = v; }
19001902

19011903
/** If !is null, elements[] can be sparse and basis is used for the
19021904
* "default" element value. In other words, non-null elements[i] overrides
@@ -2056,8 +2058,6 @@ extern (C++) final class ArrayLiteralExp : Expression
20562058
*/
20572059
extern (C++) final class AssocArrayLiteralExp : Expression
20582060
{
2059-
OwnedBy ownedByCtfe = OwnedBy.code;
2060-
20612061
Expressions* keys;
20622062
Expressions* values;
20632063
/// Lower to core.internal.newaa for static initializaton
@@ -2122,14 +2122,11 @@ extern (C++) final class AssocArrayLiteralExp : Expression
21222122
*/
21232123
extern (C++) final class StructLiteralExp : Expression
21242124
{
2125-
struct BitFields
2126-
{
2127-
bool useStaticInit; /// if this is true, use the StructDeclaration's init symbol
2128-
bool isOriginal = false; /// used when moving instances to indicate `this is this.origin`
2129-
OwnedBy ownedByCtfe = OwnedBy.code;
2130-
}
2131-
import dmd.common.bitfields;
2132-
mixin(generateBitFields!(BitFields, ubyte));
2125+
2126+
alias useStaticInit = flag1; /// if this is true, use the StructDeclaration's init symbol
2127+
bool useStaticInit() { return flag1; }
2128+
void useStaticInit(bool v) { flag1 = v; }
2129+
alias isOriginal = flag2; /// used when moving instances to indicate `this is this.origin`
21332130
StageFlags stageflags;
21342131

21352132
StructDeclaration sd; /// which aggregate this is for
@@ -2455,8 +2452,13 @@ extern (C++) final class NewExp : Expression
24552452

24562453
Expression argprefix; // expression to be evaluated just before arguments[]
24572454
CtorDeclaration member; // constructor function
2458-
bool onstack; // allocate on stack
2459-
bool thrownew; // this NewExp is the expression of a ThrowStatement
2455+
2456+
// allocate on stack
2457+
bool onstack() { return flag1; }
2458+
void onstack(bool v) { flag1 = v; }
2459+
// this NewExp is the expression of a ThrowStatement
2460+
bool thrownew() { return flag2; }
2461+
void thrownew(bool v) { flag2 = v; }
24602462

24612463
Expression lowering; // lowered druntime hook: `_d_new{class,itemT}`
24622464

@@ -2534,7 +2536,7 @@ extern (C++) class SymbolExp : Expression
25342536
{
25352537
Declaration var;
25362538
Dsymbol originalScope; // original scope before inlining
2537-
bool hasOverloads;
2539+
alias hasOverloads = flag1;
25382540

25392541
extern (D) this(Loc loc, EXP op, Declaration var, bool hasOverloads) @safe
25402542
{
@@ -2591,7 +2593,7 @@ extern (C++) final class SymOffExp : SymbolExp
25912593
*/
25922594
extern (C++) final class VarExp : SymbolExp
25932595
{
2594-
bool delegateWasExtracted;
2596+
alias delegateWasExtracted = flag1;
25952597
extern (D) this(Loc loc, Declaration var, bool hasOverloads = true) @safe
25962598
{
25972599
if (var.isVarDeclaration())
@@ -3104,10 +3106,9 @@ extern (C++) final class ThrowExp : UnaExp
31043106
extern (C++) final class DotIdExp : UnaExp
31053107
{
31063108
Identifier ident;
3107-
bool noderef; // true if the result of the expression will never be dereferenced
3108-
bool wantsym; // do not replace Symbol with its initializer during semantic()
3109-
bool arrow; // ImportC: if -> instead of .
3110-
3109+
alias noderef = flag1; // true if the result of the expression will never be dereferenced
3110+
alias wantsym = flag2; // do not replace Symbol with its initializer during semantic()
3111+
alias arrow = flag3; // ImportC: if -> instead of .
31113112
extern (D) this(Loc loc, Expression e, Identifier ident) @safe
31123113
{
31133114
super(loc, EXP.dotIdentifier, e);
@@ -3155,7 +3156,7 @@ extern (C++) final class DotTemplateExp : UnaExp
31553156
extern (C++) final class DotVarExp : UnaExp
31563157
{
31573158
Declaration var;
3158-
bool hasOverloads;
3159+
alias hasOverloads = flag1;
31593160

31603161
extern (D) this(Loc loc, Expression e, Declaration var, bool hasOverloads = true) @safe
31613162
{
@@ -3233,7 +3234,7 @@ extern (C++) final class DotTemplateInstanceExp : UnaExp
32333234
extern (C++) final class DelegateExp : UnaExp
32343235
{
32353236
FuncDeclaration func;
3236-
bool hasOverloads;
3237+
alias hasOverloads = flag1;
32373238
VarDeclaration vthis2; // container for multi-context
32383239

32393240
extern (D) this(Loc loc, Expression e, FuncDeclaration f, bool hasOverloads = true, VarDeclaration vthis2 = null) @safe
@@ -3308,11 +3309,18 @@ extern (C++) final class CallExp : UnaExp
33083309
Expressions* arguments; // function arguments
33093310
ArgumentLabels *names; // named argument labels
33103311
FuncDeclaration f; // symbol to call
3311-
bool directcall; // true if a virtual call is devirtualized
3312-
bool inDebugStatement; /// true if this was in a debug statement
3313-
bool ignoreAttributes; /// don't enforce attributes (e.g. call @gc function in @nogc code)
3314-
bool isUfcsRewrite; /// the first argument was pushed in here by a UFCS rewrite
33153312
VarDeclaration vthis2; // container for multi-context
3313+
bool directcall() { return flag1; }
3314+
void directcall(bool v) {flag1 = v; }
3315+
alias directcall = flag1; /// true if a virtual call is devirtualized
3316+
alias inDebugStatement = flag2; /// true if this was in a debug statement
3317+
alias ignoreAttributes = flag3; /// don't enforce attributes (e.g. call @gc function in @nogc code)
3318+
3319+
/// the first argument was pushed in here by a UFCS rewrite
3320+
// we reuse the `ownedBy` bits of the bitfield
3321+
bool isUfcsRewrite() { return ownedByCtfe != OwnedBy.code; }
3322+
void isUfcsRewrite(bool v) { ownedByCtfe = v ? OwnedBy.ctfe : OwnedBy.code; }
3323+
33163324

33173325
/// Puts the `arguments` and `names` into an `ArgumentList` for easily passing them around.
33183326
/// The fields are still separate for backwards compatibility
@@ -3593,7 +3601,7 @@ extern (C++) final class NotExp : UnaExp
35933601
*/
35943602
extern (C++) final class DeleteExp : UnaExp
35953603
{
3596-
bool isRAII; // true if called automatically as a result of scoped destruction
3604+
alias isRAII = flag1; // true if called automatically as a result of scoped destruction
35973605

35983606
extern (D) this(Loc loc, Expression e, bool isRAII) @safe
35993607
{
@@ -3617,9 +3625,9 @@ extern (C++) final class DeleteExp : UnaExp
36173625
extern (C++) final class CastExp : UnaExp
36183626
{
36193627
Type to; // type to cast to
3620-
ubyte mod = cast(ubyte)~0; // MODxxxxx
3621-
bool trusted; // assume cast is safe
36223628
Expression lowering;
3629+
ubyte mod = cast(ubyte)~0; // MODxxxxx
3630+
alias trusted = flag1; // assume cast is safe
36233631

36243632
extern (D) this(Loc loc, Expression e, Type t) @safe
36253633
{
@@ -3662,7 +3670,6 @@ extern (C++) final class VectorExp : UnaExp
36623670
{
36633671
TypeVector to; // the target vector type before semantic()
36643672
uint dim = ~0; // number of elements in the vector
3665-
OwnedBy ownedByCtfe = OwnedBy.code;
36663673

36673674
extern (D) this(Loc loc, Expression e, Type t) @trusted
36683675
{
@@ -3722,14 +3729,14 @@ extern (C++) final class SliceExp : UnaExp
37223729

37233730
VarDeclaration lengthVar;
37243731

3725-
private extern(D) static struct BitFields
3726-
{
3727-
bool upperIsInBounds; // true if upr <= e1.length
3728-
bool lowerIsLessThanUpper; // true if lwr <= upr
3729-
bool arrayop; // an array operation, rather than a slice
3730-
}
3731-
import dmd.common.bitfields : generateBitFields;
3732-
mixin(generateBitFields!(BitFields, ubyte));
3732+
// true if upr <= e1.length
3733+
bool upperIsInBounds() { return flag1; }
3734+
void upperIsInBounds(bool v) { flag1 = v; }
3735+
// true if lwr <= upr
3736+
bool lowerIsLessThanUpper() { return flag2; }
3737+
void lowerIsLessThanUpper(bool v) { flag2 = v; }
3738+
3739+
alias arrayop = flag3; // an array operation, rather than a slice
37333740

37343741
/************************************************************/
37353742
extern (D) this(Loc loc, Expression e1, IntervalExp ie) @safe
@@ -3857,13 +3864,14 @@ extern (C++) final class CommaExp : BinExp
38573864
{
38583865
/// This is needed because AssignExp rewrites CommaExp, hence it needs
38593866
/// to trigger the deprecation.
3860-
const bool isGenerated;
3867+
bool isGenerated() { return flag1; }
3868+
void isGenerated(bool v) { flag1 = v; }
38613869

38623870
/// Temporary variable to enable / disable deprecation of comma expression
38633871
/// depending on the context.
38643872
/// Since most constructor calls are rewritting, the only place where
38653873
/// false will be passed will be from the parser.
3866-
bool allowCommaExp;
3874+
alias allowCommaExp = flag2;
38673875

38683876
/// The original expression before any rewriting occurs.
38693877
/// This is used in error messages.
@@ -3996,8 +4004,12 @@ extern (C++) final class DelegateFuncptrExp : UnaExp
39964004
extern (C++) final class IndexExp : BinExp
39974005
{
39984006
VarDeclaration lengthVar;
3999-
bool modifiable = false; // assume it is an rvalue
4000-
bool indexIsInBounds; // true if 0 <= e2 && e2 <= e1.length - 1
4007+
// assume it is an rvalue
4008+
bool modifiable() { return flag1; }
4009+
void modifiable(bool v) { flag1 = v; }
4010+
// true if 0 <= e2 && e2 <= e1.length - 1
4011+
bool indexIsInBounds() { return flag1; }
4012+
void indexIsInBounds(bool v) { flag1 = v; }
40014013

40024014
extern (D) this(Loc loc, Expression e1, Expression e2) @safe
40034015
{

0 commit comments

Comments
 (0)