function generateClassCPPHeader($class, $f) { $lowername = strtolower($class['name']); foreach ($class['consts'] as $k) { $name = typename($k['type']); if ($name == 'String') { $name = 'StaticString'; } fprintf($f, "extern const %s q_%s_%s;\n", $name, $lowername, $k['name']); } fprintf($f, <<<EOT /////////////////////////////////////////////////////////////////////////////// // class {$class['name']} EOT ); fprintf($f, "FORWARD_DECLARE_CLASS(%s);\n", $lowername); foreach ($class['properties'] as $p) { generatePropertyCPPForwardDeclarations($p, $f); } fprintf($f, "class c_%s", $lowername); if ($class['parent']) { fprintf($f, " : public c_" . strtolower($class['parent'])); } else { fprintf($f, " : public ExtObjectData"); } foreach ($class['bases'] as $p) { fprintf($f, ", public {$p}"); } $parents = array(); fprintf($f, " {\n public:\n"); fprintf($f, " BEGIN_CLASS_MAP(%s)\n", $lowername); if ($class['parent']) { $p = $class['parent']; fprintf($f, " RECURSIVE_PARENT_CLASS(%s)\n", strtolower($p)); } foreach ($class['ifaces'] as $p) { fprintf($f, " PARENT_CLASS(%s)\n", strtolower($p)); } foreach ($parents as $p) { fprintf($f, " RECURSIVE_PARENT_CLASS(%s)\n", strtolower($p)); } fprintf($f, " END_CLASS_MAP(%s)\n", $lowername); fprintf($f, " DECLARE_CLASS(%s, %s, %s)\n", $lowername, $class['name'], $class['parent'] ? strtolower($class['parent']) : 'ObjectData'); fprintf($f, " DECLARE_INVOKES_FROM_EVAL\n"); fprintf($f, " ObjectData* dynCreate(CArrRef params, bool init = true);\n"); fprintf($f, "\n"); if (!empty($class['properties'])) { fprintf($f, " // properties\n"); foreach ($class['properties'] as $p) { generatePropertyCPPHeader($p, $f); } fprintf($f, "\n"); } fprintf($f, " // need to implement\n"); fprintf($f, " public: c_%s();\n", strtolower($class['name'])); fprintf($f, " public: ~c_%s();\n", strtolower($class['name'])); foreach ($class['methods'] as $m) { generateMethodCPPHeader($m, $class, $f); } fprintf($f, "\n"); fprintf($f, " // implemented by HPHP\n"); foreach ($class['methods'] as $m) { generatePreImplemented($m, $class, $f); } fprintf($f, $class['footer']); fprintf($f, "\n};\n"); }
function generateClassCPPHeader($class, $f) { global $MAGIC_METHODS; $clsname = $class['name']; foreach ($class['consts'] as $k) { $name = typename($k['type']); if ($name == 'String') { $name = 'StaticString'; } fprintf($f, "extern const %s q_%s\$\$%s;\n", $name, $clsname, $k['name']); } fprintf($f, <<<EOT /////////////////////////////////////////////////////////////////////////////// // class {$class['name']} EOT ); fprintf($f, "FORWARD_DECLARE_CLASS_BUILTIN(%s);\n", $clsname); foreach ($class['properties'] as $p) { generatePropertyCPPForwardDeclarations($p, $f); } fprintf($f, "class c_%s", $clsname); $flags = array(); foreach ($class['methods'] as $m) { $name = $m['name']; if (isset($MAGIC_METHODS[$name]) && $MAGIC_METHODS[$name]) { $flags[$name] = $MAGIC_METHODS[$name]; } } if ($class['parent']) { global $classes; $pclass = $class; while ($flags && $pclass['parent'] && isset($classes[$class['parent']])) { $pclass = $classes[$class['parent']]; foreach ($pclass['methods'] as $m) { unset($flags[$m['name']]); } } fprintf($f, " : public c_" . $class['parent']); } else { fprintf($f, " : public ExtObjectData"); if ($flags) { fprintf($f, "Flags<%s>", implode('|', $flags)); $flags = false; } } foreach ($class['bases'] as $p) { fprintf($f, ", public {$p}"); } $parents = array(); fprintf($f, " {\n public:\n"); fprintf($f, " DECLARE_CLASS(%s, %s, %s)\n", $clsname, $clsname, $class['parent'] ? $class['parent'] : 'ObjectData'); fprintf($f, "\n"); if (!empty($class['properties'])) { fprintf($f, " // properties\n"); foreach ($class['properties'] as $p) { generatePropertyCPPHeader($p, $f); } fprintf($f, "\n"); } fprintf($f, " // need to implement\n"); if ($flags) { fprintf($f, " // constructor must call setAttributes(%s)\n", implode('|', $flags)); } fprintf($f, " public: c_%s(const ObjectStaticCallbacks *cb = &cw_%s);\n", $class['name'], $class['name']); fprintf($f, " public: ~c_%s();\n", $class['name']); foreach ($class['methods'] as $m) { generateMethodCPPHeader($m, $class, $f); } fprintf($f, "\n"); fprintf($f, " // implemented by HPHP\n"); foreach ($class['methods'] as $m) { generatePreImplemented($m, $class, $f); } if (!empty($class['properties']) || !empty($class['consts'])) { fprintf($f, " public: static const ClassPropTable os_prop_table;\n"); } if (!empty($class['footer'])) { fprintf($f, $class['footer']); } fprintf($f, "\n};\n"); }
function generateClassCPPHeader($class, $f) { $clsname = $class['name']; foreach ($class['consts'] as $k) { $name = typename($k['type']); if ($name == 'String') { $name = 'StaticString'; } fprintf($f, "extern const %s q_%s_%s;\n", $name, $clsname, $k['name']); } fprintf($f, <<<EOT /////////////////////////////////////////////////////////////////////////////// // class {$class['name']} EOT ); fprintf($f, "FORWARD_DECLARE_CLASS(%s);\n", $clsname); foreach ($class['properties'] as $p) { generatePropertyCPPForwardDeclarations($p, $f); } fprintf($f, "class c_%s", $clsname); $magic_methods = array('__get' => 'ObjectData::UseGet', '__set' => 'ObjectData::UseSet', '__unset' => 'ObjectData::UseUnset'); $flags = array(); foreach ($class['methods'] as $m) { $name = $m['name']; if (isset($magic_methods[$name])) { $flags[$name] = $magic_methods[$name]; } } if ($class['parent']) { global $classes; $pclass = $class; while ($flags && $pclass['parent'] && isset($classes[$class['parent']])) { $pclass = $classes[$class['parent']]; foreach ($pclass['methods'] as $m) { unset($flags[$m['name']]); } } fprintf($f, " : public c_" . $class['parent']); } else { fprintf($f, " : public ExtObjectData"); if ($flags) { echo "Using Flags!\n"; fprintf($f, "Flags<%s>", implode('|', $flags)); $flags = false; } } foreach ($class['bases'] as $p) { fprintf($f, ", public {$p}"); } $parents = array(); fprintf($f, " {\n public:\n"); fprintf($f, " BEGIN_CLASS_MAP(%s)\n", $clsname); if ($class['parent']) { $p = $class['parent']; fprintf($f, " RECURSIVE_PARENT_CLASS(%s)\n", $p); } foreach ($class['ifaces'] as $p) { fprintf($f, " PARENT_CLASS(%s)\n", $p); } foreach ($parents as $p) { fprintf($f, " RECURSIVE_PARENT_CLASS(%s)\n", $p); } fprintf($f, " END_CLASS_MAP(%s)\n", $clsname); fprintf($f, " DECLARE_CLASS(%s, %s, %s)\n", $clsname, $clsname, $class['parent'] ? $class['parent'] : 'ObjectData'); fprintf($f, " DECLARE_INVOKES_FROM_EVAL\n"); fprintf($f, " ObjectData* dynCreate(CArrRef params, bool init = true);\n"); fprintf($f, "\n"); if (!empty($class['properties'])) { fprintf($f, " // properties\n"); foreach ($class['properties'] as $p) { generatePropertyCPPHeader($p, $f); } fprintf($f, "\n"); } fprintf($f, " // need to implement\n"); if ($flags) { fprintf($f, " // constructor must call setAttributes(%s)\n", implode('|', $flags)); } fprintf($f, " public: c_%s();\n", $class['name']); fprintf($f, " public: ~c_%s();\n", $class['name']); foreach ($class['methods'] as $m) { generateMethodCPPHeader($m, $class, $f); } fprintf($f, "\n"); fprintf($f, " // implemented by HPHP\n"); foreach ($class['methods'] as $m) { generatePreImplemented($m, $class, $f); } if (!empty($class['footer'])) { fprintf($f, $class['footer']); } fprintf($f, "\n};\n"); }