mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 21:51:03 +03:00
Start implementation of editions
This commit is contained in:
parent
e00869b27e
commit
400dd0134d
8 changed files with 66 additions and 2 deletions
|
@ -18,6 +18,15 @@ enum Sizeok : ubyte
|
||||||
done, /// size of aggregate is set correctly
|
done, /// size of aggregate is set correctly
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// D Language version
|
||||||
|
enum Edition : ubyte
|
||||||
|
{
|
||||||
|
none,
|
||||||
|
legacy, /// Before the introduction of editions
|
||||||
|
v2024, /// Experimental first new edition
|
||||||
|
latest = v2024 /// Newest edition that this compiler knows of
|
||||||
|
}
|
||||||
|
|
||||||
enum Baseok : ubyte
|
enum Baseok : ubyte
|
||||||
{
|
{
|
||||||
none, /// base classes not computed yet
|
none, /// base classes not computed yet
|
||||||
|
|
|
@ -358,6 +358,7 @@ extern (C++) final class Module : Package
|
||||||
FileType filetype; // source file type
|
FileType filetype; // source file type
|
||||||
bool hasAlwaysInlines; // contains references to functions that must be inlined
|
bool hasAlwaysInlines; // contains references to functions that must be inlined
|
||||||
bool isPackageFile; // if it is a package.d
|
bool isPackageFile; // if it is a package.d
|
||||||
|
Edition edition; // language edition that this module is compiled with
|
||||||
Package pkg; // if isPackageFile is true, the Package that contains this package.d
|
Package pkg; // if isPackageFile is true, the Package that contains this package.d
|
||||||
Strings contentImportedFiles; // array of files whose content was imported
|
Strings contentImportedFiles; // array of files whose content was imported
|
||||||
int needmoduleinfo;
|
int needmoduleinfo;
|
||||||
|
@ -477,6 +478,8 @@ extern (C++) final class Module : Package
|
||||||
setDocfile();
|
setDocfile();
|
||||||
if (doHdrGen)
|
if (doHdrGen)
|
||||||
hdrfile = setOutfilename(global.params.dihdr.name, global.params.dihdr.dir, arg, hdr_ext);
|
hdrfile = setOutfilename(global.params.dihdr.name, global.params.dihdr.dir, arg, hdr_ext);
|
||||||
|
|
||||||
|
this.edition = Edition.legacy;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern (D) this(const(char)[] filename, Identifier ident, int doDocComment, int doHdrGen)
|
extern (D) this(const(char)[] filename, Identifier ident, int doDocComment, int doHdrGen)
|
||||||
|
|
|
@ -830,12 +830,18 @@ extern (C++) struct Scope
|
||||||
/// Returns: whether to raise DIP1000 warnings (FeatureStabe.default) or errors (FeatureState.enabled)
|
/// Returns: whether to raise DIP1000 warnings (FeatureStabe.default) or errors (FeatureState.enabled)
|
||||||
extern (D) FeatureState useDIP1000()
|
extern (D) FeatureState useDIP1000()
|
||||||
{
|
{
|
||||||
return (flags & SCOPE.dip1000) ? FeatureState.enabled : FeatureState.disabled;
|
return (flags & SCOPE.dip1000 || hasEdition(Edition.v2024)) ? FeatureState.enabled : FeatureState.disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns: whether to raise DIP25 warnings (FeatureStabe.default) or errors (FeatureState.enabled)
|
/// Returns: whether to raise DIP25 warnings (FeatureStabe.default) or errors (FeatureState.enabled)
|
||||||
extern (D) FeatureState useDIP25()
|
extern (D) FeatureState useDIP25()
|
||||||
{
|
{
|
||||||
return (flags & SCOPE.dip25) ? FeatureState.enabled : FeatureState.disabled;
|
return (flags & SCOPE.dip25 || hasEdition(Edition.v2024)) ? FeatureState.enabled : FeatureState.disabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns: whether this scope compiles with `edition` or later
|
||||||
|
extern (D) bool hasEdition(Edition edition)
|
||||||
|
{
|
||||||
|
return _module && _module.edition >= edition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -834,6 +834,14 @@ enum class FileType : uint8_t
|
||||||
c = 3u,
|
c = 3u,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class Edition : uint8_t
|
||||||
|
{
|
||||||
|
none = 0u,
|
||||||
|
legacy = 1u,
|
||||||
|
v2024 = 2u,
|
||||||
|
latest = 2u,
|
||||||
|
};
|
||||||
|
|
||||||
struct OutBuffer final
|
struct OutBuffer final
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -7073,6 +7081,7 @@ public:
|
||||||
FileType filetype;
|
FileType filetype;
|
||||||
bool hasAlwaysInlines;
|
bool hasAlwaysInlines;
|
||||||
bool isPackageFile;
|
bool isPackageFile;
|
||||||
|
Edition edition;
|
||||||
Package* pkg;
|
Package* pkg;
|
||||||
Array<const char* > contentImportedFiles;
|
Array<const char* > contentImportedFiles;
|
||||||
int32_t needmoduleinfo;
|
int32_t needmoduleinfo;
|
||||||
|
|
|
@ -531,6 +531,9 @@ immutable Msgtable[] msgtable =
|
||||||
{ "udaMustUse", "mustuse" },
|
{ "udaMustUse", "mustuse" },
|
||||||
{ "udaStandalone", "standalone" },
|
{ "udaStandalone", "standalone" },
|
||||||
|
|
||||||
|
// Editions
|
||||||
|
{ "__edition_latest_do_not_use", },
|
||||||
|
|
||||||
// C names, for undefined identifier error messages
|
// C names, for undefined identifier error messages
|
||||||
{ "NULL" },
|
{ "NULL" },
|
||||||
{ "TRUE" },
|
{ "TRUE" },
|
||||||
|
|
|
@ -28,6 +28,14 @@ enum PKG
|
||||||
PKGpackage // already determined that's an actual package
|
PKGpackage // already determined that's an actual package
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class Edition : unsigned char
|
||||||
|
{
|
||||||
|
none = 0u,
|
||||||
|
legacy = 1u,
|
||||||
|
v2024 = 2u,
|
||||||
|
latest = 2u,
|
||||||
|
};
|
||||||
|
|
||||||
class Package : public ScopeDsymbol
|
class Package : public ScopeDsymbol
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -75,6 +83,7 @@ public:
|
||||||
FileType filetype; // source file type
|
FileType filetype; // source file type
|
||||||
d_bool hasAlwaysInlines; // contains references to functions that must be inlined
|
d_bool hasAlwaysInlines; // contains references to functions that must be inlined
|
||||||
d_bool isPackageFile; // if it is a package.d
|
d_bool isPackageFile; // if it is a package.d
|
||||||
|
Edition edition; // language edition that this module is compiled with
|
||||||
Package *pkg; // if isPackageFile is true, the Package that contains this package.d
|
Package *pkg; // if isPackageFile is true, the Package that contains this package.d
|
||||||
Strings contentImportedFiles; // array of files whose content was imported
|
Strings contentImportedFiles; // array of files whose content was imported
|
||||||
int needmoduleinfo;
|
int needmoduleinfo;
|
||||||
|
|
|
@ -233,6 +233,15 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
static if (is(typeof(mod.edition)))
|
||||||
|
if (exps && exps.length > 0)
|
||||||
|
if (auto id = (*exps)[0].isIdentifierExp())
|
||||||
|
if (id.ident == Id.__edition_latest_do_not_use)
|
||||||
|
{
|
||||||
|
mod.edition = Edition.latest;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
udas = AST.UserAttributeDeclaration.concat(udas, exps);
|
udas = AST.UserAttributeDeclaration.concat(udas, exps);
|
||||||
}
|
}
|
||||||
if (stc)
|
if (stc)
|
||||||
|
|
16
compiler/test/fail_compilation/editions.d
Normal file
16
compiler/test/fail_compilation/editions.d
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/**
|
||||||
|
Test language editions (currently experimental)
|
||||||
|
|
||||||
|
TEST_OUTPUT:
|
||||||
|
---
|
||||||
|
fail_compilation/editions.d(15): Error: scope parameter `x` may not be returned
|
||||||
|
---
|
||||||
|
*/
|
||||||
|
@__edition_latest_do_not_use
|
||||||
|
module editions;
|
||||||
|
|
||||||
|
@safe:
|
||||||
|
int* f(scope int* x)
|
||||||
|
{
|
||||||
|
return x;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue