diff --git a/include/oi/types/dy.h b/include/oi/types/dy.h index 83fb557..df088aa 100644 --- a/include/oi/types/dy.h +++ b/include/oi/types/dy.h @@ -29,9 +29,9 @@ * translating these types to OID/OITB they cannot be compiled in, so we * represent the template arguments with member fields instead. * - * Each type in this namespace corresponds 1-1 with a type in - * ObjectIntrospection::types::st, except Dynamic which references them all. See - * the types in st.h for the description of what each type contains. + * Each type in this namespace corresponds 1-1 with a type in oi::types::st, + * except Dynamic which references them all. See the types in st.h for the + * description of what each type contains. * * All types in this file include a constexpr constructor. This allows a single * extern const variable in the JIT code to include pointer references to other @@ -43,7 +43,7 @@ #include #include -namespace ObjectIntrospection::types::dy { +namespace oi::types::dy { class Unit; class VarInt; @@ -93,6 +93,6 @@ class List { Dynamic element; }; -} // namespace ObjectIntrospection::types::dy +} // namespace oi::types::dy #endif diff --git a/include/oi/types/st.h b/include/oi/types/st.h index b414124..721b1b6 100644 --- a/include/oi/types/st.h +++ b/include/oi/types/st.h @@ -55,7 +55,7 @@ * dynamic description of their type as the constexpr field `describe`. Compound * types compose appropriately. */ -namespace ObjectIntrospection::types::st { +namespace oi::types::st { #ifdef DEFINE_DESCRIBE #include "oi/types/dy.h" @@ -280,6 +280,6 @@ class List #endif }; -} // namespace ObjectIntrospection::types::st +} // namespace oi::types::st #endif diff --git a/oi/CodeGen.cpp b/oi/CodeGen.cpp index f05265a..9f62510 100644 --- a/oi/CodeGen.cpp +++ b/oi/CodeGen.cpp @@ -40,6 +40,8 @@ #include "type_graph/TypeIdentifier.h" #include "type_graph/Types.h" +namespace oi::detail { + using type_graph::AddChildren; using type_graph::AddPadding; using type_graph::AlignmentCalc; @@ -861,7 +863,8 @@ void CodeGen::generate( if (config_.features[Feature::TypedDataSegment]) { FuncGen::DefineDataSegmentDataBuffer(code); - code += "using namespace ObjectIntrospection;\n"; + code += "using namespace oi;\n"; + code += "using namespace oi::detail;\n"; code += "namespace OIInternal {\nnamespace {\n"; FuncGen::DefineBasicTypeHandlers(code); @@ -927,3 +930,5 @@ void CodeGen::generate( std::cout << code; } } + +} // namespace oi::detail diff --git a/oi/CodeGen.h b/oi/CodeGen.h index e25325f..6170c1b 100644 --- a/oi/CodeGen.h +++ b/oi/CodeGen.h @@ -26,14 +26,16 @@ #include "OICodeGen.h" struct drgn_type; - +namespace oi::detail { class SymbolService; - -namespace type_graph { +} +namespace oi::detail::type_graph { class Class; class Member; class TypeGraph; -} // namespace type_graph +} // namespace oi::detail::type_graph + +namespace oi::detail { class CodeGen { public: @@ -76,3 +78,5 @@ class CodeGen { std::string& code); void getClassTypeHandler(const type_graph::Class& c, std::string& code); }; + +} // namespace oi::detail diff --git a/oi/Features.cpp b/oi/Features.cpp index 04614a1..6ea17f1 100644 --- a/oi/Features.cpp +++ b/oi/Features.cpp @@ -19,7 +19,7 @@ #include #include -namespace ObjectIntrospection { +namespace oi::detail { namespace { std::string_view featureHelp(Feature f) { @@ -101,4 +101,4 @@ void featuresHelp(std::ostream& out) { } } -} // namespace ObjectIntrospection +} // namespace oi::detail diff --git a/oi/Features.h b/oi/Features.h index d6b7c25..adfddeb 100644 --- a/oi/Features.h +++ b/oi/Features.h @@ -36,7 +36,7 @@ X(JitTiming, "jit-timing") \ X(PolymorphicInheritance, "polymorphic-inheritance") -namespace ObjectIntrospection { +namespace oi::detail { enum class Feature { UnknownFeature, @@ -58,4 +58,4 @@ constexpr std::array allFeatures = { // Use "size+1" to account for UnknownFeature" using FeatureSet = EnumBitset; -} // namespace ObjectIntrospection +} // namespace oi::detail diff --git a/oi/FuncGen.cpp b/oi/FuncGen.cpp index 51c84cc..8aadc20 100644 --- a/oi/FuncGen.cpp +++ b/oi/FuncGen.cpp @@ -22,9 +22,7 @@ #include "oi/ContainerInfo.h" -using ObjectIntrospection::Feature; -using ObjectIntrospection::FeatureSet; - +namespace oi::detail { namespace { const std::string typedValueFunc = R"( @@ -538,7 +536,7 @@ void FuncGen::DeclareGetContainer(std::string& testCode) { */ void FuncGen::DefineDataSegmentDataBuffer(std::string& testCode) { constexpr std::string_view func = R"( - namespace ObjectIntrospection::DataBuffer { + namespace oi::detail::DataBuffer { class DataSegment { public: @@ -560,7 +558,7 @@ void FuncGen::DefineDataSegmentDataBuffer(std::string& testCode) { uint8_t* buf; }; - } // namespace ObjectIntrospection::DataBuffer + } // namespace oi::detail::DataBuffer )"; testCode.append(func); @@ -632,3 +630,5 @@ void FuncGen::DefineBasicTypeHandlers(std::string& testCode) { testCode.append(tHandler); testCode.append(voidHandler); } + +} // namespace oi::detail diff --git a/oi/FuncGen.h b/oi/FuncGen.h index 22f4c2f..65fbe71 100644 --- a/oi/FuncGen.h +++ b/oi/FuncGen.h @@ -24,6 +24,8 @@ namespace fs = std::filesystem; +namespace oi::detail { + class FuncGen { public: static void DeclareStoreData(std::string& testCode); @@ -40,10 +42,10 @@ class FuncGen { bool DeclareGetSizeFuncs(std::string& testCode, const ContainerInfoRefSet& containerInfo, - ObjectIntrospection::FeatureSet features); + FeatureSet features); bool DefineGetSizeFuncs(std::string& testCode, const ContainerInfoRefSet& containerInfo, - ObjectIntrospection::FeatureSet features); + FeatureSet features); static void DeclareGetContainer(std::string& testCode); @@ -55,24 +57,21 @@ class FuncGen { const std::string& type, const std::string& linkageName); - static void DefineTopLevelGetSizeRef( - std::string& testCode, - const std::string& rawType, - ObjectIntrospection::FeatureSet features); - static void DefineTopLevelGetSizeRefTyped( - std::string& testCode, - const std::string& rawType, - ObjectIntrospection::FeatureSet features); + static void DefineTopLevelGetSizeRef(std::string& testCode, + const std::string& rawType, + FeatureSet features); + static void DefineTopLevelGetSizeRefTyped(std::string& testCode, + const std::string& rawType, + FeatureSet features); static void DefineOutputType(std::string& testCode, const std::string& rawType); static void DefineTopLevelGetSizeRefRet(std::string& testCode, const std::string& type); - static void DefineTopLevelGetSizeSmartPtr( - std::string& testCode, - const std::string& rawType, - ObjectIntrospection::FeatureSet features); + static void DefineTopLevelGetSizeSmartPtr(std::string& testCode, + const std::string& rawType, + FeatureSet features); static void DefineGetSizeTypedValueFunc(std::string& testCode, const std::string& ctype); @@ -80,3 +79,5 @@ class FuncGen { static void DefineDataSegmentDataBuffer(std::string& testCode); static void DefineBasicTypeHandlers(std::string& testCode); }; + +} // namespace oi::detail diff --git a/oi/Headers.h b/oi/Headers.h index a0ee36f..191d54a 100644 --- a/oi/Headers.h +++ b/oi/Headers.h @@ -15,13 +15,11 @@ */ #include -namespace ObjectIntrospection { -namespace headers { +namespace oi::detail::headers { // These externs are provided by our build system. See resources/CMakeLists.txt extern const std::string_view oi_OITraceCode_cpp; extern const std::string_view oi_types_st_h; extern const std::string_view oi_types_dy_h; -} // namespace headers -} // namespace ObjectIntrospection +} // namespace oi::detail::headers diff --git a/oi/Metrics.cpp b/oi/Metrics.cpp index 358a1e3..975affa 100644 --- a/oi/Metrics.cpp +++ b/oi/Metrics.cpp @@ -29,7 +29,7 @@ * * You can instrument some code with: * ``` - * auto t = Metrics::Tracing("name_of_your_trace"); + * auto t = metrics::Tracing("name_of_your_trace"); * [... some code ...] * t.stop(); * ``` @@ -40,13 +40,13 @@ * Alternatively, you can use automatically deal with this in every return * point thanks to C++'s RAII: * ``` - * Metrics::Tracing unused_var("name_of_your_trace"); + * metrics::Tracing unused_var("name_of_your_trace"); * ``` * * When you want to collect the data, `::showTraces()` to print the data to * stdout, and `::saveTraces(file)` to save it to disk using JSON. */ -namespace ObjectIntrospection::Metrics { +namespace oi::detail::metrics { static inline TraceFlags parseTraceFlags(const char* flags) { if (flags == nullptr) { @@ -204,4 +204,4 @@ std::ostream& operator<<(std::ostream& out, const std::vector& spans) { return out; } -} // namespace ObjectIntrospection::Metrics +} // namespace oi::detail::metrics diff --git a/oi/Metrics.h b/oi/Metrics.h index f1a0452..ca7a830 100644 --- a/oi/Metrics.h +++ b/oi/Metrics.h @@ -22,7 +22,7 @@ #include #include -namespace ObjectIntrospection::Metrics { +namespace oi::detail::metrics { constexpr auto traceEnvKey = "OID_METRICS_TRACE"; constexpr auto outputEnvKey = "OID_METRICS_OUTPUT"; @@ -75,9 +75,9 @@ class Tracing final { public: /* - * Metrics::Tracing("bad"); + * metrics::Tracing("bad"); * - * Usage is Metrics::Tracing __varname_(...) The code above is an improper + * Usage is metrics::Tracing __varname_(...) The code above is an improper * use of the Tracing library. The tracing object above is not stored in a * variable. So it is immediately destroyed and won't record the expected * results. [[nodiscard]] flags the code above with a warning, which we @@ -170,4 +170,4 @@ std::ostream& operator<<(std::ostream&, const TraceFlags&); std::ostream& operator<<(std::ostream&, const Span&); std::ostream& operator<<(std::ostream&, const std::vector&); -} // namespace ObjectIntrospection::Metrics +} // namespace oi::detail::metrics diff --git a/oi/OICache.cpp b/oi/OICache.cpp index befde8f..4d80938 100644 --- a/oi/OICache.cpp +++ b/oi/OICache.cpp @@ -30,6 +30,8 @@ #include "cea/object-introspection/internal/ManifoldCache.h" #endif +namespace oi::detail { + static std::optional> getEntName( SymbolService& symbols, const irequest& req, OICache::Entity ent) { if (ent == OICache::Entity::FuncDescs || @@ -250,3 +252,5 @@ std::string OICache::generateRemoteHash(const irequest& req) { LOG(INFO) << "generating remote hash from: " << remote_cache_id; return std::to_string(std::hash{}(remote_cache_id)); } + +} // namespace oi::detail diff --git a/oi/OICache.h b/oi/OICache.h index c63e967..6f8a1d4 100644 --- a/oi/OICache.h +++ b/oi/OICache.h @@ -24,7 +24,7 @@ #include "oi/OIParser.h" #include "oi/SymbolService.h" -namespace fs = std::filesystem; +namespace oi::detail { class OICache { public: @@ -32,7 +32,7 @@ class OICache { : generatorConfig(generatorConfig) { } - fs::path basePath{}; + std::filesystem::path basePath{}; std::shared_ptr symbols{}; bool downloadedRemote = false; bool enableUpload = false; @@ -60,7 +60,7 @@ class OICache { bool isEnabled() const { return !basePath.empty(); } - std::optional getPath(const irequest&, Entity) const; + std::optional getPath(const irequest&, Entity) const; template bool store(const irequest&, Entity, const T&); template @@ -72,3 +72,5 @@ class OICache { private: std::string generateRemoteHash(const irequest&); }; + +} // namespace oi::detail diff --git a/oi/OICodeGen.cpp b/oi/OICodeGen.cpp index d7653b2..e19eaaa 100644 --- a/oi/OICodeGen.cpp +++ b/oi/OICodeGen.cpp @@ -40,6 +40,8 @@ namespace fs = std::filesystem; +namespace oi::detail { + static size_t g_level = 0; #undef VLOG @@ -3773,3 +3775,5 @@ std::vector OICodeGen::Config::toOptions() const { void OICodeGen::initializeCodeGen() { LOG(WARNING) << "OICodeGen::initializeCodeGen is no longer necessary"; }; + +} // namespace oi::detail diff --git a/oi/OICodeGen.h b/oi/OICodeGen.h index 01cfcb6..534f2e4 100644 --- a/oi/OICodeGen.h +++ b/oi/OICodeGen.h @@ -23,7 +23,6 @@ #include #include -class SymbolService; struct irequest; #include "oi/ContainerInfo.h" @@ -36,8 +35,11 @@ extern "C" { #include } -using namespace ObjectIntrospection; -namespace fs = std::filesystem; +namespace oi::detail { +class SymbolService; +} + +namespace oi::detail { struct ParentMember { drgn_type* type; @@ -59,7 +61,7 @@ class OICodeGen { bool useDataSegment; FeatureSet features; - std::set containerConfigPaths; + std::set containerConfigPaths; std::set defaultHeaders; std::set defaultNamespaces; std::vector> membersToStub; @@ -360,3 +362,5 @@ class OICodeGen { std::vector& template_params_strings, const std::string& nameWithoutTemplate); }; + +} // namespace oi::detail diff --git a/oi/OICompiler.cpp b/oi/OICompiler.cpp index 705adb9..d866b3a 100644 --- a/oi/OICompiler.cpp +++ b/oi/OICompiler.cpp @@ -47,11 +47,12 @@ extern "C" { #include } +namespace oi::detail { + using namespace std; using namespace clang; using namespace llvm; using namespace llvm::object; -using namespace ObjectIntrospection; static const char* symbolLookupCallback( [[maybe_unused]] void* disInfo, @@ -467,7 +468,7 @@ static void debugDisAsm( bool OICompiler::compile(const std::string& code, const fs::path& sourcePath, const fs::path& objectPath) { - Metrics::Tracing _("compile"); + metrics::Tracing _("compile"); /* * Note to whoever: if you're having problems compiling code, especially @@ -588,7 +589,7 @@ std::optional OICompiler::applyRelocs( uintptr_t baseRelocAddress, const std::set& objectFiles, const std::unordered_map& syntheticSymbols) { - Metrics::Tracing relocationTracing("relocation"); + metrics::Tracing relocationTracing("relocation"); memMgr = std::make_unique(symbols, syntheticSymbols); RuntimeDyld dyld(*memMgr, *memMgr); @@ -666,3 +667,5 @@ std::optional OICompiler::applyRelocs( return res; } + +} // namespace oi::detail diff --git a/oi/OICompiler.h b/oi/OICompiler.h index 67dd260..e75518e 100644 --- a/oi/OICompiler.h +++ b/oi/OICompiler.h @@ -29,6 +29,8 @@ #include "oi/SymbolService.h" #include "oi/X86InstDefs.h" +namespace oi::detail { + namespace fs = std::filesystem; class OIMemoryManager; @@ -42,7 +44,7 @@ class OICompiler { public: /* Configuration option for `OICompiler` */ struct Config { - ObjectIntrospection::FeatureSet features; + FeatureSet features; std::vector userHeaderPaths{}; std::vector sysHeaderPaths{}; @@ -221,3 +223,5 @@ std::optional> OICompiler::locateOpcodes( return locs; } + +} // namespace oi::detail diff --git a/oi/OID.cpp b/oi/OID.cpp index 58d0053..9e16060 100644 --- a/oi/OID.cpp +++ b/oi/OID.cpp @@ -38,12 +38,11 @@ extern "C" { #include "oi/TimeUtils.h" #include "oi/TreeBuilder.h" +namespace oi::detail { + /* Global for signal handling */ std::weak_ptr weak_oid; -namespace fs = std::filesystem; -using namespace ObjectIntrospection; - // Using an enum inside a namespace here instead of an `enum class` because // enums defined via `enum class` aren't implicitly convertible to `int`, and // having to cast the argument for each call to `exit` would be ugly. @@ -432,7 +431,7 @@ static ExitStatus::ExitStatus runScript( { // Resume stopped thread before cleanup VLOG(1) << "Resuming stopped threads..."; - Metrics::Tracing __("resume_threads"); + metrics::Tracing __("resume_threads"); while (oid->processTrap(oidConfig.pid, false) == OIDebugger::OID_CONT) { } } @@ -457,7 +456,11 @@ static ExitStatus::ExitStatus runScript( return ExitStatus::Success; } +} // namespace oi::detail + int main(int argc, char* argv[]) { + using namespace oi::detail; + int debugLevel = 1; Oid::Config oidConfig = {}; std::string scriptFile; @@ -474,7 +477,7 @@ int main(int argc, char* argv[]) { bool logAllStructs = true; bool dumpDataSegment = false; - Metrics::Tracing _("main"); + metrics::Tracing _("main"); #ifndef OSS_ENABLE folly::InitOptions init; init.useGFlags(false); @@ -679,8 +682,8 @@ int main(int argc, char* argv[]) { .jsonPath = jsonPath, }; - auto featureSet = OIUtils::processConfigFile(oidConfig.configFile, features, - compilerConfig, codeGenConfig); + auto featureSet = utils::processConfigFile(oidConfig.configFile, features, + compilerConfig, codeGenConfig); if (!featureSet) { return ExitStatus::UsageError; } @@ -708,11 +711,11 @@ int main(int argc, char* argv[]) { } } - if (Metrics::Tracing::isEnabled()) { - LOG(INFO) << "Will write metrics (" << Metrics::Tracing::isEnabled() - << ") in " << Metrics::Tracing::outputPath(); + if (metrics::Tracing::isEnabled()) { + LOG(INFO) << "Will write metrics (" << metrics::Tracing::isEnabled() + << ") in " << metrics::Tracing::outputPath(); } else { - LOG(INFO) << "Will not write any metric: " << Metrics::Tracing::isEnabled(); + LOG(INFO) << "Will not write any metric: " << metrics::Tracing::isEnabled(); } return ExitStatus::Success; diff --git a/oi/OIDebugger.cpp b/oi/OIDebugger.cpp index 4a4088a..8d9e87c 100644 --- a/oi/OIDebugger.cpp +++ b/oi/OIDebugger.cpp @@ -60,7 +60,8 @@ extern "C" { #endif using namespace std; -using namespace ObjectIntrospection; + +namespace oi::detail { constexpr int oidMagicId = 0x01DE8; @@ -70,7 +71,7 @@ bool OIDebugger::isGlobalDataProbeEnabled(void) const { } bool OIDebugger::parseScript(std::istream& script) { - Metrics::Tracing _("parse_script"); + metrics::Tracing _("parse_script"); OIScanner scanner(&script); OIParser parser(scanner, pdata); @@ -96,7 +97,7 @@ bool OIDebugger::parseScript(std::istream& script) { bool OIDebugger::patchFunctions(void) { assert(pdata.numReqs() != 0); - Metrics::Tracing _("patch_functions"); + metrics::Tracing _("patch_functions"); for (const auto& preq : pdata) { VLOG(1) << "Type " << preq.type << " Func " << preq.func @@ -126,7 +127,7 @@ bool OIDebugger::patchFunctions(void) { uint64_t OIDebugger::singlestepInst(pid_t pid, struct user_regs_struct& regs) { int status = 0; - Metrics::Tracing _("single_step_inst"); + metrics::Tracing _("single_step_inst"); if (ptrace(PTRACE_SINGLESTEP, pid, 0, 0) == -1) { LOG(ERROR) << "Error in singlestep!"; @@ -740,7 +741,7 @@ OIDebugger::processTrapRet OIDebugger::processJitCodeRet( auto t{iter->second}; t->lifetime.stop(); - auto jitTrapProcessTime = Metrics::Tracing("jit_ret"); + auto jitTrapProcessTime = metrics::Tracing("jit_ret"); VLOG(4) << "Hit the return path from vector. Redirect to " << std::hex << t->trapAddr; @@ -1526,7 +1527,7 @@ std::optional OIDebugger::remoteSyscall(Args... _args) { static_assert(sizeof...(_args) == Sys::ArgsCount, "Wrong number of arguments"); - Metrics::Tracing _("syscall"); + metrics::Tracing _("syscall"); VLOG(1) << "syscall enter " << Sys::Name; auto sym = symbols->locateSymbol("main"); @@ -1675,7 +1676,7 @@ std::optional OIDebugger::remoteSyscall(Args... _args) { } bool OIDebugger::setupSegment(SegType seg) { - Metrics::Tracing _("setup_segment"); + metrics::Tracing _("setup_segment"); std::optional segAddr; if (seg == SegType::text) { @@ -1717,7 +1718,7 @@ bool OIDebugger::setupSegment(SegType seg) { } bool OIDebugger::unmapSegment(SegType seg) { - Metrics::Tracing _("unmap_segment"); + metrics::Tracing _("unmap_segment"); auto addr = (seg == SegType::text) ? segConfig.textSegBase : segConfig.dataSegBase; auto size = (seg == SegType::text) ? textSegSize : dataSegSize; @@ -1762,7 +1763,7 @@ bool OIDebugger::unmapSegments(bool deleteSegConfFile) { * Unfortunately there is no cheap way to assert this. */ bool OIDebugger::removeTraps(pid_t pid) { - Metrics::Tracing removeTrapsTracing("remove_traps"); + metrics::Tracing removeTrapsTracing("remove_traps"); pid_t targetPid = pid ? pid : traceePid; @@ -2333,7 +2334,7 @@ void OIDebugger::restoreState(void) { << activeTrapsCount; assert(activeTrapsCount == 0); - Metrics::Tracing _("restore_state"); + metrics::Tracing _("restore_state"); int status = 0; @@ -2775,7 +2776,7 @@ static bool dumpDataSegment(const irequest& req, } bool OIDebugger::processTargetData() { - Metrics::Tracing _("process_target_data"); + metrics::Tracing _("process_target_data"); std::vector buf{dataSegSize}; if (!readTargetMemory(reinterpret_cast(segConfig.dataSegBase), @@ -2928,3 +2929,5 @@ std::optional OIDebugger::generateCode(const irequest& req) { return code; } + +} // namespace oi::detail diff --git a/oi/OIDebugger.h b/oi/OIDebugger.h index aba353e..934e9f3 100644 --- a/oi/OIDebugger.h +++ b/oi/OIDebugger.h @@ -29,7 +29,7 @@ #include "oi/TreeBuilder.h" #include "oi/X86InstDefs.h" -namespace fs = std::filesystem; +namespace oi::detail { class OIDebugger { OIDebugger(const OICodeGen::Config&, OICompiler::Config, TreeBuilder::Config); @@ -39,7 +39,7 @@ class OIDebugger { const OICodeGen::Config&, OICompiler::Config, TreeBuilder::Config); - OIDebugger(fs::path, + OIDebugger(std::filesystem::path, const OICodeGen::Config&, OICompiler::Config, TreeBuilder::Config); @@ -77,11 +77,12 @@ class OIDebugger { return oidShouldExit; }; - void setCacheBasePath(fs::path basePath) { - if (fs::exists(basePath.parent_path()) && !fs::exists(basePath)) { + void setCacheBasePath(std::filesystem::path basePath) { + if (std::filesystem::exists(basePath.parent_path()) && + !std::filesystem::exists(basePath)) { // Create cachedir if parent directory exists // TODO if returning false here, throw an error - fs::create_directory(basePath); + std::filesystem::create_directory(basePath); } cache.basePath = std::move(basePath); } @@ -140,7 +141,7 @@ class OIDebugger { return std::get<2>(typeInfos.at(pdata.getReq().getReqForArg())); } - void setCustomCodeFile(fs::path newCCT) { + void setCustomCodeFile(std::filesystem::path newCCT) { customCodeFile = std::move(newCCT); } @@ -243,8 +244,8 @@ class OIDebugger { std::optional generateCode(const irequest&); std::fstream segmentConfigFile; - fs::path segConfigFilePath; - fs::path customCodeFile; + std::filesystem::path segConfigFilePath; + std::filesystem::path customCodeFile; struct c { uintptr_t textSegBase{}; @@ -293,3 +294,5 @@ class OIDebugger { static constexpr size_t prologueLength = 64; static constexpr size_t constLength = 64; }; + +} // namespace oi::detail diff --git a/oi/OIGenerator.cpp b/oi/OIGenerator.cpp index 4f26867..a9e4d5d 100644 --- a/oi/OIGenerator.cpp +++ b/oi/OIGenerator.cpp @@ -28,7 +28,7 @@ #include "oi/Headers.h" #include "oi/OIUtils.h" -namespace ObjectIntrospection { +namespace oi::detail { std::unordered_map OIGenerator::oilStrongToWeakSymbolsMap(drgnplusplus::program& prog) { @@ -191,8 +191,8 @@ int OIGenerator::generate(fs::path& primaryObject, SymbolService& symbols) { OICodeGen::Config generatorConfig{}; OICompiler::Config compilerConfig{}; - auto features = OIUtils::processConfigFile(configFilePath, featuresMap, - compilerConfig, generatorConfig); + auto features = utils::processConfigFile(configFilePath, featuresMap, + compilerConfig, generatorConfig); if (!features) { LOG(ERROR) << "failed to process config file"; return -1; @@ -223,4 +223,4 @@ int OIGenerator::generate(fs::path& primaryObject, SymbolService& symbols) { return 0; } -} // namespace ObjectIntrospection +} // namespace oi::detail diff --git a/oi/OIGenerator.h b/oi/OIGenerator.h index 5d29e95..9c6934b 100644 --- a/oi/OIGenerator.h +++ b/oi/OIGenerator.h @@ -22,7 +22,7 @@ #include "oi/OICodeGen.h" #include "oi/OICompiler.h" -namespace ObjectIntrospection { +namespace oi::detail { class OIGenerator { public: @@ -61,4 +61,4 @@ class OIGenerator { SymbolService& symbols); }; -} // namespace ObjectIntrospection +} // namespace oi::detail diff --git a/oi/OILexer.h b/oi/OILexer.h index e28dd2f..adcc216 100644 --- a/oi/OILexer.h +++ b/oi/OILexer.h @@ -27,7 +27,7 @@ #include "OIParser.tab.hh" #include "location.hh" -namespace ObjectIntrospection { +namespace oi::detail { class OIScanner : public yyFlexLexer { public: @@ -48,4 +48,4 @@ class OIScanner : public yyFlexLexer { OIParser::semantic_type* yylval = nullptr; }; -} // namespace ObjectIntrospection +} // namespace oi::detail diff --git a/oi/OILexer.l b/oi/OILexer.l index cbdd421..de0504c 100644 --- a/oi/OILexer.l +++ b/oi/OILexer.l @@ -21,11 +21,11 @@ #include "oi/OILexer.h" #undef YY_DECL #define YY_DECL \ - int ObjectIntrospection::OIScanner::yylex(ObjectIntrospection::OIParser::semantic_type * const lval, \ - ObjectIntrospection::OIParser::location_type *loc ) + int oi::detail::OIScanner::yylex(oi::detail::OIParser::semantic_type * const lval, \ + oi::detail::OIParser::location_type *loc ) /* typedef to make the returns for the tokens shorter */ -using token = ObjectIntrospection::OIParser::token; +using token = oi::detail::OIParser::token; /* update location on matching */ #define YY_USER_ACTION loc->step(); loc->columns(yyleng); @@ -33,7 +33,7 @@ using token = ObjectIntrospection::OIParser::token; %option debug %option nodefault -%option yyclass="ObjectIntrospection::OIScanner" +%option yyclass="oi::detail::OIScanner" %option noyywrap %option c++ @@ -90,7 +90,7 @@ using token = ObjectIntrospection::OIParser::token; <> { if (YYSTATE == COMMENT) { - throw ObjectIntrospection::OIParser::syntax_error( + throw oi::detail::OIParser::syntax_error( *loc, "unterminated /* comment"); } else { return( token::OI_EOF ); diff --git a/oi/OILibraryImpl.cpp b/oi/OILibraryImpl.cpp index be7203e..7370ba1 100644 --- a/oi/OILibraryImpl.cpp +++ b/oi/OILibraryImpl.cpp @@ -35,6 +35,8 @@ extern "C" { namespace ObjectIntrospection { +using namespace oi::detail; + OILibraryImpl::OILibraryImpl(OILibrary* self, void* TemplateFunc) : _self(self), _TemplateFunc(TemplateFunc) { if (_self->opts.debugLevel != 0) { @@ -84,7 +86,7 @@ void OILibraryImpl::initCompiler() { } bool OILibraryImpl::processConfigFile() { - auto features = OIUtils::processConfigFile( + auto features = utils::processConfigFile( _self->opts.configFilePath, { {Feature::ChaseRawPointers, _self->opts.chaseRawPointers}, diff --git a/oi/OILibraryImpl.h b/oi/OILibraryImpl.h index 8e99340..46af148 100644 --- a/oi/OILibraryImpl.h +++ b/oi/OILibraryImpl.h @@ -39,9 +39,9 @@ class OILibraryImpl { void* _TemplateFunc; - OICompiler::Config compilerConfig{}; - OICodeGen::Config generatorConfig{}; - std::shared_ptr symbols{}; + oi::detail::OICompiler::Config compilerConfig{}; + oi::detail::OICodeGen::Config generatorConfig{}; + std::shared_ptr symbols{}; struct c { void* textSegBase = nullptr; diff --git a/oi/OIParser.yy b/oi/OIParser.yy index 259d8fb..d361039 100644 --- a/oi/OIParser.yy +++ b/oi/OIParser.yy @@ -15,16 +15,16 @@ */ /* - * This is the bison grammar responsible for generating the ObjectIntrospection::OIParser class. - * This class gives us a number of things worth calling out here if only to - * remind me later :-): + * This is the bison grammar responsible for generating the oi::detail::OIParser + * class. This class gives us a number of things worth calling out here if only + * to remind me later :-): * * - A variant interface that replaces the C union interface for the * parsers semantic values. Enabled by setting 'api.value.type variant' below. */ %skeleton "lalr1.cc" %defines -%define api.namespace {ObjectIntrospection} +%define api.namespace {oi::detail} %define api.parser.class {OIParser} %define parse.trace %define parse.error verbose @@ -32,14 +32,14 @@ %code requires{ #include - namespace ObjectIntrospection { + namespace oi::detail { class OIScanner; } class ParseData; } /* - * ObjectIntrospection::OI_Parser constructor parameters. The scanner object is produced + * oi::detail::OIParser constructor parameters. The scanner object is produced * by flex and is derived from the yyFlexLexer class. The parser calls * its yylex() implementation to generate input tokens. The ParseData * object is spopulated by the lexer/parser introspection specifications @@ -100,7 +100,7 @@ oi_block: OI_PROBETYPE OI_COLON OI_FUNC OI_COLON oi_args void -ObjectIntrospection::OIParser::error(const location_type &l, const std::string &err_message) +oi::detail::OIParser::error(const location_type &l, const std::string &err_message) { LOG(ERROR) << "OI Parse Error: " << err_message << " at " << l; } diff --git a/oi/OIUtils.cpp b/oi/OIUtils.cpp index d718efa..30346c4 100644 --- a/oi/OIUtils.cpp +++ b/oi/OIUtils.cpp @@ -27,12 +27,11 @@ namespace fs = std::filesystem; -namespace OIUtils { +namespace oi::detail::utils { -using namespace ObjectIntrospection; using namespace std::literals; -std::optional processConfigFile( +std::optional processConfigFile( const std::string& configFilePath, std::map featureMap, OICompiler::Config& compilerConfig, @@ -173,7 +172,7 @@ std::optional processConfigFile( } } - ObjectIntrospection::FeatureSet featuresSet; + FeatureSet featuresSet; for (auto [k, v] : featureMap) { if (v) { featuresSet[k] = true; @@ -208,4 +207,4 @@ std::optional processConfigFile( return featuresSet; } -} // namespace OIUtils +} // namespace oi::detail::utils diff --git a/oi/OIUtils.h b/oi/OIUtils.h index 1d0f068..76ce8e2 100644 --- a/oi/OIUtils.h +++ b/oi/OIUtils.h @@ -22,12 +22,11 @@ #include "oi/OICodeGen.h" #include "oi/OICompiler.h" -namespace OIUtils { +namespace oi::detail::utils { -std::optional processConfigFile( - const std::string& configFilePath, - std::map featureMap, - OICompiler::Config& compilerConfig, - OICodeGen::Config& generatorConfig); +std::optional processConfigFile(const std::string& configFilePath, + std::map featureMap, + OICompiler::Config& compilerConfig, + OICodeGen::Config& generatorConfig); -} // namespace OIUtils +} // namespace oi::detail::utils diff --git a/oi/SymbolService.cpp b/oi/SymbolService.cpp index f7ea362..514d4ee 100644 --- a/oi/SymbolService.cpp +++ b/oi/SymbolService.cpp @@ -34,6 +34,10 @@ extern "C" { #include "dwarf.h" } +namespace fs = std::filesystem; + +namespace oi::detail { + template struct visitor : Ts... { using Ts::operator()...; @@ -885,3 +889,5 @@ std::optional SymbolService::getRootType(const irequest& req) { return RootInfo{paramName, paramType}; } + +} // namespace oi::detail diff --git a/oi/SymbolService.h b/oi/SymbolService.h index 0be3113..b741098 100644 --- a/oi/SymbolService.h +++ b/oi/SymbolService.h @@ -26,12 +26,12 @@ #include "oi/Descs.h" #include "oi/TypeHierarchy.h" -namespace fs = std::filesystem; - struct Dwfl; struct drgn_program; struct irequest; +namespace oi::detail { + struct SymbolInfo { uint64_t addr; uint64_t size; @@ -40,7 +40,7 @@ struct SymbolInfo { class SymbolService { public: SymbolService(pid_t); - SymbolService(fs::path); + SymbolService(std::filesystem::path); SymbolService(const SymbolService&) = delete; SymbolService& operator=(const SymbolService&) = delete; ~SymbolService(); @@ -64,13 +64,13 @@ class SymbolService { } private: - std::variant target; + std::variant target; struct Dwfl* dwfl{nullptr}; struct drgn_program* prog{nullptr}; bool loadModules(); bool loadModulesFromPid(pid_t); - bool loadModulesFromPath(const fs::path&); + bool loadModulesFromPath(const std::filesystem::path&); std::vector> executableAddrs{}; bool hardDisableDrgn = false; @@ -78,3 +78,5 @@ class SymbolService { protected: SymbolService() = default; // For unit tests }; + +} // namespace oi::detail diff --git a/oi/TrapInfo.h b/oi/TrapInfo.h index 85a3d47..00841d2 100644 --- a/oi/TrapInfo.h +++ b/oi/TrapInfo.h @@ -25,6 +25,8 @@ extern "C" { #include } +namespace oi::detail { + /* * Breakpoint traps (INT3) instructions are the primary mechanism used to * transfer control from the traced process to the debugger. There are several @@ -114,7 +116,7 @@ class trapInfo { */ uintptr_t replayInstAddr{}; - ObjectIntrospection::Metrics::Tracing lifetime{"trap"}; + metrics::Tracing lifetime{"trap"}; trapInfo() = default; trapInfo(trapType t, uint64_t ta, uint64_t po = 0, bool fv = false) @@ -132,3 +134,5 @@ inline std::ostream& operator<<(std::ostream& out, const trapInfo& t) { return out << "Trap " << trapTypeDescs[t.trapKind] << " @" << (void*)t.trapAddr; } + +} // namespace oi::detail diff --git a/oi/TreeBuilder.cpp b/oi/TreeBuilder.cpp index 7caf9bd..5fe924e 100644 --- a/oi/TreeBuilder.cpp +++ b/oi/TreeBuilder.cpp @@ -39,6 +39,8 @@ extern "C" { #include } +namespace oi::detail { + /* Tag indicating if the pointer has been followed or skipped */ enum class TrackPointerTag : uint64_t { /* The content has been skipped. @@ -229,7 +231,7 @@ void TreeBuilder::build(const std::vector& data, oidDataIndex = 4; // HACK: OID's first 4 outputs are dummy 0s - ObjectIntrospection::Metrics::Tracing _("build_tree"); + metrics::Tracing _("build_tree"); VLOG(1) << "Building tree..."; { @@ -971,3 +973,5 @@ void TreeBuilder::JSON(NodeID id, std::ofstream& output) { } output << "}"; } + +} // namespace oi::detail diff --git a/oi/TreeBuilder.h b/oi/TreeBuilder.h index 05da4d9..a5a959e 100644 --- a/oi/TreeBuilder.h +++ b/oi/TreeBuilder.h @@ -36,12 +36,14 @@ class DB; // Forward declared, comes from PaddingInfo.h struct PaddingInfo; +namespace oi::detail { + class TreeBuilder { public: struct Config { // Don't set default values for the config so the user gets // an "unitialized field" warning if he missed any. - ObjectIntrospection::FeatureSet features; + FeatureSet features; bool logAllStructs; bool dumpDataSegment; std::optional jsonPath; @@ -118,3 +120,5 @@ class TreeBuilder { uint64_t dynamicSize, uint64_t memberSizes); }; + +} // namespace oi::detail diff --git a/oi/exporters/TypeCheckingWalker.cpp b/oi/exporters/TypeCheckingWalker.cpp index 3fbfa01..8467f52 100644 --- a/oi/exporters/TypeCheckingWalker.cpp +++ b/oi/exporters/TypeCheckingWalker.cpp @@ -20,8 +20,7 @@ template inline constexpr bool always_false_v = false; -namespace ObjectIntrospection { -namespace exporters { +namespace oi::detail::exporters { std::optional TypeCheckingWalker::advance() { if (stack.empty()) { @@ -76,5 +75,4 @@ std::optional TypeCheckingWalker::advance() { el); } -} // namespace exporters -} // namespace ObjectIntrospection +} // namespace oi::detail::exporters diff --git a/oi/exporters/TypeCheckingWalker.h b/oi/exporters/TypeCheckingWalker.h index 320a298..2e27009 100644 --- a/oi/exporters/TypeCheckingWalker.h +++ b/oi/exporters/TypeCheckingWalker.h @@ -36,8 +36,7 @@ #include "oi/types/dy.h" -namespace ObjectIntrospection { -namespace exporters { +namespace oi::detail::exporters { class TypeCheckingWalker { public: @@ -74,5 +73,4 @@ class TypeCheckingWalker { } }; -} // namespace exporters -} // namespace ObjectIntrospection +} // namespace oi::detail::exporters diff --git a/oi/exporters/test/TypeCheckingWalkerTest.cpp b/oi/exporters/test/TypeCheckingWalkerTest.cpp index 698472f..3383c82 100644 --- a/oi/exporters/test/TypeCheckingWalkerTest.cpp +++ b/oi/exporters/test/TypeCheckingWalkerTest.cpp @@ -2,8 +2,8 @@ #include "oi/exporters/TypeCheckingWalker.h" -using namespace ObjectIntrospection; -using exporters::TypeCheckingWalker; +using namespace oi; +using oi::detail::exporters::TypeCheckingWalker; TEST(TypeCheckingWalker, TestUnit) { // ASSIGN diff --git a/oi/type_graph/AddChildren.cpp b/oi/type_graph/AddChildren.cpp index ceddee1..91dd17b 100644 --- a/oi/type_graph/AddChildren.cpp +++ b/oi/type_graph/AddChildren.cpp @@ -29,7 +29,7 @@ extern "C" { template using ref = std::reference_wrapper; -namespace type_graph { +namespace oi::detail::type_graph { Pass AddChildren::createPass(DrgnParser& drgnParser, SymbolService& symbols) { auto fn = [&drgnParser, &symbols](TypeGraph& typeGraph) { @@ -202,4 +202,4 @@ void AddChildren::enumerateChildClasses(SymbolService& symbols) { drgn_type_iterator_destroy(typesIterator); } -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/AddChildren.h b/oi/type_graph/AddChildren.h index a7ae793..963d7de 100644 --- a/oi/type_graph/AddChildren.h +++ b/oi/type_graph/AddChildren.h @@ -23,10 +23,12 @@ #include "Types.h" #include "Visitor.h" -class SymbolService; struct drgn_type; +namespace oi::detail { +class SymbolService; +} -namespace type_graph { +namespace oi::detail::type_graph { class DrgnParser; class TypeGraph; @@ -74,4 +76,4 @@ class AddChildren final : public RecursiveVisitor { std::unordered_map> childClasses_; }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/AddPadding.cpp b/oi/type_graph/AddPadding.cpp index ac87aed..2c4a7c8 100644 --- a/oi/type_graph/AddPadding.cpp +++ b/oi/type_graph/AddPadding.cpp @@ -22,7 +22,7 @@ template using ref = std::reference_wrapper; -namespace type_graph { +namespace oi::detail::type_graph { Pass AddPadding::createPass() { auto fn = [](TypeGraph& typeGraph) { @@ -135,4 +135,4 @@ void AddPadding::addPadding(uint64_t paddingStartBits, } } -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/AddPadding.h b/oi/type_graph/AddPadding.h index 000aa7e..bff64c1 100644 --- a/oi/type_graph/AddPadding.h +++ b/oi/type_graph/AddPadding.h @@ -22,7 +22,7 @@ #include "Types.h" #include "Visitor.h" -namespace type_graph { +namespace oi::detail::type_graph { class TypeGraph; @@ -59,4 +59,4 @@ class AddPadding final : public RecursiveVisitor { std::vector& paddedMembers); }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/AlignmentCalc.cpp b/oi/type_graph/AlignmentCalc.cpp index facba09..4f3643d 100644 --- a/oi/type_graph/AlignmentCalc.cpp +++ b/oi/type_graph/AlignmentCalc.cpp @@ -22,7 +22,7 @@ template using ref = std::reference_wrapper; -namespace type_graph { +namespace oi::detail::type_graph { Pass AlignmentCalc::createPass() { auto fn = [](TypeGraph& typeGraph) { @@ -76,4 +76,4 @@ void AlignmentCalc::visit(Class& c) { } } -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/AlignmentCalc.h b/oi/type_graph/AlignmentCalc.h index 8f18d61..4949341 100644 --- a/oi/type_graph/AlignmentCalc.h +++ b/oi/type_graph/AlignmentCalc.h @@ -23,7 +23,7 @@ #include "Types.h" #include "Visitor.h" -namespace type_graph { +namespace oi::detail::type_graph { /* * AlignmentCalc @@ -46,4 +46,4 @@ class AlignmentCalc final : public RecursiveVisitor { std::unordered_set visited_; }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/DrgnParser.cpp b/oi/type_graph/DrgnParser.cpp index 0a6bfbd..2feeb15 100644 --- a/oi/type_graph/DrgnParser.cpp +++ b/oi/type_graph/DrgnParser.cpp @@ -27,7 +27,7 @@ extern "C" { #include -namespace type_graph { +namespace oi::detail::type_graph { namespace { uint64_t get_drgn_type_size(struct drgn_type* type) { @@ -499,4 +499,4 @@ DrgnParserError::~DrgnParserError() { drgn_error_destroy(err_); } -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/DrgnParser.h b/oi/type_graph/DrgnParser.h index 6dc9768..7c3605a 100644 --- a/oi/type_graph/DrgnParser.h +++ b/oi/type_graph/DrgnParser.h @@ -27,7 +27,7 @@ struct drgn_error; struct ContainerInfo; -namespace type_graph { +namespace oi::detail::type_graph { /* * DrgnParser @@ -110,4 +110,4 @@ class DrgnParserError : public std::runtime_error { struct drgn_error* err_ = nullptr; }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/EnforceCompatibility.cpp b/oi/type_graph/EnforceCompatibility.cpp index 8e55142..e5b64f2 100644 --- a/oi/type_graph/EnforceCompatibility.cpp +++ b/oi/type_graph/EnforceCompatibility.cpp @@ -24,7 +24,7 @@ #include "TypeIdentifier.h" #include "oi/OICodeGen.h" -namespace type_graph { +namespace oi::detail::type_graph { Pass EnforceCompatibility::createPass() { auto fn = [](TypeGraph& typeGraph) { @@ -78,4 +78,4 @@ void EnforceCompatibility::visit(Class& c) { }); } -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/EnforceCompatibility.h b/oi/type_graph/EnforceCompatibility.h index 826d7b7..45c22f9 100644 --- a/oi/type_graph/EnforceCompatibility.h +++ b/oi/type_graph/EnforceCompatibility.h @@ -22,7 +22,7 @@ #include "Types.h" #include "Visitor.h" -namespace type_graph { +namespace oi::detail::type_graph { /* * EnforceCompatibility @@ -46,4 +46,4 @@ class EnforceCompatibility : public RecursiveVisitor { NodeTracker& tracker_; }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/Flattener.cpp b/oi/type_graph/Flattener.cpp index bb2c00c..fd48112 100644 --- a/oi/type_graph/Flattener.cpp +++ b/oi/type_graph/Flattener.cpp @@ -18,7 +18,7 @@ #include "TypeGraph.h" #include "TypeIdentifier.h" -namespace type_graph { +namespace oi::detail::type_graph { Pass Flattener::createPass() { auto fn = [](TypeGraph& typeGraph) { @@ -212,4 +212,4 @@ void Flattener::visit(Container& c) { } } -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/Flattener.h b/oi/type_graph/Flattener.h index 997cdea..1d46f02 100644 --- a/oi/type_graph/Flattener.h +++ b/oi/type_graph/Flattener.h @@ -23,7 +23,7 @@ #include "Types.h" #include "Visitor.h" -namespace type_graph { +namespace oi::detail::type_graph { /* * Flattener @@ -52,4 +52,4 @@ class Flattener : public RecursiveVisitor { std::vector offset_stack_; }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/NameGen.cpp b/oi/type_graph/NameGen.cpp index 9123c82..eec1efc 100644 --- a/oi/type_graph/NameGen.cpp +++ b/oi/type_graph/NameGen.cpp @@ -20,7 +20,7 @@ template using ref = std::reference_wrapper; -namespace type_graph { +namespace oi::detail::type_graph { Pass NameGen::createPass() { auto fn = [](TypeGraph& typeGraph) { @@ -152,4 +152,4 @@ void NameGen::visit(Typedef& td) { accept(td.underlyingType()); } -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/NameGen.h b/oi/type_graph/NameGen.h index 8e952de..2810b79 100644 --- a/oi/type_graph/NameGen.h +++ b/oi/type_graph/NameGen.h @@ -24,7 +24,7 @@ #include "Types.h" #include "Visitor.h" -namespace type_graph { +namespace oi::detail::type_graph { // TODO make all final /* @@ -55,4 +55,4 @@ class NameGen final : public RecursiveVisitor { int n = 0; }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/NodeTracker.h b/oi/type_graph/NodeTracker.h index 89a52d8..9c3a030 100644 --- a/oi/type_graph/NodeTracker.h +++ b/oi/type_graph/NodeTracker.h @@ -19,7 +19,7 @@ #include "Types.h" -namespace type_graph { +namespace oi::detail::type_graph { /* * NodeTracker @@ -67,4 +67,4 @@ class NodeTracker { std::vector visited_; }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/PassManager.cpp b/oi/type_graph/PassManager.cpp index 5f8f5b4..6b63f7f 100644 --- a/oi/type_graph/PassManager.cpp +++ b/oi/type_graph/PassManager.cpp @@ -26,7 +26,7 @@ template using ref = std::reference_wrapper; -namespace type_graph { +namespace oi::detail::type_graph { void Pass::run(TypeGraph& typeGraph) { fn_(typeGraph); @@ -72,4 +72,4 @@ void PassManager::run(TypeGraph& typeGraph) { } } -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/PassManager.h b/oi/type_graph/PassManager.h index 7129ead..5183d94 100644 --- a/oi/type_graph/PassManager.h +++ b/oi/type_graph/PassManager.h @@ -19,7 +19,7 @@ #include #include -namespace type_graph { +namespace oi::detail::type_graph { class TypeGraph; class Type; @@ -59,4 +59,4 @@ class PassManager { std::vector passes_; }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/Printer.cpp b/oi/type_graph/Printer.cpp index 125b446..a277d00 100644 --- a/oi/type_graph/Printer.cpp +++ b/oi/type_graph/Printer.cpp @@ -17,7 +17,7 @@ #include -namespace type_graph { +namespace oi::detail::type_graph { Printer::Printer(std::ostream& out, size_t numTypes) : out_(out) { if (numTypes == 0) { @@ -236,4 +236,4 @@ std::string Printer::align_str(uint64_t align) { return ", align: " + std::to_string(align); } -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/Printer.h b/oi/type_graph/Printer.h index 36723f5..82f911d 100644 --- a/oi/type_graph/Printer.h +++ b/oi/type_graph/Printer.h @@ -21,7 +21,7 @@ #include "Types.h" #include "Visitor.h" -namespace type_graph { +namespace oi::detail::type_graph { /* * Printer @@ -60,4 +60,4 @@ class Printer : public ConstVisitor { std::unordered_map nodeNums_; }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/Prune.cpp b/oi/type_graph/Prune.cpp index d2535a5..5d5db80 100644 --- a/oi/type_graph/Prune.cpp +++ b/oi/type_graph/Prune.cpp @@ -18,7 +18,7 @@ #include "TypeGraph.h" #include "TypeIdentifier.h" -namespace type_graph { +namespace oi::detail::type_graph { Pass Prune::createPass() { auto fn = [](TypeGraph& typeGraph) { @@ -62,4 +62,4 @@ void Prune::visit(Class& c) { c.functions.shrink_to_fit(); } -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/Prune.h b/oi/type_graph/Prune.h index f6ac0ae..d444ea3 100644 --- a/oi/type_graph/Prune.h +++ b/oi/type_graph/Prune.h @@ -23,7 +23,7 @@ #include "Types.h" #include "Visitor.h" -namespace type_graph { +namespace oi::detail::type_graph { /* * Prune @@ -48,4 +48,4 @@ class Prune : public RecursiveVisitor { NodeTracker& tracker_; }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/RemoveMembers.cpp b/oi/type_graph/RemoveMembers.cpp index 9723d57..e5e4eb3 100644 --- a/oi/type_graph/RemoveMembers.cpp +++ b/oi/type_graph/RemoveMembers.cpp @@ -18,7 +18,7 @@ #include "AddPadding.h" #include "TypeGraph.h" -namespace type_graph { +namespace oi::detail::type_graph { Pass RemoveMembers::createPass( const std::vector>& membersToIgnore) { @@ -75,4 +75,4 @@ bool RemoveMembers::ignoreMember(const std::string& typeName, return false; } -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/RemoveMembers.h b/oi/type_graph/RemoveMembers.h index 0139be4..caed359 100644 --- a/oi/type_graph/RemoveMembers.h +++ b/oi/type_graph/RemoveMembers.h @@ -21,7 +21,7 @@ #include "Types.h" #include "Visitor.h" -namespace type_graph { +namespace oi::detail::type_graph { /* * RemoveMembers @@ -54,4 +54,4 @@ class RemoveMembers : public RecursiveVisitor { const std::vector>& membersToIgnore_; }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/RemoveTopLevelPointer.cpp b/oi/type_graph/RemoveTopLevelPointer.cpp index d2dc4b2..07a2ecd 100644 --- a/oi/type_graph/RemoveTopLevelPointer.cpp +++ b/oi/type_graph/RemoveTopLevelPointer.cpp @@ -17,7 +17,7 @@ #include "TypeGraph.h" -namespace type_graph { +namespace oi::detail::type_graph { Pass RemoveTopLevelPointer::createPass() { auto fn = [](TypeGraph& typeGraph) { @@ -42,4 +42,4 @@ void RemoveTopLevelPointer::visit(Pointer& p) { topLevelType_ = &p.pointeeType(); } -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/RemoveTopLevelPointer.h b/oi/type_graph/RemoveTopLevelPointer.h index a4cf482..611429f 100644 --- a/oi/type_graph/RemoveTopLevelPointer.h +++ b/oi/type_graph/RemoveTopLevelPointer.h @@ -22,7 +22,7 @@ #include "Types.h" #include "Visitor.h" -namespace type_graph { +namespace oi::detail::type_graph { /* * RemoveTopLevelPointer @@ -41,4 +41,4 @@ class RemoveTopLevelPointer : public LazyVisitor { Type* topLevelType_ = nullptr; }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/TopoSorter.cpp b/oi/type_graph/TopoSorter.cpp index 29df405..57f9121 100644 --- a/oi/type_graph/TopoSorter.cpp +++ b/oi/type_graph/TopoSorter.cpp @@ -20,7 +20,7 @@ template using ref = std::reference_wrapper; -namespace type_graph { +namespace oi::detail::type_graph { Pass TopoSorter::createPass() { auto fn = [](TypeGraph& typeGraph) { @@ -148,4 +148,4 @@ void TopoSorter::acceptAfter(Type* type) { } } -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/TopoSorter.h b/oi/type_graph/TopoSorter.h index f17b12d..d8088c0 100644 --- a/oi/type_graph/TopoSorter.h +++ b/oi/type_graph/TopoSorter.h @@ -23,7 +23,7 @@ #include "Types.h" #include "Visitor.h" -namespace type_graph { +namespace oi::detail::type_graph { /* * TopoSorter @@ -56,4 +56,4 @@ class TopoSorter : public RecursiveVisitor { void acceptAfter(Type* type); }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/TypeGraph.cpp b/oi/type_graph/TypeGraph.cpp index d13e19d..ba7a9b0 100644 --- a/oi/type_graph/TypeGraph.cpp +++ b/oi/type_graph/TypeGraph.cpp @@ -15,7 +15,7 @@ */ #include "TypeGraph.h" -namespace type_graph { +namespace oi::detail::type_graph { NodeTracker& TypeGraph::resetTracker() noexcept { tracker_.reset(); @@ -74,4 +74,4 @@ Primitive& TypeGraph::makeType(Primitive::Kind kind) { } } -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/TypeGraph.h b/oi/type_graph/TypeGraph.h index 34856d2..ec156eb 100644 --- a/oi/type_graph/TypeGraph.h +++ b/oi/type_graph/TypeGraph.h @@ -22,7 +22,7 @@ #include "NodeTracker.h" #include "Types.h" -namespace type_graph { +namespace oi::detail::type_graph { /* * TypeGraph @@ -91,4 +91,4 @@ class TypeGraph { NodeId next_id_ = 0; }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/TypeIdentifier.cpp b/oi/type_graph/TypeIdentifier.cpp index 0982d03..8fb297f 100644 --- a/oi/type_graph/TypeIdentifier.cpp +++ b/oi/type_graph/TypeIdentifier.cpp @@ -18,7 +18,7 @@ #include "TypeGraph.h" #include "oi/ContainerInfo.h" -namespace type_graph { +namespace oi::detail::type_graph { Pass TypeIdentifier::createPass( const std::vector& passThroughTypes) { @@ -115,4 +115,4 @@ void TypeIdentifier::visit(Container& c) { } } -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/TypeIdentifier.h b/oi/type_graph/TypeIdentifier.h index e451996..218816c 100644 --- a/oi/type_graph/TypeIdentifier.h +++ b/oi/type_graph/TypeIdentifier.h @@ -23,7 +23,7 @@ #include "Visitor.h" #include "oi/ContainerInfo.h" -namespace type_graph { +namespace oi::detail::type_graph { class TypeGraph; @@ -56,4 +56,4 @@ class TypeIdentifier : public RecursiveVisitor { const std::vector& passThroughTypes_; }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/Types.cpp b/oi/type_graph/Types.cpp index f76758d..af34157 100644 --- a/oi/type_graph/Types.cpp +++ b/oi/type_graph/Types.cpp @@ -17,7 +17,7 @@ #include "Visitor.h" -namespace type_graph { +namespace oi::detail::type_graph { #define X(OI_TYPE_NAME) \ void OI_TYPE_NAME::accept(Visitor& v) { \ @@ -131,4 +131,4 @@ Type& stripTypedefs(Type& type) { return *t; } -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/type_graph/Types.h b/oi/type_graph/Types.h index 94347bd..4c7a3d2 100644 --- a/oi/type_graph/Types.h +++ b/oi/type_graph/Types.h @@ -50,7 +50,7 @@ struct ContainerInfo; -namespace type_graph { +namespace oi::detail::type_graph { // Must be signed. "-1" represents "leaf node" using NodeId = int32_t; @@ -589,6 +589,6 @@ class DummyAllocator : public Type { Type& stripTypedefs(Type& type); -} // namespace type_graph +} // namespace oi::detail::type_graph #undef DECLARE_ACCEPT diff --git a/oi/type_graph/Visitor.h b/oi/type_graph/Visitor.h index 8fefa6e..78ad193 100644 --- a/oi/type_graph/Visitor.h +++ b/oi/type_graph/Visitor.h @@ -26,7 +26,7 @@ #include "Types.h" -namespace type_graph { +namespace oi::detail::type_graph { /* * Visitor @@ -145,4 +145,4 @@ class LazyConstVisitor : public ConstVisitor { #undef X }; -} // namespace type_graph +} // namespace oi::detail::type_graph diff --git a/oi/types/test/StaticTest.cpp b/oi/types/test/StaticTest.cpp index 1db0689..a68ab37 100644 --- a/oi/types/test/StaticTest.cpp +++ b/oi/types/test/StaticTest.cpp @@ -4,7 +4,7 @@ #include "oi/types/dy.h" #include "oi/types/st.h" -using namespace ObjectIntrospection; +using namespace oi; class DummyDataBuffer {}; diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt index 4c5a803..2fc0df8 100644 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -4,8 +4,7 @@ target_include_directories(resources PRIVATE ../) function(embed_headers output) file(WRITE ${output} "#include \"oi/Headers.h\"\n\n") - file(APPEND ${output} "namespace ObjectIntrospection {\n") - file(APPEND ${output} "namespace headers {\n\n") + file(APPEND ${output} "namespace oi::detail::headers {\n") set(HEADERS ../include/oi/types/dy.h @@ -33,8 +32,7 @@ function(embed_headers output) file(APPEND ${output} "const std::string_view ${varname} = R\"CONTENTS(${contents})CONTENTS\";\n\n") endforeach() - file(APPEND ${output} "} // namespace headers\n") - file(APPEND ${output} "} // namespace ObjectIntrospection\n") + file(APPEND ${output} "} // namespace oi::detail::headers\n") endfunction() embed_headers(${CMAKE_BINARY_DIR}/resources/headers.cpp) diff --git a/test/TypeGraphParser.h b/test/TypeGraphParser.h index 5f590fb..626c4a4 100644 --- a/test/TypeGraphParser.h +++ b/test/TypeGraphParser.h @@ -5,11 +5,11 @@ #include "oi/type_graph/Types.h" -using namespace type_graph; - -namespace type_graph { +namespace oi::detail::type_graph { class TypeGraph; -} // namespace type_graph +} // namespace oi::detail::type_graph + +using namespace oi::detail::type_graph; /* * TypeGraphParser diff --git a/test/mocks.h b/test/mocks.h index 8c6ac49..e6b41fd 100644 --- a/test/mocks.h +++ b/test/mocks.h @@ -3,8 +3,12 @@ #include "gmock/gmock.h" #include "oi/SymbolService.h" +namespace oi::detail { + class MockSymbolService : public SymbolService { public: MockSymbolService() { } }; + +} // namespace oi::detail diff --git a/test/test_compiler.cpp b/test/test_compiler.cpp index 06beaea..3172fc6 100644 --- a/test/test_compiler.cpp +++ b/test/test_compiler.cpp @@ -9,6 +9,8 @@ #include "oi/OICompiler.h" +using namespace oi::detail; + namespace fs = std::filesystem; /* Add the suffix operator _b to easily create array of uint8_t. */ diff --git a/test/test_drgn_parser.h b/test/test_drgn_parser.h index aff9145..fc88ac4 100644 --- a/test/test_drgn_parser.h +++ b/test/test_drgn_parser.h @@ -4,12 +4,16 @@ #include "oi/type_graph/DrgnParser.h" -namespace type_graph { +namespace oi::detail { +class SymbolService; +} +namespace oi::detail::type_graph { class TypeGraph; } -class SymbolService; struct drgn_type; +using namespace oi::detail; + class DrgnParserTest : public ::testing::Test { protected: static void SetUpTestSuite() { diff --git a/test/test_node_tracker.cpp b/test/test_node_tracker.cpp index b528718..9c59103 100644 --- a/test/test_node_tracker.cpp +++ b/test/test_node_tracker.cpp @@ -2,7 +2,7 @@ #include "oi/type_graph/NodeTracker.h" -using namespace type_graph; +using namespace oi::detail::type_graph; TEST(NodeTrackerTest, LeafNodes) { Primitive myint32{Primitive::Kind::Int32}; diff --git a/test/test_parser.cpp b/test/test_parser.cpp index 295f424..b9d5be9 100644 --- a/test/test_parser.cpp +++ b/test/test_parser.cpp @@ -9,7 +9,7 @@ using ::testing::HasSubstr; -using namespace ObjectIntrospection; +using namespace oi::detail; // Utilities static ParseData parseString(const std::string& script) { diff --git a/test/type_graph_utils.h b/test/type_graph_utils.h index b7caf0b..6175e04 100644 --- a/test/type_graph_utils.h +++ b/test/type_graph_utils.h @@ -6,9 +6,11 @@ #include "oi/type_graph/Types.h" -namespace type_graph { +namespace oi::detail::type_graph { class Pass; -} // namespace type_graph +} // namespace oi::detail::type_graph + +using namespace oi::detail; void check(const std::vector>& types, std::string_view expected, diff --git a/tools/OILGen.cpp b/tools/OILGen.cpp index 2d4a90f..fb5b67d 100644 --- a/tools/OILGen.cpp +++ b/tools/OILGen.cpp @@ -25,7 +25,7 @@ #include "oi/OIOpts.h" namespace fs = std::filesystem; -using namespace ObjectIntrospection; +using namespace oi::detail; constexpr static OIOpts opts{ OIOpt{'h', "help", no_argument, nullptr, "Print this message and exit."}, diff --git a/tools/OITB.cpp b/tools/OITB.cpp index 0adeddd..d016c29 100644 --- a/tools/OITB.cpp +++ b/tools/OITB.cpp @@ -32,7 +32,7 @@ namespace fs = std::filesystem; -using namespace ObjectIntrospection; +using namespace oi::detail; constexpr static OIOpts opts{ OIOpt{'h', "help", no_argument, nullptr, "Print this message and exit"},