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).
Esse commit está contido em:
Sara Golemon
2013-06-26 09:32:24 -07:00
commit a3f507d58d
4 arquivos alterados com 57 adições e 8 exclusões
+9
Ver Arquivo
@@ -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));
+16 -5
Ver Arquivo
@@ -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<PhpClass>& classes,
const fbvector<PhpFunc>& funcs,
const fbvector<PhpConst>& consts) {
const fbvector<PhpConst>& consts,
const fbvector<PhpExtension>& 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<PhpFunc> funcs;
fbvector<PhpClass> classes;
fbvector<PhpConst> consts;
fbvector<PhpExtension> 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);
+9 -2
Ver Arquivo
@@ -699,7 +699,8 @@ PhpClass::PhpClass(const folly::dynamic &c) :
void parseIDL(const char* idlFilePath,
fbvector<PhpFunc>& funcVec,
fbvector<PhpClass>& classVec,
fbvector<PhpConst>& constVec) {
fbvector<PhpConst>& constVec,
fbvector<PhpExtension>& 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<PhpFunc>& funcVec,
fbvector<PhpClass>& classVec) {
fbvector<PhpConst> consts; // dummy
parseIDL(idlFilePath, funcVec, classVec, consts);
fbvector<PhpExtension> exts; // dummy
parseIDL(idlFilePath, funcVec, classVec, consts, exts);
}
/////////////////////////////////////////////////////////////////////////////
+23 -1
Ver Arquivo
@@ -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<PhpFunc>& funcVec,
fbvector<PhpClass>& classVec);
@@ -378,7 +399,8 @@ void parseIDL(const char* idlFilePath,
void parseIDL(const char* idlFilePath,
fbvector<PhpFunc>& funcVec,
fbvector<PhpClass>& classVec,
fbvector<PhpConst>& constVec);
fbvector<PhpConst>& constVec,
fbvector<PhpExtension>& extVec);
/////////////////////////////////////////////////////////////////////////////
}} // namespace HPHP::IDL