diff options
| author | Christoph Schlosser <christoph@linux.com> | 2019-10-05 16:50:54 +0200 |
|---|---|---|
| committer | Christoph Schlosser <christophschlosser@users.noreply.github.com> | 2019-10-05 17:03:39 +0200 |
| commit | 6e749554cc7a47849bd63d7ec1027f084d26b505 (patch) | |
| tree | 09d14b193a7207e59b7c58e79ce16468bd9e20aa | |
| parent | 1cf0a3b9762ad5734352fa25514e50caf27ae52f (diff) | |
| download | doxdocgen-6e749554cc7a47849bd63d7ec1027f084d26b505.tar.gz | |
Add arraypointers
| -rw-r--r-- | src/Lang/Cpp/CppParser.ts | 22 | ||||
| -rw-r--r-- | src/test/CppTests/FunctionPointer.test.ts | 5 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/Lang/Cpp/CppParser.ts b/src/Lang/Cpp/CppParser.ts index c6a72fb..2ea3c3f 100644 --- a/src/Lang/Cpp/CppParser.ts +++ b/src/Lang/Cpp/CppParser.ts @@ -563,6 +563,22 @@ export default class CppParser implements ICodeParser { return nodes.filter((n) => n instanceof CppParseTree).length === 2; } + private IsArrayPtr(nodes: Array<CppToken | CppParseTree>) { + if (nodes.filter((n) => n instanceof CppParseTree).length === 1) { + const treeIdx = nodes.findIndex((n) => n instanceof CppParseTree); + if (treeIdx !== -1) { + const nextElem = nodes[treeIdx + 1]; + if (nextElem instanceof CppToken) { + const match = nextElem.value.match(/^\[[0-9]*\]$/g); + if (match !== undefined && match !== null) { + return match.length > 0; + } + } + } + } + return false; + } + private StripNonTypeNodes(tree: CppParseTree) { tree.nodes = tree.nodes // All strippable keywords. @@ -625,7 +641,7 @@ export default class CppParser implements ICodeParser { let cursor: CppParseTree = tree; - while (this.IsFuncPtr(cursor.nodes) === true) { + while (this.IsFuncPtr(cursor.nodes) === true || this.IsArrayPtr(cursor.nodes) === true) { cursor = cursor.nodes.find((n) => n instanceof CppParseTree) as CppParseTree; } @@ -713,6 +729,10 @@ export default class CppParser implements ICodeParser { return this.GetArgumentFromFuncPtr(copy); } + if (this.IsArrayPtr(copy.nodes) === true) { + return this.GetArgumentFromFuncPtr(copy); + } + // Handle member pointers for (let token: number = 0; token < copy.nodes.length - 1; token++) { const firstToken: CppToken = copy.nodes[token] as CppToken; diff --git a/src/test/CppTests/FunctionPointer.test.ts b/src/test/CppTests/FunctionPointer.test.ts index 7a4383c..cd318ce 100644 --- a/src/test/CppTests/FunctionPointer.test.ts +++ b/src/test/CppTests/FunctionPointer.test.ts @@ -44,4 +44,9 @@ suite("C++ - Function pointer Tests", () => { const result = testSetup.SetLine("void foo(void (SomeClass::* func)());").GetResult(); assert.equal("/**\n * @brief \n * \n * @param func \n */", result); }); + + test("Arraypointer", () => { + const result = testSetup.SetLine("void some_function(int (*table)[]);").GetResult(); + assert.equal("/**\n * @brief \n * \n * @param table \n */", result); + }); }); |