d: Merge upstream dmd cef1e7991.

Adds a DString type, a struct that has a compatible layout with D
strings.  Many parameters in the Global struct have been switched over
to this type, and users of these params have been adjust to use the
length or ptr field as appropriate.

gcc/d/ChangeLog:

	* dmd/MERGE: Merge upstream dmd cef1e7991.
	* d-lang.cc (d_parse_file): Adjust for new field types.
This commit is contained in:
Iain Buclaw 2020-06-07 11:26:32 +02:00
parent 557a40f599
commit d8930b1387
10 changed files with 70 additions and 52 deletions

View File

@ -1027,8 +1027,8 @@ d_parse_file (void)
{
if (global.params.verbose)
{
message ("binary %s", global.params.argv0);
message ("version %s", global.version);
message ("binary %s", global.params.argv0.ptr);
message ("version %s", global.version.ptr);
if (global.params.versionids)
{
@ -1300,11 +1300,12 @@ d_parse_file (void)
OutBuffer buf;
json_generate (&buf, &modules);
const char *name = global.params.jsonfilename;
const char *name = global.params.jsonfilename.ptr;
if (name && (name[0] != '-' || name[1] != '\0'))
{
const char *nameext = FileName::defaultExt (name, global.json_ext);
const char *nameext
= FileName::defaultExt (name, global.json_ext.ptr);
File *fjson = File::create (nameext);
fjson->setbuffer ((void *) buf.data, buf.offset);
fjson->ref = 1;

View File

@ -1,4 +1,4 @@
740f3d1eab81d88d11451083d955d5075f60d4e0
cef1e7991121a22f50e9966ea407805015922bc7
The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository.

View File

@ -994,7 +994,7 @@ void PragmaDeclaration::semantic(Scope *sc)
name[se->len] = 0;
if (global.params.verbose)
message("library %s", name);
if (global.params.moduleDeps && !global.params.moduleDepsFile)
if (global.params.moduleDeps && !global.params.moduleDepsFile.length)
{
OutBuffer *ob = global.params.moduleDeps;
Module *imod = sc->instantiatingModule();

View File

@ -407,7 +407,7 @@ DebugCondition::DebugCondition(Module *mod, unsigned level, Identifier *ident)
// Helper for printing dependency information
void printDepsConditional(Scope *sc, DVCondition* condition, const char* depType)
{
if (!global.params.moduleDeps || global.params.moduleDepsFile)
if (!global.params.moduleDeps || global.params.moduleDepsFile.length)
return;
OutBuffer *ob = global.params.moduleDeps;
Module* imod = sc ? sc->instantiatingModule() : condition->mod;

View File

@ -321,7 +321,7 @@ void Import::semantic(Scope *sc)
OutBuffer *ob = global.params.moduleDeps;
Module* imod = sc->instantiatingModule();
if (!global.params.moduleDepsFile)
if (!global.params.moduleDepsFile.length)
ob->writestring("depsImport ");
ob->writestring(imod->toPrettyChars());
ob->writestring(" (");

View File

@ -91,7 +91,7 @@ Module::Module(const char *filename, Identifier *ident, int doDocComment, int do
nameoffset = 0;
namelen = 0;
srcfilename = FileName::defaultExt(filename, global.mars_ext);
srcfilename = FileName::defaultExt(filename, global.mars_ext.ptr);
if (global.run_noext && global.params.run &&
!FileName::ext(filename) &&
@ -101,8 +101,8 @@ Module::Module(const char *filename, Identifier *ident, int doDocComment, int do
FileName::free(srcfilename);
srcfilename = FileName::removeExt(filename); // just does a mem.strdup(filename)
}
else if (!FileName::equalsExt(srcfilename, global.mars_ext) &&
!FileName::equalsExt(srcfilename, global.hdr_ext) &&
else if (!FileName::equalsExt(srcfilename, global.mars_ext.ptr) &&
!FileName::equalsExt(srcfilename, global.hdr_ext.ptr) &&
!FileName::equalsExt(srcfilename, "dd"))
{
error("source file name '%s' must have .%s extension", srcfilename, global.mars_ext);
@ -112,13 +112,13 @@ Module::Module(const char *filename, Identifier *ident, int doDocComment, int do
if (!FileName::absolute(srcfilename))
srcfilePath = getcwd(NULL, 0);
objfile = setOutfile(global.params.objname, global.params.objdir, filename, global.obj_ext);
objfile = setOutfile(global.params.objname.ptr, global.params.objdir.ptr, filename, global.obj_ext.ptr);
if (doDocComment)
setDocfile();
if (doHdrGen)
hdrfile = setOutfile(global.params.hdrname, global.params.hdrdir, arg, global.hdr_ext);
hdrfile = setOutfile(global.params.hdrname.ptr, global.params.hdrdir.ptr, arg, global.hdr_ext.ptr);
//objfile = new File(objfilename);
}
@ -130,7 +130,7 @@ Module *Module::create(const char *filename, Identifier *ident, int doDocComment
void Module::setDocfile()
{
docfile = setOutfile(global.params.docname, global.params.docdir, arg, global.doc_ext);
docfile = setOutfile(global.params.docname.ptr, global.params.docdir.ptr, arg, global.doc_ext.ptr);
}
/*********************************************
@ -302,7 +302,7 @@ bool Module::read(Loc loc)
{
::error(loc, "cannot find source code for runtime library file 'object.d'");
errorSupplemental(loc, "dmd might not be correctly installed. Run 'dmd -man' for installation instructions.");
const char *dmdConfFile = global.inifilename ? FileName::canonicalName(global.inifilename) : NULL;
const char *dmdConfFile = global.inifilename.length ? FileName::canonicalName(global.inifilename.ptr) : NULL;
errorSupplemental(loc, "config file: %s", dmdConfFile ? dmdConfFile : "not found");
}
else
@ -1288,11 +1288,11 @@ const char *lookForSourceFile(const char **path, const char *filename)
*/
*path = NULL;
const char *sdi = FileName::forceExt(filename, global.hdr_ext);
const char *sdi = FileName::forceExt(filename, global.hdr_ext.ptr);
if (FileName::exists(sdi) == 1)
return sdi;
const char *sd = FileName::forceExt(filename, global.mars_ext);
const char *sd = FileName::forceExt(filename, global.mars_ext.ptr);
if (FileName::exists(sd) == 1)
return sd;

View File

@ -2373,13 +2373,13 @@ public:
OutBuffer *ob = global.params.moduleDeps;
Module* imod = sc->instantiatingModule();
if (!global.params.moduleDepsFile)
if (!global.params.moduleDepsFile.length)
ob->writestring("depsFile ");
ob->writestring(imod->toPrettyChars());
ob->writestring(" (");
escapePath(ob, imod->srcfile->toChars());
ob->writestring(") : ");
if (global.params.moduleDepsFile)
if (global.params.moduleDepsFile.length)
ob->writestring("string : ");
ob->writestring((char *) se->string);
ob->writestring(" (");

View File

@ -144,26 +144,26 @@ struct Param
CHECKACTION checkAction; // action to take when bounds, asserts or switch defaults are violated
const char *argv0; // program name
DString argv0; // program name
Array<const char *> *modFileAliasStrings; // array of char*'s of -I module filename alias strings
Array<const char *> *imppath; // array of char*'s of where to look for import modules
Array<const char *> *fileImppath; // array of char*'s of where to look for file import modules
const char *objdir; // .obj/.lib file output directory
const char *objname; // .obj file output name
const char *libname; // .lib file output name
DString objdir; // .obj/.lib file output directory
DString objname; // .obj file output name
DString libname; // .lib file output name
bool doDocComments; // process embedded documentation comments
const char *docdir; // write documentation file to docdir directory
const char *docname; // write documentation file to docname
DString docdir; // write documentation file to docdir directory
DString docname; // write documentation file to docname
Array<const char *> *ddocfiles; // macro include files for Ddoc
bool doHdrGeneration; // process embedded documentation comments
const char *hdrdir; // write 'header' file to docdir directory
const char *hdrname; // write 'header' file to docname
DString hdrdir; // write 'header' file to docdir directory
DString hdrname; // write 'header' file to docname
bool hdrStripPlainFunctions; // strip the bodies of plain (non-template) functions
bool doJsonGeneration; // write JSON file
const char *jsonfilename; // write JSON file to jsonfilename
DString jsonfilename; // write JSON file to jsonfilename
unsigned debuglevel; // debug level
Array<const char *> *debugids; // debug identifiers
@ -171,11 +171,11 @@ struct Param
unsigned versionlevel; // version level
Array<const char *> *versionids; // version identifiers
const char *defaultlibname; // default library for non-debug builds
const char *debuglibname; // default library for debug builds
const char *mscrtlib; // MS C runtime library
DString defaultlibname; // default library for non-debug builds
DString debuglibname; // default library for debug builds
DString mscrtlib; // MS C runtime library
const char *moduleDepsFile; // filename for deps output
DString moduleDepsFile; // filename for deps output
OutBuffer *moduleDeps; // contents to be written to deps file
// Hidden debug switches
@ -194,10 +194,10 @@ struct Param
Array<const char *> *linkswitches;
Array<const char *> *libfiles;
Array<const char *> *dllfiles;
const char *deffile;
const char *resfile;
const char *exefile;
const char *mapfile;
DString deffile;
DString resfile;
DString exefile;
DString mapfile;
};
typedef unsigned structalign_t;
@ -207,26 +207,27 @@ typedef unsigned structalign_t;
struct Global
{
const char *inifilename;
const char *mars_ext;
const char *obj_ext;
const char *lib_ext;
const char *dll_ext;
const char *doc_ext; // for Ddoc generated files
const char *ddoc_ext; // for Ddoc macro include files
const char *hdr_ext; // for D 'header' import files
const char *json_ext; // for JSON files
const char *map_ext; // for .map files
DString inifilename;
DString mars_ext;
DString obj_ext;
DString lib_ext;
DString dll_ext;
DString doc_ext; // for Ddoc generated files
DString ddoc_ext; // for Ddoc macro include files
DString hdr_ext; // for D 'header' import files
DString cxxhdr_ext; // for C/C++ 'header' files
DString json_ext; // for JSON files
DString map_ext; // for .map files
bool run_noext; // allow -run sources without extensions.
const char *copyright;
const char *written;
DString copyright;
DString written;
const char *main_d; // dummy filename for dummy main()
Array<const char *> *path; // Array of char*'s which form the import lookup path
Array<const char *> *filePath; // Array of char*'s which form the file import lookup path
const char *version; // Compiler version string
const char *vendor; // Compiler backend name
DString version; // Compiler version string
DString vendor; // Compiler backend name
Param params;
unsigned errors; // number of errors reported so far

View File

@ -401,7 +401,7 @@ void Lexer::scan(Token *t)
}
else if (id == Id::VENDOR)
{
t->ustring = (utf8_t *)const_cast<char *>(global.vendor);
t->ustring = (utf8_t *)const_cast<char *>(global.vendor.ptr);
goto Lstr;
}
else if (id == Id::TIMESTAMP)
@ -417,7 +417,7 @@ void Lexer::scan(Token *t)
unsigned minor = 0;
bool point = false;
for (const char *p = global.version + 1; 1; p++)
for (const char *p = global.version.ptr + 1; 1; p++)
{
c = *p;
if (isdigit((utf8_t)c))

View File

@ -17,6 +17,22 @@ struct DArray
{
size_t length;
T *ptr;
DArray() : length(0), ptr(NULL) { }
DArray(size_t length_in, T *ptr_in)
: length(length_in), ptr(ptr_in) { }
};
struct DString : public DArray<const char>
{
DString() : DArray<const char>() { }
DString(const char *ptr)
: DArray<const char>(ptr ? strlen(ptr) : 0, ptr) { }
DString(size_t length, const char *ptr)
: DArray<const char>(length, ptr) { }
};
/// Corresponding C++ type that maps to D size_t