[committed] d: Merge upstream dmd cef1e7991.

Iain Buclaw ibuclaw@gdcproject.org
Sun Jun 7 12:17:14 GMT 2020


Hi,

This patch merges the D front-end implementation with 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.

Bootstrapped and regression tested on x86_64-linux-gnu, and committed to
mainline.

Regards
Iain.


gcc/d/ChangeLog:

	* dmd/MERGE: Merge upstream dmd cef1e7991.
	* d-lang.cc (d_parse_file): Adjust for new field types.
---
 gcc/d/d-lang.cc           |  9 +++---
 gcc/d/dmd/MERGE           |  2 +-
 gcc/d/dmd/attrib.c        |  2 +-
 gcc/d/dmd/cond.c          |  2 +-
 gcc/d/dmd/dimport.c       |  2 +-
 gcc/d/dmd/dmodule.c       | 18 +++++------
 gcc/d/dmd/expressionsem.c |  4 +--
 gcc/d/dmd/globals.h       | 63 ++++++++++++++++++++-------------------
 gcc/d/dmd/lexer.c         |  4 +--
 gcc/d/dmd/root/dcompat.h  | 16 ++++++++++
 10 files changed, 70 insertions(+), 52 deletions(-)

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 54d5799e59c..c4477cd90cb 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -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;
diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE
index 540801d1d44..fa94d63e471 100644
--- a/gcc/d/dmd/MERGE
+++ b/gcc/d/dmd/MERGE
@@ -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.
diff --git a/gcc/d/dmd/attrib.c b/gcc/d/dmd/attrib.c
index 184af1f288c..f4ca06d296a 100644
--- a/gcc/d/dmd/attrib.c
+++ b/gcc/d/dmd/attrib.c
@@ -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();
diff --git a/gcc/d/dmd/cond.c b/gcc/d/dmd/cond.c
index 53c5499f158..63f294a587c 100644
--- a/gcc/d/dmd/cond.c
+++ b/gcc/d/dmd/cond.c
@@ -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;
diff --git a/gcc/d/dmd/dimport.c b/gcc/d/dmd/dimport.c
index b176d8cadd0..32602d27e6c 100644
--- a/gcc/d/dmd/dimport.c
+++ b/gcc/d/dmd/dimport.c
@@ -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(" (");
diff --git a/gcc/d/dmd/dmodule.c b/gcc/d/dmd/dmodule.c
index ba7885e8c76..09e95472330 100644
--- a/gcc/d/dmd/dmodule.c
+++ b/gcc/d/dmd/dmodule.c
@@ -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;
 
diff --git a/gcc/d/dmd/expressionsem.c b/gcc/d/dmd/expressionsem.c
index 75e4d130564..4db9591a597 100644
--- a/gcc/d/dmd/expressionsem.c
+++ b/gcc/d/dmd/expressionsem.c
@@ -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(" (");
diff --git a/gcc/d/dmd/globals.h b/gcc/d/dmd/globals.h
index a6449b93ab8..5b5aac3ab68 100644
--- a/gcc/d/dmd/globals.h
+++ b/gcc/d/dmd/globals.h
@@ -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
diff --git a/gcc/d/dmd/lexer.c b/gcc/d/dmd/lexer.c
index 421d02a5da7..777842beff4 100644
--- a/gcc/d/dmd/lexer.c
+++ b/gcc/d/dmd/lexer.c
@@ -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))
diff --git a/gcc/d/dmd/root/dcompat.h b/gcc/d/dmd/root/dcompat.h
index dc9a7883927..72326d5ff65 100644
--- a/gcc/d/dmd/root/dcompat.h
+++ b/gcc/d/dmd/root/dcompat.h
@@ -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
-- 
2.20.1



More information about the Gcc-patches mailing list