diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d12d937f35f..0c622496d3bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1285,7 +1285,6 @@ if (TD_ENABLE_DOTNET) add_dependencies(tddotnet generate_dotnet_api) endif() - target_compile_options(tddotnet PRIVATE "/doc") if (CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") set_target_properties(tddotnet PROPERTIES VS_WINRT_COMPONENT "true") target_compile_options(tddotnet PUBLIC "/ZW") @@ -1293,6 +1292,11 @@ if (TD_ENABLE_DOTNET) set_target_properties(tddotnet PROPERTIES COMPILE_FLAGS "/GR /clr") target_compile_options(tddotnet PUBLIC "/EHa") endif() + + add_custom_command(TARGET tddotnet POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${TL_TD_AUTO_INCLUDE_DIR}/td/telegram/Telegram.Td.xml + $) endif() # tdc - TDLib interface in pure C diff --git a/td/generate/CMakeLists.txt b/td/generate/CMakeLists.txt index f6ed78a0fbd4..f83d526da5b6 100644 --- a/td/generate/CMakeLists.txt +++ b/td/generate/CMakeLists.txt @@ -208,7 +208,7 @@ if (NOT CMAKE_CROSSCOMPILING) if (TD_ENABLE_DOTNET) if (PHP_EXECUTABLE) - set(GENERATE_DOTNET_API_CMD td_generate_dotnet_api ${TD_API_TLO_FILE} && ${PHP_EXECUTABLE} ../DotnetTlDocumentationGenerator.php ../scheme/td_api.tl td/telegram/TdDotNetApi.h) + set(GENERATE_DOTNET_API_CMD td_generate_dotnet_api ${TD_API_TLO_FILE} && ${PHP_EXECUTABLE} ../DotnetTlDocumentationGenerator.php ../scheme/td_api.tl td/telegram/Telegram.Td.xml ${CMAKE_SYSTEM_NAME}) else() set(GENERATE_DOTNET_API_CMD td_generate_dotnet_api ${TD_API_TLO_FILE}) endif() diff --git a/td/generate/DotnetTlDocumentationGenerator.php b/td/generate/DotnetTlDocumentationGenerator.php index f6bb561f32c8..88bc08f1d0dc 100644 --- a/td/generate/DotnetTlDocumentationGenerator.php +++ b/td/generate/DotnetTlDocumentationGenerator.php @@ -4,6 +4,116 @@ class DotnetTlDocumentationGenerator extends TlDocumentationGenerator { + public $cpp_cli = false; + + private function getArrayType($typeName) + { + if ($this->cpp_cli) { + return $typeName.'[]'; + } + + return 'System.Collections.Generic.IList{'.$typeName.'}'; + } + + protected function isStandaloneFile() + { + return true; + } + + protected function getDocumentationBegin() + { + $documentation = << + + + "Telegram.Td" + + + + +Creates new Client. + + Handler for incoming updates. + Returns created Client. + + + +Launches a cycle which will fetch all results of queries to TDLib and incoming updates from TDLib. +Must be called once on a separate dedicated thread on which all updates and query results from all Clients will be handled. +Never returns. + + + + +Synchronously executes a TDLib request. Only a few marked accordingly requests can be executed synchronously. + + Object representing a query to the TDLib. + Returns request result. + Thrown when query is null. + + + +Sends a request to the TDLib. + + Object representing a query to the TDLib. + Result handler with OnResult method which will be called with result +of the query or with Telegram.Td.Api.Error as parameter. If it is null, nothing will be called. + Thrown when query is null. + + + +Main class for interaction with the TDLib. + + + + +Callback called on result of query to TDLib or incoming update from TDLib. + + Result of query or update of type Telegram.Td.Api.Update about new events. + + + +Interface for handler for results of queries to TDLib and incoming updates from TDLib. + + +EOT; + + if ($this->cpp_cli) { + return $documentation; + } + + $documentation .= << + +Sets the callback that will be called when a message is added to the internal TDLib log. +None of the TDLib methods can be called from the callback. + + The maximum verbosity level of messages for which the callback will be called. + Callback that will be called when a message is added to the internal TDLib log. +Pass null to remove the callback. + + + +A type of callback function that will be called when a message is added to the internal TDLib log. + + Log verbosity level with which the message was added from -1 up to 1024. +If 0, then TDLib will crash as soon as the callback returns. +None of the TDLib methods can be called from the callback. + The message added to the log. + +EOT; + + return $documentation; + } + + protected function getDocumentationEnd() + { + return << + +EOT; + } + protected function escapeDocumentation($doc) { $doc = preg_replace_callback('/(?^'; + return $this->getArrayType('System.Byte'); case 'bool': case 'int': case 'long': @@ -74,14 +184,14 @@ protected function getTypeName($type) $this->printError("Wrong vector subtype in $type"); return ''; } - return 'Array<'.$this->getTypeName(substr($type, 7, -1)).'>^'; + return $this->getArrayType($this->getTypeName(substr($type, 7, -1))); } if (preg_match('/[^A-Za-z0-9.]/', $type)) { $this->printError("Wrong type $type"); return ''; } - return $this->getClassName($type).'^'; + return $this->getClassName($type); } } @@ -124,114 +234,117 @@ protected function fixLine($line) protected function addGlobalDocumentation() { - $this->addDocumentation('public interface class Object : BaseObject {', << -/// This class is a base class for all TDLib interface classes. -/// -EOT -); - - $this->addDocumentation(' virtual String^ ToString() override;', << - /// Returns string representation of the object. - /// - /// Returns string representation of the object. + $this->addDocumentation('T:Object', << + +This class is a base class for all TDLib interface classes. + + EOT ); - $this->addDocumentation('public interface class Function : BaseObject {', << -/// This class is a base class for all TDLib interface function-classes. -/// + $this->addDocumentation('T:Function', << + +This class is a base class for all TDLib interface function-classes. + + EOT ); } protected function addAbstractClassDocumentation($class_name, $documentation) { - $this->addDocumentation("public interface class $class_name : Object {", << -/// This class is an abstract base class. -/// $documentation -/// + $this->addDocumentation("T:$class_name", << + +This class is an abstract base class. +$documentation + + EOT ); + } protected function getFunctionReturnTypeDescription($return_type, $for_constructor) { - $shift = $for_constructor ? ' ' : ''; - return "\r\n$shift/// Returns .'; + return "\r\n Returns ."; } protected function addClassDocumentation($class_name, $base_class_name, $return_type, $description) { - $this->addDocumentation("public ref class $class_name sealed : $base_class_name {", << -/// $description -/// + $this->addDocumentation("T:$class_name", << + +$description + + EOT ); } protected function addFieldDocumentation($class_name, $field_name, $type_name, $field_info, $may_be_null) { - $end = ';'; - if ($type_name == $field_name.'^' || ($type_name == 'Message^' && $field_name == 'ReplyToMessage')) { - $type_name = '::Telegram::Td::Api::'.$type_name; - $end = ' {'; - } else if ($class_name == "WebPage" && $field_name == "Stickers" && $type_name == "Array^") { - $type_name = 'Array<::Telegram::Td::Api::Sticker^>^'; - $end = ' {'; - } - $full_line = $class_name." property $type_name $field_name$end"; - $this->addDocumentation($full_line, << - /// $field_info - /// + $this->addDocumentation("P:$class_name.$field_name", << + +$field_info + + EOT ); } protected function addDefaultConstructorDocumentation($class_name, $class_description) { - $this->addDocumentation(" $class_name();", << - /// $class_description - /// + $this->addDocumentation("M:$class_name.#ctor", << + +Returns string representation of the object. + + Returns string representation of the object. + + + +$class_description + + EOT ); } protected function addFullConstructorDocumentation($class_name, $class_description, $known_fields, $info) { - $full_constructor = " $class_name("; + $full_constructor = ""; $colon = ''; foreach ($known_fields as $name => $type) { $field_type = $this->getTypeName($type); $pos = 0; - while (substr($field_type, $pos, 6) === 'Array<') { - $pos += 6; + while (substr($field_type, $pos, 33) === 'System.Collections.Generic.IList{') { + $pos += 33; } - if (substr($field_type, $pos, 4) !== 'BYTE' && substr($field_type, $pos, 6) !== 'String' && ucfirst(substr($field_type, $pos)) === substr($field_type, $pos)) { - $field_type = substr($field_type, 0, $pos).'::Telegram::Td::Api::'.substr($field_type, $pos); + if (substr($field_type, $pos, 7) !== 'System.') { + $field_type = substr($field_type, 0, $pos).'Telegram.Td.Api.'.substr($field_type, $pos); } - $full_constructor .= $colon.$field_type.' '.$this->getParameterName($name, $class_name); - $colon = ', '; + $full_constructor .= $colon.$field_type; + $colon = ','; } - $full_constructor .= ');'; $full_doc = << - /// $class_description - /// + + +$class_description + EOT; foreach ($known_fields as $name => $type) { - $full_doc .= "\r\n /// getParameterName($name, $class_name).'">'.$info[$name].""; + $full_doc .= "\r\n getParameterName($name, $class_name).'">'.$info[$name].""; } - $this->addDocumentation($full_constructor, $full_doc); + $full_doc .= "\r\n "; + $this->addDocumentation("M:$class_name.#ctor($full_constructor)", $full_doc); } } $generator = new DotnetTlDocumentationGenerator(); +$generator->cpp_cli = $argv[3] !== "WindowsStore"; $generator->generate($argv[1], $argv[2]); diff --git a/td/generate/TlDocumentationGenerator.php b/td/generate/TlDocumentationGenerator.php index e46deafacbae..9b35aa299446 100644 --- a/td/generate/TlDocumentationGenerator.php +++ b/td/generate/TlDocumentationGenerator.php @@ -81,6 +81,21 @@ final protected function addDot($str) { return $str.'.'; } + protected function isStandaloneFile() + { + return false; + } + + protected function getDocumentationBegin() + { + return ""; + } + + protected function getDocumentationEnd() + { + return ""; + } + abstract protected function escapeDocumentation($doc); abstract protected function getFieldName($name, $class_name); @@ -310,6 +325,18 @@ public function generate($tl_scheme_file, $source_file) } } + if ($this->isStandaloneFile()) { + $result = $this->getDocumentationBegin()."\n"; + foreach ($this->documentation as $value) { + $result .= $value."\n"; + } + $result .= $this->getDocumentationEnd(); + if (!file_exists($source_file) || file_get_contents($source_file) !== $result) { + file_put_contents($source_file, $result); + } + return; + } + $lines = file($source_file); $result = ''; $current_class = '';