mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-12-02 05:09:47 -06:00
add parsers to collect stdversions
This commit is contained in:
@@ -106,6 +106,8 @@ export const c_default_target_description =
|
||||
' eventhough the option is available. ' +
|
||||
'The compiler might also require additional arguments to be fully functional.';
|
||||
|
||||
export const c_default_stdver_description = 'Change the C/C++ standard version of the compiler.';
|
||||
|
||||
export class BaseCompiler implements ICompiler {
|
||||
protected compiler: CompilerInfo; // TODO: Some missing types still present in Compiler type
|
||||
public lang: Language;
|
||||
@@ -2841,6 +2843,11 @@ but nothing was dumped. Possible causes are:
|
||||
}
|
||||
}
|
||||
|
||||
async getPossibleStdversAsOverrideValues(): Promise<CompilerOverrideOption[]> {
|
||||
const parser = this.getArgumentParser();
|
||||
return await parser.getPossibleStdvers(this);
|
||||
}
|
||||
|
||||
async populatePossibleOverrides() {
|
||||
if (this.compiler.supportsMarch) {
|
||||
const targets = await this.getTargetsAsOverrideValues();
|
||||
@@ -2879,6 +2886,22 @@ but nothing was dumped. Possible causes are:
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// activate this when parsers have been made for more compilers and
|
||||
// we can add an alternative implementation to msvc
|
||||
|
||||
/*
|
||||
const stdVersions = await this.getPossibleStdversAsOverrideValues();
|
||||
if (stdVersions.length > 0) {
|
||||
this.compiler.possibleOverrides?.push({
|
||||
name: CompilerOverrideType.stdver,
|
||||
display_title: 'Std version',
|
||||
description: c_default_stdver_description,
|
||||
flags: ['-std=<value>'],
|
||||
values: stdVersions,
|
||||
});
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
async initialise(mtime: Date, clientOptions, isPrediscovered = false) {
|
||||
|
||||
@@ -31,6 +31,7 @@ import {logger} from '../logger.js';
|
||||
import * as props from '../properties.js';
|
||||
import * as utils from '../utils.js';
|
||||
import fs from 'fs-extra';
|
||||
import {CompilerOverrideOptions} from '../../types/compilation/compiler-overrides.interfaces.js';
|
||||
|
||||
export class BaseParser {
|
||||
static hasSupport(options, forOption) {
|
||||
@@ -78,6 +79,10 @@ export class BaseParser {
|
||||
return [];
|
||||
}
|
||||
|
||||
static async getPossibleStdvers(compiler): Promise<CompilerOverrideOptions> {
|
||||
return [];
|
||||
}
|
||||
|
||||
static async getOptions(compiler, helpArg) {
|
||||
const optionFinder = /^\s*(--?[\d+,<=>[\]a-z|-]*)\s*(.*)/i;
|
||||
const result = await compiler.execCompilerCached(compiler.compiler.exe, [helpArg]);
|
||||
@@ -150,6 +155,21 @@ export class GCCParser extends BaseParser {
|
||||
}
|
||||
}
|
||||
|
||||
static override async getPossibleStdvers(compiler): Promise<CompilerOverrideOptions> {
|
||||
const possible: CompilerOverrideOptions = [];
|
||||
const options = await GCCParser.getOptionsStrict(compiler, '-fsyntax-only --help=c++');
|
||||
for (const opt in options) {
|
||||
if (opt.startsWith('-std=') && !options[opt].description?.startsWith('Deprecated')) {
|
||||
const stdver = opt.substring(5);
|
||||
possible.push({
|
||||
name: stdver + ': ' + options[opt].description,
|
||||
value: stdver,
|
||||
});
|
||||
}
|
||||
}
|
||||
return possible;
|
||||
}
|
||||
|
||||
static override async getOptions(compiler, helpArg) {
|
||||
const optionFinder = /^\s*(--?[\d+,<=>[\]a-z|-]*)\s*(.*)/i;
|
||||
const result = await compiler.execCompilerCached(compiler.compiler.exe, helpArg.split(' '));
|
||||
@@ -157,6 +177,14 @@ export class GCCParser extends BaseParser {
|
||||
compiler.possibleArguments.populateOptions(options);
|
||||
return options;
|
||||
}
|
||||
|
||||
static async getOptionsStrict(compiler, helpArg) {
|
||||
const optionFinder = /^\s{2}(--?[\d+,<=>[\]a-z|-]*)\s*(.*)/i;
|
||||
const result = await compiler.execCompilerCached(compiler.compiler.exe, [helpArg]);
|
||||
const options = result.code === 0 ? BaseParser.parseLines(result.stdout + result.stderr, optionFinder) : {};
|
||||
compiler.possibleArguments.populateOptions(options);
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
export class ClangParser extends BaseParser {
|
||||
@@ -217,6 +245,47 @@ export class ClangParser extends BaseParser {
|
||||
}
|
||||
}
|
||||
|
||||
static override async getPossibleStdvers(compiler): Promise<CompilerOverrideOptions> {
|
||||
// clang doesn't have a --help option to get the std versions, we'll have to compile with a fictional stdversion to coax a response
|
||||
const re1 = /note: use '([\w\d+]*)' for '(.*)' standard/;
|
||||
const re2 = /note: use '([\w\d+]*)' or '([\w\d+]*)' for '(.*)' standard/;
|
||||
const possible: CompilerOverrideOptions = [];
|
||||
const EXAMPLES_PATH = props.get('builtin', 'sourcePath', './examples/');
|
||||
let filename = path.join(EXAMPLES_PATH, 'c++/default.cpp');
|
||||
if (!path.isAbsolute(filename)) filename = path.join(process.cwd(), filename);
|
||||
const result = await compiler.execCompilerCached(compiler.compiler.exe, ['-std=c++9999999', filename, '-c']);
|
||||
if (result.stderr) {
|
||||
const lines = utils.splitLines(result.stderr);
|
||||
for (const line of lines) {
|
||||
const match1 = line.match(re1);
|
||||
if (match1) {
|
||||
possible.push({
|
||||
name: match1[1] + ': ' + match1[2],
|
||||
value: match1[1],
|
||||
});
|
||||
} else {
|
||||
const match2 = line.match(re2);
|
||||
if (match2) {
|
||||
possible.push({
|
||||
name: match2[1] + ': ' + match2[3],
|
||||
value: match2[1],
|
||||
});
|
||||
possible.push({
|
||||
name: match2[2] + ': ' + match2[3],
|
||||
value: match2[2],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
possible.sort((a, b) => {
|
||||
return a.value === b.value ? 0 : a.value > b.value ? 1 : -1;
|
||||
});
|
||||
|
||||
return possible;
|
||||
}
|
||||
|
||||
static override async getPossibleTargets(compiler): Promise<string[]> {
|
||||
const re = /\s+([\w-]*)\s*-\s.*/;
|
||||
const result = await compiler.execCompilerCached(compiler.compiler.exe, ['--print-targets']);
|
||||
|
||||
@@ -28,6 +28,7 @@ export enum CompilerOverrideType {
|
||||
arch = 'arch',
|
||||
env = 'env',
|
||||
edition = 'edition',
|
||||
stdver = 'stdver',
|
||||
}
|
||||
|
||||
export type CompilerOverrideTypes = Set<CompilerOverrideType>;
|
||||
|
||||
Reference in New Issue
Block a user