va_end (argp);
}
-/* Print a hard error message with explicit location LOC with an optional
- message prefix PREFIX1 and PREFIX2, increasing the global or gagged
- error count. */
+/* Print a diagnostic message of type KIND with explicit location LOC with an
+ optional message prefix PREFIX1 and PREFIX2, increasing the global or gagged
+ error count depending on how KIND is treated. */
-void ATTRIBUTE_GCC_DIAG(2,0)
-verror (const Loc &loc, const char *format, va_list ap,
- const char *prefix1, const char *prefix2, const char *)
+void D_ATTRIBUTE_FORMAT(2,0) ATTRIBUTE_GCC_DIAG(2,0)
+verrorReport (const Loc& loc, const char *format, va_list ap, ErrorKind kind,
+ const char *prefix1 = NULL, const char *prefix2 = NULL)
{
- if (!global.gag || global.params.showGaggedErrors)
- {
- char *xformat;
-
- /* Build string and emit. */
- if (prefix2 != NULL)
- xformat = xasprintf ("%s %s %s", escape_d_format (prefix1),
- escape_d_format (prefix2), format);
- else if (prefix1 != NULL)
- xformat = xasprintf ("%s %s", escape_d_format (prefix1), format);
- else
- xformat = xasprintf ("%s", format);
-
- d_diagnostic_report_diagnostic (loc, 0, xformat, ap,
- global.gag ? DK_ANACHRONISM : DK_ERROR,
- false);
- free (xformat);
- }
-
- if (global.gag)
- global.gaggedErrors++;
+ diagnostic_t diag_kind = DK_UNSPECIFIED;
+ int opt = 0;
+ bool verbatim = false;
+ char *xformat;
- global.errors++;
-}
-
-/* Print supplementary message about the last error with explicit location LOC.
- This doesn't increase the global error count. */
+ if (kind == ErrorKind::error)
+ {
+ global.errors++;
+ if (global.gag)
+ global.gaggedErrors++;
-void ATTRIBUTE_GCC_DIAG(2,0)
-verrorSupplemental (const Loc &loc, const char *format, va_list ap)
-{
- if (global.gag && !global.params.showGaggedErrors)
- return;
+ if (global.gag && !global.params.showGaggedErrors)
+ return;
- d_diagnostic_report_diagnostic (loc, 0, format, ap, DK_NOTE, false);
-}
+ diag_kind = global.gag ? DK_ANACHRONISM : DK_ERROR;
+ }
+ else if (kind == ErrorKind::warning)
+ {
+ if (global.gag || global.params.warnings == DIAGNOSTICoff)
+ {
+ if (global.gag)
+ global.gaggedWarnings++;
-/* Print a warning message with explicit location LOC, increasing the
- global warning count. */
+ return;
+ }
-void ATTRIBUTE_GCC_DIAG(2,0)
-vwarning (const Loc &loc, const char *format, va_list ap)
-{
- if (!global.gag && global.params.warnings != DIAGNOSTICoff)
- {
/* Warnings don't count if not treated as errors. */
if (global.params.warnings == DIAGNOSTICerror)
global.warnings++;
- d_diagnostic_report_diagnostic (loc, 0, format, ap, DK_WARNING, false);
+ diag_kind = DK_WARNING;
}
- else if (global.gag)
- global.gaggedWarnings++;
-}
-
-/* Print supplementary message about the last warning with explicit location
- LOC. This doesn't increase the global warning count. */
-
-void ATTRIBUTE_GCC_DIAG(2,0)
-vwarningSupplemental (const Loc &loc, const char *format, va_list ap)
-{
- if (global.params.warnings == DIAGNOSTICoff || global.gag)
- return;
-
- d_diagnostic_report_diagnostic (loc, 0, format, ap, DK_NOTE, false);
-}
+ else if (kind == ErrorKind::deprecation)
+ {
+ if (global.params.useDeprecated == DIAGNOSTICerror)
+ return verrorReport (loc, format, ap, ErrorKind::error, prefix1,
+ prefix2);
+ else if (global.gag || global.params.useDeprecated != DIAGNOSTICinform)
+ {
+ if (global.gag)
+ global.gaggedWarnings++;
-/* Print a deprecation message with explicit location LOC with an optional
- message prefix PREFIX1 and PREFIX2, increasing the global warning or
- error count depending on how deprecations are treated. */
+ return;
+ }
-void ATTRIBUTE_GCC_DIAG(2,0)
-vdeprecation (const Loc &loc, const char *format, va_list ap,
- const char *prefix1, const char *prefix2)
-{
- if (global.params.useDeprecated == DIAGNOSTICerror)
- verror (loc, format, ap, prefix1, prefix2);
- else if (global.params.useDeprecated == DIAGNOSTICinform && !global.gag)
+ opt = OPT_Wdeprecated;
+ diag_kind = DK_WARNING;
+ }
+ else if (kind == ErrorKind::message)
{
- char *xformat;
-
- /* Build string and emit. */
- if (prefix2 != NULL)
- xformat = xasprintf ("%s %s %s", escape_d_format (prefix1),
- escape_d_format (prefix2), format);
- else if (prefix1 != NULL)
- xformat = xasprintf ("%s %s", escape_d_format (prefix1), format);
- else
- xformat = xasprintf ("%s", format);
-
- d_diagnostic_report_diagnostic (loc, OPT_Wdeprecated, xformat, ap,
- DK_WARNING, false);
- free (xformat);
+ diag_kind = DK_NOTE;
+ verbatim = true;
}
- else if (global.gag)
- global.gaggedWarnings++;
-}
-
-/* Print supplementary message about the last deprecation with explicit
- location LOC. This does not increase the global error count. */
+ else if (kind == ErrorKind::tip)
+ {
+ diag_kind = DK_DEBUG;
+ verbatim = true;
+ }
+ else
+ gcc_unreachable ();
+
+ /* Build string and emit. */
+ if (prefix2 != NULL)
+ xformat = xasprintf ("%s %s %s", escape_d_format (prefix1),
+ escape_d_format (prefix2), format);
+ else if (prefix1 != NULL)
+ xformat = xasprintf ("%s %s", escape_d_format (prefix1), format);
+ else
+ xformat = xasprintf ("%s", format);
-void ATTRIBUTE_GCC_DIAG(2,0)
-vdeprecationSupplemental (const Loc &loc, const char *format, va_list ap)
-{
- if (global.params.useDeprecated == DIAGNOSTICerror)
- verrorSupplemental (loc, format, ap);
- else if (global.params.useDeprecated == DIAGNOSTICinform && !global.gag)
- d_diagnostic_report_diagnostic (loc, 0, format, ap, DK_NOTE, false);
+ d_diagnostic_report_diagnostic (loc, opt, xformat, ap, diag_kind, verbatim);
+ free (xformat);
}
-/* Print a verbose message with explicit location LOC. */
+/* Print supplementary message about the last diagnostic of type KIND, with
+ explicit location LOC. This doesn't increase the global error count. */
-void ATTRIBUTE_GCC_DIAG(2,0)
-vmessage (const Loc &loc, const char *format, va_list ap)
+void D_ATTRIBUTE_FORMAT(2,0) ATTRIBUTE_GCC_DIAG(2,0)
+verrorReportSupplemental (const Loc& loc, const char* format, va_list ap,
+ ErrorKind kind)
{
- d_diagnostic_report_diagnostic (loc, 0, format, ap, DK_NOTE, true);
-}
-
-/* Print a tip message with prefix and highlighing. */
+ if (kind == ErrorKind::error)
+ {
+ if (global.gag && !global.params.showGaggedErrors)
+ return;
+ }
+ else if (kind == ErrorKind::warning)
+ {
+ if (global.params.warnings == DIAGNOSTICoff || global.gag)
+ return;
+ }
+ else if (kind == ErrorKind::deprecation)
+ {
+ if (global.params.useDeprecated == DIAGNOSTICerror)
+ return verrorReportSupplemental (loc, format, ap, ErrorKind::error);
+ else if (global.params.useDeprecated != DIAGNOSTICinform || global.gag)
+ return;
+ }
+ else
+ gcc_unreachable ();
-void ATTRIBUTE_GCC_DIAG(1,0)
-vtip (const char *format, va_list ap)
-{
- if (!global.gag)
- d_diagnostic_report_diagnostic (Loc (), 0, format, ap, DK_DEBUG, true);
+ d_diagnostic_report_diagnostic (loc, 0, format, ap, DK_NOTE, false);
}
/* Call this after printing out fatal error messages to clean up and
if (m->filetype == FileType::ddoc)
{
- gendocfile (m);
+ gendocfile (m, global.errorSink);
/* Remove M from list of modules. */
modules.remove (i);
i--;
/* Declare the name of the root module as the first global name in order
to make the middle-end fully deterministic. */
OutBuffer buf;
- mangleToBuffer (Module::rootModule, &buf);
+ mangleToBuffer (Module::rootModule, buf);
first_global_object_name = buf.extractChars ();
}
for (size_t i = 0; i < modules.length; i++)
{
Module *m = modules[i];
- gendocfile (m);
+ gendocfile (m, global.errorSink);
}
}
else
{
OutBuffer buf;
- mangleToBuffer (decl, &buf);
+ mangleToBuffer (decl, buf);
return buf.extractChars ();
}
}
-26f049fb26e755096dea3f1474decea7c0fef187
+4574d1728d1f7e52ff40e6733b8c39889d128349
The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository.
| File | Purpose |
|-----------------------------------------------------------------------------|-----------------------------------------------------------------------|
-| [mars.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/mars.d) | The entry point. Contains `main`. |
+| [main.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/main.d) | The entry point. Contains `main`. |
+| [mars.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/mars.d) | Argument parsing, path manipulation. |
| [cli.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/cli.d) | Define the command line interface |
| [dmdparams.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/dmdparams.d) | DMD-specific parameters |
| [globals.d](https://github.com/dlang/dmd/blob/master/compiler/src/dmd/globals.d) | Define a structure storing command line options |
-v2.105.0-beta.1
+v2.105.0
import dmd.dstruct;
import dmd.dsymbol;
import dmd.expression;
-import dmd.globals;
import dmd.location;
import dmd.tokens;
* Returns:
* 0-terminated string for `c`
*/
-const(char)* toChars(ClassKind c)
+const(char)* toChars(ClassKind c) @safe
{
final switch (c)
{
import dmd.identifier;
import dmd.location;
import dmd.mtype;
-import dmd.opover;
import dmd.tokens;
import dmd.visitor;
/// Whether this `alias this` is deprecated or not
bool isDeprecated_;
- extern (D) this(const ref Loc loc, Identifier ident)
+ extern (D) this(const ref Loc loc, Identifier ident) @safe
{
super(loc, null); // it's anonymous (no identifier)
this.ident = ident;
import dmd.expression;
import dmd.expressionsem;
import dmd.func;
-import dmd.globals;
import dmd.hdrgen;
import dmd.id;
import dmd.identifier;
import dmd.location;
import dmd.mtype;
import dmd.common.outbuffer;
-import dmd.statement;
import dmd.tokens;
import dmd.visitor;
Expressions* args;
public:
- extern (D) this(Scope* sc, Objects* tiargs) scope
+ extern (D) this(Scope* sc, Objects* tiargs) scope @safe
{
this.sc = sc;
this.tiargs = tiargs;
/***********************************************
* Test if expression is a unary array op.
*/
-bool isUnaArrayOp(EXP op)
+bool isUnaArrayOp(EXP op) @safe
{
switch (op)
{
/***********************************************
* Test if expression is a binary array op.
*/
-bool isBinArrayOp(EXP op)
+bool isBinArrayOp(EXP op) @safe
{
switch (op)
{
/***********************************************
* Test if expression is a binary assignment array op.
*/
-bool isBinAssignArrayOp(EXP op)
+bool isBinAssignArrayOp(EXP op) @safe
{
switch (op)
{
import dmd.objc; // for objc.addSymbols
import dmd.common.outbuffer;
import dmd.root.array; // for each
-import dmd.tokens;
import dmd.visitor;
/***********************************************************
{
Dsymbols* decl; /// Dsymbol's affected by this AttribDeclaration
- extern (D) this(Dsymbols* decl)
+ extern (D) this(Dsymbols* decl) @safe
{
this.decl = decl;
}
- extern (D) this(const ref Loc loc, Dsymbols* decl)
+ extern (D) this(const ref Loc loc, Dsymbols* decl) @safe
{
super(loc, null);
this.decl = decl;
}
- extern (D) this(const ref Loc loc, Identifier ident, Dsymbols* decl)
+ extern (D) this(const ref Loc loc, Identifier ident, Dsymbols* decl) @safe
{
super(loc, ident);
this.decl = decl;
{
StorageClass stc;
- extern (D) this(StorageClass stc, Dsymbols* decl)
+ extern (D) this(StorageClass stc, Dsymbols* decl) @safe
{
super(decl);
this.stc = stc;
}
- extern (D) this(const ref Loc loc, StorageClass stc, Dsymbols* decl)
+ extern (D) this(const ref Loc loc, StorageClass stc, Dsymbols* decl) @safe
{
super(loc, decl);
this.stc = stc;
Expression msg; /// deprecation message
const(char)* msgstr; /// cached string representation of msg
- extern (D) this(Expression msg, Dsymbols* decl)
+ extern (D) this(Expression msg, Dsymbols* decl) @safe
{
super(STC.deprecated_, decl);
this.msg = msg;
{
LINK linkage; /// either explicitly set or `default_`
- extern (D) this(const ref Loc loc, LINK linkage, Dsymbols* decl)
+ extern (D) this(const ref Loc loc, LINK linkage, Dsymbols* decl) @safe
{
super(loc, null, decl);
//printf("LinkDeclaration(linkage = %d, decl = %p)\n", linkage, decl);
this.linkage = linkage;
}
- static LinkDeclaration create(const ref Loc loc, LINK p, Dsymbols* decl)
+ static LinkDeclaration create(const ref Loc loc, LINK p, Dsymbols* decl) @safe
{
return new LinkDeclaration(loc, p, decl);
}
{
CPPMANGLE cppmangle;
- extern (D) this(const ref Loc loc, CPPMANGLE cppmangle, Dsymbols* decl)
+ extern (D) this(const ref Loc loc, CPPMANGLE cppmangle, Dsymbols* decl) @safe
{
super(loc, null, decl);
//printf("CPPMangleDeclaration(cppmangle = %d, decl = %p)\n", cppmangle, decl);
/// CTFE-able expression, resolving to `TupleExp` or `StringExp`
Expression exp;
- extern (D) this(const ref Loc loc, Identifier ident, Dsymbols* decl)
+ extern (D) this(const ref Loc loc, Identifier ident, Dsymbols* decl) @safe
{
super(loc, ident, decl);
}
- extern (D) this(const ref Loc loc, Expression exp, Dsymbols* decl)
+ extern (D) this(const ref Loc loc, Expression exp, Dsymbols* decl) @safe
{
super(loc, null, decl);
this.exp = exp;
}
extern (D) this(const ref Loc loc, Identifier ident, Expression exp, Dsymbols* decl,
- CPPNamespaceDeclaration parent)
+ CPPNamespaceDeclaration parent) @safe
{
super(loc, ident, decl);
this.exp = exp;
* visibility = visibility attribute data
* decl = declarations which are affected by this visibility attribute
*/
- extern (D) this(const ref Loc loc, Visibility visibility, Dsymbols* decl)
+ extern (D) this(const ref Loc loc, Visibility visibility, Dsymbols* decl) @safe
{
super(loc, null, decl);
this.visibility = visibility;
}
}
- extern (D) this(const ref Loc loc, Expressions* exps, Dsymbols* decl)
+ extern (D) this(const ref Loc loc, Expressions* exps, Dsymbols* decl) @safe
{
super(loc, null, decl);
this.exps = exps;
}
- extern (D) this(const ref Loc loc, structalign_t salign, Dsymbols* decl)
+ extern (D) this(const ref Loc loc, structalign_t salign, Dsymbols* decl) @safe
{
super(loc, null, decl);
this.salign = salign;
uint anonstructsize; /// size of anonymous struct
uint anonalignsize; /// size of anonymous struct for alignment purposes
- extern (D) this(const ref Loc loc, bool isunion, Dsymbols* decl)
+ extern (D) this(const ref Loc loc, bool isunion, Dsymbols* decl) @safe
{
super(loc, null, decl);
this.isunion = isunion;
{
Expressions* args; /// parameters of this pragma
- extern (D) this(const ref Loc loc, Identifier ident, Expressions* args, Dsymbols* decl)
+ extern (D) this(const ref Loc loc, Identifier ident, Expressions* args, Dsymbols* decl) @safe
{
super(loc, ident, decl);
this.args = args;
Condition condition; /// condition deciding whether decl or elsedecl applies
Dsymbols* elsedecl; /// array of Dsymbol's for else block
- extern (D) this(const ref Loc loc, Condition condition, Dsymbols* decl, Dsymbols* elsedecl)
+ extern (D) this(const ref Loc loc, Condition condition, Dsymbols* decl, Dsymbols* elsedecl) @safe
{
super(loc, null, decl);
//printf("ConditionalDeclaration::ConditionalDeclaration()\n");
private bool addisdone = false; /// true if members have been added to scope
private bool onStack = false; /// true if a call to `include` is currently active
- extern (D) this(const ref Loc loc, Condition condition, Dsymbols* decl, Dsymbols* elsedecl)
+ extern (D) this(const ref Loc loc, Condition condition, Dsymbols* decl, Dsymbols* elsedecl) @safe
{
super(loc, condition, decl, elsedecl);
//printf("StaticIfDeclaration::StaticIfDeclaration()\n");
bool cached = false;
Dsymbols* cache = null;
- extern (D) this(StaticForeach sfe, Dsymbols* decl)
+ extern (D) this(StaticForeach sfe, Dsymbols* decl) @safe
{
super(sfe.loc, null, decl);
this.sfe = sfe;
{
ForwardingScopeDsymbol sym = null;
- this(Dsymbols* decl)
+ this(Dsymbols* decl) @safe
{
super(decl);
sym = new ForwardingScopeDsymbol();
ScopeDsymbol scopesym;
bool compiled;
- extern (D) this(const ref Loc loc, Expressions* exps)
+ extern (D) this(const ref Loc loc, Expressions* exps) @safe
{
super(loc, null, null);
//printf("MixinDeclaration(loc = %d)\n", loc.linnum);
{
Expressions* atts;
- extern (D) this(Expressions* atts, Dsymbols* decl)
+ extern (D) this(Expressions* atts, Dsymbols* decl) @safe
{
super(decl);
this.atts = atts;
import dmd.mtype;
import dmd.statement;
import dmd.tokens;
-import dmd.visitor;
/**
* BE stands for BlockExit.
import dmd.init;
import dmd.mtype;
import dmd.postordervisitor;
-import dmd.root.rootobject;
import dmd.tokens;
import dmd.visitor;
CT result;
public:
- extern (D) this(FuncDeclaration func, bool mustNotThrow) scope
+ extern (D) this(FuncDeclaration func, bool mustNotThrow) scope @safe
{
this.func = func;
this.mustNotThrow = mustNotThrow;
nothrow:
+version (Windows)
+{
+ import core.sys.windows.winnls : CP_ACP;
+
+ // assume filenames encoded in system default Windows ANSI code page
+ enum CodePage = CP_ACP;
+}
+
/**
Encapsulated management of a memory-mapped file.
/**
Construct given size.
*/
- this(size_t initialSize) nothrow
+ this(size_t initialSize) nothrow @safe
{
reserve(initialSize);
}
* Returns:
* slice of the allocated space to be filled in
*/
- extern (D) char[] allocate(size_t nbytes) pure nothrow
+ extern (D) char[] allocate(size_t nbytes) pure nothrow @safe
{
reserve(nbytes);
offset += nbytes;
return cast(char*)data.ptr;
}
+ // Peek at slice of data without taking ownership
+ extern (D) ubyte[] peekSlice() pure nothrow
+ {
+ return data[0 .. offset];
+ }
+
// Append terminating null if necessary and take ownership of data
- extern (C++) char* extractChars() pure nothrow
+ extern (C++) char* extractChars() pure nothrow @safe
{
if (!offset || data[offset - 1] != '\0')
writeByte(0);
*/
version(Windows) wchar[] toWStringz(const(char)[] narrow, ref SmallBuffer!wchar buffer) nothrow
{
- import core.sys.windows.winnls : CP_ACP, MultiByteToWideChar;
- // assume filenames encoded in system default Windows ANSI code page
- enum CodePage = CP_ACP;
+ import core.sys.windows.winnls : MultiByteToWideChar;
+ import dmd.common.file : CodePage;
if (narrow is null)
return null;
return DYNCAST.condition;
}
- extern (D) this(const ref Loc loc)
+ extern (D) this(const ref Loc loc) @safe
{
this.loc = loc;
}
*/
bool needExpansion = false;
- extern (D) this(const ref Loc loc, ForeachStatement aggrfe, ForeachRangeStatement rangefe)
+ extern (D) this(const ref Loc loc, ForeachStatement aggrfe, ForeachRangeStatement rangefe) @safe
{
assert(!!aggrfe ^ !!rangefe);
* An AST for the expression `Tuple(e)`.
*/
- private extern(D) Expression createTuple(const ref Loc loc, TypeStruct type, Expressions* e)
+ private extern(D) Expression createTuple(const ref Loc loc, TypeStruct type, Expressions* e) @safe
{ // TODO: move to druntime?
return new CallExp(loc, new TypeExp(loc, type), e);
}
Identifier ident;
Module mod;
- extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident)
+ extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident) @safe
{
super(loc);
this.mod = mod;
* If `null`, this conditiion will use an integer level.
* loc = Location in the source file
*/
- extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident)
+ extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident) @safe
{
super(loc, mod, level, ident);
}
* Returns:
* `true` if it is reserved, `false` otherwise
*/
- extern(D) private static bool isReserved(const(char)[] ident)
+ extern(D) private static bool isReserved(const(char)[] ident) @safe
{
// This list doesn't include "D_*" versions, see the last return
switch (ident)
* If `null`, this conditiion will use an integer level.
* loc = Location in the source file
*/
- extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident)
+ extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident) @safe
{
super(loc, mod, level, ident);
}
{
Expression exp;
- extern (D) this(const ref Loc loc, Expression exp)
+ extern (D) this(const ref Loc loc, Expression exp) @safe
{
super(loc);
this.exp = exp;
* Returns:
* true if e is a constant
*/
-int isConst(Expression e)
+int isConst(Expression e) @safe
{
//printf("Expression::isConst(): %s\n", e.toChars());
switch (e.op)
/* Check whether slice `[newlwr .. newupr]` is in the range `[lwr .. upr]`
*/
-bool sliceBoundsCheck(uinteger_t lwr, uinteger_t upr, uinteger_t newlwr, uinteger_t newupr) pure
+bool sliceBoundsCheck(uinteger_t lwr, uinteger_t upr, uinteger_t newlwr, uinteger_t newupr) pure @safe
{
assert(lwr <= upr);
return !(newlwr <= newupr &&
* Returns:
* The previous state of this `Context` object
*/
- private Context push(lazy RootObject next)
+ private Context push(lazy RootObject next) @safe
{
auto r = this.res;
if (r !is null)
/**
* Reset the context to a previous one, making any adjustment necessary
*/
- private void pop(ref Context prev)
+ private void pop(ref Context prev) @safe
{
this.res = prev.res;
}
* See-Also:
* https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangle.seq-id
*/
- private void writeSequenceFromIndex(size_t idx)
+ private void writeSequenceFromIndex(size_t idx) @safe
{
if (idx)
{
* or `params.length` if there wasn't any match.
*/
private static size_t templateParamIndex(
- const ref Identifier ident, TemplateParameters* params)
+ const ref Identifier ident, TemplateParameters* params) @safe
{
foreach (idx, param; *params)
if (param.ident == ident)
}
/// Helper function to safely get a type out of a `RootObject`
-private Type asType(RootObject o)
+private Type asType(RootObject o) @safe
{
if (Type ta = isType(o))
return ta;
}
/// Helper function to safely get a `FuncDeclaration` out of a `RootObject`
-private FuncDeclaration asFuncDecl(RootObject o)
+private FuncDeclaration asFuncDecl(RootObject o) @safe
{
Dsymbol d = isDsymbol(o);
assert(d !is null);
/// Set to the result of the comparison
private bool result;
- public this(RootObject base)
+ public this(RootObject base) @safe
{
switch (base.dyncast())
{
/// Returns:
/// Whether two `CPPNamespaceDeclaration` are equals
-private bool isNamespaceEqual (CPPNamespaceDeclaration a, CPPNamespaceDeclaration b)
+private bool isNamespaceEqual (CPPNamespaceDeclaration a, CPPNamespaceDeclaration b) @safe
{
if (a is null || b is null)
return false;
private const(Array!StringExp)* ignore;
///
- public this(const(Array!StringExp)* previous, Array!StringExp* toWrite)
+ public this(const(Array!StringExp)* previous, Array!StringExp* toWrite) @safe
{
this.ignore = previous;
this.toWrite = toWrite;
{
StructLiteralExp value;
- extern (D) this(const ref Loc loc, StructLiteralExp lit, Type type)
+ extern (D) this(const ref Loc loc, StructLiteralExp lit, Type type) @safe
{
super(loc, EXP.classReference);
assert(lit && lit.sd && lit.sd.isClassDeclaration());
* Returns:
* index of the field, or -1 if not found
*/
-int findFieldIndexByName(const StructDeclaration sd, const VarDeclaration v) pure
+int findFieldIndexByName(const StructDeclaration sd, const VarDeclaration v) pure @safe
{
foreach (i, field; sd.fields)
{
{
ClassReferenceExp thrown; // the thing being tossed
- extern (D) this(const ref Loc loc, ClassReferenceExp victim)
+ extern (D) this(const ref Loc loc, ClassReferenceExp victim) @safe
{
super(loc, EXP.thrownException);
this.thrown = victim;
*/
extern (D) __gshared CTFEExp showcontext;
- extern (D) static bool isCantExp(const Expression e)
+ extern (D) static bool isCantExp(const Expression e) @safe
{
return e && e.op == EXP.cantExpression;
}
- extern (D) static bool isGotoExp(const Expression e)
+ extern (D) static bool isGotoExp(const Expression e) @safe
{
return e && e.op == EXP.goto_;
}
}
// True if 'e' is CTFEExp::cantexp, or an exception
-bool exceptionOrCantInterpret(const Expression e)
+bool exceptionOrCantInterpret(const Expression e) @safe
{
return e && (e.op == EXP.cantExpression || e.op == EXP.thrownException || e.op == EXP.showCtfeContext);
}
}
/// Returns cmp OP 0; where OP is ==, !=, <, >=, etc. Result is 0 or 1
-bool specificCmp(EXP op, int rawCmp)
+bool specificCmp(EXP op, int rawCmp) @safe
{
return numCmp!int(op, rawCmp, 0);
}
/// Returns e1 OP e2; where OP is ==, !=, <, >=, etc. Result is 0 or 1
-bool intUnsignedCmp(EXP op, dinteger_t n1, dinteger_t n2)
+bool intUnsignedCmp(EXP op, dinteger_t n1, dinteger_t n2) @safe
{
return numCmp!dinteger_t(op, n1, n2);
}
/// Returns e1 OP e2; where OP is ==, !=, <, >=, etc. Result is 0 or 1
-bool intSignedCmp(EXP op, sinteger_t n1, sinteger_t n2)
+bool intSignedCmp(EXP op, sinteger_t n1, sinteger_t n2) @safe
{
return numCmp!sinteger_t(op, n1, n2);
}
/// Returns e1 OP e2; where OP is ==, !=, <, >=, etc. Result is 0 or 1
-bool realCmp(EXP op, real_t r1, real_t r2)
+bool realCmp(EXP op, real_t r1, real_t r2) @safe
{
// Don't rely on compiler, handle NAN arguments separately
if (CTFloat.isNaN(r1) || CTFloat.isNaN(r2)) // if unordered
/* Given a delegate expression e, return .funcptr.
* If e is NullExp, return NULL.
*/
-private FuncDeclaration funcptrOf(Expression e)
+private FuncDeclaration funcptrOf(Expression e) @safe
{
assert(e.type.ty == Tdelegate);
if (auto de = e.isDelegateExp())
return null;
}
-private bool isArray(const Expression e)
+private bool isArray(const Expression e) @safe
{
return e.op == EXP.arrayLiteral || e.op == EXP.string_ || e.op == EXP.slice || e.op == EXP.null_;
}
* Params:
* csx = bits to set
*/
- void orCSX(CSX csx) nothrow pure
+ void orCSX(CSX csx) nothrow pure @safe
{
callSuper |= csx;
foreach (ref u; fieldinit)
* Params:
* ctorflow = bits to OR in
*/
- void OR(const ref CtorFlow ctorflow) pure nothrow
+ void OR(const ref CtorFlow ctorflow) pure nothrow @safe
{
callSuper |= ctorflow.callSuper;
if (fieldinit.length && ctorflow.fieldinit.length)
* Returns:
* false means one of the paths skips construction
*/
-bool mergeCallSuper(ref CSX a, const CSX b) pure nothrow
+bool mergeCallSuper(ref CSX a, const CSX b) pure nothrow @safe
{
// This does a primitive flow analysis to support the restrictions
// regarding when and how constructors can appear.
* Returns:
* false means either `a` or `b` skips initialization
*/
-bool mergeFieldInit(ref CSX a, const CSX b) pure nothrow
+bool mergeFieldInit(ref CSX a, const CSX b) pure nothrow @safe
{
if (b == a)
return true;
* Returns:
* true if the `bc` implements `id`, false otherwise
**/
-private bool baseClassImplementsInterface(InterfaceDeclaration id, BaseClass* bc, int* poffset) pure nothrow @nogc
+private bool baseClassImplementsInterface(InterfaceDeclaration id, BaseClass* bc, int* poffset) pure nothrow @nogc @safe
{
//printf("%s.InterfaceDeclaration.isBaseOf(bc = '%s')\n", id.toChars(), bc.sym.toChars());
for (size_t j = 0; j < bc.baseInterfaces.length; j++)
MODtoChars(var.type.mod), var.kind(), var.toChars());
errorSupplemental(loc, "Use `shared static this` instead.");
}
+ else if (fd.isStaticCtorDeclaration() && !fd.isSharedStaticCtorDeclaration() &&
+ var.type.isConst())
+ {
+ // @@@DEPRECATED_2.116@@@
+ // Turn this into an error, merging with the branch above
+ .deprecation(loc, "%s %s `%s` initialization is not allowed in `static this`",
+ MODtoChars(var.type.mod), var.kind(), var.toChars());
+ deprecationSupplemental(loc, "Use `shared static this` instead.");
+ }
return result;
}
else
// overridden symbol with pragma(mangle, "...")
const(char)[] mangleOverride;
- final extern (D) this(Identifier ident)
+ final extern (D) this(Identifier ident) @safe
{
super(ident);
visibility = Visibility(Visibility.Kind.undefined);
}
- final extern (D) this(const ref Loc loc, Identifier ident)
+ final extern (D) this(const ref Loc loc, Identifier ident) @safe
{
super(loc, ident);
visibility = Visibility(Visibility.Kind.undefined);
bool isexp; // true: expression tuple
bool building; // it's growing in AliasAssign semantic
- extern (D) this(const ref Loc loc, Identifier ident, Objects* objects)
+ extern (D) this(const ref Loc loc, Identifier ident, Objects* objects) @safe
{
super(loc, ident);
this.objects = objects;
for (size_t i = 0; i < objects.length; i++)
{
RootObject o = (*objects)[i];
- if (o.dyncast() != DYNCAST.type)
+ if (!o.isType())
{
//printf("\tnot[%d], %p, %d\n", i, o, o.dyncast());
return null;
Dsymbol overnext; // next in overload list
Dsymbol _import; // !=null if unresolved internal alias for selective import
- extern (D) this(const ref Loc loc, Identifier ident, Type type)
+ extern (D) this(const ref Loc loc, Identifier ident, Type type) @safe
{
super(loc, ident);
//printf("AliasDeclaration(id = '%s', type = %p)\n", ident.toChars(), type);
assert(type);
}
- extern (D) this(const ref Loc loc, Identifier ident, Dsymbol s)
+ extern (D) this(const ref Loc loc, Identifier ident, Dsymbol s) @safe
{
super(loc, ident);
//printf("AliasDeclaration(id = '%s', s = %p)\n", ident.toChars(), s);
assert(s);
}
- static AliasDeclaration create(const ref Loc loc, Identifier id, Type type)
+ static AliasDeclaration create(const ref Loc loc, Identifier id, Type type) @safe
{
return new AliasDeclaration(loc, id, type);
}
Dsymbol overnext; // next in overload list
Dsymbol aliassym;
- extern (D) this(Identifier ident, Dsymbol s)
+ extern (D) this(Identifier ident, Dsymbol s) @safe
{
super(ident);
this.aliassym = s;
bool inClosure; /// is inserted into a GC allocated closure
bool inAlignSection; /// is inserted into an aligned section on stack
}
+ bool systemInferred; /// @system was inferred from initializer
}
import dmd.common.bitfields : generateBitFields;
- mixin(generateBitFields!(BitFields, ushort));
+ mixin(generateBitFields!(BitFields, uint));
byte canassign; // it can be assigned to
ubyte isdataseg; // private data for isDataseg 0 unset, 1 true, 2 false
{
AggregateDeclaration dsym;
- extern (D) this(const ref Loc loc, AggregateDeclaration dsym)
+ extern (D) this(const ref Loc loc, AggregateDeclaration dsym) @safe
{
super(loc, dsym.ident);
this.dsym = dsym;
// The index of this variable on the CTFE stack, ~0u if not allocated
unsigned ctfeAdrOnStack;
private:
- uint16_t bitFields;
+ uint32_t bitFields;
public:
int8_t canassign; // // it can be assigned to
uint8_t isdataseg; // private data for isDataseg
bool inAlignSection() const; // is inserted into aligned section on stack
bool inAlignSection(bool v);
#endif
+ bool systemInferred() const;
+ bool systemInferred(bool v);
static VarDeclaration *create(const Loc &loc, Type *t, Identifier *id, Initializer *init, StorageClass storage_class = STCundefined);
VarDeclaration *syntaxCopy(Dsymbol *) override;
void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion) override final;
}
public:
- extern (D) this(FuncDeclaration fd) scope
+ extern (D) this(FuncDeclaration fd) scope @safe
{
this.fd = fd;
}
Scope* sc;
bool result;
- extern (D) this(Scope* sc) scope
+ extern (D) this(Scope* sc) scope @safe
{
this.sc = sc;
}
Expression localThis; // value of 'this', or NULL if none
public:
- size_t stackPointer()
+ size_t stackPointer() @safe
{
return values.length;
}
// The current value of 'this', or NULL if none
- Expression getThis()
+ Expression getThis() @safe
{
return localThis;
}
// Largest number of stack positions we've used
- size_t maxStackUsage()
+ size_t maxStackUsage() @safe
{
return maxStackPointer;
}
Expression result;
UnionExp* pue; // storage for `result`
- extern (D) this(UnionExp* pue, InterState* istate, CTFEGoal goal) scope
+ extern (D) this(UnionExp* pue, InterState* istate, CTFEGoal goal) scope @safe
{
this.pue = pue;
this.istate = istate;
*/
// Returns the variable which is eventually modified, or NULL if an rvalue.
// thisval is the current value of 'this'.
- static VarDeclaration findParentVar(Expression e)
+ static VarDeclaration findParentVar(Expression e) @safe
{
for (;;)
{
result = interpret(&ue, e.msg, istate);
if (exceptionOrCant(result))
return;
- e.error("`%s`", result.toChars());
+ if (StringExp se = result.isStringExp())
+ e.error("%s", se.toStringz().ptr);
+ else
+ e.error("%s", result.toChars());
}
else
e.error("`%s` failed", e.toChars());
// Get the Hook from the second template parameter
TemplateInstance templateInstance = fd.parent.isTemplateInstance;
RootObject hook = (*templateInstance.tiargs)[1];
- assert(hook.dyncast() == DYNCAST.dsymbol, "Expected _d_HookTraceImpl's second template parameter to be an alias to the hook!");
+ assert(hook.isDsymbol(), "Expected _d_HookTraceImpl's second template parameter to be an alias to the hook!");
fd = (cast(Dsymbol)hook).isFuncDeclaration;
// Remove the first three trace parameters
{
OutBuffer buf;
auto backref = Backref(null);
- scope Mangler v = new Mangler(&buf, &backref);
+ scope Mangler v = new Mangler(buf, &backref);
v.mangleExact(fd);
fd.mangleString = buf.extractChars();
}
return fd.mangleString;
}
-extern (C++) void mangleToBuffer(Type t, OutBuffer* buf)
+extern (C++) void mangleToBuffer(Type t, ref OutBuffer buf)
{
//printf("mangleToBuffer t()\n");
if (t.deco)
}
}
-extern (C++) void mangleToBuffer(Expression e, OutBuffer* buf)
+extern (C++) void mangleToBuffer(Expression e, ref OutBuffer buf)
{
//printf("mangleToBuffer e()\n");
auto backref = Backref(null);
e.accept(v);
}
-extern (C++) void mangleToBuffer(Dsymbol s, OutBuffer* buf)
+extern (C++) void mangleToBuffer(Dsymbol s, ref OutBuffer buf)
{
//printf("mangleToBuffer s(%s)\n", s.toChars());
auto backref = Backref(null);
s.accept(v);
}
-extern (C++) void mangleToBuffer(TemplateInstance ti, OutBuffer* buf)
+extern (C++) void mangleToBuffer(TemplateInstance ti, ref OutBuffer buf)
{
//printf("mangleToBuffer ti()\n");
auto backref = Backref(null);
* buf = buffer to append mangling to
* backref = state of back references (updated)
*/
-void mangleType(Type t, ubyte modMask, OutBuffer* buf, ref Backref backref)
+void mangleType(Type t, ubyte modMask, ref OutBuffer buf, ref Backref backref)
{
void visitWithMask(Type t, ubyte modMask)
{
/*************************************************************
*/
-void mangleFuncType(TypeFunction t, TypeFunction ta, ubyte modMask, Type tret, OutBuffer* buf, ref Backref backref)
+void mangleFuncType(TypeFunction t, TypeFunction ta, ubyte modMask, Type tret, ref OutBuffer buf, ref Backref backref)
{
//printf("mangleFuncType() %s\n", t.toChars());
if (t.inuse && tret)
/*************************************************************
*/
-void mangleParameter(Parameter p, OutBuffer* buf, ref Backref backref)
+void mangleParameter(Parameter p, ref OutBuffer buf, ref Backref backref)
{
// https://dlang.org/spec/abi.html#Parameter
OutBuffer* buf;
Backref* backref;
- extern (D) this(OutBuffer* buf, Backref* backref)
+ extern (D) this(ref OutBuffer buf, Backref* backref) @trusted
{
- this.buf = buf;
+ this.buf = &buf;
this.backref = backref;
}
void mangleIdentifier(Identifier id, Dsymbol s)
{
- if (!backref.addRefToIdentifier(buf, id))
- toBuffer(buf, id.toString(), s);
+ if (!backref.addRefToIdentifier(*buf, id))
+ toBuffer(*buf, id.toString(), s);
}
////////////////////////////////////////////////////////////////////////////
}
else if (sthis.type)
{
- mangleType(sthis.type, 0, buf, *backref);
+ mangleType(sthis.type, 0, *buf, *backref);
}
else
assert(0);
buf.writeByte('0');
if (localNum)
- writeLocalParent(buf, localNum);
+ writeLocalParent(*buf, localNum);
}
}
{
TypeFunction tf = fd.type.isTypeFunction();
TypeFunction tfo = fd.originalType.isTypeFunction();
- mangleFuncType(tf, tfo, 0, null, buf, *backref);
+ mangleFuncType(tf, tfo, 0, null, *buf, *backref);
}
else
{
- mangleType(fd.type, 0, buf, *backref);
+ mangleType(fd.type, 0, *buf, *backref);
}
}
if (ta)
{
buf.writeByte('T');
- mangleType(ta, 0, buf, *backref);
+ mangleType(ta, 0, *buf, *backref);
}
else if (ea)
{
/* Use type mangling that matches what it would be for a function parameter
*/
- mangleType(ea.type, 0, buf, *backref);
+ mangleType(ea.type, 0, *buf, *backref);
ea.accept(this);
}
else if (sa)
if (d.mangleOverride)
{
buf.writeByte('X');
- toBuffer(buf, d.mangleOverride, d);
+ toBuffer(*buf, d.mangleOverride, d);
continue;
}
if (const id = externallyMangledIdentifier(d))
{
buf.writeByte('X');
- toBuffer(buf, id, d);
+ toBuffer(*buf, id, d);
continue;
}
if (!d.type || !d.type.deco)
if (s.ident)
mangleIdentifier(s.ident, s);
else
- toBuffer(buf, s.toString(), s);
+ toBuffer(*buf, s.toString(), s);
//printf("Dsymbol.mangle() %s = %s\n", s.toChars(), id);
}
override void visit(RealExp e)
{
buf.writeByte('e');
- realToMangleBuffer(buf, e.value);
+ realToMangleBuffer(*buf, e.value);
}
override void visit(ComplexExp e)
{
buf.writeByte('c');
- realToMangleBuffer(buf, e.toReal());
+ realToMangleBuffer(*buf, e.toReal());
buf.writeByte('c'); // separate the two
- realToMangleBuffer(buf, e.toImaginary());
+ realToMangleBuffer(*buf, e.toImaginary());
}
override void visit(NullExp e)
* true if the type was found. A back reference has been encoded.
* false if the type was not found. The current position is saved for later back references.
*/
- bool addRefToType(OutBuffer* buf, Type t)
+ bool addRefToType(ref OutBuffer buf, Type t)
{
if (t.isTypeBasic())
return false;
* true if the identifier was found. A back reference has been encoded.
* false if the identifier was not found. The current position is saved for later back references.
*/
- bool addRefToIdentifier(OutBuffer* buf, Identifier id)
+ bool addRefToIdentifier(ref OutBuffer buf, Identifier id)
{
return backrefImpl(buf, idents, id);
}
private:
- extern(D) bool backrefImpl(T)(OutBuffer* buf, ref AssocArray!(T, size_t) aa, T key)
+ extern(D) bool backrefImpl(T)(ref OutBuffer buf, ref AssocArray!(T, size_t) aa, T key)
{
auto p = aa.getLvalue(key);
if (*p)
* Mangle basic type ty to buf.
*/
-private void tyToDecoBuffer(OutBuffer* buf, int ty)
+private void tyToDecoBuffer(ref OutBuffer buf, int ty) @safe
{
const c = mangleChar[ty];
buf.writeByte(c);
/*********************************
* Mangling for mod.
*/
-private void MODtoDecoBuffer(OutBuffer* buf, MOD mod)
+private void MODtoDecoBuffer(ref OutBuffer buf, MOD mod) @safe
{
switch (mod)
{
* pos = relative position to encode
*/
private
-void writeBackRef(OutBuffer* buf, size_t pos)
+void writeBackRef(ref OutBuffer buf, size_t pos) @safe
{
buf.writeByte('Q');
enum base = 26;
* Write length prefixed string to buf.
*/
private
-extern (D) void toBuffer(OutBuffer* buf, const(char)[] id, Dsymbol s)
+extern (D) void toBuffer(ref OutBuffer buf, const(char)[] id, Dsymbol s)
{
const len = id.length;
if (buf.length + len >= 8 * 1024 * 1024) // 8 megs ought be enough for anyone
* localNum = local symbol number
*/
private
-void writeLocalParent(OutBuffer* buf, uint localNum)
+void writeLocalParent(ref OutBuffer buf, uint localNum)
{
uint ndigits = 1;
auto n = localNum;
* value = real to write
*/
private
-void realToMangleBuffer(OutBuffer* buf, real_t value)
+void realToMangleBuffer(ref OutBuffer buf, real_t value)
{
/* Rely on %A to get portable mangling.
* Must munge result to get only identifier characters.
* gets imported, it is unaffected by context.
* Ignore prevsc.
*/
- Scope* sc = Scope.createGlobal(this); // create root scope
+ Scope* sc = Scope.createGlobal(this, global.errorSink); // create root scope
if (md && md.msg)
md.msg = semanticString(sc, md.msg, "deprecation message");
bool isdeprecated; // if it is a deprecated module
Expression msg;
- extern (D) this(const ref Loc loc, Identifier[] packages, Identifier id, Expression msg, bool isdeprecated)
+ extern (D) this(const ref Loc loc, Identifier[] packages, Identifier id, Expression msg, bool isdeprecated) @safe
{
this.loc = loc;
this.packages = packages;
this.isdeprecated = isdeprecated;
}
- extern (C++) const(char)* toChars() const
+ extern (C++) const(char)* toChars() const @safe
{
OutBuffer buf;
foreach (pid; packages)
import dmd.dsymbol;
import dmd.dsymbolsem;
import dmd.dtemplate;
-import dmd.errors;
+import dmd.errorsink;
import dmd.func;
import dmd.globals;
import dmd.hdrgen;
/***************************************
* Find character string to replace c with.
*/
- const(char)[] escapeChar(char c)
+ const(char)[] escapeChar(char c) @safe
{
version (all)
{
size_t o = buf.length;
foreach (char c; name)
buf.writeByte((c == '_') ? ' ' : c);
- escapeStrayParenthesis(loc, buf, o, false);
+ escapeStrayParenthesis(loc, buf, o, false, sc.eSink);
buf.writestring(")");
}
else
L1:
size_t o = buf.length;
buf.write(body_);
- escapeStrayParenthesis(loc, buf, o, true);
+ escapeStrayParenthesis(loc, buf, o, true, sc.eSink);
highlightText(sc, a, loc, *buf, o);
buf.writestring(")");
}
}
else if (!fparam)
{
- warning(s.loc, "Ddoc: function declaration has no parameter '%.*s'", cast(int)namelen, namestart);
+ sc.eSink.warning(s.loc, "Ddoc: function declaration has no parameter '%.*s'", cast(int)namelen, namestart);
}
buf.write(namestart[0 .. namelen]);
}
- escapeStrayParenthesis(loc, buf, o, true);
+ escapeStrayParenthesis(loc, buf, o, true, sc.eSink);
highlightCode(sc, a, *buf, o);
}
buf.writestring(")");
{
size_t o = buf.length;
buf.write(textstart[0 .. textlen]);
- escapeStrayParenthesis(loc, buf, o, true);
+ escapeStrayParenthesis(loc, buf, o, true, sc.eSink);
highlightText(sc, a, loc, *buf, o);
}
buf.writestring(")");
cast(int)(tf.parameterList.varargs == VarArg.variadic);
if (pcount != paramcount)
{
- warning(s.loc, "Ddoc: parameter count mismatch, expected %llu, got %llu",
+ sc.eSink.warning(s.loc, "Ddoc: parameter count mismatch, expected %llu, got %llu",
cast(ulong) pcount, cast(ulong) paramcount);
if (paramcount == 0)
{
// Chances are someone messed up the format
- warningSupplemental(s.loc, "Note that the format is `param = description`");
+ sc.eSink.warningSupplemental(s.loc, "Note that the format is `param = description`");
}
}
}
return null;
}
-private TemplateDeclaration getEponymousParent(Dsymbol s)
+private TemplateDeclaration getEponymousParent(Dsymbol s) @safe
{
if (!s.parent)
return null;
/****************************************************
*/
-extern(C++) void gendocfile(Module m)
+extern(C++) void gendocfile(Module m, ErrorSink eSink)
{
__gshared OutBuffer mbuf;
__gshared int mbuf_done;
}
}
DocComment.parseMacros(m.escapetable, m.macrotable, mbuf[]);
- Scope* sc = Scope.createGlobal(m); // create root scope
+ Scope* sc = Scope.createGlobal(m, eSink); // create root scope
DocComment* dc = DocComment.parse(m, m.comment);
dc.pmacrotable = &m.macrotable;
dc.escapetable = m.escapetable;
const success = m.macrotable.expand(buf2, 0, end, null, global.recursionLimit);
if (!success)
- error(Loc.initial, "DDoc macro expansion limit exceeded; more than %d expansions.", global.recursionLimit);
+ eSink.error(Loc.initial, "DDoc macro expansion limit exceeded; more than %d expansions.", global.recursionLimit);
version (all)
{
* directly preceeded by a backslash with $(LPAREN) or $(RPAREN) instead of
* counting them as stray parentheses
*/
-private void escapeStrayParenthesis(Loc loc, OutBuffer* buf, size_t start, bool respectBackslashEscapes)
+private void escapeStrayParenthesis(Loc loc, OutBuffer* buf, size_t start, bool respectBackslashEscapes, ErrorSink eSink)
{
uint par_open = 0;
char inCode = 0;
if (par_open == 0)
{
//stray ')'
- warning(loc, "Ddoc: Stray ')'. This may cause incorrect Ddoc output. Use $(RPAREN) instead for unpaired right parentheses.");
+ eSink.warning(loc, "Ddoc: Stray ')'. This may cause incorrect Ddoc output. Use $(RPAREN) instead for unpaired right parentheses.");
buf.remove(u, 1); //remove the )
buf.insert(u, "$(RPAREN)"); //insert this instead
u += 8; //skip over newly inserted macro
if (par_open == 0)
{
//stray '('
- warning(loc, "Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses.");
+ eSink.warning(loc, "Ddoc: Stray '('. This may cause incorrect Ddoc output. Use $(LPAREN) instead for unpaired left parentheses.");
buf.remove(u, 1); //remove the (
buf.insert(u, "$(LPAREN)"); //insert this instead
}
// Basically, this is to skip over things like private{} blocks in a struct or
// class definition that don't add any components to the qualified name.
-private Scope* skipNonQualScopes(Scope* sc)
+private Scope* skipNonQualScopes(Scope* sc) @safe
{
while (sc && !sc.scopesym)
sc = sc.enclosing;
}
}
- static bool inSameModule(Dsymbol s, Dsymbol p)
+ static bool inSameModule(Dsymbol s, Dsymbol p) @safe
{
for (; s; s = s.parent)
{
buf.writestring("$(DDOC_SUMMARY ");
size_t o = buf.length;
buf.write(sec.body_);
- escapeStrayParenthesis(loc, buf, o, true);
+ escapeStrayParenthesis(loc, buf, o, true, sc.eSink);
highlightText(sc, a, loc, *buf, o);
buf.writestring(")");
}
}
/// Ditto
-private const(char)[] skipwhitespace(const(char)[] p)
+private const(char)[] skipwhitespace(const(char)[] p) @safe
{
foreach (idx, char c; p)
{
* chars = the characters to skip; order is unimportant
* Returns: the index after skipping characters.
*/
-private size_t skipChars(ref OutBuffer buf, size_t i, string chars)
+private size_t skipChars(ref OutBuffer buf, size_t i, string chars) @safe
{
Outer:
foreach (j, c; buf[][i..$])
* r = the string to replace `c` with
* Returns: `s` with `c` replaced with `r`
*/
-private inout(char)[] replaceChar(inout(char)[] s, char c, string r) pure
+private inout(char)[] replaceChar(inout(char)[] s, char c, string r) pure @safe
{
int count = 0;
foreach (char sc; s)
* s = the string to lowercase
* Returns: the lowercase version of the string or the original if already lowercase
*/
-private string toLowercase(string s) pure
+private string toLowercase(string s) pure @safe
{
string lower;
foreach (size_t i; 0..s.length)
* to = the index within `buf` to stop counting at, exclusive
* Returns: the indent
*/
-private int getMarkdownIndent(ref OutBuffer buf, size_t from, size_t to)
+private int getMarkdownIndent(ref OutBuffer buf, size_t from, size_t to) @safe
{
const slice = buf[];
if (to > slice.length)
* beginning of next line
* end of buf
*/
-size_t skiptoident(ref OutBuffer buf, size_t i)
+size_t skiptoident(ref OutBuffer buf, size_t i) @safe
{
const slice = buf[];
while (i < slice.length)
/************************************************
* Scan forward past end of identifier.
*/
-private size_t skippastident(ref OutBuffer buf, size_t i)
+private size_t skippastident(ref OutBuffer buf, size_t i) @safe
{
const slice = buf[];
while (i < slice.length)
* Scan forward past end of an identifier that might
* contain dots (e.g. `abc.def`)
*/
-private size_t skipPastIdentWithDots(ref OutBuffer buf, size_t i)
+private size_t skipPastIdentWithDots(ref OutBuffer buf, size_t i) @safe
{
const slice = buf[];
bool lastCharWasDot;
* the detected heading level from 1 to 6, or
* 0 if not at an ATX heading
*/
-private int detectAtxHeadingLevel(ref OutBuffer buf, const size_t i)
+private int detectAtxHeadingLevel(ref OutBuffer buf, const size_t i) @safe
{
const iHeadingStart = i;
const iAfterHashes = skipChars(buf, i, "#");
/****************************************************
*/
-private bool isIdentifier(Dsymbols* a, const(char)[] s)
+private bool isIdentifier(Dsymbols* a, const(char)[] s) @safe
{
foreach (member; *a)
{
* Return true if str is a reserved symbol name
* that starts with a double underscore.
*/
-private bool isReservedName(const(char)[] str)
+private bool isReservedName(const(char)[] str) @safe
{
immutable string[] table =
[
char type; /// the type of delimiter, defined by its starting character
/// whether this describes a valid delimiter
- @property bool isValid() const { return count != 0; }
+ @property bool isValid() const @safe { return count != 0; }
/// flag this delimiter as invalid
- void invalidate() { count = 0; }
+ void invalidate() @safe { count = 0; }
}
/****************************************************
char type; /// the type of list, defined by its starting character
/// whether this describes a valid list
- @property bool isValid() const { return type != type.init; }
+ @property bool isValid() const @safe { return type != type.init; }
/****************************************************
* Try to parse a list item, returning whether successful.
* i = the index within `buf` of the potential list item
* Returns: the parsed list item. Its `isValid` property describes whether parsing succeeded.
*/
- static MarkdownList parseItem(ref OutBuffer buf, size_t iLineStart, size_t i)
+ static MarkdownList parseItem(ref OutBuffer buf, size_t iLineStart, size_t i) @safe
{
if (buf[i] == '+' || buf[i] == '-' || buf[i] == '*')
return parseUnorderedListItem(buf, iLineStart, i);
* i = the index within `buf` of the list item
* Returns: whether `i` is at a list item of the same type as this list
*/
- private bool isAtItemInThisList(ref OutBuffer buf, size_t iLineStart, size_t i)
+ private bool isAtItemInThisList(ref OutBuffer buf, size_t iLineStart, size_t i) @safe
{
MarkdownList item = (type == '.' || type == ')') ?
parseOrderedListItem(buf, iLineStart, i) :
* i = the index within `buf` of the list item
* Returns: the parsed list item, or a list item with type `.init` if no list item is available
*/
- private static MarkdownList parseUnorderedListItem(ref OutBuffer buf, size_t iLineStart, size_t i)
+ private static MarkdownList parseUnorderedListItem(ref OutBuffer buf, size_t iLineStart, size_t i) @safe
{
if (i+1 < buf.length &&
(buf[i] == '-' ||
* i = the index within `buf` of the list item
* Returns: the parsed list item, or a list item with type `.init` if no list item is available
*/
- private static MarkdownList parseOrderedListItem(ref OutBuffer buf, size_t iLineStart, size_t i)
+ private static MarkdownList parseOrderedListItem(ref OutBuffer buf, size_t iLineStart, size_t i) @safe
{
size_t iAfterNumbers = skipChars(buf, i, "0123456789");
if (iAfterNumbers - i > 0 &&
* delimiter = the delimiter that starts this link
* Returns: the index at the end of parsing the link, or `i` if parsing failed.
*/
- private size_t parseReferenceLink(ref OutBuffer buf, size_t i, MarkdownDelimiter delimiter)
+ private size_t parseReferenceLink(ref OutBuffer buf, size_t i, MarkdownDelimiter delimiter) @safe
{
size_t iStart = i + 1;
size_t iEnd = iStart;
* If this function returns a non-empty label then `i` will point just after the ']' at the end of the label.
* Returns: the parsed and normalized label, possibly empty
*/
- private bool parseLabel(ref OutBuffer buf, ref size_t i)
+ private bool parseLabel(ref OutBuffer buf, ref size_t i) @safe
{
if (buf[i] != '[')
return false;
* s = the string to remove escaping backslashes from
* Returns: `s` without escaping backslashes in it
*/
- private static char[] removeEscapeBackslashes(char[] s)
+ private static char[] removeEscapeBackslashes(char[] s) @safe
{
if (!s.length)
return s;
* s = the string to percent-encode
* Returns: `s` with special characters percent-encoded
*/
- private static inout(char)[] percentEncode(inout(char)[] s) pure
+ private static inout(char)[] percentEncode(inout(char)[] s) pure @safe
{
static bool shouldEncode(char c)
{
* If this function succeeds `i` will point after the newline.
* Returns: whether a newline was skipped
*/
- private static bool skipOneNewline(ref OutBuffer buf, ref size_t i) pure
+ private static bool skipOneNewline(ref OutBuffer buf, ref size_t i) pure @safe
{
if (i < buf.length && buf[i] == '\r')
++i;
* delimiter = the character to split by
* Returns: the resulting array of strings
*/
- private static string[] split(string s, char delimiter) pure
+ private static string[] split(string s, char delimiter) pure @safe
{
string[] result;
size_t iStart = 0;
* columnAlignments = alignments to populate for each column
* Returns: the index of the end of the parsed delimiter, or `0` if not found
*/
-private size_t parseTableDelimiterRow(ref OutBuffer buf, const size_t iStart, bool inQuote, ref TableColumnAlignment[] columnAlignments)
+private size_t parseTableDelimiterRow(ref OutBuffer buf, const size_t iStart, bool inQuote, ref TableColumnAlignment[] columnAlignments) @safe
{
size_t i = skipChars(buf, iStart, inQuote ? ">| \t" : "| \t");
while (i < buf.length && buf[i] != '\r' && buf[i] != '\n')
codebuf.write(buf[iCodeStart + count .. i]);
// escape the contents, but do not perform highlighting except for DDOC_PSYMBOL
highlightCode(sc, a, codebuf, 0);
- escapeStrayParenthesis(loc, &codebuf, 0, false);
+ escapeStrayParenthesis(loc, &codebuf, 0, false, sc.eSink);
buf.remove(iCodeStart, i - iCodeStart + count); // also trimming off the current `
immutable pre = "$(DDOC_BACKQUOTED ";
i = buf.insert(iCodeStart, pre);
highlightCode2(sc, a, codebuf, 0);
else
codebuf.remove(codebuf.length-1, 1); // remove the trailing 0 byte
- escapeStrayParenthesis(loc, &codebuf, 0, false);
+ escapeStrayParenthesis(loc, &codebuf, 0, false, sc.eSink);
buf.remove(iCodeStart, i - iCodeStart);
i = buf.insert(iCodeStart, codebuf[]);
i = buf.insert(i, ")\n");
}
if (inCode == '-')
- error(loc, "unmatched `---` in DDoc comment");
+ sc.eSink.error(loc, "unmatched `---` in DDoc comment");
else if (inCode)
buf.insert(buf.length, ")");
*/
private void highlightCode2(Scope* sc, Dsymbols* a, ref OutBuffer buf, size_t offset)
{
- uint errorsave = global.startGagging();
+ scope eSinkNull = new ErrorSinkNull();
scope Lexer lex = new Lexer(null, cast(char*)buf[].ptr, 0, buf.length - 1, 0, 1,
- global.errorSink,
+ eSinkNull, // ignore errors
&global.compileEnv);
OutBuffer res;
const(char)* lastp = cast(char*)buf[].ptr;
}
buf.setsize(offset);
buf.write(&res);
- global.endGagging(errorsave);
}
/****************************************
#pragma once
class Module;
+class ErrorSink;
-void gendocfile(Module *m);
+void gendocfile(Module *m, ErrorSink *eSink);
import dmd.dtemplate;
import dmd.expression;
import dmd.errors;
+import dmd.errorsink;
import dmd.func;
import dmd.globals;
import dmd.id;
bool inLoop; /// true if inside a loop (where constructor calls aren't allowed)
int intypeof; /// in typeof(exp)
VarDeclaration lastVar; /// Previous symbol used to prevent goto-skips-init
+ ErrorSink eSink; /// sink for error messages
/* If minst && !tinst, it's in definitely non-speculative scope (eg. module member scope).
* If !minst && !tinst, it's in definitely speculative scope (eg. template constraint).
return new Scope();
}
- extern (D) static Scope* createGlobal(Module _module)
+ extern (D) static Scope* createGlobal(Module _module, ErrorSink eSink)
{
Scope* sc = Scope.alloc();
*sc = Scope.init;
sc.minst = _module;
sc.scopesym = new ScopeDsymbol();
sc.scopesym.symtab = new DsymbolTable();
+ sc.eSink = eSink;
// Add top level package as member of this global scope
Dsymbol m = _module;
while (m.parent)
* Returns:
* innermost scope, null if none
*/
- extern (D) Scope* inner() return
+ extern (D) Scope* inner() return @safe
{
for (Scope* sc = &this; sc; sc = sc.enclosing)
{
/********************************************
* Search enclosing scopes for ScopeDsymbol.
*/
- extern (D) ScopeDsymbol getScopesym()
+ extern (D) ScopeDsymbol getScopesym() @safe
{
for (Scope* sc = &this; sc; sc = sc.enclosing)
{
/********************************************
* Search enclosing scopes for ClassDeclaration.
*/
- extern (D) ClassDeclaration getClassScope()
+ extern (D) ClassDeclaration getClassScope() @safe
{
for (Scope* sc = &this; sc; sc = sc.enclosing)
{
/********************************************
* Search enclosing scopes for ClassDeclaration or StructDeclaration.
*/
- extern (D) AggregateDeclaration getStructClassScope()
+ extern (D) AggregateDeclaration getStructClassScope() @safe
{
for (Scope* sc = &this; sc; sc = sc.enclosing)
{
* where it was declared. So mark the Scope as not
* to be free'd.
*/
- extern (D) void setNoFree()
+ extern (D) void setNoFree() @safe
{
//int i = 0;
//printf("Scope::setNoFree(this = %p)\n", this);
{
uint oldgag;
- extern (D) this(uint old) nothrow
+ extern (D) this(uint old) nothrow @safe
{
this.oldgag = old;
}
/**
* Checks if `this` is absolutely identical visibility attribute to `other`
*/
- bool opEquals(ref const Visibility other) const
+ bool opEquals(ref const Visibility other) const @safe
{
if (this.kind == other.kind)
{
PASS semanticRun = PASS.initial;
ushort localNum; /// perturb mangled name to avoid collisions with those in FuncDeclaration.localsymtab
- final extern (D) this() nothrow
+ final extern (D) this() nothrow @safe
{
//printf("Dsymbol::Dsymbol(%p)\n", this);
loc = Loc(null, 0, 0);
}
- final extern (D) this(Identifier ident) nothrow
+ final extern (D) this(Identifier ident) nothrow @safe
{
//printf("Dsymbol::Dsymbol(%p, ident)\n", this);
this.loc = Loc(null, 0, 0);
this.ident = ident;
}
- final extern (D) this(const ref Loc loc, Identifier ident) nothrow
+ final extern (D) this(const ref Loc loc, Identifier ident) nothrow @safe
{
//printf("Dsymbol::Dsymbol(%p, ident)\n", this);
this.loc = loc;
this.ident = ident;
}
- static Dsymbol create(Identifier ident) nothrow
+ static Dsymbol create(Identifier ident) nothrow @safe
{
return new Dsymbol(ident);
}
{
if (this == o)
return true;
- if (o.dyncast() != DYNCAST.dsymbol)
+ const s = o.isDsymbol();
+ if (!s)
return false;
- auto s = cast(Dsymbol)o;
// Overload sets don't have an ident
// Function-local declarations may have identical names
// if they are declared in different scopes
{
va_list ap;
va_start(ap, format);
- .verror(loc, format, ap, kind(), prettyFormatHelper().ptr);
+ .verrorReport(loc, format, ap, ErrorKind.error, kind(), prettyFormatHelper().ptr);
va_end(ap);
}
va_list ap;
va_start(ap, format);
const loc = getLoc();
- .verror(loc, format, ap, kind(), prettyFormatHelper().ptr);
+ .verrorReport(loc, format, ap, ErrorKind.error, kind(), prettyFormatHelper().ptr);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- .vdeprecation(loc, format, ap, kind(), prettyFormatHelper().ptr);
+ .verrorReport(loc, format, ap, ErrorKind.deprecation, kind(), prettyFormatHelper().ptr);
va_end(ap);
}
va_list ap;
va_start(ap, format);
const loc = getLoc();
- .vdeprecation(loc, format, ap, kind(), prettyFormatHelper().ptr);
+ .verrorReport(loc, format, ap, ErrorKind.deprecation, kind(), prettyFormatHelper().ptr);
va_end(ap);
}
}
{
va_list ap;
va_start(ap, format);
- .verror(loc, format, ap, kind(), prettyFormatHelper().ptr);
+ .verrorReport(loc, format, ap, ErrorKind.error, kind(), prettyFormatHelper().ptr);
va_end(ap);
}
va_list ap;
va_start(ap, format);
const loc = getLoc();
- .verror(loc, format, ap, kind(), prettyFormatHelper().ptr);
+ .verrorReport(loc, format, ap, ErrorKind.error, kind(), prettyFormatHelper().ptr);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- .vdeprecation(loc, format, ap, kind(), prettyFormatHelper().ptr);
+ .verrorReport(loc, format, ap, ErrorKind.deprecation, kind(), prettyFormatHelper().ptr);
va_end(ap);
}
va_list ap;
va_start(ap, format);
const loc = getLoc();
- .vdeprecation(loc, format, ap, kind(), prettyFormatHelper().ptr);
+ .verrorReport(loc, format, ap, ErrorKind.deprecation, kind(), prettyFormatHelper().ptr);
va_end(ap);
}
}
BitArray accessiblePackages, privateAccessiblePackages;// whitelists of accessible (imported) packages
public:
- final extern (D) this() nothrow
+ final extern (D) this() nothrow @safe
{
}
- final extern (D) this(Identifier ident) nothrow
+ final extern (D) this(Identifier ident) nothrow @safe
{
super(ident);
}
- final extern (D) this(const ref Loc loc, Identifier ident) nothrow
+ final extern (D) this(const ref Loc loc, Identifier ident) nothrow @safe
{
super(loc, ident);
}
{
WithStatement withstate;
- extern (D) this(WithStatement withstate) nothrow
+ extern (D) this(WithStatement withstate) nothrow @safe
{
this.withstate = withstate;
}
private RootObject arrayContent;
Scope* sc;
- extern (D) this(Scope* sc, Expression exp) nothrow
+ extern (D) this(Scope* sc, Expression exp) nothrow @safe
{
super(exp.loc, null);
assert(exp.op == EXP.index || exp.op == EXP.slice || exp.op == EXP.array);
this.arrayContent = exp;
}
- extern (D) this(Scope* sc, TypeTuple type) nothrow
+ extern (D) this(Scope* sc, TypeTuple type) nothrow @safe
{
this.sc = sc;
this.arrayContent = type;
}
- extern (D) this(Scope* sc, TupleDeclaration td) nothrow
+ extern (D) this(Scope* sc, TupleDeclaration td) nothrow @safe
{
this.sc = sc;
this.arrayContent = td;
*/
extern (C++) final class ForwardingScopeDsymbol : ScopeDsymbol
{
- extern (D) this() nothrow
+ extern (D) this() nothrow @safe
{
super();
}
extern (C++) final class ExpressionDsymbol : Dsymbol
{
Expression exp;
- this(Expression exp) nothrow
+ this(Expression exp) nothrow @safe
{
super();
this.exp = exp;
Dsymbol aliassym; /// replace previous RHS of AliasDeclaration with `aliassym`
/// only one of type and aliassym can be != null
- extern (D) this(const ref Loc loc, Identifier ident, Type type, Dsymbol aliassym) nothrow
+ extern (D) this(const ref Loc loc, Identifier ident, Type type, Dsymbol aliassym) nothrow @safe
{
super(loc, null);
this.ident = ident;
alias visit = Visitor.visit;
Scope* sc;
- this(Scope* sc) scope
+ this(Scope* sc) scope @safe
{
this.sc = sc;
}
return;
}
- // @@@DEPRECATED_2.121@@@
- // Deprecated in 2.101 - Can be removed in 2.121
- if (ad.isClassDeclaration() || ad.isInterfaceDeclaration())
- deprecation(dsym.loc, "alias this for classes/interfaces is deprecated");
-
assert(ad.members);
Dsymbol s = ad.search(dsym.loc, dsym.ident);
if (!s)
*/
if (ne.member && !(ne.member.storage_class & STC.scope_))
{
- if (sc.func.isSafe())
- {
- // @@@DEPRECATED_2.112@@@
- deprecation(dsym.loc,
- "`scope` allocation of `%s` requires that constructor be annotated with `scope`",
- dsym.toChars());
- deprecationSupplemental(ne.member.loc, "is the location of the constructor");
- }
- else
- sc.func.setUnsafe();
+ import dmd.escape : setUnsafeDIP1000;
+ const inSafeFunc = sc.func && sc.func.isSafeBypassingInference();
+ if (sc.setUnsafeDIP1000(false, dsym.loc, "`scope` allocation of `%s` requires that constructor be annotated with `scope`", dsym))
+ errorSupplemental(ne.member.loc, "is the location of the constructor");
+ else if (global.params.obsolete && inSafeFunc)
+ warningSupplemental(ne.member.loc, "is the location of the constructor");
}
ne.onstack = 1;
dsym.onstack = true;
bool needctfe = dsym.isDataseg() || (dsym.storage_class & STC.manifest);
if (needctfe)
sc = sc.startCTFE();
+ sc = sc.push();
+ sc.varDecl = dsym; // https://issues.dlang.org/show_bug.cgi?id=24051
exp = exp.expressionSemantic(sc);
exp = resolveProperties(sc, exp);
+ sc = sc.pop();
if (needctfe)
sc = sc.endCTFE();
ei.exp = exp;
Scope* sc = m._scope; // see if already got one from importAll()
if (!sc)
{
- sc = Scope.createGlobal(m); // create root scope
+ sc = Scope.createGlobal(m, global.errorSink); // create root scope
}
//printf("Module = %p, linkage = %d\n", sc.scopesym, sc.linkage);
alias visit = Visitor.visit;
TemplateInstance inst;
- extern (D) this(TemplateInstance inst) scope
+ extern (D) this(TemplateInstance inst) scope @safe
{
this.inst = inst;
}
enum IDX_NOTFOUND = 0x12345678;
-pure nothrow @nogc
+pure nothrow @nogc @safe
{
/********************************************
bool ignoreAliasThis;
MATCH result;
- extern (D) this(Scope* sc, Type tparam, TemplateParameters* parameters, Objects* dedtypes, uint* wm, size_t inferStart, bool ignoreAliasThis)
+ extern (D) this(Scope* sc, Type tparam, TemplateParameters* parameters, Objects* dedtypes, uint* wm, size_t inferStart, bool ignoreAliasThis) @safe
{
this.sc = sc;
this.tparam = tparam;
TemplateParameter[] tparams;
bool result;
- extern (D) this(TemplateParameter[] tparams)
+ extern (D) this(TemplateParameter[] tparams) @safe
{
this.tparams = tparams;
}
bool dependent;
/* ======================== TemplateParameter =============================== */
- extern (D) this(const ref Loc loc, Identifier ident)
+ extern (D) this(const ref Loc loc, Identifier ident) @safe
{
this.loc = loc;
this.ident = ident;
extern (D) __gshared Type tdummy = null;
- extern (D) this(const ref Loc loc, Identifier ident, Type specType, Type defaultType)
+ extern (D) this(const ref Loc loc, Identifier ident, Type specType, Type defaultType) @safe
{
super(loc, ident);
this.specType = specType;
*/
extern (C++) final class TemplateThisParameter : TemplateTypeParameter
{
- extern (D) this(const ref Loc loc, Identifier ident, Type specType, Type defaultType)
+ extern (D) this(const ref Loc loc, Identifier ident, Type specType, Type defaultType) @safe
{
super(loc, ident, specType, defaultType);
}
extern (D) __gshared Expression[void*] edummies;
extern (D) this(const ref Loc loc, Identifier ident, Type valType,
- Expression specValue, Expression defaultValue)
+ Expression specValue, Expression defaultValue) @safe
{
super(loc, ident);
this.valType = valType;
extern (D) __gshared Dsymbol sdummy = null;
- extern (D) this(const ref Loc loc, Identifier ident, Type specType, RootObject specAlias, RootObject defaultAlias)
+ extern (D) this(const ref Loc loc, Identifier ident, Type specType, RootObject specAlias, RootObject defaultAlias) @safe
{
super(loc, ident);
this.specType = specType;
*/
extern (C++) final class TemplateTupleParameter : TemplateParameter
{
- extern (D) this(const ref Loc loc, Identifier ident)
+ extern (D) this(const ref Loc loc, Identifier ident) @safe
{
super(loc, ident);
}
//printf("TemplateInstance.genIdent('%s')\n", tempdecl.ident.toChars());
assert(args is tiargs);
OutBuffer buf;
- mangleToBuffer(this, &buf);
+ mangleToBuffer(this, buf);
//printf("\tgenIdent = %s\n", buf.peekChars());
return Identifier.idPool(buf[]);
}
* Return false if it might be an alias or tuple.
* (Note that even in this case, it could still turn out to be a value).
*/
-bool definitelyValueParameter(Expression e)
+bool definitelyValueParameter(Expression e) @safe
{
// None of these can be value parameters
if (e.op == EXP.tuple || e.op == EXP.scope_ ||
// Generates getter-setter methods to replace the use of alias this
// This should be replaced by a `static foreach` once the gdc tester
// gets upgraded to version 10 (to support `static foreach`).
- private extern(D) static string generateMembers()
+ private extern(D) static string generateMembers() @safe
{
string result = "";
foreach(member; __traits(allMembers, Context))
}
return result;
}
-
mixin(generateMembers());
this(OutBuffer* fwdbuf, OutBuffer* donebuf, OutBuffer* buf) scope
}
/// Writes a final `;` and insert an empty line outside of aggregates
- private void writeDeclEnd()
+ private void writeDeclEnd() @safe
{
buf.writestringln(";");
buf.writestringln("};");
}
- private bool memberField(AST.VarDeclaration vd)
+ private bool memberField(AST.VarDeclaration vd) @safe
{
if (!vd.type || !vd.type.deco || !vd.ident)
return false;
/// Ends a custom alignment section using `#pragma pack` if
/// `alignment` specifies a custom alignment
- private void popAlignToBuffer(structalign_t alignment)
+ private void popAlignToBuffer(structalign_t alignment) @safe
{
if (alignment.isDefault() || (tdparent && alignment.isUnknown()))
return;
}
/// Returns: Explicit mangling for `sym` if present
- extern(D) static const(char)[] getMangleOverride(const AST.Dsymbol sym)
+ extern(D) static const(char)[] getMangleOverride(const AST.Dsymbol sym) @safe
{
if (auto decl = sym.isDeclaration())
return decl.mangleOverride;
}
/// Writes `#if <content>` into the supplied buffer
-void hashIf(ref OutBuffer buf, string content)
+void hashIf(ref OutBuffer buf, string content) @safe
{
buf.writestring("#if ");
buf.writestringln(content);
}
/// Writes `#elif <content>` into the supplied buffer
-void hashElIf(ref OutBuffer buf, string content)
+void hashElIf(ref OutBuffer buf, string content) @safe
{
buf.writestring("#elif ");
buf.writestringln(content);
}
/// Writes `#endif` into the supplied buffer
-void hashEndIf(ref OutBuffer buf)
+void hashEndIf(ref OutBuffer buf) @safe
{
buf.writestringln("#endif");
}
/// Writes `#define <content>` into the supplied buffer
-void hashDefine(ref OutBuffer buf, string content)
+void hashDefine(ref OutBuffer buf, string content) @safe
{
buf.writestring("#define ");
buf.writestringln(content);
}
/// Writes `#include <content>` into the supplied buffer
-void hashInclude(ref OutBuffer buf, string content)
+void hashInclude(ref OutBuffer buf, string content) @safe
{
buf.writestring("#include ");
buf.writestringln(content);
/// Fetches the symbol for user-defined types from the type `t`
/// if `t` is either `TypeClass`, `TypeStruct` or `TypeEnum`
-ASTCodegen.Dsymbol symbolFromType(ASTCodegen.Type t)
+ASTCodegen.Dsymbol symbolFromType(ASTCodegen.Type t) @safe
{
if (auto tc = t.isTypeClass())
return tc.sym;
{
uint level;
- extern (D) this(const ref Loc loc, Identifier ident)
+ extern (D) this(const ref Loc loc, Identifier ident) @safe
{
super(loc, ident);
}
- extern (D) this(const ref Loc loc, uint level)
+ extern (D) this(const ref Loc loc, uint level) @safe
{
super(loc, null);
this.level = level;
{
uint level;
- extern (D) this(const ref Loc loc, Identifier ident)
+ extern (D) this(const ref Loc loc, Identifier ident) @safe
{
super(loc, ident);
}
- extern (D) this(const ref Loc loc, uint level)
+ extern (D) this(const ref Loc loc, uint level) @safe
{
super(loc, null);
this.level = level;
nothrow:
+/// Constants used to discriminate kinds of error messages.
+enum ErrorKind
+{
+ warning,
+ deprecation,
+ error,
+ tip,
+ message,
+}
+
/***************************
* Error message sink for D compiler.
*/
{
va_list ap;
va_start(ap, format);
- verror(loc, format, ap);
+ verrorReport(loc, format, ap, ErrorKind.error);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- verrorSupplemental(loc, format, ap);
+ verrorReportSupplemental(loc, format, ap, ErrorKind.error);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- vwarning(loc, format, ap);
+ verrorReport(loc, format, ap, ErrorKind.warning);
+ va_end(ap);
+ }
+
+ void warningSupplemental(const ref Loc loc, const(char)* format, ...)
+ {
+ va_list ap;
+ va_start(ap, format);
+ verrorReportSupplemental(loc, format, ap, ErrorKind.warning);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- vdeprecation(loc, format, ap);
+ verrorReport(loc, format, ap, ErrorKind.deprecation);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- vdeprecationSupplemental(loc, format, ap);
+ verrorReportSupplemental(loc, format, ap, ErrorKind.deprecation);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- vmessage(loc, format, ap);
+ verrorReport(loc, format, ap, ErrorKind.message);
va_end(ap);
}
}
{
va_list ap;
va_start(ap, format);
- verror(loc, format, ap);
+ verrorReport(loc, format, ap, ErrorKind.error);
va_end(ap);
}
else
{
va_list ap;
va_start(ap, format);
- verror(loc, format, ap);
+ verrorReport(loc, format, ap, ErrorKind.error);
va_end(ap);
}
const loc = Loc(filename, linnum, charnum);
va_list ap;
va_start(ap, format);
- verror(loc, format, ap);
+ verrorReport(loc, format, ap, ErrorKind.error);
va_end(ap);
}
else
const loc = Loc(filename, linnum, charnum);
va_list ap;
va_start(ap, format);
- verror(loc, format, ap);
+ verrorReport(loc, format, ap, ErrorKind.error);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- verrorSupplemental(loc, format, ap);
+ verrorReportSupplemental(loc, format, ap, ErrorKind.error);
va_end(ap);
}
else
{
va_list ap;
va_start(ap, format);
- verrorSupplemental(loc, format, ap);
+ verrorReportSupplemental(loc, format, ap, ErrorKind.error);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- vwarning(loc, format, ap);
+ verrorReport(loc, format, ap, ErrorKind.warning);
va_end(ap);
}
else
{
va_list ap;
va_start(ap, format);
- vwarning(loc, format, ap);
+ verrorReport(loc, format, ap, ErrorKind.warning);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- vwarningSupplemental(loc, format, ap);
+ verrorReportSupplemental(loc, format, ap, ErrorKind.warning);
va_end(ap);
}
else
{
va_list ap;
va_start(ap, format);
- vwarningSupplemental(loc, format, ap);
+ verrorReportSupplemental(loc, format, ap, ErrorKind.warning);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- vdeprecation(loc, format, ap);
+ verrorReport(loc, format, ap, ErrorKind.deprecation);
va_end(ap);
}
else
{
va_list ap;
va_start(ap, format);
- vdeprecation(loc, format, ap);
+ verrorReport(loc, format, ap, ErrorKind.deprecation);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- vdeprecationSupplemental(loc, format, ap);
+ verrorReportSupplemental(loc, format, ap, ErrorKind.deprecation);
va_end(ap);
}
else
{
va_list ap;
va_start(ap, format);
- vdeprecationSupplemental(loc, format, ap);
+ verrorReportSupplemental(loc, format, ap, ErrorKind.deprecation);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- vmessage(loc, format, ap);
+ verrorReport(loc, format, ap, ErrorKind.message);
va_end(ap);
}
else
{
va_list ap;
va_start(ap, format);
- vmessage(loc, format, ap);
+ verrorReport(loc, format, ap, ErrorKind.message);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- vmessage(Loc.initial, format, ap);
+ verrorReport(Loc.initial, format, ap, ErrorKind.message);
va_end(ap);
}
else
{
va_list ap;
va_start(ap, format);
- vmessage(Loc.initial, format, ap);
+ verrorReport(Loc.initial, format, ap, ErrorKind.message);
va_end(ap);
}
/**
* The type of the diagnostic handler
- * see verrorPrint for arguments
+ * see verrorReport for arguments
* Returns: true if error handling is done, false to continue printing to stderr
*/
alias DiagnosticHandler = bool delegate(const ref Loc location, Color headerColor, const(char)* header, const(char)* messageFormat, va_list args, const(char)* prefix1, const(char)* prefix2);
{
va_list ap;
va_start(ap, format);
- vtip(format, ap);
+ verrorReport(Loc.initial, format, ap, ErrorKind.tip);
va_end(ap);
}
else
{
va_list ap;
va_start(ap, format);
- vtip(format, ap);
+ verrorReport(Loc.initial, format, ap, ErrorKind.tip);
va_end(ap);
}
/**
- * Same as $(D error), but takes a va_list parameter, and optionally additional message prefixes.
+ * Implements $(D error), $(D warning), $(D deprecation), $(D message), and
+ * $(D tip). Report a diagnostic error, taking a va_list parameter, and
+ * optionally additional message prefixes. Whether the message gets printed
+ * depends on runtime values of DiagnosticReporting and global gagging.
* Params:
- * loc = location of error
- * format = printf-style format specification
- * ap = printf-style variadic arguments
- * p1 = additional message prefix
- * p2 = additional message prefix
- * header = title of error message
+ * loc = location of error
+ * format = printf-style format specification
+ * ap = printf-style variadic arguments
+ * kind = kind of error being printed
+ * p1 = additional message prefix
+ * p2 = additional message prefix
*/
-extern (C++) void verror(const ref Loc loc, const(char)* format, va_list ap, const(char)* p1 = null, const(char)* p2 = null, const(char)* header = "Error: ");
+extern (C++) void verrorReport(const ref Loc loc, const(char)* format, va_list ap, ErrorKind kind, const(char)* p1 = null, const(char)* p2 = null);
/**
- * Same as $(D errorSupplemental), but takes a va_list parameter.
+ * Implements $(D errorSupplemental), $(D warningSupplemental), and
+ * $(D deprecationSupplemental). Report an addition diagnostic error, taking a
+ * va_list parameter. Whether the message gets printed depends on runtime
+ * values of DiagnosticReporting and global gagging.
* Params:
- * loc = location of error
- * format = printf-style format specification
- * ap = printf-style variadic arguments
- */
-static if (__VERSION__ < 2092)
- extern (C++) void verrorSupplemental(const ref Loc loc, const(char)* format, va_list ap);
-else
- pragma(printf) extern (C++) void verrorSupplemental(const ref Loc loc, const(char)* format, va_list ap);
-
-/**
- * Same as $(D warning), but takes a va_list parameter.
- * Params:
- * loc = location of warning
- * format = printf-style format specification
- * ap = printf-style variadic arguments
- */
-static if (__VERSION__ < 2092)
- extern (C++) void vwarning(const ref Loc loc, const(char)* format, va_list ap);
-else
- pragma(printf) extern (C++) void vwarning(const ref Loc loc, const(char)* format, va_list ap);
-
-/**
- * Same as $(D warningSupplemental), but takes a va_list parameter.
- * Params:
- * loc = location of warning
- * format = printf-style format specification
- * ap = printf-style variadic arguments
+ * loc = location of error
+ * format = printf-style format specification
+ * ap = printf-style variadic arguments
+ * kind = kind of error being printed
*/
-static if (__VERSION__ < 2092)
- extern (C++) void vwarningSupplemental(const ref Loc loc, const(char)* format, va_list ap);
-else
- pragma(printf) extern (C++) void vwarningSupplemental(const ref Loc loc, const(char)* format, va_list ap);
-
-/**
- * Same as $(D deprecation), but takes a va_list parameter, and optionally additional message prefixes.
- * Params:
- * loc = location of deprecation
- * format = printf-style format specification
- * ap = printf-style variadic arguments
- * p1 = additional message prefix
- * p2 = additional message prefix
- */
-extern (C++) void vdeprecation(const ref Loc loc, const(char)* format, va_list ap, const(char)* p1 = null, const(char)* p2 = null);
-
-/**
- * Same as $(D message), but takes a va_list parameter.
- * Params:
- * loc = location of message
- * format = printf-style format specification
- * ap = printf-style variadic arguments
- */
-static if (__VERSION__ < 2092)
- extern (C++) void vmessage(const ref Loc loc, const(char)* format, va_list ap);
-else
- pragma(printf) extern (C++) void vmessage(const ref Loc loc, const(char)* format, va_list ap);
-
-/**
- * Same as $(D tip), but takes a va_list parameter.
- * Params:
- * format = printf-style format specification
- * ap = printf-style variadic arguments
- */
-static if (__VERSION__ < 2092)
- extern (C++) void vtip(const(char)* format, va_list ap);
-else
- pragma(printf) extern (C++) void vtip(const(char)* format, va_list ap);
-
-/**
- * Same as $(D deprecationSupplemental), but takes a va_list parameter.
- * Params:
- * loc = location of deprecation
- * format = printf-style format specification
- * ap = printf-style variadic arguments
- */
-static if (__VERSION__ < 2092)
- extern (C++) void vdeprecationSupplemental(const ref Loc loc, const(char)* format, va_list ap);
-else
- pragma(printf) extern (C++) void vdeprecationSupplemental(const ref Loc loc, const(char)* format, va_list ap);
+extern (C++) void verrorReportSupplemental(const ref Loc loc, const(char)* format, va_list ap, ErrorKind kind);
/**
* The type of the fatal error handler
* Try to stop forgetting to remove the breakpoints from
* release builds.
*/
-extern (C++) void halt();
+extern (C++) void halt() @safe;
struct Loc;
+enum class ErrorKind
+{
+ warning = 0,
+ deprecation = 1,
+ error = 2,
+ tip = 3,
+ message = 4,
+};
+
bool isConsoleColorSupported();
#if defined(__GNUC__)
D_ATTRIBUTE_FORMAT(2, 3) void error(const Loc& loc, const char *format, ...);
D_ATTRIBUTE_FORMAT(4, 5) void error(const char *filename, unsigned linnum, unsigned charnum, const char *format, ...);
D_ATTRIBUTE_FORMAT(2, 3) void errorSupplemental(const Loc& loc, const char *format, ...);
-D_ATTRIBUTE_FORMAT(2, 0) void verror(const Loc& loc, const char *format, va_list ap, const char *p1 = NULL, const char *p2 = NULL, const char *header = "Error: ");
-D_ATTRIBUTE_FORMAT(2, 0) void verrorSupplemental(const Loc& loc, const char *format, va_list ap);
-D_ATTRIBUTE_FORMAT(2, 0) void vwarning(const Loc& loc, const char *format, va_list);
-D_ATTRIBUTE_FORMAT(2, 0) void vwarningSupplemental(const Loc& loc, const char *format, va_list ap);
-D_ATTRIBUTE_FORMAT(2, 0) void vdeprecation(const Loc& loc, const char *format, va_list ap, const char *p1 = NULL, const char *p2 = NULL);
-D_ATTRIBUTE_FORMAT(2, 0) void vdeprecationSupplemental(const Loc& loc, const char *format, va_list ap);
D_ATTRIBUTE_FORMAT(1, 2) void message(const char *format, ...);
D_ATTRIBUTE_FORMAT(2, 3) void message(const Loc& loc, const char *format, ...);
-D_ATTRIBUTE_FORMAT(2, 0) void vmessage(const Loc& loc, const char *format, va_list ap);
D_ATTRIBUTE_FORMAT(1, 2) void tip(const char *format, ...);
-D_ATTRIBUTE_FORMAT(1, 0) void vtip(const char *format, va_list ap);
+
+D_ATTRIBUTE_FORMAT(2, 0) void verrorReport(const Loc& loc, const char *format, va_list ap, const char *p1 = NULL, const char *p2 = NULL);
+D_ATTRIBUTE_FORMAT(2, 0) void verrorReportSupplemental(const Loc& loc, const char* format, va_list ap, ErrorKind kind);
#if defined(__GNUC__) || defined(__clang__)
#define D_ATTRIBUTE_NORETURN __attribute__((noreturn))
void warning(const ref Loc loc, const(char)* format, ...);
+ void warningSupplemental(const ref Loc loc, const(char)* format, ...);
+
void message(const ref Loc loc, const(char)* format, ...);
void deprecation(const ref Loc loc, const(char)* format, ...);
void warning(const ref Loc loc, const(char)* format, ...) { }
+ void warningSupplemental(const ref Loc loc, const(char)* format, ...) { }
+
void message(const ref Loc loc, const(char)* format, ...) { }
void deprecation(const ref Loc loc, const(char)* format, ...) { }
va_end(ap);
}
+ void warningSupplemental(const ref Loc loc, const(char)* format, ...) { }
+
void deprecation(const ref Loc loc, const(char)* format, ...)
{
fputs("Deprecation: ", stderr);
}
// `setUnsafePreview` partially evaluated for dip1000
-private bool setUnsafeDIP1000(Scope* sc, bool gag, Loc loc, const(char)* msg,
+bool setUnsafeDIP1000(Scope* sc, bool gag, Loc loc, const(char)* msg,
RootObject arg0 = null, RootObject arg1 = null, RootObject arg2 = null)
{
return setUnsafePreview(sc, global.params.useDIP1000, gag, loc, msg, arg0, arg1, arg2);
* Returns:
* template for that function, otherwise null
*/
-TemplateDeclaration getFuncTemplateDecl(Dsymbol s)
+TemplateDeclaration getFuncTemplateDecl(Dsymbol s) @safe
{
FuncDeclaration f = s.isFuncDeclaration();
if (f && f.parent)
* true if x1 is x2
* else false
*/
-bool RealIdentical(real_t x1, real_t x2)
+bool RealIdentical(real_t x1, real_t x2) @safe
{
return (CTFloat.isNaN(x1) && CTFloat.isNaN(x2)) || CTFloat.isIdentical(x1, x2);
}
* (foo).size
* cast(foo).size
*/
-DotIdExp typeDotIdExp(const ref Loc loc, Type type, Identifier ident)
+DotIdExp typeDotIdExp(const ref Loc loc, Type type, Identifier ident) @safe
{
return new DotIdExp(loc, new TypeExp(loc, type), ident);
}
Loc loc; // file location
const EXP op; // to minimize use of dynamic_cast
- extern (D) this(const ref Loc loc, EXP op) scope
+ extern (D) this(const ref Loc loc, EXP op) scope @safe
{
//printf("Expression::Expression(op = %d) this = %p\n", op, this);
this.loc = loc;
{
va_list ap;
va_start(ap, format);
- .verror(loc, format, ap);
+ .verrorReport(loc, format, ap, ErrorKind.error);
va_end(ap);
}
}
va_list ap;
va_start(ap, format);
- .verrorSupplemental(loc, format, ap);
+ .verrorReportSupplemental(loc, format, ap, ErrorKind.error);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- .vwarning(loc, format, ap);
+ .verrorReport(loc, format, ap, ErrorKind.warning);
va_end(ap);
}
}
{
va_list ap;
va_start(ap, format);
- .vdeprecation(loc, format, ap);
+ .verrorReport(loc, format, ap, ErrorKind.deprecation);
va_end(ap);
}
}
{
va_list ap;
va_start(ap, format);
- .verror(loc, format, ap);
+ .verrorReport(loc, format, ap, ErrorKind.error);
va_end(ap);
}
}
va_list ap;
va_start(ap, format);
- .verrorSupplemental(loc, format, ap);
+ .verrorReportSupplemental(loc, format, ap, ErrorKind.error);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- .vwarning(loc, format, ap);
+ .verrorReport(loc, format, ap, ErrorKind.warning);
va_end(ap);
}
}
{
va_list ap;
va_start(ap, format);
- .vdeprecation(loc, format, ap);
+ .verrorReport(loc, format, ap, ErrorKind.deprecation);
va_end(ap);
}
}
/**********************************
* Combine e1 and e2 by CommaExp if both are not NULL.
*/
- extern (D) static Expression combine(Expression e1, Expression e2)
+ extern (D) static Expression combine(Expression e1, Expression e2) @safe
{
if (e1)
{
return e1;
}
- extern (D) static Expression combine(Expression e1, Expression e2, Expression e3)
+ extern (D) static Expression combine(Expression e1, Expression e2, Expression e3) @safe
{
return combine(combine(e1, e2), e3);
}
- extern (D) static Expression combine(Expression e1, Expression e2, Expression e3, Expression e4)
+ extern (D) static Expression combine(Expression e1, Expression e2, Expression e3, Expression e4) @safe
{
return combine(combine(e1, e2), combine(e3, e4));
}
* is returned via e0.
* Otherwise 'e' is directly returned and e0 is set to NULL.
*/
- extern (D) static Expression extractLast(Expression e, out Expression e0)
+ extern (D) static Expression extractLast(Expression e, out Expression e0) @safe
{
if (e.op != EXP.comma)
{
else
{
sc.varDecl.storage_class |= STC.system;
+ sc.varDecl.systemInferred = true;
}
}
return false;
{
//printf("checkRightThis sc.intypeof = %d, ad = %p, func = %p, fdthis = %p\n",
// sc.intypeof, sc.getStructClassScope(), func, fdthis);
- error("need `this` for `%s` of type `%s`", ve.var.toChars(), ve.var.type.toChars());
+ auto t = ve.var.isThis();
+ assert(t);
+ error("accessing non-static variable `%s` requires an instance of `%s`", ve.var.toChars(), t.toChars());
return true;
}
}
VarDeclaration var; /// the variable from where the void value came from, null if not known
/// Useful for error messages
- extern (D) this(VarDeclaration var)
+ extern (D) this(VarDeclaration var) @safe
{
super(var.loc, EXP.void_);
this.var = var;
{
real_t value;
- extern (D) this(const ref Loc loc, real_t value, Type type)
+ extern (D) this(const ref Loc loc, real_t value, Type type) @safe
{
super(loc, EXP.float64);
//printf("RealExp::RealExp(%Lg)\n", value);
this.type = type;
}
- static RealExp create(const ref Loc loc, real_t value, Type type)
+ static RealExp create(const ref Loc loc, real_t value, Type type) @safe
{
return new RealExp(loc, value, type);
}
{
complex_t value;
- extern (D) this(const ref Loc loc, complex_t value, Type type)
+ extern (D) this(const ref Loc loc, complex_t value, Type type) @safe
{
super(loc, EXP.complex80);
this.value = value;
//printf("ComplexExp::ComplexExp(%s)\n", toChars());
}
- static ComplexExp create(const ref Loc loc, complex_t value, Type type)
+ static ComplexExp create(const ref Loc loc, complex_t value, Type type) @safe
{
return new ComplexExp(loc, value, type);
}
Identifier ident;
bool parens; // if it appears as (identifier)
- extern (D) this(const ref Loc loc, Identifier ident) scope
+ extern (D) this(const ref Loc loc, Identifier ident) scope @safe
{
super(loc, EXP.identifier);
this.ident = ident;
}
- static IdentifierExp create(const ref Loc loc, Identifier ident)
+ static IdentifierExp create(const ref Loc loc, Identifier ident) @safe
{
return new IdentifierExp(loc, ident);
}
Dsymbol s;
bool hasOverloads;
- extern (D) this(const ref Loc loc, Dsymbol s, bool hasOverloads = true)
+ extern (D) this(const ref Loc loc, Dsymbol s, bool hasOverloads = true) @safe
{
super(loc, EXP.dSymbol);
this.s = s;
{
VarDeclaration var;
- extern (D) this(const ref Loc loc)
+ extern (D) this(const ref Loc loc) @safe
{
super(loc, EXP.this_);
//printf("ThisExp::ThisExp() loc = %d\n", loc.linnum);
}
- this(const ref Loc loc, const EXP tok)
+ this(const ref Loc loc, const EXP tok) @safe
{
super(loc, tok);
//printf("ThisExp::ThisExp() loc = %d\n", loc.linnum);
*/
extern (C++) final class SuperExp : ThisExp
{
- extern (D) this(const ref Loc loc)
+ extern (D) this(const ref Loc loc) @safe
{
super(loc, EXP.super_);
}
*/
extern (C++) final class NullExp : Expression
{
- extern (D) this(const ref Loc loc, Type type = null) scope
+ extern (D) this(const ref Loc loc, Type type = null) scope @safe
{
super(loc, EXP.null_);
this.type = type;
Expressions* exps;
- extern (D) this(const ref Loc loc, Expression e0, Expressions* exps)
+ extern (D) this(const ref Loc loc, Expression e0, Expressions* exps) @safe
{
super(loc, EXP.tuple);
//printf("TupleExp(this = %p)\n", this);
this.exps = exps;
}
- extern (D) this(const ref Loc loc, Expressions* exps)
+ extern (D) this(const ref Loc loc, Expressions* exps) @safe
{
super(loc, EXP.tuple);
//printf("TupleExp(this = %p)\n", this);
}
}
- static TupleExp create(const ref Loc loc, Expressions* exps)
+ static TupleExp create(const ref Loc loc, Expressions* exps) @safe
{
return new TupleExp(loc, exps);
}
Expressions* elements;
- extern (D) this(const ref Loc loc, Type type, Expressions* elements)
+ extern (D) this(const ref Loc loc, Type type, Expressions* elements) @safe
{
super(loc, EXP.arrayLiteral);
this.type = type;
elements.push(e);
}
- extern (D) this(const ref Loc loc, Type type, Expression basis, Expressions* elements)
+ extern (D) this(const ref Loc loc, Type type, Expression basis, Expressions* elements) @safe
{
super(loc, EXP.arrayLiteral);
this.type = type;
this.elements = elements;
}
- static ArrayLiteralExp create(const ref Loc loc, Expressions* elements)
+ static ArrayLiteralExp create(const ref Loc loc, Expressions* elements) @safe
{
return new ArrayLiteralExp(loc, null, elements);
}
Expressions* keys;
Expressions* values;
- extern (D) this(const ref Loc loc, Expressions* keys, Expressions* values)
+ extern (D) this(const ref Loc loc, Expressions* keys, Expressions* values) @safe
{
super(loc, EXP.assocArrayLiteral);
assert(keys.length == values.length);
bool isOriginal = false; /// used when moving instances to indicate `this is this.origin`
OwnedBy ownedByCtfe = OwnedBy.code;
- extern (D) this(const ref Loc loc, StructDeclaration sd, Expressions* elements, Type stype = null)
+ extern (D) this(const ref Loc loc, StructDeclaration sd, Expressions* elements, Type stype = null) @safe
{
super(loc, EXP.structLiteral);
this.sd = sd;
{
Initializer initializer; /// initializer-list
- extern (D) this(const ref Loc loc, Type type_name, Initializer initializer)
+ extern (D) this(const ref Loc loc, Type type_name, Initializer initializer) @safe
{
super(loc, EXP.compoundLiteral);
super.type = type_name;
{
bool parens; // if this is a parenthesized expression
- extern (D) this(const ref Loc loc, Type type)
+ extern (D) this(const ref Loc loc, Type type) @safe
{
super(loc, EXP.type);
//printf("TypeExp::TypeExp(%s)\n", type.toChars());
{
ScopeDsymbol sds;
- extern (D) this(const ref Loc loc, ScopeDsymbol sds)
+ extern (D) this(const ref Loc loc, ScopeDsymbol sds) @safe
{
super(loc, EXP.scope_);
//printf("ScopeExp::ScopeExp(sds = '%s')\n", sds.toChars());
TemplateDeclaration td;
FuncDeclaration fd;
- extern (D) this(const ref Loc loc, TemplateDeclaration td, FuncDeclaration fd = null)
+ extern (D) this(const ref Loc loc, TemplateDeclaration td, FuncDeclaration fd = null) @safe
{
super(loc, EXP.template_);
//printf("TemplateExp(): %s\n", td.toChars());
/// The fields are still separate for backwards compatibility
extern (D) ArgumentList argumentList() { return ArgumentList(arguments, names); }
- extern (D) this(const ref Loc loc, Expression thisexp, Type newtype, Expressions* arguments, Identifiers* names = null)
+ extern (D) this(const ref Loc loc, Expression thisexp, Type newtype, Expressions* arguments, Identifiers* names = null) @safe
{
super(loc, EXP.new_);
this.thisexp = thisexp;
this.names = names;
}
- static NewExp create(const ref Loc loc, Expression thisexp, Type newtype, Expressions* arguments)
+ static NewExp create(const ref Loc loc, Expression thisexp, Type newtype, Expressions* arguments) @safe
{
return new NewExp(loc, thisexp, newtype, arguments);
}
ClassDeclaration cd; // class being instantiated
Expressions* arguments; // Array of Expression's to call class constructor
- extern (D) this(const ref Loc loc, Expression thisexp, ClassDeclaration cd, Expressions* arguments)
+ extern (D) this(const ref Loc loc, Expression thisexp, ClassDeclaration cd, Expressions* arguments) @safe
{
super(loc, EXP.newAnonymousClass);
this.thisexp = thisexp;
Dsymbol originalScope; // original scope before inlining
bool hasOverloads;
- extern (D) this(const ref Loc loc, EXP op, Declaration var, bool hasOverloads)
+ extern (D) this(const ref Loc loc, EXP op, Declaration var, bool hasOverloads) @safe
{
super(loc, op);
assert(var);
// FIXME: This error report will never be handled anyone.
// It should be done before the SymOffExp construction.
if (v.needThis())
- .error(loc, "need `this` for address of `%s`", v.toChars());
+ {
+ auto t = v.isThis();
+ assert(t);
+ .error(loc, "taking the address of non-static variable `%s` requires an instance of `%s`", v.toChars(), t.toChars());
+ }
hasOverloads = false;
}
super(loc, EXP.symbolOffset, var, hasOverloads);
extern (C++) final class VarExp : SymbolExp
{
bool delegateWasExtracted;
- extern (D) this(const ref Loc loc, Declaration var, bool hasOverloads = true)
+ extern (D) this(const ref Loc loc, Declaration var, bool hasOverloads = true) @safe
{
if (var.isVarDeclaration())
hasOverloads = false;
this.type = var.type;
}
- static VarExp create(const ref Loc loc, Declaration var, bool hasOverloads = true)
+ static VarExp create(const ref Loc loc, Declaration var, bool hasOverloads = true) @safe
{
return new VarExp(loc, var, hasOverloads);
}
{
Dsymbol declaration;
- extern (D) this(const ref Loc loc, Dsymbol declaration)
+ extern (D) this(const ref Loc loc, Dsymbol declaration) @safe
{
super(loc, EXP.declaration);
this.declaration = declaration;
{
RootObject obj;
- extern (D) this(const ref Loc loc, RootObject o)
+ extern (D) this(const ref Loc loc, RootObject o) @safe
{
super(loc, EXP.typeid_);
this.obj = o;
Identifier ident;
Objects* args;
- extern (D) this(const ref Loc loc, Identifier ident, Objects* args)
+ extern (D) this(const ref Loc loc, Identifier ident, Objects* args) @safe
{
super(loc, EXP.traits);
this.ident = ident;
*/
extern (C++) final class HaltExp : Expression
{
- extern (D) this(const ref Loc loc)
+ extern (D) this(const ref Loc loc) @safe
{
super(loc, EXP.halt);
}
TOK tok; // ':' or '=='
TOK tok2; // 'struct', 'union', etc.
- extern (D) this(const ref Loc loc, Type targ, Identifier id, TOK tok, Type tspec, TOK tok2, TemplateParameters* parameters) scope
+ extern (D) this(const ref Loc loc, Type targ, Identifier id, TOK tok, Type tspec, TOK tok2, TemplateParameters* parameters) scope @safe
{
super(loc, EXP.is_);
this.targ = targ;
{
Expression e1;
- extern (D) this(const ref Loc loc, EXP op, Expression e1) scope
+ extern (D) this(const ref Loc loc, EXP op, Expression e1) scope @safe
{
super(loc, op);
this.e1 = e1;
Type att1; // Save alias this type to detect recursion
Type att2; // Save alias this type to detect recursion
- extern (D) this(const ref Loc loc, EXP op, Expression e1, Expression e2) scope
+ extern (D) this(const ref Loc loc, EXP op, Expression e1, Expression e2) scope @safe
{
super(loc, op);
this.e1 = e1;
*/
extern (C++) class BinAssignExp : BinExp
{
- extern (D) this(const ref Loc loc, EXP op, Expression e1, Expression e2) scope
+ extern (D) this(const ref Loc loc, EXP op, Expression e1, Expression e2) scope @safe
{
super(loc, op, e1, e2);
}
{
Expressions* exps;
- extern (D) this(const ref Loc loc, Expressions* exps)
+ extern (D) this(const ref Loc loc, Expressions* exps) @safe
{
super(loc, EXP.mixin_);
this.exps = exps;
*/
extern (C++) final class ImportExp : UnaExp
{
- extern (D) this(const ref Loc loc, Expression e)
+ extern (D) this(const ref Loc loc, Expression e) @safe
{
super(loc, EXP.import_, e);
}
{
Expression msg;
- extern (D) this(const ref Loc loc, Expression e, Expression msg = null)
+ extern (D) this(const ref Loc loc, Expression e, Expression msg = null) @safe
{
super(loc, EXP.assert_, e);
this.msg = msg;
bool wantsym; // do not replace Symbol with its initializer during semantic()
bool arrow; // ImportC: if -> instead of .
- extern (D) this(const ref Loc loc, Expression e, Identifier ident)
+ extern (D) this(const ref Loc loc, Expression e, Identifier ident) @safe
{
super(loc, EXP.dotIdentifier, e);
this.ident = ident;
}
- static DotIdExp create(const ref Loc loc, Expression e, Identifier ident)
+ static DotIdExp create(const ref Loc loc, Expression e, Identifier ident) @safe
{
return new DotIdExp(loc, e, ident);
}
{
TemplateDeclaration td;
- extern (D) this(const ref Loc loc, Expression e, TemplateDeclaration td)
+ extern (D) this(const ref Loc loc, Expression e, TemplateDeclaration td) @safe
{
super(loc, EXP.dotTemplateDeclaration, e);
this.td = td;
Declaration var;
bool hasOverloads;
- extern (D) this(const ref Loc loc, Expression e, Declaration var, bool hasOverloads = true)
+ extern (D) this(const ref Loc loc, Expression e, Declaration var, bool hasOverloads = true) @safe
{
if (var.isVarDeclaration())
hasOverloads = false;
this.ti = new TemplateInstance(loc, name, tiargs);
}
- extern (D) this(const ref Loc loc, Expression e, TemplateInstance ti)
+ extern (D) this(const ref Loc loc, Expression e, TemplateInstance ti) @safe
{
super(loc, EXP.dotTemplateInstance, e);
this.ti = ti;
bool hasOverloads;
VarDeclaration vthis2; // container for multi-context
- extern (D) this(const ref Loc loc, Expression e, FuncDeclaration f, bool hasOverloads = true, VarDeclaration vthis2 = null)
+ extern (D) this(const ref Loc loc, Expression e, FuncDeclaration f, bool hasOverloads = true, VarDeclaration vthis2 = null) @safe
{
super(loc, EXP.delegate_, e);
this.func = f;
{
Dsymbol sym; // symbol that represents a type
- extern (D) this(const ref Loc loc, Expression e, Dsymbol s)
+ extern (D) this(const ref Loc loc, Expression e, Dsymbol s) @safe
{
super(loc, EXP.dotType, e);
this.sym = s;
/// The fields are still separate for backwards compatibility
extern (D) ArgumentList argumentList() { return ArgumentList(arguments, names); }
- extern (D) this(const ref Loc loc, Expression e, Expressions* exps, Identifiers* names = null)
+ extern (D) this(const ref Loc loc, Expression e, Expressions* exps, Identifiers* names = null) @safe
{
super(loc, EXP.call, e);
this.arguments = exps;
this.names = names;
}
- extern (D) this(const ref Loc loc, Expression e)
+ extern (D) this(const ref Loc loc, Expression e) @safe
{
super(loc, EXP.call, e);
}
this.f = fd;
}
- static CallExp create(const ref Loc loc, Expression e, Expressions* exps)
+ static CallExp create(const ref Loc loc, Expression e, Expressions* exps) @safe
{
return new CallExp(loc, e, exps);
}
- static CallExp create(const ref Loc loc, Expression e)
+ static CallExp create(const ref Loc loc, Expression e) @safe
{
return new CallExp(loc, e);
}
return null;
}
-FuncDeclaration isFuncAddress(Expression e, bool* hasOverloads = null)
+FuncDeclaration isFuncAddress(Expression e, bool* hasOverloads = null) @safe
{
if (auto ae = e.isAddrExp())
{
*/
extern (C++) final class AddrExp : UnaExp
{
- extern (D) this(const ref Loc loc, Expression e)
+ extern (D) this(const ref Loc loc, Expression e) @safe
{
super(loc, EXP.address, e);
}
- extern (D) this(const ref Loc loc, Expression e, Type t)
+ extern (D) this(const ref Loc loc, Expression e, Type t) @safe
{
this(loc, e);
type = t;
*/
extern (C++) final class PtrExp : UnaExp
{
- extern (D) this(const ref Loc loc, Expression e)
+ extern (D) this(const ref Loc loc, Expression e) @safe
{
super(loc, EXP.star, e);
//if (e.type)
// type = ((TypePointer *)e.type).next;
}
- extern (D) this(const ref Loc loc, Expression e, Type t)
+ extern (D) this(const ref Loc loc, Expression e, Type t) @safe
{
super(loc, EXP.star, e);
type = t;
*/
extern (C++) final class NegExp : UnaExp
{
- extern (D) this(const ref Loc loc, Expression e)
+ extern (D) this(const ref Loc loc, Expression e) @safe
{
super(loc, EXP.negate, e);
}
*/
extern (C++) final class UAddExp : UnaExp
{
- extern (D) this(const ref Loc loc, Expression e) scope
+ extern (D) this(const ref Loc loc, Expression e) scope @safe
{
super(loc, EXP.uadd, e);
}
*/
extern (C++) final class ComExp : UnaExp
{
- extern (D) this(const ref Loc loc, Expression e)
+ extern (D) this(const ref Loc loc, Expression e) @safe
{
super(loc, EXP.tilde, e);
}
*/
extern (C++) final class NotExp : UnaExp
{
- extern (D) this(const ref Loc loc, Expression e)
+ extern (D) this(const ref Loc loc, Expression e) @safe
{
super(loc, EXP.not, e);
}
{
bool isRAII; // true if called automatically as a result of scoped destruction
- extern (D) this(const ref Loc loc, Expression e, bool isRAII)
+ extern (D) this(const ref Loc loc, Expression e, bool isRAII) @safe
{
super(loc, EXP.delete_, e);
this.isRAII = isRAII;
Type to; // type to cast to
ubyte mod = cast(ubyte)~0; // MODxxxxx
- extern (D) this(const ref Loc loc, Expression e, Type t)
+ extern (D) this(const ref Loc loc, Expression e, Type t) @safe
{
super(loc, EXP.cast_, e);
this.to = t;
/* For cast(const) and cast(immutable)
*/
- extern (D) this(const ref Loc loc, Expression e, ubyte mod)
+ extern (D) this(const ref Loc loc, Expression e, ubyte mod) @safe
{
super(loc, EXP.cast_, e);
this.mod = mod;
uint dim = ~0; // number of elements in the vector
OwnedBy ownedByCtfe = OwnedBy.code;
- extern (D) this(const ref Loc loc, Expression e, Type t)
+ extern (D) this(const ref Loc loc, Expression e, Type t) @safe
{
super(loc, EXP.vector, e);
assert(t.ty == Tvector);
to = cast(TypeVector)t;
}
- static VectorExp create(const ref Loc loc, Expression e, Type t)
+ static VectorExp create(const ref Loc loc, Expression e, Type t) @safe
{
return new VectorExp(loc, e, t);
}
*/
extern (C++) final class VectorArrayExp : UnaExp
{
- extern (D) this(const ref Loc loc, Expression e1)
+ extern (D) this(const ref Loc loc, Expression e1) @safe
{
super(loc, EXP.vectorArray, e1);
}
mixin(generateBitFields!(BitFields, ubyte));
/************************************************************/
- extern (D) this(const ref Loc loc, Expression e1, IntervalExp ie)
+ extern (D) this(const ref Loc loc, Expression e1, IntervalExp ie) @safe
{
super(loc, EXP.slice, e1);
this.upr = ie ? ie.upr : null;
this.lwr = ie ? ie.lwr : null;
}
- extern (D) this(const ref Loc loc, Expression e1, Expression lwr, Expression upr)
+ extern (D) this(const ref Loc loc, Expression e1, Expression lwr, Expression upr) @safe
{
super(loc, EXP.slice, e1);
this.upr = upr;
*/
extern (C++) final class ArrayLengthExp : UnaExp
{
- extern (D) this(const ref Loc loc, Expression e1)
+ extern (D) this(const ref Loc loc, Expression e1) @safe
{
super(loc, EXP.arrayLength, e1);
}
arguments.push(index);
}
- extern (D) this(const ref Loc loc, Expression e1, Expressions* args)
+ extern (D) this(const ref Loc loc, Expression e1, Expressions* args) @safe
{
super(loc, EXP.array, e1);
arguments = args;
*/
extern (C++) final class DotExp : BinExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.dot, e1, e2);
}
bool allowCommaExp;
- extern (D) this(const ref Loc loc, Expression e1, Expression e2, bool generated = true)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2, bool generated = true) @safe
{
super(loc, EXP.comma, e1, e2);
allowCommaExp = isGenerated = generated;
* exp = An expression that discards its result.
* If the argument is null or not a CommaExp, nothing happens.
*/
- static void allow(Expression exp)
+ static void allow(Expression exp) @safe
{
if (exp)
if (auto ce = exp.isCommaExp())
Expression lwr;
Expression upr;
- extern (D) this(const ref Loc loc, Expression lwr, Expression upr)
+ extern (D) this(const ref Loc loc, Expression lwr, Expression upr) @safe
{
super(loc, EXP.interval);
this.lwr = lwr;
*/
extern (C++) final class DelegatePtrExp : UnaExp
{
- extern (D) this(const ref Loc loc, Expression e1)
+ extern (D) this(const ref Loc loc, Expression e1) @safe
{
super(loc, EXP.delegatePointer, e1);
}
*/
extern (C++) final class DelegateFuncptrExp : UnaExp
{
- extern (D) this(const ref Loc loc, Expression e1)
+ extern (D) this(const ref Loc loc, Expression e1) @safe
{
super(loc, EXP.delegateFunctionPointer, e1);
}
bool modifiable = false; // assume it is an rvalue
bool indexIsInBounds; // true if 0 <= e2 && e2 <= e1.length - 1
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.index, e1, e2);
//printf("IndexExp::IndexExp('%s')\n", toChars());
}
- extern (D) this(const ref Loc loc, Expression e1, Expression e2, bool indexIsInBounds)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2, bool indexIsInBounds) @safe
{
super(loc, EXP.index, e1, e2);
this.indexIsInBounds = indexIsInBounds;
*/
extern (C++) final class PreExp : UnaExp
{
- extern (D) this(EXP op, const ref Loc loc, Expression e)
+ extern (D) this(EXP op, const ref Loc loc, Expression e) @safe
{
super(loc, op, e);
assert(op == EXP.preMinusMinus || op == EXP.prePlusPlus);
/************************************************************/
/* op can be EXP.assign, EXP.construct, or EXP.blit */
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.assign, e1, e2);
}
- this(const ref Loc loc, EXP tok, Expression e1, Expression e2)
+ this(const ref Loc loc, EXP tok, Expression e1, Expression e2) @safe
{
super(loc, tok, e1, e2);
}
extern (C++) final class LoweredAssignExp : AssignExp
{
Expression lowering;
- extern (D) this(AssignExp exp, Expression lowering)
+ extern (D) this(AssignExp exp, Expression lowering) @safe
{
super(exp.loc, EXP.loweredAssignExp, exp.e1, exp.e2);
this.lowering = lowering;
*/
extern (C++) final class ConstructExp : AssignExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.construct, e1, e2);
}
// Internal use only. If `v` is a reference variable, the assignment
// will become a reference initialization automatically.
- extern (D) this(const ref Loc loc, VarDeclaration v, Expression e2)
+ extern (D) this(const ref Loc loc, VarDeclaration v, Expression e2) @safe
{
auto ve = new VarExp(loc, v);
assert(v.type && ve.type);
*/
extern (C++) final class BlitExp : AssignExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.blit, e1, e2);
}
// Internal use only. If `v` is a reference variable, the assinment
// will become a reference rebinding automatically.
- extern (D) this(const ref Loc loc, VarDeclaration v, Expression e2)
+ extern (D) this(const ref Loc loc, VarDeclaration v, Expression e2) @safe
{
auto ve = new VarExp(loc, v);
assert(v.type && ve.type);
*/
extern (C++) final class AddAssignExp : BinAssignExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.addAssign, e1, e2);
}
*/
extern (C++) final class MinAssignExp : BinAssignExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.minAssign, e1, e2);
}
*/
extern (C++) final class MulAssignExp : BinAssignExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.mulAssign, e1, e2);
}
*/
extern (C++) final class DivAssignExp : BinAssignExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.divAssign, e1, e2);
}
*/
extern (C++) final class ModAssignExp : BinAssignExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.modAssign, e1, e2);
}
*/
extern (C++) final class AndAssignExp : BinAssignExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.andAssign, e1, e2);
}
*/
extern (C++) final class OrAssignExp : BinAssignExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.orAssign, e1, e2);
}
*/
extern (C++) final class XorAssignExp : BinAssignExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.xorAssign, e1, e2);
}
*/
extern (C++) final class PowAssignExp : BinAssignExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.powAssign, e1, e2);
}
*/
extern (C++) final class ShlAssignExp : BinAssignExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.leftShiftAssign, e1, e2);
}
*/
extern (C++) final class ShrAssignExp : BinAssignExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.rightShiftAssign, e1, e2);
}
*/
extern (C++) final class UshrAssignExp : BinAssignExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.unsignedRightShiftAssign, e1, e2);
}
*/
extern (C++) class CatAssignExp : BinAssignExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.concatenateAssign, e1, e2);
}
- extern (D) this(const ref Loc loc, EXP tok, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, EXP tok, Expression e1, Expression e2) @safe
{
super(loc, tok, e1, e2);
}
*/
extern (C++) final class CatElemAssignExp : CatAssignExp
{
- extern (D) this(const ref Loc loc, Type type, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Type type, Expression e1, Expression e2) @safe
{
super(loc, EXP.concatenateElemAssign, e1, e2);
this.type = type;
*/
extern (C++) final class CatDcharAssignExp : CatAssignExp
{
- extern (D) this(const ref Loc loc, Type type, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Type type, Expression e1, Expression e2) @safe
{
super(loc, EXP.concatenateDcharAssign, e1, e2);
this.type = type;
*/
extern (C++) final class AddExp : BinExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.add, e1, e2);
}
*/
extern (C++) final class MinExp : BinExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.min, e1, e2);
}
{
Expression lowering; // call to druntime hook `_d_arraycatnTX`
- extern (D) this(const ref Loc loc, Expression e1, Expression e2) scope
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) scope @safe
{
super(loc, EXP.concatenate, e1, e2);
}
*/
extern (C++) final class MulExp : BinExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.mul, e1, e2);
}
*/
extern (C++) final class DivExp : BinExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.div, e1, e2);
}
*/
extern (C++) final class ModExp : BinExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.mod, e1, e2);
}
*/
extern (C++) final class PowExp : BinExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.pow, e1, e2);
}
*/
extern (C++) final class ShlExp : BinExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.leftShift, e1, e2);
}
*/
extern (C++) final class ShrExp : BinExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.rightShift, e1, e2);
}
*/
extern (C++) final class UshrExp : BinExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.unsignedRightShift, e1, e2);
}
*/
extern (C++) final class AndExp : BinExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.and, e1, e2);
}
*/
extern (C++) final class OrExp : BinExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.or, e1, e2);
}
*/
extern (C++) final class XorExp : BinExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.xor, e1, e2);
}
*/
extern (C++) final class LogicalExp : BinExp
{
- extern (D) this(const ref Loc loc, EXP op, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, EXP op, Expression e1, Expression e2) @safe
{
super(loc, op, e1, e2);
assert(op == EXP.andAnd || op == EXP.orOr);
*/
extern (C++) final class CmpExp : BinExp
{
- extern (D) this(EXP op, const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(EXP op, const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, op, e1, e2);
assert(op == EXP.lessThan || op == EXP.lessOrEqual || op == EXP.greaterThan || op == EXP.greaterOrEqual);
*/
extern (C++) final class InExp : BinExp
{
- extern (D) this(const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, EXP.in_, e1, e2);
}
*/
extern (C++) final class EqualExp : BinExp
{
- extern (D) this(EXP op, const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(EXP op, const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, op, e1, e2);
assert(op == EXP.equal || op == EXP.notEqual);
*/
extern (C++) final class IdentityExp : BinExp
{
- extern (D) this(EXP op, const ref Loc loc, Expression e1, Expression e2)
+ extern (D) this(EXP op, const ref Loc loc, Expression e1, Expression e2) @safe
{
super(loc, op, e1, e2);
assert(op == EXP.identity || op == EXP.notIdentity);
{
Expression econd;
- extern (D) this(const ref Loc loc, Expression econd, Expression e1, Expression e2) scope
+ extern (D) this(const ref Loc loc, Expression econd, Expression e1, Expression e2) scope @safe
{
super(loc, EXP.question, e1, e2);
this.econd = econd;
VarDeclaration vcond;
bool isThen;
- extern (D) this(Scope* sc, CondExp ce)
+ extern (D) this(Scope* sc, CondExp ce) @safe
{
this.sc = sc;
this.ce = ce;
*/
extern (C++) class DefaultInitExp : Expression
{
- extern (D) this(const ref Loc loc, EXP op)
+ extern (D) this(const ref Loc loc, EXP op) @safe
{
super(loc, op);
}
*/
extern (C++) final class FileInitExp : DefaultInitExp
{
- extern (D) this(const ref Loc loc, EXP tok)
+ extern (D) this(const ref Loc loc, EXP tok) @safe
{
super(loc, tok);
}
*/
extern (C++) final class LineInitExp : DefaultInitExp
{
- extern (D) this(const ref Loc loc)
+ extern (D) this(const ref Loc loc) @safe
{
super(loc, EXP.line);
}
*/
extern (C++) final class ModuleInitExp : DefaultInitExp
{
- extern (D) this(const ref Loc loc)
+ extern (D) this(const ref Loc loc) @safe
{
super(loc, EXP.moduleString);
}
*/
extern (C++) final class FuncInitExp : DefaultInitExp
{
- extern (D) this(const ref Loc loc)
+ extern (D) this(const ref Loc loc) @safe
{
super(loc, EXP.functionString);
}
*/
extern (C++) final class PrettyFuncInitExp : DefaultInitExp
{
- extern (D) this(const ref Loc loc)
+ extern (D) this(const ref Loc loc) @safe
{
super(loc, EXP.prettyFunction);
}
Types* types; /// type-names for generic associations (null entry for `default`)
Expressions* exps; /// 1:1 mapping of typeNames to exps
- extern (D) this(const ref Loc loc, Expression cntlExp, Types* types, Expressions* exps)
+ extern (D) this(const ref Loc loc, Expression cntlExp, Types* types, Expressions* exps) @safe
{
super(loc, EXP._Generic);
this.cntlExp = cntlExp;
private:
uint8_t bitFields;
+public:
SliceExp *syntaxCopy() override;
bool isLvalue() override;
Expression *toLvalue(Scope *sc, Expression *e) override;
if (sc.setUnsafePreview(global.params.systemVariables, false, loc,
"cannot access `@system` variable `%s` in @safe code", sd))
{
+ if (auto v = sd.isVarDeclaration())
+ {
+ if (v.systemInferred)
+ errorSupplemental(v.loc, "`%s` is inferred to be `@system` from its initializer here", v.toChars());
+ else
+ errorSupplemental(v.loc, "`%s` is declared here", v.toChars());
+ }
return ErrorExp.get();
}
}
return t0;
}
-private Expression opAssignToOp(const ref Loc loc, EXP op, Expression e1, Expression e2)
+private Expression opAssignToOp(const ref Loc loc, EXP op, Expression e1, Expression e2) @safe
{
Expression e;
switch (op)
Scope* sc;
Expression result;
- this(Scope* sc) scope
+ this(Scope* sc) scope @safe
{
this.sc = sc;
}
result = ErrorExp.get();
}
+ private void needThisError(Loc loc, FuncDeclaration f)
+ {
+ auto t = f.isThis();
+ assert(t);
+ .error(loc, "calling non-static function `%s` requires an instance of type `%s`", f.toChars(), t.toChars());
+ setError();
+ }
+
/**************************
* Semantically analyze Expression.
* Determine types, fold constants, etc.
if (cd.isAbstract())
{
exp.error("cannot create instance of abstract class `%s`", cd.toChars());
+ errorSupplemental(cd.loc, "class `%s` is declared here", cd.toChars());
for (size_t i = 0; i < cd.vtbl.length; i++)
{
FuncDeclaration fd = cd.vtbl[i].isFuncDeclaration();
if (fd && fd.isAbstract())
{
- errorSupplemental(exp.loc, "function `%s` is not implemented",
+ errorSupplemental(fd.loc, "function `%s` is not implemented",
fd.toFullSignature());
}
}
}
else if (isNeedThisScope(sc, exp.f))
{
- exp.error("need `this` for `%s` of type `%s`", exp.f.toChars(), exp.f.type.toChars());
- return setError();
+ return needThisError(exp.loc, exp.f);
}
}
exp.e1 = new VarExp(exp.e1.loc, exp.f, false);
// If no error is printed, it means that `f` is the single matching overload
// and it needs `this`.
- exp.error("need `this` for `%s` of type `%s`", exp.f.toChars(), exp.f.type.toChars());
- return setError();
+ return needThisError(exp.loc, exp.f);
}
}
break;
case TOK.function_:
+ if (e.targ.ty != Tfunction)
+ return no();
+ goto case;
case TOK.parameters:
{
- if (e.targ.ty != Tfunction)
+ if (auto tf = e.targ.isFunction_Delegate_PtrToFunction())
+ tded = tf;
+ else
return no();
- tded = e.targ;
/* Generate tuple from function parameter types.
*/
- assert(tded.ty == Tfunction);
- auto tdedf = tded.isTypeFunction();
auto args = new Parameters();
- foreach (i, arg; tdedf.parameterList)
+ foreach (i, arg; tded.isTypeFunction().parameterList)
{
assert(arg && arg.type);
/* If one of the default arguments was an error,
if (p.token.value != TOK.endOfFile)
{
- exp.error("incomplete mixin expression `%s`", str.ptr);
+ e.error("unexpected token `%s` after %s expression",
+ p.token.toChars(), EXPtoString(e.op).ptr);
+ e.errorSupplemental("while parsing string mixin expression `%s`",
+ str.ptr);
return null;
}
return e;
else
{
OutBuffer buf;
- buf.printf("%s failed", exp.toChars());
+ buf.printf("`%s` failed", exp.toChars());
exp.msg = new StringExp(Loc.initial, buf.extractSlice());
goto LSkip;
}
}
}
OutBuffer buf;
- mangleToBuffer(ds, &buf);
+ mangleToBuffer(ds, buf);
Expression e = new StringExp(loc, buf.extractSlice());
return e.expressionSemantic(sc);
}
alias visit = typeof(super).visit;
extern (D) void delegate(VarDeclaration) dgVar;
- extern (D) this(void delegate(VarDeclaration) dgVar) scope
+ extern (D) this(void delegate(VarDeclaration) dgVar) scope @safe
{
this.dgVar = dgVar;
}
* Returns:
* true found an 'out' contract
*/
- static bool needsFensure(FuncDeclaration fd)
+ static bool needsFensure(FuncDeclaration fd) @safe
{
if (fd.fensures)
return true;
.error(loc, fmt, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "", arg2 ? arg2.toChars() : "");
return true;
}
- else if (!(sc.varDecl.storage_class & STC.system))
+ else if (!(sc.varDecl.storage_class & STC.trusted))
{
sc.varDecl.storage_class |= STC.system;
+ sc.varDecl.systemInferred = true;
}
}
return false;
bool setUnsafePreview(Scope* sc, FeatureState fs, bool gag, Loc loc, const(char)* msg,
RootObject arg0 = null, RootObject arg1 = null, RootObject arg2 = null)
{
+ //printf("setUnsafePreview() fs:%d %s\n", fs, msg);
with (FeatureState) final switch (fs)
{
case disabled:
if (sc.func.isSafeBypassingInference())
{
if (!gag)
- previewErrorFunc(sc.isDeprecated(), fs)(
- loc, msg, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "", arg2 ? arg2.toChars() : ""
- );
+ {
+ if (!sc.isDeprecated() && global.params.obsolete)
+ warning(loc, msg, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "", arg2 ? arg2.toChars() : "");
+ }
}
else if (!sc.func.safetyViolation)
{
s.arg0 ? s.arg0.toChars() : "", s.arg1 ? s.arg1.toChars() : "", s.arg2 ? s.arg2.toChars() : "");
}
}
- else if (s.arg0.dyncast() == DYNCAST.dsymbol)
+ else if (auto sa = s.arg0.isDsymbol())
{
- if (FuncDeclaration fd2 = (cast(Dsymbol) s.arg0).isFuncDeclaration())
+ if (FuncDeclaration fd2 = sa.isFuncDeclaration())
{
if (maxDepth > 0)
{
bool useModuleInfo = true; // generate runtime module information
bool useTypeInfo = true; // generate runtime type information
bool useExceptions = true; // support exception handling
- bool useGC = true; // support features that require the GC
+ bool useGC = true; // support features that require the D runtime GC
bool betterC; // be a "better C" compiler; no dependency on D runtime
bool addMain; // add a default main() function
bool allInst; // generate code for all template instantiations
*
* Returns: the current number of gagged errors, which should later be passed to `endGagging`
*/
- extern (C++) uint startGagging()
+ extern (C++) uint startGagging() @safe
{
++gag;
gaggedWarnings = 0;
* oldGagged = the previous number of errors, as returned by `startGagging`
* Returns: true if errors occurred while gagged.
*/
- extern (C++) bool endGagging(uint oldGagged)
+ extern (C++) bool endGagging(uint oldGagged) @safe
{
bool anyErrs = (gaggedErrors != oldGagged);
--gag;
*
* An error message may or may not have been printed.
*/
- extern (C++) void increaseErrorCount()
+ extern (C++) void increaseErrorCount() @safe
{
if (gag)
++gaggedErrors;
compileEnv.vendor = "Digital Mars D";
// -color=auto is the default value
- import dmd.console : detectTerminal;
- params.color = detectTerminal();
+ import dmd.console : detectTerminal, detectColorPreference;
+ params.color = detectTerminal() && detectColorPreference();
}
else version (IN_GCC)
{
/**
* Computes the version number __VERSION__ from the compiler version string.
*/
- extern (D) private static uint parseVersionNumber(string version_)
+ extern (D) private static uint parseVersionNumber(string version_) @safe
{
//
// parse _version
/**
Returns: the version as the number that would be returned for __VERSION__
*/
- extern(C++) uint versionNumber()
+ extern(C++) uint versionNumber() @safe
{
return compileEnv.versionNumber;
}
/**
Returns: compiler version string.
*/
- extern(D) string versionString()
+ extern(D) string versionString() @safe
{
return _version;
}
d_bool useModuleInfo; // generate runtime module information
d_bool useTypeInfo; // generate runtime type information
d_bool useExceptions; // support exception handling
- d_bool useGC; // support features that require the GC
+ d_bool useGC; // support features that require the D runtime GC
d_bool betterC; // be a "better C" compiler; no dependency on D runtime
d_bool addMain; // add a default main() function
d_bool allInst; // generate code for all template instantiations
OutBuffer* buf;
HdrGenState* hgs;
- extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope
+ extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope @safe
{
this.buf = buf;
this.hgs = hgs;
OutBuffer* buf;
HdrGenState* hgs;
- extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope
+ extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope @safe
{
this.buf = buf;
this.hgs = hgs;
OutBuffer* buf;
HdrGenState* hgs;
- extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope
+ extern (D) this(OutBuffer* buf, HdrGenState* hgs) scope @safe
{
this.buf = buf;
this.hgs = hgs;
initializerToBuffer(cast() iz, buf, hgs);
}
-bool stcToBuffer(OutBuffer* buf, StorageClass stc)
+bool stcToBuffer(OutBuffer* buf, StorageClass stc) @safe
{
//printf("stc: %llx\n", stc);
bool result = false;
* and return a string representation of it.
* stc is reduced by the one picked.
*/
-string stcToString(ref StorageClass stc)
+string stcToString(ref StorageClass stc) @safe
{
static struct SCstring
{
return null;
}
-private void linkageToBuffer(OutBuffer* buf, LINK linkage)
+private void linkageToBuffer(OutBuffer* buf, LINK linkage) @safe
{
const s = linkageToString(linkage);
if (s.length)
return linkageToString(linkage).ptr;
}
-string linkageToString(LINK linkage) pure nothrow
+string linkageToString(LINK linkage) pure nothrow @safe
{
final switch (linkage)
{
}
/// Ditto
-extern (D) string visibilityToString(Visibility.Kind kind) nothrow pure
+extern (D) string visibilityToString(Visibility.Kind kind) nothrow pure @safe
{
final switch (kind)
{
* Returns: the name to use in the D executable, `name_` if non-empty,
* otherwise `ident`
*/
- string name()
+ string name() @safe
{
return name_ ? name_ : ident;
}
}
// Used to generate the code for each identifier.
-string identifier(Msgtable m)
+string identifier(Msgtable m) @safe
{
return "Identifier " ~ m.ident ~ ";";
}
// Used to generate the code for each initializer.
-string initializer(Msgtable m)
+string initializer(Msgtable m) @safe
{
return m.ident ~ ` = Identifier.idPool("` ~ m.name ~ `");`;
}
// Used to generate the code for each deinitializer.
-string deinitializer(Msgtable m)
+string deinitializer(Msgtable m) @safe
{
return m.ident ~ " = Identifier.init;";
}
}
/// ditto
- extern (D) this(const(char)[] name, int value)
+ extern (D) this(const(char)[] name, int value) @safe
{
//printf("Identifier('%.*s', %d)\n", cast(int)name.length, name.ptr, value);
this(name, value, false);
}
- extern (D) private this(const(char)[] name, int value, bool isAnonymous)
+ extern (D) private this(const(char)[] name, int value, bool isAnonymous) @safe
{
//printf("Identifier('%.*s', %d, %d)\n", cast(int)name.length, name.ptr, value, isAnonymous);
this.name = name;
/**********************************
* ditto
*/
- extern (D) static bool isValidIdentifier(const(char)[] str)
+ extern (D) static bool isValidIdentifier(const(char)[] str) @safe
{
if (str.length == 0 ||
(str[0] >= '0' && str[0] <= '9')) // beware of isdigit() on signed chars
* Not meant to be a comprehensive list of names in each module,
* just the most common ones.
*/
-const(char)[] importHint(const(char)[] s)
+const(char)[] importHint(const(char)[] s) @safe
{
if (auto entry = s in hints)
return *entry;
}
- extern (D) this(const ref Loc loc, InitKind kind)
+ extern (D) this(const ref Loc loc, InitKind kind) @safe
{
this.loc = loc;
this.kind = kind;
{
Type type; // type that this will initialize to
- extern (D) this(const ref Loc loc)
+ extern (D) this(const ref Loc loc) @safe
{
super(loc, InitKind.void_);
}
*/
extern (C++) final class ErrorInitializer : Initializer
{
- extern (D) this()
+ extern (D) this() @safe
{
super(Loc.initial, InitKind.error);
}
bool expandTuples;
Expression exp;
- extern (D) this(const ref Loc loc, Expression exp)
+ extern (D) this(const ref Loc loc, Expression exp) @safe
{
super(loc, InitKind.exp);
this.exp = exp;
Expression exp; /// [ constant-expression ]
Identifier ident; /// . identifier
- this(Expression exp) { this.exp = exp; }
- this(Identifier ident) { this.ident = ident; }
+ this(Expression exp) @safe { this.exp = exp; }
+ this(Identifier ident) @safe { this.ident = ident; }
}
/*********************************************
* handler = string for the name of the visit handler
* Returns: boilerplate code for a case
*/
-pure string visitCase(string handler)
+string visitCase(string handler) pure @safe
{
if (__ctfe)
{
import dmd.expression;
import dmd.globals;
-private uinteger_t copySign(uinteger_t x, bool sign)
+private uinteger_t copySign(uinteger_t x, bool sign) @safe
{
// return sign ? -x : x;
return (x - cast(uinteger_t)sign) ^ -cast(uinteger_t)sign;
uinteger_t value;
bool negative;
- static SignExtendedNumber fromInteger(uinteger_t value_)
+ static SignExtendedNumber fromInteger(uinteger_t value_) @safe
{
return SignExtendedNumber(value_, value_ >> 63);
}
- static SignExtendedNumber extreme(bool minimum)
+ static SignExtendedNumber extreme(bool minimum) @safe
{
return SignExtendedNumber(minimum - 1, minimum);
}
- static SignExtendedNumber max()
+ static SignExtendedNumber max() @safe
{
return SignExtendedNumber(ulong.max, false);
}
- static SignExtendedNumber min()
+ static SignExtendedNumber min() @safe
{
return SignExtendedNumber(0, true);
}
- bool isMinimum() const
+ bool isMinimum() const @safe
{
return negative && value == 0;
}
- bool opEquals(const ref SignExtendedNumber a) const
+ bool opEquals(const ref SignExtendedNumber a) const @safe
{
return value == a.value && negative == a.negative;
}
- int opCmp(const ref SignExtendedNumber a) const
+ int opCmp(const ref SignExtendedNumber a) const @safe
{
if (negative != a.negative)
{
{
SignExtendedNumber imin, imax;
- this(IntRange another)
+ this(IntRange another) @safe
{
imin = another.imin;
imax = another.imax;
}
- this(SignExtendedNumber a)
+ this(SignExtendedNumber a) @safe
{
imin = a;
imax = a;
}
- this(SignExtendedNumber lower, SignExtendedNumber upper)
+ this(SignExtendedNumber lower, SignExtendedNumber upper) @safe
{
imin = lower;
imax = upper;
return ab;
}
- static IntRange widest()
+ static IntRange widest() @safe
{
return IntRange(SignExtendedNumber.min(), SignExtendedNumber.max());
}
- IntRange castSigned(uinteger_t mask)
+ IntRange castSigned(uinteger_t mask) @safe
{
// .... 0x1e7f ] [0x1e80 .. 0x1f7f] [0x1f80 .. 0x7f] [0x80 .. 0x17f] [0x180 ....
//
return this;
}
- IntRange castUnsigned(uinteger_t mask)
+ IntRange castUnsigned(uinteger_t mask) @safe
{
// .... 0x1eff ] [0x1f00 .. 0x1fff] [0 .. 0xff] [0x100 .. 0x1ff] [0x200 ....
//
return this;
}
- IntRange castDchar()
+ IntRange castDchar() @safe
{
// special case for dchar. Casting to dchar means "I'll ignore all
// invalid characters."
return castUnsigned(type.sizemask());
}
- bool contains(IntRange a)
+ bool contains(IntRange a) @safe
{
return imin <= a.imin && imax >= a.imax;
}
- bool containsZero() const
+ bool containsZero() const @safe
{
return (imin.negative && !imax.negative)
|| (!imin.negative && imin.value == 0);
}
- IntRange absNeg() const
+ IntRange absNeg() const @safe
{
if (imax.negative)
return this;
}
}
- IntRange unionWith(const ref IntRange other) const
+ IntRange unionWith(const ref IntRange other) const @safe
{
return IntRange(imin < other.imin ? imin : other.imin,
imax > other.imax ? imax : other.imax);
}
- void unionOrAssign(IntRange other, ref bool union_)
+ void unionOrAssign(IntRange other, ref bool union_) @safe
{
if (!union_ || imin > other.imin)
imin = other.imin;
return this;
}
- void splitBySign(ref IntRange negRange, ref bool hasNegRange, ref IntRange nonNegRange, ref bool hasNonNegRange) const
+ void splitBySign(ref IntRange negRange, ref bool hasNegRange, ref IntRange nonNegRange, ref bool hasNonNegRange) const @safe
{
hasNegRange = imin.negative;
if (hasNegRange)
private:
// Credits to Timon Gehr maxOr, minOr, maxAnd, minAnd
// https://github.com/tgehr/d-compiler/blob/master/vrange.d
- static SignExtendedNumber maxOr(const IntRange lhs, const IntRange rhs)
+ static SignExtendedNumber maxOr(const IntRange lhs, const IntRange rhs) @safe
{
uinteger_t x = 0;
auto sign = false;
// Credits to Timon Gehr maxOr, minOr, maxAnd, minAnd
// https://github.com/tgehr/d-compiler/blob/master/vrange.d
- static SignExtendedNumber minOr(const IntRange lhs, const IntRange rhs)
+ static SignExtendedNumber minOr(const IntRange lhs, const IntRange rhs) @safe
{
return ~maxAnd(~lhs, ~rhs);
}
// Credits to Timon Gehr maxOr, minOr, maxAnd, minAnd
// https://github.com/tgehr/d-compiler/blob/master/vrange.d
- static SignExtendedNumber maxAnd(const IntRange lhs, const IntRange rhs)
+ static SignExtendedNumber maxAnd(const IntRange lhs, const IntRange rhs) @safe
{
uinteger_t x = 0;
bool sign = false;
// Credits to Timon Gehr maxOr, minOr, maxAnd, minAnd
// https://github.com/tgehr/d-compiler/blob/master/vrange.d
- static SignExtendedNumber minAnd(const IntRange lhs, const IntRange rhs)
+ static SignExtendedNumber minAnd(const IntRange lhs, const IntRange rhs) @safe
{
return ~maxOr(~lhs, ~rhs);
}
int indentLevel;
const(char)[] filename;
- extern (D) this(OutBuffer* buf) scope
+ extern (D) this(OutBuffer* buf) scope @safe
{
this.buf = buf;
}
if (s)
{
OutBuffer mangledName;
- mangleToBuffer(s, &mangledName);
+ mangleToBuffer(s, mangledName);
buf.writestring(mangledName[]);
buf.writeByte('_');
}
/******************
* Used for unittests for a mock Lexer
*/
- this(ErrorSink errorSink) scope { assert(errorSink); this.eSink = errorSink; }
+ this(ErrorSink errorSink) scope @safe { assert(errorSink); this.eSink = errorSink; }
/**************************************
* Reset lexer to lex #define's
this.messageStyle = messageStyle;
}
- extern (D) this(const(char)* filename, uint linnum, uint charnum)
+ extern (D) this(const(char)* filename, uint linnum, uint charnum) @safe
{
this._linnum = linnum;
this._charnum = cast(ushort) charnum;
* Params:
* name = file name for location, null for no file name
*/
- extern (C++) void filename(const(char)* name)
+ extern (C++) void filename(const(char)* name) @trusted
{
if (name)
{
* Returns:
* true if Loc has been set to other than the default initialization
*/
- bool isValid() const pure
+ bool isValid() const pure @safe
{
return fileIndex != 0;
}
// In dmangle.d
const char *mangleExact(FuncDeclaration *fd);
-void mangleToBuffer(Type *s, OutBuffer *buf);
-void mangleToBuffer(Expression *s, OutBuffer *buf);
-void mangleToBuffer(Dsymbol *s, OutBuffer *buf);
-void mangleToBuffer(TemplateInstance *s, OutBuffer *buf);
+void mangleToBuffer(Type *s, OutBuffer& buf);
+void mangleToBuffer(Expression *s, OutBuffer& buf);
+void mangleToBuffer(Dsymbol *s, OutBuffer& buf);
+void mangleToBuffer(TemplateInstance *s, OutBuffer& buf);
/*********************************
* Store modifier name into buf.
*/
-void MODtoBuffer(OutBuffer* buf, MOD mod) nothrow
+void MODtoBuffer(OutBuffer* buf, MOD mod) nothrow @safe
{
buf.writestring(MODtoString(mod));
}
}
/// Ditto
-string MODtoString(MOD mod) nothrow pure
+string MODtoString(MOD mod) nothrow pure @safe
{
final switch (mod)
{
return sizeTy;
}();
- final extern (D) this(TY ty) scope
+ final extern (D) this(TY ty) scope @safe
{
this.ty = ty;
}
// _init_10TypeInfo_%s
OutBuffer buf;
buf.reserve(32);
- mangleToBuffer(this, &buf);
+ mangleToBuffer(this, buf);
const slice = buf[];
*/
extern (C++) final class TypeError : Type
{
- extern (D) this()
+ extern (D) this() @safe
{
super(Terror);
}
{
Type next;
- final extern (D) this(TY ty, Type next)
+ final extern (D) this(TY ty, Type next) @safe
{
super(ty);
this.next = next;
{
Type basetype;
- extern (D) this(Type basetype)
+ extern (D) this(Type basetype) @safe
{
super(Tvector);
this.basetype = basetype;
}
- static TypeVector create(Type basetype)
+ static TypeVector create(Type basetype) @safe
{
return new TypeVector(basetype);
}
*/
extern (C++) abstract class TypeArray : TypeNext
{
- final extern (D) this(TY ty, Type next)
+ final extern (D) this(TY ty, Type next) @safe
{
super(ty, next);
}
{
Expression dim;
- extern (D) this(Type t, Expression dim)
+ extern (D) this(Type t, Expression dim) @safe
{
super(Tsarray, t);
//printf("TypeSArray(%s)\n", dim.toChars());
*/
extern (C++) final class TypeDArray : TypeArray
{
- extern (D) this(Type t)
+ extern (D) this(Type t) @safe
{
super(Tarray, t);
//printf("TypeDArray(t = %p)\n", t);
Type index; // key type
Loc loc;
- extern (D) this(Type t, Type index)
+ extern (D) this(Type t, Type index) @safe
{
super(Taarray, t);
this.index = index;
}
- static TypeAArray create(Type t, Type index)
+ static TypeAArray create(Type t, Type index) @safe
{
return new TypeAArray(t, index);
}
*/
extern (C++) final class TypePointer : TypeNext
{
- extern (D) this(Type t)
+ extern (D) this(Type t) @safe
{
super(Tpointer, t);
}
- static TypePointer create(Type t)
+ static TypePointer create(Type t) @safe
{
return new TypePointer(t);
}
*/
extern (C++) final class TypeReference : TypeNext
{
- extern (D) this(Type t)
+ extern (D) this(Type t) @safe
{
super(Treference, t);
// BUG: what about references to static arrays?
byte inuse;
Expressions* fargs; // function arguments
- extern (D) this(ParameterList pl, Type treturn, LINK linkage, StorageClass stc = 0)
+ extern (D) this(ParameterList pl, Type treturn, LINK linkage, StorageClass stc = 0) @safe
{
super(Tfunction, treturn);
//if (!treturn) *(char*)0=0;
this.trust = TRUST.trusted;
}
- static TypeFunction create(Parameters* parameters, Type treturn, ubyte varargs, LINK linkage, StorageClass stc = 0)
+ static TypeFunction create(Parameters* parameters, Type treturn, ubyte varargs, LINK linkage, StorageClass stc = 0) @safe
{
return new TypeFunction(ParameterList(parameters, cast(VarArg)varargs), treturn, linkage, stc);
}
{
// .next is a TypeFunction
- extern (D) this(TypeFunction t)
+ extern (D) this(TypeFunction t) @safe
{
super(Tfunction, t);
ty = Tdelegate;
}
- static TypeDelegate create(TypeFunction t)
+ static TypeDelegate create(TypeFunction t) @safe
{
return new TypeDelegate(t);
}
/// Cached type/symbol after semantic analysis.
RootObject obj;
- final extern (D) this(const ref Loc loc, TraitsExp exp)
+ final extern (D) this(const ref Loc loc, TraitsExp exp) @safe
{
super(Ttraits);
this.loc = loc;
Expressions* exps;
RootObject obj; // cached result of semantic analysis.
- extern (D) this(const ref Loc loc, Expressions* exps)
+ extern (D) this(const ref Loc loc, Expressions* exps) @safe
{
super(Tmixin);
this.loc = loc;
AliasThisRec att = AliasThisRec.fwdref;
bool inuse = false; // struct currently subject of recursive method call
- extern (D) this(StructDeclaration sym)
+ extern (D) this(StructDeclaration sym) @safe
{
super(Tstruct);
this.sym = sym;
}
- static TypeStruct create(StructDeclaration sym)
+ static TypeStruct create(StructDeclaration sym) @safe
{
return new TypeStruct(sym);
}
{
EnumDeclaration sym;
- extern (D) this(EnumDeclaration sym)
+ extern (D) this(EnumDeclaration sym) @safe
{
super(Tenum);
this.sym = sym;
AliasThisRec att = AliasThisRec.fwdref;
CPPMANGLE cppmangle = CPPMANGLE.def;
- extern (D) this(ClassDeclaration sym)
+ extern (D) this(ClassDeclaration sym) @safe
{
super(Tclass);
this.sym = sym;
Parameters* arguments; // types making up the tuple
- extern (D) this(Parameters* arguments)
+ extern (D) this(Parameters* arguments) @safe
{
super(Ttuple);
//printf("TypeTuple(this = %p)\n", this);
//printf("TypeTuple() %p, %s\n", this, toChars());
}
- static TypeTuple create(Parameters* arguments)
+ static TypeTuple create(Parameters* arguments) @safe
{
return new TypeTuple(arguments);
}
/*******************************************
* Type tuple with 0, 1 or 2 types in it.
*/
- extern (D) this()
+ extern (D) this() @safe
{
super(Ttuple);
arguments = new Parameters();
arguments.push(new Parameter(0, t2, null, null, null));
}
- static TypeTuple create()
+ static TypeTuple create() @safe
{
return new TypeTuple();
}
Expression lwr;
Expression upr;
- extern (D) this(Type next, Expression lwr, Expression upr)
+ extern (D) this(Type next, Expression lwr, Expression upr) @safe
{
super(Tslice, next);
//printf("TypeSlice[%s .. %s]\n", lwr.toChars(), upr.toChars());
*/
extern (C++) final class TypeNull : Type
{
- extern (D) this()
+ extern (D) this() @safe
{
//printf("TypeNull %p\n", this);
super(Tnull);
*/
extern (C++) final class TypeNoreturn : Type
{
- extern (D) this()
+ extern (D) this() @safe
{
//printf("TypeNoreturn %p\n", this);
super(Tnoreturn);
/// struct S { int a; } s1, *s2;
MOD mod; /// modifiers to apply after type is resolved (only MODFlags.const_ at the moment)
- extern (D) this(const ref Loc loc, TOK tok, Identifier id, structalign_t packalign, Type base, Dsymbols* members)
+ extern (D) this(const ref Loc loc, TOK tok, Identifier id, structalign_t packalign, Type base, Dsymbols* members) @safe
{
//printf("TypeTag ctor %s %p\n", id ? id.toChars() : "null".ptr, this);
super(Ttag);
VarArg varargs = VarArg.none;
bool hasIdentifierList; // true if C identifier-list style
- this(Parameters* parameters, VarArg varargs = VarArg.none, StorageClass stc = 0)
+ this(Parameters* parameters, VarArg varargs = VarArg.none, StorageClass stc = 0) @safe
{
this.parameters = parameters;
this.varargs = varargs;
Expression defaultArg;
UserAttributeDeclaration userAttribDecl; // user defined attributes
- extern (D) this(StorageClass storageClass, Type type, Identifier ident, Expression defaultArg, UserAttributeDeclaration userAttribDecl)
+ extern (D) this(StorageClass storageClass, Type type, Identifier ident, Expression defaultArg, UserAttributeDeclaration userAttribDecl) @safe
{
this.type = type;
this.ident = ident;
this.userAttribDecl = userAttribDecl;
}
- static Parameter create(StorageClass storageClass, Type type, Identifier ident, Expression defaultArg, UserAttributeDeclaration userAttribDecl)
+ static Parameter create(StorageClass storageClass, Type type, Identifier ident, Expression defaultArg, UserAttributeDeclaration userAttribDecl) @safe
{
return new Parameter(storageClass, type, ident, defaultArg, userAttribDecl);
}
* handler = string for the name of the visit handler
* Returns: boilerplate code for a case
*/
-pure string visitTYCase(string handler)
+pure string visitTYCase(string handler) @safe
{
if (__ctfe)
{
{
VARARGnone = 0, /// fixed number of arguments
VARARGvariadic = 1, /// T t, ...) can be C-style (core.stdc.stdarg) or D-style (core.vararg)
- VARARGtypesafe = 2 /// T t ...) typesafe https://dlang.org/spec/function.html#typesafe_variadic_functions
+ VARARGtypesafe = 2, /// T t ...) typesafe https://dlang.org/spec/function.html#typesafe_variadic_functions
/// or https://dlang.org/spec/function.html#typesafe_variadic_functions
+ VARARGKRvariadic = 3 /// K+R C style variadics (no function prototype)
};
typedef unsigned char VarArg;
import dmd.location;
// Used in isIncrementOrDecrement
-private static const StringExp plusPlus, minusMinus;
+private const StringExp plusPlus, minusMinus;
// Loc.initial cannot be used in static initializers, so
// these need a static constructor.
-static this()
+shared static this()
{
plusPlus = new StringExp(Loc.initial, "++");
minusMinus = new StringExp(Loc.initial, "--");
import dmd.astenums;
import dmd.declaration;
import dmd.dscope;
+import dmd.dtemplate : isDsymbol;
import dmd.errors;
import dmd.expression;
import dmd.func;
bool checkOnly; // don't print errors
bool err;
- extern (D) this(FuncDeclaration f) scope
+ extern (D) this(FuncDeclaration f) scope @safe
{
this.f = f;
}
// Get the Hook from the second template parameter
auto templateInstance = fd.parent.isTemplateInstance;
RootObject hook = (*templateInstance.tiargs)[1];
- assert(hook.dyncast() == DYNCAST.dsymbol, "Expected _d_HookTraceImpl's second template parameter to be an alias to the hook!");
- return (cast(Dsymbol)hook).isFuncDeclaration;
+ Dsymbol s = hook.isDsymbol();
+ assert(s, "Expected _d_HookTraceImpl's second template parameter to be an alias to the hook!");
+ return s.isFuncDeclaration;
}
fend,
}
-string toString(ObType obtype)
+string toString(ObType obtype) @safe
{
return obtype == ObType.goto_ ? "goto " :
obtype == ObType.return_ ? "ret " :
return toString(state).ptr;
}
-string toString(PtrState state)
+string toString(PtrState state) @safe
{
return ["Initial", "Undefined", "Owner", "Borrowed", "Readonly"][state];
}
* Set the `index` field of each ObNode
* to its index in the `obnodes[]` array.
*/
-void numberNodes(ref ObNodes obnodes)
+void numberNodes(ref ObNodes obnodes) @safe
{
//printf("numberNodes()\n");
foreach (i, ob; obnodes)
stringtable._init();
}
- extern (D) this(const(char)* sv, size_t len, size_t pcount)
+ extern (D) this(const(char)* sv, size_t len, size_t pcount) @safe
{
stringvalue = sv;
stringlen = len;
buf.writeByte('_');
foreach (i, fparam; ftype.parameterList)
{
- mangleToBuffer(fparam.type, &buf);
+ mangleToBuffer(fparam.type, buf);
buf.writeByte(':');
}
}
/// List of non-inherited methods.
FuncDeclaration[] methodList;
- extern (D) this(ClassDeclaration classDeclaration)
+ extern (D) this(ClassDeclaration classDeclaration) @safe
{
this.classDeclaration = classDeclaration;
}
- bool isRootClass() const
+ bool isRootClass() const @safe
{
return classDeclaration.classKind == ClassKind.objc &&
!metaclass &&
* Determine if operands of binary op can be reversed
* to fit operator overload.
*/
-bool isCommutative(EXP op)
+bool isCommutative(EXP op) @safe
{
switch (op)
{
* Returns:
* reverse of op
*/
-private EXP reverseRelation(EXP op) pure
+private EXP reverseRelation(EXP op) pure @safe
{
switch (op)
{
(orig & STC.scope_) ? "scope".ptr : "ref".ptr);
}
else if (added & STC.ref_)
- deprecation("using `in ref` is deprecated, use `-preview=in` and `in` instead");
+ {
+ // accept for legacy compatibility
+ //deprecation("using `in ref` is deprecated, use `-preview=in` and `in` instead");
+ }
else
error("attribute `scope` cannot be applied with `in`, use `-preview=in` instead");
return orig;
stc_str, stc_str);
}
else if (orig & STC.ref_)
- deprecation("using `ref in` is deprecated, use `-preview=in` and `in` instead");
+ {
+ // accept for legacy compatibility
+ //deprecation("using `in ref` is deprecated, use `-preview=in` and `in` instead");
+ }
else
error("attribute `in` cannot be added after `scope`: remove `scope` and use `-preview=in`");
return orig;
else if (token.value == TOK.leftCurly)
{
bool isAnonymousEnum = !id;
- TOK prevTOK;
//printf("enum definition\n");
e.members = new AST.Dsymbols();
StorageClass stc;
AST.Expression deprecationMessage;
enum attributeErrorMessage = "`%s` is not a valid attribute for enum members";
- while(token.value != TOK.rightCurly
- && token.value != TOK.comma
- && token.value != TOK.assign)
+ Lattrs:
+ while (1)
{
switch (token.value)
{
AST.stcToBuffer(&buf, _stc);
error(attributeErrorMessage, buf.peekChars());
}
- prevTOK = token.value;
nextToken();
}
break;
stc |= STC.deprecated_;
if (!parseDeprecatedAttribute(deprecationMessage))
{
- prevTOK = token.value;
- nextToken();
- }
- break;
- case TOK.identifier:
- const tv = peekNext();
- if (tv == TOK.assign || tv == TOK.comma || tv == TOK.rightCurly)
- {
- ident = token.ident;
- type = null;
- prevTOK = token.value;
nextToken();
}
- else
- {
- if (isAnonymousEnum)
- goto default; // maybe `Type identifier`
-
- prevTOK = token.value;
- nextToken();
- error("expected `,` or `=` after identifier, not `%s`", token.toChars());
- }
break;
default:
- if (isAnonymousEnum)
- {
- if (type)
- {
- error("expected identifier after type, not `%s`", token.toChars());
- type = null;
- break;
- }
- type = parseType(&ident, null);
- if (type == AST.Type.terror)
- {
- type = null;
- prevTOK = token.value;
- nextToken();
- }
- else
- {
- prevTOK = TOK.identifier;
- const tv = token.value;
- if (ident && tv != TOK.assign && tv != TOK.comma && tv != TOK.rightCurly)
- {
- error("expected `,` or `=` after identifier, not `%s`", token.toChars());
- }
- }
- }
- else
- {
- error(attributeErrorMessage, token.toChars());
- prevTOK = token.value;
- nextToken();
- }
- break;
+ break Lattrs;
}
- if (token.value == TOK.comma)
+ }
+ if (token.value == TOK.identifier)
+ {
+ const tv = peekNext();
+ if (tv == TOK.assign || tv == TOK.comma || tv == TOK.rightCurly)
{
- prevTOK = token.value;
+ ident = token.ident;
+ type = null;
+ nextToken();
}
- }
+ else
+ {
+ if (isAnonymousEnum)
+ goto Ltype;
- if (type && type != AST.Type.terror)
- {
- if (!ident)
- error("no identifier for declarator `%s`", type.toChars());
- if (!isAnonymousEnum)
- error("type only allowed if anonymous enum and no enum type");
+ nextToken();
+ error("expected `,` or `=` after identifier, not `%s`", token.toChars());
+ }
}
- AST.Expression value;
- if (token.value == TOK.assign)
+ else
{
- if (prevTOK == TOK.identifier)
+ if (isAnonymousEnum)
{
- nextToken();
- value = parseAssignExp();
+ Ltype:
+ // Type identifier
+ type = parseType(&ident, null);
+ if (type == AST.Type.terror)
+ {
+ type = null;
+ nextToken();
+ }
+ else if (!ident)
+ {
+ error("no identifier for declarator `%s`", type.toChars());
+ type = null;
+ }
+ else
+ {
+ const tv = token.value;
+ if (tv != TOK.assign && tv != TOK.comma && tv != TOK.rightCurly)
+ {
+ error("expected `,` or `=` after identifier, not `%s`", token.toChars());
+ nextToken();
+ }
+ }
}
else
{
- error("assignment must be preceded by an identifier");
- nextToken();
+ Token* t = &token;
+ if (isBasicType(&t))
+ {
+ error("named enum cannot declare member with type", (*t).toChars());
+ nextToken();
+ }
+ else
+ check(TOK.identifier);
+
+ // avoid extra error messages
+ const tv = token.value;
+ if (tv != TOK.assign && tv != TOK.comma && tv != TOK.rightCurly && tv != TOK.endOfFile)
+ continue;
}
}
+
+ AST.Expression value;
+ if (token.value == TOK.assign)
+ {
+ nextToken();
+ value = parseAssignExp();
+ }
else
{
value = null;
- if (type && type != AST.Type.terror && isAnonymousEnum)
+ if (type && isAnonymousEnum)
error("initializer required after `%s` when type is specified", ident.toChars());
}
em.userAttribDecl = uad;
}
- if (token.value == TOK.rightCurly)
- {
- }
- else
+ if (token.value != TOK.rightCurly)
{
addComment(em, comment);
comment = null;
nextToken();
}
else
- error("enum declaration is invalid");
-
+ {
+ nextToken();
+ error("expected `{`, not `%s` for enum declaration", token.toChars());
+ }
//printf("-parseEnum() %s\n", e.toChars());
return e;
}
*/
if (tpl)
{
+ // @@@DEPRECATED_2.114@@@
+ // Both deprecated in 2.104, change to error
+ if (storage_class & STC.override_)
+ deprecation(loc, "a function template is not virtual so cannot be marked `override`");
+ else if (storage_class & STC.abstract_)
+ deprecation(loc, "a function template is not virtual so cannot be marked `abstract`");
+
// Wrap a template around the function declaration
auto decldefs = new AST.Dsymbols();
decldefs.push(s);
AST.Parameter param = null;
StorageClass storageClass = 0;
StorageClass stc = 0;
-LagainStc:
- if (stc)
- {
- storageClass = appendStorageClass(storageClass, stc);
- nextToken();
- }
- switch (token.value)
+ Lwhile:
+ while (1)
{
- case TOK.ref_:
- stc = STC.ref_;
- goto LagainStc;
+ switch (token.value)
+ {
+ // parse ref for better error
+ case TOK.ref_:
+ stc = STC.ref_;
+ break;
- case TOK.scope_:
- stc = STC.scope_;
- goto LagainStc;
+ case TOK.scope_:
+ stc = STC.scope_;
+ break;
- case TOK.auto_:
- stc = STC.auto_;
- goto LagainStc;
+ case TOK.auto_:
+ stc = STC.auto_;
+ break;
- case TOK.const_:
- if (peekNext() != TOK.leftParenthesis)
- {
- stc = STC.const_;
- goto LagainStc;
- }
- break;
+ case TOK.const_:
+ if (peekNext() != TOK.leftParenthesis)
+ {
+ stc = STC.const_;
+ break;
+ }
+ goto default;
- case TOK.immutable_:
- if (peekNext() != TOK.leftParenthesis)
- {
- stc = STC.immutable_;
- goto LagainStc;
- }
- break;
+ case TOK.immutable_:
+ if (peekNext() != TOK.leftParenthesis)
+ {
+ stc = STC.immutable_;
+ break;
+ }
+ goto default;
- case TOK.shared_:
- if (peekNext() != TOK.leftParenthesis)
- {
- stc = STC.shared_;
- goto LagainStc;
- }
- break;
+ case TOK.shared_:
+ if (peekNext() != TOK.leftParenthesis)
+ {
+ stc = STC.shared_;
+ break;
+ }
+ goto default;
- case TOK.inout_:
- if (peekNext() != TOK.leftParenthesis)
- {
- stc = STC.wild;
- goto LagainStc;
- }
- break;
+ case TOK.inout_:
+ if (peekNext() != TOK.leftParenthesis)
+ {
+ stc = STC.wild;
+ break;
+ }
+ goto default;
- default:
- break;
+ default:
+ break Lwhile;
+ }
+ storageClass = appendStorageClass(storageClass, stc);
+ nextToken();
}
auto n = peek(&token);
if (storageClass != 0 && token.value == TOK.identifier && n.value == TOK.assign)
nextToken();
if (token.value != TOK.identifier)
{
- error("identifier expected following `(type)`.");
+ error("identifier expected following `%s.`, not `%s`",
+ t.toChars(), token.toChars());
return AST.ErrorExp.get();
}
e = new AST.DotIdExp(loc, new AST.TypeExp(loc, t), token.ident);
e = new AST.TypeExp(loc, t);
if (token.value != TOK.leftParenthesis)
{
- error("`(arguments)` expected following `%s`", t.toChars());
+ error("`(arguments)` expected following `%s`, not `%s`",
+ t.toChars(), token.toChars());
return e;
}
e = new AST.CallExp(loc, e, parseArguments());
public:
StoppableVisitor v;
- extern (D) this(StoppableVisitor v) scope
+ extern (D) this(StoppableVisitor v) scope @safe
{
this.v = v;
}
int indent;
- extern (D) this(int indent) scope
+ extern (D) this(int indent) scope @safe
{
this.indent = indent;
}
this(re, CTFloat.zero);
}
- this(real_t re, real_t im)
+ this(real_t re, real_t im) @safe
{
this.re = re;
this.im = im;
return re || im;
}
- int opEquals(complex_t y) const
+ int opEquals(complex_t y) const @safe
{
return re == y.re && im == y.im;
}
}
-extern (C++) real_t creall(complex_t x)
+extern (C++) real_t creall(complex_t x) @safe
{
return x.re;
}
-extern (C++) real_t cimagl(complex_t x)
+extern (C++) real_t cimagl(complex_t x) @safe
{
return x.im;
}
extern (Windows) DWORD GetFullPathNameW(LPCWSTR, DWORD, LPWSTR, LPWSTR*) nothrow @nogc;
extern (Windows) void SetLastError(DWORD) nothrow @nogc;
extern (C) char* getcwd(char* buffer, size_t maxlen) nothrow;
-
- // assume filenames encoded in system default Windows ANSI code page
- private enum CodePage = CP_ACP;
}
version (CRuntime_Glibc)
}
/// Ditto
- extern (D) static bool absolute(const(char)[] name) pure @nogc
+ extern (D) static bool absolute(const(char)[] name) pure @nogc @safe
{
if (!name.length)
return false;
}
/// Ditto
- extern (D) static const(char)[] name(const(char)[] str) pure @nogc
+ extern (D) static const(char)[] name(const(char)[] str) pure @nogc @safe
{
foreach_reverse (idx, char e; str)
{
*/
char[] toNarrowStringz(const(wchar)[] wide, char[] buffer = null) nothrow
{
+ import dmd.common.file : CodePage;
+
if (wide is null)
return null;
extern(C++):
nothrow:
@nogc:
+pure:
+@trusted:
// Type used by the front-end for compile-time reals
struct longdouble
{
nothrow:
@nogc:
+pure:
extern (D) this(T)(T r)
{
this.set(cast(SetType!T)r);
* Returns:
* p if not null
*/
- static void* check(void* p) pure nothrow @nogc
+ static void* check(void* p) pure nothrow @nogc @safe
{
return p ? p : error();
}
module dmd.root.utf;
-nothrow pure @nogc:
+@nogc nothrow pure @safe:
/// The Unicode code space is the range of code points [0x000000,0x10FFFF]
/// except the UTF-16 surrogate pairs in the range [0xD800,0xDFFF]
return 1;
}
-void utf_encodeChar(char* s, dchar c)
+void utf_encodeChar(char* s, dchar c) @system
{
assert(s !is null);
assert(utf_isValidDchar(c));
assert(0);
}
-void utf_encodeWchar(wchar* s, dchar c)
+void utf_encodeWchar(wchar* s, dchar c) @system
{
assert(s !is null);
assert(utf_isValidDchar(c));
}
}
-void utf_encode(int sz, void* s, dchar c)
+void utf_encode(int sz, void* s, dchar c) @system
{
if (sz == 1)
utf_encodeChar(cast(char*)s, c);
* Checks whether an Unicode code point is a bidirectional
* control character.
*/
-@safe bool isBidiControl(dchar c)
+bool isBidiControl(dchar c)
{
// Source: https://www.unicode.org/versions/Unicode15.0.0, table 23-3.
switch(c)
public:
StoppableVisitor v;
- extern (D) this(StoppableVisitor v) scope
+ extern (D) this(StoppableVisitor v) scope @safe
{
this.v = v;
}
#pragma once
+class ErrorSink;
class Identifier;
class Module;
class Statement;
d_bool inLoop; // true if inside a loop (where constructor calls aren't allowed)
int intypeof; // in typeof(exp)
VarDeclaration *lastVar; // Previous symbol used to prevent goto-skips-init
+ ErrorSink *eSink; // sink for error messages
/* If minst && !tinst, it's in definitely non-speculative scope (eg. module member scope).
* If !minst && !tinst, it's in definitely speculative scope (eg. template constraint).
{
alias visit = Visitor.visit;
Scope* sc;
- this(Scope* sc) scope
+ this(Scope* sc) scope @safe
{
this.sc = sc;
}
return;
//printf("VarDeclaration::semantic2('%s')\n", toChars());
+ sc = sc.push();
sc.varDecl = vd;
- scope(exit) sc.varDecl = null;
+ scope(exit) sc = sc.pop();
if (vd.aliasTuple) // if it's a tuple
{
// Note that modules get their own scope, from scratch.
// This is so regardless of where in the syntax a module
// gets imported, it is unaffected by context.
- Scope* sc = Scope.createGlobal(mod); // create root scope
+ Scope* sc = Scope.createGlobal(mod, global.errorSink); // create root scope
//printf("Module = %p\n", sc.scopesym);
if (mod.members)
{
alias visit = Visitor.visit;
Scope* sc;
- this(Scope* sc) scope
+ this(Scope* sc) scope @safe
{
this.sc = sc;
}
// Note that modules get their own scope, from scratch.
// This is so regardless of where in the syntax a module
// gets imported, it is unaffected by context.
- Scope* sc = Scope.createGlobal(mod); // create root scope
+ Scope* sc = Scope.createGlobal(mod, global.errorSink); // create root scope
//printf("Module = %p\n", sc.scopesym);
if (mod.members)
{
}
sc2.ctorflow.freeFieldinit();
- if (cd && !(sc2.ctorflow.callSuper & CSX.any_ctor) && cd.baseClass && cd.baseClass.ctor)
+ if (cd && !(sc2.ctorflow.callSuper & (CSX.any_ctor | CSX.halt)) && cd.baseClass && cd.baseClass.ctor)
{
sc2.ctorflow.callSuper = CSX.none;
*/
AggregateDeclaration ad = ctor.isMemberDecl();
if (!ctor.fbody || !ad || !ad.fieldDtor ||
- global.params.dtorFields == FeatureState.disabled || !global.params.useExceptions || ctor.type.toTypeFunction.isnothrow)
+ global.params.dtorFields == FeatureState.disabled || !global.params.useExceptions || ctor.type.toTypeFunction.isnothrow)
return visit(cast(FuncDeclaration)ctor);
/* Generate:
// Scope of analysis
Scope* sc;
- this(FuncDeclaration fd,Scope* s) scope
+ this(FuncDeclaration fd,Scope* s) scope @safe
{
funcdecl = fd;
sc = s;
{
alias visit = typeof(super).visit;
public:
- extern (D) this() scope
+ extern (D) this() scope @safe
{
}
{
alias visit = typeof(super).visit;
public:
- extern (D) this() scope
+ extern (D) this() scope @safe
{
}
return DYNCAST.statement;
}
- final extern (D) this(const ref Loc loc, STMT stmt)
+ final extern (D) this(const ref Loc loc, STMT stmt) @safe
{
this.loc = loc;
this.stmt = stmt;
{
va_list ap;
va_start(ap, format);
- .verror(loc, format, ap);
+ .verrorReport(loc, format, ap, ErrorKind.error);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- .vwarning(loc, format, ap);
+ .verrorReport(loc, format, ap, ErrorKind.warning);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- .vdeprecation(loc, format, ap);
+ .verrorReport(loc, format, ap, ErrorKind.deprecation);
va_end(ap);
}
}
{
va_list ap;
va_start(ap, format);
- .verror(loc, format, ap);
+ .verrorReport(loc, format, ap, ErrorKind.error);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- .vwarning(loc, format, ap);
+ .verrorReport(loc, format, ap, ErrorKind.warning);
va_end(ap);
}
{
va_list ap;
va_start(ap, format);
- .vdeprecation(loc, format, ap);
+ .verrorReport(loc, format, ap, ErrorKind.deprecation);
va_end(ap);
}
}
{
Statement s;
- extern (D) this(Statement s)
+ extern (D) this(Statement s) @safe
{
super(s.loc, STMT.Peel);
this.s = s;
{
Expression exp;
- final extern (D) this(const ref Loc loc, Expression exp)
+ final extern (D) this(const ref Loc loc, Expression exp) @safe
{
super(loc, STMT.Exp);
this.exp = exp;
}
- final extern (D) this(const ref Loc loc, Expression exp, STMT stmt)
+ final extern (D) this(const ref Loc loc, Expression exp, STMT stmt) @safe
{
super(loc, stmt);
this.exp = exp;
}
- final extern (D) this(const ref Loc loc, Dsymbol declaration)
+ final extern (D) this(const ref Loc loc, Dsymbol declaration) @safe
{
super(loc, STMT.Exp);
this.exp = new DeclarationExp(loc, declaration);
}
- static ExpStatement create(const ref Loc loc, Expression exp)
+ static ExpStatement create(const ref Loc loc, Expression exp) @safe
{
return new ExpStatement(loc, exp);
}
// Wraps an expression that is the destruction of 'var'
VarDeclaration var;
- extern (D) this(const ref Loc loc, Expression exp, VarDeclaration var)
+ extern (D) this(const ref Loc loc, Expression exp, VarDeclaration var) @safe
{
super(loc, exp, STMT.DtorExp);
this.var = var;
this(loc, exps);
}
- extern (D) this(const ref Loc loc, Expressions* exps)
+ extern (D) this(const ref Loc loc, Expressions* exps) @safe
{
super(loc, STMT.Mixin);
this.exps = exps;
* loc = Instantiation information
* statements = An array of `Statement`s, that will referenced by this class
*/
- final extern (D) this(const ref Loc loc, Statements* statements)
+ final extern (D) this(const ref Loc loc, Statements* statements) @safe
{
super(loc, STMT.Compound);
this.statements = statements;
}
- final extern (D) this(const ref Loc loc, Statements* statements, STMT stmt)
+ final extern (D) this(const ref Loc loc, Statements* statements, STMT stmt) @safe
{
super(loc, stmt);
this.statements = statements;
*/
extern (C++) final class CompoundDeclarationStatement : CompoundStatement
{
- extern (D) this(const ref Loc loc, Statements* statements)
+ extern (D) this(const ref Loc loc, Statements* statements) @safe
{
super(loc, statements, STMT.CompoundDeclaration);
}
{
Statements* statements;
- extern (D) this(const ref Loc loc, Statements* statements)
+ extern (D) this(const ref Loc loc, Statements* statements) @safe
{
super(loc, STMT.UnrolledLoop);
this.statements = statements;
Statement statement;
Loc endloc; // location of closing curly bracket
- extern (D) this(const ref Loc loc, Statement statement, Loc endloc)
+ extern (D) this(const ref Loc loc, Statement statement, Loc endloc) @safe
{
super(loc, STMT.Scope);
this.statement = statement;
/// The wrapped statement.
Statement statement;
- extern (D) this(const ref Loc loc, ForwardingScopeDsymbol sym, Statement statement)
+ extern (D) this(const ref Loc loc, ForwardingScopeDsymbol sym, Statement statement) @safe
{
super(loc, STMT.Forwarding);
this.sym = sym;
this.statement = statement;
}
- extern (D) this(const ref Loc loc, Statement statement)
+ extern (D) this(const ref Loc loc, Statement statement) @safe
{
auto sym = new ForwardingScopeDsymbol();
sym.symtab = new DsymbolTable();
Statement _body;
Loc endloc; // location of closing curly bracket
- extern (D) this(const ref Loc loc, Expression condition, Statement _body, Loc endloc, Parameter param = null)
+ extern (D) this(const ref Loc loc, Expression condition, Statement _body, Loc endloc, Parameter param = null) @safe
{
super(loc, STMT.While);
this.condition = condition;
Expression condition;
Loc endloc; // location of ';' after while
- extern (D) this(const ref Loc loc, Statement _body, Expression condition, Loc endloc)
+ extern (D) this(const ref Loc loc, Statement _body, Expression condition, Loc endloc) @safe
{
super(loc, STMT.Do);
this._body = _body;
// treat that label as referring to this loop.
Statement relatedLabeled;
- extern (D) this(const ref Loc loc, Statement _init, Expression condition, Expression increment, Statement _body, Loc endloc)
+ extern (D) this(const ref Loc loc, Statement _init, Expression condition, Expression increment, Statement _body, Loc endloc) @safe
{
super(loc, STMT.For);
this._init = _init;
Statements* cases; // put breaks, continues, gotos and returns here
ScopeStatements* gotos; // forward referenced goto's go here
- extern (D) this(const ref Loc loc, TOK op, Parameters* parameters, Expression aggr, Statement _body, Loc endloc)
+ extern (D) this(const ref Loc loc, TOK op, Parameters* parameters, Expression aggr, Statement _body, Loc endloc) @safe
{
super(loc, STMT.Foreach);
this.op = op;
VarDeclaration key;
- extern (D) this(const ref Loc loc, TOK op, Parameter prm, Expression lwr, Expression upr, Statement _body, Loc endloc)
+ extern (D) this(const ref Loc loc, TOK op, Parameter prm, Expression lwr, Expression upr, Statement _body, Loc endloc) @safe
{
super(loc, STMT.ForeachRange);
this.op = op;
VarDeclaration match; // for MatchExpression results
Loc endloc; // location of closing curly bracket
- extern (D) this(const ref Loc loc, Parameter prm, Expression condition, Statement ifbody, Statement elsebody, Loc endloc)
+ extern (D) this(const ref Loc loc, Parameter prm, Expression condition, Statement ifbody, Statement elsebody, Loc endloc) @safe
{
super(loc, STMT.If);
this.prm = prm;
Statement ifbody;
Statement elsebody;
- extern (D) this(const ref Loc loc, Condition condition, Statement ifbody, Statement elsebody)
+ extern (D) this(const ref Loc loc, Condition condition, Statement ifbody, Statement elsebody) @safe
{
super(loc, STMT.Conditional);
this.condition = condition;
{
StaticForeach sfe;
- extern (D) this(const ref Loc loc, StaticForeach sfe)
+ extern (D) this(const ref Loc loc, StaticForeach sfe) @safe
{
super(loc, STMT.StaticForeach);
this.sfe = sfe;
Expressions* args; // array of Expression's
Statement _body;
- extern (D) this(const ref Loc loc, const Identifier ident, Expressions* args, Statement _body)
+ extern (D) this(const ref Loc loc, const Identifier ident, Expressions* args, Statement _body) @safe
{
super(loc, STMT.Pragma);
this.ident = ident;
{
StaticAssert sa;
- extern (D) this(StaticAssert sa)
+ extern (D) this(StaticAssert sa) @safe
{
super(sa.loc, STMT.StaticAssert);
this.sa = sa;
VarDeclaration lastVar;
void* extra; // for use by Statement_toIR()
- extern (D) this(const ref Loc loc, Expression exp, Statement statement)
+ extern (D) this(const ref Loc loc, Expression exp, Statement statement) @safe
{
super(loc, STMT.Case);
this.exp = exp;
Expression last;
Statement statement;
- extern (D) this(const ref Loc loc, Expression first, Expression last, Statement statement)
+ extern (D) this(const ref Loc loc, Expression first, Expression last, Statement statement) @safe
{
super(loc, STMT.CaseRange);
this.first = first;
VarDeclaration lastVar;
- extern (D) this(const ref Loc loc, Statement statement)
+ extern (D) this(const ref Loc loc, Statement statement) @safe
{
super(loc, STMT.Default);
this.statement = statement;
{
SwitchStatement sw;
- extern (D) this(const ref Loc loc)
+ extern (D) this(const ref Loc loc) @safe
{
super(loc, STMT.GotoDefault);
}
CaseStatement cs; // case statement it resolves to
- extern (D) this(const ref Loc loc, Expression exp)
+ extern (D) this(const ref Loc loc, Expression exp) @safe
{
super(loc, STMT.GotoCase);
this.exp = exp;
{
Expression exp;
- extern (D) this(const ref Loc loc)
+ extern (D) this(const ref Loc loc) @safe
{
super(loc, STMT.SwitchError);
}
- final extern (D) this(const ref Loc loc, Expression exp)
+ final extern (D) this(const ref Loc loc, Expression exp) @safe
{
super(loc, STMT.SwitchError);
this.exp = exp;
Expression exp;
size_t caseDim;
- extern (D) this(const ref Loc loc, Expression exp)
+ extern (D) this(const ref Loc loc, Expression exp) @safe
{
super(loc, STMT.Return);
this.exp = exp;
{
Identifier ident;
- extern (D) this(const ref Loc loc, Identifier ident)
+ extern (D) this(const ref Loc loc, Identifier ident) @safe
{
super(loc, STMT.Break);
this.ident = ident;
{
Identifier ident;
- extern (D) this(const ref Loc loc, Identifier ident)
+ extern (D) this(const ref Loc loc, Identifier ident) @safe
{
super(loc, STMT.Continue);
this.ident = ident;
Expression exp;
Statement _body;
- extern (D) this(const ref Loc loc, Expression exp, Statement _body)
+ extern (D) this(const ref Loc loc, Expression exp, Statement _body) @safe
{
super(loc, STMT.Synchronized);
this.exp = exp;
VarDeclaration wthis;
Loc endloc;
- extern (D) this(const ref Loc loc, Expression exp, Statement _body, Loc endloc)
+ extern (D) this(const ref Loc loc, Expression exp, Statement _body, Loc endloc) @safe
{
super(loc, STMT.With);
this.exp = exp;
Statement tryBody; /// set to enclosing TryCatchStatement or TryFinallyStatement if in _body portion
- extern (D) this(const ref Loc loc, Statement _body, Catches* catches)
+ extern (D) this(const ref Loc loc, Statement _body, Catches* catches) @safe
{
super(loc, STMT.TryCatch);
this._body = _body;
// was generated by the compiler, wasn't present in source code
bool internalCatch;
- extern (D) this(const ref Loc loc, Type type, Identifier ident, Statement handler)
+ extern (D) this(const ref Loc loc, Type type, Identifier ident, Statement handler) @safe
{
//printf("Catch(%s, loc = %s)\n", id.toChars(), loc.toChars());
this.loc = loc;
Statement tryBody; /// set to enclosing TryCatchStatement or TryFinallyStatement if in _body portion
bool bodyFallsThru; /// true if _body falls through to finally
- extern (D) this(const ref Loc loc, Statement _body, Statement finalbody)
+ extern (D) this(const ref Loc loc, Statement _body, Statement finalbody) @safe
{
super(loc, STMT.TryFinally);
this._body = _body;
this.bodyFallsThru = true; // assume true until statementSemantic()
}
- static TryFinallyStatement create(const ref Loc loc, Statement _body, Statement finalbody)
+ static TryFinallyStatement create(const ref Loc loc, Statement _body, Statement finalbody) @safe
{
return new TryFinallyStatement(loc, _body, finalbody);
}
TOK tok;
Statement statement;
- extern (D) this(const ref Loc loc, TOK tok, Statement statement)
+ extern (D) this(const ref Loc loc, TOK tok, Statement statement) @safe
{
super(loc, STMT.ScopeGuard);
this.tok = tok;
// was generated by the compiler, wasn't present in source code
bool internalThrow;
- extern (D) this(const ref Loc loc, Expression exp)
+ extern (D) this(const ref Loc loc, Expression exp) @safe
{
super(loc, STMT.Throw);
this.exp = exp;
{
Statement statement;
- extern (D) this(const ref Loc loc, Statement statement)
+ extern (D) this(const ref Loc loc, Statement statement) @safe
{
super(loc, STMT.Debug);
this.statement = statement;
VarDeclaration lastVar;
bool inCtfeBlock; /// set if goto is inside an `if (__ctfe)` block
- extern (D) this(const ref Loc loc, Identifier ident)
+ extern (D) this(const ref Loc loc, Identifier ident) @safe
{
super(loc, STMT.Goto);
this.ident = ident;
bool breaks; // someone did a 'break ident'
bool inCtfeBlock; // inside a block dominated by `if (__ctfe)`
- extern (D) this(const ref Loc loc, Identifier ident, Statement statement)
+ extern (D) this(const ref Loc loc, Identifier ident, Statement statement) @safe
{
super(loc, STMT.Label);
this.ident = ident;
bool deleted; // set if rewritten to return in foreach delegate
bool iasm; // set if used by inline assembler
- extern (D) this(Identifier ident, const ref Loc loc = Loc.initial)
+ // set if label was defined multiple times, to avoid duplicate errors
+ // can be removed if generic error message deduplication is implemented
+ bool duplicated;
+
+ extern (D) this(Identifier ident, const ref Loc loc = Loc.initial) @safe
{
super(loc, ident);
}
- static LabelDsymbol create(Identifier ident)
+ static LabelDsymbol create(Identifier ident) @safe
{
return new LabelDsymbol(ident);
}
{
Token* tokens;
- extern (D) this(const ref Loc loc, Token* tokens)
+ extern (D) this(const ref Loc loc, Token* tokens) @safe
{
super(loc, STMT.Asm);
this.tokens = tokens;
}
- extern (D) this(const ref Loc loc, Token* tokens, STMT stmt)
+ extern (D) this(const ref Loc loc, Token* tokens, STMT stmt) @safe
{
super(loc, stmt);
this.tokens = tokens;
bool refparam; // true if function parameter is referenced
bool naked; // true if function is to be naked
- extern (D) this(const ref Loc loc, Token* tokens)
+ extern (D) this(const ref Loc loc, Token* tokens) @safe
{
super(loc, tokens, STMT.InlineAsm);
}
Identifiers* labels; // list of goto labels
GotoStatements* gotos; // of the goto labels, the equivalent statements they represent
- extern (D) this(const ref Loc loc, Token* tokens)
+ extern (D) this(const ref Loc loc, Token* tokens) @safe
{
super(loc, tokens, STMT.GccAsm);
}
{
StorageClass stc; // postfix attributes like nothrow/pure/@trusted
- extern (D) this(const ref Loc loc, Statements* statements, StorageClass stc)
+ extern (D) this(const ref Loc loc, Statements* statements, StorageClass stc) @safe
{
super(loc, statements, STMT.CompoundAsm);
this.stc = stc;
{
Dsymbols* imports; // Array of Import's
- extern (D) this(const ref Loc loc, Dsymbols* imports)
+ extern (D) this(const ref Loc loc, Dsymbols* imports) @safe
{
super(loc, STMT.Import);
this.imports = imports;
* handler = string for the name of the visit handler
* Returns: boilerplate code for a case
*/
-pure string visitStmtCase(string handler)
+pure string visitStmtCase(string handler) @safe
{
if (__ctfe)
{
d_bool deleted; // set if rewritten to return in foreach delegate
d_bool iasm; // set if used by inline assembler
+ d_bool duplicated; // set if multiply defined, to avoid duplicate error messages
static LabelDsymbol *create(Identifier *ident);
LabelDsymbol *isLabel() override;
import dmd.arraytypes;
import dmd.astcodegen;
import dmd.astenums;
-import dmd.ast_node;
import dmd.attrib;
import dmd.blockexit;
import dmd.clone;
import dmd.dsymbolsem;
import dmd.dtemplate;
import dmd.errors;
-import dmd.errorsink;
import dmd.escape;
import dmd.expression;
import dmd.expressionsem;
import dmd.nogc;
import dmd.opover;
import dmd.parse;
-import dmd.printast;
import dmd.common.outbuffer;
import dmd.root.string;
import dmd.semantic2;
import dmd.tokens;
import dmd.typesem;
import dmd.visitor;
-import dmd.compiler;
version (DMDLIB)
{
* Returns:
* if `true`, then the `LabelStatement`, otherwise `null`
*/
-private LabelStatement checkLabeledLoop(Scope* sc, Statement statement)
+private LabelStatement checkLabeledLoop(Scope* sc, Statement statement) @safe
{
if (sc.slabel && sc.slabel.statement == statement)
{
// Performs semantic analysis in Statement AST nodes
extern(C++) Statement statementSemantic(Statement s, Scope* sc)
{
+ import dmd.compiler;
+
version (CallbackAPI)
Compiler.onStatementSemanticStart(s, sc);
{
if (e0)
rs.error("expected return type of `%s`, not `%s`", tret.toChars(), resType.toChars());
+ else if (tbret.isTypeNoreturn())
+ {
+ rs.error("cannot return from `noreturn` function");
+ .errorSupplemental(rs.loc,
+ "Consider adding an endless loop, `assert(0)`, or another `noreturn` expression");
+ }
else
rs.error("`return` expression expected");
}
ls.inCtfeBlock = (sc.flags & SCOPE.ctfeBlock) != 0;
LabelDsymbol ls2 = fd.searchLabel(ls.ident, ls.loc);
- if (ls2.statement)
+ if (ls2.statement && !ls2.duplicated)
{
- ls.error("label `%s` already defined", ls2.toChars());
+ if (ls.loc == ls2.loc)
+ {
+ ls2.duplicated = true;
+ ls.error("label `%s` is duplicated", ls2.toChars());
+ .errorSupplemental(ls2.loc, "labels cannot be used in a static foreach with more than 1 iteration");
+ }
+ else
+ {
+ ls.error("label `%s` is already defined", ls2.toChars());
+ .errorSupplemental(ls2.loc, "first definition is here");
+ }
return setError();
}
else
}
else if (!c.type.isNaked() && !c.type.isConst())
{
- // @@@DEPRECATED_2.113@@@
- // Deprecated in 2.103, change into an error & uncomment in 2.113
+ // @@@DEPRECATED_2.115@@@
+ // Deprecated in 2.105, change into an error & uncomment assign in 2.115
deprecation(c.loc, "can only catch mutable or const qualified types, not `%s`", c.type.toChars());
//c.errors = true;
}
* This can be used to restore the state set by `_init` to its original
* state.
*/
- void deinitialize()
+ void deinitialize() @safe
{
this = this.init;
}
* 2 vector element type is not supported
* 3 vector size is not supported
*/
- extern (C++) int isVectorTypeSupported(int sz, Type type);
+ extern (C++) int isVectorTypeSupported(int sz, Type type) @safe;
/**
* Checks whether the target supports the given operation for vectors.
* Returns:
* `LINK` to use for `extern(System)`
*/
- extern (C++) LINK systemLinkage();
+ extern (C++) LINK systemLinkage() @safe;
/**
* Describes how an argument type is passed to a function on target.
* tf = type of function being called
* Returns: `true` if the callee invokes destructors for arguments.
*/
- extern (C++) bool isCalleeDestroyingArgs(TypeFunction tf);
+ extern (C++) bool isCalleeDestroyingArgs(TypeFunction tf) @safe;
/**
* Returns true if the implementation for object monitors is always defined
* Returns:
* `false` if the target does not support `pragma(linkerDirective)`.
*/
- extern (C++) bool supportsLinkerDirective() const;
+ extern (C++) bool supportsLinkerDirective() const @safe;
}
////////////////////////////////////////////////////////////////////////////////
TemplateParameters* parameters;
bool result;
- this(Scope* sc, TemplateParameters* parameters) scope
+ this(Scope* sc, TemplateParameters* parameters) scope @safe
{
this.sc = sc;
this.parameters = parameters;
nothrow:
- int isKeyword() const
+ int isKeyword() const @safe
{
foreach (kw; keywords)
{
}
RootObject o = (*tup.objects)[cast(size_t)d];
- if (o.dyncast() != DYNCAST.type)
- {
- .error(loc, "`%s` is not a type", mtype.toChars());
- return error();
- }
- return (cast(Type)o).addMod(mtype.mod);
+ if (auto tt = o.isType())
+ return tt.addMod(mtype.mod);
+ .error(loc, "`%s` is not a type", mtype.toChars());
+ return error();
}
if (t && t.ty == Terror)
OutBuffer buf;
buf.reserve(32);
- mangleToBuffer(type, &buf);
+ mangleToBuffer(type, buf);
auto sv = type.stringtable.update(buf[]);
if (sv.value)
}
if (p.token.value != TOK.endOfFile)
{
- .error(loc, "incomplete mixin type `%s`", str.ptr);
+ .error(loc, "unexpected token `%s` after type `%s`",
+ p.token.toChars(), o.toChars());
+ .errorSupplemental(loc, "while parsing string mixin type `%s`",
+ str.ptr);
return null;
}
public:
bool stop;
- final extern (D) this() scope
+ final extern (D) this() scope @safe
{
}
}
return;
OutBuffer buf;
- mangleToBuffer (fd->type, &buf);
+ mangleToBuffer (fd->type, buf);
tdeco = buf.extractChars ();
}
-/* TEST_OUTPUT:
+/* REQUIRED_ARGS: -wo -wi
+TEST_OUTPUT:
---
-compilable/test23145.d(117): Deprecation: `scope` allocation of `c` requires that constructor be annotated with `scope`
+compilable/test23145.d(117): Warning: `scope` allocation of `c` requires that constructor be annotated with `scope`
compilable/test23145.d(111): is the location of the constructor
-compilable/test23145.d(124): Deprecation: `scope` allocation of `c` requires that constructor be annotated with `scope`
+compilable/test23145.d(124): Warning: `scope` allocation of `c` requires that constructor be annotated with `scope`
compilable/test23145.d(111): is the location of the constructor
---
*/
this(D d) @safe @nogc;
}
-C foo(D d)@nogc @safe
+C foo(D d) @nogc @safe
{
scope e = new C(1); // ok
scope c = new C(d); // deprecation
scope c = new C(d); // deprecation
return c.d.c;
}
+
+void inferred(D d)
+{
+ scope c = new C(d); // ok
+}
---
fail_compilation/biterrors3.d(103): Error: storage class not allowed for bit-field declaration
fail_compilation/biterrors3.d(106): Error: expected `,` or `=` after identifier, not `:`
-fail_compilation/biterrors3.d(106): Error: `:` is not a valid attribute for enum members
-fail_compilation/biterrors3.d(106): Error: `3` is not a valid attribute for enum members
+fail_compilation/biterrors3.d(106): Error: found `:` when expecting `,`
+fail_compilation/biterrors3.d(106): Error: found `3` when expecting `identifier`
---
*/
/*
TEST_OUTPUT:
---
-fail_compilation/bug8891.d(21): Error: need `this` for `opCall` of type `S(int n)`
+fail_compilation/bug8891.d(21): Error: calling non-static function `opCall` requires an instance of type `S`
---
*/
+++ /dev/null
-/*
-REQUIRED_ARGS: -de
-TEST_OUTPUT:
----
-fail_compilation/deprecatedinref.d(9): Deprecation: using `in ref` is deprecated, use `-preview=in` and `in` instead
-fail_compilation/deprecatedinref.d(10): Deprecation: using `ref in` is deprecated, use `-preview=in` and `in` instead
----
-*/
-void foo(in ref int);
-void foor(ref in int);
/*
TEST_OUTPUT:
---
-fail_compilation/diag15209.d(18): Error: need `this` for `x` of type `int`
-fail_compilation/diag15209.d(21): Error: need `this` for `x` of type `int`
+fail_compilation/diag15209.d(18): Error: accessing non-static variable `x` requires an instance of `C1`
+fail_compilation/diag15209.d(21): Error: accessing non-static variable `x` requires an instance of `S2`
---
*/
/*
TEST_OUTPUT:
---
-fail_compilation/diag9451.d(26): Error: cannot create instance of abstract class `C2`
-fail_compilation/diag9451.d(26): function `void f1()` is not implemented
-fail_compilation/diag9451.d(26): function `void f2(int)` is not implemented
-fail_compilation/diag9451.d(26): function `void f2(float) const` is not implemented
-fail_compilation/diag9451.d(26): function `int f2(float) pure` is not implemented
+fail_compilation/diag9451.d(27): Error: cannot create instance of abstract class `C2`
+fail_compilation/diag9451.d(21): class `C2` is declared here
+fail_compilation/diag9451.d(15): function `void f1()` is not implemented
+fail_compilation/diag9451.d(16): function `void f2(int)` is not implemented
+fail_compilation/diag9451.d(17): function `void f2(float) const` is not implemented
+fail_compilation/diag9451.d(18): function `int f2(float) pure` is not implemented
---
*/
/*
TEST_OUTPUT:
---
-fail_compilation/diag9635.d(17): Error: need `this` for `i` of type `int`
-fail_compilation/diag9635.d(18): Error: need `this` for `foo` of type `pure nothrow @nogc @safe void()`
+fail_compilation/diag9635.d(17): Error: accessing non-static variable `i` requires an instance of `Foo`
+fail_compilation/diag9635.d(18): Error: calling non-static function `foo` requires an instance of type `Foo`
---
*/
/*
-REQUIRED_ARGS: -de
+REQUIRED_ARGS: -de -wo
TEST_OUTPUT:
---
fail_compilation/dip1000_deprecation.d(20): Deprecation: `@safe` function `main` calling `inferred`
fail_compilation/dip1000_deprecation.d(39): which calls `dip1000_deprecation.inferred`
fail_compilation/dip1000_deprecation.d(28): which wouldn't be `@safe` because of:
fail_compilation/dip1000_deprecation.d(28): scope variable `x0` may not be returned
-fail_compilation/dip1000_deprecation.d(54): Deprecation: escaping reference to stack allocated value returned by `S(null)`
-fail_compilation/dip1000_deprecation.d(55): Deprecation: escaping reference to stack allocated value returned by `createS()`
-fail_compilation/dip1000_deprecation.d(58): Deprecation: returning `s.incorrectReturnRef()` escapes a reference to local variable `s`
+fail_compilation/dip1000_deprecation.d(54): Warning: escaping reference to stack allocated value returned by `S(null)`
+fail_compilation/dip1000_deprecation.d(55): Warning: escaping reference to stack allocated value returned by `createS()`
+fail_compilation/dip1000_deprecation.d(58): Warning: returning `s.incorrectReturnRef()` escapes a reference to local variable `s`
---
*/
void main() @safe
{
- inferred();
- inferredB(); // no deprecation, trusted
- inferredC(); // nested deprecation
+ cast(void)inferred();
+ cast(void)inferredB(); // no deprecation, trusted
+ cast(void)inferredC(); // nested deprecation
}
auto inferred()
S createS() { return S.init; }
-int* escape()
+int* escape(int i)
{
- return S().incorrectReturnRef();
- return createS().incorrectReturnRef();
+ if (i) return S().incorrectReturnRef();
+ if (i) return createS().incorrectReturnRef();
S s;
return s.incorrectReturnRef();
/*
TEST_OUTPUT:
---
-fail_compilation/e15876_6.d(7): Error: identifier expected following `(type)`.
+fail_compilation/e15876_6.d(7): Error: identifier expected following `immutable(int).`, not `;`
---
*/
auto unaryExParseError = immutable(int).;
/*
TEST_OUTPUT:
---
-fail_compilation/fail10285.d(13): Error: no identifier for declarator `int`
-fail_compilation/fail10285.d(14): Error: expected `,` or `=` after identifier, not `y`
-fail_compilation/fail10285.d(15): Error: expected identifier after type, not `bool`
-fail_compilation/fail10285.d(16): Error: expected identifier after type, not `int`
-fail_compilation/fail10285.d(18): Error: initializer required after `z` when type is specified
+fail_compilation/fail10285.d(16): Error: no identifier for declarator `int`
+fail_compilation/fail10285.d(17): Error: expected `,` or `=` after identifier, not `y`
+fail_compilation/fail10285.d(17): Error: initializer required after `x` when type is specified
+fail_compilation/fail10285.d(18): Error: no identifier for declarator `int`
+fail_compilation/fail10285.d(18): Error: found `bool` when expecting `,`
+fail_compilation/fail10285.d(19): Error: no identifier for declarator `j`
+fail_compilation/fail10285.d(19): Error: found `int` when expecting `,`
+fail_compilation/fail10285.d(21): Error: initializer required after `z` when type is specified
---
*/
enum
/*
TEST_OUTPUT:
---
-fail_compilation/fail11545.d(14): Error: need `this` for `x` of type `int`
-fail_compilation/fail11545.d(18): Error: need `this` for `x` of type `int`
+fail_compilation/fail11545.d(14): Error: accessing non-static variable `x` requires an instance of `C`
+fail_compilation/fail11545.d(18): Error: accessing non-static variable `x` requires an instance of `C`
---
*/
/*
TEST_OUTPUT:
---
-fail_compilation/fail120.d(12): Error: need `this` for `nodes` of type `int[2]`
-fail_compilation/fail120.d(13): Error: need `this` for `nodes` of type `int[2]`
+fail_compilation/fail120.d(12): Error: accessing non-static variable `nodes` requires an instance of `Foo`
+fail_compilation/fail120.d(13): Error: accessing non-static variable `nodes` requires an instance of `Foo`
---
*/
/*
TEST_OUTPUT:
---
-fail_compilation/fail142.d(20): Error: cannot create instance of abstract class `B`
-fail_compilation/fail142.d(20): function `void test()` is not implemented
+fail_compilation/fail142.d(21): Error: cannot create instance of abstract class `B`
+fail_compilation/fail142.d(15): class `B` is declared here
+fail_compilation/fail142.d(12): function `void test()` is not implemented
---
*/
/*
TEST_OUTPUT:
---
-fail_compilation/fail143.d(23): Error: need `this` for `next` of type `uint()`
+fail_compilation/fail143.d(23): Error: calling non-static function `next` requires an instance of type `Quux`
fail_compilation/fail143.d(30): Error: template instance `fail143.Foo!int` error instantiating
---
*/
/*
TEST_OUTPUT:
---
-fail_compilation/fail144.d(13): Error: `"message"`
+fail_compilation/fail144.d(13): Error: message
fail_compilation/fail144.d(26): called from here: `bar(7)`
---
*/
REQUIRED_ARGS: -checkaction=context
TEST_OUTPUT:
---
-fail_compilation/fail145.d(14): Error: `"assert(i && (i < 0)) failed"`
+fail_compilation/fail145.d(14): Error: `assert(i && (i < 0))` failed
fail_compilation/fail145.d(27): called from here: `bar(7)`
---
*/
/*
TEST_OUTPUT:
---
-fail_compilation/fail17955.d(81): Error: cannot create instance of abstract class `SimpleTimeZone`
-fail_compilation/fail17955.d(81): function `bool hasDST()` is not implemented
-fail_compilation/fail17955.d(93): Error: template instance `fail17955.SimpleTimeZone.fromISOExtString!dstring` error instantiating
-fail_compilation/fail17955.d(25): instantiated from here: `fromISOExtString!string`
-fail_compilation/fail17955.d(56): instantiated from here: `isISOExtStringSerializable!(SysTime)`
-fail_compilation/fail17955.d(49): instantiated from here: `toRedis!(SysTime)`
-fail_compilation/fail17955.d(40): ... (2 instantiations, -v to show) ...
-fail_compilation/fail17955.d(32): instantiated from here: `indicesOf!(isRedisType, resetCodeExpireTime)`
-fail_compilation/fail17955.d(67): instantiated from here: `RedisStripped!(User, true)`
-fail_compilation/fail17955.d(93): Error: need `this` for `fromISOExtString` of type `pure nothrow @nogc @safe immutable(SimpleTimeZone)(dstring __param_0)`
-fail_compilation/fail17955.d(95): Error: undefined identifier `DateTimeException`
-fail_compilation/fail17955.d(25): Error: variable `fail17955.isISOExtStringSerializable!(SysTime).isISOExtStringSerializable` - type `void` is inferred from initializer `fromISOExtString("")`, and variables cannot be of type `void`
-fail_compilation/fail17955.d(54): Error: function `fail17955.toRedis!(SysTime).toRedis` has no `return` statement, but is expected to return a value of type `string`
+fail_compilation/fail17955.d(82): Error: cannot create instance of abstract class `SimpleTimeZone`
+fail_compilation/fail17955.d(76): class `SimpleTimeZone` is declared here
+fail_compilation/fail17955.d(73): function `bool hasDST()` is not implemented
+fail_compilation/fail17955.d(94): Error: template instance `fail17955.SimpleTimeZone.fromISOExtString!dstring` error instantiating
+fail_compilation/fail17955.d(26): instantiated from here: `fromISOExtString!string`
+fail_compilation/fail17955.d(57): instantiated from here: `isISOExtStringSerializable!(SysTime)`
+fail_compilation/fail17955.d(50): instantiated from here: `toRedis!(SysTime)`
+fail_compilation/fail17955.d(41): ... (2 instantiations, -v to show) ...
+fail_compilation/fail17955.d(33): instantiated from here: `indicesOf!(isRedisType, resetCodeExpireTime)`
+fail_compilation/fail17955.d(68): instantiated from here: `RedisStripped!(User, true)`
+fail_compilation/fail17955.d(94): Error: calling non-static function `fromISOExtString` requires an instance of type `SimpleTimeZone`
+fail_compilation/fail17955.d(96): Error: undefined identifier `DateTimeException`
+fail_compilation/fail17955.d(26): Error: variable `fail17955.isISOExtStringSerializable!(SysTime).isISOExtStringSerializable` - type `void` is inferred from initializer `fromISOExtString("")`, and variables cannot be of type `void`
+fail_compilation/fail17955.d(55): Error: function `fail17955.toRedis!(SysTime).toRedis` has no `return` statement, but is expected to return a value of type `string`
---
*/
/*
TEST_OUTPUT:
---
-fail_compilation/fail20538.d(12): Error: assignment must be preceded by an identifier
-fail_compilation/fail20538.d(12): Error: found `1` when expecting `,`
+fail_compilation/fail20538.d(13): Error: found `=` when expecting `identifier`
+fail_compilation/fail20538.d(13): Error: found `1` when expecting `identifier`
+fail_compilation/fail20538.d(14): Error: named enum cannot declare member with type
---
*/
{
a,
= 1,
+ int x = 1,
@disable b
}
/*
TEST_OUTPUT:
---
-fail_compilation/fail25.d(14): Error: need `this` for `yuiop` of type `int`
+fail_compilation/fail25.d(14): Error: accessing non-static variable `yuiop` requires an instance of `Qwert`
---
*/
/*
TEST_OUTPUT:
---
-fail_compilation/fail301.d(11): Error: need `this` for `guard` of type `int`
+fail_compilation/fail301.d(11): Error: accessing non-static variable `guard` requires an instance of `bug3305b`
fail_compilation/fail301.d(22): Error: template instance `fail301.bug3305!0` error instantiating
---
*/
/*
TEST_OUTPUT:
---
-fail_compilation/fail46.d(19): Error: need `this` for `bug` of type `int()`
+fail_compilation/fail46.d(19): Error: calling non-static function `bug` requires an instance of type `MyStruct`
---
*/
/*
TEST_OUTPUT:
---
-fail_compilation/fail4923.d(4): Error: immutable variable `bar` initialization is not allowed in `static this`
-fail_compilation/fail4923.d(4): Use `shared static this` instead.
+fail_compilation/fail4923.d(5): Error: immutable variable `bar` initialization is not allowed in `static this`
+fail_compilation/fail4923.d(5): Use `shared static this` instead.
+fail_compilation/fail4923.d(6): Deprecation: const variable `baz` initialization is not allowed in `static this`
+fail_compilation/fail4923.d(6): Use `shared static this` instead.
---
*/
#line 1
immutable int bar;
+const int baz; // https://issues.dlang.org/show_bug.cgi?id=24056
static this()
{
bar = 42;
+ baz = 43;
}
/*
TEST_OUTPUT:
---
-fail_compilation/fail50.d(12): Error: need `this` for address of `a`
+fail_compilation/fail50.d(12): Error: taking the address of non-static variable `a` requires an instance of `Marko`
fail_compilation/fail50.d(12): Error: variable `a` cannot be read at compile time
---
*/
fail_compilation/fail61.d(22): Error: no property `B` for type `fail61.A.B`
fail_compilation/fail61.d(23): Error: no property `B` for type `fail61.A.B`
fail_compilation/fail61.d(32): Error: no property `A2` for type `fail61.B2`
-fail_compilation/fail61.d(41): Error: need `this` for `foo` of type `void()`
+fail_compilation/fail61.d(41): Error: calling non-static function `foo` requires an instance of type `B3`
---
*/
class C4
{
static const int x;
- static this() { x = 5; }
+ shared static this() { x = 5; }
void foo()
{
x = 4;
---
*/
const int z5;
-static this() { z5 = 3; }
+shared static this() { z5 = 3; }
void test5()
{
z5 = 4;
/*
TEST_OUTPUT:
---
-fail_compilation/fail7851.d(38): Error: need `this` for `__mem_field_0` of type `int`
-fail_compilation/fail7851.d(38): Error: need `this` for `__mem_field_1` of type `long`
-fail_compilation/fail7851.d(38): Error: need `this` for `__mem_field_2` of type `float`
+fail_compilation/fail7851.d(38): Error: accessing non-static variable `__mem_field_0` requires an instance of `Tuple`
+fail_compilation/fail7851.d(38): Error: accessing non-static variable `__mem_field_1` requires an instance of `Tuple`
+fail_compilation/fail7851.d(38): Error: accessing non-static variable `__mem_field_2` requires an instance of `Tuple`
---
*/
/*
TEST_OUTPUT:
---
-fail_compilation/fail9613.d(12): Error: `(arguments)` expected following `const(byte)`
+fail_compilation/fail9613.d(12): Error: `(arguments)` expected following `const(byte)`, not `.`
fail_compilation/fail9613.d(12): Error: semicolon expected following auto declaration, not `.`
---
*/
/*
-REQUIRED_ARGS:
+REQUIRED_ARGS: -wo
TEST_OUTPUT:
---
fail_compilation/fail_scope.d(30): Deprecation: scope parameter `da` may not be returned
fail_compilation/fail_scope.d(92): Error: returning `cast(int[])a` escapes a reference to local variable `a`
fail_compilation/fail_scope.d(100): Error: returning `cast(int[])a` escapes a reference to local variable `a`
fail_compilation/fail_scope.d(108): Error: escaping reference to outer local variable `x`
-fail_compilation/fail_scope.d(127): Deprecation: returning `s.bar()` escapes a reference to local variable `s`
+fail_compilation/fail_scope.d(127): Warning: returning `s.bar()` escapes a reference to local variable `s`
fail_compilation/fail_scope.d(137): Error: returning `foo16226(i)` escapes a reference to local variable `i`
---
//fail_compilation/fail_scope.d(35): Error: scope variable `da` may not be returned
/* TEST_OUTPUT:
---
-fail_compilation/failcontracts.d(18): Error: missing `{ ... }` for function literal
-fail_compilation/failcontracts.d(18): Error: semicolon expected following auto declaration, not `bode`
-fail_compilation/failcontracts.d(19): Error: function declaration without return type. (Note that constructors are always named `this`)
-fail_compilation/failcontracts.d(19): Error: no identifier for declarator `test1()`
+fail_compilation/failcontracts.d(17): Error: missing `{ ... }` for function literal
+fail_compilation/failcontracts.d(17): Error: semicolon expected following auto declaration, not `bode`
+fail_compilation/failcontracts.d(18): Error: function declaration without return type. (Note that constructors are always named `this`)
+fail_compilation/failcontracts.d(18): Error: no identifier for declarator `test1()`
+fail_compilation/failcontracts.d(18): Error: semicolon expected following function declaration, not `bode`
fail_compilation/failcontracts.d(19): Error: semicolon expected following function declaration, not `bode`
-fail_compilation/failcontracts.d(20): Error: semicolon expected following function declaration, not `bode`
-fail_compilation/failcontracts.d(22): Error: unexpected `(` in declarator
-fail_compilation/failcontracts.d(22): Error: found `T` when expecting `)`
-fail_compilation/failcontracts.d(22): Error: enum declaration is invalid
-fail_compilation/failcontracts.d(22): Error: found `)` instead of statement
+fail_compilation/failcontracts.d(21): Error: unexpected `(` in declarator
+fail_compilation/failcontracts.d(21): Error: found `T` when expecting `)`
+fail_compilation/failcontracts.d(21): Error: expected `{`, not `;` for enum declaration
---
*/
/*
TEST_OUTPUT:
---
-fail_compilation/ice15332.d(16): Error: need `this` for `fun` of type `int()`
-fail_compilation/ice15332.d(17): Error: need `this` for `var` of type `int`
+fail_compilation/ice15332.d(16): Error: calling non-static function `fun` requires an instance of type `C`
+fail_compilation/ice15332.d(17): Error: accessing non-static variable `var` requires an instance of `C`
---
*/
fail_compilation/ice15922.d(23): Error: function `ice15922.ValidSparseDataStore!int.ValidSparseDataStore.correctedInsert!false.correctedInsert` has no `return` statement, but is expected to return a value of type `int`
fail_compilation/ice15922.d(21): Error: template instance `ice15922.ValidSparseDataStore!int.ValidSparseDataStore.correctedInsert!false` error instantiating
fail_compilation/ice15922.d(26): instantiated from here: `ValidSparseDataStore!int`
-fail_compilation/ice15922.d(14): Error: need `this` for `insert` of type `pure nothrow @nogc @safe int()`
+fail_compilation/ice15922.d(14): Error: calling non-static function `insert` requires an instance of type `ValidSparseDataStore`
fail_compilation/ice15922.d(26): Error: template instance `ice15922.StorageAttributes!(ValidSparseDataStore!int)` error instantiating
---
*/
/*
TEST_OUTPUT:
---
-fail_compilation/ice20056.d(19): Error: need `this` for `iter` of type `void()`
+fail_compilation/ice20056.d(19): Error: calling non-static function `iter` requires an instance of type `RangeWrapper`
---
*/
struct Def(alias fn)
/*
TEST_OUTPUT:
---
-fail_compilation/ice7645.d(28): Error: need `this` for `t` of type `char`
-fail_compilation/ice7645.d(31): Error: need `this` for `fn` of type `pure nothrow @nogc @safe void()`
+fail_compilation/ice7645.d(28): Error: accessing non-static variable `t` requires an instance of `C2`
+fail_compilation/ice7645.d(31): Error: calling non-static function `fn` requires an instance of type `S2`
---
*/
/*
TEST_OUTPUT:
---
-fail_compilation/ice9439.d(12): Error: need `this` for `foo` of type `int()`
+fail_compilation/ice9439.d(12): Error: calling non-static function `foo` requires an instance of type `Derived`
fail_compilation/ice9439.d(12): while evaluating: `static assert(foo())`
fail_compilation/ice9439.d(19): Error: template instance `ice9439.Base.boo!(foo)` error instantiating
---
fail_compilation/misc_parser_err_cov1.d(38): Error: missing closing `)` after `if (parseShift!()`
fail_compilation/misc_parser_err_cov1.d(38): Error: found `)` when expecting `(`
fail_compilation/misc_parser_err_cov1.d(39): Error: missing closing `)` after `if (`
-fail_compilation/misc_parser_err_cov1.d(39): Error: identifier expected following `(type)`.
+fail_compilation/misc_parser_err_cov1.d(39): Error: identifier expected following `immutable(int).`, not `+`
fail_compilation/misc_parser_err_cov1.d(39): Error: expression expected, not `;`
fail_compilation/misc_parser_err_cov1.d(40): Error: semicolon expected following auto declaration, not `auto`
fail_compilation/misc_parser_err_cov1.d(40): Error: identifier or `new` expected following `.`, not `+`
/* TEST_OUTPUT:
---
-fail_compilation/mixintype2.d(10): Error: alias `mixintype2.Foo.T` recursive alias declaration
-fail_compilation/mixintype2.d(16): Error: `mixin(0)` does not give a valid type
+fail_compilation/mixintype2.d(13): Error: alias `mixintype2.Foo.T` recursive alias declaration
+fail_compilation/mixintype2.d(19): Error: `mixin(0)` does not give a valid type
+fail_compilation/mixintype2.d(20): Error: unexpected token `{` after type `int()`
+fail_compilation/mixintype2.d(20): while parsing string mixin type `int() {}`
+fail_compilation/mixintype2.d(20): Error: `mixin(_error_)` does not give a valid type
---
*/
void func (T2 p) {}
enum mixin(0) a = 0;
+mixin("int() {}") f;
TEST_OUTPUT:
---
-fail_compilation\noreturn.d(38): Error: `"Accessed expression of type `noreturn`"`
+fail_compilation\noreturn.d(38): Error: Accessed expression of type `noreturn`
fail_compilation\noreturn.d(42): called from here: `assign()`
-fail_compilation\noreturn.d(49): Error: `"Accessed expression of type `noreturn`"`
+fail_compilation\noreturn.d(49): Error: Accessed expression of type `noreturn`
fail_compilation\noreturn.d(49): called from here: `foo(n)`
fail_compilation\noreturn.d(53): called from here: `calling()`
-fail_compilation\noreturn.d(59): Error: `"Accessed expression of type `noreturn`"`
+fail_compilation\noreturn.d(59): Error: Accessed expression of type `noreturn`
fail_compilation\noreturn.d(62): called from here: `nested()`
-fail_compilation\noreturn.d(68): Error: `"Accessed expression of type `noreturn`"`
+fail_compilation\noreturn.d(68): Error: Accessed expression of type `noreturn`
fail_compilation\noreturn.d(78): called from here: `casting(0)`
-fail_compilation\noreturn.d(69): Error: `"Accessed expression of type `noreturn`"`
+fail_compilation\noreturn.d(69): Error: Accessed expression of type `noreturn`
fail_compilation\noreturn.d(79): called from here: `casting(1)`
-fail_compilation\noreturn.d(72): Error: `"Accessed expression of type `noreturn`"`
+fail_compilation\noreturn.d(72): Error: Accessed expression of type `noreturn`
fail_compilation\noreturn.d(80): called from here: `casting(2)`
fail_compilation/noreturn.d(120): Error: uncaught CTFE exception `object.Exception("")`
---
TEST_OUTPUT:
---
-fail_compilation/noreturn.d(135): Error: `"Accessed expression of type `noreturn`"`
+fail_compilation/noreturn.d(135): Error: Accessed expression of type `noreturn`
fail_compilation/noreturn.d(138): called from here: `func()`
---
*/
UnkownException("")
;
}
+
+/+
+https://issues.dlang.org/show_bug.cgi?id=24054
+TEST_OUTPUT:
+---
+fail_compilation/noreturn2.d(153): Error: cannot return from `noreturn` function
+fail_compilation/noreturn2.d(153): Consider adding an endless loop, `assert(0)`, or another `noreturn` expression
+---
++/
+const(noreturn) f()
+{
+ return;
+}
REQUIRED_ARGS: -preview=systemVariables
TEST_OUTPUT:
---
-fail_compilation/systemvariables.d(30): Error: cannot access `@system` variable `gInt` in @safe code
-fail_compilation/systemvariables.d(31): Error: cannot access `@system` variable `gInt` in @safe code
-fail_compilation/systemvariables.d(32): Error: cannot access `@system` variable `gArr` in @safe code
-fail_compilation/systemvariables.d(33): Error: cannot access `@system` variable `gArr` in @safe code
-fail_compilation/systemvariables.d(34): Error: cannot access `@system` variable `gInt` in @safe code
-fail_compilation/systemvariables.d(37): Error: cannot access `@system` variable `lSys` in @safe code
-fail_compilation/systemvariables.d(38): Error: cannot access `@system` variable `lSys` in @safe code
-fail_compilation/systemvariables.d(39): Error: cannot access `@system` variable `lSys` in @safe code
-fail_compilation/systemvariables.d(41): Error: cannot access `@system` variable `eInt` in @safe code
+fail_compilation/systemvariables.d(39): Error: cannot access `@system` variable `gInt` in @safe code
+fail_compilation/systemvariables.d(29): `gInt` is declared here
+fail_compilation/systemvariables.d(40): Error: cannot access `@system` variable `gInt` in @safe code
+fail_compilation/systemvariables.d(29): `gInt` is declared here
+fail_compilation/systemvariables.d(41): Error: cannot access `@system` variable `gArr` in @safe code
+fail_compilation/systemvariables.d(31): `gArr` is declared here
+fail_compilation/systemvariables.d(42): Error: cannot access `@system` variable `gArr` in @safe code
+fail_compilation/systemvariables.d(31): `gArr` is declared here
+fail_compilation/systemvariables.d(43): Error: cannot access `@system` variable `gInt` in @safe code
+fail_compilation/systemvariables.d(29): `gInt` is declared here
+fail_compilation/systemvariables.d(46): Error: cannot access `@system` variable `lSys` in @safe code
+fail_compilation/systemvariables.d(45): `lSys` is declared here
+fail_compilation/systemvariables.d(47): Error: cannot access `@system` variable `lSys` in @safe code
+fail_compilation/systemvariables.d(45): `lSys` is declared here
+fail_compilation/systemvariables.d(48): Error: cannot access `@system` variable `lSys` in @safe code
+fail_compilation/systemvariables.d(45): `lSys` is declared here
+fail_compilation/systemvariables.d(50): Error: cannot access `@system` variable `eInt` in @safe code
+fail_compilation/systemvariables.d(30): `eInt` is declared here
---
*/
-/*
+/* REQUIRED_ARGS: -wo
TEST_OUTPUT:
---
fail_compilation/test13536.d(23): Error: field `U.sysDg` cannot access pointers in `@safe` code that overlap other fields
-fail_compilation/test13536.d(23): Deprecation: address of variable `s` assigned to `u` with longer lifetime
+fail_compilation/test13536.d(23): Warning: address of variable `s` assigned to `u` with longer lifetime
fail_compilation/test13536.d(24): Error: field `U.safeDg` cannot access pointers in `@safe` code that overlap other fields
---
*/
-/*
+/* REQUIRED_ARGS: -wo
TEST_OUTPUT:
---
fail_compilation/test16365.d(21): Error: `this` reference necessary to take address of member `f1` in `@safe` function `main`
fail_compilation/test16365.d(23): Error: cannot implicitly convert expression `&f2` of type `void delegate() pure nothrow @nogc @safe` to `void function() @safe`
-fail_compilation/test16365.d(27): Deprecation: address of variable `s` assigned to `dg` with longer lifetime
+fail_compilation/test16365.d(27): Warning: address of variable `s` assigned to `dg` with longer lifetime
fail_compilation/test16365.d(28): Error: `dg.funcptr` cannot be used in `@safe` code
---
*/
TEST_OUTPUT:
---
fail_compilation/test21008.d(110): Error: function `test21008.C.after` circular reference to class `C`
-fail_compilation/test21008.d(117): Error: need `this` for `toString` of type `string()`
-fail_compilation/test21008.d(117): Error: need `this` for `toHash` of type `nothrow @trusted $?:32=uint|64=ulong$()`
+fail_compilation/test21008.d(117): Error: calling non-static function `toString` requires an instance of type `Object`
+fail_compilation/test21008.d(117): Error: calling non-static function `toHash` requires an instance of type `Object`
fail_compilation/test21008.d(117): Error: function `object.Object.opCmp(Object o)` is not callable using argument types `()`
fail_compilation/test21008.d(117): too few arguments, expected 1, got 0
fail_compilation/test21008.d(117): Error: function `object.Object.opEquals(Object o)` is not callable using argument types `()`
fail_compilation/test9701.d(39): Error: `@system` is not a valid attribute for enum members
fail_compilation/test9701.d(40): Error: `@trusted` is not a valid attribute for enum members
fail_compilation/test9701.d(41): Error: `@nogc` is not a valid attribute for enum members
-fail_compilation/test9701.d(42): Error: `pure` is not a valid attribute for enum members
-fail_compilation/test9701.d(43): Error: `shared` is not a valid attribute for enum members
-fail_compilation/test9701.d(44): Error: `inout` is not a valid attribute for enum members
-fail_compilation/test9701.d(45): Error: `immutable` is not a valid attribute for enum members
-fail_compilation/test9701.d(46): Error: `const` is not a valid attribute for enum members
-fail_compilation/test9701.d(47): Error: `synchronized` is not a valid attribute for enum members
-fail_compilation/test9701.d(48): Error: `scope` is not a valid attribute for enum members
-fail_compilation/test9701.d(49): Error: `auto` is not a valid attribute for enum members
-fail_compilation/test9701.d(50): Error: `ref` is not a valid attribute for enum members
-fail_compilation/test9701.d(51): Error: `__gshared` is not a valid attribute for enum members
-fail_compilation/test9701.d(52): Error: `final` is not a valid attribute for enum members
-fail_compilation/test9701.d(53): Error: `extern` is not a valid attribute for enum members
-fail_compilation/test9701.d(54): Error: `export` is not a valid attribute for enum members
-fail_compilation/test9701.d(55): Error: `nothrow` is not a valid attribute for enum members
-fail_compilation/test9701.d(56): Error: `public` is not a valid attribute for enum members
-fail_compilation/test9701.d(57): Error: `private` is not a valid attribute for enum members
-fail_compilation/test9701.d(58): Error: `package` is not a valid attribute for enum members
-fail_compilation/test9701.d(59): Error: `static` is not a valid attribute for enum members
-fail_compilation/test9701.d(60): Error: `static` is not a valid attribute for enum members
-fail_compilation/test9701.d(61): Error: `static` is not a valid attribute for enum members
-fail_compilation/test9701.d(62): Error: `static` is not a valid attribute for enum members
+fail_compilation/test9701.d(42): Error: found `pure` when expecting `identifier`
+fail_compilation/test9701.d(43): Error: found `shared` when expecting `identifier`
+fail_compilation/test9701.d(44): Error: found `inout` when expecting `identifier`
+fail_compilation/test9701.d(45): Error: found `immutable` when expecting `identifier`
+fail_compilation/test9701.d(46): Error: found `const` when expecting `identifier`
+fail_compilation/test9701.d(47): Error: found `synchronized` when expecting `identifier`
+fail_compilation/test9701.d(48): Error: found `scope` when expecting `identifier`
+fail_compilation/test9701.d(49): Error: found `auto` when expecting `identifier`
+fail_compilation/test9701.d(50): Error: found `ref` when expecting `identifier`
+fail_compilation/test9701.d(51): Error: found `__gshared` when expecting `identifier`
+fail_compilation/test9701.d(52): Error: found `final` when expecting `identifier`
+fail_compilation/test9701.d(53): Error: found `extern` when expecting `identifier`
+fail_compilation/test9701.d(54): Error: found `export` when expecting `identifier`
+fail_compilation/test9701.d(55): Error: found `nothrow` when expecting `identifier`
+fail_compilation/test9701.d(56): Error: found `public` when expecting `identifier`
+fail_compilation/test9701.d(57): Error: found `private` when expecting `identifier`
+fail_compilation/test9701.d(58): Error: found `package` when expecting `identifier`
+fail_compilation/test9701.d(59): Error: found `static` when expecting `identifier`
+fail_compilation/test9701.d(60): Error: found `static` when expecting `identifier`
+fail_compilation/test9701.d(61): Error: found `static` when expecting `identifier`
+fail_compilation/test9701.d(62): Error: found `static` when expecting `identifier`
---
*/
/*
TEST_OUTPUT:
---
-runnable/aliasthis.d(103): Deprecation: alias this for classes/interfaces is deprecated
-runnable/aliasthis.d(291): Deprecation: alias this for classes/interfaces is deprecated
-runnable/aliasthis.d(292): Deprecation: alias this for classes/interfaces is deprecated
-runnable/aliasthis.d(294): Deprecation: alias this for classes/interfaces is deprecated
-runnable/aliasthis.d(465): Deprecation: alias this for classes/interfaces is deprecated
-runnable/aliasthis.d(466): Deprecation: alias this for classes/interfaces is deprecated
-runnable/aliasthis.d(477): Deprecation: alias this for classes/interfaces is deprecated
-runnable/aliasthis.d(1013): Deprecation: alias this for classes/interfaces is deprecated
false
-runnable/aliasthis.d(2100): Deprecation: alias this for classes/interfaces is deprecated
[] = int
[] = string
[0] = int
[] = int
[1] = string
[0] = int
-runnable/aliasthis.d(741): Deprecation: alias this for classes/interfaces is deprecated
---
RUN_OUTPUT:
{
real x = 3;
creal a = (2 + 4i) % 3;
- printf("%Lg %Lgi\n", a.re, a.im);
+ //printf("%Lg %Lgi\n", a.re, a.im);
assert(a == 2 + 1i);
creal b = (2 + 4i) % x;
- printf("%Lg %Lgi\n", b.re, b.im);
+ //printf("%Lg %Lgi\n", b.re, b.im);
assert(b == a);
}
{
ireal a = 5i;
ireal b = a % 2;
- printf("%Lg %Lgi\n", b.re, b.im);
+ //printf("%Lg %Lgi\n", b.re, b.im);
assert(b == 1i);
}
{
static creal[] params = [1+0i, 3+0i, 5+0i];
- printf("params[0] = %Lf + %Lfi\n", params[0].re, params[0].im);
- printf("params[1] = %Lf + %Lfi\n", params[1].re, params[1].im);
- printf("params[2] = %Lf + %Lfi\n", params[2].re, params[2].im);
+ //printf("params[0] = %Lf + %Lfi\n", params[0].re, params[0].im);
+ //printf("params[1] = %Lf + %Lfi\n", params[1].re, params[1].im);
+ //printf("params[2] = %Lf + %Lfi\n", params[2].re, params[2].im);
creal[] sums = new creal[3];
sums[] = 0+0i;
void test24()
{
ifloat f = func_24_1(10i, 8);
- printf("%fi\n", f);
+ //printf("%fi\n", f);
// assert(f == 1.25i);
f = func_24_2(10i, 8);
- printf("%fi\n", f);
+ //printf("%fi\n", f);
assert(f == 1.25i);
float g = func_24_3(10, 8);
- printf("%f\n", g);
+ //printf("%f\n", g);
// assert(g == 1.25);
g = func_24_4(10, 8);
- printf("%f\n", g);
+ //printf("%f\n", g);
assert(g == 1.25);
}
foreach( cdouble z; A )
{
s = toString26(z);
- printf("%.*s ", cast(int)s.length, s.ptr);
+ //printf("%.*s ", cast(int)s.length, s.ptr);
}
- printf("\n");
+ //printf("\n");
for(int ii=0; ii<A.length; ii++ )
A[ii] += -1i*A[ii];
foreach( cdouble z; A )
{
s = toString26(z);
- printf("%.*s ", cast(int)s.length, s.ptr);
+ //printf("%.*s ", cast(int)s.length, s.ptr);
}
- printf("\n");
+ //printf("\n");
}
/*************************************/
void test29()
{
ireal a = 6.5i % 3i;
- printf("%Lfi %Lfi\n", a, a - .5i);
+ //printf("%Lfi %Lfi\n", a, a - .5i);
assert(a == .5i);
a = 6.5i % 3;
- printf("%Lfi %Lfi\n", a, a - .5i);
+ //printf("%Lfi %Lfi\n", a, a - .5i);
assert(a == .5i);
real b = 6.5 % 3i;
- printf("%Lf %Lf\n", b, b - .5);
+ //printf("%Lf %Lf\n", b, b - .5);
assert(b == .5);
b = 6.5 % 3;
- printf("%Lf %Lf\n", b, b - .5);
+ //printf("%Lf %Lf\n", b, b - .5);
assert(b == .5);
}
{
cfloat f = 1+0i;
f %= 2fi;
- printf("%f + %fi\n", f.re, f.im);
+ //printf("%f + %fi\n", f.re, f.im);
assert(f == 1 + 0i);
cdouble d = 1+0i;
d %= 2i;
- printf("%f + %fi\n", d.re, d.im);
+ //printf("%f + %fi\n", d.re, d.im);
assert(d == 1 + 0i);
creal r = 1+0i;
r %= 2i;
- printf("%Lf + %Lfi\n", r.re, r.im);
+ //printf("%Lf + %Lfi\n", r.re, r.im);
assert(r == 1 + 0i);
}
{
cfloat f = 1+0i;
f %= 2i;
- printf("%f + %fi\n", f.re, f.im);
+ //printf("%f + %fi\n", f.re, f.im);
assert(f == 1);
cdouble d = 1+0i;
d = d % 2i;
- printf("%f + %fi\n", d.re, d.im);
+ //printf("%f + %fi\n", d.re, d.im);
assert(d == 1);
creal r = 1+0i;
r = r % 2i;
- printf("%Lf + %Lfi\n", r.re, r.im);
+ //printf("%Lf + %Lfi\n", r.re, r.im);
assert(r == 1);
}
{
if (x[i] != y[i])
{
- printf("%02zd: %02x %02x\n", i, x[i], y[i]);
+ //printf("%02zd: %02x %02x\n", i, x[i], y[i]);
import core.exception;
throw new AssertError(file, line);
}
void test36()
{
ireal imag = 2.5i;
- printf ("test of imag*imag = %Lf\n",imag*imag);
+ //printf ("test of imag*imag = %Lf\n",imag*imag);
assert(imag * imag == -6.25);
}
creal z = 1 + 2.5i;
real e = z.im;
- printf ("e = %Lf\n", e);
+ //printf ("e = %Lf\n", e);
assert(e == 2.5);
}
{
ifloat f = 1.0fi;
// f *= 2.0fi; // illegal but compiles
- printf("%g\n", f);
+ //printf("%g\n", f);
// assert(f == 0i);
}
true
g
&Test109S(&Test109S(<recursion>))
-runnable/interpret.d(3742): Deprecation: alias this for classes/interfaces is deprecated
tfoo
tfoo
Crash!
Q opOpAssign(string op)(int w) if (op == "-")
{
x -= w;
- version(D_Version2) { mixin("return this;"); } else { mixin("return *this;"); }
+ return this;
}
int boo() { return 4; }
int coo() { return x; }
int bug2564()
{
- version(D_Version2) { mixin("enum int Q = 0;"); }else {mixin("int Q = 0;"); }
+ enum int Q = 0;
string [2] s = ["a", "b"];
assert(s[Q].dup == "a");
return 0;
/************************************************/
-version(D_Version2)
-{
// https://issues.dlang.org/show_bug.cgi?id=4020
// https://issues.dlang.org/show_bug.cgi?id=4027
// D2 only
static assert(bug4027("aaa")() == "aaa");
static assert(bug4027("bbb")() == "bbb");
}
-}
// ---
// https://issues.dlang.org/show_bug.cgi?id=8940
const int n8940; // or `immutable`
-static this() { n8940 = 3; }
+shared static this() { n8940 = 3; }
void f8940(T)(ref int val)
{
-/*
-TEST_OUTPUT:
----
-runnable/test17684.d(37): Deprecation: alias this for classes/interfaces is deprecated
-runnable/test17684.d(54): Deprecation: alias this for classes/interfaces is deprecated
-runnable/test17684.d(54): Deprecation: alias this for classes/interfaces is deprecated
-runnable/test17684.d(37): Deprecation: alias this for classes/interfaces is deprecated
----
-*/
-
struct StructField(T)
{
static T Field;
// https://issues.dlang.org/show_bug.cgi?id=19782
-
-/*
-TEST_OUTPUT:
----
-runnable/test19782.d(17): Deprecation: alias this for classes/interfaces is deprecated
----
-*/
-
class Inner
{
int a;
{
}
- static this()
+ shared static this()
{
x = 5;
}
const int z60;
-static this()
+shared static this()
{
z60 = 3;
}
// https://issues.dlang.org/show_bug.cgi?id=21039
-/*
-TEST_OUTPUT:
----
-runnable/test21039.d(14): Deprecation: alias this for classes/interfaces is deprecated
----
-*/
-
class Inner {}
class Outer {
// https://issues.dlang.org/show_bug.cgi?id=23234
-/*
-TEST_OUTPUT:
----
-runnable/test23234.d(17): Deprecation: alias this for classes/interfaces is deprecated
----
-*/
-
class Bar
{
}
static this()
{
mg1 = 10;
- cg1 = 10;
}
shared static this()
{
+ cg1 = 10;
ig1 = 10;
}
static assert(!__traits(compiles, { static assert(mg1 == 0); }));
const int x11472 = void;
-static this() { x11472 = 10; }
+shared static this() { x11472 = 10; }
void test11472()
{
// https://issues.dlang.org/show_bug.cgi?id=11294
-/*
-TEST_OUTPUT:
----
-runnable/testaliascast.d(29): Deprecation: alias this for classes/interfaces is deprecated
-runnable/testaliascast.d(58): Deprecation: alias this for classes/interfaces is deprecated
----
-*/
-
string result;
extern(C) void rt_finalize(void *ptr, bool det=true);
REQUIRED_ARGS: -preview=rvaluerefparam
TEST_OUTPUT:
---
-runnable/testassign.d(802): Deprecation: alias this for classes/interfaces is deprecated
-runnable/testassign.d(808): Deprecation: alias this for classes/interfaces is deprecated
\ S1 S2a S2b S3a S3b S4a S4b
- true true true true true true true
Xa true true true true true true true
const char gc6174;
const char[1] ga6174;
-static this()
+shared static this()
{
gc6174 = 'a'; // OK
ga6174[0] = 'a'; // line 5, Err
const Foo8783[1] foos8783;
-static this()
+shared static this()
{
foreach (i; 0 .. foos8783.length)
foos8783[i].bar[i] = 1; // OK
static const int x39;
const int y39;
-static this()
+shared static this()
{
x39 = 3;
y39 = 4;
static const int d;
static const int e = ctfe() + 2;
- static this()
+ shared static this()
{
d = 4;
}
const bool[string] stopWords79;
-static this()
+shared static this()
{
stopWords79 = [ "a"[]:1 ];
}
return y;
}
-static this()
-{
- X15 = 4;
- Z15 = 5;
-}
-
shared static this()
{
+ X15 = 4;
Y15 = 4;
+ Z15 = 5;
}
void test15()
+
module traits_getPointerBitmap;
import core.stdc.stdio;
enum pOff = T.p.offsetof / bytesPerPtr;
}
+class C(T, aliasTo = void)
+{
+ static if(!is(aliasTo == void))
+ {
+ aliasTo a;
+ alias a this;
+ }
+
+ size_t x;
+ T t = void;
+ void* p;
+}
+
///////////////////////////////////////
void _testType(T)(size_t[] expected)
// prepend string
sexp[0] = (expected[0] << tOff!(S!(T, string))) | (1 << pOff!(S!(T, string))) | 2; // arr ptr
_testType!(S!(T, string))(sexp);
+
+ // generate bit pattern for C!T
+ C!T ct = null;
+ size_t mutexBit = (RTInfoMark__Monitor ? 2 : 0);
+ size_t ctpOff = ct.p.offsetof / bytesPerPtr;
+ size_t cttOff = ct.t.offsetof / bytesPerPtr;
+ sexp[0] = (expected[0] << cttOff) | (1 << ctpOff) | mutexBit;
+ _testType!(C!(T))(sexp);
+
+ C!(T, string) cts = null;
+ size_t ctspOff = cts.p.offsetof / bytesPerPtr;
+ size_t ctstOff = cts.t.offsetof / bytesPerPtr;
+ // generate bit pattern for C!T
+ sexp[0] = (expected[0] << ctstOff) | (1 << ctspOff) | mutexBit | 0b1000; // arr ptr
+ _testType!(C!(T, string))(sexp);
}
///////////////////////////////////////
//
/* TEST_OUTPUT:
---
-runnable/xtest46.d(165): Deprecation: alias this for classes/interfaces is deprecated
Boo!double
Boo!int
true
int
!! immutable(int)[]
-runnable/xtest46.d(2932): Deprecation: alias this for classes/interfaces is deprecated
-runnable/xtest46.d(2964): Deprecation: alias this for classes/interfaces is deprecated
int(int i, long j = 7L)
long
C10390(C10390(C10390(<recursion>)))
double[]
double[]
{}
-runnable/xtest46.d(4670): Deprecation: alias this for classes/interfaces is deprecated
AliasSeq!("m")
true
TFunction1: extern (C) void function()
EXTRA_FILES: xtest46.d
TEST_OUTPUT:
---
-runnable/xtest46_gc.d-mixin-33(197): Deprecation: alias this for classes/interfaces is deprecated
Boo!double
Boo!int
true
int
!! immutable(int)[]
-runnable/xtest46_gc.d-mixin-33(2964): Deprecation: alias this for classes/interfaces is deprecated
-runnable/xtest46_gc.d-mixin-33(2996): Deprecation: alias this for classes/interfaces is deprecated
int(int i, long j = 7L)
long
C10390(C10390(<recursion>))
double[]
double[]
{}
-runnable/xtest46_gc.d-mixin-33(4702): Deprecation: alias this for classes/interfaces is deprecated
AliasSeq!("m")
true
TFunction1: extern (C) void function()
-26f049fb26e755096dea3f1474decea7c0fef187
+4574d1728d1f7e52ff40e6733b8c39889d128349
The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository.
void putComma(size_t n)
{
- pragma(inline, false);
+ version (DigitalMars) pragma(inline, false);
if (n)
put(", ");
}
/// Ditto
private noreturn error(string msg = "Invalid symbol") @trusted pure
{
- pragma(inline, false); // tame dmd inliner
+ version (DigitalMars) pragma(inline, false); // tame dmd inliner
//throw new ParseException( msg );
debug(info) printf( "error: %.*s\n", cast(int) msg.length, msg.ptr );
/// Ditto
private noreturn overflow(string msg = "Buffer overflow") @trusted pure
{
- pragma(inline, false); // tame dmd inliner
+ version (DigitalMars) pragma(inline, false); // tame dmd inliner
//throw new OverflowException( msg );
debug(info) printf( "overflow: %.*s\n", cast(int) msg.length, msg.ptr );
// move val to the end of the dst buffer
char[] shift(scope const(char)[] val) return scope
{
- pragma(inline, false); // tame dmd inliner
+ version (DigitalMars) pragma(inline, false); // tame dmd inliner
if (val.length)
{
// remove val from dst buffer
void remove(scope const(char)[] val) scope
{
- pragma(inline, false); // tame dmd inliner
+ version (DigitalMars) pragma(inline, false); // tame dmd inliner
if ( val.length )
{
char[] append(scope const(char)[] val) return scope
{
- pragma(inline, false); // tame dmd inliner
+ version (DigitalMars) pragma(inline, false); // tame dmd inliner
if (val.length)
{
ref Tarr _d_arrayappendcTX(return ref scope Tarr px, size_t n) @trusted pure nothrow
{
// needed for CTFE: https://github.com/dlang/druntime/pull/3870#issuecomment-1178800718
- pragma(inline, false);
+ version (DigitalMars) pragma(inline, false);
version (D_TypeInfo)
{
auto ti = typeid(Tarr);
/// Implementation of `_d_arrayappendT`
ref Tarr _d_arrayappendT(Tarr : T[], T)(return ref scope Tarr x, scope Tarr y) @trusted
{
- pragma(inline, false);
+ version (DigitalMars) pragma(inline, false);
import core.stdc.string : memcpy;
import core.internal.traits : hasElaborateCopyConstructor, Unqual;
*/
size_t _d_arraysetlengthT(return scope ref Tarr arr, size_t newlength) @trusted pure nothrow
{
- pragma(inline, false);
+ version (DigitalMars) pragma(inline, false);
version (D_TypeInfo)
{
auto ti = typeid(Tarr);
*/
Tarr _d_arrayctor(Tarr : T[], T)(return scope Tarr to, scope Tarr from, char* makeWeaklyPure = null) @trusted
{
- pragma(inline, false);
+ version (DigitalMars) pragma(inline, false);
import core.internal.traits : hasElaborateCopyConstructor;
import core.lifetime : copyEmplace;
import core.stdc.string : memcpy;
*/
void _d_arraysetctor(Tarr : T[], T)(scope Tarr p, scope ref T value) @trusted
{
- pragma(inline, false);
+ version (DigitalMars) pragma(inline, false);
import core.lifetime : copyEmplace;
size_t i;
* reentrant, and must be called once for every call to disable before
* automatic collections are enabled.
*/
- pragma(mangle, "gc_enable") static void enable() nothrow pure;
+ pragma(mangle, "gc_enable") static void enable() @safe nothrow pure;
/**
* such as during an out of memory condition. This function is reentrant,
* but enable must be called once for each call to disable.
*/
- pragma(mangle, "gc_disable") static void disable() nothrow pure;
+ pragma(mangle, "gc_disable") static void disable() @safe nothrow pure;
/**
* and then to reclaim free space. This action may need to suspend all
* running threads for at least part of the collection process.
*/
- pragma(mangle, "gc_collect") static void collect() nothrow pure;
+ pragma(mangle, "gc_collect") static void collect() @safe nothrow pure;
/**
* Indicates that the managed memory space be minimized by returning free
* physical memory to the operating system. The amount of free memory
* returned depends on the allocator design and on program behavior.
*/
- pragma(mangle, "gc_minimize") static void minimize() nothrow pure;
+ pragma(mangle, "gc_minimize") static void minimize() @safe nothrow pure;
extern(D):
module core.sys.windows.basetsd;
version (Windows):
-/* This template is used in these modules to declare constant pointer types,
- * in order to support both D 1.x and 2.x.
- * Since removed - now supporting only D2
- */
-/*template CPtr(T) {
- version (D_Version2) {
- // must use mixin so that it doesn't cause a syntax error under D1
- mixin("alias const(T)* CPtr;");
- } else {
- alias T* CPtr;
- }
-}*/
-
-/* [CyberShadow VP 2011.12.22] typedef is now deprecated in D2.
- */
-template TypeDef(T) {
- version (D_Version2) {
- alias T TypeDef;
- } else {
- // must use mixin so that it doesn't cause a deprecation error under D2
- mixin("typedef T TypeDef;");
- }
-}
-
// [SnakE 2009-02-23] Moved HANDLE definition here from winnt.d to avoid
// 'forwatd template reference' to CPtr from winnt.d caused by a circular
// import.
-
-alias TypeDef!(void*) HANDLE;
-/+struct HANDLE {
-const(void)* h;
- alias h this;
-}+/
+alias HANDLE = void*;
package template DECLARE_HANDLE(string name, base = HANDLE) {
mixin ("alias " ~ base.stringof ~ " " ~ name ~ ";");
}
alias MMTIME* PMMTIME, LPMMTIME;
-alias TypeDef!(HANDLE) HDRVR;
+alias HANDLE HDRVR;
struct DRVCONFIGINFO {
align(1):
+/
-alias TypeDef!(HANDLE) HWAVE;
-alias TypeDef!(HANDLE) HWAVEIN;
-alias TypeDef!(HANDLE) HWAVEOUT;
+alias HANDLE HWAVE;
+alias HANDLE HWAVEIN;
+alias HANDLE HWAVEOUT;
alias HWAVEIN* LPHWAVEIN;
alias HWAVEOUT* LPHWAVEOUT;
alias WAVEFORMATEX* PWAVEFORMATEX, LPWAVEFORMATEX;
alias const(WAVEFORMATEX)* LPCWAVEFORMATEX;
-alias TypeDef!(HANDLE) HMIDI;
-alias TypeDef!(HANDLE) HMIDIIN;
-alias TypeDef!(HANDLE) HMIDIOUT;
-alias TypeDef!(HANDLE) HMIDISTRM;
+alias HANDLE HMIDI;
+alias HANDLE HMIDIIN;
+alias HANDLE HMIDIOUT;
+alias HANDLE HMIDISTRM;
alias HMIDI* LPHMIDI;
alias HMIDIIN* LPHMIDIIN;
}
alias AUXCAPSW* PAUXCAPSW, LPAUXCAPSW;
-alias TypeDef!(HANDLE) HMIXEROBJ;
+alias HANDLE HMIXEROBJ;
alias HMIXEROBJ* LPHMIXEROBJ;
-alias TypeDef!(HANDLE) HMIXER;
+alias HANDLE HMIXER;
alias HMIXER* LPHMIXER;
struct MIXERCAPSA {
alias DWORD FOURCC;
alias char* HPSTR;
-alias TypeDef!(HANDLE) HMMIO;
+alias HANDLE HMMIO;
alias LRESULT function (LPSTR, UINT, LPARAM, LPARAM) LPMMIOPROC;
OLESTATUS function(LPOLESERVER) Release;
OLESTATUS function(LPOLESERVER, HGLOBAL) Execute;
}
-alias TypeDef!(OLESERVERVTBL*) LPOLESERVERVTBL;
+alias OLESERVERVTBL* LPOLESERVERVTBL;
struct OLESERVER {
LPOLESERVERVTBL lpvtbl;
}
alias RASPROJECTION* LPRASPROJECTION;
-alias TypeDef!(HANDLE) HRASCONN;
+alias HANDLE HRASCONN;
alias HRASCONN* LPHRASCONN;
struct RASCONNW {
}
alias RPC_CLIENT_INTERFACE* PRPC_CLIENT_INTERFACE;
-alias TypeDef!(void*) I_RPC_MUTEX;
+alias void* I_RPC_MUTEX;
struct RPC_TRANSFER_SYNTAX {
GUID Uuid;
PROXY_UNMARSHAL
}
-alias TypeDef!(void *) RPC_SS_THREAD_HANDLE;
+alias void * RPC_SS_THREAD_HANDLE;
extern (Windows) {
alias void function (void*) NDR_RUNDOWN;
// #endif
//static if (ODBCVER >= 0x0300) {
-alias TypeDef!(HANDLE) SQLHANDLE;
+alias HANDLE SQLHANDLE;
alias SQLHANDLE SQLHENV, SQLHDBC, SQLHSTMT, SQLHDESC;
/*
} else {
enum ICVERSION = 0x0104;
-alias TypeDef!(HANDLE) HIC;
+alias HANDLE HIC;
enum BI_1632 = 0x32333631;
#endif
};
-alias TypeDef!(IAVIStream FAR*) PAVISTREAM;
+alias IAVIStream FAR* PAVISTREAM;
#undef INTERFACE
#define INTERFACE IAVIStreaming
STDMETHOD(End) (THIS) PURE;
};
-alias TypeDef!(IAVIStreaming FAR*) PAVISTREAMING;
+alias IAVIStreaming FAR* PAVISTREAMING;
#undef INTERFACE
LONG cbInfo) PURE;
};
-alias TypeDef!(IAVIEditStream FAR*) PAVIEDITSTREAM;
+alias IAVIEditStream FAR* PAVIEDITSTREAM;
#undef INTERFACE
#define INTERFACE IAVIPersistFile
STDMETHOD(Reserved1)(THIS) PURE;
};
-alias TypeDef!(IAVIPersistFile FAR*) PAVIPERSISTFILE;
+alias IAVIPersistFile FAR* PAVIPERSISTFILE;
#undef INTERFACE
#define INTERFACE IAVIFile
};
#undef PAVIFILE
-alias TypeDef!(IAVIFile FAR*) PAVIFILE;
+alias IAVIFile FAR* PAVIFILE;
#undef INTERFACE
#define INTERFACE IGetFrame
};
#undef PGETFRAME
-alias TypeDef!(IGetFrame FAR*) PGETFRAME;
+alias IGetFrame FAR* PGETFRAME;
#define DEFINE_AVIGUID(name, l, w1, w2) DEFINE_GUID(name, l, w1, w2, 0xC0,0,0,0,0,0,0,0x46)
MCI_MODE_OPEN,
}
-alias TypeDef!(HANDLE) HVIDEO;
+alias HANDLE HVIDEO;
alias HVIDEO* LPHVIDEO;
// Error Return Values
STD_ERROR_HANDLE = 0xFFFFFFF4
}
-enum HANDLE INVALID_HANDLE_VALUE = cast(HANDLE) (-1);
+@trusted enum HANDLE INVALID_HANDLE_VALUE = cast(HANDLE) (-1);
enum : DWORD {
GET_TAPE_MEDIA_INFORMATION = 0,
POINTL ptlEnd;
}
alias EMRARC* PEMRARC;
-alias TypeDef!(EMRARC) EMRARCTO;
+alias EMRARC EMRARCTO;
alias EMRARCTO* PEMRARCTO;
-alias TypeDef!(EMRARC) EMRCHORD;
+alias EMRARC EMRCHORD;
alias EMRCHORD* PEMRCHORD;
-alias TypeDef!(EMRARC) EMRPIE;
+alias EMRARC EMRPIE;
alias EMRPIE* PEMRPIE;
struct XFORM {
COLORREF lbColor;
ULONG_PTR lbHatch;
}
-alias TypeDef!(LOGBRUSH) PATTERN;
+alias LOGBRUSH PATTERN;
alias LOGBRUSH* PLOGBRUSH, NPLOGBRUSH, LPLOGBRUSH;
alias PATTERN* PPATTERN, NPPATTERN, LPPATTERN;
DWORD ihCS;
}
alias EMRSETCOLORSPACE* PEMRSETCOLORSPACE;
-alias TypeDef!(EMRSETCOLORSPACE) EMRSELECTCOLORSPACE;
+alias EMRSETCOLORSPACE EMRSELECTCOLORSPACE;
alias EMRSELECTCOLORSPACE* PEMRSELECTCOLORSPACE;
-alias TypeDef!(EMRSETCOLORSPACE) EMRDELETECOLORSPACE;
+alias EMRSETCOLORSPACE EMRDELETECOLORSPACE;
alias EMRDELETECOLORSPACE* PEMRDELETECOLORSPACE;
static if (_WIN32_WINNT >= 0x500) {
BYTE[1] EscData;
}
alias EMREXTESCAPE* PEMREXTESCAPE;
- alias TypeDef!(EMREXTESCAPE) EMRDRAWESCAPE;
+ alias EMREXTESCAPE EMRDRAWESCAPE;
alias EMRDRAWESCAPE* PEMRDRAWESCAPE;
struct EMRNAMEDESCAPE {
BYTE[1] Data;
}
alias EMRSETICMPROFILE* PEMRSETICMPROFILE;
- alias TypeDef!(EMRSETICMPROFILE) EMRSETICMPROFILEA;
+ alias EMRSETICMPROFILE EMRSETICMPROFILEA;
alias EMRSETICMPROFILEA* PEMRSETICMPROFILEA;
- alias TypeDef!(EMRSETICMPROFILE) EMRSETICMPROFILEW;
+ alias EMRSETICMPROFILE EMRSETICMPROFILEW;
alias EMRSETICMPROFILEW* PEMRSETICMPROFILEW;
struct EMRCREATECOLORSPACEW {
}
alias EMRELLIPSE* PEMRELLIPSE;
-alias TypeDef!(EMRELLIPSE) EMRRECTANGLE;
+alias EMRELLIPSE EMRRECTANGLE;
alias EMRRECTANGLE* PEMRRECTANGLE;
struct EMREOF {
RECTL rclClip;
}
alias EMREXCLUDECLIPRECT* PEMREXCLUDECLIPRECT;
-alias TypeDef!(EMREXCLUDECLIPRECT) EMRINTERSECTCLIPRECT;
+alias EMREXCLUDECLIPRECT EMRINTERSECTCLIPRECT;
alias EMRINTERSECTCLIPRECT* PEMRINTERSECTCLIPRECT;
struct EMREXTCREATEFONTINDIRECTW {
EMRTEXT emrtext;
}
alias EMREXTTEXTOUTA* PEMREXTTEXTOUTA;
-alias TypeDef!(EMREXTTEXTOUTA) EMREXTTEXTOUTW;
+alias EMREXTTEXTOUTA EMREXTTEXTOUTW;
alias EMREXTTEXTOUTW* PEMREXTTEXTOUTW;
struct EMRFILLPATH {
}
alias EMRFILLPATH* PEMRFILLPATH;
-alias TypeDef!(EMRFILLPATH) EMRSTROKEANDFILLPATH;
+alias EMRFILLPATH EMRSTROKEANDFILLPATH;
alias EMRSTROKEANDFILLPATH* PEMRSTROKEANDFILLPATH;
-alias TypeDef!(EMRFILLPATH) EMRSTROKEPATH;
+alias EMRFILLPATH EMRSTROKEPATH;
alias EMRSTROKEPATH* PEMRSTROKEPATH;
struct EMRFILLRGN {
BYTE[1] RgnData;
}
alias EMRINVERTRGN* PEMRINVERTRGN;
-alias TypeDef!(EMRINVERTRGN) EMRPAINTRGN;
+alias EMRINVERTRGN EMRPAINTRGN;
alias EMRPAINTRGN* PEMRPAINTRGN;
struct EMRLINETO {
POINTL ptl;
}
alias EMRLINETO* PEMRLINETO;
-alias TypeDef!(EMRLINETO) EMRMOVETOEX;
+alias EMRLINETO EMRMOVETOEX;
alias EMRMOVETOEX* PEMRMOVETOEX;
struct EMRMASKBLT {
POINTL[1] aptl;
}
alias EMRPOLYLINE* PEMRPOLYLINE;
-alias TypeDef!(EMRPOLYLINE) EMRPOLYBEZIER;
+alias EMRPOLYLINE EMRPOLYBEZIER;
alias EMRPOLYBEZIER* PEMRPOLYBEZIER;
-alias TypeDef!(EMRPOLYLINE) EMRPOLYGON;
+alias EMRPOLYLINE EMRPOLYGON;
alias EMRPOLYGON* PEMRPOLYGON;
-alias TypeDef!(EMRPOLYLINE) EMRPOLYBEZIERTO;
+alias EMRPOLYLINE EMRPOLYBEZIERTO;
alias EMRPOLYBEZIERTO* PEMRPOLYBEZIERTO;
-alias TypeDef!(EMRPOLYLINE) EMRPOLYLINETO;
+alias EMRPOLYLINE EMRPOLYLINETO;
alias EMRPOLYLINETO* PEMRPOLYLINETO;
struct EMRPOLYLINE16 {
POINTS[1] apts;
}
alias EMRPOLYLINE16* PEMRPOLYLINE16;
-alias TypeDef!(EMRPOLYLINE16) EMRPOLYBEZIER16;
+alias EMRPOLYLINE16 EMRPOLYBEZIER16;
alias EMRPOLYBEZIER16* PEMRPOLYBEZIER16;
-alias TypeDef!(EMRPOLYLINE16) EMRPOLYGON16;
+alias EMRPOLYLINE16 EMRPOLYGON16;
alias EMRPOLYGON16* PEMRPOLYGON16;
-alias TypeDef!(EMRPOLYLINE16) EMRPOLYBEZIERTO16;
+alias EMRPOLYLINE16 EMRPOLYBEZIERTO16;
alias EMRPOLYBEZIERTO16* PEMRPOLYBEZIERTO16;
-alias TypeDef!(EMRPOLYLINE16) EMRPOLYLINETO16;
+alias EMRPOLYLINE16 EMRPOLYLINETO16;
alias EMRPOLYLINETO16* PEMRPOLYLINETO16;
struct EMRPOLYPOLYLINE {
POINTL[1] aptl;
}
alias EMRPOLYPOLYLINE* PEMRPOLYPOLYLINE;
-alias TypeDef!(EMRPOLYPOLYLINE) EMRPOLYPOLYGON;
+alias EMRPOLYPOLYLINE EMRPOLYPOLYGON;
alias EMRPOLYPOLYGON* PEMRPOLYPOLYGON;
struct EMRPOLYPOLYLINE16 {
POINTS[1] apts;
}
alias EMRPOLYPOLYLINE16* PEMRPOLYPOLYLINE16;
-alias TypeDef!(EMRPOLYPOLYLINE16) EMRPOLYPOLYGON16;
+alias EMRPOLYPOLYLINE16 EMRPOLYPOLYGON16;
alias EMRPOLYPOLYGON16* PEMRPOLYPOLYGON16;
struct EMRPOLYTEXTOUTA {
EMRTEXT[1] aemrtext;
}
alias EMRPOLYTEXTOUTA* PEMRPOLYTEXTOUTA;
-alias TypeDef!(EMRPOLYTEXTOUTA) EMRPOLYTEXTOUTW;
+alias EMRPOLYTEXTOUTA EMRPOLYTEXTOUTW;
alias EMRPOLYTEXTOUTW* PEMRPOLYTEXTOUTW;
struct EMRRESIZEPALETTE {
LONG yDenom;
}
alias EMRSCALEVIEWPORTEXTEX* PEMRSCALEVIEWPORTEXTEX;
-alias TypeDef!(EMRSCALEVIEWPORTEXTEX) EMRSCALEWINDOWEXTEX;
+alias EMRSCALEVIEWPORTEXTEX EMRSCALEWINDOWEXTEX;
alias EMRSCALEWINDOWEXTEX* PEMRSCALEWINDOWEXTEX;
struct EMRSELECTOBJECT {
DWORD ihObject;
}
alias EMRSELECTOBJECT* PEMRSELECTOBJECT;
-alias TypeDef!(EMRSELECTOBJECT) EMRDELETEOBJECT;
+alias EMRSELECTOBJECT EMRDELETEOBJECT;
alias EMRDELETEOBJECT* PEMRDELETEOBJECT;
struct EMRSELECTPALETTE {
COLORREF crColor;
}
alias EMRSETTEXTCOLOR* PEMRSETTEXTCOLOR;
-alias TypeDef!(EMRSETTEXTCOLOR) EMRSETBKCOLOR;
+alias EMRSETTEXTCOLOR EMRSETBKCOLOR;
alias EMRSETBKCOLOR* PEMRSETBKCOLOR;
struct EMRSETCOLORADJUSTMENT {
SIZEL szlExtent;
}
alias EMRSETVIEWPORTEXTEX* PEMRSETVIEWPORTEXTEX;
-alias TypeDef!(EMRSETVIEWPORTEXTEX) EMRSETWINDOWEXTEX;
+alias EMRSETVIEWPORTEXTEX EMRSETWINDOWEXTEX;
alias EMRSETWINDOWEXTEX* PEMRSETWINDOWEXTEX;
struct EMRSETVIEWPORTORGEX {
POINTL ptlOrigin;
}
alias EMRSETVIEWPORTORGEX* PEMRSETVIEWPORTORGEX;
-alias TypeDef!(EMRSETVIEWPORTORGEX) EMRSETWINDOWORGEX;
+alias EMRSETVIEWPORTORGEX EMRSETWINDOWORGEX;
alias EMRSETWINDOWORGEX* PEMRSETWINDOWORGEX;
-alias TypeDef!(EMRSETVIEWPORTORGEX) EMRSETBRUSHORGEX;
+alias EMRSETVIEWPORTORGEX EMRSETBRUSHORGEX;
alias EMRSETBRUSHORGEX* PEMRSETBRUSHORGEX;
struct EMRSETWORLDTRANSFORM {
EMR emr;
}
alias EMRABORTPATH* PEMRABORTPATH;
-alias TypeDef!(EMRABORTPATH) EMRBEGINPATH;
+alias EMRABORTPATH EMRBEGINPATH;
alias EMRBEGINPATH* PEMRBEGINPATH;
-alias TypeDef!(EMRABORTPATH) EMRENDPATH;
+alias EMRABORTPATH EMRENDPATH;
alias EMRENDPATH* PEMRENDPATH;
-alias TypeDef!(EMRABORTPATH) EMRCLOSEFIGURE;
+alias EMRABORTPATH EMRCLOSEFIGURE;
alias EMRCLOSEFIGURE* PEMRCLOSEFIGURE;
-alias TypeDef!(EMRABORTPATH) EMRFLATTENPATH;
+alias EMRABORTPATH EMRFLATTENPATH;
alias EMRFLATTENPATH* PEMRFLATTENPATH;
-alias TypeDef!(EMRABORTPATH) EMRWIDENPATH;
+alias EMRABORTPATH EMRWIDENPATH;
alias EMRWIDENPATH* PEMRWIDENPATH;
-alias TypeDef!(EMRABORTPATH) EMRSETMETARGN;
+alias EMRABORTPATH EMRSETMETARGN;
alias EMRSETMETARGN* PEMRSETMETARGN;
-alias TypeDef!(EMRABORTPATH) EMRSAVEDC;
+alias EMRABORTPATH EMRSAVEDC;
alias EMRSAVEDC* PEMRSAVEDC;
-alias TypeDef!(EMRABORTPATH) EMRREALIZEPALETTE;
+alias EMRABORTPATH EMRREALIZEPALETTE;
alias EMRREALIZEPALETTE* PEMRREALIZEPALETTE;
struct EMRSELECTCLIPPATH {
DWORD iMode;
}
alias EMRSELECTCLIPPATH* PEMRSELECTCLIPPATH;
-alias TypeDef!(EMRSELECTCLIPPATH) EMRSETBKMODE;
+alias EMRSELECTCLIPPATH EMRSETBKMODE;
alias EMRSETBKMODE* PEMRSETBKMODE;
-alias TypeDef!(EMRSELECTCLIPPATH) EMRSETMAPMODE;
+alias EMRSELECTCLIPPATH EMRSETMAPMODE;
alias EMRSETMAPMODE* PEMRSETMAPMODE;
-alias TypeDef!(EMRSELECTCLIPPATH) EMRSETPOLYFILLMODE;
+alias EMRSELECTCLIPPATH EMRSETPOLYFILLMODE;
alias EMRSETPOLYFILLMODE* PEMRSETPOLYFILLMODE;
-alias TypeDef!(EMRSELECTCLIPPATH) EMRSETROP2;
+alias EMRSELECTCLIPPATH EMRSETROP2;
alias EMRSETROP2* PEMRSETROP2;
-alias TypeDef!(EMRSELECTCLIPPATH) EMRSETSTRETCHBLTMODE;
+alias EMRSELECTCLIPPATH EMRSETSTRETCHBLTMODE;
alias EMRSETSTRETCHBLTMODE* PEMRSETSTRETCHBLTMODE;
-alias TypeDef!(EMRSELECTCLIPPATH) EMRSETICMMODE;
+alias EMRSELECTCLIPPATH EMRSETICMMODE;
alias EMRSETICMMODE* PEMRSETICMMODE;
-alias TypeDef!(EMRSELECTCLIPPATH) EMRSETTEXTALIGN;
+alias EMRSELECTCLIPPATH EMRSETTEXTALIGN;
alias EMRSETTEXTALIGN* PEMRSETTEXTALIGN;
-alias TypeDef!(EMRSELECTCLIPPATH) EMRENABLEICM;
+alias EMRSELECTCLIPPATH EMRENABLEICM;
alias EMRENABLEICM* PEMRENABLEICM;
static if (_WIN32_WINNT >= 0x500) {
- alias TypeDef!(EMRSELECTCLIPPATH) EMRSETLAYOUT;
+ alias EMRSELECTCLIPPATH EMRSETLAYOUT;
alias EMRSETLAYOUT* PEMRSETLAYOUT;
}
}
alias BSMINFO* PBSMINFO;
- alias TypeDef!(HANDLE) HRAWINPUT;
+ alias HANDLE HRAWINPUT;
struct RAWINPUTHEADER {
DWORD dwType;
// These shouldn't be necessary for D.
-alias TypeDef!(char*) va_list_;
+alias char* va_list_;
int wvsprintfA(LPSTR, LPCSTR, va_list_ arglist);
int wvsprintfW(LPWSTR, LPCWSTR, va_list_ arglist);
/** Return info used by the garbage collector to do precise collection.
*/
- @property immutable(void)* rtInfo() nothrow pure const @safe @nogc { return rtinfoHasPointers; } // better safe than sorry
+ @property immutable(void)* rtInfo() nothrow pure const @trusted @nogc { return rtinfoHasPointers; } // better safe than sorry
}
@system unittest
assert("k1" !in aa);
}
+// Issue 20559
+@system unittest
+{
+ static class Foo
+ {
+ int[string] aa;
+ alias aa this;
+ }
+
+ auto v = new Foo();
+ v["Hello World"] = 42;
+ v.clear;
+ assert("Hello World" !in v);
+
+ // Test for T*
+ static assert(!__traits(compiles, (&v).clear));
+ static assert( __traits(compiles, (*(&v)).clear));
+}
+
/***********************************
* Reorganizes the associative array in place so that lookups are more
* efficient.
destroy!true(new C());
}
+@system unittest
+{
+ // class with an `alias this`
+ class A
+ {
+ static int dtorCount;
+ ~this()
+ {
+ dtorCount++;
+ }
+ }
+
+ class B
+ {
+ A a;
+ alias a this;
+ this()
+ {
+ a = new A;
+ }
+ static int dtorCount;
+ ~this()
+ {
+ dtorCount++;
+ }
+ }
+ auto b = new B;
+ assert(A.dtorCount == 0);
+ assert(B.dtorCount == 0);
+ destroy(b);
+ assert(A.dtorCount == 0);
+ assert(B.dtorCount == 1);
+
+ auto a = new A;
+ destroy(a);
+ assert(A.dtorCount == 1);
+}
+
@system unittest
{
interface I { }
}
}
+// https://issues.dlang.org/show_bug.cgi?id=19218
+@system unittest
+{
+ static struct S
+ {
+ static dtorCount = 0;
+ ~this() { ++dtorCount; }
+ }
+
+ static interface I
+ {
+ ref S[3] getArray();
+ alias getArray this;
+ }
+
+ static class C : I
+ {
+ static dtorCount = 0;
+ ~this() { ++dtorCount; }
+
+ S[3] a;
+ alias a this;
+
+ ref S[3] getArray() { return a; }
+ }
+
+ C c = new C();
+ destroy(c);
+ assert(S.dtorCount == 3);
+ assert(C.dtorCount == 1);
+
+ I i = new C();
+ destroy(i);
+ assert(S.dtorCount == 6);
+ assert(C.dtorCount == 2);
+}
+
/// ditto
void destroy(bool initialize = true, T)(ref T obj)
if (!is(T == struct) && !is(T == interface) && !is(T == class) && !__traits(isStaticArray, T))
-330d6a4fdbe82683e081959d0aeb53597b025bc4
+d7e79f024606f18e989ae8b5fe298f9d07c7dced
The first line of this file holds the git revision number of the last
merge done from the dlang/phobos repository.
}
/++
-Constructs a static array from `a`.
-The type of elements can be specified implicitly so that $(D [1, 2].staticArray) results in `int[2]`,
-or explicitly, e.g. $(D [1, 2].staticArray!float) returns `float[2]`.
-When `a` is a range whose length is not known at compile time, the number of elements must be
-given as template argument (e.g. `myrange.staticArray!2`).
-Size and type can be combined, if the source range elements are implicitly
-convertible to the requested element type (eg: `2.iota.staticArray!(long[2])`).
-When the range `a` is known at compile time, it can also be specified as a
-template argument to avoid having to specify the number of elements
-(e.g.: `staticArray!(2.iota)` or `staticArray!(double, 2.iota)`).
+Constructs a static array from a dynamic array whose length is known at compile-time.
+The element type can be inferred or specified explicitly:
+
+* $(D [1, 2].staticArray) returns `int[2]`
+* $(D [1, 2].staticArray!float) returns `float[2]`
Note: `staticArray` returns by value, so expressions involving large arrays may be inefficient.
Params:
- a = The input elements. If there are less elements than the specified length of the static array,
- the rest of it is default-initialized. If there are more than specified, the first elements
- up to the specified length are used.
- rangeLength = outputs the number of elements used from `a` to it. Optional.
+ a = The input array.
Returns: A static array constructed from `a`.
+/
[cast(byte) 1, cast(byte) 129].staticArray.checkStaticArray!byte([1, -127]);
}
-/// ditto
+/**
+Constructs a static array from a range.
+When `a.length` is not known at compile time, the number of elements must be
+given as a template argument (e.g. `myrange.staticArray!2`).
+Size and type can be combined, if the source range elements are implicitly
+convertible to the requested element type (eg: `2.iota.staticArray!(long[2])`).
+
+When the range `a` is known at compile time, it can be given as a
+template argument to avoid having to specify the number of elements
+(e.g.: `staticArray!(2.iota)` or `staticArray!(double, 2.iota)`).
+
+Params:
+ a = The input range. If there are less elements than the specified length of the static array,
+ the rest of it is default-initialized. If there are more than specified, the first elements
+ up to the specified length are used.
+ rangeLength = Output for the number of elements used from `a`. Optional.
+*/
auto staticArray(size_t n, T)(scope T a)
if (isInputRange!T)
{
`atoi()` and `atol()` by checking for overflow and not allowing whitespace.
For conversion of strings _to signed types, the grammar recognized is:
-$(PRE $(I Integer): $(I Sign UnsignedInteger)
-$(I UnsignedInteger)
+$(PRE $(I Integer):
+ $(I Sign UnsignedInteger)
+ $(I UnsignedInteger)
$(I Sign):
$(B +)
$(B -))
}
/**
- * When converting strings _to numeric types, note that the D hexadecimal and binary
+ * When converting strings _to numeric types, note that D hexadecimal and binary
* literals are not handled. Neither the prefixes that indicate the base, nor the
* horizontal bar used _to separate groups of digits are recognized. This also
* applies to the suffixes that indicate the type.
* $(LI Pointer to string conversions convert the pointer to a `size_t` value.
* If pointer is `char*`, treat it as C-style strings.
* In that case, this function is `@system`.))
- * See $(REF formatValue, std,format) on how toString should be defined.
+ * See $(REF formatValue, std,format) on how `toString` should be defined.
*/
@system pure unittest // @system due to cast and ptr
{
assert(c == "abcx");
}
+/**
+ * Strings can be converted to enum types. The enum member with the same name as the
+ * input string is returned. The comparison is case-sensitive.
+ *
+ * A $(LREF ConvException) is thrown if the enum does not have the specified member.
+ */
+@safe pure unittest
+{
+ import std.exception : assertThrown;
+
+ enum E { a, b, c }
+ assert(to!E("a") == E.a);
+ assert(to!E("b") == E.b);
+ assertThrown!ConvException(to!E("A"));
+}
+
// Tests for https://issues.dlang.org/show_bug.cgi?id=6175
@safe pure nothrow unittest
{
}
/**
-The `parse` family of functions works quite like the `to`
+$(PANEL
+The `parse` family of functions works quite like the $(LREF to)
family, except that:
$(OL
$(LI It only works with character ranges as input.)
- $(LI It takes the input by reference. (This means that rvalues - such
- as string literals - are not accepted: use `to` instead.))
+ $(LI It takes the input by reference. This means that rvalues (such
+ as string literals) are not accepted: use `to` instead.)
$(LI It advances the input to the position following the conversion.)
$(LI It does not throw if it could not convert the entire input.))
+)
-This overload converts a character input range to a `bool`.
+This overload parses a `bool` from a character input range.
Params:
- Target = the type to convert to
+ Target = the boolean type to convert to
source = the lvalue of an $(REF_ALTTEXT input range, isInputRange, std,range,primitives)
doCount = the flag for deciding to report the number of consumed characters
to `parse` and do not require lvalues.
*/
auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source source)
-if (isInputRange!Source &&
- isSomeChar!(ElementType!Source) &&
- is(immutable Target == immutable bool))
+if (is(immutable Target == immutable bool) &&
+ isInputRange!Source &&
+ isSomeChar!(ElementType!Source))
{
import std.ascii : toLower;
}
/**
-Parses a character $(REF_ALTTEXT input range, isInputRange, std,range,primitives)
-to an integral value.
+Parses an integer from a character $(REF_ALTTEXT input range, isInputRange, std,range,primitives).
Params:
Target = the integral type to convert to
if no character of the input was meaningfully converted.
*/
auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref scope Source s)
-if (isSomeChar!(ElementType!Source) &&
- isIntegral!Target && !is(Target == enum))
+if (isIntegral!Target && !is(Target == enum) &&
+ isSomeChar!(ElementType!Source))
{
static if (Target.sizeof < int.sizeof)
{
/// ditto
auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source source, uint radix)
-if (isSomeChar!(ElementType!Source) &&
- isIntegral!Target && !is(Target == enum))
+if (isIntegral!Target && !is(Target == enum) &&
+ isSomeChar!(ElementType!Source))
in
{
assert(radix >= 2 && radix <= 36, "radix must be in range [2,36]");
}
/**
- * Takes a string representing an `enum` type and returns that type.
+ * Parses an `enum` type from a string representing an enum member name.
*
* Params:
* Target = the `enum` type to convert to
* represented by `s`.
*/
auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s)
-if (isSomeString!Source && !is(Source == enum) &&
- is(Target == enum))
+if (is(Target == enum) && isSomeString!Source && !is(Source == enum))
{
import std.algorithm.searching : startsWith;
import std.traits : Unqual, EnumMembers;
}
/**
- * Parses a character range to a floating point number.
+ * Parses a floating point number from a character range.
*
* Params:
* Target = a floating point type
* parsed, or if an overflow occurred.
*/
auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source source)
-if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum) &&
- isFloatingPoint!Target && !is(Target == enum))
+if (isFloatingPoint!Target && !is(Target == enum) &&
+ isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum))
{
import std.ascii : isDigit, isAlpha, toLower, toUpper, isHexDigit;
import std.exception : enforce;
}
/**
-Parsing one character off a range returns the first element and calls `popFront`.
+Parses one character from a character range.
Params:
Target = the type to convert to
A $(LREF ConvException) if the range is empty.
*/
auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s)
-if (isSomeString!Source && !is(Source == enum) &&
- staticIndexOf!(immutable Target, immutable dchar, immutable ElementEncodingType!Source) >= 0)
+if (staticIndexOf!(immutable Target, immutable dchar, immutable ElementEncodingType!Source) >= 0 &&
+ isSomeString!Source && !is(Source == enum))
{
if (s.empty)
throw convError!(Source, Target)(s);
/// ditto
auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s)
-if (!isSomeString!Source && isInputRange!Source && isSomeChar!(ElementType!Source) &&
- isSomeChar!Target && Target.sizeof >= ElementType!Source.sizeof && !is(Target == enum))
+if (isSomeChar!Target && Target.sizeof >= ElementType!Source.sizeof && !is(Target == enum) &&
+ !isSomeString!Source && isInputRange!Source && isSomeChar!(ElementType!Source))
{
if (s.empty)
throw convError!(Source, Target)(s);
}
/**
-Parsing a character range to `typeof(null)` returns `null` if the range
+Parses `typeof(null)` from a character range if the range
spells `"null"`. This function is case insensitive.
Params:
A $(LREF ConvException) if the range doesn't represent `null`.
*/
auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s)
-if (isInputRange!Source &&
- isSomeChar!(ElementType!Source) &&
- is(immutable Target == immutable typeof(null)))
+if (is(immutable Target == immutable typeof(null)) &&
+ isInputRange!Source &&
+ isSomeChar!(ElementType!Source))
{
import std.ascii : toLower;
foreach (c; "null")
*/
auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s, dchar lbracket = '[',
dchar rbracket = ']', dchar comma = ',')
-if (isSomeString!Source && !is(Source == enum) &&
- isDynamicArray!Target && !is(Target == enum))
+if (isDynamicArray!Target && !is(Target == enum) &&
+ isSomeString!Source && !is(Source == enum))
{
import std.array : appender;
/// ditto
auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s, dchar lbracket = '[',
dchar rbracket = ']', dchar comma = ',')
-if (isExactSomeString!Source &&
- isStaticArray!Target && !is(Target == enum))
+if (isStaticArray!Target && !is(Target == enum) &&
+ isExactSomeString!Source)
{
static if (hasIndirections!Target)
Target result = Target.init[0].init;
*/
auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source s, dchar lbracket = '[',
dchar rbracket = ']', dchar keyval = ':', dchar comma = ',')
-if (isSomeString!Source && !is(Source == enum) &&
- isAssociativeArray!Target && !is(Target == enum))
+if (isAssociativeArray!Target && !is(Target == enum) &&
+ isSomeString!Source && !is(Source == enum))
{
alias KeyType = typeof(Target.init.keys[0]);
alias ValType = typeof(Target.init.values[0]);
*/
void put(scope const(ubyte)[] data...) @trusted pure nothrow @nogc
{
- uint i, index, partLen;
+ size_t i;
+ uint index, partLen;
auto inputLen = data.length;
//Compute number of bytes mod 64
void put(scope const(ubyte)[] input...) @trusted pure nothrow @nogc
{
enum blockSizeInBytes = blockSize/8;
- uint i, index, partLen;
+
+ size_t i;
+ uint index, partLen;
auto inputLen = input.length;
/* Compute number of bytes mod block size (64 or 128 bytes) */
Returns: `value`, if `cast(bool) value` is true. Otherwise,
depending on the chosen overload, `new Exception(msg)`, `dg()` or `ex` is thrown.
- Note:
- `enforce` is used to throw exceptions and is therefore intended to
+ $(PANEL
+ $(NOTE `enforce` is used to throw exceptions and is therefore intended to
aid in error handling. It is $(I not) intended for verifying the logic
- of your program. That is what `assert` is for. Also, do not use
+ of your program - that is what `assert` is for.)
+
+ Do not use
`enforce` inside of contracts (i.e. inside of `in` and `out`
blocks and `invariant`s), because contracts are compiled out when
compiling with $(I -release).
+ )
If a delegate is passed, the safety and purity of this function are inferred
from `Dg`'s safety and purity.
)
The use in the example above is correct because `result`
-was private to `letters` and is inaccessible in writing
+was private to `letters` and the memory it referenced can no longer be written to
after the function returns. The following example shows an
incorrect use of `assumeUnique`.
----
)
-The example above wreaks havoc on client code because it is
-modifying arrays that callers considered immutable. To obtain an
+The example above wreaks havoc on client code because it modifies the
+returned array that the previous caller considered immutable. To obtain an
immutable array from the writable array `buffer`, replace
the last line with:
return to!(string)(sneaky); // not that sneaky anymore
----
-The call will duplicate the array appropriately.
+The `to` call will duplicate the array appropriately.
-Note that checking for uniqueness during compilation is
+$(PANEL
+$(NOTE Checking for uniqueness during compilation is
possible in certain cases, especially when a function is
-marked as a pure function. The following example does not
+marked (or inferred) as `pure`. The following example does not
need to call `assumeUnique` because the compiler can infer the
-uniqueness of the array in the pure function:
+uniqueness of the array in the pure function:)
$(RUNNABLE_EXAMPLE
----
$(B lent) keywords in the
$(HTTP www.cs.cmu.edu/~aldrich/papers/aldrich-dissertation.pdf, ArchJava)
language.
+)
The downside of using `assumeUnique`'s
convention-based usage is that at this time there is no
enum right = ")";
put(w, left);
- foreach (i, e; val.tupleof)
- {
+ static foreach (i; 0 .. T.tupleof.length)
+ {{
static if (__traits(identifier, val.tupleof[i]) == "this")
- continue;
- else static if (0 < i && val.tupleof[i-1].offsetof == val.tupleof[i].offsetof)
{
- static if (i == val.tupleof.length - 1 || val.tupleof[i].offsetof != val.tupleof[i+1].offsetof)
+ // ignore hidden context pointer
+ }
+ else static if (0 < i && T.tupleof[i-1].offsetof == T.tupleof[i].offsetof)
+ {
+ static if (i == T.tupleof.length - 1 || T.tupleof[i].offsetof != T.tupleof[i+1].offsetof)
{
- enum el = separator ~ val.tupleof[i].stringof[4 .. $] ~ "}";
+ enum el = separator ~ __traits(identifier, T.tupleof[i]) ~ "}";
put(w, el);
}
else
{
- enum el = separator ~ val.tupleof[i].stringof[4 .. $];
+ enum el = separator ~ __traits(identifier, T.tupleof[i]);
put(w, el);
}
}
- else static if (i+1 < val.tupleof.length && val.tupleof[i].offsetof == val.tupleof[i+1].offsetof)
+ else static if (i+1 < T.tupleof.length && T.tupleof[i].offsetof == T.tupleof[i+1].offsetof)
{
- enum el = (i > 0 ? separator : "") ~ "#{overlap " ~ val.tupleof[i].stringof[4 .. $];
+ enum el = (i > 0 ? separator : "") ~ "#{overlap " ~ __traits(identifier, T.tupleof[i]);
put(w, el);
}
else
{
static if (i > 0)
put(w, separator);
- formatElement(w, e, f);
+ formatElement(w, val.tupleof[i], f);
}
- }
+ }}
put(w, right);
}
else
{
int n;
string s;
- string toString() const { return s; }
+ string toString() @trusted const { return s; }
}
U2 u2;
() @trusted { u2.s = "hello"; } ();
public struct Int128
{
- @safe pure nothrow @nogc:
-
+ @safe pure nothrow @nogc
+ {
Cent data; /// core.int128.Cent
/****************
{
return tst(this.data);
}
+ } // @safe pure nothrow @nogc
/** Support binary arithmetic operators + - * / % & | ^ << >> >>>
* Params:
}
/// ditto
- Int128 opBinary(string op)(long op2) const
- if (op == "+" || op == "-" ||
+ Int128 opBinary(string op, Int)(const Int op2) const
+ if ((op == "+" || op == "-" ||
op == "*" || op == "/" || op == "%" ||
- op == "&" || op == "|" || op == "^")
+ op == "&" || op == "|" || op == "^") &&
+ is(Int : long) && __traits(isIntegral, Int))
{
- return mixin("this " ~ op ~ " Int128(0, op2)");
+ static if (__traits(isUnsigned, Int))
+ return mixin("this " ~ op ~ " Int128(0, op2)");
+ else
+ return mixin("this " ~ op ~ " Int128((cast(long) op2) >> 63 , op2)");
}
/// ditto
- Int128 opBinaryRight(string op)(long op2) const
- if (op == "+" || op == "-" ||
+ Int128 opBinary(string op, IntLike)(auto ref IntLike op2) const
+ if ((op == "+" || op == "-" ||
op == "*" || op == "/" || op == "%" ||
- op == "&" || op == "|" || op == "^")
+ op == "&" || op == "|" || op == "^") &&
+ is(IntLike : long) && !__traits(isIntegral, IntLike))
+ {
+ return opBinary!(op)(__traits(getMember, op2, __traits(getAliasThis, IntLike)[0]));
+ }
+
+ /// ditto
+ Int128 opBinaryRight(string op, Int)(const Int op2) const
+ if ((op == "+" || op == "-" ||
+ op == "*" || op == "/" || op == "%" ||
+ op == "&" || op == "|" || op == "^") &&
+ is(Int : long) && __traits(isIntegral, Int))
+ {
+ static if (__traits(isUnsigned, Int))
+ mixin("return Int128(0, op2) " ~ op ~ " this;");
+ else
+ mixin("return Int128((cast(long) op2) >> 63, op2) " ~ op ~ " this;");
+ }
+
+ /// ditto
+ Int128 opBinaryRight(string op, IntLike)(auto ref IntLike op2) const
+ if ((op == "+" || op == "-" ||
+ op == "*" || op == "/" || op == "%" ||
+ op == "&" || op == "|" || op == "^") &&
+ is(IntLike : long) && !__traits(isIntegral, IntLike))
{
- mixin("return Int128(0, op2) " ~ op ~ " this;");
+ return opBinaryRight!(op)(__traits(getMember, op2, __traits(getAliasThis, IntLike)[0]));
}
/// ditto
}
/// ditto
- ref Int128 opOpAssign(string op)(long op2)
- if (op == "+" || op == "-" ||
+ ref Int128 opOpAssign(string op, Int)(auto ref Int op2)
+ if ((op == "+" || op == "-" ||
op == "*" || op == "/" || op == "%" ||
op == "&" || op == "|" || op == "^" ||
op == "<<" || op == ">>" || op == ">>>")
+ && is(Int : long))
{
mixin("this = this " ~ op ~ " op2;");
return this;
}
- /** support signed arithmentic comparison operators < <= > >=
+ /** support arithmentic comparison operators < <= > >=
* Params: op2 = right hand operand
* Returns: -1 for less than, 0 for equals, 1 for greater than
*/
- int opCmp(Int128 op2) const
+ int opCmp(Int128 op2) const @nogc nothrow pure @safe
{
return this == op2 ? 0 : gt(this.data, op2.data) * 2 - 1;
}
- /** support signed arithmentic comparison operators < <= > >=
- * Params: op2 = right hand operand
- * Returns: -1 for less than, 0 for equals, 1 for greater than
+ /// ditto
+ int opCmp(Int)(const Int op2) const @nogc nothrow pure @safe
+ if (is(Int : long) && __traits(isIntegral, Int))
+ {
+ static if (__traits(isUnsigned, Int))
+ return opCmp(Int128(0, op2));
+ else
+ return opCmp(Int128((cast(long) op2) >> 63, op2));
+ }
+
+ /// ditto
+ int opCmp(IntLike)(auto ref IntLike op2) const
+ if (is(IntLike : long) && !__traits(isIntegral, IntLike))
+ {
+ return opCmp(__traits(getMember, op2, __traits(getAliasThis, IntLike)[0]));
+ }
+
+ /**
+ * Formats `Int128` with either `%d`, `%x`, `%X`, or `%s` (same as `%d`).
+ *
+ * Params:
+ * sink = $(REF_ALTTEXT Output range, isOutputRange, std, range, primitives)
+ * to write to.
+ * fmt = A $(REF FormatSpec, std,format) which controls how the number
+ * is displayed.
+ *
+ * Throws:
+ * $(REF FormatException, std,format) if the format specifier is
+ * not one of 'd', 'x', 'X', 's'.
+ *
+ * See_Also: $(REF formatValue, std,format)
*/
- int opCmp(long op2) const
+ void toString(Writer, FormatSpec)(scope ref Writer sink, scope const ref FormatSpec fmt) const
{
- return opCmp(Int128(0, op2));
+ import std.range.primitives : put;
+ import std.format : FormatException, Fmt = FormatSpec;
+
+ static if (is(FormatSpec == Fmt!Char, Char))
+ {
+ // Puts "Char" into scope if the pattern matches.
+ }
+ static assert(is(Char),
+ "Expecting `FormatSpec` to be instantiation of `std.format.FormatSpec`");
+
+ Char[39] buf = void;
+ size_t bufStart = void;
+ Char signChar = 0;
+ if (fmt.spec == 'd' || fmt.spec == 's')
+ {
+ const bool isNeg = 0 > cast(long) this.data.hi;
+ Cent val = isNeg ? neg(this.data) : this.data;
+ immutable Cent radix = { lo: 10, hi: 0 };
+ Cent modulus;
+ bufStart = buf.length;
+ do
+ {
+ uint x = void;
+ if (ugt(radix, val))
+ {
+ x = cast(uint) val.lo;
+ val = Cent(0, 0);
+ }
+ else
+ {
+ val = udivmod(val, radix, modulus);
+ x = cast(uint) modulus.lo;
+ }
+ buf[--bufStart] = cast(Char) ('0' + x);
+ } while (tst(val));
+ if (isNeg)
+ signChar = '-';
+ else if (fmt.flPlus)
+ signChar = '+';
+ else if (fmt.flSpace)
+ signChar = ' ';
+ }
+ else if (fmt.spec == 'x' || fmt.spec == 'X')
+ {
+ immutable hexDigits = fmt.spec == 'X' ? "0123456789ABCDEF" : "0123456789abcdef";
+ ulong a = data.lo;
+ bufStart = buf.length - 1;
+ size_t penPos = buf.length - 1;
+ do
+ {
+ if ((buf[penPos] = hexDigits[0xF & cast(uint) a]) != '0')
+ bufStart = penPos;
+ a >>>= 4;
+ } while (--penPos >= buf.length - 16);
+ a = data.hi;
+ do
+ {
+ if ((buf[penPos] = hexDigits[0xF & cast(uint) a]) != '0')
+ bufStart = penPos;
+ a >>>= 4;
+ } while (--penPos >= buf.length - 32);
+ }
+ else
+ {
+ throw new FormatException("Format specifier not understood: %" ~ fmt.spec);
+ }
+
+ const minw = (buf.length - bufStart) + int(signChar != 0);
+ const maxw = minw < fmt.width ? fmt.width : minw;
+ const difw = maxw - minw;
+
+ static void putRepeatedChars(Char c)(scope ref Writer sink, size_t n)
+ {
+ static immutable Char[8] array = [c, c, c, c, c, c, c, c];
+ foreach (_; 0 .. n / 8)
+ put(sink, array[0 .. 8]);
+ if (n & 7)
+ put(sink, array[0 .. n & 7]);
+ }
+
+ if (!fmt.flDash && !fmt.flZero && difw)
+ putRepeatedChars!' '(sink, difw);
+
+ if (signChar)
+ {
+ Char[1] signCharBuf = signChar;
+ put(sink, signCharBuf[0 .. 1]);
+ }
+
+ if (!fmt.flDash && fmt.flZero && difw)
+ putRepeatedChars!'0'(sink, difw);
+
+ put(sink, buf[bufStart .. $]);
+
+ if (fmt.flDash && difw)
+ putRepeatedChars!' '(sink, difw);
+ }
+
+ /**
+ `toString` is rarely directly invoked; the usual way of using it is via
+ $(REF format, std, format):
+ */
+ @safe unittest
+ {
+ import std.format : format;
+
+ assert(format("%s", Int128.max) == "170141183460469231731687303715884105727");
+ assert(format("%s", Int128.min) == "-170141183460469231731687303715884105728");
+ assert(format("%x", Int128.max) == "7fffffffffffffffffffffffffffffff");
+ assert(format("%X", Int128.max) == "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
+ assert(format("%032X", Int128(123L)) == "0000000000000000000000000000007B");
+ assert(format("%+ 40d", Int128(123L)) == " +123");
+ assert(format("%+-40d", Int128(123L)) == "+123 ");
+ }
+
+ /// Also can format as `wchar` or `dchar`.
+ @safe unittest
+ {
+ import std.conv : to;
+
+ assert(to!wstring(Int128.max) == "170141183460469231731687303715884105727"w);
+ assert(to!dstring(Int128.max) == "170141183460469231731687303715884105727"d);
}
enum min = Int128(long.min, 0); /// minimum value
c = Int128(-1L);
assert(c == -1L);
}
+
+@system unittest
+{
+ alias Seq(T...) = T;
+ Int128 c = Int128(-1L);
+ assert(c.opCmp(-1L) == 0);
+ // To avoid regression calling opCmp with any integral type needs to
+ // work without the compiler complaining "opCmp called with argument
+ // X matches both <...>".
+ static foreach (Int; Seq!(long, int, short, byte, ulong, uint, ushort, ubyte, dchar, wchar, char))
+ assert(c < Int.max);
+ static foreach (Int; Seq!(int, short, byte))
+ assert(c.opCmp(Int(-1)) == 0);
+ assert(c < true);
+ // To avoid regression calling opCmp with any type that converts to an
+ // integral type through alias this needs to work regardless of whether
+ // the alias is safe/pure/nothrow/nogc and regardless of whether the
+ // type has a disabled postblit.
+ static struct Wrapped(T)
+ {
+ T value;
+ uint count;
+ T get() @system { ++count; return value; } // not const
+ alias get this;
+ @disable this(this); // no implicit copies
+ }
+ assert(c.opCmp(Wrapped!long(-1)) == 0);
+ auto w = Wrapped!ulong(ulong.max);
+ w.count++; // avoid invalid D-Scanner message that w could have been declared const
+ assert(c < w);
+
+ const zero = Int128(0L);
+ const one = Int128(1L);
+ const neg_one = Int128(-1L);
+ const neg_two = Int128(-2L);
+ // Correct result with ulong.max:
+ assert(zero + ulong.max == ulong.max);
+ assert(one * ulong.max == ulong.max);
+ assert((neg_one & ulong.max) == ulong.max);
+ assert((zero | ulong.max) == ulong.max);
+ assert((zero ^ ulong.max) == ulong.max);
+ // Correct result with negative arguments:
+ assert(zero + -1L == -1L);
+ assert(neg_two * -3L == 6L);
+ assert(neg_two / -2L == 1L);
+ assert(neg_two % -2L == 0L);
+ assert((neg_one & -1L) == -1L);
+ assert((zero | -1L) == -1L);
+ assert((zero ^ -1L) == -1L);
+ // Ensure alias this still works.
+ {
+ Int128 a = zero;
+ assert((a ^= w) == ulong.max);
+ }
+ assert((Wrapped!long(-1L) + zero) == -1L);
+}
*/
enum JSONFloatLiteral : string
{
- nan = "NaN", /// string representation of floating-point NaN
- inf = "Infinite", /// string representation of floating-point Infinity
- negativeInf = "-Infinite", /// string representation of floating-point negative Infinity
+ nan = "NaN", /// String representation of floating-point NaN
+ inf = "Infinite", /// String representation of floating-point Infinity
+ negativeInf = "-Infinite", /// String representation of floating-point negative Infinity
}
/**
-Flags that control how json is encoded and parsed.
+Flags that control how JSON is encoded and parsed.
*/
enum JSONOptions
{
- none, /// standard parsing
- specialFloatLiterals = 0x1, /// encode NaN and Inf float values as strings
- escapeNonAsciiChars = 0x2, /// encode non ascii characters with an unicode escape sequence
- doNotEscapeSlashes = 0x4, /// do not escape slashes ('/')
+ none, /// Standard parsing and encoding
+ specialFloatLiterals = 0x1, /// Encode NaN and Inf float values as strings
+ escapeNonAsciiChars = 0x2, /// Encode non-ASCII characters with a Unicode escape sequence
+ doNotEscapeSlashes = 0x4, /// Do not escape slashes ('/')
strictParsing = 0x8, /// Strictly follow RFC-8259 grammar when parsing
}
/**
-JSON type enumeration
+Enumeration of JSON types
*/
enum JSONType : byte
{
* Value getter/setter for `JSONType.object`.
* Throws: `JSONException` for read access if `type` is not
* `JSONType.object`.
- * Note: this is @system because of the following pattern:
+ * Note: This is @system because of the following pattern:
---
auto a = &(json.object());
json.uinteger = 0; // overwrite AA pointer
/***
* Value getter for `JSONType.object`.
- * Unlike `object`, this retrieves the object by value and can be used in @safe code.
+ * Unlike `object`, this retrieves the object by value
+ * and can be used in @safe code.
*
- * A caveat is that, if the returned value is null, modifications will not be visible:
+ * One possible caveat is that, if the returned value is null,
+ * modifications will not be visible:
* ---
* JSONValue json;
* json.object = null;
* Value getter/setter for `JSONType.array`.
* Throws: `JSONException` for read access if `type` is not
* `JSONType.array`.
- * Note: this is @system because of the following pattern:
+ * Note: This is @system because of the following pattern:
---
auto a = &(json.array());
json.uinteger = 0; // overwrite array pointer
* Value getter for `JSONType.array`.
* Unlike `array`, this retrieves the array by value and can be used in @safe code.
*
- * A caveat is that, if you append to the returned array, the new values aren't visible in the
- * JSONValue:
+ * One possible caveat is that, if you append to the returned array,
+ * the new values aren't visible in the `JSONValue`:
* ---
* JSONValue json;
* json.array = [JSONValue("hello")];
}
/***
- * Generic type value getter
* A convenience getter that returns this `JSONValue` as the specified D type.
- * Note: only numeric, `bool`, `string`, `JSONValue[string]` and `JSONValue[]` types are accepted
+ * Note: Only numeric types, `bool`, `string`, `JSONValue[string]`, and `JSONValue[]` types are accepted
* Throws: `JSONException` if `T` cannot hold the contents of this `JSONValue`
* `ConvException` in case of integer overflow when converting to `T`
*/
}
/***
- * Array syntax for json arrays.
+ * Array syntax for JSON arrays.
* Throws: `JSONException` if `type` is not `JSONType.array`.
*/
ref inout(JSONValue) opIndex(size_t i) inout pure @safe
}
/***
- * Hash syntax for json objects.
+ * Hash syntax for JSON objects.
* Throws: `JSONException` if `type` is not `JSONType.object`.
*/
ref inout(JSONValue) opIndex(return scope string k) inout pure @safe
}
/***
- * Operator sets `value` for element of JSON object by `key`.
+ * Provides support for index assignments, which sets the
+ * corresponding value of the JSON object's `key` field to `value`.
*
- * If JSON value is null, then operator initializes it with object and then
- * sets `value` for it.
+ * If the `JSONValue` is `JSONType.null_`, then this function
+ * initializes it with a JSON object and then performs
+ * the index assignment.
*
* Throws: `JSONException` if `type` is not `JSONType.object`
* or `JSONType.null_`.
}
/**
- * Support for the `in` operator.
+ * Provides support for the `in` operator.
*
- * Tests wether a key can be found in an object.
+ * Tests whether a key can be found in an object.
*
* Returns:
- * when found, the `inout(JSONValue)*` that matches to the key,
+ * When found, the `inout(JSONValue)*` that matches to the key,
* otherwise `null`.
*
* Throws: `JSONException` if the right hand side argument `JSONType`
/**
* Contains the elementary mathematical functions (powers, roots,
* and trigonometric functions), and low-level floating-point operations.
- * Mathematical special functions are available in `std.mathspecial`.
+ * Mathematical special functions are available in $(MREF std, mathspecial).
*
$(SCRIPT inhibitQuickIndex = 1;)
// force staticMap type conversion to Rebindable
static struct ResultRanges
{
- staticMap!(Rebindable, Ranges) fields;
+ staticMap!(Rebindable, typeof(source)) fields;
}
auto sourceI(size_t i)() => rebindable(this.source[i]);
auto resultRanges = ResultRanges(staticMap!(sourceI, aliasSeqOf!(R.length.iota))).fields;
assert(range.array == [S(5), S(6)]);
}
+/// https://issues.dlang.org/show_bug.cgi?id=24064
+pure @safe nothrow unittest
+{
+ import std.algorithm.comparison : equal;
+ import std.typecons : Nullable;
+
+ immutable Nullable!string foo = "b";
+ string[] bar = ["a"];
+ assert(chain(bar, foo).equal(["a", "b"]));
+}
+
pure @safe nothrow @nogc unittest
{
// support non-copyable items
return isBig ? big.ptr[0 .. length] : small[0 .. length];
}
- this(this)
+ this(this) @trusted
{
if (isBig)
{
return "Socket error " ~ to!string(err);
}
-/// Retrieve the error message for the most recently encountered network error.
+/// Returns the error message of the most recently encountered network error.
@property string lastSocketError()
{
return formatSocketError(_lasterr());
}
-/**
- * Socket exceptions representing network errors reported by the operating
- * system.
- */
+/// Socket exception representing network errors reported by the operating system.
class SocketOSException: SocketException
{
int errorCode; /// Platform-specific error code.
}
}
-/// Socket exceptions representing invalid parameters specified by user code.
+/// Socket exception representing invalid parameters specified by user code.
class SocketParameterException: SocketException
{
mixin basicExceptionCtors;
}
/**
- * Socket exceptions representing attempts to use network capabilities not
+ * Socket exception representing attempts to use network capabilities not
* available on the current system.
*/
class SocketFeatureException: SocketException
* Returns:
* `true` if the last socket operation failed because the socket
* was in non-blocking mode and the operation would have blocked,
- * or if the socket is in blocking mode and set a SNDTIMEO or RCVTIMEO,
+ * or if the socket is in blocking mode and set a `SNDTIMEO` or `RCVTIMEO`,
* and the operation timed out.
*/
bool wouldHaveBlocked() nothrow @nogc
enum AddressFamily: ushort
{
UNSPEC = AF_UNSPEC, /// Unspecified address family
- UNIX = AF_UNIX, /// Local communication
+ UNIX = AF_UNIX, /// Local communication (Unix socket)
INET = AF_INET, /// Internet Protocol version 4
IPX = AF_IPX, /// Novell IPX
APPLETALK = AF_APPLETALK, /// AppleTalk
/**
- * `Protocol` is a class for retrieving protocol information.
+ * Class for retrieving protocol information.
*
* Example:
* ---
/**
- * `Service` is a class for retrieving service information.
+ * Class for retrieving service information.
*
* Example:
* ---
}
/**
- * `InternetHost` is a class for resolving IPv4 addresses.
+ * Class for resolving IPv4 addresses.
*
* Consider using `getAddress`, `parseAddress` and `Address` methods
* instead of using this class directly.
/**
- * `Address` is an abstract class for representing a socket addresses.
+ * Abstract class for representing a socket address.
*
* Example:
* ---
}
/**
- * `UnknownAddress` encapsulates an unknown socket address.
+ * Encapsulates an unknown socket address.
*/
class UnknownAddress: Address
{
/**
- * `UnknownAddressReference` encapsulates a reference to an arbitrary
+ * Encapsulates a reference to an arbitrary
* socket address.
*/
class UnknownAddressReference: Address
/**
- * `InternetAddress` encapsulates an IPv4 (Internet Protocol version 4)
- * socket address.
+ * Encapsulates an IPv4 (Internet Protocol version 4) socket address.
*
* Consider using `getAddress`, `parseAddress` and `Address` methods
* instead of using this class directly.
}
/**
- * Compares with another InternetAddress of same type for equality
+ * Provides support for comparing equality with another
+ * InternetAddress of the same type.
* Returns: true if the InternetAddresses share the same address and
* port number.
*/
/**
- * `Internet6Address` encapsulates an IPv6 (Internet Protocol version 6)
- * socket address.
+ * Encapsulates an IPv6 (Internet Protocol version 6) socket address.
*
* Consider using `getAddress`, `parseAddress` and `Address` methods
* instead of using this class directly.
}
/**
- * `UnixAddress` encapsulates an address for a Unix domain socket
- * (`AF_UNIX`), i.e. a socket bound to a path name in the file system.
+ * Encapsulates an address for a Unix domain socket (`AF_UNIX`),
+ * i.e. a socket bound to a path name in the file system.
* Available only on supported systems.
*
* Linux also supports an abstract address namespace, in which addresses
/**
- * Class for exceptions thrown by `Socket.accept`.
+ * Exception thrown by `Socket.accept`.
*/
class SocketAcceptException: SocketOSException
{
}
-/// Flags may be OR'ed together:
+/// Socket flags that may be OR'ed together:
enum SocketFlags: int
{
NONE = 0, /// no flags specified
/**
- * `Socket` is a class that creates a network communication endpoint using
+ * Class that creates a network communication endpoint using
* the Berkeley sockets interface.
*/
class Socket
/**
- * Returns: the local machine's host name
+ * Returns: The local machine's host name
*/
static @property string hostName() @trusted // getter
{
/**
* Can be overridden to support other addresses.
- * Returns: a new `Address` object for the current address family.
+ * Returns: A new `Address` object for the current address family.
*/
protected Address createAddress() pure nothrow
{
}
-/// `TcpSocket` is a shortcut class for a TCP Socket.
+/// Shortcut class for a TCP Socket.
class TcpSocket: Socket
{
/// Constructs a blocking TCP Socket.
//shortcut
- /// Constructs a blocking TCP Socket and connects to an `Address`.
+ /// Constructs a blocking TCP Socket and connects to the given `Address`.
this(Address connectTo)
{
this(connectTo.addressFamily);
}
-/// `UdpSocket` is a shortcut class for a UDP Socket.
+/// Shortcut class for a UDP Socket.
class UdpSocket: Socket
{
/// Constructs a blocking UDP Socket.
version (CRuntime_Microsoft)
{
- version = MICROSOFT_STDIO;
}
else version (CRuntime_DigitalMars)
{
- // Specific to the way Digital Mars C does stdio
- version = DIGITAL_MARS_STDIO;
}
else version (CRuntime_Glibc)
{
- // Specific to the way Gnu C does stdio
- version = GCC_IO;
}
else version (CRuntime_Bionic)
{
static import core.sys.posix.stdio; // getdelim, flockfile
}
-version (DIGITAL_MARS_STDIO)
+version (CRuntime_DigitalMars)
{
private alias _FPUTC = _fputc_nlock;
private alias _FPUTWC = _fputwc_nlock;
private alias _FLOCK = __fp_lock;
private alias _FUNLOCK = __fp_unlock;
- // Alias for MICROSOFT_STDIO compatibility.
+ // Alias for CRuntime_Microsoft compatibility.
// @@@DEPRECATED_2.107@@@
// Rename this back to _setmode once the deprecation phase has ended.
private alias __setmode = setmode;
~ "std.stdio and will be removed afer 2.107")
fileno_t _fileno(FILE* f) { return f._file; }
}
-else version (MICROSOFT_STDIO)
+else version (CRuntime_Microsoft)
{
private alias _FPUTC = _fputc_nolock;
private alias _FPUTWC = _fputwc_nolock;
private alias _FUNLOCK = _unlock_file;
// @@@DEPRECATED_2.107@@@
- // Remove this once the deprecation phase for DIGITAL_MARS_STDIO has ended.
+ // Remove this once the deprecation phase for CRuntime_DigitalMars has ended.
private alias __setmode = _setmode;
// @@@DEPRECATED_2.107@@@
~ "std.stdio and will be removed afer 2.107")
alias FUNLOCK = _unlock_file;
}
-else version (GCC_IO)
+else version (CRuntime_Glibc)
{
private alias _FPUTC = fputc_unlocked;
private alias _FPUTWC = fputwc_unlocked;
{
pragma(mangle, _FPUTC.mangleof) int trustedFPUTC(int ch, _iobuf* h) @trusted;
- version (DIGITAL_MARS_STDIO)
+ version (CRuntime_DigitalMars)
pragma(mangle, _FPUTWC.mangleof) int trustedFPUTWC(int ch, _iobuf* h) @trusted;
else
pragma(mangle, _FPUTWC.mangleof) int trustedFPUTWC(wchar_t ch, _iobuf* h) @trusted;
name);
// MSVCRT workaround (https://issues.dlang.org/show_bug.cgi?id=14422)
- version (MICROSOFT_STDIO)
+ version (CRuntime_Microsoft)
{
setAppendWin(stdioOpenmode);
}
}
_p = cast(Impl*) enforce(malloc(Impl.sizeof), "Out of memory");
initImpl(handle, name, 1, isPopened);
- version (MICROSOFT_STDIO)
+ version (CRuntime_Microsoft)
{
setAppendWin(stdioOpenmode);
}
}
}
- version (MICROSOFT_STDIO)
+ version (CRuntime_Microsoft)
{
private void setAppendWin(scope const(char)[] stdioOpenmode) @safe
{
auto modez = stdioOpenmode.tempCString();
detach();
- version (DIGITAL_MARS_STDIO)
+ version (CRuntime_DigitalMars)
{
// This is a re-implementation of DMC's fdopen, but without the
// mucking with the file descriptor. POSIX standard requires the
iob._flag &= ~_IOTRAN;
_FUNLOCK(fp);
}
- else
+ else version (CRuntime_Microsoft)
{
- version (Windows) // MSVCRT
- auto fp = _fdopen(fd, modez);
- else version (Posix)
- {
- import core.sys.posix.stdio : fdopen;
- auto fp = fdopen(fd, modez);
- }
+ auto fp = _fdopen(fd, modez);
errnoEnforce(fp);
}
+ else version (Posix)
+ {
+ import core.sys.posix.stdio : fdopen;
+ auto fp = fdopen(fd, modez);
+ errnoEnforce(fp);
+ }
+ else
+ static assert(0, "no fdopen() available");
+
this = File(fp, name);
}
import std.format : format;
// Create file descriptors from the handles
- version (DIGITAL_MARS_STDIO)
+ version (CRuntime_DigitalMars)
auto fd = _handleToFD(handle, FHND_DEVICE);
else // MSVCRT
{
immutable fileno_t fd = .fileno(_p.handle);
immutable mode = .__setmode(fd, _O_BINARY);
scope(exit) .__setmode(fd, mode);
- version (DIGITAL_MARS_STDIO)
+ version (CRuntime_DigitalMars)
{
import core.atomic : atomicOp;
.__setmode(fd, _O_BINARY);
}
- version (DIGITAL_MARS_STDIO)
+ version (CRuntime_DigitalMars)
{
import core.atomic : atomicOp;
version (Windows)
@property HANDLE windowsHandle()
{
- version (DIGITAL_MARS_STDIO)
+ version (CRuntime_DigitalMars)
return _fdToHandle(fileno);
else
return cast(HANDLE)_get_osfhandle(fileno);
file_ = f;
FILE* fps = f._p.handle;
- version (MICROSOFT_STDIO)
+ version (CRuntime_Microsoft)
{
// Microsoft doesn't implement fwide. Instead, there's the
// concept of ANSI/UNICODE mode. fputc doesn't work in UNICODE
{
fileno_t fd;
int oldMode;
- version (DIGITAL_MARS_STDIO)
+ version (CRuntime_DigitalMars)
ubyte oldInfo;
}
.fflush(fps); // before changing translation mode
fd = .fileno(fps);
oldMode = .__setmode(fd, _O_BINARY);
- version (DIGITAL_MARS_STDIO)
+ version (CRuntime_DigitalMars)
{
import core.atomic : atomicOp;
version (Windows)
{
.fflush(fps); // before restoring translation mode
- version (DIGITAL_MARS_STDIO)
+ version (CRuntime_DigitalMars)
{
// https://issues.dlang.org/show_bug.cgi?id=4243
__fhnd_info[fd] = oldInfo;
return setlocale(LC_CTYPE, loc.ptr).fromStringz.endsWith(loc);
});
scope(exit) () @trusted { setlocale(LC_CTYPE, oldCt); } ();
- version (DIGITAL_MARS_STDIO) // DM can't handle Unicode above U+07FF.
+ version (CRuntime_DigitalMars) // DM can't handle Unicode above U+07FF.
{
alias strs = AliasSeq!("xä\u07FE", "yö\u07FF"w);
}
}
{
auto f = File(deleteme, "w");
- version (MICROSOFT_STDIO)
+ version (CRuntime_Microsoft)
{
() @trusted { __setmode(fileno(f.getFP()), _O_U8TEXT); } ();
}
// Private implementation of readln
private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator, File.Orientation orientation) @safe
{
- version (DIGITAL_MARS_STDIO)
+ version (CRuntime_DigitalMars)
return () @trusted {
auto lf = LockedFile(fps);
ReadlnAppender app;
buf = app.data;
return buf.length;
}();
- else version (MICROSOFT_STDIO)
+ else version (CRuntime_Microsoft)
{
auto lf = LockedFile(fps);
}
/**
-Get tuple, one per function parameter, of the storage classes of the parameters.
+Get a tuple of the storage classes of a function's parameters.
Params:
func = function symbol or type of function, delegate, or pointer to function
Returns:
static if (is(Func PT == __parameters))
{
- template StorageClass(size_t i)
+ alias ParameterStorageClassTuple = AliasSeq!();
+ static foreach (i; 0 .. PT.length)
{
- static if (i < PT.length)
- {
- alias StorageClass = AliasSeq!(
- extractParameterStorageClassFlags!(__traits(getParameterStorageClasses, Func, i)),
- StorageClass!(i + 1));
- }
- else
- alias StorageClass = AliasSeq!();
+ ParameterStorageClassTuple = AliasSeq!(ParameterStorageClassTuple,
+ extractParameterStorageClassFlags!(__traits(getParameterStorageClasses, Func, i)));
}
- alias ParameterStorageClassTuple = StorageClass!0;
}
else
{
- static assert(0, func[0].stringof ~ " is not a function");
+ static assert(0, func.stringof, " is not a function");
alias ParameterStorageClassTuple = AliasSeq!();
}
}
{
static if (is(FunctionTypeOf!func PT == __parameters))
{
- template Get(size_t i)
+ alias ParameterIdentifierTuple = AliasSeq!();
+ static foreach (i; 0 .. PT.length)
{
static if (!isFunctionPointer!func && !isDelegate!func
// Unnamed parameters yield CT error.
// Filter out unnamed args, which look like (Type) instead of (Type name).
&& PT[i].stringof != PT[i .. i+1].stringof[1..$-1])
{
- enum Get = __traits(identifier, PT[i .. i+1]);
+ ParameterIdentifierTuple = AliasSeq!(ParameterIdentifierTuple,
+ __traits(identifier, PT[i .. i+1]));
}
else
{
- enum Get = "";
+ ParameterIdentifierTuple = AliasSeq!(ParameterIdentifierTuple, "");
}
}
}
else
{
static assert(0, func.stringof ~ " is not a function");
-
- // Define dummy entities to avoid pointless errors
- template Get(size_t i) { enum Get = ""; }
- alias PT = AliasSeq!();
- }
-
- template Impl(size_t i = 0)
- {
- static if (i == PT.length)
- alias Impl = AliasSeq!();
- else
- alias Impl = AliasSeq!(Get!i, Impl!(i+1));
+ // avoid pointless errors
+ alias ParameterIdentifierTuple = AliasSeq!();
}
-
- alias ParameterIdentifierTuple = Impl!();
}
///
/**
-Get, as a tuple, the default value of the parameters to a function symbol.
+Get, as a tuple, the default values of the parameters to a function symbol.
If a parameter doesn't have the default value, `void` is returned instead.
*/
template ParameterDefaults(alias func)
enum args = "args" ~ (name == "args" ? "_" : "");
enum val = "val" ~ (name == "val" ? "_" : "");
enum ptr = "ptr" ~ (name == "ptr" ? "_" : "");
- mixin("
- enum hasDefaultArg = (PT[i .. i+1] " ~ args ~ ") { return true; };
- ");
+ enum hasDefaultArg = mixin("(PT[i .. i+1] ", args, ") => true");
static if (is(typeof(hasDefaultArg())))
{
- mixin("
- // workaround scope escape check, see
- // https://issues.dlang.org/show_bug.cgi?id=16582
- // should use return scope once available
- enum get = (PT[i .. i+1] " ~ args ~ ") @trusted
+ enum get = mixin("(return scope PT[i .. i+1] ", args, ")
{
// If the parameter is lazy, we force it to be evaluated
// like this.
- auto " ~ val ~ " = " ~ args ~ "[0];
- auto " ~ ptr ~ " = &" ~ val ~ ";
- return *" ~ ptr ~ ";
- };");
+ auto ", val, " = ", args, "[0];
+ auto ", ptr, " = &", val, ";
+ return *", ptr, ";
+ }");
enum Get = get();
}
else
alias Get = void;
// If default arg doesn't exist, returns void instead.
}
+ alias ParameterDefaults = AliasSeq!();
+ static foreach (i; 0 .. PT.length)
+ {
+ ParameterDefaults = AliasSeq!(ParameterDefaults,
+ Get!i);
+ }
}
else
{
static assert(0, func.stringof ~ " is not a function");
-
- // Define dummy entities to avoid pointless errors
- template Get(size_t i) { enum Get = ""; }
- alias PT = AliasSeq!();
+ // avoid pointless errors
+ alias ParameterDefaults = AliasSeq!();
}
-
- template Impl(size_t i = 0)
- {
- static if (i == PT.length)
- alias Impl = AliasSeq!();
- else
- alias Impl = AliasSeq!(Get!i, Impl!(i+1));
- }
-
- alias ParameterDefaults = Impl!();
}
///
static assert(false, "No operation "~op~" defined for Grapheme");
}
+ // This is not a good `opEquals`, but formerly the automatically generated
+ // opEquals was used, which was inferred `@safe` because of bugzilla 20655:
+ // https://issues.dlang.org/show_bug.cgi?id=20655
+ // This `@trusted opEquals` is only here to prevent breakage.
+ bool opEquals(R)(const auto ref R other) const @trusted
+ {
+ return this.tupleof == other.tupleof;
+ }
+
/++
True if this object contains valid extended grapheme cluster.
Decoding primitives of this module always return a valid `Grapheme`.