summaryrefslogtreecommitdiffstats
path: root/src/CodeParser/CParser
diff options
context:
space:
mode:
authorRowan Goemans <RB.Goemans@student.han.nl>2017-11-05 18:19:53 +0100
committerChristoph Schlosser <christophschlosser@users.noreply.github.com>2017-11-05 18:45:08 +0100
commitde9792646ba66f4965e8170613cee3efb1295d0a (patch)
treec408515920eaf8bb874d97d79e9915385975e288 /src/CodeParser/CParser
parent7e0d21f8dbbc4ec82235b1886b00d7380f174681 (diff)
downloaddoxdocgen-de9792646ba66f4965e8170613cee3efb1295d0a.tar.gz
-- Refactored stripping initializer list and assignment token into function.
Diffstat (limited to 'src/CodeParser/CParser')
-rw-r--r--src/CodeParser/CParser/CParser.ts38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/CodeParser/CParser/CParser.ts b/src/CodeParser/CParser/CParser.ts
index 2b6204d..f87dbdd 100644
--- a/src/CodeParser/CParser/CParser.ts
+++ b/src/CodeParser/CParser/CParser.ts
@@ -226,20 +226,7 @@ export default class CParser implements ICodeParser {
// Create hierarchical tree based on the parenthesis.
const tree: ParseTree = ParseTree.CreateTree(tokens).Compact();
- // First slice of everything after assignment since that will not be used.
- const assignmentIndex = tree.nodes.findIndex((n) => n instanceof Token && n.Type === TokenType.Assignment);
- if (assignmentIndex !== -1) {
- tree.nodes = tree.nodes.slice(0, assignmentIndex);
- }
-
- // Check if there is an initializer list and slice of everything after it.
- const initializerList = tree.nodes
- .findIndex((n) => n instanceof Token && n.Type === TokenType.Symbol && n.Value === ":");
- if (initializerList !== -1) {
- tree.nodes = tree.nodes.slice(0, initializerList);
- }
-
- // return arg.
+ // return argument.
const returnArg = this.GetArgument(tree);
// check if it is a constructor or descructor since these have no name..
// and reverse the assignment of type and name.
@@ -286,9 +273,30 @@ export default class CParser implements ICodeParser {
return [retVals, args];
}
+ private RemoveUnusedTokens(tree: ParseTree): ParseTree {
+ tree = tree.Copy();
+
+ // First slice of everything after assignment since that will not be used.
+ const assignmentIndex = tree.nodes.findIndex((n) => n instanceof Token && n.Type === TokenType.Assignment);
+ if (assignmentIndex !== -1) {
+ tree.nodes = tree.nodes.slice(0, assignmentIndex);
+ }
+
+ // Check if there is an initializer list and slice of everything after it.
+ const initializerList = tree.nodes
+ .findIndex((n) => n instanceof Token && n.Type === TokenType.Symbol && n.Value === ":");
+ if (initializerList !== -1) {
+ tree.nodes = tree.nodes.slice(0, initializerList);
+ }
+
+ return tree;
+ }
+
private GetArgumentList(tree: ParseTree): ParseTree[] {
const args: ParseTree[] = [];
+ tree = this.RemoveUnusedTokens(tree);
+
let cursor: ParseTree = tree;
while (this.IsFuncPtr(cursor.nodes) === true) {
cursor = cursor.nodes.find((n) => n instanceof ParseTree) as ParseTree;
@@ -443,7 +451,7 @@ export default class CParser implements ICodeParser {
private GetArgument(tree: ParseTree): Argument {
// Copy tree structure leave original untouched.
- const copy = tree.Copy();
+ const copy = this.RemoveUnusedTokens(tree);
// Special case with only ellipsis. C style variadic arguments
if (copy.nodes.length === 1) {