aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/dmd/expression.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/d/dmd/expression.h')
-rw-r--r--gcc/d/dmd/expression.h108
1 files changed, 50 insertions, 58 deletions
diff --git a/gcc/d/dmd/expression.h b/gcc/d/dmd/expression.h
index 2f6bb84..3c8d90d 100644
--- a/gcc/d/dmd/expression.h
+++ b/gcc/d/dmd/expression.h
@@ -1,6 +1,6 @@
/* Compiler implementation of the D programming language
- * Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
+ * Copyright (C) 1999-2025 by The D Language Foundation, All Rights Reserved
* written by Walter Bright
* https://www.digitalmars.com
* Distributed under the Boost Software License, Version 1.0.
@@ -40,6 +40,7 @@ class OverloadSet;
class StringExp;
class InterpExp;
class LoweredAssignExp;
+class StaticForeach;
#ifdef IN_GCC
typedef union tree_node Symbol;
#else
@@ -50,8 +51,9 @@ namespace dmd
{
// in expressionsem.d
Expression *expressionSemantic(Expression *e, Scope *sc);
+ void lowerNonArrayAggregate(StaticForeach *sfe, Scope *sc);
// in typesem.d
- Expression *defaultInit(Type *mt, const Loc &loc, const bool isCfile = false);
+ Expression *defaultInit(Type *mt, Loc loc, const bool isCfile = false);
// Entry point for CTFE.
// A compile-time result is required. Give an error if not possible
@@ -71,26 +73,18 @@ enum
#define WANTvalue 0 // default
#define WANTexpand 1 // expand const/immutable variables if possible
-/**
- * Specifies how the checkModify deals with certain situations
- */
-enum class ModifyFlags
-{
- /// Issue error messages on invalid modifications of the variable
- none,
- /// No errors are emitted for invalid modifications
- noError = 0x1,
- /// The modification occurs for a subfield of the current variable
- fieldAssign = 0x2,
-};
-
class Expression : public ASTNode
{
public:
Type *type; // !=NULL means that semantic() has been run
Loc loc; // file location
EXP op; // to minimize use of dynamic_cast
- d_bool parens; // if this is a parenthesized expression
+ uint8_t bitFields;
+
+ bool parens() const;
+ bool parens(bool v);
+ bool rvalue() const;
+ bool rvalue(bool v);
size_t size() const;
static void _init();
@@ -99,7 +93,7 @@ public:
// kludge for template.isExpression()
DYNCAST dyncast() const override final { return DYNCAST_EXPRESSION; }
- const char *toChars() const override;
+ const char* toChars() const final override;
virtual dinteger_t toInteger();
virtual uinteger_t toUInteger();
@@ -109,7 +103,6 @@ public:
virtual StringExp *toStringExp();
virtual bool isLvalue();
virtual bool checkType();
- virtual bool checkValue();
Expression *addressOf();
Expression *deref();
@@ -151,7 +144,7 @@ public:
TypeidExp* isTypeidExp();
TraitsExp* isTraitsExp();
HaltExp* isHaltExp();
- IsExp* isExp();
+ IsExp* isIsExp();
MixinExp* isMixinExp();
ImportExp* isImportExp();
AssertExp* isAssertExp();
@@ -242,7 +235,7 @@ class IntegerExp final : public Expression
public:
dinteger_t value;
- static IntegerExp *create(const Loc &loc, dinteger_t value, Type *type);
+ static IntegerExp *create(Loc loc, dinteger_t value, Type *type);
bool equals(const RootObject * const o) const override;
dinteger_t toInteger() override;
real_t toReal() override;
@@ -268,7 +261,7 @@ class RealExp final : public Expression
public:
real_t value;
- static RealExp *create(const Loc &loc, real_t value, Type *type);
+ static RealExp *create(Loc loc, real_t value, Type *type);
bool equals(const RootObject * const o) const override;
bool isIdentical(const Expression *e) const override;
dinteger_t toInteger() override;
@@ -285,7 +278,7 @@ class ComplexExp final : public Expression
public:
complex_t value;
- static ComplexExp *create(const Loc &loc, complex_t value, Type *type);
+ static ComplexExp *create(Loc loc, complex_t value, Type *type);
bool equals(const RootObject * const o) const override;
bool isIdentical(const Expression *e) const override;
dinteger_t toInteger() override;
@@ -302,7 +295,7 @@ class IdentifierExp : public Expression
public:
Identifier *ident;
- static IdentifierExp *create(const Loc &loc, Identifier *ident);
+ static IdentifierExp *create(Loc loc, Identifier *ident);
bool isLvalue() override final;
void accept(Visitor *v) override { v->visit(this); }
};
@@ -362,8 +355,8 @@ public:
d_bool committed; // if type is committed
d_bool hexString; // if string is parsed from a hex string literal
- static StringExp *create(const Loc &loc, const char *s);
- static StringExp *create(const Loc &loc, const void *s, d_size_t len);
+ static StringExp *create(Loc loc, const char *s);
+ static StringExp *create(Loc loc, const void *s, d_size_t len);
bool equals(const RootObject * const o) const override;
char32_t getCodeUnit(d_size_t i) const;
dinteger_t getIndex(d_size_t i) const;
@@ -400,7 +393,7 @@ public:
*/
Expressions *exps;
- static TupleExp *create(const Loc &loc, Expressions *exps);
+ static TupleExp *create(Loc loc, Expressions *exps);
TupleExp *syntaxCopy() override;
bool equals(const RootObject * const o) const override;
@@ -415,7 +408,7 @@ public:
Expression *basis;
Expressions *elements;
- static ArrayLiteralExp *create(const Loc &loc, Expressions *elements);
+ static ArrayLiteralExp *create(Loc loc, Expressions *elements);
ArrayLiteralExp *syntaxCopy() override;
bool equals(const RootObject * const o) const override;
Expression *getElement(d_size_t i);
@@ -443,6 +436,24 @@ public:
class StructLiteralExp final : public Expression
{
public:
+ uint8_t bitFields;
+
+ // if this is true, use the StructDeclaration's init symbol
+ bool useStaticInit() const;
+ bool useStaticInit(bool v);
+ // used when moving instances to indicate `this is this.origin`
+ bool isOriginal() const;
+ bool isOriginal(bool v);
+ OwnedBy ownedByCtfe() const;
+ OwnedBy ownedByCtfe(OwnedBy v);
+
+ /** anytime when recursive function is calling, 'stageflags' marks with bit flag of
+ * current stage and unmarks before return from this function.
+ * 'inlinecopy' uses similar 'stageflags' and from multiple evaluation 'doInline'
+ * (with infinite recursion) of this expression.
+ */
+ uint8_t stageflags;
+
StructDeclaration *sd; // which aggregate this is for
Expressions *elements; // parallels sd->fields[] with NULL entries for fields to skip
Type *stype; // final type of result (can be different from sd's type)
@@ -463,18 +474,7 @@ public:
StructLiteralExp *origin;
- /** anytime when recursive function is calling, 'stageflags' marks with bit flag of
- * current stage and unmarks before return from this function.
- * 'inlinecopy' uses similar 'stageflags' and from multiple evaluation 'doInline'
- * (with infinite recursion) of this expression.
- */
- uint8_t stageflags;
-
- d_bool useStaticInit; // if this is true, use the StructDeclaration's init symbol
- d_bool isOriginal; // used when moving instances to indicate `this is this.origin`
- OwnedBy ownedByCtfe;
-
- static StructLiteralExp *create(const Loc &loc, StructDeclaration *sd, void *elements, Type *stype = NULL);
+ static StructLiteralExp *create(Loc loc, StructDeclaration *sd, void *elements, Type *stype = nullptr);
bool equals(const RootObject * const o) const override;
StructLiteralExp *syntaxCopy() override;
@@ -486,7 +486,6 @@ class TypeExp final : public Expression
public:
TypeExp *syntaxCopy() override;
bool checkType() override;
- bool checkValue() override;
void accept(Visitor *v) override { v->visit(this); }
};
@@ -497,7 +496,6 @@ public:
ScopeExp *syntaxCopy() override;
bool checkType() override;
- bool checkValue() override;
void accept(Visitor *v) override { v->visit(this); }
};
@@ -509,7 +507,6 @@ public:
bool isLvalue() override;
bool checkType() override;
- bool checkValue() override;
void accept(Visitor *v) override { v->visit(this); }
};
@@ -522,6 +519,7 @@ public:
Type *newtype;
Expressions *arguments; // Array of Expression's
Identifiers *names; // Array of names corresponding to expressions
+ Expression *placement; // if !NULL, placement expression
Expression *argprefix; // expression to be evaluated just before arguments[]
@@ -531,7 +529,7 @@ public:
Expression *lowering; // lowered druntime hook: `_d_newclass`
- static NewExp *create(const Loc &loc, Expression *thisexp, Type *newtype, Expressions *arguments);
+ static NewExp *create(Loc loc, Expression *placement, Expression *thisexp, Type *newtype, Expressions *arguments);
NewExp *syntaxCopy() override;
void accept(Visitor *v) override { v->visit(this); }
@@ -545,6 +543,7 @@ public:
Expression *thisexp; // if !NULL, 'this' for class being allocated
ClassDeclaration *cd; // class being instantiated
Expressions *arguments; // Array of Expression's to call class constructor
+ Expression *placement; // if !NULL, placement expression
NewAnonClassExp *syntaxCopy() override;
void accept(Visitor *v) override { v->visit(this); }
@@ -578,7 +577,7 @@ class VarExp final : public SymbolExp
{
public:
d_bool delegateWasExtracted;
- static VarExp *create(const Loc &loc, Declaration *var, bool hasOverloads = true);
+ static VarExp *create(Loc loc, Declaration *var, bool hasOverloads = true);
bool equals(const RootObject * const o) const override;
bool isLvalue() override;
@@ -607,9 +606,7 @@ public:
bool equals(const RootObject * const o) const override;
FuncExp *syntaxCopy() override;
- const char *toChars() const override;
bool checkType() override;
- bool checkValue() override;
void accept(Visitor *v) override { v->visit(this); }
};
@@ -691,9 +688,6 @@ public:
Expression *e1;
Expression *e2;
- Type *att1; // Save alias this type to detect recursion
- Type *att2; // Save alias this type to detect recursion
-
BinExp *syntaxCopy() override;
void accept(Visitor *v) override { v->visit(this); }
@@ -746,7 +740,7 @@ public:
d_bool wantsym; // do not replace Symbol with its initializer during semantic()
d_bool arrow; // ImportC: if -> instead of .
- static DotIdExp *create(const Loc &loc, Expression *e, Identifier *ident);
+ static DotIdExp *create(Loc loc, Expression *e, Identifier *ident);
void accept(Visitor *v) override { v->visit(this); }
};
@@ -756,7 +750,6 @@ public:
TemplateDeclaration *td;
bool checkType() override;
- bool checkValue() override;
void accept(Visitor *v) override { v->visit(this); }
};
@@ -777,7 +770,6 @@ public:
DotTemplateInstanceExp *syntaxCopy() override;
bool checkType() override;
- bool checkValue() override;
void accept(Visitor *v) override { v->visit(this); }
};
@@ -827,10 +819,10 @@ public:
d_bool isUfcsRewrite; // the first argument was pushed in here by a UFCS rewrite
VarDeclaration *vthis2; // container for multi-context
- static CallExp *create(const Loc &loc, Expression *e, Expressions *exps);
- static CallExp *create(const Loc &loc, Expression *e);
- static CallExp *create(const Loc &loc, Expression *e, Expression *earg1);
- static CallExp *create(const Loc &loc, FuncDeclaration *fd, Expression *earg1);
+ static CallExp *create(Loc loc, Expression *e, Expressions *exps);
+ static CallExp *create(Loc loc, Expression *e);
+ static CallExp *create(Loc loc, Expression *e, Expression *earg1);
+ static CallExp *create(Loc loc, FuncDeclaration *fd, Expression *earg1);
CallExp *syntaxCopy() override;
bool isLvalue() override;
@@ -889,6 +881,7 @@ public:
// Possible to cast to one type while painting to another type
Type *to; // type to cast to
unsigned char mod; // MODxxxxx
+ d_bool trusted; // assume cast is safe
CastExp *syntaxCopy() override;
bool isLvalue() override;
@@ -903,7 +896,7 @@ public:
unsigned dim; // number of elements in the vector
OwnedBy ownedByCtfe;
- static VectorExp *create(const Loc &loc, Expression *e, Type *t);
+ static VectorExp *create(Loc loc, Expression *e, Type *t);
VectorExp *syntaxCopy() override;
void accept(Visitor *v) override { v->visit(this); }
};
@@ -1059,7 +1052,6 @@ class LoweredAssignExp final : public AssignExp
public:
Expression *lowering;
- const char *toChars() const override;
void accept(Visitor *v) override { v->visit(this); }
};