') {
return '';
}
return 'array<'.$this->getTypeName(substr($type, 7, -1)).'> &&';
}
if (preg_match('/[^A-Za-z0-9.]/', $type)) {
return '';
}
return 'object_ptr<'.$this->getClassName($type).'> &&';
}
}
protected function escapeDocumentation($doc)
{
$doc = htmlspecialchars($doc, ENT_COMPAT, 'UTF-8');
$doc = preg_replace_callback('/"((http|https|tg):\/\/[^" ]*)"/',
function ($quoted_link)
{
return """.$quoted_link[1].""";
}, $doc);
$doc = str_replace('*/', '*/', $doc);
$doc = str_replace('#', '\#', $doc);
return $doc;
}
protected function getFieldName($name, $class_name)
{
if (substr($name, 0, 6) === 'param_') {
$name = substr($name, 6);
}
return $name.'_';
}
protected function getClassName($type)
{
return implode(explode('.', trim($type, "\r\n ;")));
}
protected function getTypeName($type)
{
switch ($type) {
case 'Bool':
return 'bool';
case 'int32':
return 'int32';
case 'int53':
return 'int53';
case 'int64':
return 'int64';
case 'double':
return 'double';
case 'string':
return 'string';
case 'bytes':
return 'bytes';
case 'bool':
case 'int':
case 'long':
case 'Int':
case 'Long':
case 'Int32':
case 'Int53':
case 'Int64':
case 'Double':
case 'String':
case 'Bytes':
$this->printError("Wrong type $type");
return '';
default:
if (substr($type, 0, 6) === 'vector') {
if ($type[6] !== '<' || $type[strlen($type) - 1] !== '>') {
$this->printError("Wrong vector subtype in $type");
return '';
}
return 'array<'.$this->getTypeName(substr($type, 7, -1)).'>';
}
if (preg_match('/[^A-Za-z0-9.]/', $type)) {
$this->printError("Wrong type $type");
return '';
}
return 'object_ptr<'.$this->getClassName($type).'>';
}
}
protected function getBaseClassName($is_function)
{
return $is_function ? 'Function' : 'Object';
}
protected function needRemoveLine($line)
{
$line = trim($line);
return strpos($line, '/**') === 0 || strpos($line, '*') === 0 || strpos($line, '///') === 0;
}
protected function needSkipLine($line)
{
$tline = trim($line);
return empty($tline) || $tline[0] === '}' || $tline === 'public:' || strpos($line, '#pragma ') === 0 ||
strpos($line, '#include <') === 0 || strpos($tline, 'return ') === 0 || strpos($tline, 'namespace') === 0 ||
preg_match('/class [A-Za-z0-9_]*;/', $line) || $tline === 'if (value == nullptr) {' ||
strpos($tline, 'result += ') === 0 || strpos($tline, 'result = ') || strpos($tline, ' : values') ||
strpos($line, 'JNIEnv') || strpos($line, 'jfieldID') || $tline === 'virtual ~Object() {' ||
$tline === 'virtual void store(TlStorerToString &s, const char *field_name) const = 0;' ||
$tline === 'const char *&get_package_name_ref();';
}
protected function isHeaderLine($line)
{
return strpos($line, 'template <') === 0;
}
protected function extractClassName($line)
{
if (strpos($line, 'class ') === 0) {
return explode(' ', trim($line))[1];
}
return '';
}
protected function fixLine($line)
{
if (strpos($line, 'ID = ') > 0 || strpos($line, 'ReturnType = ') > 0 || strpos($line, 'using BaseObject = ') === 0) {
return substr($line, 0, strpos($line, '='));
}
if (strpos($line, 'class Function: ') === 0) {
return 'class Function';
}
if (strpos($line, 'class Object {') === 0 || strpos($line, 'class Object: public TlObject {') === 0) {
return 'class Object';
}
return $line;
}
protected function addGlobalDocumentation()
{
$this->addDocumentation('#include "td/tl/TlObject.h"', <<addDocumentation('using int32 = std::int32_t;', <<addDocumentation('using int53 = std::int64_t;', <<addDocumentation('using int64 = std::int64_t;', <<addDocumentation('using string = std::string;', <<addDocumentation('using bytes = std::string;', <<addDocumentation('using array = std::vector;', <<addDocumentation('using BaseObject', <<addDocumentation('using object_ptr = ::td::tl_object_ptr;', <<addDocumentation('object_ptr make_object(Args &&... args) {', <<();
* auto message_text = td::td_api::make_object("Hello, world!!!",
* td::td_api::array>());
* auto send_message_request = td::td_api::make_object(chat_id, 0, nullptr, nullptr, nullptr,
* td::td_api::make_object(std::move(message_text), nullptr, true));
* \\endcode
*
* \\tparam Type Type of object to construct.
* \\param[in] args Arguments to pass to the object constructor.
* \\return Wrapped pointer to the created object.
*/
EOT
);
$this->addDocumentation('object_ptr move_object_as(FromType &&from) {', << call_state = ...;
* switch (call_state->get_id()) {
* case td::td_api::callStatePending::ID: {
* auto state = td::td_api::move_object_as(call_state);
* // use state
* break;
* }
* case td::td_api::callStateExchangingKeys::ID: {
* // no additional fields, no casting is needed
* break;
* }
* case td::td_api::callStateReady::ID: {
* auto state = td::td_api::move_object_as(call_state);
* // use state
* break;
* }
* case td::td_api::callStateHangingUp::ID: {
* // no additional fields, no casting is needed
* break;
* }
* case td::td_api::callStateDiscarded::ID: {
* auto state = td::td_api::move_object_as(call_state);
* // use state
* break;
* }
* case td::td_api::callStateError::ID: {
* auto state = td::td_api::move_object_as(call_state);
* // use state
* break;
* }
* default:
* assert(false);
* }
* \\endcode
*
* \\tparam ToType Type of TDLib API object to move to.
* \\tparam FromType Type of TDLib API object to move from, this is auto-deduced.
* \\param[in] from Wrapped in td::td_api::object_ptr pointer to a TDLib API object.
*/
EOT
);
$this->addDocumentation('std::string to_string(const BaseObject &value);', <<addDocumentation('std::string to_string(const object_ptr &value) {', <<addDocumentation('std::string to_string(const std::vector> &values) {', <<addDocumentation(' void store(TlStorerToString &s, const char *field_name) const final;', <<addDocumentation('class Object', <<addDocumentation('class Function', <<addDocumentation(' static const std::int32_t ID', <<addDocumentation(' std::int32_t get_id() const final {', <<ID.
*/
EOT
);
$this->addDocumentation(' virtual std::int32_t get_id() const = 0;', <<ID.
*/
EOT
);
$this->addDocumentation(' using ReturnType', <<addDocumentation("class $class_name: public Object {", <<addDocumentation("class $class_name final : public $base_class_name {", <<addDocumentation($class_name." $type_name $field_name;", <<addDocumentation(" $class_name();", << $type) {
$full_constructor .= $colon.$this->getParameterTypeName($type).$this->getFieldName($name, $class_name);
$colon = ', ';
}
$full_constructor .= ');';
$full_doc = << $type) {
$full_doc .= ' * \\param[in] '.$this->getFieldName($name, $class_name).' '.$info[$name].PHP_EOL;
}
$full_doc .= ' */';
$this->addDocumentation($full_constructor, $full_doc);
}
}
$generator = new DoxygenTlDocumentationGenerator();
$generator->generate($argv[1], $argv[2]);