From a3f507d58df15f8edad7237c15750ac693de8fde Mon Sep 17 00:00:00 2001 From: Sara Golemon Date: Wed, 26 Jun 2013 09:32:24 -0700 Subject: [PATCH] Add reference to extension object to class_map Add IDL component: { "extension": { "symbol": "s_foo_extension" } } extension.symbol is the C++ HPHP::Extension symbol for the extension (if one exists and is exported). --- hphp/runtime/base/class_info.cpp | 9 +++++++++ hphp/tools/bootstrap/gen-class-map.cpp | 21 ++++++++++++++++----- hphp/tools/bootstrap/idl.cpp | 11 +++++++++-- hphp/tools/bootstrap/idl.h | 24 +++++++++++++++++++++++- 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/hphp/runtime/base/class_info.cpp b/hphp/runtime/base/class_info.cpp index 4cb462e80..3fd49f9d0 100644 --- a/hphp/runtime/base/class_info.cpp +++ b/hphp/runtime/base/class_info.cpp @@ -21,6 +21,7 @@ #include "hphp/runtime/base/hphp_system.h" #include "hphp/runtime/base/variable_serializer.h" #include "hphp/runtime/base/variable_unserializer.h" +#include "hphp/runtime/ext/extension.h" #include "hphp/util/util.h" #include "hphp/util/lock.h" #include "hphp/util/logger.h" @@ -745,6 +746,14 @@ void ClassInfoUnique::postInit() { void ClassInfo::Load() { if (s_loaded) return; const char **p = g_class_map; + + while (*p) { + Extension *ext = (Extension*)*p++; + // TODO: Do something useful with this + // For now, it's here to anchor "empty" extensions + } + p++; + while (*p) { Attribute attribute = (Attribute)(int64_t)*p; always_assert(!(attribute & IsRedeclared)); diff --git a/hphp/tools/bootstrap/gen-class-map.cpp b/hphp/tools/bootstrap/gen-class-map.cpp index 7456eb0eb..708760b85 100644 --- a/hphp/tools/bootstrap/gen-class-map.cpp +++ b/hphp/tools/bootstrap/gen-class-map.cpp @@ -317,7 +317,8 @@ static void writeClass(std::ostream& out, const PhpClass& cls) { static void outputClassMap(const char *outputfn, const char *classmap_name, const fbvector& classes, const fbvector& funcs, - const fbvector& consts) { + const fbvector& consts, + const fbvector& exts) { std::ofstream out(outputfn); out << "// @" "generated by gen-class-map.cpp\n" @@ -325,8 +326,17 @@ static void outputClassMap(const char *outputfn, const char *classmap_name, << "#include \"hphp/runtime/ext/ext.h\"\n" << "namespace HPHP {\n"; declareConstants(out, consts, false); - out << "const char *" << classmap_name << "[] = {\n" - << " (const char *)ClassInfo::IsSystem, NULL, " + out << "const char *" << classmap_name << "[] = {\n"; + + for (auto &e : exts) { + auto sym = e.symbol(); + if (!sym.empty()) { + out << " (const char*)&" << sym << ",\n"; + } + } + out << " NULL,\n"; // End of extensions + + out << " (const char *)ClassInfo::IsSystem, NULL, " << "\"\", \"\", NULL, NULL, NULL,\n"; for (auto &f : funcs) { writeFunction(out, f); @@ -377,10 +387,11 @@ int main(int argc, const char* argv[]) { fbvector funcs; fbvector classes; fbvector consts; + fbvector exts; for (int i = (system ? 4 : 3); i < argc; ++i) { try { - parseIDL(argv[i], funcs, classes, consts); + parseIDL(argv[i], funcs, classes, consts, exts); } catch (const std::exception& exc) { std::cerr << argv[i] << ": " << exc.what() << "\n"; return 1; @@ -389,7 +400,7 @@ int main(int argc, const char* argv[]) { const char* path = argv[2]; const char* name = (system ? "g_class_map" : argv[1]); - outputClassMap(path, name, classes, funcs, consts); + outputClassMap(path, name, classes, funcs, consts, exts); if (system) { path = argv[3]; outputConstants(path, consts); diff --git a/hphp/tools/bootstrap/idl.cpp b/hphp/tools/bootstrap/idl.cpp index 1f326fdf1..ee213bdaa 100644 --- a/hphp/tools/bootstrap/idl.cpp +++ b/hphp/tools/bootstrap/idl.cpp @@ -699,7 +699,8 @@ PhpClass::PhpClass(const folly::dynamic &c) : void parseIDL(const char* idlFilePath, fbvector& funcVec, fbvector& classVec, - fbvector& constVec) { + fbvector& constVec, + fbvector& extVec) { std::ostringstream jsonString; std::ifstream infile(idlFilePath); infile >> jsonString.rdbuf(); @@ -718,13 +719,19 @@ void parseIDL(const char* idlFilePath, PhpConst cns(c); constVec.push_back(cns); } + auto it = parsed.find("extension"); + if (it != parsed.items().end()) { + PhpExtension ext(it->second); + extVec.push_back(ext); + } } void parseIDL(const char* idlFilePath, fbvector& funcVec, fbvector& classVec) { fbvector consts; // dummy - parseIDL(idlFilePath, funcVec, classVec, consts); + fbvector exts; // dummy + parseIDL(idlFilePath, funcVec, classVec, consts, exts); } ///////////////////////////////////////////////////////////////////////////// diff --git a/hphp/tools/bootstrap/idl.h b/hphp/tools/bootstrap/idl.h index acb27bceb..fd37a3695 100644 --- a/hphp/tools/bootstrap/idl.h +++ b/hphp/tools/bootstrap/idl.h @@ -371,6 +371,27 @@ class PhpClass { fbstring m_desc; }; +class PhpExtension { + public: + explicit PhpExtension(const folly::dynamic& e) + : m_extension(e) { } + + /* The C++ symbol name of the Extension struct. + * Only needed if s_(name)_extension is not correct. + * Set to blank if this ext doens't declare an Extension. + */ + fbstring symbol() const { + auto it = m_extension.find("symbol"); + if (it != m_extension.items().end()) { + return it->second.asString(); + } + return ""; + } + + private: + folly::dynamic m_extension; +}; + void parseIDL(const char* idlFilePath, fbvector& funcVec, fbvector& classVec); @@ -378,7 +399,8 @@ void parseIDL(const char* idlFilePath, void parseIDL(const char* idlFilePath, fbvector& funcVec, fbvector& classVec, - fbvector& constVec); + fbvector& constVec, + fbvector& extVec); ///////////////////////////////////////////////////////////////////////////// }} // namespace HPHP::IDL