Browse Source

Parse class doc strings

Josh Engebretson 9 years ago
parent
commit
fa13d4496b

+ 13 - 0
Source/ToolCore/JSBind/CSharp/CSClassWriter.cpp

@@ -187,6 +187,19 @@ void CSClassWriter::GenerateManagedSource(String& sourceOut)
     source += "\n";
     String line;
 
+    if (klass_->GetDocString().Length())
+    {
+        // monodocer -assembly:NETCore.dll -path:en -pretty
+        // mdoc export-html -o htmldocs en
+        source += IndentLine("/// <summary>\n");
+        if (klass_->GetDocString().Contains('\n'))
+            source += IndentLine("/* " + klass_->GetDocString() + "*/\n");
+        else
+            source += IndentLine("/// " + klass_->GetDocString() + "\n");
+
+        source += IndentLine("/// </summary>\n");
+    }
+
     if (klass_->GetBaseClass())
     {
         line = ToString("public partial class %s%s : %s\n", klass_->GetName().CString(), klass_->IsGeneric() ? "<T>" : "", klass_->GetBaseClass()->GetName().CString());

+ 4 - 0
Source/ToolCore/JSBind/JSBClass.h

@@ -157,6 +157,7 @@ public:
     JSBHeader* GetHeader() { return header_; }
     JSBModule* GetModule() { return module_; }
     JSBPackage* GetPackage() { return module_->GetPackage(); }
+    const String& GetDocString() const { return docString_; }
 
     bool IsNumberArray() { return numberArrayElements_ != 0; }
     int  GetNumberArrayElements() { return numberArrayElements_;}
@@ -168,6 +169,7 @@ public:
     void SetObject(bool value = true) { isObject_ = value; }
     void SetGeneric(bool value = true) { isGeneric_ = value; }
     void SetHeader(JSBHeader* header) { header_ = header; }
+    void SetDocString(const String& value) { docString_ = value; }
     void SetBaseClass(JSBClass* baseClass);
 
     void SetSkipFunction(const String& name, bool skip = true);
@@ -213,6 +215,8 @@ private:
     bool isObject_;
     bool isGeneric_;
 
+    String docString_;
+
     // Vector3, Color, etc are marshalled via arrays
     int numberArrayElements_;
     String arrayElementType_;

+ 70 - 56
Source/ToolCore/JSBind/JSBHeaderVisitor.h

@@ -370,6 +370,69 @@ public:
 
     }
 
+    String parseDocString(int commentLine) const
+    {
+        const char* comment = NULL;
+        for (unsigned i = 0; i < unit_->commentCount(); i++)
+        {
+            const Token &tcomment = unit_->commentAt(i);
+            unsigned line;
+            unit_->getPosition(tcomment.utf16charsEnd(), &line);
+
+            if (line ==  commentLine)
+            {
+                comment = unit_->firstSourceChar() + tcomment.byteOffset;
+                break;
+            }
+        }
+
+        String docString;
+
+        if (comment && strlen(comment) > 3)
+        {
+            if (comment[0] == '/' && comment[1] == '/' && comment[2] == '/')
+            {
+                int index = 3;
+                while(comment[index] && comment[index] != '\n' && comment[index] != '\r')
+                {
+                    docString += comment[index++];
+                }
+
+            }
+
+            if (comment[0] == '/' && comment[1] == '*' && comment[2] == '*')
+            {
+                int index = 3;
+                bool foundStar = false;
+                while(comment[index])
+                {
+                    // did we find a star in the last loop?
+                    if (foundStar)
+                    {
+                        // We have a an end of block indicator, let's break
+                        if (comment[index] == '/' && foundStar)
+                            break;
+
+                        // This is just a star in the comment, not an end of comment indicator.  Let's keep it
+                        docString += '*';
+                    }
+
+                    foundStar = comment[index] == '*';
+
+                    if (!foundStar)
+                        docString += comment[index];
+
+                    index++;
+                }
+            }
+
+        }
+
+        return docString;
+
+
+    }
+
     JSBFunction* processFunction(JSBClass* klass, Function* function)
     {
         JSBFunction* jfunction = new JSBFunction(klass);
@@ -457,64 +520,11 @@ public:
         jfunction->sourceColumn_ = function->column();
         //const Token &token = unit_->tokenAt(function->sourceLocation());
         //const char* source = unit_->firstSourceChar() + token.byteOffset;
-        const char* comment = NULL;
-        for (unsigned i = 0; i < unit_->commentCount(); i++)
-        {
-            const Token &tcomment = unit_->commentAt(i);
-            unsigned line;
-            unit_->getPosition(tcomment.utf16charsEnd(), &line);
-
-            if (line ==  function->line() - 1)
-            {
-                comment = unit_->firstSourceChar() + tcomment.byteOffset;
-                break;
-            }
-        }
 
-        if (comment && strlen(comment) > 3)
-        {
-            if (comment[0] == '/' && comment[1] == '/' && comment[2] == '/')
-            {
-                int index = 3;
-                while(comment[index] && comment[index] != '\n' && comment[index] != '\r')
-                {
-                    String docString = jfunction->GetDocString();
-                    docString += comment[index++];
-                    jfunction->SetDocString(docString);
-                }
-
-            }
-
-            if (comment[0] == '/' && comment[1] == '*' && comment[2] == '*')
-            {
-                int index = 3;
-                bool foundStar = false;
-                String docString = jfunction->GetDocString();
-                while(comment[index])
-                {
-                    // did we find a star in the last loop?
-                    if (foundStar)
-                    {
-                        // We have a an end of block indicator, let's break
-                        if (comment[index] == '/' && foundStar)
-                            break;
-
-                        // This is just a star in the comment, not an end of comment indicator.  Let's keep it
-                        docString += '*';
-                    }
-                    
-                    foundStar = comment[index] == '*';
-
-                    if (!foundStar)
-                        docString += comment[index];
-
-                    index++;
-                }
-                jfunction->SetDocString(docString);
-            }
-
-        }
+        String docString = parseDocString(function->line() - 1);
 
+        if (docString.Length())
+            jfunction->SetDocString(docString);
 
         return jfunction;
 
@@ -607,6 +617,10 @@ public:
 
         jclass->SetHeader(header_);
 
+        String docString = parseDocString(klass->line() - 1);
+        if (docString.Length())
+            jclass->SetDocString(docString);
+
         for (unsigned i = 0; i < klass->baseClassCount(); i++)
         {
             BaseClass* baseclass = klass->baseClassAt(i);