Skip to content

Commit a2906c8

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

File tree

3 files changed

+46
-90
lines changed

3 files changed

+46
-90
lines changed

compiler/src/dmd/expression.d

Lines changed: 41 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,7 @@ 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+
alias onstack = flag1;
19001901

19011902
/** If !is null, elements[] can be sparse and basis is used for the
19021903
* "default" element value. In other words, non-null elements[i] overrides
@@ -2056,8 +2057,6 @@ extern (C++) final class ArrayLiteralExp : Expression
20562057
*/
20572058
extern (C++) final class AssocArrayLiteralExp : Expression
20582059
{
2059-
OwnedBy ownedByCtfe = OwnedBy.code;
2060-
20612060
Expressions* keys;
20622061
Expressions* values;
20632062
/// Lower to core.internal.newaa for static initializaton
@@ -2122,14 +2121,9 @@ extern (C++) final class AssocArrayLiteralExp : Expression
21222121
*/
21232122
extern (C++) final class StructLiteralExp : Expression
21242123
{
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));
2124+
2125+
alias useStaticInit = flag1; /// if this is true, use the StructDeclaration's init symbol
2126+
alias isOriginal = flag2; /// used when moving instances to indicate `this is this.origin`
21332127
StageFlags stageflags;
21342128

21352129
StructDeclaration sd; /// which aggregate this is for
@@ -2455,8 +2449,8 @@ extern (C++) final class NewExp : Expression
24552449

24562450
Expression argprefix; // expression to be evaluated just before arguments[]
24572451
CtorDeclaration member; // constructor function
2458-
bool onstack; // allocate on stack
2459-
bool thrownew; // this NewExp is the expression of a ThrowStatement
2452+
alias onstack = flag1; // allocate on stack
2453+
alias thrownew = flag2; // this NewExp is the expression of a ThrowStatement
24602454

24612455
Expression lowering; // lowered druntime hook: `_d_new{class,itemT}`
24622456

