From 7911589964f21a0824311e549e044a074b7a8ca0 Mon Sep 17 00:00:00 2001 From: Alexey Prokhin Date: Tue, 4 Jan 2011 13:48:08 +0300 Subject: [PATCH] Added ability to generate JSON files. Fixed generating of 'header' files. --- dmd2/mars.h | 2 +- gen/cl_options.cpp | 9 +++++++++ gen/cl_options.h | 1 + gen/main.cpp | 18 +++++++++++++++++- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/dmd2/mars.h b/dmd2/mars.h index 61ae0390..b9329f5a 100644 --- a/dmd2/mars.h +++ b/dmd2/mars.h @@ -208,7 +208,7 @@ struct Param char *hdrdir; // write 'header' file to docdir directory char *hdrname; // write 'header' file to docname - char doXGeneration; // write JSON file + bool doXGeneration; // write JSON file char *xfilename; // write JSON file to xfilename unsigned debuglevel; // debug level diff --git a/gen/cl_options.cpp b/gen/cl_options.cpp index f24e9c3a..cbb8c5c1 100644 --- a/gen/cl_options.cpp +++ b/gen/cl_options.cpp @@ -116,6 +116,15 @@ cl::opt ddocFile("Df", cl::value_desc("filename"), cl::Prefix); +// Json options +static cl::opt doJson("X", + cl::desc("generate JSON file"), + cl::location(global.params.doXGeneration)); + +cl::opt jsonFile("Xf", + cl::desc("write JSON file to "), + cl::value_desc("filename"), + cl::Prefix); // Header generation options #ifdef _DH diff --git a/gen/cl_options.h b/gen/cl_options.h index e2c32e91..f7bf623a 100644 --- a/gen/cl_options.h +++ b/gen/cl_options.h @@ -28,6 +28,7 @@ namespace opts { extern cl::opt output_o; extern cl::opt ddocDir; extern cl::opt ddocFile; + extern cl::opt jsonFile; #ifdef _DH extern cl::opt hdrDir; extern cl::opt hdrFile; diff --git a/gen/main.cpp b/gen/main.cpp index e40b2533..caa38adc 100644 --- a/gen/main.cpp +++ b/gen/main.cpp @@ -33,6 +33,7 @@ #include "mtype.h" #include "id.h" #include "cond.h" +#include "json.h" #include "gen/logger.h" #include "gen/linkage.h" @@ -228,6 +229,10 @@ int main(int argc, char** argv) global.params.doDocComments |= global.params.docdir || global.params.docname; + initFromString(global.params.xfilename, jsonFile); + if (global.params.xfilename) + global.params.doXGeneration = true; + #ifdef _DH initFromString(global.params.hdrdir, hdrDir); initFromString(global.params.hdrname, hdrFile); @@ -724,6 +729,13 @@ LDC_TARGETS continue; } + if (FileName::equals(ext, global.json_ext)) + { + global.params.doXGeneration = 1; + global.params.xfilename = (char *)files.data[i]; + continue; + } + #if !POSIX if (stricmp(ext, "res") == 0) { @@ -790,9 +802,9 @@ LDC_TARGETS if (!Module::rootModule) Module::rootModule = m; m->importedFrom = m; + m->buildTargetFiles(singleObj); m->read(0); m->parse(); - m->buildTargetFiles(singleObj); m->deleteObjFile(); if (m->isDocFile) { @@ -978,6 +990,10 @@ LDC_TARGETS global.params.objfiles->push(filename); } + // output json file + if (global.params.doXGeneration) + json_generate(&modules); + backend_term(); if (global.errors) fatal();