mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
b5b94ed236
Summary: OI was previously using `std::regex_match` to match container names. This was bad because `libstdc++`'s implementation of regex is awful. In the case of limited inlining it was causing a stack overflow when running CodeGen for large types (I think types with large names but I never got to the bottom of it). Replace this with the competent `boost::regex_match` that we already have a dependency on. Reviewed By: ajor Differential Revision: D53002752
130 lines
4.1 KiB
C++
130 lines
4.1 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
#pragma once
|
|
#include <boost/regex.hpp>
|
|
#include <filesystem>
|
|
#include <optional>
|
|
#include <set>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "oi/ContainerTypeEnum.h"
|
|
#include "oi/Features.h"
|
|
|
|
ContainerTypeEnum containerTypeEnumFromStr(std::string& str);
|
|
const char* containerTypeEnumToStr(ContainerTypeEnum ty);
|
|
|
|
struct ContainerInfo {
|
|
struct Processor {
|
|
std::string type;
|
|
std::string func;
|
|
};
|
|
|
|
struct Codegen {
|
|
std::string decl;
|
|
std::string func;
|
|
std::string traversalFunc = "";
|
|
std::string extra = "";
|
|
std::vector<Processor> processors{};
|
|
};
|
|
|
|
explicit ContainerInfo(const std::filesystem::path& path); // Throws
|
|
ContainerInfo(std::string typeName,
|
|
ContainerTypeEnum ctype,
|
|
std::string header);
|
|
|
|
// Old ctors, remove with OICodeGen:
|
|
ContainerInfo() = default;
|
|
ContainerInfo(std::string typeName_,
|
|
boost::regex matcher,
|
|
std::optional<size_t> numTemplateParams_,
|
|
ContainerTypeEnum ctype_,
|
|
std::string header_,
|
|
std::vector<std::string> ns_,
|
|
std::vector<size_t> replaceTemplateParamIndex_,
|
|
std::optional<size_t> allocatorIndex_,
|
|
std::optional<size_t> underlyingContainerIndex_,
|
|
std::vector<size_t> stubTemplateParams_,
|
|
oi::detail::FeatureSet requiredFeatures,
|
|
ContainerInfo::Codegen codegen_)
|
|
: typeName(std::move(typeName_)),
|
|
numTemplateParams(numTemplateParams_),
|
|
ctype(ctype_),
|
|
header(std::move(header_)),
|
|
ns(std::move(ns_)),
|
|
replaceTemplateParamIndex(std::move(replaceTemplateParamIndex_)),
|
|
allocatorIndex(allocatorIndex_),
|
|
underlyingContainerIndex(underlyingContainerIndex_),
|
|
stubTemplateParams(std::move(stubTemplateParams_)),
|
|
requiredFeatures(requiredFeatures),
|
|
codegen(std::move(codegen_)),
|
|
matcher_(std::move(matcher)) {
|
|
}
|
|
|
|
ContainerInfo(ContainerInfo&&) = default;
|
|
ContainerInfo& operator=(ContainerInfo&&) = default;
|
|
|
|
// Explicit interface for copying
|
|
ContainerInfo clone() const {
|
|
ContainerInfo copy{*this};
|
|
return copy;
|
|
}
|
|
|
|
bool matches(std::string_view sv) const {
|
|
return boost::regex_search(sv.begin(), sv.end(), matcher_);
|
|
}
|
|
|
|
std::string typeName;
|
|
std::optional<size_t> numTemplateParams;
|
|
ContainerTypeEnum ctype = UNKNOWN_TYPE;
|
|
std::string header;
|
|
std::vector<std::string> ns;
|
|
std::vector<size_t> replaceTemplateParamIndex{};
|
|
std::optional<size_t> allocatorIndex{};
|
|
// Index of underlying container in template parameters for a container
|
|
// adapter
|
|
std::optional<size_t> underlyingContainerIndex{};
|
|
std::vector<size_t> stubTemplateParams{};
|
|
bool captureKeys = false;
|
|
oi::detail::FeatureSet requiredFeatures;
|
|
|
|
Codegen codegen;
|
|
|
|
static std::unique_ptr<ContainerInfo> loadFromFile(
|
|
const std::filesystem::path& path);
|
|
|
|
bool operator<(const ContainerInfo& rhs) const {
|
|
return (typeName < rhs.typeName);
|
|
}
|
|
|
|
private:
|
|
ContainerInfo(const ContainerInfo&) = default;
|
|
ContainerInfo& operator=(const ContainerInfo& other) = default;
|
|
|
|
boost::regex matcher_;
|
|
};
|
|
|
|
class ContainerInfoError : public std::runtime_error {
|
|
public:
|
|
ContainerInfoError(const std::filesystem::path& path, const std::string& msg)
|
|
: std::runtime_error{std::string{path} + ": " + msg} {
|
|
}
|
|
};
|
|
|
|
using ContainerInfoRefSet =
|
|
std::set<std::reference_wrapper<const ContainerInfo>,
|
|
std::less<ContainerInfo>>;
|