@@ -2534,7 +2528,7 @@ extern (C++) class SymbolExp : Expression
25342528
{
25352529
Declaration var;
25362530
Dsymbol originalScope; // original scope before inlining
2537-
bool hasOverloads;
2531+
alias hasOverloads = flag1;
25382532

25392533
extern (D) this(Loc loc, EXP op, Declaration var, bool hasOverloads) @safe
25402534
{
@@ -2591,7 +2585,7 @@ extern (C++) final class SymOffExp : SymbolExp
25912585
*/
25922586
extern (C++) final class VarExp : SymbolExp
25932587
{
2594-
bool delegateWasExtracted;
2588+
alias delegateWasExtracted = flag1;
25952589
extern (D) this(Loc loc, Declaration var, bool hasOverloads = true) @safe
25962590
{
25972591
if (var.isVarDeclaration())
@@ -3104,10 +3098,9 @@ extern (C++) final class ThrowExp : UnaExp
31043098
extern (C++) final class DotIdExp : UnaExp
31053099
{
31063100
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-
3101+
alias noderef = flag1; // true if the result of the expression will never be dereferenced
3102+
alias wantsym = flag2; // do not replace Symbol with its initializer during semantic()
3103+
alias arrow = flag3; // ImportC: if -> instead of .
31113104
extern (D) this(Loc loc, Expression e, Identifier ident) @safe
31123105
{
31133106
super(loc, EXP.dotIdentifier, e);
@@ -3155,7 +3148,7 @@ extern (C++) final class DotTemplateExp : UnaExp
31553148
extern (C++) final class DotVarExp : UnaExp
31563149
{
31573150
Declaration var;
3158-
bool hasOverloads;
3151+
alias hasOverloads = flag1;
31593152

31603153
extern (D) this(Loc loc, Expression e, Declaration var, bool hasOverloads = true) @safe
31613154
{
@@ -3233,7 +3226,7 @@ extern (C++) final class DotTemplateInstanceExp : UnaExp
32333226
extern (C++) final class DelegateExp : UnaExp
32343227
{
32353228
FuncDeclaration func;
3236-
bool hasOverloads;
3229+
alias hasOverloads = flag1;
32373230
VarDeclaration vthis2; // container for multi-context
32383231

32393232
extern (D) this(Loc loc, Expression e, FuncDeclaration f, bool hasOverloads = true, VarDeclaration vthis2 = null) @safe
@@ -3308,11 +3301,12 @@ extern (C++) final class CallExp : UnaExp
33083301
Expressions* arguments; // function arguments
33093302
ArgumentLabels *names; // named argument labels
33103303
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
33153304
VarDeclaration vthis2; // container for multi-context
3305+
alias directcall = flag1; // true if a virtual call is devirtualized
3306+
alias inDebugStatement = flag2; /// true if this was in a debug statement
3307+
alias ignoreAttributes = flag3; /// don't enforce attributes (e.g. call @gc function in @nogc code)
3308+
bool isUfcsRewrite; /// the first argument was pushed in here by a UFCS rewrite
3309+
33163310

33173311
/// Puts the `arguments` and `names` into an `ArgumentList` for easily passing them around.
33183312
/// The fields are still separate for backwards compatibility
@@ -3593,7 +3587,7 @@ extern (C++) final class NotExp : UnaExp
35933587
*/
35943588
extern (C++) final class DeleteExp : UnaExp
35953589
{
3596-
bool isRAII; // true if called automatically as a result of scoped destruction
3590+
alias isRAII = flag1; // true if called automatically as a result of scoped destruction
35973591

35983592
extern (D) this(Loc loc, Expression e, bool isRAII) @safe
35993593
{
@@ -3617,9 +3611,9 @@ extern (C++) final class DeleteExp : UnaExp
36173611
extern (C++) final class CastExp : UnaExp
36183612
{
36193613
Type to; // type to cast to
3620-
ubyte mod = cast(ubyte)~0; // MODxxxxx
3621-
bool trusted; // assume cast is safe
36223614
Expression lowering;
3615+
ubyte mod = cast(ubyte)~0; // MODxxxxx
3616+
alias trusted = flag1; // assume cast is safe
36233617

36243618
extern (D) this(Loc loc, Expression e, Type t) @safe
36253619
{
@@ -3662,7 +3656,6 @@ extern (C++) final class VectorExp : UnaExp
36623656
{
36633657
TypeVector to; // the target vector type before semantic()
36643658
uint dim = ~0; // number of elements in the vector
3665-
OwnedBy ownedByCtfe = OwnedBy.code;
36663659

36673660
extern (D) this(Loc loc, Expression e, Type t) @trusted
36683661
{
@@ -3722,14 +3715,9 @@ extern (C++) final class SliceExp : UnaExp
37223715

37233716
VarDeclaration lengthVar;
37243717

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));
3718+
alias upperIsInBounds = flag1; // true if upr <= e1.length
3719+
alias lowerIsLessThanUpper = flag2; // true if lwr <= upr
3720+
alias arrayop = flag3; // an array operation, rather than a slice
37333721

37343722
/************************************************************/
37353723
extern (D) this(Loc loc, Expression e1, IntervalExp ie) @safe
@@ -3857,13 +3845,13 @@ extern (C++) final class CommaExp : BinExp
38573845
{
38583846
/// This is needed because AssignExp rewrites CommaExp, hence it needs
38593847
/// to trigger the deprecation.
3860-
const bool isGenerated;
3848+
alias isGenerated = flag1;
38613849

38623850
/// Temporary variable to enable / disable deprecation of comma expression
38633851
/// depending on the context.
38643852
/// Since most constructor calls are rewritting, the only place where
38653853
/// false will be passed will be from the parser.
3866-
bool allowCommaExp;
3854+
alias allowCommaExp = flag2;
38673855

38683856
/// The original expression before any rewriting occurs.
38693857
/// This is used in error messages.
@@ -3996,8 +3984,8 @@ extern (C++) final class DelegateFuncptrExp : UnaExp
39963984
extern (C++) final class IndexExp : BinExp
39973985
{
39983986
VarDeclaration lengthVar;
3999-
bool modifiable = false; // assume it is an rvalue
4000-
bool indexIsInBounds; // true if 0 <= e2 && e2 <= e1.length - 1
3987+
alias modifiable = flag1; // assume it is an rvalue
3988+
alias indexIsInBounds = flag2; // true if 0 <= e2 && e2 <= e1.length - 1
40013989

40023990
extern (D) this(Loc loc, Expression e1, Expression e2) @safe
40033991
{

0 commit comments

Comments
 (0)