]> git.tdb.fi Git - builder.git/commitdiff
More sophisticated handling of language standards
authorMikko Rasa <tdb@tdb.fi>
Sat, 10 Dec 2022 23:16:49 +0000 (01:16 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 10 Dec 2022 23:16:49 +0000 (01:16 +0200)
source/buildinfo.cpp
source/buildinfo.h
source/gnucompiler.cpp
source/msvccompiler.cpp

index e2df34c06e3ec91cb56500f97c3bed1b53b23d02..1cafbd3b866344d2665181393b7e1fa0855ea197 100644 (file)
@@ -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.size()); ++i)
+               if(isdigit(static_cast<unsigned char>(std[i])))
+                       num = i;
+       type = std.substr(0, num);
+       year = lexical_cast<unsigned>(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<BuildInfo>(bi)
 {
index fa8ae62d39606527509d7c9a8b8dd18d77db68e7..c0584002233512392849dd7a6097de40bc02f1a6 100644 (file)
@@ -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<Msp::FS::Path> PathList;
        typedef std::list<std::string> WordList;
        typedef std::map<std::string, LibraryMode> LibModeMap;
-       typedef std::map<std::string, std::string> StandardMap;
+       typedef std::map<std::string, LanguageStandard> StandardMap;
 
        Tracked<Msp::FS::Path> sysroot;
        DefineMap defines;
index fe1d735db197c6acff4512fe08721ec94b2ffaf5..a6e838d1e49ea160bf6d320d647fe44ed9be7381 100644 (file)
@@ -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)
        {
index 12668a639c6dfc7db8941be12627ef52b520ba20..0e1a1f4e94158136737a077bb17d7362d6036875 100644 (file)
@@ -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)