diff options
author | RabsRincon <rubrinbla@gmail.com> | 2018-01-18 19:43:10 +0100 |
---|---|---|
committer | RabsRincon <rubrinbla@gmail.com> | 2018-01-18 19:43:10 +0100 |
commit | a54faefb4c8668d9c9f93c78bd6bc639d1f0c219 (patch) | |
tree | 6465bf3e1d8e270cc53e67c04277c5773b16f7d6 /lib/compilers/argument-parsers.js | |
parent | 7bd30b4c4b10f93f26db81fbbe492149b8d487eb (diff) | |
download | compiler-explorer-a54faefb4c8668d9c9f93c78bd6bc639d1f0c219.tar.gz compiler-explorer-a54faefb4c8668d9c9f93c78bd6bc639d1f0c219.zip |
ES6fy compilers inheritance
Diffstat (limited to 'lib/compilers/argument-parsers.js')
-rw-r--r-- | lib/compilers/argument-parsers.js | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/lib/compilers/argument-parsers.js b/lib/compilers/argument-parsers.js index a0803a676..bf26271e5 100644 --- a/lib/compilers/argument-parsers.js +++ b/lib/compilers/argument-parsers.js @@ -26,9 +26,9 @@ const _ = require('underscore-node'), logger = require('../logger').logger, utils = require('../utils'); -const getOptions = function (compiler, helpArg) { - return compiler.exec(compiler.compiler.exe, [helpArg]) - .then(result => { +class BaseParser { + static getOptions(compiler, helpArg) { + return compiler.exec(compiler.compiler.exe, [helpArg]).then(result => { const options = {}; if (result.code === 0) { const optionFinder = /^\s*(--?[-a-zA-Z]+)/; @@ -41,13 +41,18 @@ const getOptions = function (compiler, helpArg) { } return options; }); -}; + } + static parse(compiler) { + return compiler; + } +} -const gccParser = function (compiler) { - return Promise.all([ - getOptions(compiler, "--target-help"), - getOptions(compiler, "--help=common")]) - .then(results => { +class GCCParser extends BaseParser { + static parse(compiler) { + return Promise.all([ + GCCParser.getOptions(compiler, "--target-help"), + GCCParser.getOptions(compiler, "--help=common") + ]).then(results => { const options = _.extend.apply(_.extend, results); compiler.compiler.supportsGccDump = true; logger.debug("gcc-like compiler options: ", _.keys(options).join(" ")); @@ -61,26 +66,28 @@ const gccParser = function (compiler) { } return compiler; }); -}; - -const clangParser = function (compiler) { - return getOptions(compiler, "--help").then(options => { - logger.debug("clang-like compiler options: ", _.keys(options).join(" ")); - if (options['-fsave-optimization-record']) { - compiler.compiler.optArg = "-fsave-optimization-record"; - compiler.compiler.supportsOptOutput = true; - } - if (options['-fcolor-diagnostics']) { - if (compiler.compiler.options) compiler.compiler.options += " "; - compiler.compiler.options += "-fcolor-diagnostics"; - } - return compiler; - }); -}; + } +} +class ClangParser extends BaseParser { + static parse(compiler) { + return ClangParser.getOptions(compiler, "--help").then(options => { + logger.debug("clang-like compiler options: ", _.keys(options).join(" ")); + if (options['-fsave-optimization-record']) { + compiler.compiler.optArg = "-fsave-optimization-record"; + compiler.compiler.supportsOptOutput = true; + } + if (options['-fcolor-diagnostics']) { + if (compiler.compiler.options) compiler.compiler.options += " "; + compiler.compiler.options += "-fcolor-diagnostics"; + } + return compiler; + }); + } +} module.exports = { - getOptions: getOptions, - clang: clangParser, - gcc: gccParser -};
\ No newline at end of file + Base: BaseParser, + Clang: ClangParser, + GCC: GCCParser +}; |