-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Verbatim comments translation for C# #1695
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
#include <limits.h> // for INT_MAX | ||
#include "cparse.h" | ||
#include <ctype.h> | ||
#include "../Doxygen/doxytranslator.h" | ||
|
||
/* Hash type used for upcalls from C/C++ */ | ||
typedef DOH UpcallData; | ||
|
@@ -46,6 +47,8 @@ class CSHARP:public Language { | |
bool global_variable_flag; // Flag for when wrapping a global variable | ||
bool old_variable_names; // Flag for old style variable names in the intermediary class | ||
bool generate_property_declaration_flag; // Flag for generating properties | ||
bool doxygen; //flag enabling comment processing | ||
bool comment_creation_chatter; //flag for getting information about where comments were created | ||
|
||
String *imclass_name; // intermediary class name | ||
String *module_class_name; // module class name | ||
|
@@ -81,6 +84,7 @@ class CSHARP:public Language { | |
String *director_connect_parms; // Director delegates parameter list for director connect call | ||
String *destructor_call; //C++ destructor call if any | ||
String *output_file; // File name for single file mode. If set all generated code will be written to this file | ||
String* structuralComments; | ||
|
||
// Director method stuff: | ||
List *dmethods_seq; | ||
|
@@ -122,6 +126,8 @@ class CSHARP:public Language { | |
global_variable_flag(false), | ||
old_variable_names(false), | ||
generate_property_declaration_flag(false), | ||
doxygen(false), | ||
comment_creation_chatter(false), | ||
imclass_name(NULL), | ||
module_class_name(NULL), | ||
imclass_class_code(NULL), | ||
|
@@ -155,6 +161,7 @@ class CSHARP:public Language { | |
director_method_types(NULL), | ||
director_connect_parms(NULL), | ||
destructor_call(NULL), | ||
structuralComments(NULL), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This results in
which is harmless here but still would be better to fix. |
||
output_file(NULL), | ||
dmethods_seq(NULL), | ||
dmethods_table(NULL), | ||
|
@@ -169,6 +176,10 @@ class CSHARP:public Language { | |
director_language = 1; | ||
} | ||
|
||
~CSHARP() { | ||
delete doxygenTranslator; | ||
} | ||
|
||
/* ----------------------------------------------------------------------------- | ||
* getProxyName() | ||
* | ||
|
@@ -221,6 +232,8 @@ class CSHARP:public Language { | |
|
||
SWIG_library_directory("csharp"); | ||
|
||
int doxygen_translator_flags = 0; | ||
|
||
// Look for certain command line options | ||
for (int i = 1; i < argc; i++) { | ||
if (argv[i]) { | ||
|
@@ -248,7 +261,21 @@ class CSHARP:public Language { | |
} else { | ||
Swig_arg_error(); | ||
} | ||
} else if ((strcmp(argv[i], "-noproxy") == 0)) { | ||
} | ||
else if ((strcmp(argv[i], "-doxygen") == 0)) { | ||
Swig_mark_arg(i); | ||
doxygen = true; | ||
scan_doxygen_comments = true; | ||
} | ||
else if ((strcmp(argv[i], "-debug-doxygen-translator") == 0)) { | ||
Swig_mark_arg(i); | ||
doxygen_translator_flags |= DoxygenTranslator::debug_translator; | ||
} | ||
else if ((strcmp(argv[i], "-debug-doxygen-parser") == 0)) { | ||
Swig_mark_arg(i); | ||
doxygen_translator_flags |= DoxygenTranslator::debug_parser; | ||
} | ||
else if ((strcmp(argv[i], "-noproxy") == 0)) { | ||
Swig_mark_arg(i); | ||
proxy_flag = false; | ||
} else if (strcmp(argv[i], "-oldvarnames") == 0) { | ||
|
@@ -270,6 +297,9 @@ class CSHARP:public Language { | |
} | ||
} | ||
|
||
if (doxygen) | ||
doxygenTranslator = new DoxygenTranslator(doxygen_translator_flags); | ||
|
||
// Add a symbol to the parser for conditional compilation | ||
Preprocessor_define("SWIGCSHARP 1", 0); | ||
|
||
|
@@ -453,11 +483,23 @@ class CSHARP:public Language { | |
{ | ||
File *f_im = getOutputFile(SWIG_output_directory(), imclass_name); | ||
|
||
//Add any structural comments to the top | ||
if (doxygen && structuralComments) | ||
Printf(f_im, "%s", structuralComments); | ||
|
||
addOpenNamespace(0, f_im); | ||
|
||
if (imclass_imports) | ||
Printf(f_im, "%s\n", imclass_imports); | ||
|
||
if (doxygen && doxygenTranslator->hasDocumentation(n)) { | ||
String* doxygen_comments = doxygenTranslator->getDocumentation(n, 0); | ||
if (comment_creation_chatter) | ||
Printf(f_im, "/* This was generated from top() */"); | ||
Printv(f_im, " /** ", Char(doxygen_comments), " */\n", NIL); | ||
Delete(doxygen_comments); | ||
} | ||
|
||
if (Len(imclass_class_modifiers) > 0) | ||
Printf(f_im, "%s ", imclass_class_modifiers); | ||
Printf(f_im, "%s ", imclass_name); | ||
|
@@ -592,6 +634,8 @@ class CSHARP:public Language { | |
module_class_modifiers = NULL; | ||
Delete(imclass_imports); | ||
imclass_imports = NULL; | ||
Delete(structuralComments); | ||
structuralComments = NULL; | ||
Delete(imclass_cppcasts_code); | ||
imclass_cppcasts_code = NULL; | ||
Delete(upcasts_code); | ||
|
@@ -1201,6 +1245,15 @@ class CSHARP:public Language { | |
EnumFeature enum_feature = decodeEnumFeature(n); | ||
String *typemap_lookup_type = Getattr(n, "name"); | ||
|
||
if (doxygen && doxygenTranslator->hasDocumentation(n)) { | ||
String* doxygen_comments = doxygenTranslator->getDocumentation(n, 0); | ||
if (comment_creation_chatter) { | ||
Printf(enum_code, "/* This was generated from enumDeclaration() */"); | ||
} | ||
Printv(enum_code, "/** ", Char(doxygen_comments), " */\n", NIL); | ||
Delete(doxygen_comments); | ||
} | ||
|
||
if ((enum_feature != SimpleEnum) && symname && typemap_lookup_type) { | ||
// Wrap (non-anonymous) C/C++ enum within a typesafe, typeunsafe or proper C# enum | ||
|
||
|
@@ -1226,6 +1279,15 @@ class CSHARP:public Language { | |
// Wrap C++ enum with integers - just indicate start of enum with a comment, no comment for anonymous enums of any sort | ||
if (symname && !Getattr(n, "unnamedinstance")) | ||
Printf(constants_code, " // %s \n", symname); | ||
// Translate and write javadoc comment for the enum itself if flagged | ||
if (doxygen && doxygenTranslator->hasDocumentation(n)) { | ||
String* doxygen_comments = doxygenTranslator->getDocumentation(n, " "); | ||
if (comment_creation_chatter) | ||
Printf(constants_code, "/* This was generated from enumDeclaration() */\n"); | ||
Printf(constants_code, Char(doxygen_comments)); | ||
Printf(constants_code, "\n"); | ||
Delete(doxygen_comments); | ||
} | ||
} | ||
|
||
// Emit each enum item | ||
|
@@ -1367,7 +1429,16 @@ class CSHARP:public Language { | |
if (!GetFlag(n, "firstenumitem")) | ||
Printf(enum_code, ",\n"); | ||
|
||
if (csattributes) | ||
//translate and write comment if flagged | ||
if (doxygen && doxygenTranslator->hasDocumentation(n)) { | ||
String* doxygen_comments = doxygenTranslator->getDocumentation(n, " "); | ||
if (comment_creation_chatter) | ||
Printf(enum_code, "/* This was generated from enumvalueDeclaration() */"); | ||
Printv(enum_code, "\n /** ", Char(doxygen_comments), " */\n", NIL); | ||
Delete(doxygen_comments); | ||
} | ||
|
||
if (csattributes) | ||
Printf(enum_code, " %s\n", csattributes); | ||
|
||
Printf(enum_code, " %s", symname); | ||
|
@@ -1381,7 +1452,16 @@ class CSHARP:public Language { | |
Printf(enum_code, " = %s", value); | ||
} | ||
} else { | ||
// Wrap C/C++ enums with constant integers or use the typesafe enum pattern | ||
//translate and write comment if flagged | ||
if (doxygen && doxygenTranslator->hasDocumentation(n)) { | ||
String* doxygen_comments = doxygenTranslator->getDocumentation(n, " "); | ||
if (comment_creation_chatter) | ||
Printf(enum_code, "/* This was generated from enumvalueDeclaration() */"); | ||
Printv(enum_code, "\n /** ", Char(doxygen_comments), " */\n", NIL); | ||
Delete(doxygen_comments); | ||
} | ||
|
||
// Wrap C/C++ enums with constant integers or use the typesafe enum pattern | ||
SwigType *typemap_lookup_type = parent_name ? parent_name : NewString("enum "); | ||
Setattr(n, "type", typemap_lookup_type); | ||
const String *tm = typemapLookup(n, "cstype", typemap_lookup_type, WARN_CSHARP_TYPEMAP_CSWTYPE_UNDEF); | ||
|
@@ -1434,6 +1514,22 @@ class CSHARP:public Language { | |
return SWIG_OK; | ||
} | ||
|
||
/* ----------------------------------------------------------------------- | ||
* doxygenComment() | ||
* Simply translates the doxygen comment and places it into the appropriate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if "translates" here is really correct, as it doesn't seem to be doing any translation, does it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It depends on the translator, just default being verbatim copy. I mean, technically C# module knows that the translator is doing nothing only in module constructor (that may change if someone will introduce an alternative). |
||
* file | ||
* ------------------------------------------------------------------------ */ | ||
virtual int doxygenComment(Node* n) { | ||
if (doxygen && doxygenTranslator->hasDocumentation(n)) { | ||
String* doxygen_comments = doxygenTranslator->getDocumentation(n, 0); | ||
if (comment_creation_chatter) | ||
Printf(structuralComments, "/* This was generated from doxygenComment() */"); | ||
Printv(structuralComments, "/** ", Char(doxygen_comments), " */\n", NIL); | ||
Delete(doxygen_comments); | ||
} | ||
return SWIG_OK; | ||
} | ||
|
||
/* ----------------------------------------------------------------------- | ||
* constantWrapper() | ||
* Used for wrapping constants - #define or %constant. | ||
|
@@ -1456,6 +1552,15 @@ class CSHARP:public Language { | |
Swig_save("constantWrapper", n, "value", NIL); | ||
Swig_save("constantWrapper", n, "tmap:ctype:out", "tmap:imtype:out", "tmap:cstype:out", "tmap:out:null", "tmap:imtype:outattributes", "tmap:cstype:outattributes", NIL); | ||
|
||
//translate and write comment if flagged | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, could you please explain what do you mean by "if flagged" here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blind copy from the Java module, probably means "if enabled", removed now. |
||
if (doxygen && doxygenTranslator->hasDocumentation(n)) { | ||
String* doxygen_comments = doxygenTranslator->getDocumentation(n, " "); | ||
if (comment_creation_chatter) | ||
Printf(constants_code, "/* This was generated from constantWrapper() */"); | ||
Printv(constants_code, " /** ", Char(doxygen_comments), " */ ", NIL); | ||
Delete(doxygen_comments); | ||
} | ||
|
||
bool is_enum_item = (Cmp(nodeType(n), "enumitem") == 0); | ||
|
||
const String *itemname = (proxy_flag && wrapping_member_flag) ? variable_name : symname; | ||
|
@@ -1861,6 +1966,15 @@ class CSHARP:public Language { | |
Printv(proxy_class_def, typemapLookup(n, "csimports", typemap_lookup_type, WARN_NONE), // Import statements | ||
"\n", NIL); | ||
|
||
// translate and write comment if flagged | ||
if (doxygen && doxygenTranslator->hasDocumentation(n)) { | ||
String* doxygen_comments = doxygenTranslator->getDocumentation(n, 0); | ||
if (comment_creation_chatter) | ||
Printf(proxy_class_def, "/* This was generated from emitProxyClassDefAndCPPCasts() */"); | ||
Printv(proxy_class_def, " /** ", Char(doxygen_comments), " */ \n", NIL); | ||
Delete(doxygen_comments); | ||
} | ||
|
||
// Class attributes | ||
const String *csattributes = typemapLookup(n, "csattributes", typemap_lookup_type, WARN_NONE); | ||
if (csattributes && *Char(csattributes)) | ||
|
@@ -2602,7 +2716,17 @@ class CSHARP:public Language { | |
Swig_warning(WARN_CSHARP_TYPEMAP_CSOUT_UNDEF, input_file, line_number, "No cstype typemap defined for %s\n", SwigType_str(cvariable_type, 0)); | ||
} | ||
} | ||
const String *csattributes = Getattr(n, "feature:cs:attributes"); | ||
|
||
// translate and write comment if flagged | ||
if (doxygen && doxygenTranslator->hasDocumentation(n)) { | ||
String* doxygen_comments = doxygenTranslator->getDocumentation(n, " "); | ||
if (comment_creation_chatter) | ||
Printf(function_code, "/* This was generated from proxyclassfunctionhandler() */"); | ||
Printv(function_code, " /** ", Char(doxygen_comments), " */ \n", NIL); | ||
Delete(doxygen_comments); | ||
} | ||
|
||
const String* csattributes = Getattr(n, "feature:cs:attributes"); | ||
if (csattributes) | ||
Printf(proxy_class_code, " %s\n", csattributes); | ||
const String *methodmods = Getattr(n, "feature:cs:methodmodifiers"); | ||
|
@@ -2685,6 +2809,15 @@ class CSHARP:public Language { | |
String *mangled_overname = Swig_name_construct(getNSpace(), overloaded_name); | ||
String *imcall = NewString(""); | ||
|
||
// translate and write comment if flagged | ||
if (doxygen && doxygenTranslator->hasDocumentation(n)) { | ||
String* doxygen_comments = doxygenTranslator->getDocumentation(n, " "); | ||
if (comment_creation_chatter) | ||
Printf(function_code, "/* This was generated from constructionhandler() */"); | ||
Printv(function_code, " /** ", Char(doxygen_comments), " */ \n", NIL); | ||
Delete(doxygen_comments); | ||
} | ||
|
||
const String *csattributes = Getattr(n, "feature:cs:attributes"); | ||
if (csattributes) { | ||
Printf(function_code, " %s\n", csattributes); | ||
|
@@ -2988,6 +3121,15 @@ class CSHARP:public Language { | |
String *post_code = NewString(""); | ||
String *terminator_code = NewString(""); | ||
|
||
// translate and write comment if flagged | ||
if (doxygen && doxygenTranslator->hasDocumentation(n)) { | ||
String* doxygen_comments = doxygenTranslator->getDocumentation(n, " "); | ||
if (comment_creation_chatter) | ||
Printf(function_code, "/* This was generated from moduleClassFunctionHandler() */"); | ||
Printv(function_code, " /** ", doxygen_comments, " */\n", NIL); | ||
Delete(doxygen_comments); | ||
} | ||
|
||
if (l) { | ||
if (SwigType_type(Getattr(l, "type")) == T_VOID) { | ||
l = nextSibling(l); | ||
|
@@ -4585,6 +4727,9 @@ extern "C" Language *swig_csharp(void) { | |
|
||
const char *CSHARP::usage = "\ | ||
C# Options (available with -csharp)\n\ | ||
-doxygen - Convert C++ doxygen comments to JavaDoc comments in proxy classes\n\ | ||
-debug-doxygen-parser - Display doxygen parser module debugging information\n\ | ||
-debug-doxygen-translator - Display doxygen translator module debugging information\n\ | ||
-dllimport <dl> - Override DllImport attribute name to <dl>\n\ | ||
-namespace <nm> - Generate wrappers into C# namespace <nm>\n\ | ||
-noproxy - Generate the low-level functional interface instead\n\ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this supposed to be left in? Because there doesn't seem to be any way to set it, so it doesn't look useful in its current form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe set from the debugger (just like in Java module)