From: Mikko Rasa Date: Sat, 10 Dec 2022 23:16:49 +0000 (+0200) Subject: More sophisticated handling of language standards X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=1c66151c44b4f4fb567da5ec8b75f066cccc5421;p=builder.git More sophisticated handling of language standards --- diff --git a/source/buildinfo.cpp b/source/buildinfo.cpp index e2df34c..1cafbd3 100644 --- a/source/buildinfo.cpp +++ b/source/buildinfo.cpp @@ -84,6 +84,23 @@ void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level) } +BuildInfo::LanguageStandard::LanguageStandard(const string &std) +{ + string::size_type num = string::npos; + for(string::size_type i=0; (num==string::npos && i(std[i]))) + num = i; + type = std.substr(0, num); + year = lexical_cast(std.substr(num)); + year += (year<70 ? 2000 : 1900); +} + +string BuildInfo::LanguageStandard::str() const +{ + return format("%s%02d", type, year%100); +} + + BuildInfo::Loader::Loader(BuildInfo &bi): DataFile::ObjectLoader(bi) { diff --git a/source/buildinfo.h b/source/buildinfo.h index fa8ae62..c058400 100644 --- a/source/buildinfo.h +++ b/source/buildinfo.h @@ -51,6 +51,17 @@ public: CHAINED //< Include only compilation options }; + struct LanguageStandard + { + std::string type; + unsigned year; + + LanguageStandard(): year(0) { } + LanguageStandard(const std::string &); + + std::string str() const; + }; + /** A wrapper which tracks the set status of the wrapped variable. A default value may be provided in initialization without causing it to be treated as @@ -82,7 +93,7 @@ public: typedef std::list PathList; typedef std::list WordList; typedef std::map LibModeMap; - typedef std::map StandardMap; + typedef std::map StandardMap; Tracked sysroot; DefineMap defines; diff --git a/source/gnucompiler.cpp b/source/gnucompiler.cpp index fe1d735..a6e838d 100644 --- a/source/gnucompiler.cpp +++ b/source/gnucompiler.cpp @@ -210,9 +210,9 @@ Task *GnuCompiler::run(const Target &target) const string tag_for_std = (tag=="OBJC" ? "CC" : tag); if(binfo.standards.count(tag_for_std)) - argv.push_back("-std="+get_item(binfo.standards, tag_for_std)); + argv.push_back("-std="+get_item(binfo.standards, tag_for_std).str()); if(tag=="OBJC" && binfo.standards.count(tag)) - argv.push_back("-fobjc-std="+get_item(binfo.standards, tag)); + argv.push_back("-fobjc-std="+get_item(binfo.standards, tag).str()); if(binfo.warning_level>=1) { diff --git a/source/msvccompiler.cpp b/source/msvccompiler.cpp index 12668a6..0e1a1f4 100644 --- a/source/msvccompiler.cpp +++ b/source/msvccompiler.cpp @@ -107,9 +107,9 @@ Task *MsvcCompiler::run(const Target &target) const if(binfo.standards.count(tag)) { - string std = get_item(binfo.standards, tag); - if(std!="c++11" && std!="c99") - argv.push_back("/std:"+std); + const BuildInfo::LanguageStandard &std = get_item(binfo.standards, tag); + if((tag=="CXX" && std.year>2011) || (tag=="CC" && std.year>1999)) + argv.push_back("/std:"+std.str()); } if(binfo.warning_level>=1)