summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md16
-rw-r--r--src/CodeParser/CParser.ts39
-rw-r--r--src/DocGen/CGen.ts9
3 files changed, 55 insertions, 9 deletions
diff --git a/README.md b/README.md
index 5507a24..f4f9ca7 100644
--- a/README.md
+++ b/README.md
@@ -43,9 +43,23 @@ Or void return values
See [Below](#whats-to-come)
+## Contributors
+
+[Christoph Schlosser](https://github.com/christophschlosser)
+
+[Rowan Goemans](https://github.com/rowanG077)
+
## Known Issues
-Completely new extension, so none.
+### Function pointers
+
+See [#18](https://github.com/christophschlosser/doxdocgen/issues/18)
+
+Documentation for certain constructs (like the following) may not be generated correctly.
+
+```C
+int (*idputs(int (*puts)(const char *)))(const char *)
+```
## What's to come
diff --git a/src/CodeParser/CParser.ts b/src/CodeParser/CParser.ts
index 8b0bfe1..f26aa5f 100644
--- a/src/CodeParser/CParser.ts
+++ b/src/CodeParser/CParser.ts
@@ -70,8 +70,7 @@ export default class CParser implements ICodeParser {
logicalLine += nextLineTxt;
// Get method end line
- while (nextLineTxt.indexOf(")") === -1 &&
- (nextLineTxt.indexOf(";") === -1 || nextLineTxt.indexOf("}") === -1)) { // Check for method end
+ while (nextLineTxt.indexOf(";") === -1 && nextLineTxt.indexOf("{") === -1) { // Check for method end
nextLine = new Position(nextLine.line + 1, nextLine.character);
nextLineTxt = this.activeEditor.document.lineAt(nextLine.line).text.trim();
@@ -118,20 +117,50 @@ export default class CParser implements ICodeParser {
protected getParams(method: string): string[] {
const params: string[] = [];
+ const endOfCtorIdx: number = method.search(/\)\s*:/g);
+
+ let func: string = "";
+
+ if (endOfCtorIdx !== -1) {
+ func = method.substring(0, endOfCtorIdx + 1);
+ } else {
+ func = method;
+ }
+
// Get parameters from enclosing brackets
- const parameters: string = method.slice(method.indexOf("(")) // Get opening bracket
- .slice(1, method.indexOf(")")) // Remove opening bracket
- .split(")")[0]; // Get closing bracket
+ const parameters: string = func.substring(func.indexOf("(") + 1, // Get text after opening bracket
+ func.lastIndexOf(")")); // Remove closing bracket
if (parameters.length === 0) { // No parameters
return params;
}
+ let functionPointer: boolean = false;
+
let paramArr: string[] = parameters.split(",");
paramArr = paramArr.map((item: string) => {
// Remove any special C++ characters
const clean: string = item.trim().replace(/[&*\[\]]/g, "");
+ // function pointer special case
+ if (item.indexOf("(") !== -1) {
+ if (item.indexOf(")") !== -1) {
+ // Get the name of the function pointer
+ const funPtr: string = clean.substring(item.indexOf("("), item.indexOf(")"))
+ .replace(/[()]/g, ""); // Remove the brackets
+
+ functionPointer = true;
+ return funPtr.trim();
+ }
+ return null;
+ }
+
+ // Ignore all params until the closing bracket of the function pointer params
+ if (item.indexOf(")") !== -1 && functionPointer) {
+ functionPointer = false;
+ return null;
+ }
+
return clean.split(" ").pop();
});
diff --git a/src/DocGen/CGen.ts b/src/DocGen/CGen.ts
index c2750ee..e333014 100644
--- a/src/DocGen/CGen.ts
+++ b/src/DocGen/CGen.ts
@@ -108,9 +108,12 @@ export default class CGen implements IDocGen {
let line: string = "";
templateWith.forEach((element: string) => {
- line = this.commentPrefix;
- line += this.getTemplatedString(replace, template, element);
- lines.push(line);
+ // Ignore null values
+ if (element !== null) {
+ line = this.commentPrefix;
+ line += this.getTemplatedString(replace, template, element);
+ lines.push(line);
+ }
});
}