Merge "header-checker: Downgrade to C++ 14"

This commit is contained in:
Logan Chien
2019-12-10 04:36:33 +00:00
committed by Gerrit Code Review
10 changed files with 36 additions and 25 deletions

View File

@@ -32,7 +32,7 @@ cc_defaults {
cppflags: [
"-fno-exceptions",
"-fno-rtti",
"-std=c++17",
"-std=c++14",
],
target: {
@@ -211,6 +211,7 @@ cc_test_host {
],
shared_libs: [
"libLLVM_host",
"libc++_host",
],

View File

@@ -156,8 +156,9 @@ static std::string GetConfigFilePath(const std::string &dump_file_path) {
static void ReadConfigFile(const std::string &config_file_path) {
ConfigFile cfg = ConfigParser::ParseFile(config_file_path);
if (cfg.HasSection("global")) {
for (auto &&[key, value] : cfg.GetSection("global")) {
bool value_bool = ParseBool(value);
for (auto &&p : cfg.GetSection("global")) {
auto &&key = p.first;
bool value_bool = ParseBool(p.second);
if (key == "allow_adding_removing_weak_symbols") {
allow_adding_removing_weak_symbols = value_bool;
} else if (key == "advice_only") {

View File

@@ -20,6 +20,7 @@
#include "utils/command_line_utils.h"
#include "utils/header_abi_util.h"
#include <llvm/ADT/Optional.h>
#include <llvm/Support/CommandLine.h>
#include <llvm/Support/raw_ostream.h>
@@ -401,7 +402,7 @@ bool HeaderAbiLinker::ReadExportedSymbols() {
}
bool HeaderAbiLinker::ReadExportedSymbolsFromVersionScript() {
std::optional<utils::ApiLevel> api_level = utils::ParseApiLevel(api_);
llvm::Optional<utils::ApiLevel> api_level = utils::ParseApiLevel(api_);
if (!api_level) {
llvm::errs() << "-api must be either \"current\" or an integer (e.g. 21)\n";
return false;
@@ -415,7 +416,7 @@ bool HeaderAbiLinker::ReadExportedSymbolsFromVersionScript() {
repr::VersionScriptParser parser;
parser.SetArch(arch_);
parser.SetApiLevel(api_level.value());
parser.SetApiLevel(api_level.getValue());
for (auto &&version : excluded_symbol_versions_) {
parser.AddExcludedSymbolVersion(version);
}

View File

@@ -17,6 +17,8 @@
#include "repr/symbol/exported_symbol_set.h"
#include "utils/string_utils.h"
#include <llvm/ADT/Optional.h>
#include <iostream>
#include <memory>
#include <regex>
@@ -94,28 +96,28 @@ VersionScriptParser::ParsedTags VersionScriptParser::ParseSymbolTags(
// Check introduced tags.
if (utils::StartsWith(tag, "introduced=")) {
std::optional<utils::ApiLevel> intro = utils::ParseApiLevel(
llvm::Optional<utils::ApiLevel> intro = utils::ParseApiLevel(
std::string(tag.substr(sizeof("introduced=") - 1)));
if (!intro) {
ReportError("Bad introduced tag: " + std::string(tag));
} else {
if (!has_introduced_arch_tags) {
result.has_introduced_tags_ = true;
result.introduced_ = intro.value();
result.introduced_ = intro.getValue();
}
}
continue;
}
if (utils::StartsWith(tag, introduced_arch_tag_)) {
std::optional<utils::ApiLevel> intro = utils::ParseApiLevel(
llvm::Optional<utils::ApiLevel> intro = utils::ParseApiLevel(
std::string(tag.substr(introduced_arch_tag_.size())));
if (!intro) {
ReportError("Bad introduced tag " + std::string(tag));
} else {
has_introduced_arch_tags = true;
result.has_introduced_tags_ = true;
result.introduced_ = intro.value();
result.introduced_ = intro.getValue();
}
continue;
}

View File

@@ -16,6 +16,8 @@
#include "utils/string_utils.h"
#include <llvm/ADT/Optional.h>
#include <cassert>
#include <string>
@@ -24,7 +26,7 @@ namespace header_checker {
namespace utils {
std::optional<ApiLevel> ParseApiLevel(const std::string &api_level_str) {
llvm::Optional<ApiLevel> ParseApiLevel(const std::string &api_level_str) {
if (api_level_str == "current") {
return FUTURE_API_LEVEL;
}

View File

@@ -15,7 +15,8 @@
#ifndef API_LEVEL_H_
#define API_LEVEL_H_
#include <optional>
#include <llvm/ADT/Optional.h>
#include <string>
@@ -29,7 +30,7 @@ using ApiLevel = int;
constexpr ApiLevel FUTURE_API_LEVEL = 10000;
std::optional<ApiLevel> ParseApiLevel(const std::string &api);
llvm::Optional<ApiLevel> ParseApiLevel(const std::string &api);
} // namespace utils

View File

@@ -25,11 +25,11 @@ TEST(ApiLevelTest, ParseApiLevel) {
EXPECT_FALSE(ParseApiLevel(""));
EXPECT_FALSE(ParseApiLevel("A"));
EXPECT_TRUE(ParseApiLevel("current").has_value());
EXPECT_EQ(FUTURE_API_LEVEL, ParseApiLevel("current").value());
EXPECT_TRUE(ParseApiLevel("current").hasValue());
EXPECT_EQ(FUTURE_API_LEVEL, ParseApiLevel("current").getValue());
EXPECT_TRUE(ParseApiLevel("16").has_value());
EXPECT_EQ(16l, ParseApiLevel("16").value());
EXPECT_TRUE(ParseApiLevel("16").hasValue());
EXPECT_EQ(16l, ParseApiLevel("16").getValue());
}

View File

@@ -14,6 +14,8 @@
#include "utils/string_utils.h"
#include <llvm/ADT/Optional.h>
#include <algorithm>
#include <cctype>
#include <cstdlib>
@@ -72,7 +74,7 @@ std::vector<std::string_view> Split(std::string_view s,
}
std::optional<int> ParseInt(const std::string &s) {
llvm::Optional<int> ParseInt(const std::string &s) {
const char *start = s.c_str();
if (*start == '\0') {
return {};

View File

@@ -15,7 +15,8 @@
#ifndef STRING_UTILS_H_
#define STRING_UTILS_H_
#include <optional>
#include <llvm/ADT/Optional.h>
#include <string>
#include <vector>
@@ -33,7 +34,7 @@ bool EndsWith(std::string_view s, std::string_view suffix);
std::vector<std::string_view> Split(std::string_view s,
std::string_view delim_chars);
std::optional<int> ParseInt(const std::string &s);
llvm::Optional<int> ParseInt(const std::string &s);
bool ParseBool(const std::string &s);

View File

@@ -83,14 +83,14 @@ TEST(StringUtilsTest, ParseInt) {
EXPECT_FALSE(ParseInt("0xa"));
EXPECT_FALSE(ParseInt("16h"));
EXPECT_TRUE(ParseInt("0").has_value());
EXPECT_EQ(0, ParseInt("0").value());
EXPECT_TRUE(ParseInt("0").hasValue());
EXPECT_EQ(0, ParseInt("0").getValue());
EXPECT_TRUE(ParseInt("16").has_value());
EXPECT_EQ(16, ParseInt("16").value());
EXPECT_TRUE(ParseInt("16").hasValue());
EXPECT_EQ(16, ParseInt("16").getValue());
EXPECT_TRUE(ParseInt("-16").has_value());
EXPECT_EQ(-16, ParseInt("-16").value());
EXPECT_TRUE(ParseInt("-16").hasValue());
EXPECT_EQ(-16, ParseInt("-16").getValue());
}